-/*******************************************************************************\r
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
- * in Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.modeling.ui.diagramEditor.handlers;\r
-\r
-import java.util.Set;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.common.ResourceArray;\r
-import org.simantics.db.common.request.ReadRequest;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.management.ISessionContext;\r
-import org.simantics.diagram.stubs.DiagramResource;\r
-import org.simantics.g2d.canvas.impl.AbstractCanvasParticipant;\r
-import org.simantics.g2d.canvas.impl.DependencyReflection.Dependency;\r
-import org.simantics.g2d.diagram.participant.Selection;\r
-import org.simantics.g2d.element.ElementHints;\r
-import org.simantics.g2d.element.IElement;\r
-import org.simantics.modeling.ModelingResources;\r
-import org.simantics.scenegraph.g2d.events.EventHandlerReflection.EventHandler;\r
-import org.simantics.scenegraph.g2d.events.MouseEvent.MouseDoubleClickedEvent;\r
-import org.simantics.structural.stubs.StructuralResource2;\r
-\r
-/**\r
- * StructuralBrowsingHandler supports visual browsing into subcomponents through\r
- * mouse events.\r
- * \r
- * @author Tuukka Lehtonen\r
- */\r
-public class HeadlessStructuralBrowsingHandler extends AbstractCanvasParticipant {\r
-\r
- @Dependency\r
- Selection selection;\r
- ISessionContext sessionContext;\r
- ResourceArray parentStructuralPath;\r
- IDiagramUpdateSupport diagramProvider;\r
- \r
- public static interface IDiagramUpdateSupport {\r
- public void updateDiagram(ResourceArray structuralPath);\r
- }\r
- \r
- public HeadlessStructuralBrowsingHandler(IDiagramUpdateSupport diagramProvider, ISessionContext sessionContext, ResourceArray parentStructuralPath) {\r
- assert diagramProvider != null;\r
-\r
- this.diagramProvider = diagramProvider;\r
- this.sessionContext = sessionContext;\r
- this.parentStructuralPath = parentStructuralPath;\r
- }\r
-\r
- @EventHandler(priority = 0)\r
- public boolean handleDoubleClick(MouseDoubleClickedEvent me) {\r
- if (sessionContext == null)\r
- return false;\r
-\r
- Set<IElement> sel = selection.getSelection(0);\r
-\r
- if (sel.size() == 1) {\r
- IElement e = sel.iterator().next();\r
- Object data = e.getHint(ElementHints.KEY_OBJECT);\r
- if (data instanceof Resource) {\r
- final Resource element = (Resource) data;\r
- sessionContext.getSession().asyncRequest(new ReadRequest() {\r
- @Override\r
- public void run(ReadGraph graph) throws DatabaseException {\r
- ModelingResources mr = ModelingResources.getInstance(graph);\r
- DiagramResource dr = DiagramResource.getInstance(graph);\r
- StructuralResource2 sr = StructuralResource2.getInstance(graph);\r
-\r
- if (graph.isInstanceOf(element, dr.Flag)) {\r
- /* FIXME: implement headless version\r
- ContextMap parameters = new ContextMap();\r
- parameters.put(ModelingOperationConstants.WORKBENCH_WINDOW, site.getWorkbenchWindow());\r
- parameters.put(ModelingOperationConstants.WORKBENCH_PART, site.getPart());\r
- parameters.put(IOperation.SUBJECT, element);\r
- new NavigateToTarget().exec(graph.getSession(), parameters);\r
- */\r
- return;\r
- }\r
-\r
- final Resource component = graph.getPossibleObject(element, mr.ElementToComponent);\r
- if (component == null)\r
- return;\r
-\r
- Resource type = graph.getSingleType(component, sr.Component);\r
- if (type == null)\r
- return;\r
-\r
- Resource definedBy = graph.getPossibleObject(type, sr.IsDefinedBy);\r
- if (definedBy == null)\r
- return;\r
-\r
- final Resource diagram = graph.getPossibleObject(definedBy, mr.CompositeToDiagram);\r
- if (diagram == null)\r
- return;\r
-\r
- diagramProvider.updateDiagram(parentStructuralPath.prepended(diagram, component));\r
- }\r
- });\r
- }\r
-\r
- return true;\r
- }\r
-\r
- return false;\r
- }\r
-\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 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.modeling.ui.diagramEditor.handlers;
+
+import java.util.Set;
+import org.simantics.db.Resource;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.common.ResourceArray;
+import org.simantics.db.common.request.ReadRequest;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.management.ISessionContext;
+import org.simantics.diagram.stubs.DiagramResource;
+import org.simantics.g2d.canvas.impl.AbstractCanvasParticipant;
+import org.simantics.g2d.canvas.impl.DependencyReflection.Dependency;
+import org.simantics.g2d.diagram.participant.Selection;
+import org.simantics.g2d.element.ElementHints;
+import org.simantics.g2d.element.IElement;
+import org.simantics.modeling.ModelingResources;
+import org.simantics.scenegraph.g2d.events.EventHandlerReflection.EventHandler;
+import org.simantics.scenegraph.g2d.events.MouseEvent.MouseDoubleClickedEvent;
+import org.simantics.structural.stubs.StructuralResource2;
+
+/**
+ * StructuralBrowsingHandler supports visual browsing into subcomponents through
+ * mouse events.
+ *
+ * @author Tuukka Lehtonen
+ */
+public class HeadlessStructuralBrowsingHandler extends AbstractCanvasParticipant {
+
+ @Dependency
+ Selection selection;
+ ISessionContext sessionContext;
+ ResourceArray parentStructuralPath;
+ IDiagramUpdateSupport diagramProvider;
+
+ public static interface IDiagramUpdateSupport {
+ public void updateDiagram(ResourceArray structuralPath);
+ }
+
+ public HeadlessStructuralBrowsingHandler(IDiagramUpdateSupport diagramProvider, ISessionContext sessionContext, ResourceArray parentStructuralPath) {
+ assert diagramProvider != null;
+
+ this.diagramProvider = diagramProvider;
+ this.sessionContext = sessionContext;
+ this.parentStructuralPath = parentStructuralPath;
+ }
+
+ @EventHandler(priority = 0)
+ public boolean handleDoubleClick(MouseDoubleClickedEvent me) {
+ if (sessionContext == null)
+ return false;
+
+ Set<IElement> sel = selection.getSelection(0);
+
+ if (sel.size() == 1) {
+ IElement e = sel.iterator().next();
+ Object data = e.getHint(ElementHints.KEY_OBJECT);
+ if (data instanceof Resource) {
+ final Resource element = (Resource) data;
+ sessionContext.getSession().asyncRequest(new ReadRequest() {
+ @Override
+ public void run(ReadGraph graph) throws DatabaseException {
+ ModelingResources mr = ModelingResources.getInstance(graph);
+ DiagramResource dr = DiagramResource.getInstance(graph);
+ StructuralResource2 sr = StructuralResource2.getInstance(graph);
+
+ if (graph.isInstanceOf(element, dr.Flag)) {
+ /* FIXME: implement headless version
+ ContextMap parameters = new ContextMap();
+ parameters.put(ModelingOperationConstants.WORKBENCH_WINDOW, site.getWorkbenchWindow());
+ parameters.put(ModelingOperationConstants.WORKBENCH_PART, site.getPart());
+ parameters.put(IOperation.SUBJECT, element);
+ new NavigateToTarget().exec(graph.getSession(), parameters);
+ */
+ return;
+ }
+
+ final Resource component = graph.getPossibleObject(element, mr.ElementToComponent);
+ if (component == null)
+ return;
+
+ Resource type = graph.getSingleType(component, sr.Component);
+ if (type == null)
+ return;
+
+ Resource definedBy = graph.getPossibleObject(type, sr.IsDefinedBy);
+ if (definedBy == null)
+ return;
+
+ final Resource diagram = graph.getPossibleObject(definedBy, mr.CompositeToDiagram);
+ if (diagram == null)
+ return;
+
+ diagramProvider.updateDiagram(parentStructuralPath.prepended(diagram, component));
+ }
+ });
+ }
+
+ return true;
+ }
+
+ return false;
+ }
+
+}