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
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
;
24 * A filter used by default that filtered out removed elements.
26 * @author <a href="mailto:axel.richard@obeo.fr">Axel Richard</a>
29 public class RemovedElementsFilter
implements IDifferenceFilter
{
31 /** A human-readable label for this filter. This will be displayed in the EMF Compare UI. */
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
;
41 * Constructs the filter with the appropriate predicate.
43 public RemovedElementsFilter() {
51 * @see org.eclipse.emf.compare.rcp.ui.structuremergeviewer.filters.IDifferenceFilter#getLabel()
53 public String
getLabel() {
60 * @see org.eclipse.emf.compare.rcp.ui.structuremergeviewer.filters.IDifferenceFilter#setLabel(java.lang.String)
62 public void setLabel(String label
) {
69 * @see org.eclipse.emf.compare.rcp.ui.structuremergeviewer.filters.IDifferenceFilter#defaultSelected()
71 public boolean defaultSelected() {
72 return activeByDefault
;
78 * @see org.eclipse.emf.compare.rcp.ui.structuremergeviewer.filters.IDifferenceFilter#setDefaultSelected(boolean)
80 public void setDefaultSelected(boolean activeByDefault
) {
81 this.activeByDefault
= activeByDefault
;
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
) {
97 * @see org.eclipse.emf.compare.rcp.ui.structuremergeviewer.filters.IDifferenceFilter#getPredicate()
99 public Predicate
<?
super EObject
> getPredicate() {
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
;