>-- SYSDYN.IndependentVariable.rangeStep --> L0.Double <R L0.HasProperty : L0.FunctionalRelation
// To be used in transient graphs for showing the correct experiment in equation editor
>-- SYSDYN.IndependentVariable.activeExpression --> SYSDYN.Expression <R L0.IsWeaklyRelatedTo : L0.FunctionalRelation
+ >-- SYSDYN.IndependentVariable.isUninitialized --> SYSDYN.IndependentVariable <R L0.HasProperty
SYSDYN.Auxiliary <T SYSDYN.IndependentVariable
@L0.assert SYSDYN.Variable.type "Real"
public final Resource ImportedOntologies;\r
public final Resource IndependentVariable;\r
public final Resource IndependentVariable_activeExpression;\r
+ public final Resource IndependentVariable_isUninitialized;\r
+ public final Resource IndependentVariable_isUninitialized_Inverse;\r
public final Resource IndependentVariable_rangeEnd;\r
public final Resource IndependentVariable_rangeEnd_Inverse;\r
public final Resource IndependentVariable_rangeStart;\r
public static final String ImportedOntologies = "http://www.simantics.org/Sysdyn-1.1/ImportedOntologies";\r
public static final String IndependentVariable = "http://www.simantics.org/Sysdyn-1.1/IndependentVariable";\r
public static final String IndependentVariable_activeExpression = "http://www.simantics.org/Sysdyn-1.1/IndependentVariable/activeExpression";\r
+ public static final String IndependentVariable_isUninitialized = "http://www.simantics.org/Sysdyn-1.1/IndependentVariable/isUninitialized";\r
+ public static final String IndependentVariable_isUninitialized_Inverse = "http://www.simantics.org/Sysdyn-1.1/IndependentVariable/isUninitialized/Inverse";\r
public static final String IndependentVariable_rangeEnd = "http://www.simantics.org/Sysdyn-1.1/IndependentVariable/rangeEnd";\r
public static final String IndependentVariable_rangeEnd_Inverse = "http://www.simantics.org/Sysdyn-1.1/IndependentVariable/rangeEnd/Inverse";\r
public static final String IndependentVariable_rangeStart = "http://www.simantics.org/Sysdyn-1.1/IndependentVariable/rangeStart";\r
ImportedOntologies = getResourceOrNull(graph, URIs.ImportedOntologies);\r
IndependentVariable = getResourceOrNull(graph, URIs.IndependentVariable);\r
IndependentVariable_activeExpression = getResourceOrNull(graph, URIs.IndependentVariable_activeExpression);\r
+ IndependentVariable_isUninitialized = getResourceOrNull(graph, URIs.IndependentVariable_isUninitialized);\r
+ IndependentVariable_isUninitialized_Inverse = getResourceOrNull(graph, URIs.IndependentVariable_isUninitialized_Inverse);\r
IndependentVariable_rangeEnd = getResourceOrNull(graph, URIs.IndependentVariable_rangeEnd);\r
IndependentVariable_rangeEnd_Inverse = getResourceOrNull(graph, URIs.IndependentVariable_rangeEnd_Inverse);\r
IndependentVariable_rangeStart = getResourceOrNull(graph, URIs.IndependentVariable_rangeStart);\r
import java.util.Collection;\r
\r
import org.eclipse.core.expressions.PropertyTester;\r
-import org.eclipse.ui.IWorkbench;\r
import org.eclipse.ui.IWorkbenchPage;\r
-import org.eclipse.ui.IWorkbenchWindow;\r
-import org.eclipse.ui.PlatformUI;\r
import org.simantics.DatabaseJob;\r
import org.simantics.browsing.ui.common.node.AbstractNode;\r
import org.simantics.db.ReadGraph;\r
import org.simantics.db.layer0.request.PossibleModel;\r
import org.simantics.db.request.Read;\r
import org.simantics.modeling.ui.diagramEditor.DiagramEditor;\r
+import org.simantics.sysdyn.ui.utils.SysdynWorkbenchUtils;\r
import org.simantics.ui.SimanticsUI;\r
import org.simantics.ui.utils.ResourceAdaptionUtils;\r
import org.simantics.utils.ui.AdaptionUtils;\r
inputResource = (Resource)a.iterator().next().data;\r
}\r
if (inputResource == null) {\r
- DiagramEditor editor = null;\r
- IWorkbench workbench = PlatformUI.getWorkbench();\r
- IWorkbenchWindow[] windows = workbench.getWorkbenchWindows();\r
- // To ask for the active window doesn't work, so browse through all\r
- // windows and when an active editor is found, use that\r
- for (IWorkbenchWindow window : windows) {\r
- IWorkbenchPage page = window.getActivePage();\r
- if (page != null) {\r
- try {\r
- editor = (DiagramEditor)page.getActiveEditor();\r
- if (editor != null)\r
- // Found one\r
- break;\r
- } catch (ClassCastException e) {\r
- continue;\r
- }\r
- }\r
- }\r
- if (editor != null) {\r
+ \r
+ IWorkbenchPage page = SysdynWorkbenchUtils.getActivePageOfEditor();\r
+ DiagramEditor editor = (DiagramEditor)page.getActiveEditor();\r
+ if (editor != null) {\r
if (editor instanceof DiagramEditor) {\r
inputResource = editor.getInputResource();\r
}\r
);\r
g.claim(result, L0X.Represents, result);\r
\r
- \r
+ // Add uninitialized tag. The tag is used to start name editing \r
+ SysdynResource SR = SysdynResource.getInstance(g);\r
+ g.claim(result, SR.IndependentVariable_isUninitialized, result);\r
\r
// Async reference dialog for shadow variables\r
- SysdynResource SR = SysdynResource.getInstance(g);\r
if(SR.Shadow.equals(componentType)) {\r
Layer0 L0 = Layer0.getInstance(g);\r
Collection<Resource> referrableVariables = g.syncRequest(new ObjectsWithType(configuration, L0.ConsistsOf, SR.IndependentVariable));\r
ShapeNode node;\r
G2DParentNode parent;\r
\r
+ private boolean createVar;\r
+ private IDiagram createVarDiagram;\r
+\r
@SGInit(designation = SGDesignation.CANVAS)\r
public void init(G2DParentNode parent) {\r
this.parent = parent;\r
if (variableInformation != null\r
&& (kre.keyCode == variableInformation.shortcutKey || kre.keyCode == java.awt.event.KeyEvent.VK_SHIFT)) {\r
if (node != null) {\r
+ // If there is a variable to be created, do it when a key is released.\r
+ if (createVar) {\r
+ createVar = false;\r
+ createVariableOnDiagram(createVarDiagram);\r
+ }\r
variableInformation = null;\r
removeSG();\r
return true;\r
{\r
return false;\r
}\r
-\r
-\r
+ \r
final IDiagram d = getHint(DiagramHints.KEY_DIAGRAM);\r
if (d == null)\r
return false;\r
+ \r
+ // Need to create a new variable, save the diagram to do this later.\r
+ createVar = true;\r
+ createVarDiagram = d;\r
+\r
+ return true;\r
+ }\r
\r
+\r
+ private void createVariableOnDiagram(IDiagram d) {\r
DiagramUtils.mutateDiagram(d, new Callback<DiagramMutator>() {\r
@Override\r
public void run(DiagramMutator m) {\r
\r
synchronizer.getCanvasContext().getContentContext().setDirty();\r
\r
- return true;\r
}\r
\r
private class VariableInformation {\r
import java.awt.Font;\r
import java.awt.geom.AffineTransform;\r
\r
+import org.eclipse.swt.widgets.Control;\r
+import org.eclipse.ui.IWorkbenchPage;\r
import org.simantics.db.ReadGraph;\r
import org.simantics.db.Resource;\r
import org.simantics.db.WriteGraph;\r
import org.simantics.db.common.request.ReadRequest;\r
import org.simantics.db.common.request.WriteRequest;\r
import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.diagram.elements.DiagramNodeUtil;\r
import org.simantics.diagram.elements.ITextListener;\r
import org.simantics.diagram.elements.TextElementNoBounds;\r
import org.simantics.diagram.elements.TextNode;\r
+import org.simantics.diagram.participant.SGFocusParticipant;\r
+import org.simantics.g2d.canvas.ICanvasContext;\r
+import org.simantics.g2d.chassis.SWTChassis;\r
import org.simantics.g2d.diagram.DiagramUtils;\r
import org.simantics.g2d.diagram.IDiagram;\r
import org.simantics.g2d.element.ElementHints;\r
import org.simantics.g2d.utils.Alignment;\r
import org.simantics.layer0.Layer0;\r
import org.simantics.modeling.ModelingResources;\r
+import org.simantics.modeling.ui.diagramEditor.DiagramEditor;\r
+import org.simantics.modeling.ui.diagramEditor.DiagramViewer;\r
import org.simantics.scenegraph.g2d.G2DParentNode;\r
+import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.sysdyn.ui.utils.SysdynWorkbenchUtils;\r
import org.simantics.sysdyn.ui.utils.VariableNameValidator;\r
import org.simantics.ui.SimanticsUI;\r
import org.simantics.utils.datastructures.Callback;\r
\r
public static double SCALE = 0.235;\r
\r
- @Override\r
- public void init(final IElement e, G2DParentNode parent) {\r
- HoverTextNode node = getTextNode(e, parent);\r
-\r
+ protected void initNode(IElement e, HoverTextNode node) {\r
//Font font = new Font("Tahoma", 0, 12);\r
Font font = ElementUtils.getTextFont(e);\r
Color color = ElementUtils.getTextColor(e);\r
if(at != null)\r
node.setTransform(at);\r
}\r
+ \r
+ protected void activateEdit(final HoverTextNode node, final IElement e) {\r
+ final ICanvasContext ctx = DiagramNodeUtil.getCanvasContext(node);\r
+ // FIXME: needed only because eventdelegator registrations are done before adding node to scene graph.\r
+ if (ctx == null)\r
+ return;\r
+ if (!node.isEditMode()) {\r
+ \r
+ // Get the active editor\r
+ IWorkbenchPage page = SysdynWorkbenchUtils.getActivePageOfEditor();\r
+ final DiagramEditor editor = (DiagramEditor)page.getActiveEditor();\r
+ final ICanvasContext editorCtx = (ICanvasContext) editor.getViewer().getAdapter(ICanvasContext.class);\r
+\r
+ editor.getViewer().getComposite().getDisplay().asyncExec(new Runnable() {\r
+ \r
+ @Override\r
+ public void run() {\r
+ Control c = editor.getViewer().getComposite().getDisplay().getFocusControl();\r
+ if (c == null || "BasicSymbols".equals(c.getParent().getToolTipText())) {\r
+ // If the variable has been drag and dropped, set focus to diagram and then activate edit.\r
+ \r
+ editorCtx.add(new SGFocusParticipant((SWTChassis)editor.getViewer().getComposite(), DiagramViewer.DIAGRAMMING_CONTEXT) {\r
+ \r
+ @Override\r
+ public void focusGained(java.awt.event.FocusEvent event) {\r
+ \r
+ // When focus has been gained, acticate edit and destroy the listener.\r
+ editor.getViewer().getComposite().getDisplay().asyncExec(new Runnable() {\r
+ \r
+ @Override\r
+ public void run() {\r
+ if (Boolean.TRUE.equals(node.setEditMode(true))) {\r
+ node.activateEdit(0, e, ctx, true);\r
+ node.repaint();\r
+ }\r
+ }\r
+ });\r
+ ctx.remove(this);\r
+ }\r
+ \r
+ @Override\r
+ public void focusLost(java.awt.event.FocusEvent e) {\r
+ }\r
+ });\r
+ \r
+ editor.setFocus();\r
+ } else {\r
+ // If the variable has been created with shortcut key, just activate the edit.\r
+ if (Boolean.TRUE.equals(node.setEditMode(true))) {\r
+ node.activateEdit(0, e, ctx, true);\r
+ node.repaint();\r
+ }\r
+ }\r
+ }\r
+ }); \r
+ }\r
+ }\r
+ \r
+ @Override\r
+ public void init(final IElement e, G2DParentNode parent) {\r
+ final HoverTextNode node = getTextNode(e, parent);\r
+ initNode(e, node);\r
+\r
+ Object o = e.getHint(ElementHints.KEY_OBJECT);\r
+ if (o instanceof Resource) {\r
+ final Resource element = (Resource)o;\r
+ try {\r
+ SimanticsUI.getSession().syncRequest(new WriteRequest() {\r
+ \r
+ @Override\r
+ public void perform(WriteGraph graph) throws DatabaseException {\r
+ SysdynResource SR = SysdynResource.getInstance(graph);\r
+ ModelingResources MR = ModelingResources.getInstance(graph);\r
+ Resource component = graph.getPossibleObject(element, MR.ElementToComponent);\r
+ if (component == null)\r
+ return;\r
+ \r
+ // See if the resource of the element has just been created. \r
+ Resource r = graph.getPossibleObject(component, SR.IndependentVariable_isUninitialized);\r
+ if (r == null){\r
+ return;\r
+ }\r
+ \r
+ // If the resource is just been created, activate editing its name. \r
+ activateEdit(node, e);\r
+ graph.deny(component, SR.IndependentVariable_isUninitialized, r);\r
+ }\r
+ });\r
+ } catch (DatabaseException e1) {\r
+ e1.printStackTrace();\r
+ }\r
+ }\r
+ }\r
\r
@Override\r
public void cleanup(IElement e) {\r
import java.awt.geom.Rectangle2D;\r
\r
import org.simantics.diagram.elements.DiagramNodeUtil;\r
+import org.simantics.diagram.elements.TextEditActivation;\r
import org.simantics.diagram.elements.TextNode;\r
import org.simantics.g2d.canvas.ICanvasContext;\r
import org.simantics.g2d.element.IElement;\r
}\r
return false;\r
}\r
+\r
+ public TextEditActivation activateEdit(int mouseId, IElement e, ICanvasContext ctx, boolean save) {\r
+ if (save)\r
+ return editActivation = super.activateEdit(mouseId, e, ctx);\r
+ return super.activateEdit(mouseId, e, ctx);\r
+ }\r
}\r
import java.util.Set;\r
\r
import org.eclipse.core.runtime.IProgressMonitor;\r
-import org.eclipse.ui.IWorkbench;\r
import org.eclipse.ui.IWorkbenchPage;\r
-import org.eclipse.ui.IWorkbenchWindow;\r
-import org.eclipse.ui.PlatformUI;\r
import org.simantics.databoard.Bindings;\r
import org.simantics.db.ReadGraph;\r
import org.simantics.db.Resource;\r
import org.simantics.sysdyn.SysdynResource;\r
import org.simantics.sysdyn.ui.handlers.FindSearchTrim;\r
import org.simantics.sysdyn.ui.handlers.FindSearchTrim.Scope;\r
+import org.simantics.sysdyn.ui.utils.SysdynWorkbenchUtils;\r
import org.simantics.workbench.search.NameAndTypeRow;\r
import org.simantics.workbench.search.NamedResource;\r
import org.simantics.workbench.search.SearchQuery;\r
\r
private static boolean resourceFoundInCurrentDiagram(ReadGraph graph, Resource diagram) throws ManyObjectsForFunctionalRelationException, ServiceException {\r
\r
- DiagramEditor editor = null;\r
- IWorkbench workbench = PlatformUI.getWorkbench();\r
- IWorkbenchWindow[] windows = workbench.getWorkbenchWindows();\r
- // To ask for the active window doesn't work, so browse through all\r
- // windows and when an active editor is found, use that\r
- for (IWorkbenchWindow window : windows) {\r
- IWorkbenchPage page = window.getActivePage();\r
- if (page != null) {\r
- try {\r
- editor = (DiagramEditor)page.getActiveEditor();\r
- if (editor != null)\r
- // Found one\r
- break;\r
- } catch (ClassCastException e) {\r
- continue;\r
- }\r
- }\r
- }\r
- if (editor != null) {\r
+ IWorkbenchPage page = SysdynWorkbenchUtils.getActivePageOfEditor();\r
+ DiagramEditor editor = (DiagramEditor)page.getActiveEditor();\r
+ if (editor != null) {\r
Resource inputResource = editor.getInputResource();\r
ModelingResources MOD = ModelingResources.getInstance(graph);\r
Resource editorResource = graph.getPossibleObject(inputResource, MOD.DiagramToComposite);\r
import org.eclipse.core.commands.ExecutionException;\r
import org.eclipse.jface.viewers.ISelection;\r
import org.eclipse.jface.viewers.IStructuredSelection;\r
-import org.eclipse.ui.IWorkbench;\r
import org.eclipse.ui.IWorkbenchPage;\r
import org.eclipse.ui.IWorkbenchPart;\r
-import org.eclipse.ui.IWorkbenchWindow;\r
-import org.eclipse.ui.PlatformUI;\r
import org.eclipse.ui.handlers.HandlerUtil;\r
import org.simantics.browsing.ui.common.node.AbstractNode;\r
import org.simantics.browsing.ui.platform.PropertyPageView;\r
import org.simantics.db.layer0.request.PossibleModel;\r
import org.simantics.db.request.Read;\r
import org.simantics.modeling.ui.diagramEditor.DiagramEditor;\r
+import org.simantics.sysdyn.ui.utils.SysdynWorkbenchUtils;\r
import org.simantics.ui.SimanticsUI;\r
import org.simantics.ui.utils.ResourceAdaptionUtils;\r
import org.simantics.utils.ui.AdaptionUtils;\r
\r
// When the selection doesn't have a resource, use the currently active diagram.\r
if (inputResource == null) {\r
- DiagramEditor editor = null;\r
- IWorkbench workbench = PlatformUI.getWorkbench();\r
- IWorkbenchWindow[] windows = workbench.getWorkbenchWindows();\r
- // To ask for the active window doesn't work, so browse through all\r
- // windows and when an active editor is found, use that\r
- for (IWorkbenchWindow window : windows) {\r
- IWorkbenchPage page = window.getActivePage();\r
- if (page != null) {\r
- try {\r
- editor = (DiagramEditor)page.getActiveEditor();\r
- if (editor != null)\r
- // Found one\r
- break;\r
- } catch (ClassCastException e) {\r
- continue;\r
- }\r
- }\r
- }\r
- if (editor != null && editor instanceof DiagramEditor) {\r
+ IWorkbenchPage page = SysdynWorkbenchUtils.getActivePageOfEditor();\r
+ DiagramEditor editor = (DiagramEditor)page.getActiveEditor();\r
+ if (editor != null && editor instanceof DiagramEditor) {\r
inputResource = editor.getInputResource();\r
} else {\r
return null; \r
--- /dev/null
+package org.simantics.sysdyn.ui.utils;\r
+\r
+import org.eclipse.ui.IWorkbench;\r
+import org.eclipse.ui.IWorkbenchPage;\r
+import org.eclipse.ui.IWorkbenchWindow;\r
+import org.eclipse.ui.PlatformUI;\r
+import org.simantics.modeling.ui.diagramEditor.DiagramEditor;\r
+\r
+public class SysdynWorkbenchUtils {\r
+\r
+ /**\r
+ * Get the active page of the diagram editor.\r
+ * \r
+ * @return active page of the diagram editor.\r
+ */\r
+ public static IWorkbenchPage getActivePageOfEditor() {\r
+ DiagramEditor editor = null;\r
+ IWorkbench workbench = PlatformUI.getWorkbench();\r
+ IWorkbenchWindow[] windows = workbench.getWorkbenchWindows();\r
+ IWorkbenchPage page = null;\r
+ // To ask for the active window doesn't work, so browse through all\r
+ // windows and when an active editor is found, use that\r
+ for (IWorkbenchWindow window : windows) {\r
+ page = window.getActivePage();\r
+ if (page != null) {\r
+ try {\r
+ editor = (DiagramEditor)page.getActiveEditor();\r
+ if (editor != null)\r
+ // Found one\r
+ break;\r
+ } catch (ClassCastException e) {\r
+ continue;\r
+ }\r
+ }\r
+ }\r
+ return page;\r
+ }\r
+}\r