Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/action/PapyrusControlHandler.java')
-rw-r--r--plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/action/PapyrusControlHandler.java81
1 files changed, 81 insertions, 0 deletions
diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/action/PapyrusControlHandler.java b/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/action/PapyrusControlHandler.java
new file mode 100644
index 00000000000..7631670cded
--- /dev/null
+++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/action/PapyrusControlHandler.java
@@ -0,0 +1,81 @@
+/*****************************************************************************
+ * Copyright (c) 2012 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.services.controlmode.action;
+
+import java.util.Iterator;
+
+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.edit.domain.EditingDomain;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
+import org.eclipse.ui.ISources;
+
+
+/**
+ *
+ * @author Camille Letavernier
+ *
+ */
+//FIXME: Partial implementation to repair the Control/Uncontrol menu. Introduces several issues.
+public class PapyrusControlHandler extends AbstractHandler {
+
+ //FIXME: EditingDomain is leaked here. The handler isn't destroyed after the editor is closed.
+ PapyrusControlAction action;
+
+ public PapyrusControlHandler() {
+ setBaseEnabled(false);
+ }
+
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ if(action != null) {
+ action.run();
+ }
+ return null;
+ }
+
+ @Override
+ public void setEnabled(Object evaluationContext) {
+ if(evaluationContext instanceof IEvaluationContext) {
+ IEvaluationContext context = (IEvaluationContext)evaluationContext;
+ Object selection = context.getVariable(ISources.ACTIVE_CURRENT_SELECTION_NAME);
+ if(selection instanceof IStructuredSelection) {
+ IStructuredSelection currentSelection = (IStructuredSelection)selection;
+
+ EditingDomain domain = null;
+
+ Iterator<?> iterator = currentSelection.iterator();
+ while(iterator.hasNext()) {
+ domain = EMFHelper.resolveEditingDomain(iterator.next());
+ if(domain != null) {
+ break;
+ }
+ }
+
+ action = new PapyrusControlAction(domain);
+ action.updateSelection(currentSelection);
+ setBaseEnabled(action.isEnabled());
+ }
+ } else {
+ setBaseEnabled(false);
+ }
+ }
+
+ @Override
+ public void dispose() {
+ super.dispose();
+ action = null;
+ }
+
+}

Back to the top