]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Removed double click handler for structural browsing, because it is not working prope...
authorlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Mon, 2 Aug 2010 13:19:53 +0000 (13:19 +0000)
committerlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Mon, 2 Aug 2010 13:19:53 +0000 (13:19 +0000)
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@16904 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/DiagramViewer.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/InputFactory.java

index 54c5883233ba630ba0c60fdc3dee340b30ffa6d7..fa54697977a80f05e76abfd20f4ff278f863aad9 100644 (file)
@@ -1,16 +1,25 @@
 package org.simantics.sysdyn.ui.editor;\r
 \r
+import java.util.ArrayList;\r
 import java.util.Collections;\r
 import java.util.Set;\r
 \r
+import org.eclipse.jface.viewers.ISelection;\r
+import org.eclipse.jface.viewers.StructuredSelection;\r
 import org.eclipse.ui.IWorkbenchPartSite;\r
+import org.simantics.browsing.ui.swt.AdaptableHintContext;\r
 import org.simantics.browsing.ui.swt.IPropertyPage;\r
 import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
 import org.simantics.db.Session;\r
+import org.simantics.db.layer0.SelectionHints;\r
 import org.simantics.diagram.adapter.FlagClassFactory;\r
 import org.simantics.diagram.handler.CopyPasteHandler;\r
 import org.simantics.diagram.stubs.DiagramResource;\r
 import org.simantics.diagram.synchronization.IModifiableSynchronizationContext;\r
+import org.simantics.diagram.ui.DiagramModelHints;\r
+import org.simantics.diagram.ui.WorkbenchSelectionProvider;\r
+import org.simantics.g2d.canvas.ICanvasContext;\r
 import org.simantics.g2d.canvas.impl.CanvasContext;\r
 import org.simantics.g2d.connection.IConnectionAdvisor;\r
 import org.simantics.g2d.diagram.DiagramHints;\r
@@ -18,13 +27,18 @@ import org.simantics.g2d.diagram.participant.DeleteHandler;
 import org.simantics.g2d.diagram.participant.pointertool.PointerInteractor;\r
 import org.simantics.g2d.element.ElementClassProviders;\r
 import org.simantics.g2d.element.ElementClasses;\r
+import org.simantics.g2d.element.ElementHints;\r
+import org.simantics.g2d.element.IElement;\r
 import org.simantics.g2d.element.IElementClassProvider;\r
 import org.simantics.g2d.element.handler.impl.StaticObjectAdapter;\r
+import org.simantics.modeling.ui.diagramEditor.handlers.LinkBrowsingHandler;\r
 import org.simantics.structural2.modelingRules.IModelingRules;\r
 import org.simantics.sysdyn.SysdynResource;\r
 import org.simantics.sysdyn.ui.elements2.connections.ConnectionClasses;\r
 import org.simantics.sysdyn.ui.elements2.connections.SysdynConnectionClass;\r
 import org.simantics.sysdyn.ui.properties.SysdynPropertyPage;\r
+import org.simantics.utils.datastructures.hints.HintContext;\r
+import org.simantics.utils.datastructures.hints.IHintContext;\r
 \r
 /**\r
  * @author Tuukka Lehtonen\r
@@ -79,11 +93,46 @@ public class DiagramViewer extends org.simantics.modeling.ui.diagramEditor.Diagr
         SysdynResource.getInstance(graph);\r
     }\r
 \r
-//    @Override\r
-//    protected void addStructureParticipants(ICanvasContext ctx) {\r
-////        structuralPath = getResourceInput().getResourceArray().removeFromBeginning(1);\r
-//        ctx.add(new WorkbenchStructuralSelectionProvider2(swt, getSite(), ResourceArray.EMPTY));\r
-//    }\r
+    @Override\r
+    protected void addStructureParticipants(ICanvasContext ctx) {\r
+\r
+        ctx.add(new WorkbenchSelectionProvider(swt, getSite()) {\r
+\r
+            @Override\r
+            protected ISelection constructAdaptableSelection(Iterable<?> selection) {\r
+                ArrayList<Object> objects = new ArrayList<Object>();\r
+                Resource runtime = sourceDiagram.getHint(DiagramModelHints.KEY_DIAGRAM_RUNTIME_RESOURCE);\r
+                for (Object o : selection) {\r
+                    if (o instanceof IElement) {\r
+                        IElement e = (IElement) o;\r
+                        Object object = e.getHint(ElementHints.KEY_OBJECT);\r
+                        if (object != null && runtime != null) {\r
+                            IHintContext context = new AdaptableHintContext(SelectionHints.KEY_MAIN);\r
+                            context.setHint(SelectionHints.KEY_MAIN, object);\r
+                            if (runtime != null)\r
+                                context.setHint(SelectionHints.KEY_VARIABLE_RESOURCE, runtime);\r
+                            objects.add(context);\r
+                        }\r
+                    } else {\r
+                        System.out.println("  unrecognized selection: " + o.getClass() + ": " + o);\r
+                    }\r
+                }\r
+                if(objects.isEmpty() && runtime != null) {\r
+                    HintContext context = new HintContext();\r
+                    context.setHint(SelectionHints.KEY_VARIABLE_RESOURCE, runtime);\r
+                    objects.add(context);\r
+                }\r
+                return new StructuredSelection(objects);\r
+            }\r
+\r
+        });\r
+        // Add visual browsing capabilities for structural models\r
+        \r
+//        Remove double click handler, because it is not working properly\r
+//        ctx.add(new StructuralBrowsingHandler(getSite(), sessionContext, getResourceInput2()));\r
+        ctx.add(new LinkBrowsingHandler(getSite(), this, sessionContext));\r
+\r
+    }\r
 \r
     @Override\r
     protected void addOtherParticipants(CanvasContext ctx) {\r
index d59bc3b339d8b8b28da3c1d23b98c2fad8447072..1977dfb04cd4be96029852a54d5c71197be5bc5e 100644 (file)
@@ -110,7 +110,7 @@ public class InputFactory extends SysdynElementFactory {
             String variable = (String)graph.getRelatedValue(runtime, dr.HasVariable);\r
             Resource moduleRepresentation = graph.getPossibleResource(variable);\r
             if(moduleRepresentation != null)\r
-                module = graph.getSingleObject(moduleRepresentation, b.Represents);\r
+                module = graph.getPossibleObject(moduleRepresentation, b.Represents);\r
             if(module != null)\r
                 for(Resource dep : graph.getObjects(module, sr.IsHeadOf)) {\r
                     Resource reference = graph.getPossibleObject(dep, sr.RefersTo);\r