diff options
Diffstat (limited to 'plugins/org.eclipse.emf.compare.edit')
22 files changed, 775 insertions, 525 deletions
diff --git a/plugins/org.eclipse.emf.compare.edit/META-INF/MANIFEST.MF b/plugins/org.eclipse.emf.compare.edit/META-INF/MANIFEST.MF index 59a352283..78ab0f80f 100644 --- a/plugins/org.eclipse.emf.compare.edit/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.emf.compare.edit/META-INF/MANIFEST.MF @@ -22,5 +22,5 @@ Require-Bundle: org.eclipse.core.runtime, org.eclipse.emf.ecore.edit;visibility:=reexport,
org.eclipse.emf.transaction;bundle-version="1.3.0"
Bundle-ActivationPolicy: lazy
-Import-Package: com.google.common.base;version="[10.0.0,11.0.0)",
- com.google.common.collect;version="[10.0.0,11.0.0)"
+Import-Package: com.google.common.base;version="[11.0.0,15.0.0)",
+ com.google.common.collect;version="[11.0.0,15.0.0)"
diff --git a/plugins/org.eclipse.emf.compare.edit/icons/full/ovr16/confinoutchg_ov.png b/plugins/org.eclipse.emf.compare.edit/icons/full/ovr16/confinoutchg_ov.png Binary files differnew file mode 100644 index 000000000..9f4a38717 --- /dev/null +++ b/plugins/org.eclipse.emf.compare.edit/icons/full/ovr16/confinoutchg_ov.png diff --git a/plugins/org.eclipse.emf.compare.edit/icons/full/ovr16/inadd_ov.gif b/plugins/org.eclipse.emf.compare.edit/icons/full/ovr16/inadd_ov.gif Binary files differdeleted file mode 100644 index 05a9f5a68..000000000 --- a/plugins/org.eclipse.emf.compare.edit/icons/full/ovr16/inadd_ov.gif +++ /dev/null diff --git a/plugins/org.eclipse.emf.compare.edit/icons/full/ovr16/inchg_ov.gif b/plugins/org.eclipse.emf.compare.edit/icons/full/ovr16/inchg_ov.gif Binary files differdeleted file mode 100644 index 12d4a9732..000000000 --- a/plugins/org.eclipse.emf.compare.edit/icons/full/ovr16/inchg_ov.gif +++ /dev/null diff --git a/plugins/org.eclipse.emf.compare.edit/icons/full/ovr16/indel_ov.gif b/plugins/org.eclipse.emf.compare.edit/icons/full/ovr16/indel_ov.gif Binary files differdeleted file mode 100644 index 373a68f14..000000000 --- a/plugins/org.eclipse.emf.compare.edit/icons/full/ovr16/indel_ov.gif +++ /dev/null diff --git a/plugins/org.eclipse.emf.compare.edit/icons/full/ovr16/inoutchg_ov.gif b/plugins/org.eclipse.emf.compare.edit/icons/full/ovr16/inoutchg_ov.gif Binary files differdeleted file mode 100644 index 453497689..000000000 --- a/plugins/org.eclipse.emf.compare.edit/icons/full/ovr16/inoutchg_ov.gif +++ /dev/null diff --git a/plugins/org.eclipse.emf.compare.edit/icons/full/ovr16/outadd_ov.gif b/plugins/org.eclipse.emf.compare.edit/icons/full/ovr16/outadd_ov.gif Binary files differdeleted file mode 100644 index 63fb2967c..000000000 --- a/plugins/org.eclipse.emf.compare.edit/icons/full/ovr16/outadd_ov.gif +++ /dev/null diff --git a/plugins/org.eclipse.emf.compare.edit/icons/full/ovr16/outchg_ov.gif b/plugins/org.eclipse.emf.compare.edit/icons/full/ovr16/outchg_ov.gif Binary files differdeleted file mode 100644 index 78321d74d..000000000 --- a/plugins/org.eclipse.emf.compare.edit/icons/full/ovr16/outchg_ov.gif +++ /dev/null diff --git a/plugins/org.eclipse.emf.compare.edit/icons/full/ovr16/outdel_ov.gif b/plugins/org.eclipse.emf.compare.edit/icons/full/ovr16/outdel_ov.gif Binary files differdeleted file mode 100644 index 7182e5596..000000000 --- a/plugins/org.eclipse.emf.compare.edit/icons/full/ovr16/outdel_ov.gif +++ /dev/null diff --git a/plugins/org.eclipse.emf.compare.edit/plugin.properties b/plugins/org.eclipse.emf.compare.edit/plugin.properties index 85f997260..827824a76 100644 --- a/plugins/org.eclipse.emf.compare.edit/plugin.properties +++ b/plugins/org.eclipse.emf.compare.edit/plugin.properties @@ -7,7 +7,7 @@ # Contributors: # Obeo - initial API and implementation -pluginName = Compare Edit Support +pluginName = EMF Compare Edit Support providerName = Eclipse Modeling Project _UI_CreateChild_text = {0} diff --git a/plugins/org.eclipse.emf.compare.edit/plugin.xml b/plugins/org.eclipse.emf.compare.edit/plugin.xml index e7a9d46ca..9bc27d9d7 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 000000000..5fa0431d0 --- /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 80b13b6c4..af11ec692 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 8f70267aa..7e52270fd 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(), true);
- }
-
- /**
- * {@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 eb272fcae..8c96fbf99 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 8e4c1402d..e66ce917a 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 325a65405..7ef4c5e49 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 f00268299..a893323ad 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 @@ -27,19 +27,17 @@ 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.ConflictKind; import org.eclipse.emf.compare.Diff; 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; import org.eclipse.emf.compare.provider.utils.IStyledString; import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.EReference; /** * Specialized {@link MatchItemProvider} returning nice output for {@link #getText(Object)} and @@ -47,20 +45,27 @@ import org.eclipse.emf.ecore.EReference; * * @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. + */ private static final Predicate<ReferenceChange> CONTAINMENT_REFERENCE_CHANGE = new Predicate<ReferenceChange>() { public boolean apply(ReferenceChange input) { return input.getReference().isContainment(); } }; + /** + * A function returning the {@link ReferenceChange#getValue()} of the given {@link ReferenceChange}. + */ private static final Function<ReferenceChange, EObject> VALUE = new Function<ReferenceChange, EObject>() { public EObject apply(ReferenceChange input) { return input.getValue(); } }; + /** The image provider used with this item provider. */ private final OverlayImageProvider overlayProvider; /** @@ -71,7 +76,7 @@ public class MatchItemProviderSpec extends MatchItemProvider implements IItemSty */ public MatchItemProviderSpec(AdapterFactory adapterFactory) { super(adapterFactory); - overlayProvider = new OverlayImageProvider(getResourceLocator(), true); + overlayProvider = new OverlayImageProvider(getResourceLocator()); } /** @@ -139,19 +144,55 @@ public class MatchItemProviderSpec extends MatchItemProvider implements IItemSty return ImmutableList.copyOf(filteredChildren); } - Iterable<?> getChildrenIterable(Match match) { + /** + * Returns the children that will be displayed under the given Match. + * + * @param match + * the given Match. + * @return an iterable of children that will be displayed under the given Match. + * @since 3.0 + */ + public Iterable<?> getChildrenIterable(Match match) { + ImmutableSet<EObject> containementDifferenceValues = containmentReferencesValues(match); + + @SuppressWarnings("unchecked") + Predicate<Object> childrenFilter = not(or(matchOfContainmentDiff(containementDifferenceValues), + emptyMatch(), instanceOf(ResourceAttachmentChange.class))); + + Iterable<?> filteredChildren = filter(super.getChildren(match), childrenFilter); + return filteredChildren; + } + + /** + * Returns the filtered children (children without those who don't have children) that will be displayed + * under the given Match. + * + * @param match + * the given Match. + * @return an iterable of the filtered children (children without those who don't have children) that will + * be displayed under the given Match. + * @since 3.0 + */ + public Iterable<?> getFilteredChildren(Match match) { ImmutableSet<EObject> containementDifferenceValues = containmentReferencesValues(match); @SuppressWarnings("unchecked") Predicate<Object> childrenFilter = not(or(matchOfContainmentDiff(containementDifferenceValues), - matchWithNoChildren(), emptyMatch(), PSEUDO_CONFLICT_DIFF, REFINED_DIFF, - PSEUDO_DELETE_CONFLICT, instanceOf(ResourceAttachmentChange.class))); + matchWithNoChildren(), emptyMatch(), instanceOf(ResourceAttachmentChange.class))); Iterable<?> filteredChildren = filter(super.getChildren(match), childrenFilter); return filteredChildren; } - private ImmutableSet<EObject> containmentReferencesValues(Match match) { + /** + * Returns the containment references values of the given Match. + * + * @param match + * the given Match. + * @return the containment references values of the given Match. + * @since 3.0 + */ + public static ImmutableSet<EObject> containmentReferencesValues(Match match) { EList<Diff> differences = match.getDifferences(); Iterable<ReferenceChange> containmentReferenceChanges = filter(filter(differences, ReferenceChange.class), CONTAINMENT_REFERENCE_CHANGE); @@ -160,8 +201,18 @@ public class MatchItemProviderSpec extends MatchItemProvider implements IItemSty return containementDifferenceValues; } - private static Predicate<? super Object> matchOfContainmentDiff( - final ImmutableSet<EObject> containementDifferenceValues) { + /** + * A predicate to know if the given object is a {@link Match} containing a {@link Diff} of type + * containment. + * + * @param containementDifferenceValues + * the list of containment values. + * @return a predicate to know if the given object is a {@link Match} containing a {@link Diff} of type + * containment. + * @since 3.0 + */ + public static Predicate<? super Object> matchOfContainmentDiff( + final ImmutableSet<? extends EObject> containementDifferenceValues) { return new Predicate<Object>() { public boolean apply(Object input) { boolean ret = false; @@ -178,24 +229,34 @@ public class MatchItemProviderSpec extends MatchItemProvider implements IItemSty }; } + /** + * A predicate to know if the given object is a {@link Match} with no children. + * + * @return A predicate to know if the given object is a {@link Match} with no children. + */ private Predicate<? super Object> matchWithNoChildren() { return new Predicate<Object>() { public boolean apply(Object input) { boolean ret = false; if (input instanceof Match) { Match match = (Match)input; - ret = Iterables.isEmpty(MatchItemProviderSpec.this.getChildrenIterable(match)); + ret = Iterables.isEmpty(MatchItemProviderSpec.this.getFilteredChildren(match)); } return ret; } }; } + /** + * A predicate to know if the given object is an empty match (no left, right and origin). + * + * @return A predicate to know if the given object is an empty match (no left, right and origin). + */ private static Predicate<? super Object> emptyMatch() { return new Predicate<Object>() { public boolean apply(Object input) { if (input instanceof Match) { - final Match match = ((Match)input); + final Match match = (Match)input; return match.getLeft() == null && match.getRight() == null && match.getOrigin() == null; } return false; @@ -203,55 +264,6 @@ public class MatchItemProviderSpec extends MatchItemProvider implements IItemSty }; } - static final Predicate<? super Object> REFINED_DIFF = new Predicate<Object>() { - public boolean apply(Object input) { - boolean ret = false; - if (input instanceof Diff) { - Diff diff = (Diff)input; - ret = !diff.getRefines().isEmpty(); - } - return ret; - } - }; - - private static final Predicate<? super Object> PSEUDO_CONFLICT_DIFF = new Predicate<Object>() { - public boolean apply(Object input) { - boolean ret = false; - if (input instanceof Diff) { - Diff diff = (Diff)input; - Conflict conflict = diff.getConflict(); - if (conflict != null && conflict.getKind() == ConflictKind.PSEUDO) { - ret = true; - } - } - return ret; - } - }; - - private static final Predicate<? super Object> PSEUDO_DELETE_CONFLICT = new Predicate<Object>() { - public boolean apply(Object input) { - boolean ret = false; - if (input instanceof ReferenceChange) { - ReferenceChange referenceChange = (ReferenceChange)input; - Conflict conflict = referenceChange.getConflict(); - if (conflict != null) { - EReference eReference = referenceChange.getReference(); - EObject value = referenceChange.getValue(); - Iterable<ReferenceChange> conflictualReferenceChanges = filter(conflict.getDifferences(), - ReferenceChange.class); - for (ReferenceChange conflictualReferenceChange : conflictualReferenceChanges) { - if (conflictualReferenceChange != referenceChange - && conflictualReferenceChange.getReference() == eReference - && conflictualReferenceChange.getValue() == value) { - ret = true; - } - } - } - } - return ret; - } - }; - /** * {@inheritDoc} * @@ -267,8 +279,18 @@ public class MatchItemProviderSpec extends MatchItemProvider implements IItemSty * {@inheritDoc} * * @see org.eclipse.emf.compare.provider.IItemStyledLabelProvider#getStyledText(java.lang.Object) + * @since 3.0 */ 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 90c5fbc15..79643b0a0 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/OverlayImageProvider.java b/plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/provider/spec/OverlayImageProvider.java index b5ba7a103..21428c059 100644 --- a/plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/provider/spec/OverlayImageProvider.java +++ b/plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/provider/spec/OverlayImageProvider.java @@ -11,13 +11,11 @@ package org.eclipse.emf.compare.provider.spec;
import static com.google.common.collect.Iterables.any;
-import static com.google.common.collect.Iterables.filter;
import static com.google.common.collect.Iterables.isEmpty;
import static com.google.common.collect.Lists.newArrayList;
+import static org.eclipse.emf.compare.utils.EMFComparePredicates.fromSide;
import static org.eclipse.emf.compare.utils.EMFComparePredicates.hasConflict;
-import com.google.common.base.Predicate;
-
import java.util.Collection;
import java.util.List;
@@ -38,16 +36,13 @@ import org.eclipse.emf.edit.provider.ComposedImage; */
public class OverlayImageProvider {
- private final boolean fLeftIsLocal;
-
private final ResourceLocator fResourceLocator;
/**
*
*/
- public OverlayImageProvider(ResourceLocator resourceLocator, boolean leftIsLocal) {
+ public OverlayImageProvider(ResourceLocator resourceLocator) {
this.fResourceLocator = resourceLocator;
- this.fLeftIsLocal = leftIsLocal;
}
public Object getComposedImage(Diff diff, Object imageToCompose) {
@@ -70,44 +65,36 @@ public class OverlayImageProvider { return new ComposedImageExtension(images);
}
+ // Nothing here has to be externalized
+ @SuppressWarnings("nls")
private String getImageOverlay(Diff diff) {
final DifferenceSource source = diff.getSource();
final Match match = diff.getMatch();
final Conflict conflict = diff.getConflict();
final DifferenceKind diffKind = diff.getKind();
- final Comparison c = match.getComparison();
+ final Comparison comparison = match.getComparison();
String path = "full/ovr16/";
if (diff.getState() == DifferenceState.MERGED) {
path += "merged_ov";
} else if (diff.getState() == DifferenceState.DISCARDED) {
path += "removed_ov";
- } else if (c.isThreeWay()) {
- String filext = "";
- if (conflict != null) {
- if (conflict.getKind() == ConflictKind.REAL) {
- filext = ".png";
- path += "conf";
- path += getConflictWay(source);
+ } else if (comparison.isThreeWay()) {
+ // "png" needs explicit declaration, "gif" does not
+ String extension = "";
+ if (conflict != null && conflict.getKind() == ConflictKind.REAL) {
+ extension = ".png";
+ path += "conf";
+ if (source == DifferenceSource.RIGHT) {
+ path += "r_";
}
- // if (conflict.getKind() == ConflictKind.PSEUDO) {
- // path += "pconf";
- // }
} else {
switch (source) {
case LEFT:
- if (fLeftIsLocal) {
- path += "r_out";
- } else {
- path += "out";
- }
+ path += "r_out";
break;
case RIGHT:
- if (fLeftIsLocal) {
- path += "r_in";
- } else {
- path += "in";
- }
+ path += "r_in";
break;
default:
// Cannot happen ... for now
@@ -131,54 +118,29 @@ public class OverlayImageProvider { // Cannot happen ... for now
break;
}
- path += filext;
+ path += extension;
} else {
- path += getPathForTwoWayDiff(diffKind);
- }
- return path;
- }
-
- private String getPathForTwoWayDiff(final DifferenceKind diffKind) {
- final String path;
- switch (diffKind) {
- case ADD:
- if (fLeftIsLocal) {
- path = "add_ov";
- } else {
- path = "del_ov";
- }
- break;
- case DELETE:
- if (fLeftIsLocal) {
- path = "del_ov";
- } else {
- path = "add_ov";
- }
- break;
- case CHANGE:
- // fallthrough
- case MOVE:
- path = "chg_ov";
- break;
- default:
- path = "";
- break;
- }
- return path;
- }
-
- private String getConflictWay(final DifferenceSource source) {
- final String path;
- if (source == DifferenceSource.LEFT && !fLeftIsLocal) {
- path = "r_";
- } else if (source == DifferenceSource.RIGHT && fLeftIsLocal) {
- path = "r_";
- } else {
- path = "";
+ switch (diffKind) {
+ case ADD:
+ path += "add_ov";
+ break;
+ case DELETE:
+ path += "del_ov";
+ break;
+ case CHANGE:
+ // fallthrough
+ case MOVE:
+ path += "chg_ov";
+ break;
+ default:
+ break;
+ }
}
return path;
}
+ // Nothing here has to be externalized
+ @SuppressWarnings("nls")
private String getImageOverlay(Match match) {
String path = null;
final EObject ancestor = match.getOrigin();
@@ -188,91 +150,46 @@ public class OverlayImageProvider { final Iterable<Diff> differences = match.getAllDifferences();
if (match.getComparison().isThreeWay()) {
- boolean hasConflicts = any(differences, hasConflict(ConflictKind.REAL, ConflictKind.PSEUDO));
-
- if (ancestor == null) {
- if (left == null) {
- if (right != null) {
- if (fLeftIsLocal) {
- path = "r_inadd_ov";
- } else {
- path = "inadd_ov";
- }
- }
- } else if (right == null) {
- if (fLeftIsLocal) {
- path = "r_outadd_ov";
- } else {
- path = "outadd_ov";
- }
- } else if (hasConflicts && any(differences, hasConflict(ConflictKind.REAL))) {
- path = "confadd_ov.png";
+ if (any(differences, hasConflict(ConflictKind.REAL))) {
+ path = "confinoutchg_ov.png";
+ } else if (ancestor == null) {
+ if (right == null) {
+ path = "r_outadd_ov";
+ } else if (left == null) {
+ path = "r_inadd_ov";
+ } else {
+ // pseudo conflict addition
+ // TODO we filter this by default, what to do if the filter is off?
}
} else if (left == null) {
- if (right == null) {
- // path = Differencer.CONFLICTING | Differencer.DELETION |
- // Differencer.PSEUDO_CONFLICT;
- } else if (!hasConflicts) {
- if (fLeftIsLocal) {
- path = "r_outdel_ov";
- } else {
- path = "outdel_ov";
- }
- } else if (any(differences, hasConflict(ConflictKind.REAL))) {
- path = "confdel_ov.png";
+ if (right != null) {
+ path = "r_outdel_ov";
+ } else {
+ // pseudo conflict deletion
+ // TODO we filter this by default, what to do if the filter is off?
}
} else if (right == null) {
- if (!hasConflicts) {
- if (fLeftIsLocal) {
- path = "r_indel_ov";
- } else {
- path = "indel_ov";
- }
- } else if (any(differences, hasConflict(ConflictKind.REAL))) {
- path = "confchg_ov.png";
- }
+ path = "r_indel_ov";
} else {
- boolean ay = isEmpty(filter(differences, LEFT_DIFF));
- boolean am = isEmpty(filter(differences, RIGHT_DIFF));
-
- if (isEmpty(differences)) {
- // empty
- } else if (ay && !am) {
- if (fLeftIsLocal) {
- path = "r_inchg_ov";
- } else {
- path = "inchg_ov";
- }
- } else if (!ay && am) {
- if (fLeftIsLocal) {
- path = "r_outchg_ov";
- } else {
- path = "outchg_ov";
- }
- } else {
- if (hasConflicts && any(differences, hasConflict(ConflictKind.REAL))) {
- path = "confchg_ov.png";
- } else {
- path = "r_inoutchg_ov.gif";
- }
- }
- }
- } else if (left == null) {
- if (right != null) {
- if (fLeftIsLocal) {
- path = "add_ov";
- } else {
- path = "del_ov";
+ boolean hasLeftDiffs = any(differences, fromSide(DifferenceSource.LEFT));
+ boolean hasRightDiffs = any(differences, fromSide(DifferenceSource.RIGHT));
+
+ if (hasLeftDiffs && hasRightDiffs) {
+ path = "r_inoutchg_ov";
+ } else if (hasLeftDiffs) {
+ path = "r_outchg_ov";
+ } else if (hasRightDiffs) {
+ path = "r_inchg_ov";
}
}
- } else if (right == null) {
- if (fLeftIsLocal) {
+ } else {
+ if (left == null) {
path = "del_ov";
- } else {
+ } else if (right == null) {
path = "add_ov";
+ } else if (!isEmpty(differences)) {
+ path = "chg_ov";
}
- } else if (!isEmpty(differences)) {
- path = "chg_ov";
}
String ret = null;
@@ -282,18 +199,6 @@ public class OverlayImageProvider { return ret;
}
- private static final Predicate<Diff> LEFT_DIFF = new Predicate<Diff>() {
- public boolean apply(Diff input) {
- return input != null && input.getSource() == DifferenceSource.LEFT;
- }
- };
-
- private static final Predicate<Diff> RIGHT_DIFF = new Predicate<Diff>() {
- public boolean apply(Diff input) {
- return input != null && input.getSource() == DifferenceSource.RIGHT;
- }
- };
-
private final class ComposedImageExtension extends ComposedImage {
/**
@@ -324,12 +229,12 @@ public class OverlayImageProvider { * @see org.eclipse.emf.edit.provider.ComposedImage#getSize(java.util.Collection)
*/
@Override
- public Size getSize(Collection<? extends Size> imageSizes) {
- this.imageSizes = newArrayList(imageSizes);
+ public Size getSize(Collection<? extends Size> sizes) {
+ this.imageSizes = newArrayList(sizes);
List<Point> drawPoints = getDrawPoints(null);
Size result = new Size();
- for (int i = 0; i < imageSizes.size(); i++) {
+ for (int i = 0; i < sizes.size(); i++) {
Size size = this.imageSizes.get(i);
Point point = drawPoints.get(i);
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 f20e11fee..13bc5ddef 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; /** @@ -61,7 +66,7 @@ public class ReferenceChangeItemProviderSpec extends ReferenceChangeItemProvider */ public ReferenceChangeItemProviderSpec(AdapterFactory adapterFactory) { super(adapterFactory); - overlayProvider = new OverlayImageProvider(getResourceLocator(), true); + overlayProvider = new OverlayImageProvider(getResourceLocator()); } /** @@ -90,29 +95,49 @@ 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; if (sourceSide != null) { Object leftValue = ReferenceUtil.safeEGet(sourceSide, eStructuralFeature); if (leftValue == null || isStringAndNullOrEmpty(leftValue)) { - changeText = "unset"; //$NON-NLS-1$ + changeText = "unset"; } else if (otherSide != null) { Object otherValue = ReferenceUtil.safeEGet(otherSide, eStructuralFeature); if (otherValue == null || isStringAndNullOrEmpty(otherValue)) { - changeText = "set"; //$NON-NLS-1$ + changeText = "set"; } else { - changeText = "changed"; //$NON-NLS-1$ + changeText = "changed"; } } else { - changeText = "set"; //$NON-NLS-1$ + changeText = "set"; } } else { - changeText = "unset"; //$NON-NLS-1$ + changeText = "unset"; } 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; } @@ -176,11 +215,17 @@ public class ReferenceChangeItemProviderSpec extends ReferenceChangeItemProvider } } - return ImmutableList.copyOf(filter(filter(ret, not(instanceOf(ResourceAttachmentChange.class))), - not(MatchItemProviderSpec.REFINED_DIFF))); + return ImmutableList.copyOf(filter(ret, not(instanceOf(ResourceAttachmentChange.class)))); } + /** + * 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( @@ -243,23 +288,63 @@ public class ReferenceChangeItemProviderSpec extends ReferenceChangeItemProvider switch (refChange.getKind()) { case ADD: - ret.append(" add", Style.DECORATIONS_STYLER); //$NON-NLS-1$ + ret.append(" add", Style.DECORATIONS_STYLER); break; case DELETE: - ret.append(" delete", Style.DECORATIONS_STYLER); //$NON-NLS-1$ + ret.append(" delete", Style.DECORATIONS_STYLER); break; case CHANGE: - ret.append(" " + changeText(refChange, refChange.getReference()), //$NON-NLS-1$ - Style.DECORATIONS_STYLER); + ret.append(" " + changeText(refChange, refChange.getReference()), Style.DECORATIONS_STYLER); break; case MOVE: - ret.append(" move", Style.DECORATIONS_STYLER); //$NON-NLS-1$ + ret.append(" move", Style.DECORATIONS_STYLER); + break; + default: + throw new IllegalStateException("Unsupported " + DifferenceKind.class.getSimpleName() + + " value: " + refChange.getKind()); + } + 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 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$ } - ret.append("]", Style.DECORATIONS_STYLER); //$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 bf3656a9e..a403a9b8d 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 @@ -10,8 +10,6 @@ *******************************************************************************/ package org.eclipse.emf.compare.provider.spec; -import static com.google.common.base.Predicates.not; -import static com.google.common.collect.Iterables.filter; import static com.google.common.collect.Lists.newArrayList; import com.google.common.collect.ImmutableCollection; @@ -23,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; @@ -41,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; /** @@ -53,7 +54,7 @@ public class ResourceAttachmentChangeItemProviderSpec extends ResourceAttachment */ public ResourceAttachmentChangeItemProviderSpec(AdapterFactory adapterFactory) { super(adapterFactory); - overlayProvider = new OverlayImageProvider(getResourceLocator(), true); + overlayProvider = new OverlayImageProvider(getResourceLocator()); } /** @@ -88,9 +89,16 @@ public class ResourceAttachmentChangeItemProviderSpec extends ResourceAttachment ret.addAll(children); } - return ImmutableList.copyOf(filter(ret, not(MatchItemProviderSpec.REFINED_DIFF))); + 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( @@ -154,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()); @@ -175,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; + } } |