diff options
| author | Laurent Fasani | 2017-05-30 15:21:29 +0000 |
|---|---|---|
| committer | Laurent Fasani | 2017-07-07 15:55:44 +0000 |
| commit | 9ae2852bc4c4dd63d3cb2e5f608930399f515e65 (patch) | |
| tree | 578cca662a59a83b81c56b6d13a4f16d226e6294 | |
| parent | 07e9ce2a6fc7f5dd72959a1f1b3a6d95d3c8bcdb (diff) | |
| download | org.eclipse.sirius-9ae2852bc4c4dd63d3cb2e5f608930399f515e65.tar.gz org.eclipse.sirius-9ae2852bc4c4dd63d3cb2e5f608930399f515e65.tar.xz org.eclipse.sirius-9ae2852bc4c4dd63d3cb2e5f608930399f515e65.zip | |
[516669] Make OpenRepresentation from ctx menu work
* Adapt the code to rely on the DRepDescriptor(instead of
DRepresentation that may not be loaded) to display "Navigate To"
decoration or to display "Open"contextual menus.
Bug: 516669
Change-Id: I039d6b36e1873c3478db405519154d4d1f6de77e
Signed-off-by: Laurent Fasani <laurent.fasani@obeo.fr>
6 files changed, 127 insertions, 120 deletions
diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/decoration/SubDiagramDecorationDescriptorProvider.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/decoration/SubDiagramDecorationDescriptorProvider.java index bbf87b5b21..4f9dfb39d7 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/decoration/SubDiagramDecorationDescriptorProvider.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/decoration/SubDiagramDecorationDescriptorProvider.java @@ -15,6 +15,7 @@ import java.util.Arrays; import java.util.Collection; import java.util.Iterator; import java.util.List; +import java.util.Objects; import java.util.Optional; import org.eclipse.emf.ecore.EObject; @@ -27,6 +28,7 @@ import org.eclipse.sirius.business.api.componentization.ViewpointRegistry; import org.eclipse.sirius.business.api.dialect.DialectManager; import org.eclipse.sirius.business.api.logger.RuntimeLoggerManager; import org.eclipse.sirius.business.api.query.DRepresentationElementQuery; +import org.eclipse.sirius.business.api.query.DRepresentationQuery; import org.eclipse.sirius.business.api.session.Session; import org.eclipse.sirius.common.tools.api.interpreter.EvaluationException; import org.eclipse.sirius.common.tools.api.interpreter.IInterpreter; @@ -42,6 +44,7 @@ import org.eclipse.sirius.diagram.ui.tools.api.decoration.SiriusDecorationDescri import org.eclipse.sirius.diagram.ui.tools.api.figure.WorkspaceImageFigure; import org.eclipse.sirius.diagram.ui.tools.api.image.DiagramImagesPath; import org.eclipse.sirius.viewpoint.DRepresentation; +import org.eclipse.sirius.viewpoint.DRepresentationDescriptor; import org.eclipse.sirius.viewpoint.DRepresentationElement; import org.eclipse.sirius.viewpoint.SiriusPlugin; import org.eclipse.sirius.viewpoint.description.DecorationDistributionDirection; @@ -52,10 +55,6 @@ import org.eclipse.sirius.viewpoint.description.tool.RepresentationNavigationDes import org.eclipse.sirius.viewpoint.description.tool.ToolPackage; import org.eclipse.swt.graphics.Image; -import com.google.common.base.Predicate; -import com.google.common.base.Predicates; -import com.google.common.collect.Iterables; - /** * This {@link SiriusDecorationDescriptorProvider} provides a decoration on the bottom right corner when the element * provides a detail diagram. @@ -105,11 +104,7 @@ public class SubDiagramDecorationDescriptorProvider implements SiriusDecorationD boolean shouldHaveSubDiagramDecorator = false; if (target != null && target.eResource() != null) { if (session != null && !parentHasSameSemanticElement(node)) { - // Does the target element has any representation on it? Exclude - // the current representation itself to avoid redundant markers. - DRepresentation representation = new DRepresentationElementQuery(node).getParentRepresentation(); - Predicate<DRepresentation> otherReperesentation = Predicates.not(Predicates.equalTo(representation)); - shouldHaveSubDiagramDecorator = Iterables.any(DialectManager.INSTANCE.getRepresentations(target, session), otherReperesentation); + shouldHaveSubDiagramDecorator = checkExistingRepresentationDescriptors(node, session); if (node.getMapping() != null && !shouldHaveSubDiagramDecorator) { shouldHaveSubDiagramDecorator = checkRepresentationNavigationDescriptions(node, session); } @@ -119,6 +114,22 @@ public class SubDiagramDecorationDescriptorProvider implements SiriusDecorationD } /** + * Check if an existing {@link DRepresentationDescriptor} as the node target element as target element. + * + * @return the value + */ + private boolean checkExistingRepresentationDescriptors(DRepresentationElement node, Session session) { + // Does the target element has any representation on it? Exclude + // the current representation itself to avoid redundant markers. + EObject semanticObject = node.getTarget(); + DRepresentation representation = new DRepresentationElementQuery(node).getParentRepresentation(); + DRepresentationDescriptor representationDescriptor = new DRepresentationQuery(representation).getRepresentationDescriptor(); + + return DialectManager.INSTANCE.getAllRepresentationDescriptors(session).stream().filter(repDesc -> !Objects.equals(repDesc, representationDescriptor)) + .filter(repDesc -> Objects.equals(repDesc.getTarget(), semanticObject)).count() > 0; + } + + /** * Tests whether the specified node has the same semantic element as its parent. */ private boolean parentHasSameSemanticElement(DRepresentationElement element) { @@ -126,13 +137,16 @@ public class SubDiagramDecorationDescriptorProvider implements SiriusDecorationD } private boolean checkRepresentationNavigationDescriptions(DRepresentationElement element, Session session) { - + boolean isAnyRepresentation = false; EObject target = element.getTarget(); if (session.isOpen()) { IInterpreter interpreter = session.getInterpreter(); - for (RepresentationNavigationDescription navDesc : element.getMapping().getNavigationDescriptions()) { + Iterator<RepresentationNavigationDescription> navDescIterator = element.getMapping().getNavigationDescriptions().iterator(); + while (!isAnyRepresentation && navDescIterator.hasNext()) { + RepresentationNavigationDescription navDesc = navDescIterator.next(); + if (isFromActiveViewpoint(navDesc.getRepresentationDescription(), session)) { interpreter.setVariable(navDesc.getContainerVariable().getName(), target); interpreter.setVariable(navDesc.getContainerViewVariable().getName(), element); @@ -147,9 +161,7 @@ public class SubDiagramDecorationDescriptorProvider implements SiriusDecorationD } if (precondition) { - if (checkRepresentationNavigationDescription(interpreter, navDesc, element, session)) { - return true; - } + isAnyRepresentation = checkRepresentationNavigationDescription(interpreter, navDesc, element, session); } interpreter.unSetVariable(navDesc.getContainerVariable().getName()); @@ -157,7 +169,7 @@ public class SubDiagramDecorationDescriptorProvider implements SiriusDecorationD } } } - return false; + return isAnyRepresentation; } private boolean isFromActiveViewpoint(final RepresentationDescription description, Session session) { @@ -166,28 +178,20 @@ public class SubDiagramDecorationDescriptorProvider implements SiriusDecorationD } private boolean checkRepresentationNavigationDescription(IInterpreter interpreter, RepresentationNavigationDescription navDesc, DRepresentationElement element, Session session) { - Collection<EObject> candidates = null; + Collection<EObject> candidates = new ArrayList<EObject>(); if (!StringUtil.isEmpty(navDesc.getBrowseExpression())) { - candidates = RuntimeLoggerManager.INSTANCE.decorate(interpreter).evaluateCollection(element.getTarget(), navDesc, - ToolPackage.eINSTANCE.getRepresentationNavigationDescription_BrowseExpression()); + candidates.addAll(RuntimeLoggerManager.INSTANCE.decorate(interpreter).evaluateCollection(element.getTarget(), navDesc, + ToolPackage.eINSTANCE.getRepresentationNavigationDescription_BrowseExpression())); } else { - candidates = new ArrayList<EObject>(); Iterator<EObject> it = SiriusPlugin.getDefault().getModelAccessorRegistry().getModelAccessor(element.getTarget()).eAllContents(element.getTarget()); while (it.hasNext()) { candidates.add(it.next()); } } - for (EObject candidate : candidates) { - Collection<DRepresentation> representations = DialectManager.INSTANCE.getRepresentations(candidate, session); - for (DRepresentation representation : representations) { - if (navDesc.getRepresentationDescription() != null && navDesc.getRepresentationDescription().equals(DialectManager.INSTANCE.getDescription(representation))) { - return true; - } - } - } - - return false; + return DialectManager.INSTANCE.getAllRepresentationDescriptors(session).stream().filter(repDesc -> candidates.contains(repDesc.getTarget())).filter(repDesc -> { + return repDesc.getDescription().equals(navDesc.getRepresentationDescription()); + }).count() > 0; } @Override diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/menu/OpenMenuContribution.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/menu/OpenMenuContribution.java index c855c5aaf3..7dabe717e1 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/menu/OpenMenuContribution.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/menu/OpenMenuContribution.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2015 THALES GLOBAL SERVICES and others. + * Copyright (c) 2007, 2017 THALES GLOBAL SERVICES and others. * 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 @@ -10,13 +10,12 @@ *******************************************************************************/ package org.eclipse.sirius.diagram.ui.tools.internal.menu; -import java.util.Collection; import java.util.HashMap; import java.util.Map; +import java.util.Objects; import org.eclipse.emf.common.notify.AdapterFactory; import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.util.EcoreUtil; import org.eclipse.emf.transaction.TransactionalEditingDomain; import org.eclipse.emf.transaction.util.TransactionUtil; import org.eclipse.gef.EditPart; @@ -32,6 +31,7 @@ import org.eclipse.sirius.business.api.componentization.ViewpointRegistry; import org.eclipse.sirius.business.api.dialect.DialectManager; import org.eclipse.sirius.business.api.helper.task.InitInterpreterVariablesTask; import org.eclipse.sirius.business.api.logger.RuntimeLoggerManager; +import org.eclipse.sirius.business.api.query.DRepresentationQuery; import org.eclipse.sirius.business.api.session.Session; import org.eclipse.sirius.business.api.session.SessionManager; import org.eclipse.sirius.common.tools.api.interpreter.EvaluationException; @@ -48,20 +48,21 @@ import org.eclipse.sirius.ext.base.Option; import org.eclipse.sirius.ui.business.api.dialect.DialectUIManager; import org.eclipse.sirius.ui.tools.internal.editor.MenuHelper; import org.eclipse.sirius.viewpoint.DRepresentation; +import org.eclipse.sirius.viewpoint.DRepresentationDescriptor; import org.eclipse.sirius.viewpoint.DRepresentationElement; import org.eclipse.sirius.viewpoint.DSemanticDecorator; import org.eclipse.sirius.viewpoint.SiriusPlugin; +import org.eclipse.sirius.viewpoint.description.AbstractVariable; import org.eclipse.sirius.viewpoint.description.RepresentationDescription; import org.eclipse.sirius.viewpoint.description.Viewpoint; -import org.eclipse.sirius.viewpoint.description.AbstractVariable; import org.eclipse.sirius.viewpoint.description.tool.RepresentationNavigationDescription; import org.eclipse.sirius.viewpoint.description.tool.ToolPackage; import org.eclipse.ui.IActionBars; import org.eclipse.ui.IWorkbenchPart; /** - * This menu contribution add a "open" menu in the DDiagram diagram editor. This - * menu provides navigation links to Model elements or Source files. + * This menu contribution add a "open" menu in the DDiagram diagram editor. This menu provides navigation links to Model + * elements or Source files. * * @author cbrun * @@ -124,12 +125,15 @@ public class OpenMenuContribution implements IContributionItemProvider { } contributeToPopupMenu(openMenuManager, null); final TransactionalEditingDomain transDomain = TransactionUtil.getEditingDomain(designerDiag); - final Collection<DRepresentation> otherRepresentations = DialectManager.INSTANCE.getRepresentations(semantic, session); - for (final DRepresentation representation : otherRepresentations) { - if (!EcoreUtil.equals(designerDiag, representation) && isFromActiveViewpoint(session, representation)) { - openMenuManager.add(MenuHelper.buildOpenRepresentationAction(session, representation, getAdapterFactory())); - } - } + + // build open representation actions + + DRepresentationDescriptor representationDescriptor = new DRepresentationQuery(designerDiag).getRepresentationDescriptor(); + DialectManager.INSTANCE.getAllRepresentationDescriptors(session).stream().filter(rd -> !Objects.equals(rd, representationDescriptor)) + .filter(repDesc -> Objects.equals(repDesc.getTarget(), semantic)).filter(repDesc -> isFromActiveViewpoint(session, repDesc.getDescription())).forEach(repDesc -> { + openMenuManager.add(MenuHelper.buildOpenRepresentationAction(session, repDesc, getAdapterFactory())); + }); + if (designerObj instanceof DRepresentationElement) { buildOpenableRepresentationsMenu(openMenuManager, designerObj, session, editpart, transDomain); } @@ -138,15 +142,14 @@ public class OpenMenuContribution implements IContributionItemProvider { } /** - * Tests whether a representation description belongs to a viewpoint which - * is currently active in the session. + * Tests whether a representation description belongs to a viewpoint which is currently active in the session. * * @param session * the current session. * @param representationDescription * the representation description to check. - * @return <code>true</code> if the representation description belongs to a - * viewpoint which is currently active in the session. + * @return <code>true</code> if the representation description belongs to a viewpoint which is currently active in + * the session. */ private boolean isFromActiveViewpoint(final Session session, final RepresentationDescription representationDescription) { final Viewpoint vp = ViewpointRegistry.getInstance().getViewpoint(representationDescription); @@ -154,15 +157,13 @@ public class OpenMenuContribution implements IContributionItemProvider { } /** - * Tests whether a representation belongs to a viewpoint which is currently - * active in the session. + * Tests whether a representation belongs to a viewpoint which is currently active in the session. * * @param session * the current session. * @param representation * the representation to check. - * @return <code>true</code> if the representation belongs to a viewpoint - * which is currently active in the session. + * @return <code>true</code> if the representation belongs to a viewpoint which is currently active in the session. */ private boolean isFromActiveViewpoint(final Session session, final DRepresentation representation) { final RepresentationDescription description = DialectManager.INSTANCE.getDescription(representation); diff --git a/plugins/org.eclipse.sirius.table.ui/src/org/eclipse/sirius/table/ui/tools/internal/editor/DTableMenuListener.java b/plugins/org.eclipse.sirius.table.ui/src/org/eclipse/sirius/table/ui/tools/internal/editor/DTableMenuListener.java index 2f622d2353..2140af7518 100644 --- a/plugins/org.eclipse.sirius.table.ui/src/org/eclipse/sirius/table/ui/tools/internal/editor/DTableMenuListener.java +++ b/plugins/org.eclipse.sirius.table.ui/src/org/eclipse/sirius/table/ui/tools/internal/editor/DTableMenuListener.java @@ -14,11 +14,11 @@ import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Objects; import org.eclipse.core.commands.common.CommandException; import org.eclipse.emf.common.notify.AdapterFactory; import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.util.EcoreUtil; import org.eclipse.jface.action.Action; import org.eclipse.jface.action.IAction; import org.eclipse.jface.action.IMenuListener; @@ -30,6 +30,7 @@ import org.eclipse.sirius.business.api.componentization.ViewpointRegistry; import org.eclipse.sirius.business.api.dialect.DialectManager; import org.eclipse.sirius.business.api.helper.task.InitInterpreterVariablesTask; import org.eclipse.sirius.business.api.logger.RuntimeLoggerManager; +import org.eclipse.sirius.business.api.query.DRepresentationQuery; import org.eclipse.sirius.business.api.session.Session; import org.eclipse.sirius.business.api.session.SessionManager; import org.eclipse.sirius.common.tools.api.interpreter.EvaluationException; @@ -67,6 +68,7 @@ import org.eclipse.sirius.table.ui.tools.internal.editor.action.SortLinesByColum import org.eclipse.sirius.ui.business.api.dialect.DialectUIManager; import org.eclipse.sirius.ui.tools.internal.editor.MenuHelper; import org.eclipse.sirius.viewpoint.DRepresentation; +import org.eclipse.sirius.viewpoint.DRepresentationDescriptor; import org.eclipse.sirius.viewpoint.DRepresentationElement; import org.eclipse.sirius.viewpoint.DSemanticDecorator; import org.eclipse.sirius.viewpoint.SiriusPlugin; @@ -317,14 +319,15 @@ public class DTableMenuListener implements IMenuListener { final EObject semanticElement = decorator.getTarget(); final Session session = SessionManager.INSTANCE.getSession(semanticElement); if (session != null) { - final Collection<DRepresentation> otherRepresentations = DialectManager.INSTANCE.getRepresentations(semanticElement, session); - for (final DRepresentation representation : otherRepresentations) { - if (!EcoreUtil.equals(dTable, representation) && isFromActiveViewpoint(session, representation)) { - openRepresentation.setVisible(true); - ((IMenuManager) openRepresentation.getInnerItem()).appendToGroup(EXISTING_REPRESENTATION_GROUP_SEPARATOR, - MenuHelper.buildOpenRepresentationAction(session, representation, adapterFactory)); - } - } + // build open representation actions + DRepresentationDescriptor representationDescriptor = new DRepresentationQuery(dTable).getRepresentationDescriptor(); + DialectManager.INSTANCE.getAllRepresentationDescriptors(session).stream().filter(rd -> !Objects.equals(rd, representationDescriptor)) + .filter(repDesc -> Objects.equals(repDesc.getTarget(), semanticElement)).filter(repDesc -> isFromActiveViewpoint(session, repDesc.getDescription())).forEach(repDesc -> { + openRepresentation.setVisible(true); + ((IMenuManager) openRepresentation.getInnerItem()).appendToGroup(EXISTING_REPRESENTATION_GROUP_SEPARATOR, + MenuHelper.buildOpenRepresentationAction(session, repDesc, adapterFactory)); + }); + if (decorator instanceof DRepresentationElement) { if (buildOpenRepresentationsMenu((IMenuManager) openRepresentation.getInnerItem(), (DRepresentationElement) decorator, session)) { // If at least one navigable representation menu diff --git a/plugins/org.eclipse.sirius.tree.ui/src/org/eclipse/sirius/tree/ui/tools/internal/editor/DTreeMenuListener.java b/plugins/org.eclipse.sirius.tree.ui/src/org/eclipse/sirius/tree/ui/tools/internal/editor/DTreeMenuListener.java index eb6836ec23..5b14682166 100644 --- a/plugins/org.eclipse.sirius.tree.ui/src/org/eclipse/sirius/tree/ui/tools/internal/editor/DTreeMenuListener.java +++ b/plugins/org.eclipse.sirius.tree.ui/src/org/eclipse/sirius/tree/ui/tools/internal/editor/DTreeMenuListener.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010, 2016 THALES GLOBAL SERVICES and others. + * Copyright (c) 2010, 2017 THALES GLOBAL SERVICES and others. * 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 @@ -14,10 +14,10 @@ import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Objects; import org.eclipse.emf.common.notify.AdapterFactory; import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.util.EcoreUtil; import org.eclipse.jface.action.IMenuListener; import org.eclipse.jface.action.IMenuManager; import org.eclipse.jface.action.MenuManager; @@ -27,6 +27,7 @@ import org.eclipse.sirius.business.api.componentization.ViewpointRegistry; import org.eclipse.sirius.business.api.dialect.DialectManager; import org.eclipse.sirius.business.api.helper.task.InitInterpreterVariablesTask; import org.eclipse.sirius.business.api.logger.RuntimeLoggerManager; +import org.eclipse.sirius.business.api.query.DRepresentationQuery; import org.eclipse.sirius.business.api.session.Session; import org.eclipse.sirius.business.api.session.SessionManager; import org.eclipse.sirius.common.tools.api.interpreter.EvaluationException; @@ -48,6 +49,7 @@ import org.eclipse.sirius.tree.ui.tools.internal.editor.provider.TreePopupMenuCo import org.eclipse.sirius.ui.business.api.dialect.DialectUIManager; import org.eclipse.sirius.ui.tools.internal.editor.MenuHelper; import org.eclipse.sirius.viewpoint.DRepresentation; +import org.eclipse.sirius.viewpoint.DRepresentationDescriptor; import org.eclipse.sirius.viewpoint.DRepresentationElement; import org.eclipse.sirius.viewpoint.DSemanticDecorator; import org.eclipse.sirius.viewpoint.SiriusPlugin; @@ -111,12 +113,9 @@ public class DTreeMenuListener implements IMenuListener { * @param treeViewManager * The manager of the TreeView * @param mappingToCreateActions - * A map which associates {@link TreeMapping} with the - * corresponding list of {@link AbstractToolAction} ( - * {@link org.eclipse.sirius.tree.ui.tools.internal.editor.action.CreateLineAction} - * or - * {@link org.eclipse.sirius.tree.ui.tools.internal.editor.action.CreateTargetColumnAction} - * ) + * A map which associates {@link TreeMapping} with the corresponding list of {@link AbstractToolAction} ( + * {@link org.eclipse.sirius.tree.ui.tools.internal.editor.action.CreateLineAction} or + * {@link org.eclipse.sirius.tree.ui.tools.internal.editor.action.CreateTargetColumnAction} ) * @param createActionsForTree * A list of the actions for create lines under the tree. */ @@ -238,13 +237,14 @@ public class DTreeMenuListener implements IMenuListener { final EObject semanticElement = decorator.getTarget(); final Session session = SessionManager.INSTANCE.getSession(semanticElement); if (session != null) { - final Collection<DRepresentation> otherRepresentations = DialectManager.INSTANCE.getRepresentations(semanticElement, session); - for (final DRepresentation representation : otherRepresentations) { - if (!EcoreUtil.equals(dTree, representation) && isFromActiveViewpoint(session, representation)) { - openItem.setVisible(true); - ((IMenuManager) openItem.getInnerItem()).appendToGroup(EXISTING_REPRESENTATION_GROUP_SEPARATOR, MenuHelper.buildOpenRepresentationAction(session, representation, adapterFactory)); - } - } + // build open representation actions + DRepresentationDescriptor representationDescriptor = new DRepresentationQuery(dTree).getRepresentationDescriptor(); + DialectManager.INSTANCE.getAllRepresentationDescriptors(session).stream().filter(rd -> !Objects.equals(rd, representationDescriptor)) + .filter(repDesc -> Objects.equals(repDesc.getTarget(), semanticElement)).filter(repDesc -> isFromActiveViewpoint(session, repDesc.getDescription())).forEach(repDesc -> { + openItem.setVisible(true); + ((IMenuManager) openItem.getInnerItem()).appendToGroup(EXISTING_REPRESENTATION_GROUP_SEPARATOR, MenuHelper.buildOpenRepresentationAction(session, repDesc, adapterFactory)); + }); + if (decorator instanceof DRepresentationElement) { if (buildOpenRepresentationsMenu((IMenuManager) openItem.getInnerItem(), (DRepresentationElement) decorator, session)) { // if at least one navigable representation menu @@ -378,15 +378,14 @@ public class DTreeMenuListener implements IMenuListener { } /** - * Tests whether a representation description belongs to a viewpoint which - * is currently active in the session. + * Tests whether a representation description belongs to a viewpoint which is currently active in the session. * * @param session * the current session. * @param representationDescription * the representation description to check. - * @return <code>true</code> if the representation description belongs to a - * viewpoint which is currently active in the session. + * @return <code>true</code> if the representation description belongs to a viewpoint which is currently active in + * the session. */ private boolean isFromActiveViewpoint(final Session session, final RepresentationDescription representationDescription) { final Viewpoint vp = ViewpointRegistry.getInstance().getViewpoint(representationDescription); @@ -394,15 +393,13 @@ public class DTreeMenuListener implements IMenuListener { } /** - * Tests whether a representation belongs to a viewpoint which is currently - * active in the session. + * Tests whether a representation belongs to a viewpoint which is currently active in the session. * * @param session * the current session. * @param representation * the representation to check. - * @return <code>true</code> if the representation belongs to a viewpoint - * which is currently active in the session. + * @return <code>true</code> if the representation belongs to a viewpoint which is currently active in the session. */ private boolean isFromActiveViewpoint(final Session session, final DRepresentation representation) { final RepresentationDescription description = DialectManager.INSTANCE.getDescription(representation); diff --git a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/actions/session/OpenRepresentationAction.java b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/actions/session/OpenRepresentationAction.java index 48bf81f386..de2ef147e0 100644 --- a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/actions/session/OpenRepresentationAction.java +++ b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/actions/session/OpenRepresentationAction.java @@ -16,10 +16,11 @@ import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.sirius.business.api.session.Session; import org.eclipse.sirius.ui.tools.internal.editor.NavigateToCommand; import org.eclipse.sirius.viewpoint.DRepresentation; +import org.eclipse.sirius.viewpoint.DRepresentationDescriptor; public final class OpenRepresentationAction extends Action { - private final DRepresentation representation; + private final DRepresentationDescriptor representationDescriptor; private final Session session; @@ -32,17 +33,15 @@ public final class OpenRepresentationAction extends Action { * the action's text, or <code>null</code> if there is no text * @param image * the action's image, or <code>null</code> if there is no image - * @param representation - * the representation to open. Caller has to check this is not a - * dangling representation, see {@link - * org.eclipse.sirius.business.api.query.DRepresentationQuery. - * isDanglingRepresentation()}. + * @param repDesc + * the representation to open. Caller has to check this is not a dangling representation, see + * {@link org.eclipse.sirius.business.api.query.DRepresentationQuery. isDanglingRepresentation()}. * @param session * the session in which to open it. */ - public OpenRepresentationAction(String text, ImageDescriptor image, DRepresentation representation, Session session) { + public OpenRepresentationAction(String text, ImageDescriptor image, DRepresentationDescriptor repDesc, Session session) { super(text, image); - this.representation = representation; + this.representationDescriptor = repDesc; this.session = session; this.editingDomain = session.getTransactionalEditingDomain(); } @@ -50,14 +49,14 @@ public final class OpenRepresentationAction extends Action { /** * Constructor. * - * @param representation - * the representation to open. + * @param repDesc + * the representationDescriptor to open. * @param session * the session in which to open it. */ - public OpenRepresentationAction(DRepresentation representation, Session session) { + public OpenRepresentationAction(DRepresentationDescriptor repDesc, Session session) { super(); - this.representation = representation; + this.representationDescriptor = repDesc; this.session = session; this.editingDomain = session.getTransactionalEditingDomain(); } @@ -67,7 +66,7 @@ public final class OpenRepresentationAction extends Action { */ @Override public void run() { - super.run(); + DRepresentation representation = representationDescriptor.getRepresentation(); editingDomain.getCommandStack().execute(new NavigateToCommand(session, representation)); } } diff --git a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/editor/MenuHelper.java b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/editor/MenuHelper.java index 49a4e19f15..14f84a7a55 100644 --- a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/editor/MenuHelper.java +++ b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/editor/MenuHelper.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2014, 2015 Obeo. + * Copyright (c) 2014, 2017 Obeo. * 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 @@ -11,6 +11,9 @@ package org.eclipse.sirius.ui.tools.internal.editor; import java.util.Collection; +import java.util.List; +import java.util.Objects; +import java.util.stream.Collectors; import org.eclipse.emf.common.notify.AdapterFactory; import org.eclipse.emf.ecore.EAttribute; @@ -32,7 +35,7 @@ import org.eclipse.sirius.common.ui.SiriusTransPlugin; import org.eclipse.sirius.ecore.extender.business.api.accessor.ModelAccessor; import org.eclipse.sirius.ui.tools.api.image.ImagesPath; import org.eclipse.sirius.ui.tools.internal.actions.session.OpenRepresentationAction; -import org.eclipse.sirius.viewpoint.DRepresentation; +import org.eclipse.sirius.viewpoint.DRepresentationDescriptor; import org.eclipse.sirius.viewpoint.DRepresentationElement; import org.eclipse.sirius.viewpoint.SiriusPlugin; import org.eclipse.sirius.viewpoint.description.RepresentationDescription; @@ -61,8 +64,8 @@ public final class MenuHelper { } /** - * Build the menus and corresponding actions for this <code>element</code> - * and this navigation description <code>navDesc</code>. + * Build the menus and corresponding actions for this <code>element</code> and this navigation description + * <code>navDesc</code>. * * @param openMenu * The menu manager in which to add the actions @@ -83,11 +86,14 @@ public final class MenuHelper { boolean atLeastOneRepresentationActionsWasCreated = false; Collection<EObject> candidates = MenuHelper.findCandidates(element, navDesc, interpreter); for (EObject candidate : candidates) { - Collection<DRepresentation> representations = DialectManager.INSTANCE.getRepresentations(candidate, session); - for (DRepresentation representation : representations) { - if (navDesc.getRepresentationDescription() != null && navDesc.getRepresentationDescription().equals(DialectManager.INSTANCE.getDescription(representation))) { - interpreter.setVariable(navDesc.getRepresentationNameVariable().getName(), representation.getName()); - String label = new StringBuffer().append(new IdentifiedElementQuery(navDesc).getLabel()).append(representation.getName()).toString(); + // build open representation actions + List<DRepresentationDescriptor> repDescs = DialectManager.INSTANCE.getAllRepresentationDescriptors(session).stream().filter(repDesc -> Objects.equals(repDesc.getTarget(), candidate)) + .collect(Collectors.toList()); + + for (DRepresentationDescriptor repDesc : repDescs) { + if (navDesc.getRepresentationDescription() != null && navDesc.getRepresentationDescription().equals(repDesc.getDescription())) { + interpreter.setVariable(navDesc.getRepresentationNameVariable().getName(), repDesc.getName()); + String label = new StringBuffer().append(new IdentifiedElementQuery(navDesc).getLabel()).append(repDesc.getName()).toString(); if (!StringUtil.isEmpty(navDesc.getNavigationNameExpression())) { try { label = interpreter.evaluateString(element.getTarget(), navDesc.getNavigationNameExpression()); @@ -95,7 +101,7 @@ public final class MenuHelper { RuntimeLoggerManager.INSTANCE.error(navDesc, ToolPackage.eINSTANCE.getRepresentationNavigationDescription_NavigationNameExpression(), e); } } - openMenu.appendToGroup(MenuHelper.OPEN_REPRESENTATION_GROUP_SEPARATOR, MenuHelper.buildOpenRepresentationAction(session, representation, label, adapterFactory)); + openMenu.appendToGroup(MenuHelper.OPEN_REPRESENTATION_GROUP_SEPARATOR, MenuHelper.buildOpenRepresentationAction(session, repDesc, label, adapterFactory)); atLeastOneRepresentationActionsWasCreated = true; } } @@ -104,18 +110,15 @@ public final class MenuHelper { } /** - * Computes all the candidates for navigation from a starting element using - * the specified navigation description. + * Computes all the candidates for navigation from a starting element using the specified navigation description. * * @param element * the starting point. * @param navDesc * the navigation description element. * @param interpreter - * the interpreter to use to compute the expressions in the - * navigation description element. - * @return the semantic elements to which it is valid to navigate to from - * the stating element. + * the interpreter to use to compute the expressions in the navigation description element. + * @return the semantic elements to which it is valid to navigate to from the stating element. */ private static Collection<EObject> findCandidates(final DRepresentationElement element, final RepresentationNavigationDescription navDesc, final IInterpreter interpreter) { final Collection<EObject> candidates; @@ -135,36 +138,36 @@ public final class MenuHelper { * * @param session * The current session. - * @param representation - * The representation to open + * @param repDesc + * The representationDescriptor to open * @param adapterFactory * The adapter factory * @return The new action to open this <code>representation</code>. */ - public static IAction buildOpenRepresentationAction(final Session session, final DRepresentation representation, final AdapterFactory adapterFactory) { - String representationName = representation.getName(); + public static IAction buildOpenRepresentationAction(final Session session, final DRepresentationDescriptor repDesc, final AdapterFactory adapterFactory) { + String representationName = repDesc.getName(); if (StringUtil.isEmpty(representationName)) { representationName = Messages.MenuHelper_anonymousRepresentation; - RepresentationDescription representationDescription = DialectManager.INSTANCE.getDescription(representation); + RepresentationDescription representationDescription = repDesc.getDescription(); if (representationDescription != null) { representationName += " " + new IdentifiedElementQuery(representationDescription).getLabel(); //$NON-NLS-1$ } } - return MenuHelper.buildOpenRepresentationAction(session, representation, representationName, adapterFactory); + return MenuHelper.buildOpenRepresentationAction(session, repDesc, representationName, adapterFactory); } - private static IAction buildOpenRepresentationAction(final Session session, final DRepresentation representation, final String label, final AdapterFactory adapterFactory) { + private static IAction buildOpenRepresentationAction(final Session session, final DRepresentationDescriptor repDesc, final String label, final AdapterFactory adapterFactory) { ImageDescriptor imageDescriptor = null; - final IItemLabelProvider labelProvider = (IItemLabelProvider) adapterFactory.adapt(representation, IItemLabelProvider.class); + final IItemLabelProvider labelProvider = (IItemLabelProvider) adapterFactory.adapt(repDesc, IItemLabelProvider.class); if (labelProvider != null) { - imageDescriptor = ExtendedImageRegistry.getInstance().getImageDescriptor(labelProvider.getImage(representation)); + imageDescriptor = ExtendedImageRegistry.getInstance().getImageDescriptor(labelProvider.getImage(repDesc)); } if (imageDescriptor == null) { imageDescriptor = SiriusTransPlugin.getBundledImageDescriptor(ImagesPath.LINK_TO_VIEWPOINT_IMG); } - return new OpenRepresentationAction(label, imageDescriptor, representation, session); + return new OpenRepresentationAction(label, imageDescriptor, repDesc, session); } } |
