use LoadingCache instead of Cache
[EMFCompare2.git] / plugins / org.eclipse.emf.compare.rcp.ui / src / org / eclipse / emf / compare / rcp / ui / structuremergeviewer / filters / RemovedElementsFilter.java
blob2bf51be43379098f5e9136277663ea196318190e
1 /*******************************************************************************
2 * Copyright (c) 2013 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.rcp.ui.structuremergeviewer.filters;
13 import static org.eclipse.emf.compare.utils.EMFComparePredicates.ofKind;
15 import com.google.common.base.Predicate;
17 import org.eclipse.emf.compare.Comparison;
18 import org.eclipse.emf.compare.Diff;
19 import org.eclipse.emf.compare.DifferenceKind;
20 import org.eclipse.emf.compare.scope.IComparisonScope;
21 import org.eclipse.emf.ecore.EObject;
23 /**
24 * A filter used by default that filtered out removed elements.
26 * @author <a href="mailto:axel.richard@obeo.fr">Axel Richard</a>
27 * @since 3.0
29 public class RemovedElementsFilter implements IDifferenceFilter {
31 /** A human-readable label for this filter. This will be displayed in the EMF Compare UI. */
32 private String label;
34 /** The initial activation state of the filter. */
35 private boolean activeByDefault;
37 /** The Predicate activate through this action. */
38 private Predicate<? super EObject> predicate;
40 /**
41 * Constructs the filter with the appropriate predicate.
43 public RemovedElementsFilter() {
44 super();
45 setPredicate();
48 /**
49 * {@inheritDoc}
51 * @see org.eclipse.emf.compare.rcp.ui.structuremergeviewer.filters.IDifferenceFilter#getLabel()
53 public String getLabel() {
54 return label;
57 /**
58 * {@inheritDoc}
60 * @see org.eclipse.emf.compare.rcp.ui.structuremergeviewer.filters.IDifferenceFilter#setLabel(java.lang.String)
62 public void setLabel(String label) {
63 this.label = label;
66 /**
67 * {@inheritDoc}
69 * @see org.eclipse.emf.compare.rcp.ui.structuremergeviewer.filters.IDifferenceFilter#defaultSelected()
71 public boolean defaultSelected() {
72 return activeByDefault;
75 /**
76 * {@inheritDoc}
78 * @see org.eclipse.emf.compare.rcp.ui.structuremergeviewer.filters.IDifferenceFilter#setDefaultSelected(boolean)
80 public void setDefaultSelected(boolean activeByDefault) {
81 this.activeByDefault = activeByDefault;
84 /**
85 * {@inheritDoc}
87 * @see org.eclipse.emf.compare.rcp.ui.structuremergeviewer.filters.IDifferenceFilter#isEnabled(org.eclipse.emf.compare.scope.IComparisonScope,
88 * org.eclipse.emf.compare.Comparison)
90 public boolean isEnabled(IComparisonScope scope, Comparison comparison) {
91 return true;
94 /**
95 * {@inheritDoc}
97 * @see org.eclipse.emf.compare.rcp.ui.structuremergeviewer.filters.IDifferenceFilter#getPredicate()
99 public Predicate<? super EObject> getPredicate() {
100 return predicate;
104 * Set the predicate that will be activate through this filter.
106 private void setPredicate() {
107 final Predicate<? super EObject> actualPredicate = new Predicate<EObject>() {
108 public boolean apply(EObject input) {
109 return input instanceof Diff && ofKind(DifferenceKind.DELETE).apply((Diff)input);
112 predicate = actualPredicate;