Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'extraplugins/cdo/org.eclipse.papyrus.cdo.uml.diagram.ui/src/org/eclipse/papyrus/cdo/uml/diagram/internal/ui/handlers/NewModelHandler.java')
-rw-r--r--extraplugins/cdo/org.eclipse.papyrus.cdo.uml.diagram.ui/src/org/eclipse/papyrus/cdo/uml/diagram/internal/ui/handlers/NewModelHandler.java37
1 files changed, 25 insertions, 12 deletions
diff --git a/extraplugins/cdo/org.eclipse.papyrus.cdo.uml.diagram.ui/src/org/eclipse/papyrus/cdo/uml/diagram/internal/ui/handlers/NewModelHandler.java b/extraplugins/cdo/org.eclipse.papyrus.cdo.uml.diagram.ui/src/org/eclipse/papyrus/cdo/uml/diagram/internal/ui/handlers/NewModelHandler.java
index 75b2ee6ecb4..e273f8994e9 100644
--- a/extraplugins/cdo/org.eclipse.papyrus.cdo.uml.diagram.ui/src/org/eclipse/papyrus/cdo/uml/diagram/internal/ui/handlers/NewModelHandler.java
+++ b/extraplugins/cdo/org.eclipse.papyrus.cdo.uml.diagram.ui/src/org/eclipse/papyrus/cdo/uml/diagram/internal/ui/handlers/NewModelHandler.java
@@ -14,38 +14,51 @@ package org.eclipse.papyrus.cdo.uml.diagram.internal.ui.handlers;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.emf.cdo.CDOObject;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.wizard.WizardDialog;
+import org.eclipse.net4j.util.ui.UIUtil;
+import org.eclipse.papyrus.cdo.internal.core.CDOUtils;
import org.eclipse.papyrus.uml.diagram.wizards.InitModelWizard;
+import org.eclipse.ui.ISources;
import org.eclipse.ui.handlers.HandlerUtil;
/**
* This is the NewModelHandler type. Enjoy.
*/
-public class NewModelHandler
- extends AbstractHandler {
+public class NewModelHandler extends AbstractHandler {
public NewModelHandler() {
super();
}
- public Object execute(ExecutionEvent event)
- throws ExecutionException {
+ @Override
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ setEnabled(event.getApplicationContext());
- ISelection selection = HandlerUtil.getCurrentSelection(event);
- if (selection instanceof IStructuredSelection) {
- InitModelWizard wizard = new InitModelWizard();
+ if(isEnabled()) {
+ ISelection selection = HandlerUtil.getCurrentSelection(event);
+ if(selection instanceof IStructuredSelection) {
+ InitModelWizard wizard = new InitModelWizard();
- wizard.init(HandlerUtil.getActiveWorkbenchWindow(event)
- .getWorkbench(), (IStructuredSelection) selection);
+ wizard.init(HandlerUtil.getActiveWorkbenchWindow(event).getWorkbench(), (IStructuredSelection)selection);
- WizardDialog dlg = new WizardDialog(
- HandlerUtil.getActiveShell(event), wizard);
- dlg.open();
+ WizardDialog dlg = new WizardDialog(HandlerUtil.getActiveShell(event), wizard);
+ dlg.open();
+ }
}
return null;
}
+ @Override
+ public void setEnabled(Object evaluationContext) {
+ Object variable = HandlerUtil.getVariable(evaluationContext, ISources.ACTIVE_CURRENT_SELECTION_NAME);
+ ISelection selection = variable instanceof ISelection ? (ISelection)variable : StructuredSelection.EMPTY;
+ CDOObject cdoObject = CDOUtils.adapt(UIUtil.getElement(selection), CDOObject.class);
+
+ setBaseEnabled((cdoObject == null) || !CDOUtils.isReadOnly(cdoObject));
+ }
}

Back to the top