diff options
author | vlorenzo | 2012-01-30 14:00:42 +0000 |
---|---|---|
committer | vlorenzo | 2012-01-30 14:00:42 +0000 |
commit | 9f73582a43562a834e6684b26553c1145d7d0d09 (patch) | |
tree | da271f7f17b7003a006b41d9a62fa6bda32c3876 /deprecated/org.eclipse.papyrus.uml.compare.ui | |
parent | 2fddc6c4f09a922ca8381c6a8c35bfd3f09593d7 (diff) | |
download | org.eclipse.papyrus-9f73582a43562a834e6684b26553c1145d7d0d09.tar.gz org.eclipse.papyrus-9f73582a43562a834e6684b26553c1145d7d0d09.tar.xz org.eclipse.papyrus-9f73582a43562a834e6684b26553c1145d7d0d09.zip |
The plugin oep.uml.compare.ui is now deprecated
Diffstat (limited to 'deprecated/org.eclipse.papyrus.uml.compare.ui')
23 files changed, 1639 insertions, 0 deletions
diff --git a/deprecated/org.eclipse.papyrus.uml.compare.ui/.classpath b/deprecated/org.eclipse.papyrus.uml.compare.ui/.classpath new file mode 100644 index 00000000000..64c5e31b7a2 --- /dev/null +++ b/deprecated/org.eclipse.papyrus.uml.compare.ui/.classpath @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?> +<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 kind="output" path="bin"/> +</classpath> diff --git a/deprecated/org.eclipse.papyrus.uml.compare.ui/.project b/deprecated/org.eclipse.papyrus.uml.compare.ui/.project new file mode 100644 index 00000000000..754f5c7db6a --- /dev/null +++ b/deprecated/org.eclipse.papyrus.uml.compare.ui/.project @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.papyrus.uml.compare.ui</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/deprecated/org.eclipse.papyrus.uml.compare.ui/.settings/org.eclipse.jdt.core.prefs b/deprecated/org.eclipse.papyrus.uml.compare.ui/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 00000000000..4049fe65088 --- /dev/null +++ b/deprecated/org.eclipse.papyrus.uml.compare.ui/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,8 @@ +#Tue Mar 08 16:02:45 GMT+01:00 2011 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 +org.eclipse.jdt.core.compiler.compliance=1.5 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.5 diff --git a/deprecated/org.eclipse.papyrus.uml.compare.ui/META-INF/MANIFEST.MF b/deprecated/org.eclipse.papyrus.uml.compare.ui/META-INF/MANIFEST.MF new file mode 100644 index 00000000000..836a3ed26f8 --- /dev/null +++ b/deprecated/org.eclipse.papyrus.uml.compare.ui/META-INF/MANIFEST.MF @@ -0,0 +1,23 @@ +Manifest-Version: 1.0
+Require-Bundle: org.eclipse.core.runtime,
+ org.eclipse.compare;bundle-version="3.5.200",
+ org.eclipse.papyrus.uml.compare;bundle-version="0.9.0",
+ org.eclipse.emf.compare.diff;bundle-version="1.1.1",
+ org.eclipse.emf.compare;bundle-version="1.1.1",
+ org.eclipse.emf.compare.ui;bundle-version="1.1.1",
+ org.eclipse.emf.compare.match;bundle-version="1.1.1",
+ org.eclipse.emf.facet.infra.browser.custom;bundle-version="0.1.0",
+ org.eclipse.emf.facet.infra.browser.custom.core;bundle-version="0.1.0",
+ org.eclipse.emf.facet.infra.browser.uicore;bundle-version="0.1.0",
+ org.eclipse.team.ui;bundle-version="3.5.200",
+ org.eclipse.uml2.uml.edit;bundle-version="3.1.100",
+ org.eclipse.emf.edit.ui;bundle-version="2.6.0"
+Bundle-Vendor: %Bundle-Vendor
+Bundle-ActivationPolicy: lazy
+Bundle-Version: 0.9.0.qualifier
+Bundle-Name: %Bundle-Name
+Bundle-Activator: org.eclipse.papyrus.uml.compare.ui.Activator
+Bundle-ManifestVersion: 2
+Bundle-SymbolicName: org.eclipse.papyrus.uml.compare.ui;singleton:=true
+Bundle-RequiredExecutionEnvironment: J2SE-1.5
+
diff --git a/deprecated/org.eclipse.papyrus.uml.compare.ui/about.html b/deprecated/org.eclipse.papyrus.uml.compare.ui/about.html new file mode 100644 index 00000000000..82d49bf5f81 --- /dev/null +++ b/deprecated/org.eclipse.papyrus.uml.compare.ui/about.html @@ -0,0 +1,28 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
+<title>About</title>
+</head>
+<body lang="EN-US">
+<h2>About This Content</h2>
+
+<p>June 5, 2007</p>
+<h3>License</h3>
+
+<p>The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise
+indicated below, the Content is provided to you under the terms and conditions of the
+Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available
+at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>.
+For purposes of the EPL, "Program" will mean the Content.</p>
+
+<p>If you did not receive this Content directly from the Eclipse Foundation, the Content is
+being redistributed by another party ("Redistributor") and different terms and conditions may
+apply to your use of any object code in the Content. Check the Redistributor's license that was
+provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise
+indicated below, the terms and conditions of the EPL still apply to any source code in the Content
+and such source code may be obtained at <a href="http://www.eclipse.org/">http://www.eclipse.org</a>.</p>
+
+</body>
+</html>
diff --git a/deprecated/org.eclipse.papyrus.uml.compare.ui/build.properties b/deprecated/org.eclipse.papyrus.uml.compare.ui/build.properties new file mode 100644 index 00000000000..b3545bf4896 --- /dev/null +++ b/deprecated/org.eclipse.papyrus.uml.compare.ui/build.properties @@ -0,0 +1,12 @@ +#
+#Mon Sep 12 09:29:35 CEST 2011
+bin.includes = META-INF/,\
+ .,\
+ plugin.xml,\
+ messages.properties,\
+ about.html,\
+ OSGI-INF/l10n/bundle.properties
+output..=bin/
+src.includes=META-INF/,.,plugin.xml,messages.properties,about.html
+source..=src/
+bin..=bin/
diff --git a/deprecated/org.eclipse.papyrus.uml.compare.ui/messages.properties b/deprecated/org.eclipse.papyrus.uml.compare.ui/messages.properties new file mode 100644 index 00000000000..9693117feca --- /dev/null +++ b/deprecated/org.eclipse.papyrus.uml.compare.ui/messages.properties @@ -0,0 +1,4 @@ +Activator_log_error_message=Unexpected error: +CompareTwoElementsAction_left_element_is_null=Cannot compare elements: left element is null +CompareTwoElementsAction_only_only_element_is_selected=Cannot compare elements: 2 elements should be selected, but only {0} is selected +CompareTwoElementsAction_right_element_is_null=Cannot compare elements: right element is null diff --git a/deprecated/org.eclipse.papyrus.uml.compare.ui/plugin.properties b/deprecated/org.eclipse.papyrus.uml.compare.ui/plugin.properties new file mode 100644 index 00000000000..f86c0caaac7 --- /dev/null +++ b/deprecated/org.eclipse.papyrus.uml.compare.ui/plugin.properties @@ -0,0 +1,3 @@ +#Properties file for org.eclipse.papyrus.uml.compare.ui
+Bundle-Vendor = Eclipse Modeling Project
+Bundle-Name = UML Compare UI
\ No newline at end of file diff --git a/deprecated/org.eclipse.papyrus.uml.compare.ui/plugin.xml b/deprecated/org.eclipse.papyrus.uml.compare.ui/plugin.xml new file mode 100644 index 00000000000..052599166ac --- /dev/null +++ b/deprecated/org.eclipse.papyrus.uml.compare.ui/plugin.xml @@ -0,0 +1,35 @@ +<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.0"?>
+<plugin>
+
+ <extension
+ point="org.eclipse.compare.contentMergeViewers">
+ <viewer
+ class="org.eclipse.papyrus.uml.compare.ui.viewer.content.UMLModelContentMergeViewerCreator"
+ extensions="uml"
+ id="org.eclipse.papyrus.uml.compare.ui.viewer.content.UMLModelContentMergeViewer"
+ label="Papyrus UML"/>
+ </extension>
+
+ <extension point="org.eclipse.ui.popupMenus">
+ <objectContribution
+ adaptable="true"
+ objectClass="org.eclipse.emf.ecore.EObject"
+ nameFilter="*"
+ id="org.eclipse.papyrus.domaincodegen.ui.popupMenus.contribution.IFile">
+ <menu id="UMLCompare" label="Compare With" path="additions">
+ <separator
+ name="compareTwoElements">
+ </separator>
+ </menu>
+ <action
+ class="org.eclipse.papyrus.uml.compare.ui.action.CompareTwoElementsAction"
+ enablesFor="2"
+ id="org.eclipse.papyrus.uml.compare.action.CompareTwoElementsAction"
+ icon="icons/export_as_html.gif"
+ label="Each Other"
+ menubarPath="UMLCompare/compareTwoElements"/>
+ </objectContribution>
+ </extension>
+
+</plugin>
diff --git a/deprecated/org.eclipse.papyrus.uml.compare.ui/src/org/eclipse/papyrus/uml/compare/ui/Activator.java b/deprecated/org.eclipse.papyrus.uml.compare.ui/src/org/eclipse/papyrus/uml/compare/ui/Activator.java new file mode 100644 index 00000000000..64518b7d60e --- /dev/null +++ b/deprecated/org.eclipse.papyrus.uml.compare.ui/src/org/eclipse/papyrus/uml/compare/ui/Activator.java @@ -0,0 +1,89 @@ +package org.eclipse.papyrus.uml.compare.ui; + +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.osgi.framework.BundleContext; + +/** + * The activator class controls the plug-in life cycle. + */ +public class Activator extends AbstractUIPlugin { + + // The plug-in ID + /** The Constant PLUGIN_ID. */ + public static final String PLUGIN_ID = "org.eclipse.papyrus.uml.compare.ui"; //$NON-NLS-1$ + + // The shared instance + /** The plugin. */ + private static Activator plugin; + + /** + * The constructor. + */ + public Activator() { + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) + */ + @Override + public void start(BundleContext context) throws Exception { + super.start(context); + plugin = this; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) + */ + @Override + public void stop(BundleContext context) throws Exception { + plugin = null; + super.stop(context); + } + + /** + * Returns the shared instance. + * + * @return the shared instance + */ + public static Activator getDefault() { + return plugin; + } + + /** + * Log error. + * + * @param e the e + */ + public static void logError(Throwable e) { + logError(Messages.Activator_log_error_message, e); + } + + /** + * Log error. + * + * @param message the message + * @param e the e + */ + public static void logError(String message, Throwable e) { + IStatus status = new Status(IStatus.ERROR, PLUGIN_ID, message, e); + getDefault().getLog().log(status); + } + + /** + * Log info. + * + * @param message the message + */ + public static void logInfo(String message) { + IStatus status = new Status(IStatus.INFO, PLUGIN_ID, message); + getDefault().getLog().log(status); + } + + +} diff --git a/deprecated/org.eclipse.papyrus.uml.compare.ui/src/org/eclipse/papyrus/uml/compare/ui/Messages.java b/deprecated/org.eclipse.papyrus.uml.compare.ui/src/org/eclipse/papyrus/uml/compare/ui/Messages.java new file mode 100644 index 00000000000..545dd7df6b9 --- /dev/null +++ b/deprecated/org.eclipse.papyrus.uml.compare.ui/src/org/eclipse/papyrus/uml/compare/ui/Messages.java @@ -0,0 +1,34 @@ +package org.eclipse.papyrus.uml.compare.ui; + +import org.eclipse.osgi.util.NLS; + +/** + * The NLS Messages. + */ +public class Messages extends NLS { + + /** The Constant BUNDLE_NAME. */ + private static final String BUNDLE_NAME = "messages"; //$NON-NLS-1$ + + /** The Activator_log_error_message. */ + public static String Activator_log_error_message; + + /** The Compare two elements action_left_element_is_null. */ + public static String CompareTwoElementsAction_left_element_is_null; + + /** The Compare two elements action_only_only_element_is_selected. */ + public static String CompareTwoElementsAction_only_only_element_is_selected; + + /** The Compare two elements action_right_element_is_null. */ + public static String CompareTwoElementsAction_right_element_is_null; + static { + // initialize resource bundle + NLS.initializeMessages(BUNDLE_NAME, Messages.class); + } + + /** + * Instantiates a new messages. + */ + private Messages() { + } +} diff --git a/deprecated/org.eclipse.papyrus.uml.compare.ui/src/org/eclipse/papyrus/uml/compare/ui/action/CompareTwoElementsAction.java b/deprecated/org.eclipse.papyrus.uml.compare.ui/src/org/eclipse/papyrus/uml/compare/ui/action/CompareTwoElementsAction.java new file mode 100644 index 00000000000..4186499ad15 --- /dev/null +++ b/deprecated/org.eclipse.papyrus.uml.compare.ui/src/org/eclipse/papyrus/uml/compare/ui/action/CompareTwoElementsAction.java @@ -0,0 +1,222 @@ +/***************************************************************************** + * 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.uml.compare.ui.action; + +import java.lang.reflect.InvocationTargetException; +import java.util.Collection; +import java.util.Map; + +import org.eclipse.compare.CompareConfiguration; +import org.eclipse.compare.CompareUI; +import org.eclipse.compare.CompareViewerPane; +import org.eclipse.compare.contentmergeviewer.IMergeViewerContentProvider; +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.AbstractDiffExtension; +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.engine.IMatchEngine; +import org.eclipse.emf.compare.match.metamodel.MatchModel; +import org.eclipse.emf.compare.ui.editor.ModelCompareEditorInput; +import org.eclipse.emf.compare.ui.viewer.content.ModelContentMergeViewer; +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.papyrus.uml.compare.diff.extension.UMLStyledStructureLabelProvider; +import org.eclipse.papyrus.uml.compare.element.ElementContentDiffEngine; +import org.eclipse.papyrus.uml.compare.element.ElementContentMatchEngine; +import org.eclipse.papyrus.uml.compare.ui.Activator; +import org.eclipse.papyrus.uml.compare.ui.Messages; +import org.eclipse.papyrus.uml.compare.ui.PapyrusLabelProvider; +import org.eclipse.papyrus.uml.compare.ui.viewer.content.ElementContentMergeContentProvider; +import org.eclipse.papyrus.uml.compare.ui.viewer.content.UMLModelContentMergeViewer; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.team.internal.ui.actions.TeamAction; +import org.eclipse.ui.PlatformUI; + +/** + * Action to compare two arbitrary elements. + * Availbale in the context menu of the model explorer. + */ +public class CompareTwoElementsAction extends TeamAction { + + /* (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.logInfo(Messages.bind(Messages.CompareTwoElementsAction_only_only_element_is_selected, selectedElements.length)); + return; + } + + EObject left = getElementFor(selectedElements[0]); + EObject right = getElementFor(selectedElements[1]); + if(left == null) { + Activator.logInfo(Messages.CompareTwoElementsAction_left_element_is_null); + return; + } + + if(right == null) { + Activator.logInfo(Messages.CompareTwoElementsAction_right_element_is_null); + return; + } + + ComparisonResourceSnapshot snapshot = doContentCompare(left, right); + openInCompare(snapshot); + } + + /* (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) { + CompareUI.openCompareEditor(new ModelCompareEditorInput(snapshot) { + + @Override + protected ModelContentMergeViewer createMergeViewer(CompareViewerPane pane, CompareConfiguration config) { + return new UMLModelContentMergeViewer(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 = contentMatch(left, right, monitor); + final DiffModel diff = contentDiff(left, right, match); + + snapshot.setDiff(diff); + snapshot.setMatch(match); + } + + }); + } catch (final InterruptedException e) { + Activator.logError(e); + } catch (final EMFCompareException e) { + Activator.logError(e); + } catch (final InvocationTargetException e) { + Activator.logError(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) { + 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; + } + + /** + * 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; + } + + /** + * 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; + } + +} diff --git a/deprecated/org.eclipse.papyrus.uml.compare.ui/src/org/eclipse/papyrus/uml/compare/ui/viewer/content/ElementContentMergeContentProvider.java b/deprecated/org.eclipse.papyrus.uml.compare.ui/src/org/eclipse/papyrus/uml/compare/ui/viewer/content/ElementContentMergeContentProvider.java new file mode 100644 index 00000000000..d57899f1bf4 --- /dev/null +++ b/deprecated/org.eclipse.papyrus.uml.compare.ui/src/org/eclipse/papyrus/uml/compare/ui/viewer/content/ElementContentMergeContentProvider.java @@ -0,0 +1,88 @@ +/***************************************************************************** + * 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.uml.compare.ui.viewer.content; + +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.uml.compare.diff.metamodel.uml_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) { + 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 + 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/deprecated/org.eclipse.papyrus.uml.compare.ui/src/org/eclipse/papyrus/uml/compare/ui/viewer/content/Messages.java b/deprecated/org.eclipse.papyrus.uml.compare.ui/src/org/eclipse/papyrus/uml/compare/ui/viewer/content/Messages.java new file mode 100644 index 00000000000..5e3bd676624 --- /dev/null +++ b/deprecated/org.eclipse.papyrus.uml.compare.ui/src/org/eclipse/papyrus/uml/compare/ui/viewer/content/Messages.java @@ -0,0 +1,28 @@ +package org.eclipse.papyrus.uml.compare.ui.viewer.content; + +import org.eclipse.osgi.util.NLS; + +/** + * The NLS Messages. + */ +public class Messages extends NLS { + + /** The Constant BUNDLE_NAME. */ + private static final String BUNDLE_NAME = "org.eclipse.papyrus.uml.compare.ui.viewer.content.messages"; //$NON-NLS-1$ + + /** The UML model content merge viewer_action_show_all_properties_text. */ + public static String UMLModelContentMergeViewer_action_show_all_properties_text; + + /** The UML model content merge viewer_action_show_all_properties_tooltip. */ + public static String UMLModelContentMergeViewer_action_show_all_properties_tooltip; + static { + // initialize resource bundle + NLS.initializeMessages(BUNDLE_NAME, Messages.class); + } + + /** + * Instantiates a new messages. + */ + private Messages() { + } +} diff --git a/deprecated/org.eclipse.papyrus.uml.compare.ui/src/org/eclipse/papyrus/uml/compare/ui/viewer/content/UMLModelContentMergeViewer.java b/deprecated/org.eclipse.papyrus.uml.compare.ui/src/org/eclipse/papyrus/uml/compare/ui/viewer/content/UMLModelContentMergeViewer.java new file mode 100644 index 00000000000..09266bc31ba --- /dev/null +++ b/deprecated/org.eclipse.papyrus.uml.compare.ui/src/org/eclipse/papyrus/uml/compare/ui/viewer/content/UMLModelContentMergeViewer.java @@ -0,0 +1,189 @@ +/***************************************************************************** + * 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.uml.compare.ui.viewer.content; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.compare.CompareConfiguration; +import org.eclipse.emf.compare.diff.metamodel.DiffElement; +import org.eclipse.emf.compare.ui.ICompareEditorPartListener; +import org.eclipse.emf.compare.ui.viewer.content.ModelContentMergeViewer; +import org.eclipse.emf.compare.ui.viewer.content.part.ModelContentMergeTabFolder; +import org.eclipse.jface.action.Action; +import org.eclipse.jface.action.ActionContributionItem; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.action.Separator; +import org.eclipse.jface.action.ToolBarManager; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.papyrus.uml.compare.Activator; +import org.eclipse.papyrus.uml.compare.ui.viewer.content.part.UMLModelContentMergeTabFolder; +import org.eclipse.swt.widgets.Composite; + + +/** + * The Class UMLModelContentMergeViewer. + */ +public class UMLModelContentMergeViewer extends ModelContentMergeViewer { + + /** The Constant VIEWER_SETTINGS_GROUP. */ + private static final String VIEWER_SETTINGS_GROUP = "viewer";//$NON-NLS-1$ + + /** The Constant SHOW_ALL_PRORPERTIES_IMAGE_PATH. */ + private static final String SHOW_ALL_PRORPERTIES_IMAGE_PATH = "/icons/show_all_properties.gif"; //$NON-NLS-1$ + + /** The my show all properties. */ + private IAction myShowAllProperties; + + /** The my property tab selection listener. */ + private ICompareEditorPartListener myPropertyTabSelectionListener; + + /** The my left part. */ + private UMLModelContentMergeTabFolder myLeftPart; + + /** + * Instantiates a new uML model content merge viewer. + * + * @param parent the parent + * @param config the config + */ + public UMLModelContentMergeViewer(Composite parent, CompareConfiguration config) { + super(parent, config); + } + + /* (non-Javadoc) + * @see org.eclipse.emf.compare.ui.viewer.content.ModelContentMergeViewer#createModelContentMergeTabFolder(org.eclipse.swt.widgets.Composite, int) + */ + @Override + protected ModelContentMergeTabFolder createModelContentMergeTabFolder(Composite composite, int side) { + return new UMLModelContentMergeTabFolder(this, composite, side); + } + + /* (non-Javadoc) + * @see org.eclipse.emf.compare.ui.viewer.content.ModelContentMergeViewer#createControls(org.eclipse.swt.widgets.Composite) + */ + @Override + protected void createControls(Composite composite) { + super.createControls(composite); + myPropertyTabSelectionListener = new PropertyTabSelectionListener(); + leftPart.addCompareEditorPartListener(myPropertyTabSelectionListener); + rightPart.addCompareEditorPartListener(myPropertyTabSelectionListener); + ancestorPart.addCompareEditorPartListener(myPropertyTabSelectionListener); + myLeftPart = (UMLModelContentMergeTabFolder)leftPart; + } + + /* (non-Javadoc) + * @see org.eclipse.emf.compare.ui.viewer.content.ModelContentMergeViewer#createToolItems(org.eclipse.jface.action.ToolBarManager) + */ + @Override + protected void createToolItems(ToolBarManager tbm) { + super.createToolItems(tbm); + tbm.add(new Separator(VIEWER_SETTINGS_GROUP)); + myShowAllProperties = new Action(Messages.UMLModelContentMergeViewer_action_show_all_properties_text, IAction.AS_CHECK_BOX) { + + @Override + public void run() { + showAllProperties(); + } + }; + boolean isEnabled = isPropertyTab(myLeftPart.getSelectedTab()); + myShowAllProperties.setEnabled(isEnabled); + myShowAllProperties.setEnabled(false); + myShowAllProperties.setToolTipText(Messages.UMLModelContentMergeViewer_action_show_all_properties_tooltip); + myShowAllProperties.setImageDescriptor(ImageDescriptor.createFromImage(Activator.getImage(SHOW_ALL_PRORPERTIES_IMAGE_PATH))); + + final ActionContributionItem showAllPropertiesContribution = new ActionContributionItem(myShowAllProperties); + showAllPropertiesContribution.setVisible(true); + tbm.appendToGroup(VIEWER_SETTINGS_GROUP, showAllPropertiesContribution); + } + + /** + * Show all properties. + */ + protected void showAllProperties() { + setSelection(new ArrayList<DiffElement>(currentSelection)); + } + + /** + * Property tab selected. + * + * @param isActive the is active + */ + protected void propertyTabSelected(boolean isActive) { + if(isActive) { + myShowAllProperties.setEnabled(true); + } else { + myShowAllProperties.setEnabled(false); + } + } + + /** + * Checks if is property tab. + * + * @param index the index + * @return true, if is property tab + */ + private boolean isPropertyTab(int index) { + return myLeftPart.isPropertyTab(index); + } + + /** + * Checks if is show all properties. + * + * @return true, if is show all properties + */ + public boolean isShowAllProperties() { + return myShowAllProperties.isChecked(); + } + + /** + * Gets the current selection. + * + * @return the current selection + */ + public List<DiffElement> getCurrentSelection() { + return currentSelection; + } + + /** + * Bug 338414 - [UML Compare] Filter only changes properties in the Merge Property Viewer. + * + * @see PropertyTabSelectionEvent + */ + private class PropertyTabSelectionListener implements ICompareEditorPartListener { + + /* (non-Javadoc) + * @see org.eclipse.emf.compare.ui.ICompareEditorPartListener#selectedTabChanged(int) + */ + public void selectedTabChanged(int newIndex) { + UMLModelContentMergeViewer.this.propertyTabSelected(isPropertyTab(newIndex)); + } + + /* (non-Javadoc) + * @see org.eclipse.emf.compare.ui.ICompareEditorPartListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent) + */ + public void selectionChanged(SelectionChangedEvent event) { + // do nothing + } + + /* (non-Javadoc) + * @see org.eclipse.emf.compare.ui.ICompareEditorPartListener#updateCenter() + */ + public void updateCenter() { + // do nothing + } + } + +} diff --git a/deprecated/org.eclipse.papyrus.uml.compare.ui/src/org/eclipse/papyrus/uml/compare/ui/viewer/content/UMLModelContentMergeViewerCreator.java b/deprecated/org.eclipse.papyrus.uml.compare.ui/src/org/eclipse/papyrus/uml/compare/ui/viewer/content/UMLModelContentMergeViewerCreator.java new file mode 100644 index 00000000000..a178bd423f0 --- /dev/null +++ b/deprecated/org.eclipse.papyrus.uml.compare.ui/src/org/eclipse/papyrus/uml/compare/ui/viewer/content/UMLModelContentMergeViewerCreator.java @@ -0,0 +1,39 @@ +/***************************************************************************** + * 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.uml.compare.ui.viewer.content; + +import org.eclipse.compare.CompareConfiguration; +import org.eclipse.compare.IViewerCreator; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.swt.widgets.Composite; + + +/** + * The Class UMLModelContentMergeViewerCreator. + */ +public class UMLModelContentMergeViewerCreator implements IViewerCreator { + + /** + * Creates the viewer. + * + * @param parent the parent + * @param config the config + * @return the viewer + * {@inheritDoc} + */ + public Viewer createViewer(Composite parent, CompareConfiguration config) { + return new UMLModelContentMergeViewer(parent, config); + } + +} diff --git a/deprecated/org.eclipse.papyrus.uml.compare.ui/src/org/eclipse/papyrus/uml/compare/ui/viewer/content/messages.properties b/deprecated/org.eclipse.papyrus.uml.compare.ui/src/org/eclipse/papyrus/uml/compare/ui/viewer/content/messages.properties new file mode 100644 index 00000000000..a0363133867 --- /dev/null +++ b/deprecated/org.eclipse.papyrus.uml.compare.ui/src/org/eclipse/papyrus/uml/compare/ui/viewer/content/messages.properties @@ -0,0 +1,2 @@ +UMLModelContentMergeViewer_action_show_all_properties_text=Show All Properties +UMLModelContentMergeViewer_action_show_all_properties_tooltip=Show All Properties of the Element diff --git a/deprecated/org.eclipse.papyrus.uml.compare.ui/src/org/eclipse/papyrus/uml/compare/ui/viewer/content/part/UMLAdapterFactory.java b/deprecated/org.eclipse.papyrus.uml.compare.ui/src/org/eclipse/papyrus/uml/compare/ui/viewer/content/part/UMLAdapterFactory.java new file mode 100644 index 00000000000..bb4f8900282 --- /dev/null +++ b/deprecated/org.eclipse.papyrus.uml.compare.ui/src/org/eclipse/papyrus/uml/compare/ui/viewer/content/part/UMLAdapterFactory.java @@ -0,0 +1,48 @@ +/***************************************************************************** + * 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.uml.compare.ui.viewer.content.part; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.emf.common.notify.AdapterFactory; +import org.eclipse.emf.ecore.provider.EcoreItemProviderAdapterFactory; +import org.eclipse.emf.edit.provider.ComposedAdapterFactory; +import org.eclipse.uml2.uml.edit.providers.UMLItemProviderAdapterFactory; +import org.eclipse.uml2.uml.edit.providers.UMLReflectiveItemProviderAdapterFactory; +import org.eclipse.uml2.uml.edit.providers.UMLResourceItemProviderAdapterFactory; + + +/** + * A factory for creating UMLAdapter objects. + */ +public class UMLAdapterFactory extends ComposedAdapterFactory { + + /** The Constant factories. */ + private final static List<AdapterFactory> factories = new ArrayList<AdapterFactory>(); + static { + factories.add(new UMLResourceItemProviderAdapterFactory()); + factories.add(new UMLItemProviderAdapterFactory()); + factories.add(new EcoreItemProviderAdapterFactory()); + factories.add(new UMLReflectiveItemProviderAdapterFactory()); + } + + /** + * Instantiates a new uML adapter factory. + */ + public UMLAdapterFactory() { + super(factories); + } + +} diff --git a/deprecated/org.eclipse.papyrus.uml.compare.ui/src/org/eclipse/papyrus/uml/compare/ui/viewer/content/part/UMLModelContentMergeTabFolder.java b/deprecated/org.eclipse.papyrus.uml.compare.ui/src/org/eclipse/papyrus/uml/compare/ui/viewer/content/part/UMLModelContentMergeTabFolder.java new file mode 100644 index 00000000000..0ee17a0a5b8 --- /dev/null +++ b/deprecated/org.eclipse.papyrus.uml.compare.ui/src/org/eclipse/papyrus/uml/compare/ui/viewer/content/part/UMLModelContentMergeTabFolder.java @@ -0,0 +1,128 @@ +/***************************************************************************** + * 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.uml.compare.ui.viewer.content.part; + +import org.eclipse.emf.compare.match.metamodel.Match2Elements; +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.property.ModelContentMergePropertyTab; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.edit.provider.ComposedAdapterFactory; +import org.eclipse.emf.edit.ui.provider.AdapterFactoryContentProvider; +import org.eclipse.jface.viewers.IContentProvider; +import org.eclipse.papyrus.uml.compare.ui.PapyrusLabelProvider; +import org.eclipse.papyrus.uml.compare.ui.viewer.content.UMLModelContentMergeViewer; +import org.eclipse.papyrus.uml.compare.ui.viewer.content.ElementContentMergeContentProvider.RootObject; +import org.eclipse.papyrus.uml.compare.ui.viewer.content.part.diff.UMLModelContentMergeDiffTab; +import org.eclipse.papyrus.uml.compare.ui.viewer.content.part.property.Match2ElementsWithDiff; +import org.eclipse.papyrus.uml.compare.ui.viewer.content.part.property.UMLPropertyContentProvider; +import org.eclipse.swt.widgets.Composite; + + +/** + * The Class UMLModelContentMergeTabFolder. + */ +public class UMLModelContentMergeTabFolder extends ModelContentMergeTabFolder { + + /** The my uml viewer. */ + protected final UMLModelContentMergeViewer myUMLViewer; + + /** + * Instantiates a new uML model content merge tab folder. + * + * @param viewer the viewer + * @param composite the composite + * @param side the side + */ + public UMLModelContentMergeTabFolder(ModelContentMergeViewer viewer, Composite composite, int side) { + super(viewer, composite, side); + myUMLViewer = (UMLModelContentMergeViewer)viewer; + } + + /* (non-Javadoc) + * @see org.eclipse.emf.compare.ui.viewer.content.part.ModelContentMergeTabFolder#createModelContentMergeDiffTab(org.eclipse.swt.widgets.Composite) + */ + @Override + protected IModelContentMergeViewerTab createModelContentMergeDiffTab(Composite parent) { + UMLModelContentMergeDiffTab diffTab = new UMLModelContentMergeDiffTab(parent, partSide, this); + diffTab.setContentProvider(createDiffTabContentProvider()); + diffTab.setLabelProvider(new PapyrusLabelProvider()); + return diffTab; + + } + + /* (non-Javadoc) + * @see org.eclipse.emf.compare.ui.viewer.content.part.ModelContentMergeTabFolder#createModelContentMergeViewerTab(org.eclipse.swt.widgets.Composite) + */ + @Override + protected IModelContentMergeViewerTab createModelContentMergeViewerTab(Composite parent) { + ModelContentMergePropertyTab propertyTab = new ModelContentMergePropertyTab(parent, partSide, this); + propertyTab.setContentProvider(new UMLPropertyContentProvider()); + return propertyTab; + } + + /** + * Creates the diff tab content provider. + * + * @return the i content provider + */ + protected IContentProvider createDiffTabContentProvider() { + ComposedAdapterFactory adapterFactory = new UMLAdapterFactory(); + AdapterFactoryContentProvider result = new AdapterFactoryContentProvider(adapterFactory) { + + @Override + public Object[] getElements(Object object) { + if(object instanceof RootObject) { + return new Object[]{ ((RootObject)object).object }; + } + return super.getElements(object); + } + }; + + return result; + } + + /* (non-Javadoc) + * @see org.eclipse.emf.compare.ui.viewer.content.part.ModelContentMergeTabFolder#findMatchFromElement(org.eclipse.emf.ecore.EObject) + */ + protected EObject findMatchFromElement(EObject element) { + EObject matchElement = super.findMatchFromElement(element); + if(!myUMLViewer.isShowAllProperties() && matchElement instanceof Match2Elements) { + return new Match2ElementsWithDiff((Match2Elements)matchElement, myUMLViewer.getCurrentSelection().get(0)); + } + return matchElement; + } + + /** + * Gets the selected tab. + * + * @return the selected tab + */ + public int getSelectedTab() { + return tabFolder.getSelectionIndex(); + } + + /** + * Checks if is property tab. + * + * @param index the index + * @return true, if is property tab + */ + public boolean isPropertyTab(int index) { + final IModelContentMergeViewerTab currentTab = tabs.get(index); + return (currentTab == getPropertyPart()); + } + +} diff --git a/deprecated/org.eclipse.papyrus.uml.compare.ui/src/org/eclipse/papyrus/uml/compare/ui/viewer/content/part/diff/ModelContentMergeDiffTabContentProvider.java b/deprecated/org.eclipse.papyrus.uml.compare.ui/src/org/eclipse/papyrus/uml/compare/ui/viewer/content/part/diff/ModelContentMergeDiffTabContentProvider.java new file mode 100644 index 00000000000..f0c7a71bdbb --- /dev/null +++ b/deprecated/org.eclipse.papyrus.uml.compare.ui/src/org/eclipse/papyrus/uml/compare/ui/viewer/content/part/diff/ModelContentMergeDiffTabContentProvider.java @@ -0,0 +1,152 @@ +/***************************************************************************** + * 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.uml.compare.ui.viewer.content.part.diff; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +import org.eclipse.emf.common.notify.AdapterFactory; +import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.compare.diff.metamodel.ComparisonSnapshot; +import org.eclipse.emf.compare.ui.TypedElementWrapper; +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.papyrus.uml.compare.UMLCompareUtils; +import org.eclipse.uml2.uml.Element; + + +/** + * ContentProvider for the Structure Tab of the Merge Viewer. + */ +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); + } + + /** + * Gets the elements. + * + * @param object the object + * @return the elements + * {@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 + return filterStereotypeApplications((Resource)object); + } else { + result = super.getElements(object); + } + return result; + } + + /** + * Filter stereotype applications. + * + * @param object the object + * @return the object[] + */ + private Object[] filterStereotypeApplications(Resource object) { + EList<EObject> contents = object.getContents(); + List<EObject> result = new ArrayList<EObject>(); + for(int i = 0; i < contents.size(); i++) { + EObject next = contents.get(i); + if(!UMLCompareUtils.isStereotypeApplication(next)) { + result.add(next); + } + } + return result.toArray(new Object[result.size()]); + } + + /** + * Gets the children. + * + * @param object the object + * @return the children + * {@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 new Object[]{ ((Resource)object).getContents().get(0) }; + } + ArrayList<Object> result = new ArrayList<Object>(); + result.addAll(Arrays.asList(super.getChildren(object))); + result.addAll(getStereotypeApplications(object)); + return result.toArray(new Object[result.size()]); + } + + /** + * Gets the stereotype applications. + * + * @param eObject the e object + * @return the stereotype applications + */ + private List<EObject> getStereotypeApplications(Object eObject) { + if(eObject instanceof Element) { + return ((Element)eObject).getStereotypeApplications(); + } + return Collections.emptyList(); + } + + + /** + * Checks for children. + * + * @param object the object + * @return true, if successful + * {@inheritDoc} + * @see org.eclipse.emf.edit.ui.provider.AdapterFactoryContentProvider#hasChildren(java.lang.Object) + */ + @Override + public boolean hasChildren(Object object) { + return getChildren(object).length > 0; + } + + +} diff --git a/deprecated/org.eclipse.papyrus.uml.compare.ui/src/org/eclipse/papyrus/uml/compare/ui/viewer/content/part/diff/UMLModelContentMergeDiffTab.java b/deprecated/org.eclipse.papyrus.uml.compare.ui/src/org/eclipse/papyrus/uml/compare/ui/viewer/content/part/diff/UMLModelContentMergeDiffTab.java new file mode 100644 index 00000000000..9cb437482fd --- /dev/null +++ b/deprecated/org.eclipse.papyrus.uml.compare.ui/src/org/eclipse/papyrus/uml/compare/ui/viewer/content/part/diff/UMLModelContentMergeDiffTab.java @@ -0,0 +1,86 @@ +/***************************************************************************** + * 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.uml.compare.ui.viewer.content.part.diff; + +import java.util.ArrayList; +import java.util.List; + +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.ecore.EObject; +import org.eclipse.papyrus.uml.compare.UMLCompareUtils; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.uml2.uml.util.UMLUtil; + + +/** + * The Structure Tab in the Merge Viewer. + */ +public class UMLModelContentMergeDiffTab extends ModelContentMergeDiffTab { + + + /** + * Instantiates a new uML model content merge diff tab. + * + * @param parentComposite + * the parent composite + * @param side + * the side + * @param parentFolder + * the parent folder + */ + public UMLModelContentMergeDiffTab(Composite parentComposite, int side, ModelContentMergeTabFolder parentFolder) { + super(parentComposite, side, parentFolder); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.emf.compare.ui.viewer.content.part.diff.ModelContentMergeDiffTab#setSelectionToWidget(java.util.List, boolean) + */ + @Override + protected void setSelectionToWidget(List l, boolean reveal) { + // tfesenko filter stereotype applications + List result = new ArrayList(); + for(Object next : l) { + if(next instanceof EObject && UMLCompareUtils.isStereotypeApplication((EObject)next)) { + EObject stereotypeApplication = (EObject)next; + result.add(UMLUtil.getBaseElement(stereotypeApplication)); + } else { + result.add(next); + } + } + super.setSelectionToWidget(result, reveal); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.emf.compare.ui.viewer.content.part.diff.ModelContentMergeDiffTab#setReflectiveInput(java.lang.Object) + */ + @Override + public void setReflectiveInput(Object object) { + // tfesenko 336361 - [UML Compare] Compare two elements: show right element as root + if(object instanceof EObject) { + clearCaches(); + // tfesenko default implementation sets object.eResource here + setInput(object); + setupCaches(); + needsRedraw = true; + } + super.setReflectiveInput(object); + } + + +} diff --git a/deprecated/org.eclipse.papyrus.uml.compare.ui/src/org/eclipse/papyrus/uml/compare/ui/viewer/content/part/property/Match2ElementsWithDiff.java b/deprecated/org.eclipse.papyrus.uml.compare.ui/src/org/eclipse/papyrus/uml/compare/ui/viewer/content/part/property/Match2ElementsWithDiff.java new file mode 100644 index 00000000000..5fbeefc7f70 --- /dev/null +++ b/deprecated/org.eclipse.papyrus.uml.compare.ui/src/org/eclipse/papyrus/uml/compare/ui/viewer/content/part/property/Match2ElementsWithDiff.java @@ -0,0 +1,256 @@ +/***************************************************************************** + * 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.uml.compare.ui.viewer.content.part.property; + +import java.lang.reflect.InvocationTargetException; + +import org.eclipse.emf.common.notify.Adapter; +import org.eclipse.emf.common.notify.Notification; +import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.common.util.TreeIterator; +import org.eclipse.emf.compare.diff.metamodel.DiffElement; +import org.eclipse.emf.compare.match.metamodel.Match2Elements; +import org.eclipse.emf.compare.match.metamodel.MatchElement; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.EOperation; +import org.eclipse.emf.ecore.EReference; +import org.eclipse.emf.ecore.EStructuralFeature; +import org.eclipse.emf.ecore.resource.Resource; + + +/** + * The Class Match2Elements implementation that also contains corresponding DiffElement. + Used to filter only changes properties in the Merge Property Viewer (Bug 338414) + */ + +public class Match2ElementsWithDiff implements Match2Elements { + + /** The my delegate. */ + private Match2Elements myDelegate; + + /** The my diff element. */ + private DiffElement myDiffElement; + + /** + * Instantiates a new match2 elements with diff. + * + * @param delegate the delegate + * @param diffElement the diff element + */ + public Match2ElementsWithDiff(Match2Elements delegate, DiffElement diffElement) { + myDelegate = delegate; + myDiffElement = diffElement; + } + + /** + * Gets the diff element. + * + * @return the diff element + */ + public DiffElement getDiffElement() { + return myDiffElement; + } + + /* (non-Javadoc) + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + return myDelegate.toString() + " " + (myDiffElement == null ? "" : myDiffElement.toString()); //$NON-NLS-1$ //$NON-NLS-2$ + } + + /* (non-Javadoc) + * @see org.eclipse.emf.compare.match.metamodel.MatchElement#getSimilarity() + */ + public double getSimilarity() { + return myDelegate.getSimilarity(); + } + + /* (non-Javadoc) + * @see org.eclipse.emf.compare.match.metamodel.MatchElement#getSubMatchElements() + */ + public EList<MatchElement> getSubMatchElements() { + return myDelegate.getSubMatchElements(); + } + + /* (non-Javadoc) + * @see org.eclipse.emf.compare.match.metamodel.MatchElement#setSimilarity(double) + */ + public void setSimilarity(double value) { + myDelegate.setSimilarity(value); + } + + /* (non-Javadoc) + * @see org.eclipse.emf.ecore.EObject#eClass() + */ + public EClass eClass() { + return myDelegate.eClass(); + } + + /* (non-Javadoc) + * @see org.eclipse.emf.ecore.EObject#eResource() + */ + public Resource eResource() { + return myDelegate.eResource(); + } + + /* (non-Javadoc) + * @see org.eclipse.emf.ecore.EObject#eContainer() + */ + public EObject eContainer() { + return myDelegate; + } + + /* (non-Javadoc) + * @see org.eclipse.emf.ecore.EObject#eContainingFeature() + */ + public EStructuralFeature eContainingFeature() { + return myDelegate.eContainingFeature(); + } + + /* (non-Javadoc) + * @see org.eclipse.emf.ecore.EObject#eContainmentFeature() + */ + public EReference eContainmentFeature() { + return myDelegate.eContainmentFeature(); + } + + /* (non-Javadoc) + * @see org.eclipse.emf.ecore.EObject#eContents() + */ + public EList<EObject> eContents() { + return myDelegate.eContents(); + } + + /* (non-Javadoc) + * @see org.eclipse.emf.ecore.EObject#eAllContents() + */ + public TreeIterator<EObject> eAllContents() { + return myDelegate.eAllContents(); + } + + /* (non-Javadoc) + * @see org.eclipse.emf.ecore.EObject#eIsProxy() + */ + public boolean eIsProxy() { + return myDelegate.eIsProxy(); + } + + /* (non-Javadoc) + * @see org.eclipse.emf.ecore.EObject#eCrossReferences() + */ + public EList<EObject> eCrossReferences() { + return myDelegate.eCrossReferences(); + } + + /* (non-Javadoc) + * @see org.eclipse.emf.ecore.EObject#eGet(org.eclipse.emf.ecore.EStructuralFeature) + */ + public Object eGet(EStructuralFeature feature) { + return myDelegate.eGet(feature); + } + + /* (non-Javadoc) + * @see org.eclipse.emf.ecore.EObject#eGet(org.eclipse.emf.ecore.EStructuralFeature, boolean) + */ + public Object eGet(EStructuralFeature feature, boolean resolve) { + return myDelegate.eGet(feature, resolve); + } + + /* (non-Javadoc) + * @see org.eclipse.emf.ecore.EObject#eSet(org.eclipse.emf.ecore.EStructuralFeature, java.lang.Object) + */ + public void eSet(EStructuralFeature feature, Object newValue) { + myDelegate.eSet(feature, newValue); + } + + /* (non-Javadoc) + * @see org.eclipse.emf.ecore.EObject#eIsSet(org.eclipse.emf.ecore.EStructuralFeature) + */ + public boolean eIsSet(EStructuralFeature feature) { + return myDelegate.eIsSet(feature); + } + + /* (non-Javadoc) + * @see org.eclipse.emf.ecore.EObject#eUnset(org.eclipse.emf.ecore.EStructuralFeature) + */ + public void eUnset(EStructuralFeature feature) { + myDelegate.eUnset(feature); + } + + /* (non-Javadoc) + * @see org.eclipse.emf.ecore.EObject#eInvoke(org.eclipse.emf.ecore.EOperation, org.eclipse.emf.common.util.EList) + */ + public Object eInvoke(EOperation operation, EList<?> arguments) throws InvocationTargetException { + return myDelegate.eInvoke(operation, arguments); + } + + /* (non-Javadoc) + * @see org.eclipse.emf.common.notify.Notifier#eAdapters() + */ + public EList<Adapter> eAdapters() { + return myDelegate.eAdapters(); + } + + /* (non-Javadoc) + * @see org.eclipse.emf.common.notify.Notifier#eDeliver() + */ + public boolean eDeliver() { + return myDelegate.eDeliver(); + } + + /* (non-Javadoc) + * @see org.eclipse.emf.common.notify.Notifier#eSetDeliver(boolean) + */ + public void eSetDeliver(boolean deliver) { + myDelegate.eSetDeliver(deliver); + } + + /* (non-Javadoc) + * @see org.eclipse.emf.common.notify.Notifier#eNotify(org.eclipse.emf.common.notify.Notification) + */ + public void eNotify(Notification notification) { + myDelegate.eNotify(notification); + } + + /* (non-Javadoc) + * @see org.eclipse.emf.compare.match.metamodel.Match2Elements#getLeftElement() + */ + public EObject getLeftElement() { + return myDelegate.getLeftElement(); + } + + /* (non-Javadoc) + * @see org.eclipse.emf.compare.match.metamodel.Match2Elements#getRightElement() + */ + public EObject getRightElement() { + return myDelegate.getRightElement(); + } + + /* (non-Javadoc) + * @see org.eclipse.emf.compare.match.metamodel.Match2Elements#setLeftElement(org.eclipse.emf.ecore.EObject) + */ + public void setLeftElement(EObject value) { + myDelegate.setLeftElement(value); + } + + /* (non-Javadoc) + * @see org.eclipse.emf.compare.match.metamodel.Match2Elements#setRightElement(org.eclipse.emf.ecore.EObject) + */ + public void setRightElement(EObject value) { + myDelegate.setRightElement(value); + } + +} diff --git a/deprecated/org.eclipse.papyrus.uml.compare.ui/src/org/eclipse/papyrus/uml/compare/ui/viewer/content/part/property/UMLPropertyContentProvider.java b/deprecated/org.eclipse.papyrus.uml.compare.ui/src/org/eclipse/papyrus/uml/compare/ui/viewer/content/part/property/UMLPropertyContentProvider.java new file mode 100644 index 00000000000..4ca46ebadd6 --- /dev/null +++ b/deprecated/org.eclipse.papyrus.uml.compare.ui/src/org/eclipse/papyrus/uml/compare/ui/viewer/content/part/property/UMLPropertyContentProvider.java @@ -0,0 +1,130 @@ +/***************************************************************************** + * 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.uml.compare.ui.viewer.content.part.property; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.compare.diff.metamodel.AttributeChange; +import org.eclipse.emf.compare.diff.metamodel.DiffElement; +import org.eclipse.emf.compare.diff.metamodel.DiffGroup; +import org.eclipse.emf.compare.diff.metamodel.ReferenceChange; +import org.eclipse.emf.compare.ui.viewer.content.part.property.PropertyContentProvider; +import org.eclipse.emf.ecore.EStructuralFeature; + +/** + * ContentProvider for the Property Tab of the Merge Viewer. + * Used to filter only changes properties in the Merge Property Viewer (Bug 338414) + */ +public class UMLPropertyContentProvider extends PropertyContentProvider { + + /* (non-Javadoc) + * @see org.eclipse.emf.compare.ui.viewer.content.part.property.PropertyContentProvider#getElements(java.lang.Object) + */ + @Override + public Object[] getElements(Object inputElement) { + Object[] elements = super.getElements(inputElement); + if(inputElement instanceof Match2ElementsWithDiff) { + DiffElement diffElement = ((Match2ElementsWithDiff)inputElement).getDiffElement(); + return findRowsForFeatures(elements, getChangedFeatures(diffElement)); + } + return elements; + } + + /** + * Find rows for features. + * + * @param propertyRows the property rows + * @param features the features + * @return the object[] + */ + protected Object[] findRowsForFeatures(Object[] propertyRows, EStructuralFeature[] features) { + List<Object> result = new ArrayList<Object>(); + for (EStructuralFeature feature : features) { + Object row = findPropertyRowFor(propertyRows, feature); + if(row != null) { + result.add(row); + } + } + return result.toArray(new Object[result.size()]); + } + + /** + * Gets the changed features. + * + * @param diffElement the diff element + * @return the changed features + */ + private EStructuralFeature[] getChangedFeatures(DiffElement diffElement) { + if(diffElement instanceof AttributeChange) { + EStructuralFeature feature = ((AttributeChange)diffElement).getAttribute(); + return new EStructuralFeature[]{feature}; + } + if(diffElement instanceof ReferenceChange) { + EStructuralFeature feature = ((ReferenceChange)diffElement).getReference(); + return new EStructuralFeature[]{feature}; + } + if(diffElement instanceof DiffGroup) { + EList<DiffElement> children = ((DiffGroup)diffElement).getSubDiffElements(); + List<EStructuralFeature> result = new ArrayList<EStructuralFeature>(); + for (DiffElement child: children) { + result.addAll(Arrays.asList(getChangedFeatures(child))); + } + return result.toArray(new EStructuralFeature[result.size()]); + } + return new EStructuralFeature[0]; + } + + + /** + * Find property row for. + * + * @param propertyRows the property rows + * @param feature the feature + * @return the object + */ + private Object findPropertyRowFor(Object[] propertyRows, EStructuralFeature feature) { + for(Object nextRow : propertyRows) { + if(isTheSameFeature(feature, getFeatureFromPropertyRow(nextRow))) { + return nextRow; + } + } + return null; + } + + /** + * Gets the feature from property row. + * + * @param propertyRow the property row + * @return the feature from property row + */ + private EStructuralFeature getFeatureFromPropertyRow(Object propertyRow) { + List<Object> row = (List<Object>)propertyRow; + return (EStructuralFeature)row.get(0); + } + + /** + * Checks if is the same feature. + * + * @param feature1 the feature1 + * @param feature2 the feature2 + * @return true, if is the same feature + */ + private boolean isTheSameFeature(EStructuralFeature feature1, EStructuralFeature feature2) { + return feature1.getFeatureID() == feature2.getFeatureID() && feature1.getName().equals(feature2.getName()); + } + +} |