Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcdumoulin2013-06-04 22:28:00 +0000
committercdumoulin2013-06-04 22:28:00 +0000
commit86bc96a9feeb841c45736f3e15a1137ec639fdc3 (patch)
treebe625aeeaacbc8af42fed273aa5cb76bfdc22675 /plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.commands
parentf528de033db621d3dfdc497c5f655ee86d3577d4 (diff)
downloadorg.eclipse.papyrus-86bc96a9feeb841c45736f3e15a1137ec639fdc3.tar.gz
org.eclipse.papyrus-86bc96a9feeb841c45736f3e15a1137ec639fdc3.tar.xz
org.eclipse.papyrus-86bc96a9feeb841c45736f3e15a1137ec639fdc3.zip
ASSIGNED - bug 404142: [sasheditor] Rename diagram command from sash tab
https://bugs.eclipse.org/bugs/show_bug.cgi?id=404142 Rename works. - add a mechanism allowing to listen on mouse double click events from sashcontainer'tabs - add a listener listening on double click, and calling a predefined command. - add a rename handler class callable when the current editor denote a diagram. - associate the rename handler class to the rename predefined command id - add an observable List of IFolder. The IFolder are nevered removed (this is a bug). Need to correct this bug
Diffstat (limited to 'plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.commands')
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.commands/META-INF/MANIFEST.MF4
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.commands/plugin.xml15
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.commands/src/org/eclipse/papyrus/commands/NotFoundException.java76
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.commands/src/org/eclipse/papyrus/commands/RenameDiagramHandler.java219
4 files changed, 313 insertions, 1 deletions
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.commands/META-INF/MANIFEST.MF b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.commands/META-INF/MANIFEST.MF
index 3770cef769e..b8a0197777c 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.commands/META-INF/MANIFEST.MF
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.commands/META-INF/MANIFEST.MF
@@ -12,7 +12,9 @@ Require-Bundle: org.eclipse.ui.workbench,
org.eclipse.gmf.runtime.diagram.ui;bundle-version="1.5.0",
org.eclipse.papyrus.infra.core;bundle-version="0.10.0",
org.eclipse.papyrus.infra.emf;bundle-version="0.10.0",
- org.eclipse.papyrus.infra.core.sasheditor;bundle-version="0.10.0"
+ org.eclipse.papyrus.infra.core.sasheditor;bundle-version="0.10.0",
+ org.eclipse.core.expressions;bundle-version="3.4.500",
+ org.eclipse.gmf.runtime.diagram.ui.resources.editor
Bundle-Vendor: %providerName
Bundle-ActivationPolicy: lazy
Bundle-Version: 0.10.0.qualifier
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.commands/plugin.xml b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.commands/plugin.xml
index 9fef2c770d4..214f131e19c 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.commands/plugin.xml
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.commands/plugin.xml
@@ -2,5 +2,20 @@
<?eclipse version="3.4"?>
<plugin>
<extension-point id="operationApprover" name="operationApprover" schema="schema/operationApprover.exsd"/>
+ <extension
+ point="org.eclipse.ui.handlers">
+ <handler
+ class="org.eclipse.papyrus.commands.RenameDiagramHandler"
+ commandId="org.eclipse.papyrus.infra.core.sasheditor.command.tabdoubleclick">
+ </handler>
+ </extension>
+ <extension
+ point="org.eclipse.ui.commands">
+ <command
+ description="Rename the current Diagram"
+ id="org.eclipse.papyrus.infra.core.sasheditor.command.tabdoubleclick"
+ name="Rename Diagram">
+ </command>
+ </extension>
</plugin>
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.commands/src/org/eclipse/papyrus/commands/NotFoundException.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.commands/src/org/eclipse/papyrus/commands/NotFoundException.java
new file mode 100644
index 00000000000..50fea19ed0d
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.commands/src/org/eclipse/papyrus/commands/NotFoundException.java
@@ -0,0 +1,76 @@
+/*****************************************************************************
+ * Copyright (c) 2013 Cedric Dumoulin.
+ *
+ *
+ * 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:
+ * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.commands;
+
+
+/**
+ * @author cedric dumoulin
+ *
+ */
+public class NotFoundException extends Exception {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Constructor.
+ *
+ */
+ public NotFoundException() {
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param message
+ */
+ public NotFoundException(String message) {
+ super(message);
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param cause
+ */
+ public NotFoundException(Throwable cause) {
+ super(cause);
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param message
+ * @param cause
+ */
+ public NotFoundException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param message
+ * @param cause
+ * @param enableSuppression
+ * @param writableStackTrace
+ */
+ public NotFoundException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
+ super(message, cause, enableSuppression, writableStackTrace);
+ }
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.commands/src/org/eclipse/papyrus/commands/RenameDiagramHandler.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.commands/src/org/eclipse/papyrus/commands/RenameDiagramHandler.java
new file mode 100644
index 00000000000..a58f0628318
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.commands/src/org/eclipse/papyrus/commands/RenameDiagramHandler.java
@@ -0,0 +1,219 @@
+/*****************************************************************************
+ * Copyright (c) 2013 Cedric Dumoulin.
+ *
+ *
+ * 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:
+ * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.commands;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.expressions.IEvaluationContext;
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.transaction.RecordingCommand;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gmf.runtime.diagram.ui.resources.editor.parts.DiagramDocumentEditor;
+import org.eclipse.gmf.runtime.notation.Diagram;
+import org.eclipse.jface.dialogs.InputDialog;
+import org.eclipse.jface.window.Window;
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForIEvaluationContext;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.IEditorPart;
+
+/**
+ * This handler allows to rename a gmf diagram.
+ * The handler is activated when the current selection denote a gmf diagram.
+ *
+ * <br>
+ * There is another RenameHandler in Papyrus (for modelexplorer): /org.eclipse.papyrus.infra.gmfdiag.modelexplorer/src/org/eclipse/papyrus/infra/gmfdiag/modelexplorer/handlers/RenameDiagramHandler.java
+ * @author cedric dumoulin
+ *
+ */
+public class RenameDiagramHandler extends AbstractHandler {
+
+ public static String RenameDiagramHandler_NewName = "New name:";
+
+ public static String RenameDiagramHandler_RenameAnExistingDiagram = "Rename an existing diagram";
+
+
+ /**
+ * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
+ * @param event
+ * @return
+ * @throws ExecutionException
+ *
+ */
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ executeTransaction(event);
+
+ return null;
+ }
+
+ /**
+ * Execute as transaction
+ * @param event
+ */
+ private void executeTransaction(ExecutionEvent event) {
+
+ // Get requested objects
+ final Diagram notationDiagramHelper;
+ TransactionalEditingDomain editingDomain;
+ try {
+ IEvaluationContext context = getIEvaluationContext(event);
+ notationDiagramHelper = lookupNotationDiagramChecked(context);
+ editingDomain = lookupTransactionalEditingDomain(context);
+ } catch (NotFoundException e) {
+ // silently fails
+ return;
+ } catch (ServiceException e) {
+ // silently fails
+ return;
+ }
+
+ // Open the dialog to ask the new name
+ String currentName = notationDiagramHelper.getName();
+ String newName = null;
+ InputDialog dialog = new InputDialog(Display.getCurrent().getActiveShell(), RenameDiagramHandler_RenameAnExistingDiagram, RenameDiagramHandler_NewName, currentName, null);
+ if(dialog.open() == Window.OK) {
+ newName = dialog.getValue();
+ if(newName == null || newName.length() <= 0) {
+ return;
+ }
+ }
+ else {
+ // cancelled
+ return;
+ }
+
+ final String name = newName;
+ Command cmd = new RecordingCommand(editingDomain, getCommandName()) {
+
+ @Override
+ protected void doExecute() {
+ // Rename the diagram !
+ notationDiagramHelper.setName(name);
+ }
+
+
+ };
+
+ editingDomain.getCommandStack().execute(cmd);
+
+ }
+
+ /**
+ * Get the name used in the {@link RecordingCommand}. This name will be visible in
+ * undo/redo.
+ *
+ * @return The command name to show.
+ */
+ public String getCommandName() {
+ return "Rename Diagram";
+ }
+
+ protected IEvaluationContext getIEvaluationContext(ExecutionEvent event) throws NotFoundException {
+ try {
+ return (IEvaluationContext)event.getApplicationContext();
+ } catch (ClassCastException e) {
+ throw new NotFoundException("IEvaluationContext can't be found.");
+ }
+
+ }
+
+ // /**
+ // *
+ // * @return
+ // * @throws NotFoundException
+ // */
+ // protected LayerStackMngr lookupLayerStackMngrChecked() throws NotFoundException {
+ //
+ // return lookupLayersViewChecked().getLayerStackMngrChecked();
+ //
+ // }
+
+ /**
+ * Get the notation diagram helper.
+ * This method can be used from {@link #execute(ExecutionEvent)} or {@link #setEnabled(Object)}.
+ *
+ * @return The
+ * @throws NotFoundException
+ * @throws ServiceException
+ */
+ protected Diagram lookupNotationDiagramChecked(IEvaluationContext context) throws NotFoundException, ServiceException {
+
+
+ // Get page from the event !
+ // IWorkbenchPage page = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage();
+
+ IEditorPart editor = ServiceUtilsForIEvaluationContext.getInstance().getNestedActiveIEditorPart(context);
+
+ if( ! (editor instanceof DiagramDocumentEditor) ) {
+ throw new NotFoundException("Selected editor do not contains Diagram");
+ }
+ DiagramDocumentEditor diagramEditor = (DiagramDocumentEditor)editor;
+
+ Diagram diagram = diagramEditor.getDiagram();
+ if(diagram == null) {
+ throw new NotFoundException("Selected editor do not contains Diagram");
+ }
+
+ // Return a new instance of the Helper
+ return diagram;
+ }
+
+ /**
+ * Try to lookup the TransactionalEditingDomain.
+ * @return
+ * @throws ServiceException If the Editing domain can't be found.
+ */
+ protected TransactionalEditingDomain lookupTransactionalEditingDomain(IEvaluationContext context) throws ServiceException {
+
+ // Get page from the event !
+ // IWorkbenchPage page = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage();
+
+ return ServiceUtilsForIEvaluationContext.getInstance().getTransactionalEditingDomain(context);
+ }
+
+ /**
+ * Called by framework. Need to set the enabled flag.
+ *
+ * @see org.eclipse.core.commands.AbstractHandler#setEnabled(java.lang.Object)
+ *
+ * @param evaluationContext
+ */
+ @Override
+ public void setEnabled(Object evaluationContext) {
+
+ if( ! (evaluationContext instanceof IEvaluationContext)) {
+ setBaseEnabled(false);
+ return;
+ }
+
+ IEvaluationContext context = (IEvaluationContext)evaluationContext;
+
+ try {
+ // Try to get the diagram
+ lookupNotationDiagramChecked(context);
+
+ // ok, we got it.
+ setBaseEnabled(true);
+
+ } catch (ServiceException e) {
+ // Can't find ServiceRegistry: disable
+ setBaseEnabled( false);
+ } catch (NotFoundException e) {
+ // Can't find ServiceRegistry: disable
+ setBaseEnabled( false);
+ }
+
+ }
+}

Back to the top