Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorvlorenzo2011-02-11 08:57:39 +0000
committervlorenzo2011-02-11 08:57:39 +0000
commitb37824f1435505156eb1aa3122cc5d085894ecb2 (patch)
treeb5beeb0e5dd4831b3c76153e91a15cac7b9c4577 /plugins/uml/org.eclipse.papyrus.diagram.common
parentd589c5e7d03fcc4fd831fde6b89c60b28c6abe76 (diff)
downloadorg.eclipse.papyrus-b37824f1435505156eb1aa3122cc5d085894ecb2.tar.gz
org.eclipse.papyrus-b37824f1435505156eb1aa3122cc5d085894ecb2.tar.xz
org.eclipse.papyrus-b37824f1435505156eb1aa3122cc5d085894ecb2.zip
NEW bug - 317424: [General]Bind the org.eclipse.ui. keybindings and the shortcut written in the menus
https://bugs.eclipse.org/bugs/show_bug.cgi?id=317424 Remove the keybindings provided by GMF : in the class UmlGmfDiagramEditors + in the class SymlDiagramEditor which doesn't have the same hierarchy that others diagrams Provides a handler for the rename action Write the keybinding with the rewritten command (Zoom In, Zoom Out) CTRL + DEL and DEL are yet done. Other GMF binding are removed
Diffstat (limited to 'plugins/uml/org.eclipse.papyrus.diagram.common')
-rw-r--r--plugins/uml/org.eclipse.papyrus.diagram.common/plugin.xml20
-rw-r--r--plugins/uml/org.eclipse.papyrus.diagram.common/src/org/eclipse/papyrus/diagram/common/handlers/RenamedElementHandler.java102
-rw-r--r--plugins/uml/org.eclipse.papyrus.diagram.common/src/org/eclipse/papyrus/diagram/common/part/UmlGmfDiagramEditor.java10
-rw-r--r--plugins/uml/org.eclipse.papyrus.diagram.common/src/org/eclipse/papyrus/diagram/common/providers/ActionStateSourceProvider.java27
4 files changed, 148 insertions, 11 deletions
diff --git a/plugins/uml/org.eclipse.papyrus.diagram.common/plugin.xml b/plugins/uml/org.eclipse.papyrus.diagram.common/plugin.xml
index bf81d552cfe..6c5c0fda378 100644
--- a/plugins/uml/org.eclipse.papyrus.diagram.common/plugin.xml
+++ b/plugins/uml/org.eclipse.papyrus.diagram.common/plugin.xml
@@ -380,7 +380,7 @@
</visibleWhen>
</command>
- </menuContribution>
+ </menuContribution>
</extension>
<extension point="org.eclipse.ui.commands">
@@ -426,6 +426,10 @@
name="deleteInDiagram"
priorityLevel="workbench">
</variable>
+ <variable
+ name="renameNamedElement"
+ priorityLevel="workbench">
+ </variable>
</sourceProvider>
</extension>
<extension
@@ -460,6 +464,20 @@
</and>
</activeWhen>
</handler>
+ <handler
+ class="org.eclipse.papyrus.diagram.common.handlers.RenamedElementHandler"
+ commandId="org.eclipse.ui.edit.rename">
+ <activeWhen>
+ <and>
+ <with
+ variable="renameNamedElement">
+ <equals
+ value="enabled">
+ </equals>
+ </with>
+ </and>
+ </activeWhen>
+ </handler>
</extension>
<extension
point="org.eclipse.papyrus.core.service">
diff --git a/plugins/uml/org.eclipse.papyrus.diagram.common/src/org/eclipse/papyrus/diagram/common/handlers/RenamedElementHandler.java b/plugins/uml/org.eclipse.papyrus.diagram.common/src/org/eclipse/papyrus/diagram/common/handlers/RenamedElementHandler.java
new file mode 100644
index 00000000000..31e8ab342b1
--- /dev/null
+++ b/plugins/uml/org.eclipse.papyrus.diagram.common/src/org/eclipse/papyrus/diagram/common/handlers/RenamedElementHandler.java
@@ -0,0 +1,102 @@
+/*****************************************************************************
+ * Copyright (c) 2011 CEA LIST.
+ *
+ *
+ * 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:
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.diagram.common.handlers;
+
+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.gef.Request;
+import org.eclipse.gef.RequestConstants;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.papyrus.diagram.common.util.DiagramEditPartsUtil;
+import org.eclipse.ui.PlatformUI;
+
+/**
+ * This handler allows to rename element in the Diagram.
+ * It works with the org.eclipse.ui.edit.rename command.
+ * It is created to replace the initial keybinding done by GMF.
+ * see bug 317424
+ *
+ */
+public class RenamedElementHandler extends AbstractHandler {
+
+ /**
+ * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
+ *
+ * @param event
+ * @return
+ * @throws ExecutionException
+ */
+
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ List<IGraphicalEditPart> selection = getSelectedElements();
+ selection.get(0).performRequest(new Request(RequestConstants.REQ_DIRECT_EDIT));
+ return null;
+ }
+
+ /**
+ *
+ * @see org.eclipse.core.commands.AbstractHandler#isEnabled()
+ *
+ * @return
+ */
+ @Override
+ public boolean isEnabled() {
+ List<IGraphicalEditPart> selection = getSelectedElements();
+ if(selection.size() == 1) {
+ IGraphicalEditPart editpart = selection.get(0);
+ DiagramEditPart diagramEP = DiagramEditPartsUtil.getDiagramEditPart(editpart);
+ //we don't rename the diagram
+ return editpart != diagramEP;
+ }
+ return false;
+ }
+
+
+ /**
+ * Iterate over current selection and build a list of the {@link IGraphicalEditPart} contained in
+ * the selection.
+ *
+ * @return the currently selected {@link IGraphicalEditPart}
+ */
+ protected List<IGraphicalEditPart> getSelectedElements() {
+ List<IGraphicalEditPart> editparts = new ArrayList<IGraphicalEditPart>();
+
+ ISelection selection = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService().getSelection();
+ if(selection instanceof IStructuredSelection) {
+
+ IStructuredSelection structuredSelection = (IStructuredSelection)selection;
+
+ Iterator<?> it = structuredSelection.iterator();
+ while(it.hasNext()) {
+ Object object = it.next();
+ if(object instanceof IGraphicalEditPart) {
+ editparts.add((IGraphicalEditPart)object);
+ }
+ }
+
+ } else if(selection instanceof IGraphicalEditPart) {
+ editparts.add((IGraphicalEditPart)selection);
+ }
+
+ return editparts;
+ }
+}
diff --git a/plugins/uml/org.eclipse.papyrus.diagram.common/src/org/eclipse/papyrus/diagram/common/part/UmlGmfDiagramEditor.java b/plugins/uml/org.eclipse.papyrus.diagram.common/src/org/eclipse/papyrus/diagram/common/part/UmlGmfDiagramEditor.java
index 29a49913dbe..cc34dbc14a4 100644
--- a/plugins/uml/org.eclipse.papyrus.diagram.common/src/org/eclipse/papyrus/diagram/common/part/UmlGmfDiagramEditor.java
+++ b/plugins/uml/org.eclipse.papyrus.diagram.common/src/org/eclipse/papyrus/diagram/common/part/UmlGmfDiagramEditor.java
@@ -7,15 +7,12 @@ import org.eclipse.emf.common.notify.Adapter;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.Notifier;
import org.eclipse.gef.KeyHandler;
-import org.eclipse.gef.KeyStroke;
-import org.eclipse.gmf.runtime.diagram.ui.resources.editor.parts.DiagramDocumentEditor;
import org.eclipse.gmf.runtime.notation.Diagram;
import org.eclipse.gmf.runtime.notation.NotationPackage;
import org.eclipse.papyrus.core.adaptor.gmf.SynchronizableGmfDiagramEditor;
import org.eclipse.papyrus.core.lifecycleevents.ISaveAndDirtyService;
import org.eclipse.papyrus.core.services.ServiceException;
import org.eclipse.papyrus.core.services.ServicesRegistry;
-import org.eclipse.swt.SWT;
/**
@@ -120,11 +117,8 @@ public class UmlGmfDiagramEditor extends SynchronizableGmfDiagramEditor {
*/
@Override
protected KeyHandler getKeyHandler() {
- KeyHandler keyHandler = super.getKeyHandler();
- //removes binding provided by GMF in order to avoid conflicting keybinding
- if(keyHandler != null) {
- keyHandler.remove(KeyStroke.getPressed(SWT.DEL, 127, 0));
- }
+ //we remove all keybinding provided by GMF
+ KeyHandler keyHandler = new KeyHandler();
return keyHandler;
}
diff --git a/plugins/uml/org.eclipse.papyrus.diagram.common/src/org/eclipse/papyrus/diagram/common/providers/ActionStateSourceProvider.java b/plugins/uml/org.eclipse.papyrus.diagram.common/src/org/eclipse/papyrus/diagram/common/providers/ActionStateSourceProvider.java
index 13da8ad7ba0..c3ec93fbe24 100644
--- a/plugins/uml/org.eclipse.papyrus.diagram.common/src/org/eclipse/papyrus/diagram/common/providers/ActionStateSourceProvider.java
+++ b/plugins/uml/org.eclipse.papyrus.diagram.common/src/org/eclipse/papyrus/diagram/common/providers/ActionStateSourceProvider.java
@@ -14,6 +14,7 @@
package org.eclipse.papyrus.diagram.common.providers;
import org.eclipse.papyrus.diagram.common.handlers.DeleteFromDiagramCommandHandler;
+import org.eclipse.papyrus.diagram.common.handlers.RenamedElementHandler;
import org.eclipse.ui.ISources;
/**
@@ -27,10 +28,12 @@ import org.eclipse.ui.ISources;
public class ActionStateSourceProvider extends AbstractActionStateSourceProvider {
/**
- * The name of the variable to check.
+ * The name of the variables to check.
*/
public static final String DELETE_IN_DIAGRAM = "deleteInDiagram"; //$NON-NLS-1$
+ public static final String RENAME_NAMED_ELEMENT = "renameNamedElement";//$NON-NLS-1$
+
/**
*
* Constructor.
@@ -39,6 +42,7 @@ public class ActionStateSourceProvider extends AbstractActionStateSourceProvider
public ActionStateSourceProvider() {
super();
currentState.put(DELETE_IN_DIAGRAM, DISABLED);
+ currentState.put(RENAME_NAMED_ELEMENT, DISABLED);
}
@@ -50,7 +54,7 @@ public class ActionStateSourceProvider extends AbstractActionStateSourceProvider
*/
@Override
public String[] getProvidedSourceNames() {
- return new String[]{ DELETE_IN_DIAGRAM };
+ return new String[]{ DELETE_IN_DIAGRAM, RENAME_NAMED_ELEMENT };
}
@@ -86,5 +90,24 @@ public class ActionStateSourceProvider extends AbstractActionStateSourceProvider
@Override
protected void refreshActions() {
refreshDeleteAction();
+ refreshRenamedNamedElement();
+ }
+
+
+ /**
+ * Refresh the status of the handlers which listen {@link #RENAME_NAMED_ELEMENT}
+ */
+ protected void refreshRenamedNamedElement() {
+ RenamedElementHandler handler = new RenamedElementHandler();
+ boolean newValue = handler.isEnabled();
+
+ String oldState = currentState.get(RENAME_NAMED_ELEMENT);
+ String newState = (newValue ? ENABLED : DISABLED);
+
+ if(oldState != newState) {
+ currentState.put(RENAME_NAMED_ELEMENT, newState);
+ fireSourceChanged(ISources.WORKBENCH, currentState);
+ }
+
}
}

Back to the top