diff options
| author | Belqassim Djafer | 2014-08-13 15:00:06 +0000 |
|---|---|---|
| committer | Laurent Redor | 2014-08-25 07:05:56 +0000 |
| commit | 63e634a2701d59f4f48853bbe0ab8284bd897402 (patch) | |
| tree | a400567921bc6810fb343b3fe6abe4620ff6b1e5 | |
| parent | 384fb01d4306d2709dd3c40d7b19ad2a2bb29ca9 (diff) | |
| download | org.eclipse.sirius-63e634a2701d59f4f48853bbe0ab8284bd897402.tar.gz org.eclipse.sirius-63e634a2701d59f4f48853bbe0ab8284bd897402.tar.xz org.eclipse.sirius-63e634a2701d59f4f48853bbe0ab8284bd897402.zip | |
[441262] replace navigate menu by two menus "new" and "open"
instead of a "Navigate" top-level menu entry with mixed entries for
creating new representations and opening existing ones, I have created
two top-level menus:
* One named "New", which lists only the available actions to create new
representations on the selected element.
* One named "Open", which lists only the existing representations on the
selected element.
If any of these does not contain anything, it should not be visible at
all.
Bug: 441262
Change-Id: I597ca58ff915c38d61b97c8540df9ea9bfa58532
Signed-off-by: Belqassim Djafer <belqassim.djafer@obeo.fr>
5 files changed, 166 insertions, 104 deletions
diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/menu/DiagramEditorContextMenuProvider.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/menu/DiagramEditorContextMenuProvider.java index e81e58de1b..5512c07e90 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/menu/DiagramEditorContextMenuProvider.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/menu/DiagramEditorContextMenuProvider.java @@ -107,7 +107,6 @@ public class DiagramEditorContextMenuProvider extends DiagramContextMenuProvider ContributionItemService.getInstance().contributeToPopupMenu(DiagramEditorContextMenuProvider.this, part); menu.remove(ActionIds.ACTION_DELETE_FROM_MODEL); updateFormatMenu(menu); - final IMenuManager manager = menu.findMenuUsingPath(ActionIds.MENU_EDIT); IContributionItem find = manager.find(DELETE_FROM_GROUP); if (find != null) { diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/menu/NavigateToMenuContribution.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/menu/NavigateToMenuContribution.java index 930522ac26..fe7d36a509 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/menu/NavigateToMenuContribution.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/menu/NavigateToMenuContribution.java @@ -31,6 +31,7 @@ import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; import org.eclipse.jface.action.Action; import org.eclipse.jface.action.IAction; import org.eclipse.jface.action.IMenuManager; +import org.eclipse.jface.action.MenuManager; import org.eclipse.jface.action.Separator; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.sirius.business.api.componentization.ViewpointRegistry; @@ -79,7 +80,9 @@ import com.google.common.collect.Lists; */ public class NavigateToMenuContribution implements IContributionItemProvider { - private static final String NAVIGATE_REPRESENTATION_GROUP_SEPARATOR = "navigateRepresentationGroup"; + private static final String OPEN_REPRESENTATION_GROUP_SEPARATOR = "openRepresentationGroup"; + + private static final String MENU_OPEN_REPRESENTATION_ID = "popup.open"; private AdapterFactory adapterFactory; @@ -117,19 +120,28 @@ public class NavigateToMenuContribution implements IContributionItemProvider { final Session session = SessionManager.INSTANCE.getSession(semantic); if (session != null) { menu.insertBefore("additions", new Separator("generator")); //$NON-NLS-1$ //$NON-NLS-2$ - final IMenuManager navigate = (IMenuManager) menu.find("navigateMenu"); //$NON-NLS-1$ - + // Remove Open action in navigate menu which is not used in + // Sirius and avoid to have a gray "Open" item menu in Navigate + // menu + final IMenuManager navigateManager = (IMenuManager) menu.find("navigateMenu"); + navigateManager.remove("open"); + // Add menus to open existing representations + final MenuManager openMenuManager = new MenuManager("Open", MENU_OPEN_REPRESENTATION_ID); + if (!menu.isEmpty()) { + menu.insertBefore(menu.getItems()[0].getId(), openMenuManager); + } else { + menu.add(openMenuManager); + } + 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)) { - navigate.add(buildOpenRepresentationAction(session, representation, editpart, transDomain)); + openMenuManager.add(buildOpenRepresentationAction(session, representation, editpart, transDomain)); } } if (designerObj instanceof DRepresentationElement) { - buildNavigableRepresentationsMenu(navigate, designerObj, session, editpart, transDomain); + buildOpenableRepresentationsMenu(openMenuManager, designerObj, session, editpart, transDomain); } } } @@ -167,10 +179,10 @@ public class NavigateToMenuContribution implements IContributionItemProvider { return isFromActiveViewpoint(session, description); } - private void buildNavigableRepresentationsMenu(final IMenuManager navigate, final EObject designerObj, final Session session, final EditPart editpart, final TransactionalEditingDomain transDomain) { + private void buildOpenableRepresentationsMenu(final IMenuManager openMenu, final EObject designerObj, final Session session, final EditPart editpart, final TransactionalEditingDomain transDomain) { final DRepresentationElement element = (DRepresentationElement) designerObj; - final Separator createGroup = new Separator(NAVIGATE_REPRESENTATION_GROUP_SEPARATOR); - navigate.add(createGroup); + final Separator createGroup = new Separator(OPEN_REPRESENTATION_GROUP_SEPARATOR); + openMenu.add(createGroup); for (RepresentationNavigationDescription navDesc : element.getMapping().getNavigationDescriptions()) { boolean append = true; if (!isFromActiveViewpoint(session, navDesc.getRepresentationDescription())) { @@ -204,14 +216,14 @@ public class NavigateToMenuContribution implements IContributionItemProvider { } if (append) { - buildOpenRepresentationActions(navigate, interpreter, navDesc, element, session, editpart, transDomain); + buildOpenRepresentationActions(openMenu, interpreter, navDesc, element, session, editpart, transDomain); } interpreter.unSetVariable(IInterpreterSiriusVariables.DIAGRAM); } } - private void buildOpenRepresentationActions(final IMenuManager navigate, final IInterpreter interpreter, final RepresentationNavigationDescription navDesc, final DRepresentationElement element, + private void buildOpenRepresentationActions(final IMenuManager openMenu, final IInterpreter interpreter, final RepresentationNavigationDescription navDesc, final DRepresentationElement element, final Session session, final EditPart editpart, final TransactionalEditingDomain transDomain) { final Collection<EObject> candidates = findCandidates(element, navDesc, interpreter); final Collection<DRepresentation> representations = DialectManager.INSTANCE.getRepresentations(navDesc.getRepresentationDescription(), session); @@ -226,7 +238,7 @@ public class NavigateToMenuContribution implements IContributionItemProvider { RuntimeLoggerManager.INSTANCE.error(navDesc, ToolPackage.eINSTANCE.getRepresentationNavigationDescription_NavigationNameExpression(), e); } } - navigate.appendToGroup(NAVIGATE_REPRESENTATION_GROUP_SEPARATOR, buildOpenRepresentationAction(session, representation, editpart, transDomain, label)); + openMenu.appendToGroup(OPEN_REPRESENTATION_GROUP_SEPARATOR, buildOpenRepresentationAction(session, representation, editpart, transDomain, label)); } } } diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/menu/SubDiagramMenu.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/menu/SubDiagramMenu.java index 3a4015ed92..dd3ab4145d 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/menu/SubDiagramMenu.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/menu/SubDiagramMenu.java @@ -21,6 +21,7 @@ import org.eclipse.gmf.runtime.common.ui.util.IWorkbenchPartDescriptor; import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; import org.eclipse.gmf.runtime.diagram.ui.editparts.NoteEditPart; import org.eclipse.jface.action.IMenuManager; +import org.eclipse.jface.action.MenuManager; import org.eclipse.jface.action.Separator; import org.eclipse.sirius.business.api.componentization.ViewpointRegistry; import org.eclipse.sirius.business.api.session.Session; @@ -50,6 +51,8 @@ public class SubDiagramMenu implements IContributionItemProvider { private static final String CREATE_REPRESENTATION_GROUP_SEPARATOR = "createRepresentationGroup"; + private static final String MENU_NEW_REPRESENTATION_ID = "popup.new"; + /** * {@inheritDoc} */ @@ -82,11 +85,19 @@ public class SubDiagramMenu implements IContributionItemProvider { } } if (editpart instanceof ISiriusEditPart) { - final IMenuManager navigate = (IMenuManager) menu.find("navigateMenu"); + // Create a new sub-menu manager + final MenuManager newMenuManager = new MenuManager("New", SubDiagramMenu.MENU_NEW_REPRESENTATION_ID); + // Create the item to add to the top of main manager, just + // before the open menu + if (!menu.isEmpty()) { + menu.insertBefore(menu.getItems()[0].getId(), newMenuManager); + } else { + menu.add(newMenuManager); + } final Separator createGroup = new Separator(CREATE_REPRESENTATION_GROUP_SEPARATOR); - navigate.add(createGroup); + newMenuManager.add(createGroup); if (eObj instanceof DDiagramElement) { - createDetailsActions((DDiagramElement) eObj, navigate, diagrampart.getEditingDomain(), curPart); + createDetailsActions((DDiagramElement) eObj, newMenuManager, diagrampart.getEditingDomain(), curPart); } } else { // no focused edit part @@ -101,7 +112,7 @@ public class SubDiagramMenu implements IContributionItemProvider { return vp != null && session.getSelectedViewpoints(false).contains(vp); } - private void createDetailsActions(final DDiagramElement dde, final IMenuManager navigate, final TransactionalEditingDomain editingDomain, final IGraphicalEditPart curPart) { + private void createDetailsActions(final DDiagramElement dde, final IMenuManager newMenu, final TransactionalEditingDomain editingDomain, final IGraphicalEditPart curPart) { if (dde.getMapping() != null) { EObject sessionFinder = null; final EList<EObject> semanticElements = dde.getSemanticElements(); @@ -128,7 +139,7 @@ public class SubDiagramMenu implements IContributionItemProvider { } } if (append) { - navigate.appendToGroup(CREATE_REPRESENTATION_GROUP_SEPARATOR, new CreateRepresentationFromRepresentationCreationDescription(desc, dde, editingDomain, curPart)); + newMenu.appendToGroup(CREATE_REPRESENTATION_GROUP_SEPARATOR, new CreateRepresentationFromRepresentationCreationDescription(desc, dde, editingDomain, curPart)); } } } 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 6a4da061b8..ef1fe43cb9 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 @@ -106,7 +106,9 @@ import com.google.common.collect.Lists; * */ public class DTableMenuListener implements IMenuListener { - private static final String MENU_NAVIGATE_ID = "popup.navigate"; + private static final String MENU_OPEN_REPRESENTATION_ID = "popup.open"; + + private static final String MENU_NEW_REPRESENTATION_ID = "popup.new"; private static final String MENU_HIDEREVEAL_ID = "popup.hidereveal"; @@ -116,7 +118,7 @@ public class DTableMenuListener implements IMenuListener { private static final String EXISTING_REPRESENTATION_GROUP_SEPARATOR = "existingRepresentation"; - private static final String NAVIGATE_REPRESENTATION_GROUP_SEPARATOR = "navigateRepresentationGroup"; + private static final String OPEN_REPRESENTATION_GROUP_SEPARATOR = "navigateRepresentationGroup"; private static final String VIEWPOINT_GROUP_SEPARATOR = "viewpoint"; @@ -210,8 +212,10 @@ public class DTableMenuListener implements IMenuListener { public void menuAboutToShow(final IMenuManager manager) { // Refresh the cached actions if needed treeViewManager.fillMenu(); - // Add navigate menus - addNavigateMenu(manager); + // Add Open representation menu + addOpenRepresentationMenu(manager); + // Add New representation menu + addNewRepresentationMenu(manager); manager.add(new Separator()); // Add viewpoint menus addRefreshMenu(manager); @@ -267,42 +271,57 @@ public class DTableMenuListener implements IMenuListener { } /** - * Add the navigate sub menu and its actions if needed. + * Add the open sub menu and its actions if needed. * * @param manager * The menu manager */ - private void addNavigateMenu(final IMenuManager manager) { + private void addOpenRepresentationMenu(final IMenuManager manager) { // Create a new sub-menu manager - final MenuManager navigateMenuManager = new MenuManager("Navigate", DTableMenuListener.MENU_NAVIGATE_ID); + final MenuManager openMenuManager = new MenuManager("Open", DTableMenuListener.MENU_OPEN_REPRESENTATION_ID); // Create the item to add to the main manager - final SubContributionItem navigateMenuItem = new SubContributionItem(navigateMenuManager); - manager.add(navigateMenuItem); - // Add menus to navigate through existing representations (created by + final SubContributionItem openMenuItem = new SubContributionItem(openMenuManager); + manager.add(openMenuItem); + // Add menus to open existing representations (created by // RepresentationCreationDescription) final Separator existingGroup = new Separator(DTableMenuListener.EXISTING_REPRESENTATION_GROUP_SEPARATOR); - navigateMenuManager.add(existingGroup); - // Add menus to navigate through existing representations (corresponding + openMenuManager.add(existingGroup); + // Add menus to open existing representations (corresponding // to the RepresentationNavigationDescription) - final Separator navigateRepresentationGroup = new Separator(NAVIGATE_REPRESENTATION_GROUP_SEPARATOR); - navigateMenuManager.add(navigateRepresentationGroup); - // Add menus to navigate through new representations (corresponding to - // the RepresentationCreationDescription) - final Separator createGroup = new Separator(DTableMenuListener.NEW_REPRESENTATION_GROUP_SEPARATOR); - navigateMenuManager.add(createGroup); + final Separator openRepresentationGroup = new Separator(OPEN_REPRESENTATION_GROUP_SEPARATOR); + openMenuManager.add(openRepresentationGroup); final DTableElement currentTableElement = getCurrentTableElement(); if (currentTableElement != null) { - // Add actions to navigate to existing representation - createNavigationAction(navigateMenuItem, currentTableElement); - // Add actions to navigate to new representation - if (currentTableElement instanceof DCell) { - createDetailsActions(currentTableElement, navigateMenuItem); - } else if (currentTableElement instanceof DLine) { - createDetailsActions(currentTableElement, navigateMenuItem); - } + // Add actions to open existing representation + createOpenAction(openMenuItem, currentTableElement); } else { - // Add actions to navigate to existing representation - createNavigationAction(navigateMenuItem, dTable); + // Add actions to open representation + createOpenAction(openMenuItem, dTable); + } + } + + /** + * Add the new sub menu and its actions if needed. + * + * @param manager + * The menu manager + */ + private void addNewRepresentationMenu(final IMenuManager manager) { + // Create a new sub-menu manager + final MenuManager newMenuManager = new MenuManager("New", DTableMenuListener.MENU_NEW_REPRESENTATION_ID); + // Create the item to add to the main manager + final SubContributionItem newMenuItem = new SubContributionItem(newMenuManager); + manager.add(newMenuItem); + // Add menus to create new representations (corresponding to + // the RepresentationCreationDescription) + final Separator createGroup = new Separator(DTableMenuListener.NEW_REPRESENTATION_GROUP_SEPARATOR); + newMenuManager.add(createGroup); + final DTableElement currentTableElement = getCurrentTableElement(); + // Add actions to create new representation + if (currentTableElement instanceof DCell) { + createDetailsActions(currentTableElement, newMenuItem); + } else if (currentTableElement instanceof DLine) { + createDetailsActions(currentTableElement, newMenuItem); } } @@ -310,29 +329,29 @@ public class DTableMenuListener implements IMenuListener { * @param navigateMenuItem * @param semanticElement */ - private void createNavigationAction(final SubContributionItem navigate, final DSemanticDecorator decorator) { + private void createOpenAction(final SubContributionItem openRepresentation, final DSemanticDecorator decorator) { 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)) { - navigate.setVisible(true); - ((IMenuManager) navigate.getInnerItem()).appendToGroup(EXISTING_REPRESENTATION_GROUP_SEPARATOR, buildOpenRepresentationAction(session, representation)); + openRepresentation.setVisible(true); + ((IMenuManager) openRepresentation.getInnerItem()).appendToGroup(EXISTING_REPRESENTATION_GROUP_SEPARATOR, buildOpenRepresentationAction(session, representation)); } } if (decorator instanceof DRepresentationElement) { - if (buildNavigableRepresentationsMenu((IMenuManager) navigate.getInnerItem(), decorator, session)) { + if (buildOpenRepresentationsMenu((IMenuManager) openRepresentation.getInnerItem(), decorator, session)) { // If at least one navigable representation menu // has been created, we have to make the navigate menu // visible - navigate.setVisible(true); + openRepresentation.setVisible(true); } } } } - private boolean buildNavigableRepresentationsMenu(final IMenuManager navigate, final EObject designerObj, final Session session) { + private boolean buildOpenRepresentationsMenu(final IMenuManager open, final EObject designerObj, final Session session) { final DRepresentationElement element = (DRepresentationElement) designerObj; if (element.getMapping() != null) { @@ -365,15 +384,15 @@ public class DTableMenuListener implements IMenuListener { if (append) { // We return true if at least one action has been // added in the menu to make it visible - return buildOpenRepresentationActions(navigate, interpreter, navDesc, element, session); + return buildOpenRepresentationActions(open, interpreter, navDesc, element, session); } } } return false; } - private boolean buildOpenRepresentationActions(final IMenuManager navigate, final IInterpreter interpreter, final RepresentationNavigationDescription navDesc, - final DRepresentationElement element, final Session session) { + private boolean buildOpenRepresentationActions(final IMenuManager open, final IInterpreter interpreter, final RepresentationNavigationDescription navDesc, final DRepresentationElement element, + final Session session) { boolean atLeastOneRepresentationActionsWasCreated = false; Collection<EObject> candidates; if (!StringUtil.isEmpty(navDesc.getBrowseExpression())) { @@ -390,7 +409,7 @@ public class DTableMenuListener implements IMenuListener { for (final DRepresentation representation : representations) { if (representation instanceof DSemanticDecorator && candidates.contains(((DSemanticDecorator) representation).getTarget())) { interpreter.setVariable(navDesc.getRepresentationNameVariable().getName(), representation.getName()); - String label = new StringBuffer("Open ").append(navDesc.getName()).append(" : ").append(representation.getName()).toString(); + String label = new StringBuffer().append(navDesc.getName()).append(representation.getName()).toString(); if (!StringUtil.isEmpty(navDesc.getNavigationNameExpression())) { try { label = interpreter.evaluateString(element.getTarget(), navDesc.getNavigationNameExpression()); @@ -398,7 +417,7 @@ public class DTableMenuListener implements IMenuListener { RuntimeLoggerManager.INSTANCE.error(navDesc, ToolPackage.eINSTANCE.getRepresentationNavigationDescription_NavigationNameExpression(), e); } } - navigate.appendToGroup(NAVIGATE_REPRESENTATION_GROUP_SEPARATOR, buildOpenRepresentationAction(session, representation, label)); + open.appendToGroup(OPEN_REPRESENTATION_GROUP_SEPARATOR, buildOpenRepresentationAction(session, representation, label)); atLeastOneRepresentationActionsWasCreated = true; } } @@ -413,7 +432,7 @@ public class DTableMenuListener implements IMenuListener { representationName += " " + new IdentifiedElementQuery(((DTable) representation).getDescription()).getLabel(); } } - return buildOpenRepresentationAction(session, representation, "Open " + representationName); + return buildOpenRepresentationAction(session, representation, representationName); } private IAction buildOpenRepresentationAction(final Session session, final DRepresentation representation, final String label) { @@ -637,7 +656,7 @@ public class DTableMenuListener implements IMenuListener { } } - private void createDetailsActions(final DTableElement currentElement, final SubContributionItem navigate) { + private void createDetailsActions(final DTableElement currentElement, final SubContributionItem newMenuItems) { if (currentElement.getMapping() != null) { final Session session = currentElement.getTarget() != null ? SessionManager.INSTANCE.getSession(currentElement.getTarget()) : null; if (session != null) { @@ -658,9 +677,9 @@ public class DTableMenuListener implements IMenuListener { } } if (append) { - navigate.setVisible(true); - ((IMenuManager) navigate.getInnerItem()).appendToGroup(NEW_REPRESENTATION_GROUP_SEPARATOR, new CreateRepresentationFromRepresentationCreationDescription(desc, currentElement, - treeViewManager.getEditingDomain(), treeViewManager.getTableCommandFactory())); + newMenuItems.setVisible(true); + ((IMenuManager) newMenuItems.getInnerItem()).appendToGroup(NEW_REPRESENTATION_GROUP_SEPARATOR, new CreateRepresentationFromRepresentationCreationDescription(desc, + currentElement, treeViewManager.getEditingDomain(), treeViewManager.getTableCommandFactory())); } } } 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 86f8f8c0df..e07a8c8c3a 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 @@ -77,13 +77,15 @@ import org.eclipse.ui.IWorkbenchActionConstants; */ public class DTreeMenuListener implements IMenuListener { - private static final String MENU_NAVIGATE_ID = "popup.navigate"; + private static final String MENU_OPEN_REPRESENTATION_ID = "popup.navigate"; + + private static final String MENU_NEW_REPRESENTATION_ID = "popup.new"; private static final String NEW_REPRESENTATION_GROUP_SEPARATOR = "newRepresentation"; private static final String EXISTING_REPRESENTATION_GROUP_SEPARATOR = "existingRepresentation"; - private static final String NAVIGATE_REPRESENTATION_GROUP_SEPARATOR = "navigateRepresentationGroup"; + private static final String OPEN_REPRESENTATION_GROUP_SEPARATOR = "navigateRepresentationGroup"; private static final String PROPERTIES_SEPARATOR = "properties"; @@ -147,14 +149,16 @@ public class DTreeMenuListener implements IMenuListener { public void menuAboutToShow(final IMenuManager manager) { // Refresh the cached actions if needed treeViewManager.fillMenu(); - // Add line menus - addTreeItemMenus(manager); - // Add navigate menus - addNavigateMenu(manager); + // Add Open representation menu + addOpenRepresentationMenu(manager); + // Add new representation menu + addNewRepresentationMenu(manager); manager.add(new Separator()); // Add viewpoint menus addRefreshMenu(manager); manager.add(new Separator()); + // Add line menus + addTreeItemMenus(manager); manager.add(new Separator(DTreeMenuListener.LOCK_SEPARATOR)); addTreeMenus(manager); // Add show properties view @@ -178,7 +182,6 @@ public class DTreeMenuListener implements IMenuListener { if (createLineAction.canExecute()) { manager.add(createLineAction); } - } } manager.add(new Separator()); @@ -186,71 +189,89 @@ public class DTreeMenuListener implements IMenuListener { } /** - * Add the navigate sub menu and its actions if needed. + * Add the open sub menu and its actions if needed. * * @param manager * The menu manager */ - private void addNavigateMenu(final IMenuManager manager) { + private void addOpenRepresentationMenu(final IMenuManager manager) { // Create a new sub-menu manager - final MenuManager navigateMenuManager = new MenuManager("Navigate", DTreeMenuListener.MENU_NAVIGATE_ID); + final MenuManager openMenuManager = new MenuManager("Open", DTreeMenuListener.MENU_OPEN_REPRESENTATION_ID); // Create the item to add to the main manager - final SubContributionItem navigateMenuItem = new SubContributionItem(navigateMenuManager); - manager.add(navigateMenuItem); - // Add menus to navigate through existing representations (created by + final SubContributionItem openMenuItem = new SubContributionItem(openMenuManager); + manager.add(openMenuItem); + // Add menus to open existing representations (created by // RepresentationCreationDescription) final Separator existingGroup = new Separator(DTreeMenuListener.EXISTING_REPRESENTATION_GROUP_SEPARATOR); - navigateMenuManager.add(existingGroup); - // Add menus to navigate through existing representations (corresponding + openMenuManager.add(existingGroup); + // Add menus to open existing representations (corresponding // to the RepresentationNavigationDescription) - final Separator navigateRepresentationGroup = new Separator(NAVIGATE_REPRESENTATION_GROUP_SEPARATOR); - navigateMenuManager.add(navigateRepresentationGroup); - // Add menus to navigate through new representations (corresponding to + final Separator openRepresentationGroup = new Separator(OPEN_REPRESENTATION_GROUP_SEPARATOR); + openMenuManager.add(openRepresentationGroup); + final Collection<DTreeItem> currentTreeElements = treeViewManager.getSelectedItems(); + if (currentTreeElements != null && currentTreeElements.size() == 1) { + DTreeItem currentTreeElement = currentTreeElements.iterator().next(); + // Add actions to open existing representation + createOpenAction(openMenuItem, currentTreeElement); + } else { + // Add actions to open existing representation + createOpenAction(openMenuItem, dTree); + } + } + + /** + * Add the new sub menu and its actions if needed. + * + * @param manager + * The menu manager + */ + private void addNewRepresentationMenu(final IMenuManager manager) { + // Create a new sub-menu manager + final MenuManager newMenuManager = new MenuManager("New", DTreeMenuListener.MENU_NEW_REPRESENTATION_ID); + // Create the item to add to the main manager + final SubContributionItem newMenuItem = new SubContributionItem(newMenuManager); + manager.add(newMenuItem); + // Add menus to create new representations (corresponding to // the RepresentationCreationDescription) final Separator createGroup = new Separator(DTreeMenuListener.NEW_REPRESENTATION_GROUP_SEPARATOR); - navigateMenuManager.add(createGroup); + newMenuManager.add(createGroup); final Collection<DTreeItem> currentTreeElements = treeViewManager.getSelectedItems(); if (currentTreeElements != null && currentTreeElements.size() == 1) { DTreeItem currentTreeElement = currentTreeElements.iterator().next(); - // Add actions to navigate to existing representation - createNavigationAction(navigateMenuItem, currentTreeElement); // Add actions to navigate to new representation if (currentTreeElement != null) { - createDetailsActions(currentTreeElement, navigateMenuItem); + createDetailsActions(currentTreeElement, newMenuItem); } - } else { - // Add actions to navigate to existing representation - createNavigationAction(navigateMenuItem, dTree); } } /** - * @param navigateMenuItem + * @param openMenuItem * @param semanticElement */ - private void createNavigationAction(final SubContributionItem navigate, final DSemanticDecorator decorator) { + private void createOpenAction(final SubContributionItem openItem, final DSemanticDecorator decorator) { 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)) { - navigate.setVisible(true); - ((IMenuManager) navigate.getInnerItem()).appendToGroup(EXISTING_REPRESENTATION_GROUP_SEPARATOR, buildOpenRepresentationAction(session, representation)); + openItem.setVisible(true); + ((IMenuManager) openItem.getInnerItem()).appendToGroup(EXISTING_REPRESENTATION_GROUP_SEPARATOR, buildOpenRepresentationAction(session, representation)); } } if (decorator instanceof DRepresentationElement) { - if (buildNavigableRepresentationsMenu((IMenuManager) navigate.getInnerItem(), (DRepresentationElement) decorator, session)) { + if (buildOpenRepresentationsMenu((IMenuManager) openItem.getInnerItem(), (DRepresentationElement) decorator, session)) { // if at least one navigable representation menu // has been created, we have to make the navigate menu // visible - navigate.setVisible(true); + openItem.setVisible(true); } } } } - private boolean buildNavigableRepresentationsMenu(final IMenuManager navigate, final DRepresentationElement element, final Session session) { + private boolean buildOpenRepresentationsMenu(final IMenuManager openMenu, final DRepresentationElement element, final Session session) { if (element.getMapping() != null) { for (final RepresentationNavigationDescription navDesc : element.getMapping().getNavigationDescriptions()) { @@ -282,14 +303,14 @@ public class DTreeMenuListener implements IMenuListener { if (append) { // VP-2659 : we return true if at least one action has been // added in the menu to make it visible - return buildOpenRepresentationActions(navigate, interpreter, navDesc, element, session); + return buildOpenRepresentationActions(openMenu, interpreter, navDesc, element, session); } } } return false; } - private boolean buildOpenRepresentationActions(final IMenuManager navigate, final IInterpreter interpreter, final RepresentationNavigationDescription navDesc, + private boolean buildOpenRepresentationActions(final IMenuManager openMenu, final IInterpreter interpreter, final RepresentationNavigationDescription navDesc, final DRepresentationElement element, final Session session) { boolean atLeastOneRepresentationActionsWasCreated = false; Collection<EObject> candidates; @@ -307,7 +328,7 @@ public class DTreeMenuListener implements IMenuListener { for (final DRepresentation representation : representations) { if (representation instanceof DSemanticDecorator && candidates.contains(((DSemanticDecorator) representation).getTarget())) { interpreter.setVariable(navDesc.getRepresentationNameVariable().getName(), representation.getName()); - String label = new StringBuffer("Open ").append(navDesc.getName()).append(" : ").append(representation.getName()).toString(); + String label = new StringBuffer().append(navDesc.getName()).append(representation.getName()).toString(); if (!StringUtil.isEmpty(navDesc.getNavigationNameExpression())) { try { label = interpreter.evaluateString(element.getTarget(), navDesc.getNavigationNameExpression()); @@ -315,7 +336,7 @@ public class DTreeMenuListener implements IMenuListener { RuntimeLoggerManager.INSTANCE.error(navDesc, ToolPackage.eINSTANCE.getRepresentationNavigationDescription_NavigationNameExpression(), e); } } - navigate.appendToGroup(NAVIGATE_REPRESENTATION_GROUP_SEPARATOR, buildOpenRepresentationAction(session, representation, label)); + openMenu.appendToGroup(OPEN_REPRESENTATION_GROUP_SEPARATOR, buildOpenRepresentationAction(session, representation, label)); atLeastOneRepresentationActionsWasCreated = true; } } @@ -330,7 +351,7 @@ public class DTreeMenuListener implements IMenuListener { representationName += " " + new IdentifiedElementQuery(((DTree) representation).getDescription()).getLabel(); } } - return buildOpenRepresentationAction(session, representation, "Open " + representationName); + return buildOpenRepresentationAction(session, representation, representationName); } private IAction buildOpenRepresentationAction(final Session session, final DRepresentation representation, final String label) { @@ -393,7 +414,7 @@ public class DTreeMenuListener implements IMenuListener { } } - private void createDetailsActions(final DTreeItem currentElement, final SubContributionItem navigate) { + private void createDetailsActions(final DTreeItem currentElement, final SubContributionItem newMenuItem) { if (currentElement.getMapping() != null) { final Session session = currentElement.getTarget() != null ? SessionManager.INSTANCE.getSession(currentElement.getTarget()) : null; if (session != null) { @@ -414,9 +435,9 @@ public class DTreeMenuListener implements IMenuListener { } } if (append) { - navigate.setVisible(true); - ((IMenuManager) navigate.getInnerItem()).appendToGroup(NEW_REPRESENTATION_GROUP_SEPARATOR, new CreateRepresentationFromRepresentationCreationDescription(desc, currentElement, - treeViewManager.getEditingDomain(), treeViewManager.getTreeCommandFactory())); + newMenuItem.setVisible(true); + ((IMenuManager) newMenuItem.getInnerItem()).appendToGroup(NEW_REPRESENTATION_GROUP_SEPARATOR, new CreateRepresentationFromRepresentationCreationDescription(desc, + currentElement, treeViewManager.getEditingDomain(), treeViewManager.getTreeCommandFactory())); } } } |
