Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorvlorenzo2012-07-25 13:51:37 +0000
committervlorenzo2012-07-25 13:51:37 +0000
commit8dd6b4d209d4f146385548c14af384b0bb1535ae (patch)
tree6510741e79104bc1e1407a690e0d9c8f8dd7a2f7
parente8fe8836b6e51aa01eb4c68aa398b69306e0bcc2 (diff)
downloadorg.eclipse.papyrus-8dd6b4d209d4f146385548c14af384b0bb1535ae.tar.gz
org.eclipse.papyrus-8dd6b4d209d4f146385548c14af384b0bb1535ae.tar.xz
org.eclipse.papyrus-8dd6b4d209d4f146385548c14af384b0bb1535ae.zip
385726: [UML Compare] Add an action in the Diagram Menu to allow the comparison between to 2 UML Element
https://bugs.eclipse.org/bugs/show_bug.cgi?id=385726 Create the AdapterFactory in gmfdiag.common in order to be able do adapt EditPart to EObject in a plugin.xml
-rw-r--r--extraplugins/uml/compare/org.eclipse.papyrus.uml.compare/plugin.xml22
-rw-r--r--extraplugins/uml/compare/org.eclipse.papyrus.uml.compare/src/org/eclipse/papyrus/uml/compare/utils/UMLComparePropertyTester.java83
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/plugin.xml10
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/adapter/EditPartAdapterFactory.java65
4 files changed, 82 insertions, 98 deletions
diff --git a/extraplugins/uml/compare/org.eclipse.papyrus.uml.compare/plugin.xml b/extraplugins/uml/compare/org.eclipse.papyrus.uml.compare/plugin.xml
index 07bfe3075cc..184cf5af12c 100644
--- a/extraplugins/uml/compare/org.eclipse.papyrus.uml.compare/plugin.xml
+++ b/extraplugins/uml/compare/org.eclipse.papyrus.uml.compare/plugin.xml
@@ -51,11 +51,13 @@
<and>
<with
variable="selection">
- <test
- forcePluginActivation="true"
- property="org.eclipse.papyrus.uml.compare.property.isCorrectSelection"
- value="true">
- </test>
+ <iterate
+ ifEmpty="false"
+ operator="and">
+ <adapt
+ type="org.eclipse.emf.ecore.EObject">
+ </adapt>
+ </iterate>
</with>
<with
variable="activeEditorId">
@@ -69,15 +71,5 @@
</command>
</menuContribution>
</extension>
- <extension
- point="org.eclipse.core.expressions.propertyTesters">
- <propertyTester
- class="org.eclipse.papyrus.uml.compare.utils.UMLComparePropertyTester"
- id="org.eclipse.papyrus.uml.compare.property"
- namespace="org.eclipse.papyrus.uml.compare.property"
- properties="isCorrectSelection"
- type="org.eclipse.jface.viewers.IStructuredSelection">
- </propertyTester>
- </extension>
</plugin>
diff --git a/extraplugins/uml/compare/org.eclipse.papyrus.uml.compare/src/org/eclipse/papyrus/uml/compare/utils/UMLComparePropertyTester.java b/extraplugins/uml/compare/org.eclipse.papyrus.uml.compare/src/org/eclipse/papyrus/uml/compare/utils/UMLComparePropertyTester.java
deleted file mode 100644
index 67b168b3eb7..00000000000
--- a/extraplugins/uml/compare/org.eclipse.papyrus.uml.compare/src/org/eclipse/papyrus/uml/compare/utils/UMLComparePropertyTester.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/*****************************************************************************
- * 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:
- * Vincent Lorenzo (CEA LIST) Vincent.Lorenzo@cea.fr - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.uml.compare.utils;
-
-import java.util.Iterator;
-
-import org.eclipse.core.expressions.PropertyTester;
-import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.jface.viewers.IStructuredSelection;
-
-
-/*
- *
- *
- *TODO : should be replace by the correct test on the plugin.xml, when it will work (see bug 385744)
- * the correct test in the plugin.xml :
- * activeWhen
- * with selection
- * iterate
- * adapt to EObject
- */
-public class UMLComparePropertyTester extends PropertyTester {
-
- /**
- * The property to test
- */
- private static final String IS_CORRECT_SELECTION = "isCorrectSelection"; //$NON-NLS-1$
-
- /**
- *
- * @see org.eclipse.core.expressions.IPropertyTester#test(java.lang.Object, java.lang.String, java.lang.Object[], java.lang.Object)
- *
- * @param receiver
- * @param property
- * @param args
- * @param expectedValue
- * @return
- */
- public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
- if(IS_CORRECT_SELECTION.equals(property) && receiver instanceof IStructuredSelection && expectedValue instanceof Boolean) {
- return testCurrentSelection((IStructuredSelection)receiver).equals(expectedValue);
- }
- return false;
- }
-
- /**
- * Test the type of the diagram
- *
- * @param iEditor
- * the current editor
- * @param expectedValue
- * the expected value : the wanted diagram type
- * @return <code>true</code> if the current diagram has the wanted type
- */
- protected Boolean testCurrentSelection(final IStructuredSelection selection) {
- final Iterator<?> iterator = ((IStructuredSelection)selection).iterator();
- boolean answer = selection.size() == 2;
- while(iterator.hasNext() && answer) {
- Object current = iterator.next();
- if(current instanceof IAdaptable) {
- final Object eObject = ((IAdaptable)current).getAdapter(EObject.class);
- if(eObject == null) {
- answer = false;
- }
- } else {
- answer = false;
- }
- }
- return answer;
- }
-}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/plugin.xml b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/plugin.xml
index d3ceeda9930..eef272629d1 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/plugin.xml
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/plugin.xml
@@ -82,6 +82,16 @@
class="org.eclipse.papyrus.infra.gmfdiag.common.preferences.ConnectionToolPreferenceInitializer">
</initializer>
</extension>
+<extension
+ point="org.eclipse.core.runtime.adapters">
+ <factory
+ adaptableType="org.eclipse.gef.EditPart"
+ class="org.eclipse.papyrus.infra.gmfdiag.common.adapter.EditPartAdapterFactory">
+ <adapter
+ type="org.eclipse.emf.ecore.EObject">
+ </adapter>
+ </factory>
+</extension>
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/adapter/EditPartAdapterFactory.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/adapter/EditPartAdapterFactory.java
new file mode 100644
index 00000000000..cda10c3b3e2
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/adapter/EditPartAdapterFactory.java
@@ -0,0 +1,65 @@
+/*****************************************************************************
+ * 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:
+ * Vincent Lorenzo (CEA LIST) Vincent.Lorenzo@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.adapter;
+
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IAdapterFactory;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.gef.EditPart;
+
+/**
+ *
+ * This factory allows to get an EObject from an EditPart
+ * It is useful in the plugin.xml
+ *
+ * handler
+ * activeWhen
+ * with
+ * selection
+ * iterate
+ * adapt to EObject
+ *
+ * -> The handler is active when the selection can be adapted to EObject
+ *
+ * It is useful for action active on the EditPart in the Diagrams
+ *
+ */
+public class EditPartAdapterFactory implements IAdapterFactory {
+
+ /**
+ *
+ * @see org.eclipse.core.runtime.IAdapterFactory#getAdapter(java.lang.Object, java.lang.Class)
+ *
+ * @param adaptableObject
+ * @param adapterType
+ * @return
+ */
+ public Object getAdapter(Object adaptableObject, Class adapterType) {
+ if(adaptableObject instanceof EditPart && adaptableObject instanceof IAdaptable) {
+ return ((IAdaptable)adaptableObject).getAdapter(adapterType);
+ }
+ return null;
+ }
+
+ /**
+ *
+ * @see org.eclipse.core.runtime.IAdapterFactory#getAdapterList()
+ *
+ * @return
+ */
+ public Class<?>[] getAdapterList() {
+ return new Class[]{ EObject.class };
+ }
+
+}

Back to the top