1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2012 Association for Decentralized Information Management in
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.sysdyn.ui.editor;
\r
14 import org.eclipse.ui.IEditorInput;
\r
15 import org.simantics.db.ReadGraph;
\r
16 import org.simantics.db.Resource;
\r
17 import org.simantics.db.common.utils.NameUtils;
\r
18 import org.simantics.db.exception.DatabaseException;
\r
19 import org.simantics.db.layer0.variable.Variable;
\r
20 import org.simantics.db.layer0.variable.Variables;
\r
21 import org.simantics.layer0.Layer0;
\r
22 import org.simantics.modeling.ModelingResources;
\r
23 import org.simantics.modeling.ui.features.EditorNamingService2;
\r
24 import org.simantics.simulation.ontology.SimulationResource;
\r
25 import org.simantics.sysdyn.SysdynResource;
\r
26 import org.simantics.ui.workbench.IResourceEditorInput2;
\r
29 * SysdynEditorNamingService provides names for diagram viewers.
\r
30 * If the viewer shows an instantiated module, the service provides a name of type: "instanceName : instanceOf".
\r
31 * Otherwise works as standard EditorNamingService2.
\r
33 * @author Teemu Lempinen
\r
36 public class SysdynEditorNamingService extends EditorNamingService2 {
\r
39 public String getName(ReadGraph g, String editorId, IEditorInput in) throws DatabaseException {
\r
40 if(in instanceof IResourceEditorInput2) {
\r
41 IResourceEditorInput2 input = (IResourceEditorInput2) in;
\r
43 if(input.getRVI() != null && !input.getRVI().isEmpty()) {
\r
44 Resource model = g.getPossibleResource(input.getModelURI());
\r
46 Resource configuration = g.getPossibleObject(model, SimulationResource.getInstance(g).HasConfiguration);
\r
47 String configurationName = NameUtils.getSafeName(g, configuration);
\r
48 String uri = input.getModelURI() + "/" + configurationName + input.getRVI();
\r
49 Variable v = Variables.getPossibleVariable(g, uri);
\r
51 String name = input.getRVI();
\r
52 if(name.contains("/"))
\r
53 name = name.substring(name.lastIndexOf("/") + 1);
\r
55 Resource instanceOf = g.getPossibleObject(v.getRepresents(g), Layer0.getInstance(g).InstanceOf);
\r
56 return name + " : " + NameUtils.getSafeName(g, instanceOf);
\r
60 ModelingResources mr = ModelingResources.getInstance(g);
\r
61 SysdynResource sr = SysdynResource.getInstance(g);
\r
62 Resource composite = g.getPossibleObject(input.getResource(), mr.DiagramToComposite);
\r
63 if(composite != null) {
\r
64 if(g.isInstanceOf(composite, sr.Configuration))
\r
65 composite = g.getPossibleObject(composite, Layer0.getInstance(g).PartOf);
\r
66 if(composite != null)
\r
67 return NameUtils.getSafeName(g, composite);
\r
71 return super.getName(g, editorId, in);
\r