Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcletavernie2012-08-23 06:04:01 -0400
committercletavernie2012-08-23 06:04:01 -0400
commit3aefe99e61689c91c0222194337a9c14febb3a2f (patch)
tree0e721fa3bb797491ffb4a1cbb5b259076cbfeead /plugins/infra
parent2aac2fd006ad05f69bcb43a7b01ea322148ecb86 (diff)
downloadorg.eclipse.papyrus-3aefe99e61689c91c0222194337a9c14febb3a2f.tar.gz
org.eclipse.papyrus-3aefe99e61689c91c0222194337a9c14febb3a2f.tar.xz
org.eclipse.papyrus-3aefe99e61689c91c0222194337a9c14febb3a2f.zip
386545: [Control Mode] The Control/Uncontrol menus have disappeared in Papyrus - 0.9.0
https://bugs.eclipse.org/bugs/show_bug.cgi?id=386545
Diffstat (limited to 'plugins/infra')
-rw-r--r--plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/plugin.xml28
-rw-r--r--plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/action/ControlModePropertyTester.java61
-rw-r--r--plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/action/PapyrusControlAction.java50
-rw-r--r--plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/action/PapyrusControlHandler.java32
-rw-r--r--plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/action/PapyrusUncontrolAction.java17
-rw-r--r--plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/action/PapyrusUncontrolHandler.java33
-rw-r--r--plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/util/ControlModeUtil.java105
7 files changed, 212 insertions, 114 deletions
diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/plugin.xml b/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/plugin.xml
index ea5423704e1..bbcfcee8ab9 100644
--- a/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/plugin.xml
+++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/plugin.xml
@@ -26,7 +26,14 @@
style="push"
tooltip="Split the model into an external model">
<visibleWhen
- checkEnabled="true">
+ checkEnabled="false">
+ <with
+ variable="selection">
+ <test
+ forcePluginActivation="true"
+ property="org.eclipse.papyrus.infra.services.controlmode.control">
+ </test>
+ </with>
</visibleWhen>
</command>
<command
@@ -35,10 +42,27 @@
style="push"
tooltip="Merge the external model with the current model">
<visibleWhen
- checkEnabled="true">
+ checkEnabled="false">
+ <with
+ variable="selection">
+ <test
+ forcePluginActivation="true"
+ property="org.eclipse.papyrus.infra.services.controlmode.uncontrol">
+ </test>
+ </with>
</visibleWhen>
</command>
</menuContribution>
</extension>
+ <extension
+ point="org.eclipse.core.expressions.propertyTesters">
+ <propertyTester
+ class="org.eclipse.papyrus.infra.services.controlmode.action.ControlModePropertyTester"
+ id="org.eclipse.papyrus.infra.services.controlmode"
+ namespace="org.eclipse.papyrus.infra.services.controlmode"
+ properties="control,uncontrol"
+ type="org.eclipse.jface.viewers.IStructuredSelection">
+ </propertyTester>
+ </extension>
</plugin>
diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/action/ControlModePropertyTester.java b/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/action/ControlModePropertyTester.java
new file mode 100644
index 00000000000..e7b8a2f9f0e
--- /dev/null
+++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/action/ControlModePropertyTester.java
@@ -0,0 +1,61 @@
+/*****************************************************************************
+ * 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 org.eclipse.core.expressions.PropertyTester;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
+import org.eclipse.papyrus.infra.services.controlmode.util.ControlModeUtil;
+
+/**
+ * A Property tester to determine whether the Control/Uncontrol actions
+ * are enabled
+ *
+ * @author Camille Letavernier
+ *
+ */
+public class ControlModePropertyTester extends PropertyTester {
+
+ private static final String CONTROl_PROPERTY = "control";
+
+ private static final String UNCONTROL_PROPERTY = "uncontrol";
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
+ if(receiver instanceof IStructuredSelection) {
+ IStructuredSelection selection = (IStructuredSelection)receiver;
+ if(selection.size() != 1) {
+ return false;
+ }
+
+ Object selectedElement = selection.getFirstElement();
+ EObject eObject = EMFHelper.getEObject(selectedElement);
+
+ if(eObject == null) {
+ return false;
+ }
+
+ if(CONTROl_PROPERTY.equals(property)) {
+ return ControlModeUtil.canControl(eObject);
+ } else if(UNCONTROL_PROPERTY.equals(property)) {
+ return ControlModeUtil.canUncontrol(eObject);
+ }
+ }
+
+ return false;
+ }
+
+
+}
diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/action/PapyrusControlAction.java b/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/action/PapyrusControlAction.java
index ae0226e3071..ed40b35dfa4 100644
--- a/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/action/PapyrusControlAction.java
+++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/action/PapyrusControlAction.java
@@ -13,16 +13,10 @@
*****************************************************************************/
package org.eclipse.papyrus.infra.services.controlmode.action;
-import java.util.LinkedList;
-import java.util.List;
-
import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.core.runtime.Platform;
import org.eclipse.emf.ecore.EAttribute;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
@@ -46,9 +40,8 @@ import org.eclipse.papyrus.infra.core.resource.ModelUtils;
import org.eclipse.papyrus.infra.core.resource.notation.NotationModel;
import org.eclipse.papyrus.infra.core.resource.uml.UmlModel;
import org.eclipse.papyrus.infra.core.utils.EditorUtils;
-import org.eclipse.papyrus.infra.services.controlmode.ControlModePlugin;
import org.eclipse.papyrus.infra.services.controlmode.commands.ControlCommand;
-import org.eclipse.papyrus.infra.services.controlmode.commands.IControlCondition;
+import org.eclipse.papyrus.infra.services.controlmode.util.ControlModeUtil;
import org.eclipse.papyrus.infra.widgets.toolbox.notification.NotificationRunnable;
import org.eclipse.papyrus.infra.widgets.toolbox.notification.Type;
import org.eclipse.papyrus.infra.widgets.toolbox.notification.builders.IContext;
@@ -61,18 +54,6 @@ import org.eclipse.ui.PlatformUI;
*/
public class PapyrusControlAction extends ControlAction {
- /** extension point ID for custom control command */
- private static final String CONTROL_CONDITION_EXTENSION_POINT_ID = "org.eclipse.papyrus.infra.services.controlmode.customControlCommand";
-
- /** attribute ID for the custom command class. */
- private static final String CONTROL_CONDITION_ATTRIBUTE_EXTENSION_POINT = "controlCondition";
-
- /** element ID for the custom command class. */
- private static final String CONTROL_CONDITION_ELEMENT_EXTENSION_POINT = "enableControlCommand";
-
- /** custom commands from extensions */
- /* package */static List<IControlCondition> commands;
-
/**
* Instantiates a new papyrus control action.
*
@@ -83,7 +64,6 @@ public class PapyrusControlAction extends ControlAction {
super(domain);
setDescription(EMFEditUIPlugin.INSTANCE.getString("_UI_Control_menu_item_description"));
setToolTipText("Split the model into an external model");
- commands = getCommandConditionsExtensions();
}
/**
@@ -91,12 +71,7 @@ public class PapyrusControlAction extends ControlAction {
*/
@Override
public boolean isEnabled() {
- boolean enableControl = true;
- for(IControlCondition cond : commands) {
- // check if action is disabled by an extension
- enableControl &= cond.enableControl(eObject);
- }
- return enableControl && getEditingDomain().isControllable(eObject) && !AdapterFactoryEditingDomain.isControlled(eObject);
+ return ControlModeUtil.canControl(eObject);
}
/**
@@ -277,25 +252,4 @@ public class PapyrusControlAction extends ControlAction {
return result;
}
- /**
- * Gets the conditions that enable control action
- *
- * @return the command extensions
- */
- private List<IControlCondition> getCommandConditionsExtensions() {
- List<IControlCondition> commands = new LinkedList<IControlCondition>();
- IConfigurationElement[] extensions = Platform.getExtensionRegistry().getConfigurationElementsFor(CONTROL_CONDITION_EXTENSION_POINT_ID);
- for(IConfigurationElement e : extensions) {
- if(CONTROL_CONDITION_ELEMENT_EXTENSION_POINT.equals(e.getName())) {
- try {
- IControlCondition controlCondition = (IControlCondition)e.createExecutableExtension(CONTROL_CONDITION_ATTRIBUTE_EXTENSION_POINT);
- commands.add(controlCondition);
- } catch (CoreException exception) {
- ControlModePlugin.log.error(exception);
- }
- }
- }
- return commands;
- }
-
}
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
index 7631670cded..1d1b7514a51 100644
--- 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
@@ -28,25 +28,10 @@ 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) {
+ Object evaluationContext = event.getApplicationContext();
if(evaluationContext instanceof IEvaluationContext) {
IEvaluationContext context = (IEvaluationContext)evaluationContext;
Object selection = context.getVariable(ISources.ACTIVE_CURRENT_SELECTION_NAME);
@@ -63,19 +48,16 @@ public class PapyrusControlHandler extends AbstractHandler {
}
}
- action = new PapyrusControlAction(domain);
+ PapyrusControlAction action = new PapyrusControlAction(domain);
action.updateSelection(currentSelection);
- setBaseEnabled(action.isEnabled());
+
+ if(action.isEnabled()) {
+ action.run();
+ }
}
- } else {
- setBaseEnabled(false);
}
- }
- @Override
- public void dispose() {
- super.dispose();
- action = null;
+ return null;
}
}
diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/action/PapyrusUncontrolAction.java b/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/action/PapyrusUncontrolAction.java
index fed7c1d7bd1..13d004c19c3 100644
--- a/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/action/PapyrusUncontrolAction.java
+++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/action/PapyrusUncontrolAction.java
@@ -31,9 +31,8 @@ import org.eclipse.papyrus.infra.core.resource.IModel;
import org.eclipse.papyrus.infra.core.resource.ModelUtils;
import org.eclipse.papyrus.infra.core.resource.uml.UmlModel;
import org.eclipse.papyrus.infra.core.utils.EditorUtils;
-import org.eclipse.papyrus.infra.services.controlmode.commands.IControlCondition;
-import org.eclipse.papyrus.infra.services.controlmode.commands.IControlUncontrolCondition;
import org.eclipse.papyrus.infra.services.controlmode.commands.UncontrolCommand;
+import org.eclipse.papyrus.infra.services.controlmode.util.ControlModeUtil;
import org.eclipse.papyrus.infra.widgets.toolbox.notification.Type;
import org.eclipse.papyrus.infra.widgets.toolbox.notification.builders.NotificationBuilder;
import org.eclipse.swt.widgets.Display;
@@ -68,15 +67,7 @@ public class PapyrusUncontrolAction extends CommandActionHandler {
*/
@Override
public boolean isEnabled() {
- boolean enableUnControl = true;
- for(IControlCondition cond : PapyrusControlAction.commands) {
- if (cond instanceof IControlUncontrolCondition) {
- IControlUncontrolCondition controlUnControl = (IControlUncontrolCondition) cond;
- // check if action is disabled by an extension
- enableUnControl &= controlUnControl.enableUnControl(eObject);
- }
- }
- return enableUnControl && getEditingDomain().isControllable(eObject) && AdapterFactoryEditingDomain.isControlled(eObject);
+ return ControlModeUtil.canUncontrol(eObject);
}
/**
@@ -93,7 +84,7 @@ public class PapyrusUncontrolAction extends CommandActionHandler {
if(selection.size() == 1) {
Object object = AdapterFactoryEditingDomain.unwrap(selection.getFirstElement());
if(object instanceof IAdaptable) {
- object = (EObject)((IAdaptable)object).getAdapter(EObject.class);
+ object = ((IAdaptable)object).getAdapter(EObject.class);
}
// Check whether the selected object is controllable
if(domain != null) {
@@ -130,7 +121,7 @@ public class PapyrusUncontrolAction extends CommandActionHandler {
boolean confirmDelete = MessageDialog.openQuestion(Display.getDefault().getActiveShell(), "Delete controlled resources?", "Delete the original controlled files ?");
UncontrolCommand transactionalCommand = new UncontrolCommand(EditorUtils.getTransactionalEditingDomain(), eObject, "Uncontrol", null, confirmDelete);
IStatus status = CheckedOperationHistory.getInstance().execute(transactionalCommand, new NullProgressMonitor(), null);
- if (!status.isOK()) {
+ if(!status.isOK()) {
NotificationBuilder.createErrorPopup(status.getMessage()).setTitle("Unable to uncontrol").run();
}
} catch (ExecutionException e) {
diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/action/PapyrusUncontrolHandler.java b/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/action/PapyrusUncontrolHandler.java
index 9eca15ac68c..a2dff718521 100644
--- a/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/action/PapyrusUncontrolHandler.java
+++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/action/PapyrusUncontrolHandler.java
@@ -27,25 +27,10 @@ import org.eclipse.ui.ISources;
* @author Camille Letavernier
*
*/
-//FIXME: Partial implementation to repair the Control/Uncontrol menu. Introduces several issues.
public class PapyrusUncontrolHandler extends AbstractHandler {
- //FIXME: EditingDomain is leaked here. The handler isn't destroyed after the editor is closed.
- PapyrusUncontrolAction action;
-
- public PapyrusUncontrolHandler() {
- setBaseEnabled(false);
- }
-
public Object execute(ExecutionEvent event) throws ExecutionException {
- if(action != null) {
- action.run();
- }
- return null;
- }
-
- @Override
- public void setEnabled(Object evaluationContext) {
+ Object evaluationContext = event.getApplicationContext();
if(evaluationContext instanceof IEvaluationContext) {
IEvaluationContext context = (IEvaluationContext)evaluationContext;
Object selection = context.getVariable(ISources.ACTIVE_CURRENT_SELECTION_NAME);
@@ -62,20 +47,16 @@ public class PapyrusUncontrolHandler extends AbstractHandler {
}
}
- action = new PapyrusUncontrolAction(domain);
+ PapyrusUncontrolAction action = new PapyrusUncontrolAction(domain);
action.updateSelection(currentSelection);
- setBaseEnabled(action.isEnabled());
+
+ if(action.isEnabled()) {
+ action.run();
+ }
}
- } else {
- setBaseEnabled(false);
}
- }
- @Override
- public void dispose() {
- System.out.println("Dispose");
- super.dispose();
- action = null;
+ return null;
}
}
diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/util/ControlModeUtil.java b/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/util/ControlModeUtil.java
new file mode 100644
index 00000000000..d0f68053c9a
--- /dev/null
+++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/util/ControlModeUtil.java
@@ -0,0 +1,105 @@
+/*****************************************************************************
+ * 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.util;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
+import org.eclipse.papyrus.infra.services.controlmode.ControlModePlugin;
+import org.eclipse.papyrus.infra.services.controlmode.commands.IControlCondition;
+import org.eclipse.papyrus.infra.services.controlmode.commands.IControlUncontrolCondition;
+
+/**
+ *
+ * @author Camille Letavernier
+ *
+ */
+public class ControlModeUtil {
+
+ /** extension point ID for custom control command */
+ private static final String CONTROL_CONDITION_EXTENSION_POINT_ID = "org.eclipse.papyrus.infra.services.controlmode.customControlCommand";
+
+ /** attribute ID for the custom command class. */
+ private static final String CONTROL_CONDITION_ATTRIBUTE_EXTENSION_POINT = "controlCondition";
+
+ /** element ID for the custom command class. */
+ private static final String CONTROL_CONDITION_ELEMENT_EXTENSION_POINT = "enableControlCommand";
+
+ private static List<IControlCondition> commands = getCommandConditionsExtensions();
+
+ /**
+ * Tests whether the parameter EObject can be controlled
+ *
+ * @param eObject
+ * @return
+ */
+ public static boolean canControl(EObject eObject) {
+ boolean enableControl = true;
+ for(IControlCondition cond : commands) {
+ // check if action is disabled by an extension
+ enableControl &= cond.enableControl(eObject);
+ }
+
+ EditingDomain domain = EMFHelper.resolveEditingDomain(eObject);
+
+ return enableControl && domain.isControllable(eObject) && !AdapterFactoryEditingDomain.isControlled(eObject);
+ }
+
+ /**
+ * Tests whether the parameter EObject can be uncontrolled
+ *
+ * @param eObject
+ * @return
+ */
+ public static boolean canUncontrol(EObject eObject) {
+ boolean enableUnControl = true;
+ for(IControlCondition cond : commands) {
+ if(cond instanceof IControlUncontrolCondition) {
+ IControlUncontrolCondition controlUnControl = (IControlUncontrolCondition)cond;
+ // check if action is disabled by an extension
+ enableUnControl &= controlUnControl.enableUnControl(eObject);
+ }
+ }
+
+ EditingDomain domain = EMFHelper.resolveEditingDomain(eObject);
+
+ return enableUnControl && domain.isControllable(eObject) && AdapterFactoryEditingDomain.isControlled(eObject);
+ }
+
+ /**
+ * Gets the conditions that enable control action
+ *
+ * @return the command extensions
+ */
+ private static List<IControlCondition> getCommandConditionsExtensions() {
+ List<IControlCondition> commands = new LinkedList<IControlCondition>();
+ IConfigurationElement[] extensions = Platform.getExtensionRegistry().getConfigurationElementsFor(CONTROL_CONDITION_EXTENSION_POINT_ID);
+ for(IConfigurationElement e : extensions) {
+ if(CONTROL_CONDITION_ELEMENT_EXTENSION_POINT.equals(e.getName())) {
+ try {
+ IControlCondition controlCondition = (IControlCondition)e.createExecutableExtension(CONTROL_CONDITION_ATTRIBUTE_EXTENSION_POINT);
+ commands.add(controlCondition);
+ } catch (CoreException exception) {
+ ControlModePlugin.log.error(exception);
+ }
+ }
+ }
+ return commands;
+ }
+}

Back to the top