]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagramEditor/handlers/LinkBrowsingHandler.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.modeling.ui / src / org / simantics / modeling / ui / diagramEditor / handlers / LinkBrowsingHandler.java
index 8fccf170b7e1a37760be55dd115b243cadc52722..26639ced01bfbfb881a5f290c12319841192ecd8 100644 (file)
-/*******************************************************************************\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.awt.Shape;\r
-import java.awt.geom.AffineTransform;\r
-import java.awt.geom.Rectangle2D;\r
-import java.util.Collection;\r
-import java.util.HashSet;\r
-import java.util.Set;\r
-import java.util.function.Consumer;\r
-\r
-import org.eclipse.ui.IEditorPart;\r
-import org.eclipse.ui.IWorkbenchPartSite;\r
-import org.eclipse.ui.PartInitException;\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.common.ResourceArray;\r
-import org.simantics.db.common.request.ReadRequest;\r
-import org.simantics.db.common.utils.OrderedSetUtils;\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.ICanvasContext;\r
-import org.simantics.g2d.canvas.impl.AbstractCanvasParticipant;\r
-import org.simantics.g2d.canvas.impl.DependencyReflection.Dependency;\r
-import org.simantics.g2d.diagram.DiagramHints;\r
-import org.simantics.g2d.diagram.IDiagram;\r
-import org.simantics.g2d.diagram.handler.DataElementMap;\r
-import org.simantics.g2d.diagram.participant.Selection;\r
-import org.simantics.g2d.element.ElementHints;\r
-import org.simantics.g2d.element.ElementUtils;\r
-import org.simantics.g2d.element.IElement;\r
-import org.simantics.g2d.participant.CanvasBoundsParticipant;\r
-import org.simantics.g2d.participant.TransformUtil;\r
-import org.simantics.g2d.utils.GeometryUtils;\r
-import org.simantics.modeling.ModelingResources;\r
-import org.simantics.modeling.ui.diagramEditor.DiagramViewer;\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
-import org.simantics.ui.workbench.ResourceEditorInput;\r
-import org.simantics.utils.page.MarginUtils;\r
-import org.simantics.utils.threads.ThreadUtils;\r
-import org.simantics.utils.ui.ErrorLogger;\r
-import org.simantics.utils.ui.workbench.WorkbenchUtils;\r
-\r
-/**\r
- * StructuralBrowsingHandler supports visual browsing into subcomponents through\r
- * mouse events.\r
- * \r
- * @author Tuukka Lehtonen\r
- */\r
-public class LinkBrowsingHandler extends AbstractCanvasParticipant {\r
-\r
-    @Dependency\r
-    CanvasBoundsParticipant canvasBounds;\r
-    @Dependency\r
-    Selection               selection;\r
-\r
-    IWorkbenchPartSite      site;\r
-    DiagramViewer           viewer;\r
-    ISessionContext         sessionContext;\r
-\r
-    public LinkBrowsingHandler(IWorkbenchPartSite site, DiagramViewer viewer, ISessionContext context) {\r
-\r
-        assert site != null;\r
-\r
-//             System.out.println("LinkBrowsingHandler " + viewer + " " + viewer.structuralPath);\r
-\r
-        this.site = site;\r
-        this.viewer = viewer;\r
-        this.sessionContext = context;\r
-\r
-    }\r
-\r
-    public static Runnable editorActivator(final IEditorPart part, final ResourceArray input, final Consumer<IEditorPart> successCallback) {\r
-        String sourcePartId = part.getSite().getId();\r
-        return editorActivator(sourcePartId, input, successCallback);\r
-    }\r
-\r
-    public Runnable elementSelectorZoomer(final ICanvasContext canvas, final Collection<Object> elementObjects, final boolean keepZoom) {\r
-        return new Runnable() {\r
-            @Override\r
-            public void run() {\r
-                IDiagram diagram = canvas.getHintStack().getHint(DiagramHints.KEY_DIAGRAM);\r
-                assert diagram != null;\r
-                if (!zoomToSelection(canvas, diagram, selectElement(canvas, diagram, elementObjects), keepZoom)) {\r
-                    // Reschedule for later.\r
-                    ThreadUtils.asyncExec(canvas.getThreadAccess(), this);\r
-                }\r
-            }\r
-        };\r
-    }\r
-\r
-    public static Set<IElement> selectElement(final ICanvasContext canvas, final IDiagram diagram, final Collection<Object> elementObjects) {\r
-        // Select element\r
-        Set<IElement> selection = new HashSet<IElement>();\r
-        DataElementMap dataMap = diagram.getDiagramClass().getSingleItem(DataElementMap.class);\r
-        for (Object obj : elementObjects) {\r
-            IElement element = dataMap.getElement(diagram, obj);\r
-            if (element == null) {\r
-                ErrorLogger.defaultLogWarning("No element to select for object " + obj, new Exception());\r
-            } else {\r
-                selection.add(element);\r
-            }\r
-        }\r
-        for (Selection s : canvas.getItemsByClass(Selection.class)) {\r
-            s.setSelection(0, selection);\r
-        }\r
-        return selection;\r
-    }\r
-\r
-    public boolean zoomToSelection(final ICanvasContext canvas, final IDiagram diagram, Set<IElement> selection, boolean keepZoom) {\r
-        TransformUtil util = canvas.getSingleItem(TransformUtil.class);\r
-        Rectangle2D controlBounds = canvasBounds.getControlBounds();\r
-        if (controlBounds == null)\r
-            return false;\r
-\r
-        Shape shp = ElementUtils.getElementBoundsOnDiagram(selection);\r
-        if (shp == null)\r
-            return false;\r
-\r
-        Rectangle2D diagramRect = shp.getBounds2D();\r
-        if (keepZoom) {\r
-            double scaleFactor = GeometryUtils.getScale(util.getTransform());\r
-            double cwh = controlBounds.getWidth() / (scaleFactor*2);\r
-            double chh = controlBounds.getHeight() / (scaleFactor*2);\r
-\r
-            AffineTransform view = new AffineTransform();\r
-            view.scale(scaleFactor, scaleFactor);\r
-            view.translate(-diagramRect.getCenterX()+cwh, -diagramRect.getCenterY()+chh);\r
-\r
-            util.setTransform(view);\r
-        } else {\r
-            MarginUtils.Margin margin = MarginUtils.marginOf(40, 0, 0);\r
-            MarginUtils.Margins margins = new MarginUtils.Margins(margin, margin, margin, margin);\r
-            util.fitArea(controlBounds, diagramRect, margins);\r
-        }\r
-        return true;\r
-    }\r
-\r
-    public static Runnable editorActivator(String editorPartId, ResourceArray input, Consumer<IEditorPart> successCallback) {\r
-        return new Runnable() {\r
-            @Override\r
-            public void run() {\r
-                try {\r
-                    // open and activate new editor\r
-                    IEditorPart newPart = WorkbenchUtils.openEditor(editorPartId, new ResourceEditorInput(editorPartId, input));\r
-                    newPart.getSite().getPage().activate(newPart);\r
-                    successCallback.accept(newPart);\r
-                } catch (PartInitException e) {\r
-                    // TODO: handle properly\r
-                    e.printStackTrace();\r
-                }\r
-            }\r
-        };\r
-    }\r
-\r
-    public static Resource getOwnerList(ReadGraph g, Resource listElement) throws DatabaseException {\r
-        return OrderedSetUtils.getSingleOwnerList(g, listElement, DiagramResource.getInstance(g).Composite);\r
-    }\r
-\r
-    @EventHandler(priority = 0)\r
-    public boolean handleDoubleClick(MouseDoubleClickedEvent me) {\r
-\r
-        //System.out.println("LinkBrowsingHandler");\r
-\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
-\r
-                        //System.out.println("LinkBrowsingHandler0");\r
-\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.UpwardLink)) {\r
-\r
-//                            Resource component = viewer.structuralPath.resources[0];\r
-//                            Resource element = graph.getPossibleObject(component, mr.ComponentToElement);\r
-//                            Resource diagram = getOwnerList(graph, element);\r
-//\r
-//                            IEditorPart thisEditor = (IEditorPart) site.getPart();\r
-//                            site.getWorkbenchWindow().getShell().getDisplay().asyncExec(\r
-//                                    editorActivator(thisEditor, viewer.structuralPath.removeFromBeginning(1).prepended(diagram), new Callback<IEditorPart>() {\r
-//                                        @Override\r
-//                                        public void run(IEditorPart part) {\r
-//                                        }\r
-//                                    }));\r
-\r
-                        } else if (graph.isInstanceOf(element, dr.Link)) {\r
-\r
-                            //System.out.println("LinkBrowsingHandler2");\r
-\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
-\r
-                            Resource thisDiagram = getOwnerList(graph, element);\r
-                            if (thisDiagram == null) return;\r
-\r
-                            final Resource target = graph.getPossibleObject(element, dr.HasLinkTarget);\r
-                            if (target == null) return;\r
-\r
-                            final Resource otherDiagram = getOwnerList(graph, target);\r
-                            if (otherDiagram == null)\r
-                                return;\r
-\r
-                            final Resource component = graph.getPossibleObject(target, 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
-//                             PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {\r
-//                                 @Override\r
-//                                 public void run() {\r
-//                                     try {\r
-//                                         WorkbenchUtils.openEditor(site.getId(), new ResourceEditorInput(site.getId(), parentStructuralPath.prepended(diagram, component)));\r
-//                                     } catch (PartInitException e) {\r
-//                                         // TODO Auto-generated catch block\r
-//                                         e.printStackTrace();\r
-//                                     }\r
-//                                 }\r
-//                             });\r
-\r
-//                            IEditorPart thisEditor = (IEditorPart) site.getPart();\r
-//                            ResourceArray input = viewer.structuralPath.prepended(diagram, component);\r
-//                            System.out.println("Browsing link " + input);\r
-//                            site.getWorkbenchWindow().getShell().getDisplay().asyncExec(\r
-//                                    editorActivator(thisEditor, input, new Callback<IEditorPart>() {\r
-//                                        @Override\r
-//                                        public void run(IEditorPart part) {\r
-////                                                                                   final ICanvasContext openedCanvas = (ICanvasContext) part.getAdapter(ICanvasContext.class);\r
-////                                                                                   assert openedCanvas != null;\r
-////                                                                                   IDiagram diagram = (IDiagram) part.getAdapter(IDiagram.class);\r
-////                                                                                   assert diagram != null;\r
-//                                            // Disable automatic-zoom-to-fit\r
-////                                                                                   diagram.removeHint(DiagramHints.KEY_INITIAL_ZOOM_TO_FIT);\r
-////                                                                                   ThreadUtils.asyncExec(openedCanvas.getThreadAccess(),\r
-////                                                                                                   elementSelectorZoomer(openedCanvas, Collections.singleton((Object) target), false));\r
-//                                        }\r
-//                                    }));\r
-\r
-\r
-\r
-//                                                     System.out.println("LinkBrowsingHandler3");\r
-//\r
-//                                                     if (!thisDiagram.equals(otherDiagram)) {\r
-//\r
-//                                                             System.out.println("LinkBrowsingHandler4");\r
-//\r
-//                                                             // Find the structural path\r
-//                                                             Resource ownerComposite = graph.getPossibleObject(otherDiagram, mr.DiagramToComposite);\r
-//                                                             if (ownerComposite == null)\r
-//                                                                     return;\r
-//\r
-//                                                             Collection<ResourceArray> inputs = ComponentUtils.formInputs(graph, ownerComposite);\r
-//\r
-//\r
-//                                                             for (final ResourceArray input : inputs) {\r
-//                                                             }\r
-//                                                     }\r
-//                                                     return;\r
-\r
-                        }\r
-\r
-                        return;\r
-\r
-                    }\r
-\r
-                });\r
-\r
-\r
-            }\r
-\r
-        }\r
-        return false;\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.awt.Shape;
+import java.awt.geom.AffineTransform;
+import java.awt.geom.Rectangle2D;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.function.Consumer;
+
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IWorkbenchPartSite;
+import org.eclipse.ui.PartInitException;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.common.ResourceArray;
+import org.simantics.db.common.request.ReadRequest;
+import org.simantics.db.common.utils.OrderedSetUtils;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.management.ISessionContext;
+import org.simantics.diagram.stubs.DiagramResource;
+import org.simantics.g2d.canvas.ICanvasContext;
+import org.simantics.g2d.canvas.impl.AbstractCanvasParticipant;
+import org.simantics.g2d.canvas.impl.DependencyReflection.Dependency;
+import org.simantics.g2d.diagram.DiagramHints;
+import org.simantics.g2d.diagram.IDiagram;
+import org.simantics.g2d.diagram.handler.DataElementMap;
+import org.simantics.g2d.diagram.participant.Selection;
+import org.simantics.g2d.element.ElementHints;
+import org.simantics.g2d.element.ElementUtils;
+import org.simantics.g2d.element.IElement;
+import org.simantics.g2d.participant.CanvasBoundsParticipant;
+import org.simantics.g2d.participant.TransformUtil;
+import org.simantics.g2d.utils.GeometryUtils;
+import org.simantics.modeling.ModelingResources;
+import org.simantics.modeling.ui.diagramEditor.DiagramViewer;
+import org.simantics.scenegraph.g2d.events.EventHandlerReflection.EventHandler;
+import org.simantics.scenegraph.g2d.events.MouseEvent.MouseDoubleClickedEvent;
+import org.simantics.structural.stubs.StructuralResource2;
+import org.simantics.ui.workbench.ResourceEditorInput;
+import org.simantics.utils.page.MarginUtils;
+import org.simantics.utils.threads.ThreadUtils;
+import org.simantics.utils.ui.ErrorLogger;
+import org.simantics.utils.ui.workbench.WorkbenchUtils;
+
+/**
+ * StructuralBrowsingHandler supports visual browsing into subcomponents through
+ * mouse events.
+ * 
+ * @author Tuukka Lehtonen
+ */
+public class LinkBrowsingHandler extends AbstractCanvasParticipant {
+
+    @Dependency
+    CanvasBoundsParticipant canvasBounds;
+    @Dependency
+    Selection               selection;
+
+    IWorkbenchPartSite      site;
+    DiagramViewer           viewer;
+    ISessionContext         sessionContext;
+
+    public LinkBrowsingHandler(IWorkbenchPartSite site, DiagramViewer viewer, ISessionContext context) {
+
+        assert site != null;
+
+//             System.out.println("LinkBrowsingHandler " + viewer + " " + viewer.structuralPath);
+
+        this.site = site;
+        this.viewer = viewer;
+        this.sessionContext = context;
+
+    }
+
+    public static Runnable editorActivator(final IEditorPart part, final ResourceArray input, final Consumer<IEditorPart> successCallback) {
+        String sourcePartId = part.getSite().getId();
+        return editorActivator(sourcePartId, input, successCallback);
+    }
+
+    public Runnable elementSelectorZoomer(final ICanvasContext canvas, final Collection<Object> elementObjects, final boolean keepZoom) {
+        return new Runnable() {
+            @Override
+            public void run() {
+                IDiagram diagram = canvas.getHintStack().getHint(DiagramHints.KEY_DIAGRAM);
+                assert diagram != null;
+                if (!zoomToSelection(canvas, diagram, selectElement(canvas, diagram, elementObjects), keepZoom)) {
+                    // Reschedule for later.
+                    ThreadUtils.asyncExec(canvas.getThreadAccess(), this);
+                }
+            }
+        };
+    }
+
+    public static Set<IElement> selectElement(final ICanvasContext canvas, final IDiagram diagram, final Collection<Object> elementObjects) {
+        // Select element
+        Set<IElement> selection = new HashSet<IElement>();
+        DataElementMap dataMap = diagram.getDiagramClass().getSingleItem(DataElementMap.class);
+        for (Object obj : elementObjects) {
+            IElement element = dataMap.getElement(diagram, obj);
+            if (element == null) {
+                ErrorLogger.defaultLogWarning("No element to select for object " + obj, new Exception());
+            } else {
+                selection.add(element);
+            }
+        }
+        for (Selection s : canvas.getItemsByClass(Selection.class)) {
+            s.setSelection(0, selection);
+        }
+        return selection;
+    }
+
+    public boolean zoomToSelection(final ICanvasContext canvas, final IDiagram diagram, Set<IElement> selection, boolean keepZoom) {
+        TransformUtil util = canvas.getSingleItem(TransformUtil.class);
+        Rectangle2D controlBounds = canvasBounds.getControlBounds();
+        if (controlBounds == null)
+            return false;
+
+        Shape shp = ElementUtils.getElementBoundsOnDiagram(selection);
+        if (shp == null)
+            return false;
+
+        Rectangle2D diagramRect = shp.getBounds2D();
+        if (keepZoom) {
+            double scaleFactor = GeometryUtils.getScale(util.getTransform());
+            double cwh = controlBounds.getWidth() / (scaleFactor*2);
+            double chh = controlBounds.getHeight() / (scaleFactor*2);
+
+            AffineTransform view = new AffineTransform();
+            view.scale(scaleFactor, scaleFactor);
+            view.translate(-diagramRect.getCenterX()+cwh, -diagramRect.getCenterY()+chh);
+
+            util.setTransform(view);
+        } else {
+            MarginUtils.Margin margin = MarginUtils.marginOf(40, 0, 0);
+            MarginUtils.Margins margins = new MarginUtils.Margins(margin, margin, margin, margin);
+            util.fitArea(controlBounds, diagramRect, margins);
+        }
+        return true;
+    }
+
+    public static Runnable editorActivator(String editorPartId, ResourceArray input, Consumer<IEditorPart> successCallback) {
+        return new Runnable() {
+            @Override
+            public void run() {
+                try {
+                    // open and activate new editor
+                    IEditorPart newPart = WorkbenchUtils.openEditor(editorPartId, new ResourceEditorInput(editorPartId, input));
+                    newPart.getSite().getPage().activate(newPart);
+                    successCallback.accept(newPart);
+                } catch (PartInitException e) {
+                    // TODO: handle properly
+                    e.printStackTrace();
+                }
+            }
+        };
+    }
+
+    public static Resource getOwnerList(ReadGraph g, Resource listElement) throws DatabaseException {
+        return OrderedSetUtils.getSingleOwnerList(g, listElement, DiagramResource.getInstance(g).Composite);
+    }
+
+    @EventHandler(priority = 0)
+    public boolean handleDoubleClick(MouseDoubleClickedEvent me) {
+
+        //System.out.println("LinkBrowsingHandler");
+
+        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 {
+
+                        //System.out.println("LinkBrowsingHandler0");
+
+                        ModelingResources mr = ModelingResources.getInstance(graph);
+                        DiagramResource dr = DiagramResource.getInstance(graph);
+                        StructuralResource2 sr = StructuralResource2.getInstance(graph);
+
+                        if (graph.isInstanceOf(element, dr.UpwardLink)) {
+
+//                            Resource component = viewer.structuralPath.resources[0];
+//                            Resource element = graph.getPossibleObject(component, mr.ComponentToElement);
+//                            Resource diagram = getOwnerList(graph, element);
+//
+//                            IEditorPart thisEditor = (IEditorPart) site.getPart();
+//                            site.getWorkbenchWindow().getShell().getDisplay().asyncExec(
+//                                    editorActivator(thisEditor, viewer.structuralPath.removeFromBeginning(1).prepended(diagram), new Callback<IEditorPart>() {
+//                                        @Override
+//                                        public void run(IEditorPart part) {
+//                                        }
+//                                    }));
+
+                        } else if (graph.isInstanceOf(element, dr.Link)) {
+
+                            //System.out.println("LinkBrowsingHandler2");
+
+//                                                     ContextMap parameters = new ContextMap();
+//                                                     parameters.put(ModelingOperationConstants.WORKBENCH_WINDOW, site.getWorkbenchWindow());
+//                                                     parameters.put(ModelingOperationConstants.WORKBENCH_PART, site.getPart());
+//                                                     parameters.put(IOperation.SUBJECT, element);
+
+                            Resource thisDiagram = getOwnerList(graph, element);
+                            if (thisDiagram == null) return;
+
+                            final Resource target = graph.getPossibleObject(element, dr.HasLinkTarget);
+                            if (target == null) return;
+
+                            final Resource otherDiagram = getOwnerList(graph, target);
+                            if (otherDiagram == null)
+                                return;
+
+                            final Resource component = graph.getPossibleObject(target, 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;
+
+//                             PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
+//                                 @Override
+//                                 public void run() {
+//                                     try {
+//                                         WorkbenchUtils.openEditor(site.getId(), new ResourceEditorInput(site.getId(), parentStructuralPath.prepended(diagram, component)));
+//                                     } catch (PartInitException e) {
+//                                         // TODO Auto-generated catch block
+//                                         e.printStackTrace();
+//                                     }
+//                                 }
+//                             });
+
+//                            IEditorPart thisEditor = (IEditorPart) site.getPart();
+//                            ResourceArray input = viewer.structuralPath.prepended(diagram, component);
+//                            System.out.println("Browsing link " + input);
+//                            site.getWorkbenchWindow().getShell().getDisplay().asyncExec(
+//                                    editorActivator(thisEditor, input, new Callback<IEditorPart>() {
+//                                        @Override
+//                                        public void run(IEditorPart part) {
+////                                                                                   final ICanvasContext openedCanvas = (ICanvasContext) part.getAdapter(ICanvasContext.class);
+////                                                                                   assert openedCanvas != null;
+////                                                                                   IDiagram diagram = (IDiagram) part.getAdapter(IDiagram.class);
+////                                                                                   assert diagram != null;
+//                                            // Disable automatic-zoom-to-fit
+////                                                                                   diagram.removeHint(DiagramHints.KEY_INITIAL_ZOOM_TO_FIT);
+////                                                                                   ThreadUtils.asyncExec(openedCanvas.getThreadAccess(),
+////                                                                                                   elementSelectorZoomer(openedCanvas, Collections.singleton((Object) target), false));
+//                                        }
+//                                    }));
+
+
+
+//                                                     System.out.println("LinkBrowsingHandler3");
+//
+//                                                     if (!thisDiagram.equals(otherDiagram)) {
+//
+//                                                             System.out.println("LinkBrowsingHandler4");
+//
+//                                                             // Find the structural path
+//                                                             Resource ownerComposite = graph.getPossibleObject(otherDiagram, mr.DiagramToComposite);
+//                                                             if (ownerComposite == null)
+//                                                                     return;
+//
+//                                                             Collection<ResourceArray> inputs = ComponentUtils.formInputs(graph, ownerComposite);
+//
+//
+//                                                             for (final ResourceArray input : inputs) {
+//                                                             }
+//                                                     }
+//                                                     return;
+
+                        }
+
+                        return;
+
+                    }
+
+                });
+
+
+            }
+
+        }
+        return false;
+    }
+
 }
\ No newline at end of file