Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrancois Le Fevre2017-09-08 13:44:09 +0000
committerShuai Li2017-09-12 08:15:45 +0000
commit6807a05a2b755a479d0d6bd7db43f39b43618f2f (patch)
treec1854270f79a616163c98e37982748c9ab94c451 /plugins/infra
parent781e40e035aa24a31c55b2d37a8e4db39ad27f36 (diff)
downloadorg.eclipse.papyrus-6807a05a2b755a479d0d6bd7db43f39b43618f2f.tar.gz
org.eclipse.papyrus-6807a05a2b755a479d0d6bd7db43f39b43618f2f.tar.xz
org.eclipse.papyrus-6807a05a2b755a479d0d6bd7db43f39b43618f2f.zip
Bug 510181 - [diagram][userxp] Add Hyperlink menu in Edit group menu
Actions -adding a default menu -adding a key binding -adding an icon Test -creation of a package and crtl+K or navigate menu https://meta.stackexchange.com/questions/49948/use-ctrlk-to-insert-modify-a-hyperlink-instead-of-code Change-Id: Ibe886dd27780c359858152bfb281fd7c7cd0a1cd Signed-off-by: Francois Le Fevre <francois.le-fevre@cea.fr> Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=510181
Diffstat (limited to 'plugins/infra')
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.hyperlink/icons/hyperlink_icon.pngbin0 -> 1150 bytes
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.hyperlink/plugin.xml45
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.hyperlink/src/org/eclipse/papyrus/infra/gmfdiag/hyperlink/handler/ManageHyperLinksHandler.java133
3 files changed, 178 insertions, 0 deletions
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.hyperlink/icons/hyperlink_icon.png b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.hyperlink/icons/hyperlink_icon.png
new file mode 100644
index 00000000000..5ca1855a77e
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.hyperlink/icons/hyperlink_icon.png
Binary files differ
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.hyperlink/plugin.xml b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.hyperlink/plugin.xml
index c4891f51b53..8f4f1793750 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.hyperlink/plugin.xml
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.hyperlink/plugin.xml
@@ -40,4 +40,49 @@
provider="org.eclipse.papyrus.infra.gmfdiag.hyperlink.providers.EditorHyperlinkLabelProvider">
</labelProvider>
</extension>
+
+
+ <extension
+ point="org.eclipse.ui.commands">
+ <command
+ id="org.eclipse.papyrus.infra.gmfdiag.hyperlink.commands.hyperlinkManagerCommand"
+ name="Manage Hyperlinks">
+ </command>
+ </extension>
+ <extension
+ point="org.eclipse.ui.handlers">
+ <handler
+ class="org.eclipse.papyrus.infra.gmfdiag.hyperlink.handler.ManageHyperLinksHandler"
+ commandId="org.eclipse.papyrus.infra.gmfdiag.hyperlink.commands.hyperlinkManagerCommand">
+ </handler>
+ </extension>
+ <extension
+ point="org.eclipse.ui.menus">
+ <menuContribution
+ locationURI="popup:navigateMenu">
+
+ <command
+ commandId="org.eclipse.papyrus.infra.gmfdiag.hyperlink.commands.hyperlinkManagerCommand"
+ icon="icons/hyperlink_icon.png"
+ id="org.eclipse.papyrus.infra.gmfdiag.hyperlink.menu.toolbars.hyperlinkManagerCommand"
+ tooltip="Manage Hyperlinks">
+ </command>
+ </menuContribution>
+ </extension>
+<!-- commands and their bindings
+NOTE:
+M1 = CTRL/COMMAND
+M2 = SHIFT
+M3 = ALT
+M4 = Platform-specific fourth key
+-->
+<extension
+ point="org.eclipse.ui.bindings">
+ <key
+ commandId="org.eclipse.papyrus.infra.gmfdiag.hyperlink.commands.hyperlinkManagerCommand"
+ schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
+ sequence="M1+L"/>
+ </extension>
+
+
</plugin>
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.hyperlink/src/org/eclipse/papyrus/infra/gmfdiag/hyperlink/handler/ManageHyperLinksHandler.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.hyperlink/src/org/eclipse/papyrus/infra/gmfdiag/hyperlink/handler/ManageHyperLinksHandler.java
new file mode 100644
index 00000000000..6fbd1241a72
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.hyperlink/src/org/eclipse/papyrus/infra/gmfdiag/hyperlink/handler/ManageHyperLinksHandler.java
@@ -0,0 +1,133 @@
+/*****************************************************************************
+ * Copyright (c) 2017 CEA LIST 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Francois Le Fevre - CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.gmfdiag.hyperlink.handler;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.emf.ecore.EModelElement;
+import org.eclipse.gef.EditPart;
+import org.eclipse.gef.EditPolicy;
+import org.eclipse.gef.commands.UnexecutableCommand;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.IPrimaryEditPart;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.papyrus.commands.Activator;
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.infra.gmfdiag.common.utils.ServiceUtilsForEditPart;
+import org.eclipse.papyrus.infra.gmfdiag.hyperlink.editpolicies.NavigationEditPolicy;
+import org.eclipse.papyrus.infra.hyperlink.helper.AbstractHyperLinkHelper;
+import org.eclipse.papyrus.infra.hyperlink.helper.HyperLinkHelperFactory;
+import org.eclipse.papyrus.infra.hyperlink.object.HyperLinkObject;
+import org.eclipse.papyrus.infra.hyperlink.ui.HyperLinkManagerShell;
+import org.eclipse.papyrus.infra.hyperlink.util.HyperLinkException;
+import org.eclipse.papyrus.infra.hyperlink.util.HyperLinkHelpersRegistrationUtil;
+import org.eclipse.papyrus.infra.ui.editorsfactory.IPageIconsRegistry;
+import org.eclipse.papyrus.infra.ui.util.EditorHelper;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.ISelectionService;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PlatformUI;
+
+/**
+ * Dedicated to open a shell for managing the hyperlinks
+ *
+ */
+public class ManageHyperLinksHandler extends AbstractHandler {
+
+ /**
+ * {@inheritDoc}
+ */
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+
+ //Retrieve NavigationEditPolicy
+ NavigationEditPolicy navigationEditPolicy = (NavigationEditPolicy) getEditPolicy(org.eclipse.papyrus.infra.gmfdiag.hyperlink.editpolicies.NavigationEditPolicy.NAVIGATION_POLICY);
+ if (navigationEditPolicy == null) {
+ return UnexecutableCommand.INSTANCE;
+ }
+
+ //Retrieve other variables needed to create HyperLinkManagerShell
+ final IGraphicalEditPart gep ;
+ EditPart target = navigationEditPolicy.getHost();
+ while (!(target instanceof IPrimaryEditPart) && target != null) {
+ target = target.getParent();
+ }
+
+ if (!(target instanceof IGraphicalEditPart)) {
+ return UnexecutableCommand.INSTANCE;
+ }
+
+ gep = (IGraphicalEditPart)target;
+
+
+ Shell parentShell = EditorHelper.getActiveShell();
+
+ try {
+ IPageIconsRegistry iconsregistry = ServiceUtilsForEditPart.getInstance().getService(IPageIconsRegistry.class, navigationEditPolicy.getHost());
+
+
+ List<AbstractHyperLinkHelper> hyperLinkHelpers = new ArrayList<AbstractHyperLinkHelper>();
+ hyperLinkHelpers.addAll(HyperLinkHelpersRegistrationUtil.INSTANCE.getAllRegisteredHyperLinkHelper());
+ final HyperLinkHelperFactory hyperlinkHelperFactory = new HyperLinkHelperFactory(hyperLinkHelpers);
+
+ final List<HyperLinkObject> hyperLinkObjectList = (ArrayList<HyperLinkObject>) hyperlinkHelperFactory.getAllreferenced(gep.getNotationView());
+
+ //Creation of the Shell
+ HyperLinkManagerShell hyperLinkManagerShell = new HyperLinkManagerShell(parentShell, iconsregistry, ((IGraphicalEditPart) navigationEditPolicy.getHost()).getEditingDomain(),
+ (EModelElement) ((IGraphicalEditPart) navigationEditPolicy.getHost()).getNotationView().getElement(),
+ ((IGraphicalEditPart) navigationEditPolicy.getHost()).getNotationView(), hyperlinkHelperFactory);
+ hyperLinkManagerShell.setInput(hyperLinkObjectList);
+ hyperLinkManagerShell.open();
+
+ } catch (ServiceException | HyperLinkException e) {
+ Activator.log.error("Error in opening HyperLink Management Shell",e);//$NON-NLS-1$
+ }
+
+ return UnexecutableCommand.INSTANCE;
+ }
+
+ /**
+ * @return a given EditPolicy from its name
+ */
+ public EditPolicy getEditPolicy(String editPolicyName) {
+ EditPolicy lookupEditPolicy = null;
+ IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+ if (activeWorkbenchWindow != null) {
+ ISelectionService selectionService = activeWorkbenchWindow.getSelectionService();
+ ISelection selectionTmp = selectionService.getSelection();
+ if ((selectionTmp != null) && (!selectionTmp.isEmpty())) {
+ if (selectionTmp instanceof StructuredSelection) {
+ Iterator<?> it = ((StructuredSelection) selectionTmp).iterator();
+ while (it.hasNext()) {
+ Object current = it.next();
+ if (current instanceof IGraphicalEditPart) {
+ EditPolicy editpolicy = ((IGraphicalEditPart) current).getEditPolicy(editPolicyName);
+ if (editpolicy != null) {
+ lookupEditPolicy = editpolicy;
+ break;
+ }
+ }
+ }
+ }
+ }
+ }
+ return lookupEditPolicy;
+ }
+}
+

Back to the top