Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorvlorenzo2012-02-22 15:36:10 +0000
committervlorenzo2012-02-22 15:36:10 +0000
commit0f7e353b757c39c33564585082cdcfde77ee67df (patch)
tree9efaf02fe8363bd7958ce0e80f1af6329f0c79f8
parent910d1b5f16013e34747288fc58294505ce73fd8d (diff)
downloadorg.eclipse.papyrus-0f7e353b757c39c33564585082cdcfde77ee67df.tar.gz
org.eclipse.papyrus-0f7e353b757c39c33564585082cdcfde77ee67df.tar.xz
org.eclipse.papyrus-0f7e353b757c39c33564585082cdcfde77ee67df.zip
371606: [UML Compare] Papyrus should provide a nested editor to compare 2 elements included in the same resource
https://bugs.eclipse.org/bugs/show_bug.cgi?id=371606
-rw-r--r--sandbox/org.eclipse.papyrus.infra.emf.compare.ui/.classpath2
-rw-r--r--sandbox/org.eclipse.papyrus.infra.emf.compare.ui/META-INF/MANIFEST.MF16
-rw-r--r--sandbox/org.eclipse.papyrus.infra.emf.compare.ui/plugin.xml29
-rw-r--r--sandbox/org.eclipse.papyrus.infra.emf.compare.ui/src/org/eclipse/papyrus/infra/emf/compare/ui/Activator.java1
-rw-r--r--sandbox/org.eclipse.papyrus.infra.emf.compare.ui/src/org/eclipse/papyrus/infra/emf/compare/ui/content/transactional/viewer/PapyrusContentMergeViewerCreator.java50
-rw-r--r--sandbox/org.eclipse.papyrus.infra.emf.compare.ui/src/org/eclipse/papyrus/infra/emf/compare/ui/content/transactional/viewer/PapyrusModelContentMergeTabFolder.java197
-rw-r--r--sandbox/org.eclipse.papyrus.infra.emf.compare.ui/src/org/eclipse/papyrus/infra/emf/compare/ui/content/transactional/viewer/PapyrusModelContentMergeViewer.java107
-rw-r--r--sandbox/org.eclipse.papyrus.infra.emf.compare.ui/src/org/eclipse/papyrus/infra/emf/compare/ui/content/viewer/PapyrusContentMergeViewerCreator.java50
-rw-r--r--sandbox/org.eclipse.papyrus.infra.emf.compare.ui/src/org/eclipse/papyrus/infra/emf/compare/ui/content/viewer/PapyrusModelContentMergeTabFolder.java197
-rw-r--r--sandbox/org.eclipse.papyrus.infra.emf.compare.ui/src/org/eclipse/papyrus/infra/emf/compare/ui/content/viewer/PapyrusModelContentMergeViewer.java107
-rw-r--r--sandbox/org.eclipse.papyrus.infra.emf.compare.ui/src/org/eclipse/papyrus/infra/emf/compare/ui/handler/CompareTwoElementsAction.java278
-rw-r--r--sandbox/org.eclipse.papyrus.infra.emf.compare.ui/src/org/eclipse/papyrus/infra/emf/compare/ui/provider/ElementContentMergeContentProvider.java90
-rw-r--r--sandbox/org.eclipse.papyrus.infra.emf.compare.ui/src/org/eclipse/papyrus/infra/emf/compare/ui/provider/StyledDiffLabelSwitch.java190
-rw-r--r--sandbox/org.eclipse.papyrus.infra.emf.compare.ui/src/org/eclipse/papyrus/infra/emf/compare/ui/provider/UMLStyledStructureLabelProvider.java100
14 files changed, 1405 insertions, 9 deletions
diff --git a/sandbox/org.eclipse.papyrus.infra.emf.compare.ui/.classpath b/sandbox/org.eclipse.papyrus.infra.emf.compare.ui/.classpath
index 2d1a4302f04..2e46cf78086 100644
--- a/sandbox/org.eclipse.papyrus.infra.emf.compare.ui/.classpath
+++ b/sandbox/org.eclipse.papyrus.infra.emf.compare.ui/.classpath
@@ -2,6 +2,6 @@
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
- <classpathentry kind="src" path="src"/>
+ <classpathentry excluding="org/eclipse/papyrus/infra/emf/compare/ui/provider/ElementContentMergeContentProvider.java|org/eclipse/papyrus/infra/emf/compare/ui/provider/StyledDiffLabelSwitch.java|org/eclipse/papyrus/infra/emf/compare/ui/provider/UMLStyledStructureLabelProvider.java" kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
diff --git a/sandbox/org.eclipse.papyrus.infra.emf.compare.ui/META-INF/MANIFEST.MF b/sandbox/org.eclipse.papyrus.infra.emf.compare.ui/META-INF/MANIFEST.MF
index 222cb901662..5a824ca9ab4 100644
--- a/sandbox/org.eclipse.papyrus.infra.emf.compare.ui/META-INF/MANIFEST.MF
+++ b/sandbox/org.eclipse.papyrus.infra.emf.compare.ui/META-INF/MANIFEST.MF
@@ -14,13 +14,15 @@ Require-Bundle: org.eclipse.compare,
org.eclipse.papyrus.infra.tools;bundle-version="0.9.0",
org.eclipse.emf.ecore,
org.eclipse.emf.facet.infra.query.core,
- org.eclipse.papyrus.infra.core.log
-Export-Package: org.eclipse.papyrus.infra.emf.compare.ui,org.eclipse.p
- apyrus.infra.emf.compare.ui.actions,org.eclipse.papyrus.infra.emf.com
- pare.ui.messages,org.eclipse.papyrus.infra.emf.compare.ui.provider,or
- g.eclipse.papyrus.infra.emf.compare.ui.structural.viewer,org.eclipse.
- papyrus.infra.emf.compare.ui.utils,org.eclipse.papyrus.infra.emf.comp
- are.ui.viewer
+ org.eclipse.papyrus.infra.core.log,
+ org.eclipse.emf.compare.match
+Export-Package: org.eclipse.papyrus.infra.emf.compare.ui,
+ org.eclipse.papyrus.infra.emf.compare.ui.actions,
+ org.eclipse.papyrus.infra.emf.compare.ui.content.viewer,
+ org.eclipse.papyrus.infra.emf.compare.ui.messages,
+ org.eclipse.papyrus.infra.emf.compare.ui.provider,
+ org.eclipse.papyrus.infra.emf.compare.ui.structural.viewer,
+ org.eclipse.papyrus.infra.emf.compare.ui.utils
Bundle-Vendor: Eclipse Modeling Project
Bundle-ActivationPolicy: lazy
Bundle-Version: 0.9.0.qualifier
diff --git a/sandbox/org.eclipse.papyrus.infra.emf.compare.ui/plugin.xml b/sandbox/org.eclipse.papyrus.infra.emf.compare.ui/plugin.xml
index 294f69de2c0..6a3040fb61d 100644
--- a/sandbox/org.eclipse.papyrus.infra.emf.compare.ui/plugin.xml
+++ b/sandbox/org.eclipse.papyrus.infra.emf.compare.ui/plugin.xml
@@ -3,7 +3,7 @@
<plugin>
<extension point="org.eclipse.compare.contentMergeViewers">
- <viewer class="org.eclipse.papyrus.infra.emf.compare.ui.viewer.PapyrusContentMergeViewerCreator" extensions="ecore, uml" id="org.eclipse.papyrus.infra.emf.compare.ui.papyrus.viewer" label="Papyrus Content Merge Viewer">
+ <viewer class="org.eclipse.papyrus.infra.emf.compare.ui.content.viewer.PapyrusContentMergeViewerCreator" extensions="ecore, uml" id="org.eclipse.papyrus.infra.emf.compare.ui.papyrus.viewer" label="Papyrus Content Merge Viewer">
</viewer>
</extension>
<extension point="org.eclipse.compare.structureMergeViewers">
@@ -18,4 +18,31 @@
<extension point="org.eclipse.emf.facet.infra.query.registration">
<modelqueryset file="resources/compare_diff.querySet"/>
</extension>
+ <extension
+ point="org.eclipse.ui.menus">
+ <menuContribution
+ allPopups="true"
+ locationURI="popup:org.eclipse.ui.popup.any">
+ <command
+ commandId="org.eclipse.compare.compareWithOther"
+ label="Papyrus Compare With Each Other"
+ style="push">
+ </command>
+ </menuContribution>
+ </extension>
+ <extension
+ point="org.eclipse.ui.handlers">
+ <handler
+ class="org.eclipse.papyrus.infra.emf.compare.ui.handler.CompareTwoElementsAction"
+ commandId="org.eclipse.compare.compareWithOther">
+ <activeWhen>
+ <with
+ variable="activePartId">
+ <equals
+ value="org.eclipse.papyrus.views.modelexplorer.modelexplorer">
+ </equals>
+ </with>
+ </activeWhen>
+ </handler>
+ </extension>
</plugin>
diff --git a/sandbox/org.eclipse.papyrus.infra.emf.compare.ui/src/org/eclipse/papyrus/infra/emf/compare/ui/Activator.java b/sandbox/org.eclipse.papyrus.infra.emf.compare.ui/src/org/eclipse/papyrus/infra/emf/compare/ui/Activator.java
index d96e182404d..d0cd3856e14 100644
--- a/sandbox/org.eclipse.papyrus.infra.emf.compare.ui/src/org/eclipse/papyrus/infra/emf/compare/ui/Activator.java
+++ b/sandbox/org.eclipse.papyrus.infra.emf.compare.ui/src/org/eclipse/papyrus/infra/emf/compare/ui/Activator.java
@@ -28,6 +28,7 @@ public class Activator extends AbstractUIPlugin {
/** the activator */
private static Activator plugin;
+ /**the log helper for this plugin*/
public static LogHelper log;
/**
diff --git a/sandbox/org.eclipse.papyrus.infra.emf.compare.ui/src/org/eclipse/papyrus/infra/emf/compare/ui/content/transactional/viewer/PapyrusContentMergeViewerCreator.java b/sandbox/org.eclipse.papyrus.infra.emf.compare.ui/src/org/eclipse/papyrus/infra/emf/compare/ui/content/transactional/viewer/PapyrusContentMergeViewerCreator.java
new file mode 100644
index 00000000000..3b38225439c
--- /dev/null
+++ b/sandbox/org.eclipse.papyrus.infra.emf.compare.ui/src/org/eclipse/papyrus/infra/emf/compare/ui/content/transactional/viewer/PapyrusContentMergeViewerCreator.java
@@ -0,0 +1,50 @@
+/*****************************************************************************
+ * Copyright (c) 2011 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.emf.compare.ui.content.transactional.viewer;
+
+import org.eclipse.compare.CompareConfiguration;
+import org.eclipse.compare.IViewerCreator;
+import org.eclipse.emf.compare.diff.metamodel.AbstractDiffExtension;
+import org.eclipse.emf.compare.diff.metamodel.UpdateReference;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.swt.widgets.Composite;
+
+/**
+ *
+ * This class allows to create the MergeViewer
+ *
+ */
+public class PapyrusContentMergeViewerCreator implements IViewerCreator {
+
+ /**
+ *
+ * Constructor.
+ *
+ */
+ public PapyrusContentMergeViewerCreator() {
+ //nothing to do
+ }
+
+ /**
+ *
+ * @see org.eclipse.compare.IViewerCreator#createViewer(org.eclipse.swt.widgets.Composite, org.eclipse.compare.CompareConfiguration)
+ *
+ * @param parent
+ * @param config
+ * @return
+ */
+ public Viewer createViewer(Composite parent, CompareConfiguration config) {
+ return new PapyrusModelContentMergeViewer(parent, config);
+ }
+}
diff --git a/sandbox/org.eclipse.papyrus.infra.emf.compare.ui/src/org/eclipse/papyrus/infra/emf/compare/ui/content/transactional/viewer/PapyrusModelContentMergeTabFolder.java b/sandbox/org.eclipse.papyrus.infra.emf.compare.ui/src/org/eclipse/papyrus/infra/emf/compare/ui/content/transactional/viewer/PapyrusModelContentMergeTabFolder.java
new file mode 100644
index 00000000000..a0fa33b31be
--- /dev/null
+++ b/sandbox/org.eclipse.papyrus.infra.emf.compare.ui/src/org/eclipse/papyrus/infra/emf/compare/ui/content/transactional/viewer/PapyrusModelContentMergeTabFolder.java
@@ -0,0 +1,197 @@
+/*****************************************************************************
+ * Copyright (c) 2010 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:
+ * Tatiana Fesenko (CEA LIST) - Initial API and implementation
+ * Vincent Lorenzo (CEA LIST) - 349650: [Papyrus Merge] IndexOfBoundException
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.emf.compare.ui.content.transactional.viewer;
+
+import java.lang.reflect.Constructor;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.emf.common.notify.AdapterFactory;
+import org.eclipse.emf.compare.diff.metamodel.ComparisonSnapshot;
+import org.eclipse.emf.compare.ui.TypedElementWrapper;
+import org.eclipse.emf.compare.ui.viewer.content.ModelContentMergeViewer;
+import org.eclipse.emf.compare.ui.viewer.content.part.IModelContentMergeViewerTab;
+import org.eclipse.emf.compare.ui.viewer.content.part.ModelContentMergeTabFolder;
+import org.eclipse.emf.compare.ui.viewer.content.part.diff.ModelContentMergeDiffTab;
+import org.eclipse.emf.compare.util.AdapterUtils;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.edit.ui.provider.AdapterFactoryContentProvider;
+import org.eclipse.jface.viewers.IBaseLabelProvider;
+import org.eclipse.jface.viewers.IContentProvider;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.papyrus.infra.emf.compare.ui.provider.ILabelProviderRefreshingViewer;
+import org.eclipse.papyrus.infra.emf.compare.ui.utils.LabelProviderUtil;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.PlatformUI;
+
+
+/**
+ * The Class UMLModelContentMergeTabFolder.
+ */
+public class PapyrusModelContentMergeTabFolder extends ModelContentMergeTabFolder {
+
+ /** The my uml viewer. */
+ protected final PapyrusModelContentMergeViewer myUMLViewer;
+
+ /** the label provider */
+ private ILabelProviderRefreshingViewer labelProvider;
+
+ /** the diff tab */
+ private ModelContentMergeDiffTab diffTab;
+
+ /**
+ * Instantiates a new uML model content merge tab folder.
+ *
+ * @param viewer
+ * the viewer
+ * @param composite
+ * the composite
+ * @param side
+ * the side
+ */
+ public PapyrusModelContentMergeTabFolder(ModelContentMergeViewer viewer, Composite composite, int side) {
+ super(viewer, composite, side);
+ myUMLViewer = (PapyrusModelContentMergeViewer)viewer;
+ }
+
+ /**
+ *
+ * @see org.eclipse.emf.compare.ui.viewer.content.part.ModelContentMergeTabFolder#createModelContentMergeDiffTab(org.eclipse.swt.widgets.Composite)
+ *
+ * @param parent
+ * @return
+ */
+ @Override
+ protected IModelContentMergeViewerTab createModelContentMergeDiffTab(Composite parent) {
+ diffTab = new ModelContentMergeDiffTab(parent, partSide, this);
+ diffTab.setContentProvider(createDiffTabContentProvider());
+ IEditorPart activeEditor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
+ labelProvider = (ILabelProviderRefreshingViewer)LabelProviderUtil.INSTANCE.getLabelProviderFor(activeEditor);
+ labelProvider.registerViewer(diffTab);
+ diffTab.setLabelProvider((IBaseLabelProvider)labelProvider);
+ return diffTab;
+
+ }
+
+ /**
+ *
+ * @see org.eclipse.emf.compare.ui.viewer.content.part.ModelContentMergeTabFolder#dispose()
+ *
+ */
+ @Override
+ public void dispose() {
+ labelProvider.unregisterViewer(diffTab);
+ diffTab = null;
+ labelProvider = null;
+ super.dispose();
+ }
+
+ /**
+ *
+ * @return
+ */
+ protected IContentProvider createDiffTabContentProvider() {
+ return new ModelContentMergeDiffTabContentProvider(AdapterUtils.getAdapterFactory());
+ }
+
+
+ /**
+ * This implementation of an {@link AdapterFactoryContentProvider} will strip ComparisonSnapshots out of
+ * the view.
+ *
+ * @author <a href="mailto:laurent.goubet@obeo.fr">Laurent Goubet</a>
+ */
+ //duplicate code from EMF-Compare :ModelContentMergeDiffTab.ModelContentMergeDiffTabContentProvider
+ public class ModelContentMergeDiffTabContentProvider extends AdapterFactoryContentProvider {
+
+ /**
+ * Default constructor. Delegates to the super implementation.
+ *
+ * @param factory
+ * Factory to get labels and icons from.
+ */
+ public ModelContentMergeDiffTabContentProvider(AdapterFactory factory) {
+ super(factory);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.edit.ui.provider.AdapterFactoryContentProvider#getElements(java.lang.Object)
+ */
+ @SuppressWarnings("unchecked")
+ @Override
+ public Object[] getElements(Object object) {
+ // overwritten to ensure contents of ResourceSets, List<Resource>, and Resource are correclty
+ // returned.
+ Object[] result = null;
+ if(object instanceof ResourceSet) {
+ final List<Resource> resources = ((ResourceSet)object).getResources();
+ final List<Resource> elements = new ArrayList<Resource>(resources.size());
+ for(final Resource resource : resources) {
+ if(resource.getContents().isEmpty() || !(resource.getContents().get(0) instanceof ComparisonSnapshot)) {
+ elements.add(resource);
+ }
+ }
+ result = elements.toArray();
+ } else if(object instanceof TypedElementWrapper) {
+ result = new Object[]{ ((EObject)object).eResource(), };
+ } else if(object instanceof List) {
+ // we may also display a list of resources
+ result = ((List)object).toArray();
+ } else if(object instanceof Resource) {
+ // return contents of resource
+ result = ((Resource)object).getContents().toArray();
+ } else {
+ result = super.getElements(object);
+ }
+ return result;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.edit.ui.provider.AdapterFactoryContentProvider#getChildren(java.lang.Object)
+ */
+ @Override
+ public Object[] getChildren(Object object) {
+ if(object instanceof Resource) {
+ return ((Resource)object).getContents().toArray();
+ }
+ return super.getChildren(object);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.edit.ui.provider.AdapterFactoryContentProvider#hasChildren(java.lang.Object)
+ */
+ @Override
+ public boolean hasChildren(Object object) {
+ if(object instanceof Resource) {
+ return ((Resource)object).getContents().size() > 0;
+ }
+ return super.hasChildren(object);
+ }
+ }
+
+ @Override
+ protected void fireSelectionChanged(SelectionChangedEvent event) {
+ // TODO Auto-generated method stub
+ super.fireSelectionChanged(event);
+ }
+}
diff --git a/sandbox/org.eclipse.papyrus.infra.emf.compare.ui/src/org/eclipse/papyrus/infra/emf/compare/ui/content/transactional/viewer/PapyrusModelContentMergeViewer.java b/sandbox/org.eclipse.papyrus.infra.emf.compare.ui/src/org/eclipse/papyrus/infra/emf/compare/ui/content/transactional/viewer/PapyrusModelContentMergeViewer.java
new file mode 100644
index 00000000000..d34b2a55c1a
--- /dev/null
+++ b/sandbox/org.eclipse.papyrus.infra.emf.compare.ui/src/org/eclipse/papyrus/infra/emf/compare/ui/content/transactional/viewer/PapyrusModelContentMergeViewer.java
@@ -0,0 +1,107 @@
+/*****************************************************************************
+ * Copyright (c) 2011 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.emf.compare.ui.content.transactional.viewer;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+
+import org.eclipse.compare.CompareConfiguration;
+import org.eclipse.emf.compare.ui.viewer.content.ModelContentMergeViewer;
+import org.eclipse.emf.compare.ui.viewer.content.part.ModelContentMergeTabFolder;
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.jface.action.ActionContributionItem;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.action.ToolBarManager;
+import org.eclipse.papyrus.infra.emf.compare.ui.actions.CustomizationAction;
+import org.eclipse.papyrus.infra.emf.compare.ui.utils.Utils;
+import org.eclipse.swt.events.DisposeEvent;
+import org.eclipse.swt.widgets.Composite;
+
+public class PapyrusModelContentMergeViewer extends ModelContentMergeViewer {
+
+ /** the list of the metamodels referenced in the compared files. this field is used by the Customization Manager */
+ private Collection<EPackage> metamodels;
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param parent
+ * @param config
+ */
+ public PapyrusModelContentMergeViewer(final Composite parent, final CompareConfiguration config) {
+ super(parent, config);
+ }
+
+
+ /**
+ * {@inheritDoc}
+ *
+ * @param input
+ * the input
+ */
+ @Override
+ public void setInput(final Object input) {
+ super.setInput(input);
+ metamodels = Utils.getMetamodelForCustomization(input, metamodels);
+ updateToolItems();
+ }
+
+ /**
+ *
+ * {@inheritDoc}
+ *
+ * @param composite
+ * @param side
+ * @return
+ */
+ @Override
+ protected ModelContentMergeTabFolder createModelContentMergeTabFolder(final Composite composite, final int side) {
+ return new PapyrusModelContentMergeTabFolder(this, composite, side);
+ }
+
+
+
+ /**
+ *
+ * {@inheritDoc} Add a toogle button to the toolbar to do the synchronization with the diagram
+ *
+ * @param tbm
+ * the toolbar manager
+ */
+ @Override
+ protected void createToolItems(final ToolBarManager tbm) {
+ //we add an action to change the applied customization
+ if(metamodels == null) {
+ metamodels = new HashSet<EPackage>();
+ }
+ final IAction customizationAction = new CustomizationAction(Collections.unmodifiableCollection(metamodels));
+ final ActionContributionItem customizationContributionItem = new ActionContributionItem(customizationAction);
+ tbm.insert(1, customizationContributionItem);
+ super.createToolItems(tbm);
+ }
+
+ /**
+ *
+ * @see org.eclipse.emf.compare.ui.viewer.content.ModelContentMergeViewer#handleDispose(org.eclipse.swt.events.DisposeEvent)
+ *
+ * @param event
+ */
+ @Override
+ protected void handleDispose(DisposeEvent event) {
+ metamodels.clear();
+ super.handleDispose(event);
+ }
+}
diff --git a/sandbox/org.eclipse.papyrus.infra.emf.compare.ui/src/org/eclipse/papyrus/infra/emf/compare/ui/content/viewer/PapyrusContentMergeViewerCreator.java b/sandbox/org.eclipse.papyrus.infra.emf.compare.ui/src/org/eclipse/papyrus/infra/emf/compare/ui/content/viewer/PapyrusContentMergeViewerCreator.java
new file mode 100644
index 00000000000..03b9dea210d
--- /dev/null
+++ b/sandbox/org.eclipse.papyrus.infra.emf.compare.ui/src/org/eclipse/papyrus/infra/emf/compare/ui/content/viewer/PapyrusContentMergeViewerCreator.java
@@ -0,0 +1,50 @@
+/*****************************************************************************
+ * Copyright (c) 2011 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.emf.compare.ui.content.viewer;
+
+import org.eclipse.compare.CompareConfiguration;
+import org.eclipse.compare.IViewerCreator;
+import org.eclipse.emf.compare.diff.metamodel.AbstractDiffExtension;
+import org.eclipse.emf.compare.diff.metamodel.UpdateReference;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.swt.widgets.Composite;
+
+/**
+ *
+ * This class allows to create the MergeViewer
+ *
+ */
+public class PapyrusContentMergeViewerCreator implements IViewerCreator {
+
+ /**
+ *
+ * Constructor.
+ *
+ */
+ public PapyrusContentMergeViewerCreator() {
+ //nothing to do
+ }
+
+ /**
+ *
+ * @see org.eclipse.compare.IViewerCreator#createViewer(org.eclipse.swt.widgets.Composite, org.eclipse.compare.CompareConfiguration)
+ *
+ * @param parent
+ * @param config
+ * @return
+ */
+ public Viewer createViewer(Composite parent, CompareConfiguration config) {
+ return new PapyrusModelContentMergeViewer(parent, config);
+ }
+}
diff --git a/sandbox/org.eclipse.papyrus.infra.emf.compare.ui/src/org/eclipse/papyrus/infra/emf/compare/ui/content/viewer/PapyrusModelContentMergeTabFolder.java b/sandbox/org.eclipse.papyrus.infra.emf.compare.ui/src/org/eclipse/papyrus/infra/emf/compare/ui/content/viewer/PapyrusModelContentMergeTabFolder.java
new file mode 100644
index 00000000000..cbde851fa45
--- /dev/null
+++ b/sandbox/org.eclipse.papyrus.infra.emf.compare.ui/src/org/eclipse/papyrus/infra/emf/compare/ui/content/viewer/PapyrusModelContentMergeTabFolder.java
@@ -0,0 +1,197 @@
+/*****************************************************************************
+ * Copyright (c) 2010 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:
+ * Tatiana Fesenko (CEA LIST) - Initial API and implementation
+ * Vincent Lorenzo (CEA LIST) - 349650: [Papyrus Merge] IndexOfBoundException
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.emf.compare.ui.content.viewer;
+
+import java.lang.reflect.Constructor;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.emf.common.notify.AdapterFactory;
+import org.eclipse.emf.compare.diff.metamodel.ComparisonSnapshot;
+import org.eclipse.emf.compare.ui.TypedElementWrapper;
+import org.eclipse.emf.compare.ui.viewer.content.ModelContentMergeViewer;
+import org.eclipse.emf.compare.ui.viewer.content.part.IModelContentMergeViewerTab;
+import org.eclipse.emf.compare.ui.viewer.content.part.ModelContentMergeTabFolder;
+import org.eclipse.emf.compare.ui.viewer.content.part.diff.ModelContentMergeDiffTab;
+import org.eclipse.emf.compare.util.AdapterUtils;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.edit.ui.provider.AdapterFactoryContentProvider;
+import org.eclipse.jface.viewers.IBaseLabelProvider;
+import org.eclipse.jface.viewers.IContentProvider;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.papyrus.infra.emf.compare.ui.provider.ILabelProviderRefreshingViewer;
+import org.eclipse.papyrus.infra.emf.compare.ui.utils.LabelProviderUtil;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.PlatformUI;
+
+
+/**
+ * The Class UMLModelContentMergeTabFolder.
+ */
+public class PapyrusModelContentMergeTabFolder extends ModelContentMergeTabFolder {
+
+ /** The my uml viewer. */
+ protected final PapyrusModelContentMergeViewer myUMLViewer;
+
+ /** the label provider */
+ private ILabelProviderRefreshingViewer labelProvider;
+
+ /** the diff tab */
+ private ModelContentMergeDiffTab diffTab;
+
+ /**
+ * Instantiates a new uML model content merge tab folder.
+ *
+ * @param viewer
+ * the viewer
+ * @param composite
+ * the composite
+ * @param side
+ * the side
+ */
+ public PapyrusModelContentMergeTabFolder(ModelContentMergeViewer viewer, Composite composite, int side) {
+ super(viewer, composite, side);
+ myUMLViewer = (PapyrusModelContentMergeViewer)viewer;
+ }
+
+ /**
+ *
+ * @see org.eclipse.emf.compare.ui.viewer.content.part.ModelContentMergeTabFolder#createModelContentMergeDiffTab(org.eclipse.swt.widgets.Composite)
+ *
+ * @param parent
+ * @return
+ */
+ @Override
+ protected IModelContentMergeViewerTab createModelContentMergeDiffTab(Composite parent) {
+ diffTab = new ModelContentMergeDiffTab(parent, partSide, this);
+ diffTab.setContentProvider(createDiffTabContentProvider());
+ IEditorPart activeEditor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
+ labelProvider = (ILabelProviderRefreshingViewer)LabelProviderUtil.INSTANCE.getLabelProviderFor(activeEditor);
+ labelProvider.registerViewer(diffTab);
+ diffTab.setLabelProvider((IBaseLabelProvider)labelProvider);
+ return diffTab;
+
+ }
+
+ /**
+ *
+ * @see org.eclipse.emf.compare.ui.viewer.content.part.ModelContentMergeTabFolder#dispose()
+ *
+ */
+ @Override
+ public void dispose() {
+ labelProvider.unregisterViewer(diffTab);
+ diffTab = null;
+ labelProvider = null;
+ super.dispose();
+ }
+
+ /**
+ *
+ * @return
+ */
+ protected IContentProvider createDiffTabContentProvider() {
+ return new ModelContentMergeDiffTabContentProvider(AdapterUtils.getAdapterFactory());
+ }
+
+
+ /**
+ * This implementation of an {@link AdapterFactoryContentProvider} will strip ComparisonSnapshots out of
+ * the view.
+ *
+ * @author <a href="mailto:laurent.goubet@obeo.fr">Laurent Goubet</a>
+ */
+ //duplicate code from EMF-Compare :ModelContentMergeDiffTab.ModelContentMergeDiffTabContentProvider
+ public class ModelContentMergeDiffTabContentProvider extends AdapterFactoryContentProvider {
+
+ /**
+ * Default constructor. Delegates to the super implementation.
+ *
+ * @param factory
+ * Factory to get labels and icons from.
+ */
+ public ModelContentMergeDiffTabContentProvider(AdapterFactory factory) {
+ super(factory);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.edit.ui.provider.AdapterFactoryContentProvider#getElements(java.lang.Object)
+ */
+ @SuppressWarnings("unchecked")
+ @Override
+ public Object[] getElements(Object object) {
+ // overwritten to ensure contents of ResourceSets, List<Resource>, and Resource are correclty
+ // returned.
+ Object[] result = null;
+ if(object instanceof ResourceSet) {
+ final List<Resource> resources = ((ResourceSet)object).getResources();
+ final List<Resource> elements = new ArrayList<Resource>(resources.size());
+ for(final Resource resource : resources) {
+ if(resource.getContents().isEmpty() || !(resource.getContents().get(0) instanceof ComparisonSnapshot)) {
+ elements.add(resource);
+ }
+ }
+ result = elements.toArray();
+ } else if(object instanceof TypedElementWrapper) {
+ result = new Object[]{ ((EObject)object).eResource(), };
+ } else if(object instanceof List) {
+ // we may also display a list of resources
+ result = ((List)object).toArray();
+ } else if(object instanceof Resource) {
+ // return contents of resource
+ result = ((Resource)object).getContents().toArray();
+ } else {
+ result = super.getElements(object);
+ }
+ return result;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.edit.ui.provider.AdapterFactoryContentProvider#getChildren(java.lang.Object)
+ */
+ @Override
+ public Object[] getChildren(Object object) {
+ if(object instanceof Resource) {
+ return ((Resource)object).getContents().toArray();
+ }
+ return super.getChildren(object);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.edit.ui.provider.AdapterFactoryContentProvider#hasChildren(java.lang.Object)
+ */
+ @Override
+ public boolean hasChildren(Object object) {
+ if(object instanceof Resource) {
+ return ((Resource)object).getContents().size() > 0;
+ }
+ return super.hasChildren(object);
+ }
+ }
+
+ @Override
+ protected void fireSelectionChanged(SelectionChangedEvent event) {
+ // TODO Auto-generated method stub
+ super.fireSelectionChanged(event);
+ }
+}
diff --git a/sandbox/org.eclipse.papyrus.infra.emf.compare.ui/src/org/eclipse/papyrus/infra/emf/compare/ui/content/viewer/PapyrusModelContentMergeViewer.java b/sandbox/org.eclipse.papyrus.infra.emf.compare.ui/src/org/eclipse/papyrus/infra/emf/compare/ui/content/viewer/PapyrusModelContentMergeViewer.java
new file mode 100644
index 00000000000..ec18fd24f89
--- /dev/null
+++ b/sandbox/org.eclipse.papyrus.infra.emf.compare.ui/src/org/eclipse/papyrus/infra/emf/compare/ui/content/viewer/PapyrusModelContentMergeViewer.java
@@ -0,0 +1,107 @@
+/*****************************************************************************
+ * Copyright (c) 2011 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.emf.compare.ui.content.viewer;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+
+import org.eclipse.compare.CompareConfiguration;
+import org.eclipse.emf.compare.ui.viewer.content.ModelContentMergeViewer;
+import org.eclipse.emf.compare.ui.viewer.content.part.ModelContentMergeTabFolder;
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.jface.action.ActionContributionItem;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.action.ToolBarManager;
+import org.eclipse.papyrus.infra.emf.compare.ui.actions.CustomizationAction;
+import org.eclipse.papyrus.infra.emf.compare.ui.utils.Utils;
+import org.eclipse.swt.events.DisposeEvent;
+import org.eclipse.swt.widgets.Composite;
+
+public class PapyrusModelContentMergeViewer extends ModelContentMergeViewer {
+
+ /** the list of the metamodels referenced in the compared files. this field is used by the Customization Manager */
+ private Collection<EPackage> metamodels;
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param parent
+ * @param config
+ */
+ public PapyrusModelContentMergeViewer(final Composite parent, final CompareConfiguration config) {
+ super(parent, config);
+ }
+
+
+ /**
+ * {@inheritDoc}
+ *
+ * @param input
+ * the input
+ */
+ @Override
+ public void setInput(final Object input) {
+ super.setInput(input);
+ metamodels = Utils.getMetamodelForCustomization(input, metamodels);
+ updateToolItems();
+ }
+
+ /**
+ *
+ * {@inheritDoc}
+ *
+ * @param composite
+ * @param side
+ * @return
+ */
+ @Override
+ protected ModelContentMergeTabFolder createModelContentMergeTabFolder(final Composite composite, final int side) {
+ return new PapyrusModelContentMergeTabFolder(this, composite, side);
+ }
+
+
+
+ /**
+ *
+ * {@inheritDoc} Add a toogle button to the toolbar to do the synchronization with the diagram
+ *
+ * @param tbm
+ * the toolbar manager
+ */
+ @Override
+ protected void createToolItems(final ToolBarManager tbm) {
+ //we add an action to change the applied customization
+ if(metamodels == null) {
+ metamodels = new HashSet<EPackage>();
+ }
+ final IAction customizationAction = new CustomizationAction(Collections.unmodifiableCollection(metamodels));
+ final ActionContributionItem customizationContributionItem = new ActionContributionItem(customizationAction);
+ tbm.insert(1, customizationContributionItem);
+ super.createToolItems(tbm);
+ }
+
+ /**
+ *
+ * @see org.eclipse.emf.compare.ui.viewer.content.ModelContentMergeViewer#handleDispose(org.eclipse.swt.events.DisposeEvent)
+ *
+ * @param event
+ */
+ @Override
+ protected void handleDispose(DisposeEvent event) {
+ metamodels.clear();
+ super.handleDispose(event);
+ }
+}
diff --git a/sandbox/org.eclipse.papyrus.infra.emf.compare.ui/src/org/eclipse/papyrus/infra/emf/compare/ui/handler/CompareTwoElementsAction.java b/sandbox/org.eclipse.papyrus.infra.emf.compare.ui/src/org/eclipse/papyrus/infra/emf/compare/ui/handler/CompareTwoElementsAction.java
new file mode 100644
index 00000000000..736bebbefb9
--- /dev/null
+++ b/sandbox/org.eclipse.papyrus.infra.emf.compare.ui/src/org/eclipse/papyrus/infra/emf/compare/ui/handler/CompareTwoElementsAction.java
@@ -0,0 +1,278 @@
+/*****************************************************************************
+ * Copyright (c) 2010 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:
+ * Tatiana Fesenko (CEA LIST) - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.emf.compare.ui.handler;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.eclipse.compare.CompareUI;
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.emf.compare.EMFCompareException;
+import org.eclipse.emf.compare.diff.metamodel.ComparisonResourceSnapshot;
+import org.eclipse.emf.compare.diff.metamodel.ComparisonSnapshot;
+import org.eclipse.emf.compare.diff.metamodel.DiffFactory;
+import org.eclipse.emf.compare.diff.metamodel.DiffModel;
+import org.eclipse.emf.compare.diff.service.DiffService;
+import org.eclipse.emf.compare.match.MatchOptions;
+import org.eclipse.emf.compare.match.engine.GenericMatchScopeProvider;
+import org.eclipse.emf.compare.match.metamodel.MatchModel;
+import org.eclipse.emf.compare.match.service.MatchService;
+import org.eclipse.emf.compare.ui.editor.ModelCompareEditorInput;
+import org.eclipse.emf.compare.util.EMFCompareMap;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.papyrus.infra.emf.compare.ui.Activator;
+import org.eclipse.ui.PlatformUI;
+//import org.eclipse.papyrus.compare.diff.extension.UMLStyledStructureLabelProvider;
+//import org.eclipse.papyrus.compare.element.ElementContentDiffEngine;
+//import org.eclipse.papyrus.compare.element.ElementContentMatchEngine;
+//import org.eclipse.papyrus.compare.ui.Messages;
+//import org.eclipse.papyrus.compare.ui.PapyrusLabelProvider;
+//import org.eclipse.papyrus.compare.ui.viewer.content.ElementContentMergeContentProvider;
+//import org.eclipse.papyrus.compare.ui.viewer.content.UMLModelContentMergeViewer;
+
+/**
+ * Action to compare two arbitrary elements.
+ * Available in the context menu of the model explorer.
+ */
+public class CompareTwoElementsAction extends AbstractHandler {
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.team.internal.ui.actions.TeamAction#execute(org.eclipse.jface.action.IAction)
+ */
+ protected void execute(IAction action) throws InvocationTargetException, InterruptedException {
+ Object[] selectedElements = getSelection().toArray();
+ if(selectedElements.length != 2) {
+ Activator.log.info("Two elements should be selected.");
+ } else {
+ EObject left = getElementFor(selectedElements[0]);
+ EObject right = getElementFor(selectedElements[1]);
+ if(left == null) {
+ Activator.log.info("The left element is null. I can't do the comparison");
+ } else if(right == null) {
+ Activator.log.info("The right element is null. I can't do the comparison");
+ } else {
+ ComparisonResourceSnapshot snapshot = doContentCompare(left, right);
+ openInCompare(snapshot);
+ }
+ }
+ }
+
+ private Collection<Object> getSelection() {
+ ISelection selection = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService().getSelection();
+ Collection<Object> currentSelection = new ArrayList<Object>();
+ Iterator<?> iter = ((IStructuredSelection)selection).iterator();
+ while(iter.hasNext()) {
+ currentSelection.add(iter.next());
+ }
+ return currentSelection;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.commands.AbstractHandler#isEnabled()
+ */
+ public boolean isEnabled() {
+ Object[] selectedElements = getSelection().toArray();
+ if(selectedElements.length != 2) {
+ return false;
+ }
+ EObject left = getElementFor(selectedElements[0]);
+ EObject right = getElementFor(selectedElements[1]);
+ return left != null && right != null;
+ }
+
+ /**
+ * Open in compare.
+ *
+ * @param snapshot
+ * the snapshot
+ */
+ private void openInCompare(ComparisonSnapshot snapshot) {
+ ModelCompareEditorInput model = null;
+
+ CompareUI.openCompareEditor(new ModelCompareEditorInput(snapshot) {
+
+ //TODO : uncomment.
+ // @Override
+ // protected ModelContentMergeViewer createMergeViewer(CompareViewerPane pane, CompareConfiguration config) {
+ // return new PapyrusModelContentMergeViewer(pane, config) {
+ // @Override
+ // protected IMergeViewerContentProvider createMergeViewerContentProvider() {
+ // return new ElementContentMergeContentProvider(configuration);
+ // }
+ // };
+ // }
+ //
+ // @Override
+ // public Control createOutlineContents(Composite parent, int direction) {
+ // Control result = super.createOutlineContents(parent, direction);
+ // structureMergeViewer.setLabelProvider(new UMLStyledStructureLabelProvider(new PapyrusLabelProvider()));
+ // return result;
+ // }
+
+ });
+ }
+
+ /**
+ * Do content compare.
+ *
+ * @param left
+ * the left
+ * @param right
+ * the right
+ * @return the comparison resource snapshot
+ */
+ protected ComparisonResourceSnapshot doContentCompare(final EObject left, final EObject right) {
+ final ComparisonResourceSnapshot snapshot = DiffFactory.eINSTANCE.createComparisonResourceSnapshot();
+
+ try {
+ PlatformUI.getWorkbench().getProgressService().busyCursorWhile(new IRunnableWithProgress() {
+
+ public void run(IProgressMonitor monitor) throws InterruptedException {
+ // final MatchModel match = MatchService.doContentMatch(left, right, options);
+ // DiffModel diff = DiffService.doDiff(match);
+ final MatchModel match = contentMatch(left, right, monitor);
+ final DiffModel diff = contentDiff(left, right, match);
+
+ snapshot.setDiff(diff);
+ snapshot.setMatch(match);
+
+ }
+
+ });
+ } catch (final InterruptedException e) {
+ Activator.log.error(e);
+ } catch (final EMFCompareException e) {
+ Activator.log.error(e);
+ } catch (final InvocationTargetException e) {
+ Activator.log.error(e);
+ }
+
+ return snapshot;
+ }
+
+ /**
+ * Content diff.
+ *
+ * @param left
+ * the left
+ * @param right
+ * the right
+ * @param match
+ * the match
+ * @return the diff model
+ */
+ protected DiffModel contentDiff(final EObject left, final EObject right, final MatchModel match) {
+ //TODO
+ // ElementContentDiffEngine engine = new ElementContentDiffEngine(left, right);
+ // final DiffModel diff = engine.doDiff(match);
+ // final Collection<AbstractDiffExtension> extensions = DiffService.getCorrespondingDiffExtensions(match);
+ // for(final AbstractDiffExtension ext : extensions) {
+ // if(ext != null) {
+ // ext.visit(diff);
+ // }
+ // }
+ //
+ // engine.reset();
+ // return diff;
+ return null;
+ }
+
+ /**
+ * Content match.
+ *
+ * @param left
+ * the left
+ * @param right
+ * the right
+ * @param monitor
+ * the monitor
+ * @return the match model
+ * @throws InterruptedException
+ * the interrupted exception
+ */
+ protected MatchModel contentMatch(final EObject left, final EObject right, IProgressMonitor monitor) throws InterruptedException {
+ // final Map<String, Object> options = new EMFCompareMap<String, Object>();
+ // options.put(MatchOptions.OPTION_PROGRESS_MONITOR, monitor);
+ // options.put(MatchOptions.OPTION_MATCH_SCOPE_PROVIDER, new GenericMatchScopeProvider(left.eResource(), right.eResource()));
+ // options.put(MatchOptions.OPTION_IGNORE_ID, Boolean.TRUE);
+ // options.put(MatchOptions.OPTION_IGNORE_XMI_ID, Boolean.TRUE);
+ //
+ // final IMatchEngine matchEngine = new ElementContentMatchEngine(left, right);
+ // final MatchModel match = matchEngine.contentMatch(left, right, options);
+ // return match;
+ //TODO
+ return null;
+ }
+
+ /**
+ * Gets the element for.
+ *
+ * @param object
+ * the object
+ * @return the element for
+ */
+ protected EObject getElementFor(Object object) {
+ if(object instanceof IAdaptable) {
+ return (EObject)((IAdaptable)object).getAdapter(EObject.class);
+ }
+
+ if(object instanceof EObject) {
+ return (EObject)object;
+ }
+ return null;
+ }
+
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ Object[] selectedElements = getSelection().toArray();
+ if(selectedElements.length != 2) {
+ //TODO
+ // Activator.logInfo(Messages.bind(Messages.CompareTwoElementsAction_only_only_element_is_selected, selectedElements.length));
+ return null;
+ }
+
+ EObject left = getElementFor(selectedElements[0]);
+ EObject right = getElementFor(selectedElements[1]);
+ if(left == null) {
+ //TODO
+ // Activator.logInfo(Messages.CompareTwoElementsAction_left_element_is_null);
+ return null;
+ }
+
+ if(right == null) {
+ //TODO
+ // Activator.logInfo(Messages.CompareTwoElementsAction_right_element_is_null);
+ return null;
+ }
+
+ ComparisonResourceSnapshot snapshot = doContentCompare(left, right);
+ openInCompare(snapshot);
+ return null;
+ }
+
+}
diff --git a/sandbox/org.eclipse.papyrus.infra.emf.compare.ui/src/org/eclipse/papyrus/infra/emf/compare/ui/provider/ElementContentMergeContentProvider.java b/sandbox/org.eclipse.papyrus.infra.emf.compare.ui/src/org/eclipse/papyrus/infra/emf/compare/ui/provider/ElementContentMergeContentProvider.java
new file mode 100644
index 00000000000..eb264705fb8
--- /dev/null
+++ b/sandbox/org.eclipse.papyrus.infra.emf.compare.ui/src/org/eclipse/papyrus/infra/emf/compare/ui/provider/ElementContentMergeContentProvider.java
@@ -0,0 +1,90 @@
+/*****************************************************************************
+ * Copyright (c) 2010 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:
+ * Tatiana Fesenko (CEA LIST) - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.emf.compare.ui.provider;
+
+import org.eclipse.compare.CompareConfiguration;
+import org.eclipse.emf.compare.ui.ModelCompareInput;
+import org.eclipse.emf.compare.ui.viewer.content.ModelContentMergeContentProvider;
+import org.eclipse.papyrus.infra.emf.compare.ecore_diff_extension.CompareTwoElementsDiffModel;
+
+
+/**
+ * The ContentProvider used in the Merge Content Viewer.
+ */
+public class ElementContentMergeContentProvider extends ModelContentMergeContentProvider {
+
+ /**
+ * Instantiates a new element content merge content provider.
+ *
+ * @param cc the cc
+ */
+ public ElementContentMergeContentProvider(CompareConfiguration cc) {
+ super(cc);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.emf.compare.ui.viewer.content.ModelContentMergeContentProvider#getLeftContent(java.lang.Object)
+ */
+ @Override
+ public Object getLeftContent(Object element) {
+ //TODO verif this test!
+ if(element instanceof ModelCompareInput) {
+ // if we compared a complete resource set, we should display the different resources
+ final Object diff = ((ModelCompareInput)element).getDiff();
+ //Bug 336361 - [UML Compare] Compare two elements: show right element as root
+ if(diff instanceof CompareTwoElementsDiffModel) {
+ return new RootObject(((CompareTwoElementsDiffModel)diff).getLeftRoots().get(0));
+ }
+ }
+ return super.getLeftContent(element);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.emf.compare.ui.viewer.content.ModelContentMergeContentProvider#getRightContent(java.lang.Object)
+ */
+ @Override
+ public Object getRightContent(Object element) {
+ if(element instanceof ModelCompareInput) {
+ // if we compared a complete resource set, we should display the different resources
+ final Object diff = ((ModelCompareInput)element).getDiff();
+ //Bug 336361 - [UML Compare] Compare two elements: show right element as root
+ if(diff instanceof CompareTwoElementsDiffModel) {
+ return new RootObject(((CompareTwoElementsDiffModel)diff).getRightRoots().get(0));
+ }
+ }
+ return super.getRightContent(element);
+ }
+
+ /**
+ * The Class RootObject.
+ */
+ //Bug 336361 - [UML Compare] Compare two elements: show right element as root
+ //FIXME : why in static?!
+ public static class RootObject {
+
+ /** The object. */
+ public final Object object;
+
+ /**
+ * Instantiates a new root object.
+ *
+ * @param object the object
+ */
+ public RootObject(Object object) {
+ this.object = object;
+ }
+ }
+
+
+}
diff --git a/sandbox/org.eclipse.papyrus.infra.emf.compare.ui/src/org/eclipse/papyrus/infra/emf/compare/ui/provider/StyledDiffLabelSwitch.java b/sandbox/org.eclipse.papyrus.infra.emf.compare.ui/src/org/eclipse/papyrus/infra/emf/compare/ui/provider/StyledDiffLabelSwitch.java
new file mode 100644
index 00000000000..bae992a089e
--- /dev/null
+++ b/sandbox/org.eclipse.papyrus.infra.emf.compare.ui/src/org/eclipse/papyrus/infra/emf/compare/ui/provider/StyledDiffLabelSwitch.java
@@ -0,0 +1,190 @@
+/*****************************************************************************
+ * Copyright (c) 2010 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:
+ * Tatiana Fesenko (CEA LIST) - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.compare.diff.extension;
+
+import org.eclipse.emf.compare.diff.metamodel.AttributeChange;
+import org.eclipse.emf.compare.diff.metamodel.AttributeChangeLeftTarget;
+import org.eclipse.emf.compare.diff.metamodel.AttributeChangeRightTarget;
+import org.eclipse.emf.compare.diff.metamodel.DiffGroup;
+import org.eclipse.emf.compare.diff.metamodel.DiffPackage;
+import org.eclipse.emf.compare.diff.metamodel.ReferenceChange;
+import org.eclipse.emf.compare.diff.metamodel.UpdateAttribute;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.viewers.StyledString;
+import org.eclipse.papyrus.compare.Messages;
+import org.eclipse.papyrus.compare.StyledMessageFormat;
+import org.eclipse.papyrus.compare.diff.metamodel.uml_diff_extension.CompareTwoElementsDiffModel;
+import org.eclipse.papyrus.compare.diff.metamodel.uml_diff_extension.util.UMLDiffSwitch;
+
+
+/**
+ * Switch to return Styled label for the given DiffElement.
+ * Usually changed elements and number of chnages are shown in bold.
+ */
+//TODO use this to get the tatiana customization in the upper viewer
+public class StyledDiffLabelSwitch extends UMLDiffSwitch<StyledString> {
+
+ /** The my domain element label provider. */
+ private final ILabelProvider myDomainElementLabelProvider;
+
+ /**
+ * Instantiates a new styled diff label switch.
+ *
+ * @param labelProvider the label provider
+ */
+ public StyledDiffLabelSwitch(ILabelProvider labelProvider) {
+ myDomainElementLabelProvider = labelProvider;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.papyrus.compare.diff.metamodel.uml_diff_extension.util.UMLDiffSwitch#defaultCase(org.eclipse.emf.ecore.EObject)
+ */
+ @Override
+ public StyledString defaultCase(EObject object) {
+ int classifierID = object.eClass().getClassifierID();
+ switch(classifierID) {
+ case DiffPackage.DIFF_GROUP:
+ {
+ DiffGroup diffGroup = (DiffGroup)object;
+ return caseDiffGroup(diffGroup);
+ }
+ case DiffPackage.UPDATE_ATTRIBUTE:
+ {
+ UpdateAttribute updateAttribute = (UpdateAttribute)object;
+ return caseUpdateAttribute(updateAttribute);
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Gets the label provider.
+ *
+ * @return the label provider
+ */
+ private ILabelProvider getLabelProvider() {
+ return myDomainElementLabelProvider;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.papyrus.compare.diff.metamodel.uml_diff_extension.util.UMLDiffSwitch#caseCompareTwoElementsDiffModel(org.eclipse.papyrus.compare.diff.metamodel.uml_diff_extension.CompareTwoElementsDiffModel)
+ */
+ @Override
+ public StyledString caseCompareTwoElementsDiffModel(CompareTwoElementsDiffModel object) {
+ int subchanges = ((DiffGroup)object.getOwnedElements().get(0)).getSubchanges();
+ EObject leftElement = object.getLeftRoots().get(0);
+ String leftName = getLabelProvider().getText(leftElement);
+ EObject rightElement = object.getRightRoots().get(0);
+ String rightName = getLabelProvider().getText(rightElement);
+
+ // String message = "%s change(s) between elements [%s] and [%s]";
+ // return String.StyledMessageFormat.format(message, subchanges, leftName, rightName);
+
+ return StyledMessageFormat.format(Messages.StyledDiffLabelSwitch_two_elements_model_text, String.valueOf(subchanges), leftName, rightName);
+
+ }
+
+ /**
+ * Case diff group.
+ *
+ * @param object the object
+ * @return the styled string
+ */
+ public StyledString caseDiffGroup(DiffGroup object) {
+ final EObject parent = object.getRightParent();
+ final String parentLabel;
+ if(parent != null) {
+ parentLabel = getLabelProvider().getText(parent);
+ } else {
+ parentLabel = Messages.StyledDiffLabelSwitch_root_text;
+ }
+ return StyledMessageFormat.format(Messages.StyledDiffLabelSwitch_diff_group_text, String.valueOf(object.getSubchanges()), parentLabel);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.papyrus.compare.diff.metamodel.uml_diff_extension.util.UMLDiffSwitch#caseAttributeChange(org.eclipse.emf.compare.diff.metamodel.AttributeChange)
+ */
+ @Override
+ public StyledString caseAttributeChange(AttributeChange object) {
+ return StyledMessageFormat.format(Messages.StyledDiffLabelSwitch_attribute_change_text, String.valueOf(object.isConflicting()));
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.papyrus.compare.diff.metamodel.uml_diff_extension.util.UMLDiffSwitch#caseAttributeChangeLeftTarget(org.eclipse.emf.compare.diff.metamodel.AttributeChangeLeftTarget)
+ */
+ @Override
+ public StyledString caseAttributeChangeLeftTarget(AttributeChangeLeftTarget object) {
+ final String attributeLabel = getLabelProvider().getText(object.getAttribute());
+ final String elementLabel = getLabelProvider().getText(object.getRightElement());
+
+ if(object.isRemote()) {
+ return StyledMessageFormat.format(Messages.StyledDiffLabelSwitch_attribute_change_left_target_remote_text, attributeValueToString(object.getLeftTarget()), attributeLabel, elementLabel);
+ }
+ return StyledMessageFormat.format(Messages.StyledDiffLabelSwitch_attribute_change_left_target_text, attributeValueToString(object.getLeftTarget()), attributeLabel, elementLabel);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.papyrus.compare.diff.metamodel.uml_diff_extension.util.UMLDiffSwitch#caseAttributeChangeRightTarget(org.eclipse.emf.compare.diff.metamodel.AttributeChangeRightTarget)
+ */
+ @Override
+ public StyledString caseAttributeChangeRightTarget(AttributeChangeRightTarget object) {
+ final String attributeLabel = getLabelProvider().getText(object.getAttribute());
+ final String elementLabel = getLabelProvider().getText(object.getLeftElement());
+
+ if(object.isRemote()) {
+ return StyledMessageFormat.format(Messages.StyledDiffLabelSwitch_attribute_change_right_target_remote_text, attributeValueToString(object.getRightTarget()), attributeLabel, elementLabel);
+ }
+ return StyledMessageFormat.format(Messages.StyledDiffLabelSwitch_attribute_change_right_target_text, attributeValueToString(object.getRightTarget()), attributeLabel, elementLabel);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.papyrus.compare.diff.metamodel.uml_diff_extension.util.UMLDiffSwitch#caseUpdateAttribute(org.eclipse.emf.compare.diff.metamodel.UpdateAttribute)
+ */
+ @Override
+ public StyledString caseUpdateAttribute(UpdateAttribute object) {
+ final String attributeLabel = getLabelProvider().getText(object.getAttribute());
+ final String elementLabel = getLabelProvider().getText(object.getLeftElement());
+ final Object leftValue = object.getLeftElement().eGet(object.getAttribute());
+ final Object rightValue = object.getRightElement().eGet(object.getAttribute());
+
+ if(object.isRemote()) {
+ return StyledMessageFormat.format(Messages.StyledDiffLabelSwitch_update_attribute_remote_text, attributeLabel, elementLabel, attributeValueToString(leftValue), attributeValueToString(rightValue));
+ }
+
+ if(object.isConflicting()) {
+ return StyledMessageFormat.format(Messages.StyledDiffLabelSwitch_update_attribute_conflicting_text, attributeLabel, attributeValueToString(rightValue), attributeValueToString(leftValue));
+ }
+ return StyledMessageFormat.format(Messages.StyledDiffLabelSwitch_update_attribute_text, attributeLabel, elementLabel, attributeValueToString(rightValue), attributeValueToString(leftValue));
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.papyrus.compare.diff.metamodel.uml_diff_extension.util.UMLDiffSwitch#caseReferenceChange(org.eclipse.emf.compare.diff.metamodel.ReferenceChange)
+ */
+ @Override
+ public StyledString caseReferenceChange(ReferenceChange object) {
+ return StyledMessageFormat.format(Messages.StyledDiffLabelSwitch_reference_chnage_text, String.valueOf(object.isConflicting()));
+ }
+
+ /**
+ * Attribute value to string.
+ *
+ * @param attributeValue the attribute value
+ * @return the string
+ */
+ private String attributeValueToString(Object attributeValue) {
+ return attributeValue == null ? Messages.StyledDiffLabelSwitch_null_value_text : attributeValue.toString();
+ }
+
+}
diff --git a/sandbox/org.eclipse.papyrus.infra.emf.compare.ui/src/org/eclipse/papyrus/infra/emf/compare/ui/provider/UMLStyledStructureLabelProvider.java b/sandbox/org.eclipse.papyrus.infra.emf.compare.ui/src/org/eclipse/papyrus/infra/emf/compare/ui/provider/UMLStyledStructureLabelProvider.java
new file mode 100644
index 00000000000..7babdf7e34b
--- /dev/null
+++ b/sandbox/org.eclipse.papyrus.infra.emf.compare.ui/src/org/eclipse/papyrus/infra/emf/compare/ui/provider/UMLStyledStructureLabelProvider.java
@@ -0,0 +1,100 @@
+/*****************************************************************************
+ * Copyright (c) 2010 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:
+ * Tatiana Fesenko (CEA LIST) - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.compare.diff.extension;
+
+import org.eclipse.emf.compare.diff.metamodel.AbstractDiffExtension;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.viewers.StyledCellLabelProvider;
+import org.eclipse.jface.viewers.StyledString;
+import org.eclipse.jface.viewers.ViewerCell;
+import org.eclipse.papyrus.compare.diff.metamodel.uml_diff_extension.util.UMLDiffSwitch;
+import org.eclipse.swt.graphics.Image;
+
+
+/**
+ * LabelProvider that returns Styled label.
+ * Usually changed elements and number of changes are shown in bold.
+ */
+//TODO use this to get the tatiana customization in the upper viewer
+public class UMLStyledStructureLabelProvider extends StyledCellLabelProvider implements ILabelProvider {
+
+ /** The my delegate. */
+ private final ILabelProvider myDelegate;
+
+ /** The my diff label switch. */
+ private final UMLDiffSwitch<StyledString> myDiffLabelSwitch;
+
+ /**
+ * Instantiates a new uML styled structure label provider.
+ *
+ * @param delegate the delegate
+ */
+ public UMLStyledStructureLabelProvider(ILabelProvider delegate) {
+ myDelegate = delegate;
+ myDiffLabelSwitch = new StyledDiffLabelSwitch(delegate);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.ILabelProvider#getImage(java.lang.Object)
+ */
+ public Image getImage(Object element) {
+ if(element instanceof AbstractDiffExtension) {
+ return (Image)((AbstractDiffExtension)element).getImage();
+ }
+ return myDelegate.getImage(element);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object)
+ */
+ public String getText(Object element) {
+ return getStyledText(element).getString();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.StyledCellLabelProvider#update(org.eclipse.jface.viewers.ViewerCell)
+ */
+ public void update(ViewerCell cell) {
+ StyledString string = getStyledText(cell.getElement());
+ cell.setText(string.getString());
+ cell.setStyleRanges(string.getStyleRanges());
+ cell.setImage(getImage(cell.getElement()));
+ super.update(cell);
+ }
+
+ /**
+ * Gets the styled text.
+ *
+ * @param element the element
+ * @return the styled text
+ */
+ public StyledString getStyledText(Object element) {
+ if(element instanceof EObject) {
+ StyledString diffElementLabel = myDiffLabelSwitch.doSwitch((EObject)element);
+ if(diffElementLabel != null) {
+ return diffElementLabel;
+ }
+ }
+ String elementText = myDelegate.getText(element);
+ if (elementText != null) {
+ StyledString styledString = new StyledString();
+ styledString.append(myDelegate.getText(element));
+ return styledString;
+ }
+ return null;
+ }
+
+
+}

Back to the top