[401659] New filters and trees under groups
[EMFCompare2.git] / plugins / org.eclipse.emf.compare.rcp.ui / src / org / eclipse / emf / compare / rcp / ui / structuremergeviewer / actions / FilterAction.java
blob39b6d26d179f8a14e6dc337f502ee1f8681bede0
1 /*******************************************************************************
2 * Copyright (c) 2012, 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.actions;
13 import org.eclipse.emf.compare.rcp.ui.structuremergeviewer.filters.IDifferenceFilter;
14 import org.eclipse.emf.compare.rcp.ui.structuremergeviewer.filters.StructureMergeViewerFilter;
15 import org.eclipse.jface.action.Action;
16 import org.eclipse.jface.action.IAction;
18 /**
19 * These will be the actual actions displayed in the filter menu. Their sole purpose is to provide a Predicate
20 * to the structure viewer's filter.
21 * <p>
22 * Do note that each distinct {@link FilterAction} in the {@link FilterActionMenu filter menu} is considered
23 * as an "exclude" filter, and that they are OR'ed together (thus, any element must <b>not</b> meet the
24 * selected filters' criteria in order to be displayed).
25 * </p>
27 * @author <a href="mailto:laurent.goubet@obeo.fr">Laurent Goubet</a>
28 * @since 3.0
30 public class FilterAction extends Action {
32 /** The filter associated with this action. */
33 private IDifferenceFilter filter;
35 /** The Filter that will be modified by the action. */
36 private StructureMergeViewerFilter structureMergeViewerFilter;
38 /**
39 * The "default" constructor for this action.
41 * @param text
42 * Will be used as the action's tooltip.
43 * @param structureMergeViewerFilter
44 * The viewer filter that this action will need to update.
45 * @param filter
46 * The filter associated with this action.
48 public FilterAction(String text, StructureMergeViewerFilter structureMergeViewerFilter,
49 IDifferenceFilter filter) {
50 super(text, IAction.AS_CHECK_BOX);
51 this.structureMergeViewerFilter = structureMergeViewerFilter;
52 this.filter = filter;
55 /**
56 * {@inheritDoc}
58 * @see org.eclipse.jface.action.Action#run()
60 @Override
61 public void run() {
62 if (isChecked()) {
63 structureMergeViewerFilter.addFilter(filter);
64 } else {
65 structureMergeViewerFilter.removeFilter(filter);