X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.modeling.ui%2Fsrc%2Forg%2Fsimantics%2Fmodeling%2Fui%2FdiagramEditor%2Fhandlers%2FHeadlessStructuralBrowsingHandler.java;h=a03d8a9b27da0984c0b9026538c3187abc56466e;hb=f4b65f5afe961edc8d5e1696f32c8efbb8ea48f6;hp=ff17e21266f7a8d2386d31f57cd06cf3abce8169;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagramEditor/handlers/HeadlessStructuralBrowsingHandler.java b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagramEditor/handlers/HeadlessStructuralBrowsingHandler.java index ff17e2126..a03d8a9b2 100644 --- a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagramEditor/handlers/HeadlessStructuralBrowsingHandler.java +++ b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagramEditor/handlers/HeadlessStructuralBrowsingHandler.java @@ -1,115 +1,115 @@ -/******************************************************************************* - * 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 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; - } - -} +/******************************************************************************* + * 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 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; + } + +}