summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAxel Richard2013-03-06 10:29:08 (EST)
committer Axel Richard2013-03-07 10:15:21 (EST)
commit6f960175d1d92d20fa315c37227b18eaadea1c3b (patch)
tree1332d7144ed44d8769c57e20bea93daeff3292f4
parent6fb047374981258a4e158ff053757f4ea519396d (diff)
downloadorg.eclipse.emf.compare-6f960175d1d92d20fa315c37227b18eaadea1c3b.zip
org.eclipse.emf.compare-6f960175d1d92d20fa315c37227b18eaadea1c3b.tar.gz
org.eclipse.emf.compare-6f960175d1d92d20fa315c37227b18eaadea1c3b.tar.bz2
[401440] Adjust API to be able to read the description of a difference.refs/changes/94/10894/2
EMF compare had a long description for comparison model elements which was not available since commit db993319d95f1b04fd5139af9e7d4e8f3017fa41. Adjust API to provide both choices : long description with plain old labels and synthetic description with styled labels. Add new interface : IItemDescriptionProvider with method String getDescription() Existing ItemProviderSpecs now extends this new interface. Bug: 401440 Change-Id: I3324ca86c2834337647f565d1a37152885b7d223
-rw-r--r--plugins/org.eclipse.emf.compare.edit/plugin.xml61
-rw-r--r--plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/provider/IItemDescriptionProvider.java30
-rw-r--r--plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/provider/IItemStyledLabelProvider.java15
-rw-r--r--plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/provider/spec/AttributeChangeItemProviderSpec.java398
-rw-r--r--plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/provider/spec/CompareItemProviderAdapterFactorySpec.java9
-rw-r--r--plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/provider/spec/ComparisonItemProviderSpec.java34
-rw-r--r--plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/provider/spec/ConflictItemProviderSpec.java162
-rw-r--r--plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/provider/spec/MatchItemProviderSpec.java16
-rw-r--r--plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/provider/spec/MatchResourceItemProviderSpec.java26
-rw-r--r--plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/provider/spec/ReferenceChangeItemProviderSpec.java91
-rw-r--r--plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/provider/spec/ResourceAttachmentChangeItemProviderSpec.java61
11 files changed, 620 insertions, 283 deletions
diff --git a/plugins/org.eclipse.emf.compare.edit/plugin.xml b/plugins/org.eclipse.emf.compare.edit/plugin.xml
index e7a9d46..9bc27d9 100644
--- a/plugins/org.eclipse.emf.compare.edit/plugin.xml
+++ b/plugins/org.eclipse.emf.compare.edit/plugin.xml
@@ -1,30 +1,31 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<?eclipse version="3.0"?>
-
-<!--
- Copyright (c) 2012 Obeo.
- 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:
- Obeo - initial API and implementation
--->
-
-<plugin>
-
- <extension point="org.eclipse.emf.edit.itemProviderAdapterFactories">
- <factory
- uri="http://www.eclipse.org/emf/compare"
- class="org.eclipse.emf.compare.provider.spec.CompareItemProviderAdapterFactorySpec"
- supportedTypes=
- "org.eclipse.emf.edit.provider.IEditingDomainItemProvider
- org.eclipse.emf.edit.provider.IStructuredItemContentProvider
- org.eclipse.emf.edit.provider.ITreeItemContentProvider
- org.eclipse.emf.edit.provider.IItemLabelProvider
- org.eclipse.emf.edit.provider.IItemPropertySource
- org.eclipse.emf.compare.provider.IItemStyledLabelProvider"/>
- </extension>
-
-</plugin>
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.0"?>
+
+<!--
+ Copyright (c) 2012 Obeo.
+ 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:
+ Obeo - initial API and implementation
+-->
+
+<plugin>
+
+ <extension point="org.eclipse.emf.edit.itemProviderAdapterFactories">
+ <factory
+ uri="http://www.eclipse.org/emf/compare"
+ class="org.eclipse.emf.compare.provider.spec.CompareItemProviderAdapterFactorySpec"
+ supportedTypes=
+ "org.eclipse.emf.edit.provider.IEditingDomainItemProvider
+ org.eclipse.emf.edit.provider.IStructuredItemContentProvider
+ org.eclipse.emf.edit.provider.ITreeItemContentProvider
+ org.eclipse.emf.edit.provider.IItemLabelProvider
+ org.eclipse.emf.edit.provider.IItemPropertySource
+ org.eclipse.emf.compare.provider.IItemStyledLabelProvider
+ org.eclipse.emf.compare.provider.IItemDescriptionProvider"/>
+ </extension>
+
+</plugin>
diff --git a/plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/provider/IItemDescriptionProvider.java b/plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/provider/IItemDescriptionProvider.java
new file mode 100644
index 0000000..5fa0431
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/provider/IItemDescriptionProvider.java
@@ -0,0 +1,30 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Obeo.
+ * 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:
+ * Obeo - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.compare.provider;
+
+/**
+ * This is the interface implemented to provide a description for an item.
+ *
+ * @author <a href="mailto:axel.richard@obeo.fr">Axel Richard</a>
+ * @since 3.0
+ */
+public interface IItemDescriptionProvider {
+
+ /**
+ * Returns the description for the given object.
+ *
+ * @param object
+ * the object to evaluate the description for.
+ * @return the description.
+ */
+ String getDescription(Object object);
+
+}
diff --git a/plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/provider/IItemStyledLabelProvider.java b/plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/provider/IItemStyledLabelProvider.java
index 80b13b6..af11ec6 100644
--- a/plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/provider/IItemStyledLabelProvider.java
+++ b/plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/provider/IItemStyledLabelProvider.java
@@ -1,9 +1,22 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Obeo.
+ * 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:
+ * Obeo - initial API and implementation
+ *******************************************************************************/
package org.eclipse.emf.compare.provider;
import org.eclipse.emf.compare.provider.utils.IStyledString.IComposedStyledString;
/**
+ * This is the interface implemented to provide a styled label for an item.
+ *
* @author <a href="mailto:axel.richard@obeo.fr">Axel Richard</a>
+ * @since 3.0
*/
public interface IItemStyledLabelProvider {
@@ -14,5 +27,5 @@ public interface IItemStyledLabelProvider {
* the object to evaluate the styled string for.
* @return the styled string.
*/
- public IComposedStyledString getStyledText(Object object);
+ IComposedStyledString getStyledText(Object object);
}
diff --git a/plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/provider/spec/AttributeChangeItemProviderSpec.java b/plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/provider/spec/AttributeChangeItemProviderSpec.java
index 23f7e2e..7e52270 100644
--- a/plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/provider/spec/AttributeChangeItemProviderSpec.java
+++ b/plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/provider/spec/AttributeChangeItemProviderSpec.java
@@ -1,165 +1,233 @@
-/*******************************************************************************
- * Copyright (c) 2012 Obeo.
- * 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:
- * Obeo - initial API and implementation
- *******************************************************************************/
-package org.eclipse.emf.compare.provider.spec;
-
-import static com.google.common.collect.Lists.newArrayList;
-
-import java.util.Collection;
-import java.util.List;
-
-import org.eclipse.emf.common.notify.AdapterFactory;
-import org.eclipse.emf.common.util.URI;
-import org.eclipse.emf.compare.AttributeChange;
-import org.eclipse.emf.compare.Conflict;
-import org.eclipse.emf.compare.DifferenceKind;
-import org.eclipse.emf.compare.provider.AdapterFactoryUtil;
-import org.eclipse.emf.compare.provider.AttributeChangeItemProvider;
-import org.eclipse.emf.compare.provider.IItemStyledLabelProvider;
-import org.eclipse.emf.compare.provider.utils.ComposedStyledString;
-import org.eclipse.emf.compare.provider.utils.IStyledString;
-import org.eclipse.emf.compare.provider.utils.IStyledString.Style;
-import org.eclipse.emf.ecore.util.EcoreUtil;
-
-/**
- * @author <a href="mailto:mikael.barbero@obeo.fr">Mikael Barbero</a>
- */
-public class AttributeChangeItemProviderSpec extends AttributeChangeItemProvider implements IItemStyledLabelProvider {
-
- private final OverlayImageProvider overlayProvider;
-
- /**
- * @param adapterFactory
- */
- public AttributeChangeItemProviderSpec(AdapterFactory adapterFactory) {
- super(adapterFactory);
- overlayProvider = new OverlayImageProvider(getResourceLocator());
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.compare.provider.MatchItemProvider#getImage(java.lang.Object)
- */
- @Override
- public Object getImage(Object object) {
- AttributeChange attributeChange = (AttributeChange)object;
- Object attributeChangeValueImage = AdapterFactoryUtil.getImage(getRootAdapterFactory(),
- attributeChange.getValue());
-
- if (attributeChangeValueImage == null) {
- attributeChangeValueImage = super.getImage(object);
- }
-
- Object diffImage = overlayProvider.getComposedImage(attributeChange, attributeChangeValueImage);
- Object ret = overlayImage(object, diffImage);
-
- return ret;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.compare.provider.AttributeChangeItemProvider#getText(java.lang.Object)
- */
- @Override
- public String getText(Object object) {
- return getStyledText(object).getString();
- }
-
- protected String getAttributeText(final AttributeChange attChange) {
- return attChange.getAttribute().getName();
- }
-
- protected String getValueText(final AttributeChange attChange) {
- String value = EcoreUtil.convertToString(attChange.getAttribute().getEAttributeType(), attChange
- .getValue());
- if (value == null) {
- value = "<null>"; //$NON-NLS-1$
- } else {
- value = Strings.elide(value, 50, "..."); //$NON-NLS-1$
- }
- return value;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.edit.provider.ItemProviderAdapter#getChildren(java.lang.Object)
- */
- @Override
- public Collection<?> getChildren(Object object) {
- Collection<?> children = super.getChildren(object);
- List<? super Object> ret = newArrayList(children);
- AttributeChange attributeChange = (AttributeChange)object;
- Conflict conflict = attributeChange.getConflict();
- if (conflict != null) {
- // ret.add(conflict);
- }
-
- return ret;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.edit.provider.ItemProviderAdapter#getForeground(java.lang.Object)
- */
- @Override
- public Object getForeground(Object object) {
- AttributeChange attributeChange = (AttributeChange)object;
- switch (attributeChange.getState()) {
- case MERGED:
- case DISCARDED:
- return URI.createURI("color://rgb/156/156/156"); //$NON-NLS-1$
- default:
- return super.getForeground(object);
- }
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.compare.provider.IItemStyledLabelProvider#getStyledText(java.lang.Object)
- */
- public IStyledString.IComposedStyledString getStyledText(Object object) {
- final AttributeChange attChange = (AttributeChange)object;
-
- final String valueText = getValueText(attChange);
-
- final String attributeText = getAttributeText(attChange);
-
- ComposedStyledString ret = new ComposedStyledString(valueText);
- ret.append(" [" + attributeText, Style.DECORATIONS_STYLER); //$NON-NLS-1$
-
- switch (attChange.getKind()) {
- case ADD:
- ret.append(" add", Style.DECORATIONS_STYLER); //$NON-NLS-1$
- break;
- case DELETE:
- ret.append(" delete", Style.DECORATIONS_STYLER); //$NON-NLS-1$
- break;
- case CHANGE:
- ret.append(
- " " + ReferenceChangeItemProviderSpec.changeText(attChange, attChange.getAttribute()), //$NON-NLS-1$
- Style.DECORATIONS_STYLER);
- break;
- case MOVE:
- ret.append(" move", Style.DECORATIONS_STYLER); //$NON-NLS-1$
- break;
- default:
- throw new IllegalStateException("Unsupported " + DifferenceKind.class.getSimpleName() //$NON-NLS-1$
- + " value: " + attChange.getKind()); //$NON-NLS-1$
- }
- ret.append("]", Style.DECORATIONS_STYLER); //$NON-NLS-1$
-
- return ret;
- }
-}
+/*******************************************************************************
+ * Copyright (c) 2012, 2013 Obeo.
+ * 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:
+ * Obeo - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.compare.provider.spec;
+
+import static com.google.common.collect.Lists.newArrayList;
+
+import java.util.Collection;
+import java.util.List;
+
+import org.eclipse.emf.common.notify.AdapterFactory;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.compare.AttributeChange;
+import org.eclipse.emf.compare.Conflict;
+import org.eclipse.emf.compare.DifferenceKind;
+import org.eclipse.emf.compare.DifferenceSource;
+import org.eclipse.emf.compare.provider.AdapterFactoryUtil;
+import org.eclipse.emf.compare.provider.AttributeChangeItemProvider;
+import org.eclipse.emf.compare.provider.IItemDescriptionProvider;
+import org.eclipse.emf.compare.provider.IItemStyledLabelProvider;
+import org.eclipse.emf.compare.provider.utils.ComposedStyledString;
+import org.eclipse.emf.compare.provider.utils.IStyledString;
+import org.eclipse.emf.compare.provider.utils.IStyledString.Style;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+
+/**
+ * Specialized {@link AttributeChangeItemProvider} returning nice output for {@link #getText(Object)} and
+ * {@link #getImage(Object)}.
+ *
+ * @author <a href="mailto:mikael.barbero@obeo.fr">Mikael Barbero</a>
+ */
+public class AttributeChangeItemProviderSpec extends AttributeChangeItemProvider {
+
+ /** The elide length. */
+ private static final int ELIDE_LENGTH = 50;
+
+ /** The image provider used with this item provider. */
+ private final OverlayImageProvider overlayProvider;
+
+ /**
+ * Constructs an AttributeChangeItemProviderSpec with the given factory.
+ *
+ * @param adapterFactory
+ * the factory given to the super constructor.
+ */
+ public AttributeChangeItemProviderSpec(AdapterFactory adapterFactory) {
+ super(adapterFactory);
+ overlayProvider = new OverlayImageProvider(getResourceLocator());
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.compare.provider.MatchItemProvider#getImage(java.lang.Object)
+ */
+ @Override
+ public Object getImage(Object object) {
+ AttributeChange attributeChange = (AttributeChange)object;
+ Object attributeChangeValueImage = AdapterFactoryUtil.getImage(getRootAdapterFactory(),
+ attributeChange.getValue());
+
+ if (attributeChangeValueImage == null) {
+ attributeChangeValueImage = super.getImage(object);
+ }
+
+ Object diffImage = overlayProvider.getComposedImage(attributeChange, attributeChangeValueImage);
+ Object ret = overlayImage(object, diffImage);
+
+ return ret;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.compare.provider.AttributeChangeItemProvider#getText(java.lang.Object)
+ */
+ @Override
+ public String getText(Object object) {
+ return getStyledText(object).getString();
+ }
+
+ /**
+ * Returns the name of the attribute linked to the given {@link AttributeChange}.
+ *
+ * @param attChange
+ * the given {@link AttributeChange}.
+ * @return the name of the attribute linked to the given {@link AttributeChange}.
+ */
+ protected String getAttributeText(final AttributeChange attChange) {
+ return attChange.getAttribute().getName();
+ }
+
+ /**
+ * Converts to text the given {@link AttributeChange}.
+ *
+ * @param attChange
+ * the given {@link AttributeChange}.
+ * @return a nice text from the the given {@link AttributeChange}.
+ */
+ protected String getValueText(final AttributeChange attChange) {
+ String value = EcoreUtil.convertToString(attChange.getAttribute().getEAttributeType(), attChange
+ .getValue());
+ if (value == null) {
+ value = "<null>"; //$NON-NLS-1$
+ } else {
+ value = Strings.elide(value, ELIDE_LENGTH, "..."); //$NON-NLS-1$
+ }
+ return value;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.edit.provider.ItemProviderAdapter#getChildren(java.lang.Object)
+ */
+ @Override
+ public Collection<?> getChildren(Object object) {
+ Collection<?> children = super.getChildren(object);
+ List<? super Object> ret = newArrayList(children);
+ AttributeChange attributeChange = (AttributeChange)object;
+ Conflict conflict = attributeChange.getConflict();
+ if (conflict != null) {
+ // ret.add(conflict);
+ }
+
+ return ret;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.edit.provider.ItemProviderAdapter#getForeground(java.lang.Object)
+ */
+ @Override
+ public Object getForeground(Object object) {
+ AttributeChange attributeChange = (AttributeChange)object;
+ switch (attributeChange.getState()) {
+ case MERGED:
+ case DISCARDED:
+ return URI.createURI("color://rgb/156/156/156"); //$NON-NLS-1$
+ default:
+ return super.getForeground(object);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.compare.provider.IItemStyledLabelProvider#getStyledText(java.lang.Object)
+ */
+ public IStyledString.IComposedStyledString getStyledText(Object object) {
+ final AttributeChange attChange = (AttributeChange)object;
+
+ final String valueText = getValueText(attChange);
+
+ final String attributeText = getAttributeText(attChange);
+
+ ComposedStyledString ret = new ComposedStyledString(valueText);
+ ret.append(" [" + attributeText, Style.DECORATIONS_STYLER); //$NON-NLS-1$
+
+ switch (attChange.getKind()) {
+ case ADD:
+ ret.append(" add", Style.DECORATIONS_STYLER); //$NON-NLS-1$
+ break;
+ case DELETE:
+ ret.append(" delete", Style.DECORATIONS_STYLER); //$NON-NLS-1$
+ break;
+ case CHANGE:
+ ret.append(
+ " " + ReferenceChangeItemProviderSpec.changeText(attChange, attChange.getAttribute()), //$NON-NLS-1$
+ Style.DECORATIONS_STYLER);
+ break;
+ case MOVE:
+ ret.append(" move", Style.DECORATIONS_STYLER); //$NON-NLS-1$
+ break;
+ default:
+ throw new IllegalStateException("Unsupported " + DifferenceKind.class.getSimpleName() //$NON-NLS-1$
+ + " value: " + attChange.getKind()); //$NON-NLS-1$
+ }
+ ret.append("]", Style.DECORATIONS_STYLER); //$NON-NLS-1$
+
+ return ret;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.compare.provider.IItemDescriptionProvider#getDescription(java.lang.Object)
+ */
+ public String getDescription(Object object) {
+ final AttributeChange attChange = (AttributeChange)object;
+
+ final String valueText = getValueText(attChange);
+ final String attributeText = getAttributeText(attChange);
+
+ String remotely = "";
+ if (attChange.getSource() == DifferenceSource.RIGHT) {
+ remotely = "remotely ";
+ }
+
+ String ret = "";
+ final String hasBeen = " has been ";
+
+ switch (attChange.getKind()) {
+ case ADD:
+ ret = valueText + hasBeen + remotely + "added to " + attributeText;
+ break;
+ case DELETE:
+ ret = valueText + hasBeen + remotely + "deleted from " + attributeText;
+ break;
+ case CHANGE:
+ String changeText = ReferenceChangeItemProviderSpec.changeText(attChange, attChange
+ .getAttribute());
+ ret = attributeText + " " + valueText + hasBeen + remotely + changeText;
+ break;
+ case MOVE:
+ ret = valueText + hasBeen + remotely + "moved in '" + attributeText;
+ break;
+ default:
+ throw new IllegalStateException("Unsupported " + DifferenceKind.class.getSimpleName()
+ + " value: " + attChange.getKind());
+ }
+
+ return ret;
+ }
+}
diff --git a/plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/provider/spec/CompareItemProviderAdapterFactorySpec.java b/plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/provider/spec/CompareItemProviderAdapterFactorySpec.java
index eb272fc..8c96fbf 100644
--- a/plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/provider/spec/CompareItemProviderAdapterFactorySpec.java
+++ b/plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/provider/spec/CompareItemProviderAdapterFactorySpec.java
@@ -12,20 +12,25 @@ package org.eclipse.emf.compare.provider.spec;
import org.eclipse.emf.common.notify.Adapter;
import org.eclipse.emf.compare.provider.CompareItemProviderAdapterFactory;
+import org.eclipse.emf.compare.provider.IItemDescriptionProvider;
import org.eclipse.emf.compare.provider.IItemStyledLabelProvider;
-import org.eclipse.emf.edit.provider.IItemLabelProvider;
/**
* Specialized {@link CompareItemProviderAdapterFactory} returning ItemProviderAdapter with nice
- * {@link IItemLabelProvider#getText(Object)} and {@link IItemLabelProvider#getImage(Object)}.
+ * {@link org.eclipse.emf.edit.provider.IItemLabelProvider#getText(Object)} and
+ * {@link org.eclipse.emf.edit.provider.IItemLabelProvider#getImage(Object)}.
*
* @author <a href="mailto:mikael.barbero@obeo.fr">Mikael Barbero</a>
*/
public class CompareItemProviderAdapterFactorySpec extends CompareItemProviderAdapterFactory {
+ /**
+ * Constructor calling super {@link #CompareItemProviderAdapterFactory()}.
+ */
public CompareItemProviderAdapterFactorySpec() {
super();
supportedTypes.add(IItemStyledLabelProvider.class);
+ supportedTypes.add(IItemDescriptionProvider.class);
}
/**
diff --git a/plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/provider/spec/ComparisonItemProviderSpec.java b/plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/provider/spec/ComparisonItemProviderSpec.java
index 8e4c140..e66ce91 100644
--- a/plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/provider/spec/ComparisonItemProviderSpec.java
+++ b/plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/provider/spec/ComparisonItemProviderSpec.java
@@ -28,6 +28,7 @@ import org.eclipse.emf.compare.Diff;
import org.eclipse.emf.compare.Match;
import org.eclipse.emf.compare.ResourceAttachmentChange;
import org.eclipse.emf.compare.provider.ComparisonItemProvider;
+import org.eclipse.emf.compare.provider.IItemDescriptionProvider;
import org.eclipse.emf.compare.provider.IItemStyledLabelProvider;
import org.eclipse.emf.compare.provider.utils.ComposedStyledString;
import org.eclipse.emf.compare.provider.utils.IStyledString;
@@ -35,12 +36,18 @@ import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.edit.provider.IEditingDomainItemProvider;
/**
+ * Specialized {@link ComparisonItemProvider} returning nice output for {@link #getText(Object)} and
+ * {@link #getImage(Object)}.
+ *
* @author <a href="mailto:mikael.barbero@obeo.fr">Mikael Barbero</a>
*/
-public class ComparisonItemProviderSpec extends ComparisonItemProvider implements IItemStyledLabelProvider {
+public class ComparisonItemProviderSpec extends ComparisonItemProvider implements IItemStyledLabelProvider, IItemDescriptionProvider {
/**
+ * Constructs a ComparisonItemProviderSpec with the given factory.
+ *
* @param adapterFactory
+ * the factory given to the super constructor.
*/
public ComparisonItemProviderSpec(AdapterFactory adapterFactory) {
super(adapterFactory);
@@ -68,6 +75,15 @@ public class ComparisonItemProviderSpec extends ComparisonItemProvider implement
return !isEmpty(getChildrenIterable(comparison));
}
+ /**
+ * Returns the children of the given {@link Comparison}. In this case children means: non empty matches
+ * (see {@link ComparisonItemProviderSpec#getNonEmptyMatches(Comparison)}), matches which not only
+ * contains {@link ResourceAttachmentChange} differences, and matched resources.
+ *
+ * @param comparison
+ * the given {@link Comparison}.
+ * @return the filtered list of children of the given {@link Comparison}.
+ */
private Iterable<EObject> getChildrenIterable(Comparison comparison) {
Iterable<? extends EObject> matches = getNonEmptyMatches(comparison);
List<EObject> children = Lists.newArrayList(matches);
@@ -81,6 +97,13 @@ public class ComparisonItemProviderSpec extends ComparisonItemProvider implement
return concat(children, comparison.getMatchedResources());
}
+ /**
+ * Filters out the empty matches of the given {@link Comparison}.
+ *
+ * @param comparison
+ * the given {@link Comparison}.
+ * @return an iterable of non empty matches.
+ */
private Iterable<Match> getNonEmptyMatches(Comparison comparison) {
Iterable<Match> match = filter(comparison.getMatches(), new Predicate<Match>() {
public boolean apply(Match input) {
@@ -111,4 +134,13 @@ public class ComparisonItemProviderSpec extends ComparisonItemProvider implement
public IStyledString.IComposedStyledString getStyledText(Object object) {
return new ComposedStyledString(getText(object));
}
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.compare.provider.IItemDescriptionProvider#getDescription(java.lang.Object)
+ */
+ public String getDescription(Object object) {
+ return getText(object);
+ }
}
diff --git a/plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/provider/spec/ConflictItemProviderSpec.java b/plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/provider/spec/ConflictItemProviderSpec.java
index 325a654..7ef4c5e 100644
--- a/plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/provider/spec/ConflictItemProviderSpec.java
+++ b/plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/provider/spec/ConflictItemProviderSpec.java
@@ -1,70 +1,92 @@
-/*******************************************************************************
- * Copyright (c) 2012 Obeo.
- * 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:
- * Obeo - initial API and implementation
- *******************************************************************************/
-package org.eclipse.emf.compare.provider.spec;
-
-import java.util.Collection;
-
-import org.eclipse.emf.common.notify.AdapterFactory;
-import org.eclipse.emf.common.util.EList;
-import org.eclipse.emf.compare.Conflict;
-import org.eclipse.emf.compare.Diff;
-import org.eclipse.emf.compare.provider.ConflictItemProvider;
-import org.eclipse.emf.compare.provider.IItemStyledLabelProvider;
-import org.eclipse.emf.compare.provider.utils.ComposedStyledString;
-import org.eclipse.emf.compare.provider.utils.IStyledString;
-
-/**
- * @author <a href="mailto:mikael.barbero@obeo.fr">Mikael Barbero</a>
- */
-public class ConflictItemProviderSpec extends ConflictItemProvider implements IItemStyledLabelProvider {
-
- /**
- * @param adapterFactory
- */
- public ConflictItemProviderSpec(AdapterFactory adapterFactory) {
- super(adapterFactory);
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.compare.provider.ConflictItemProvider#getText(java.lang.Object)
- */
- @Override
- public String getText(Object object) {
- return getStyledText(object).getString();
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.edit.provider.ItemProviderAdapter#getChildren(java.lang.Object)
- */
- @Override
- public Collection<?> getChildren(Object object) {
- Conflict conflict = (Conflict)object;
- EList<Diff> differences = conflict.getDifferences();
- return differences;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.compare.provider.IItemStyledLabelProvider#getStyledText(java.lang.Object)
- */
- public IStyledString.IComposedStyledString getStyledText(Object object) {
- Conflict conflict = (Conflict)object;
- int size = conflict.getDifferences().size() - 1;
- return new ComposedStyledString(conflict.getKind().getName()
- + " conflict with " + size + " other difference" //$NON-NLS-1$ //$NON-NLS-2$
- + (size > 1 ? "s" : "")); //$NON-NLS-1$ //$NON-NLS-2$
- }
-}
+/*******************************************************************************
+ * Copyright (c) 2012, 2013 Obeo.
+ * 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:
+ * Obeo - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.compare.provider.spec;
+
+import java.util.Collection;
+
+import org.eclipse.emf.common.notify.AdapterFactory;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.compare.Conflict;
+import org.eclipse.emf.compare.Diff;
+import org.eclipse.emf.compare.provider.ConflictItemProvider;
+import org.eclipse.emf.compare.provider.IItemDescriptionProvider;
+import org.eclipse.emf.compare.provider.IItemStyledLabelProvider;
+import org.eclipse.emf.compare.provider.utils.ComposedStyledString;
+import org.eclipse.emf.compare.provider.utils.IStyledString;
+
+/**
+ * Specialized {@link ConflictItemProvider} returning nice output for {@link #getText(Object)} and
+ * {@link #getImage(Object)}.
+ *
+ * @author <a href="mailto:mikael.barbero@obeo.fr">Mikael Barbero</a>
+ */
+public class ConflictItemProviderSpec extends ConflictItemProvider implements IItemStyledLabelProvider, IItemDescriptionProvider {
+
+ /**
+ * Constructs a ComparisonItemProviderSpec with the given factory.
+ *
+ * @param adapterFactory
+ * the factory given to the super constructor.
+ */
+ public ConflictItemProviderSpec(AdapterFactory adapterFactory) {
+ super(adapterFactory);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.compare.provider.ConflictItemProvider#getText(java.lang.Object)
+ */
+ @Override
+ public String getText(Object object) {
+ return getStyledText(object).getString();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.edit.provider.ItemProviderAdapter#getChildren(java.lang.Object)
+ */
+ @Override
+ public Collection<?> getChildren(Object object) {
+ Conflict conflict = (Conflict)object;
+ EList<Diff> differences = conflict.getDifferences();
+ return differences;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.compare.provider.IItemStyledLabelProvider#getStyledText(java.lang.Object)
+ */
+ public IStyledString.IComposedStyledString getStyledText(Object object) {
+ Conflict conflict = (Conflict)object;
+ int size = conflict.getDifferences().size() - 1;
+ return new ComposedStyledString(conflict.getKind().getName()
+ + " conflict with " + size + " other difference" //$NON-NLS-1$ //$NON-NLS-2$
+ + (size > 1 ? "s" : "")); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.compare.provider.IItemDescriptionProvider#getDescription(java.lang.Object)
+ */
+ public String getDescription(Object object) {
+ Conflict conflict = (Conflict)object;
+ int size = conflict.getDifferences().size() - 1;
+ String ret = conflict.getKind().getName() + " conflict with " + size + " other difference";
+ if (size > 1) {
+ ret += "s";
+ }
+ return ret;
+ }
+}
diff --git a/plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/provider/spec/MatchItemProviderSpec.java b/plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/provider/spec/MatchItemProviderSpec.java
index 863dc33..a893323 100644
--- a/plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/provider/spec/MatchItemProviderSpec.java
+++ b/plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/provider/spec/MatchItemProviderSpec.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2012 Obeo.
+ * Copyright (c) 2012, 2013 Obeo.
* 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
@@ -32,6 +32,7 @@ import org.eclipse.emf.compare.Match;
import org.eclipse.emf.compare.ReferenceChange;
import org.eclipse.emf.compare.ResourceAttachmentChange;
import org.eclipse.emf.compare.provider.AdapterFactoryUtil;
+import org.eclipse.emf.compare.provider.IItemDescriptionProvider;
import org.eclipse.emf.compare.provider.IItemStyledLabelProvider;
import org.eclipse.emf.compare.provider.MatchItemProvider;
import org.eclipse.emf.compare.provider.utils.ComposedStyledString;
@@ -44,7 +45,7 @@ import org.eclipse.emf.ecore.EObject;
*
* @author <a href="mailto:mikael.barbero@obeo.fr">Mikael Barbero</a>
*/
-public class MatchItemProviderSpec extends MatchItemProvider implements IItemStyledLabelProvider {
+public class MatchItemProviderSpec extends MatchItemProvider implements IItemStyledLabelProvider, IItemDescriptionProvider {
/**
* A predicate to know if the given {@link ReferenceChange} is a reference of type containment.
@@ -64,7 +65,7 @@ public class MatchItemProviderSpec extends MatchItemProvider implements IItemSty
}
};
- /** A provider to compose images. */
+ /** The image provider used with this item provider. */
private final OverlayImageProvider overlayProvider;
/**
@@ -283,4 +284,13 @@ public class MatchItemProviderSpec extends MatchItemProvider implements IItemSty
public IStyledString.IComposedStyledString getStyledText(Object object) {
return new ComposedStyledString(getText(object));
}
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.compare.provider.IItemDescriptionProvider#getDescription(java.lang.Object)
+ */
+ public String getDescription(Object object) {
+ return getText(object);
+ }
}
diff --git a/plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/provider/spec/MatchResourceItemProviderSpec.java b/plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/provider/spec/MatchResourceItemProviderSpec.java
index 90c5fbc..79643b0 100644
--- a/plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/provider/spec/MatchResourceItemProviderSpec.java
+++ b/plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/provider/spec/MatchResourceItemProviderSpec.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2012 Obeo.
+ * Copyright (c) 2012, 2013 Obeo.
* 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
@@ -19,6 +19,7 @@ import org.eclipse.emf.common.notify.AdapterFactory;
import org.eclipse.emf.compare.Comparison;
import org.eclipse.emf.compare.MatchResource;
import org.eclipse.emf.compare.ResourceAttachmentChange;
+import org.eclipse.emf.compare.provider.IItemDescriptionProvider;
import org.eclipse.emf.compare.provider.IItemStyledLabelProvider;
import org.eclipse.emf.compare.provider.MatchResourceItemProvider;
import org.eclipse.emf.compare.provider.utils.ComposedStyledString;
@@ -32,7 +33,7 @@ import org.eclipse.emf.edit.provider.IItemLabelProvider;
*
* @author <a href="mailto:mikael.barbero@obeo.fr">Mikael Barbero</a>
*/
-public class MatchResourceItemProviderSpec extends MatchResourceItemProvider implements IItemStyledLabelProvider {
+public class MatchResourceItemProviderSpec extends MatchResourceItemProvider implements IItemStyledLabelProvider, IItemDescriptionProvider {
/**
* Constructor calling super {@link #MatchResourceItemProviderSpec(AdapterFactory)}.
@@ -100,6 +101,7 @@ public class MatchResourceItemProviderSpec extends MatchResourceItemProvider imp
public Object getImage(Object object) {
final MatchResource matchResource = (MatchResource)object;
Resource resource = matchResource.getLeft();
+ Object image = null;
if (resource == null) {
resource = matchResource.getRight();
if (resource == null) {
@@ -111,15 +113,14 @@ public class MatchResourceItemProviderSpec extends MatchResourceItemProvider imp
IItemLabelProvider itemLabelProvider = (IItemLabelProvider)getRootAdapterFactory().adapt(
resource, IItemLabelProvider.class);
- Object image = itemLabelProvider.getImage(resource);
- if (image != null) {
- return image;
- } else {
- return super.getImage(object);
+ image = itemLabelProvider.getImage(resource);
+ if (image == null) {
+ image = super.getImage(object);
}
} else {
- return super.getImage(object);
+ image = super.getImage(object);
}
+ return image;
}
/**
@@ -165,4 +166,13 @@ public class MatchResourceItemProviderSpec extends MatchResourceItemProvider imp
public IStyledString.IComposedStyledString getStyledText(Object object) {
return new ComposedStyledString(getText(object));
}
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.compare.provider.IItemDescriptionProvider#getDescription(java.lang.Object)
+ */
+ public String getDescription(Object object) {
+ return getText(object);
+ }
}
diff --git a/plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/provider/spec/ReferenceChangeItemProviderSpec.java b/plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/provider/spec/ReferenceChangeItemProviderSpec.java
index 4ba41b2..13bc5dd 100644
--- a/plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/provider/spec/ReferenceChangeItemProviderSpec.java
+++ b/plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/provider/spec/ReferenceChangeItemProviderSpec.java
@@ -32,6 +32,7 @@ import org.eclipse.emf.compare.Match;
import org.eclipse.emf.compare.ReferenceChange;
import org.eclipse.emf.compare.ResourceAttachmentChange;
import org.eclipse.emf.compare.provider.AdapterFactoryUtil;
+import org.eclipse.emf.compare.provider.IItemDescriptionProvider;
import org.eclipse.emf.compare.provider.IItemStyledLabelProvider;
import org.eclipse.emf.compare.provider.ReferenceChangeItemProvider;
import org.eclipse.emf.compare.provider.utils.ComposedStyledString;
@@ -49,8 +50,12 @@ import org.eclipse.emf.edit.provider.ITreeItemContentProvider;
*
* @author <a href="mailto:mikael.barbero@obeo.fr">Mikael Barbero</a>
*/
-public class ReferenceChangeItemProviderSpec extends ReferenceChangeItemProvider implements IItemStyledLabelProvider {
+public class ReferenceChangeItemProviderSpec extends ReferenceChangeItemProvider implements IItemStyledLabelProvider, IItemDescriptionProvider {
+ /** The elide length. */
+ private static final int ELIDE_LENGTH = 50;
+
+ /** The image provider used with this item provider. */
private final OverlayImageProvider overlayProvider;
/**
@@ -90,6 +95,19 @@ public class ReferenceChangeItemProviderSpec extends ReferenceChangeItemProvider
return changeText;
}
+ /**
+ * Returns the type of change linked to the given {@link EStructuralFeature} ("unset", "set" or
+ * "changed"), according the the given sides.
+ *
+ * @param eStructuralFeature
+ * the given {@link EStructuralFeature}.
+ * @param sourceSide
+ * the source side as an {@link EObject}.
+ * @param otherSide
+ * the other side as an {@link EObject}.
+ * @return a String ("unset", "set" or "changed") containing the type of change linked to the given
+ * {@link EStructuralFeature}, according the the given sides.
+ */
private static String changeText(final EStructuralFeature eStructuralFeature, EObject sourceSide,
EObject otherSide) {
String changeText;
@@ -113,6 +131,13 @@ public class ReferenceChangeItemProviderSpec extends ReferenceChangeItemProvider
return changeText;
}
+ /**
+ * Checks if the given Object is a null or empty String.
+ *
+ * @param s
+ * the given Object.
+ * @return true if the Object is a null or empty String, false otherwise.
+ */
private static boolean isStringAndNullOrEmpty(Object s) {
if (s instanceof String) {
return Strings.isNullOrEmpty((String)s);
@@ -121,16 +146,30 @@ public class ReferenceChangeItemProviderSpec extends ReferenceChangeItemProvider
}
}
+ /**
+ * Returns the name of the reference linked to the given {@link ReferenceChange}.
+ *
+ * @param refChange
+ * the given {@link ReferenceChange}.
+ * @return the name of the reference linked to the given {@link ReferenceChange}.
+ */
protected String getReferenceText(final ReferenceChange refChange) {
return refChange.getReference().getName();
}
+ /**
+ * Converts to text the given {@link ReferenceChange}.
+ *
+ * @param refChange
+ * the given {@link ReferenceChange}.
+ * @return a nice text from the the given {@link ReferenceChange}.
+ */
protected String getValueText(final ReferenceChange refChange) {
String value = AdapterFactoryUtil.getText(getRootAdapterFactory(), refChange.getValue());
if (value == null) {
value = "<null>"; //$NON-NLS-1$
} else {
- value = org.eclipse.emf.compare.provider.spec.Strings.elide(value, 50, "..."); //$NON-NLS-1$
+ value = org.eclipse.emf.compare.provider.spec.Strings.elide(value, ELIDE_LENGTH, "..."); //$NON-NLS-1$
}
return value;
}
@@ -180,6 +219,13 @@ public class ReferenceChangeItemProviderSpec extends ReferenceChangeItemProvider
}
+ /**
+ * Returns the children of the given {@link Match}.
+ *
+ * @param matchOfValue
+ * the given {@link Match}.
+ * @return the children of the given {@link Match}.
+ */
private Collection<?> getChildren(Match matchOfValue) {
final Collection<?> children;
ITreeItemContentProvider matchItemContentProvider = (ITreeItemContentProvider)adapterFactory.adapt(
@@ -261,4 +307,45 @@ public class ReferenceChangeItemProviderSpec extends ReferenceChangeItemProvider
return ret;
}
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.compare.provider.IItemDescriptionProvider#getDescription(java.lang.Object)
+ */
+ public String getDescription(Object object) {
+ final ReferenceChange refChange = (ReferenceChange)object;
+
+ final String valueText = getValueText(refChange);
+ final String referenceText = getReferenceText(refChange);
+
+ String remotely = ""; //$NON-NLS-1$
+ if (refChange.getSource() == DifferenceSource.RIGHT) {
+ remotely = "remotely "; //$NON-NLS-1$
+ }
+
+ String ret = ""; //$NON-NLS-1$
+ final String hasBeen = " has been "; //$NON-NLS-1$
+
+ switch (refChange.getKind()) {
+ case ADD:
+ ret = valueText + hasBeen + remotely + "added to " + referenceText; //$NON-NLS-1$
+ break;
+ case DELETE:
+ ret = valueText + hasBeen + remotely + "deleted from " + referenceText; //$NON-NLS-1$
+ break;
+ case CHANGE:
+ String changeText = changeText(refChange, refChange.getReference());
+ ret = referenceText + " " + valueText + hasBeen + remotely + changeText; //$NON-NLS-1$
+ break;
+ case MOVE:
+ ret = valueText + hasBeen + remotely + "moved in " + referenceText; //$NON-NLS-1$
+ break;
+ default:
+ throw new IllegalStateException("Unsupported " + DifferenceKind.class.getSimpleName() //$NON-NLS-1$
+ + " value: " + refChange.getKind()); //$NON-NLS-1$
+ }
+
+ return ret;
+ }
}
diff --git a/plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/provider/spec/ResourceAttachmentChangeItemProviderSpec.java b/plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/provider/spec/ResourceAttachmentChangeItemProviderSpec.java
index 5b501a2..a403a9b 100644
--- a/plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/provider/spec/ResourceAttachmentChangeItemProviderSpec.java
+++ b/plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/provider/spec/ResourceAttachmentChangeItemProviderSpec.java
@@ -21,9 +21,11 @@ import java.util.List;
import org.eclipse.emf.common.notify.AdapterFactory;
import org.eclipse.emf.compare.DifferenceKind;
+import org.eclipse.emf.compare.DifferenceSource;
import org.eclipse.emf.compare.Match;
import org.eclipse.emf.compare.ResourceAttachmentChange;
import org.eclipse.emf.compare.provider.AdapterFactoryUtil;
+import org.eclipse.emf.compare.provider.IItemDescriptionProvider;
import org.eclipse.emf.compare.provider.IItemStyledLabelProvider;
import org.eclipse.emf.compare.provider.ResourceAttachmentChangeItemProvider;
import org.eclipse.emf.compare.provider.utils.ComposedStyledString;
@@ -39,8 +41,9 @@ import org.eclipse.emf.edit.provider.ITreeItemContentProvider;
* @author <a href="mailto:axel.richard@obeo.fr">Axel Richard</a>
* @since 3.0
*/
-public class ResourceAttachmentChangeItemProviderSpec extends ResourceAttachmentChangeItemProvider implements IItemStyledLabelProvider {
+public class ResourceAttachmentChangeItemProviderSpec extends ResourceAttachmentChangeItemProvider implements IItemStyledLabelProvider, IItemDescriptionProvider {
+ /** The image provider used with this item provider. */
private final OverlayImageProvider overlayProvider;
/**
@@ -89,6 +92,13 @@ public class ResourceAttachmentChangeItemProviderSpec extends ResourceAttachment
return ImmutableList.copyOf(ret);
}
+ /**
+ * Returns the children of the given {@link Match}.
+ *
+ * @param matchOfValue
+ * the given {@link Match}.
+ * @return the children of the given {@link Match}.
+ */
private Collection<?> getChildren(Match matchOfValue) {
final Collection<?> children;
ITreeItemContentProvider matchItemContentProvider = (ITreeItemContentProvider)adapterFactory.adapt(
@@ -152,6 +162,11 @@ public class ResourceAttachmentChangeItemProviderSpec extends ResourceAttachment
return getStyledText(object).getString();
}
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.compare.provider.IItemStyledLabelProvider#getStyledText(java.lang.Object)
+ */
public IComposedStyledString getStyledText(Object object) {
final Match match = ((ResourceAttachmentChange)object).getMatch();
String value = AdapterFactoryUtil.getText(getRootAdapterFactory(), match.getLeft());
@@ -173,4 +188,48 @@ public class ResourceAttachmentChangeItemProviderSpec extends ResourceAttachment
return ret.append(" [resource contents " + label + "]", Style.DECORATIONS_STYLER); //$NON-NLS-1$ //$NON-NLS-2$
}
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.compare.provider.IItemDescriptionProvider#getDescription(java.lang.Object)
+ */
+ public String getDescription(Object object) {
+ final ResourceAttachmentChange rac = (ResourceAttachmentChange)object;
+ final Match match = rac.getMatch();
+ String ret = AdapterFactoryUtil.getText(getRootAdapterFactory(), match.getLeft());
+ if (ret == null) {
+ ret = AdapterFactoryUtil.getText(getRootAdapterFactory(), match.getRight());
+ }
+ if (ret == null) {
+ ret = AdapterFactoryUtil.getText(getRootAdapterFactory(), match.getOrigin());
+ }
+ if (ret == null) {
+ ret = super.getText(object);
+ }
+
+ String remotely = "";
+ if (rac.getSource() == DifferenceSource.RIGHT) {
+ remotely = "remotely ";
+ }
+
+ DifferenceKind labelValue = rac.getKind();
+ final String hasBeen = " has been ";
+
+ switch (labelValue) {
+ case ADD:
+ ret += hasBeen + remotely + "added to resource contents";
+ break;
+ case DELETE:
+ ret += hasBeen + remotely + "deleted from resource contents";
+ break;
+ case MOVE:
+ ret += hasBeen + remotely + "moved in resource contents";
+ break;
+ default:
+ throw new IllegalStateException("Unsupported " + DifferenceKind.class.getSimpleName()
+ + " value: " + rac.getKind());
+ }
+ return ret;
+ }
}