From 1065ddce98ccdab762ba2e535fe3ee6badbb7a97 Mon Sep 17 00:00:00 2001 From: lempinen Date: Wed, 4 May 2011 09:02:45 +0000 Subject: [PATCH] New naming service for sysdyn editor. git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@20754 ac1ea38d-2e2b-0410-8846-a27921b304fc --- .../ui/editor/SysdynEditorNamingService.java | 62 +++++++++++++++++++ .../sysdyn/ui/project/SysdynProject.java | 4 +- .../widgets/functions/FunctionCodeWidget.java | 11 ++++ 3 files changed, 75 insertions(+), 2 deletions(-) create mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/SysdynEditorNamingService.java diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/SysdynEditorNamingService.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/SysdynEditorNamingService.java new file mode 100644 index 00000000..261d04db --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/SysdynEditorNamingService.java @@ -0,0 +1,62 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.editor; + +import org.eclipse.ui.IEditorInput; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.utils.NameUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.variable.Variable; +import org.simantics.db.layer0.variable.Variables; +import org.simantics.modeling.ui.features.EditorNamingService2; +import org.simantics.simulation.ontology.SimulationResource; +import org.simantics.ui.workbench.IResourceEditorInput2; + +/** + * SysdynEditorNamingService provides names for diagram viewers. + * If the viewer shows an instantiated module, the service provides a name of type: "instanceName : instanceOf". + * Otherwise works as standard EditorNamingService2. + * + * @author TLTEEMU + * + */ +public class SysdynEditorNamingService extends EditorNamingService2 { + + @Override + public String getName(ReadGraph g, String editorId, IEditorInput in) throws DatabaseException { + if(in instanceof IResourceEditorInput2) { + IResourceEditorInput2 input = (IResourceEditorInput2) in; + + if(!input.getRVI().isEmpty()) { + Resource model = g.getPossibleResource(input.getModelURI()); + if(model != null) { + Resource configuration = g.getPossibleObject(model, SimulationResource.getInstance(g).HasConfiguration); + String configurationName = NameUtils.getSafeName(g, configuration); + String uri = input.getModelURI() + "/" + configurationName + input.getRVI(); + Variable v = Variables.getPossibleVariable(g, uri); + if(v != null) { + String name = input.getRVI(); + if(name.contains("/")) + name = name.substring(name.lastIndexOf("/") + 1); + + String instanceOf = super.getName(g, editorId, in); + return name + " : " + instanceOf; + } + } + + } + } + return super.getName(g, editorId, in); + } + +} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/project/SysdynProject.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/project/SysdynProject.java index 96f7693a..657a8ff1 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/project/SysdynProject.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/project/SysdynProject.java @@ -44,7 +44,6 @@ import org.simantics.modeling.ModelingResources; import org.simantics.modeling.ModelingUtils; import org.simantics.modeling.services.CaseInsensitiveComponentNamingStrategy2; import org.simantics.modeling.services.ComponentNamingStrategy; -import org.simantics.modeling.ui.features.EditorNamingService2; import org.simantics.project.IProject; import org.simantics.project.ProjectElementType; import org.simantics.project.ProjectElements; @@ -57,6 +56,7 @@ import org.simantics.simulation.ontology.SimulationResource; import org.simantics.simulation.project.IExperimentManager; import org.simantics.sysdyn.SysdynResource; import org.simantics.sysdyn.ui.Activator; +import org.simantics.sysdyn.ui.editor.SysdynEditorNamingService; import org.simantics.ui.SimanticsUI; import org.simantics.ui.workbench.IEditorNamingService; import org.simantics.ui.workbench.action.ChooseActionRequest; @@ -186,7 +186,7 @@ public class SysdynProject extends AbstractProjectFeature { getProjectElement().setHint(ProjectKeys.DEFAULT_PERSPECTIVE, DEFAULT_PERSPECTIVE); - getProjectElement().setHint(IEditorNamingService.KEY_EDITOR_NAMING_SERVICE, new EditorNamingService2()); + getProjectElement().setHint(IEditorNamingService.KEY_EDITOR_NAMING_SERVICE, new SysdynEditorNamingService()); mm = new ModelManager(); getProjectElement().setHint(UIModelManager.KEY_MODEL_MANAGER, mm); diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/functions/FunctionCodeWidget.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/functions/FunctionCodeWidget.java index ac26d7c2..7c07e305 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/functions/FunctionCodeWidget.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/functions/FunctionCodeWidget.java @@ -1,3 +1,14 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ package org.simantics.sysdyn.ui.properties.widgets.functions; import java.awt.event.ActionEvent; -- 2.47.1