Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcletavernie2013-06-07 11:45:48 +0000
committercletavernie2013-06-07 11:45:48 +0000
commit9a664b0bf7fa243562236f6732ed0d9a88de335d (patch)
tree99d95f821f42f5b67d148e882859afd93217ecca /plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.commands
parent3405063be1022530353a9ef4cc612ff277a5761f (diff)
downloadorg.eclipse.papyrus-9a664b0bf7fa243562236f6732ed0d9a88de335d.tar.gz
org.eclipse.papyrus-9a664b0bf7fa243562236f6732ed0d9a88de335d.tar.xz
org.eclipse.papyrus-9a664b0bf7fa243562236f6732ed0d9a88de335d.zip
404142: [sasheditor] Rename diagram command from sash tab
https://bugs.eclipse.org/bugs/show_bug.cgi?id=404142 Propagate the feature to the Table (Initial/Partial contribution)
Diffstat (limited to 'plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.commands')
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.commands/plugin.xml16
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.commands/src/org/eclipse/papyrus/commands/RenameDiagramHandler.java150
2 files changed, 85 insertions, 81 deletions
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 214f131e19c..f8f60be4ccb 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
@@ -7,15 +7,15 @@
<handler
class="org.eclipse.papyrus.commands.RenameDiagramHandler"
commandId="org.eclipse.papyrus.infra.core.sasheditor.command.tabdoubleclick">
+ <activeWhen>
+ <with
+ variable="activeEditor">
+ <adapt
+ type="org.eclipse.gmf.runtime.notation.Diagram">
+ </adapt>
+ </with>
+ </activeWhen>
</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/RenameDiagramHandler.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.commands/src/org/eclipse/papyrus/commands/RenameDiagramHandler.java
index a3d9b9f4ff6..d024d4bd6de 100644
--- 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
@@ -35,9 +35,11 @@ import org.eclipse.ui.IEditorPart;
* 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
+ * 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 {
@@ -50,16 +52,17 @@ public class RenameDiagramHandler extends AbstractHandler {
*/
public Object execute(ExecutionEvent event) throws ExecutionException {
executeTransaction(event);
-
+
return null;
}
/**
* Execute as transaction
- * @param event
+ *
+ * @param event
*/
private void executeTransaction(ExecutionEvent event) {
-
+
// Get requested objects
final Diagram notationDiagramHelper;
TransactionalEditingDomain editingDomain;
@@ -74,7 +77,7 @@ public class RenameDiagramHandler extends AbstractHandler {
// silently fails
return;
}
-
+
// Open the dialog to ask the new name
String currentName = notationDiagramHelper.getName();
String newName = null;
@@ -84,30 +87,29 @@ public class RenameDiagramHandler extends AbstractHandler {
if(newName == null || newName.length() <= 0) {
return;
}
- }
- else {
+ } else {
// cancelled
return;
}
-
- final String name = newName;
+
+ 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
+ * Get the name used in the {@link RecordingCommand}. This name will be visible in
* undo/redo.
*
* @return The command name to show.
@@ -116,15 +118,15 @@ public class RenameDiagramHandler extends AbstractHandler {
return Messages.RenameDiagramHandler_RenameDiagram;
}
- protected IEvaluationContext getIEvaluationContext(ExecutionEvent event) throws NotFoundException {
- try {
- return (IEvaluationContext)event.getApplicationContext();
- } catch (ClassCastException e) {
- throw new NotFoundException("IEvaluationContext can't be found."); //$NON-NLS-1$
- }
-
+ protected IEvaluationContext getIEvaluationContext(ExecutionEvent event) throws NotFoundException {
+ try {
+ return (IEvaluationContext)event.getApplicationContext();
+ } catch (ClassCastException e) {
+ throw new NotFoundException("IEvaluationContext can't be found."); //$NON-NLS-1$
}
+ }
+
// /**
// *
// * @return
@@ -135,81 +137,83 @@ public class RenameDiagramHandler extends AbstractHandler {
// 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"); //$NON-NLS-1$
- }
- DiagramDocumentEditor diagramEditor = (DiagramDocumentEditor)editor;
-
- Diagram diagram = diagramEditor.getDiagram();
- if(diagram == null) {
- throw new NotFoundException("Selected editor do not contains Diagram"); //$NON-NLS-1$
- }
-
- // 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);
+ * 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"); //$NON-NLS-1$
}
+ DiagramDocumentEditor diagramEditor = (DiagramDocumentEditor)editor;
+
+ Diagram diagram = diagramEditor.getDiagram();
+ if(diagram == null) {
+ throw new NotFoundException("Selected editor do not contains Diagram"); //$NON-NLS-1$
+ }
+
+ // 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)) {
+
+ 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);
+ setBaseEnabled(false);
} catch (NotFoundException e) {
// Can't find ServiceRegistry: disable
- setBaseEnabled( false);
+ setBaseEnabled(false);
}
-
+
}
}

Back to the top