Customizes the way StereotypeAttributeChange and StereotypeRefenceChange
[EMFCompare2.git] / plugins / org.eclipse.emf.compare.uml2.edit / src / org / eclipse / emf / compare / uml2 / internal / provider / decorator / StereotypeAttributeChangeItemProviderDecorator.java
blobe79e4be06acb1d962110dbb9755a9fd6e5e25a74
1 /*******************************************************************************
2 * Copyright (c) 2014 Obeo.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * Obeo - initial API and implementation
10 *******************************************************************************/
11 package org.eclipse.emf.compare.uml2.internal.provider.decorator;
13 import com.google.common.base.Optional;
14 import com.google.common.base.Predicates;
15 import com.google.common.collect.Iterables;
17 import org.eclipse.emf.compare.AttributeChange;
18 import org.eclipse.emf.compare.Diff;
19 import org.eclipse.emf.compare.uml2.internal.StereotypeAttributeChange;
20 import org.eclipse.emf.edit.provider.ComposeableAdapterFactory;
22 /**
23 * Item provider decorator for {@link StereotypeAttributeChange}.
25 * @author <a href="mailto:arthur.daussy@obeo.fr">Arthur Daussy</a>
27 public class StereotypeAttributeChangeItemProviderDecorator extends UMLDiffItemProviderDecorator {
29 /**
30 * Constructor.
32 * @param adapterFactory
33 * .
35 public StereotypeAttributeChangeItemProviderDecorator(ComposeableAdapterFactory adapterFactory) {
36 super(adapterFactory);
39 @Override
40 public Object getImage(Object object) {
41 final AttributeChange attributeChange = getAttributeChange(object);
42 if (attributeChange != null) {
43 return getItemDelegator().getImage(attributeChange);
45 return super.getImage(object);
48 /**
49 * Retrieves the {@link AttributeChange} which is refined by the {@link StereotypeAttributeChange}.
51 * @param diff
52 * Input object. .
53 * @return an {@link AttributeChange} if the input is a {@link StereotypeAttributeChange} which is refined
54 * by an {@link AttributeChange} or <code>null</code> otherwise.
56 private AttributeChange getAttributeChange(Object diff) {
57 AttributeChange attributeChange = null;
58 if (diff instanceof StereotypeAttributeChange) {
59 StereotypeAttributeChange stereotypeAttributeChange = (StereotypeAttributeChange)diff;
60 Optional<Diff> element = Iterables.tryFind(stereotypeAttributeChange.getRefinedBy(), Predicates
61 .instanceOf(AttributeChange.class));
62 if (element.isPresent()) {
63 attributeChange = (AttributeChange)element.get();
66 return attributeChange;