Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: c8095cd36be8dd40ae0124fa93f440941840185f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*****************************************************************************
 * Copyright (c) 2015 CEA LIST and others.
 * 
 * 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:
 *   Vincent LORENZO (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
 *   Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Bug 502559
 *   
 *****************************************************************************/

package org.eclipse.papyrus.infra.nattable.filter;

import java.util.Collection;

import org.eclipse.core.runtime.Assert;
import org.eclipse.nebula.widgets.nattable.config.IConfigRegistry;
import org.eclipse.nebula.widgets.nattable.data.IColumnAccessor;

import ca.odell.glazedlists.matchers.Matcher;

/**
 * Abstract matcher class used by filter
 *
 */
public abstract class AbstractSinglePapyrusMatcher<E> implements Matcher<E> {

	/**
	 * the wanted object
	 */
	private Object matchOn;

	/**
	 * the column accesor to use
	 */
	private IColumnAccessor<Object> columnAccessor;

	/**
	 * the index of the column on which we are working
	 */
	private int columnIndex;


	/**
	 * 
	 * Constructor.
	 *
	 * @param columnAccessor
	 *            the accessor to use to get cell value
	 * @param columnIndex
	 *            the index of the column on which we are working
	 * @param matchOn
	 *            the object looked for by the filter, it must not be a collection
	 */
	public AbstractSinglePapyrusMatcher(IColumnAccessor<Object> columnAccessor, int columnIndex, Object matchOn) {
		this(columnAccessor, columnIndex, matchOn, null);
	}

	/**
	 * 
	 * Constructor.
	 *
	 * @param columnAccessor
	 *            the accessor to use to get cell value
	 * @param columnIndex
	 *            the index of the column on which we are working
	 * @param matchOn
	 *            the object looked for by the filter, it must not be a collection
	 * @param configRegistry
	 *            the config registry used by the nattable widget
	 */
	public AbstractSinglePapyrusMatcher(IColumnAccessor<Object> columnAccessor, int columnIndex, Object matchOn, IConfigRegistry configRegistry) {
		this.matchOn = matchOn;
		Assert.isTrue(!(matchOn instanceof Collection<?>));
		this.columnAccessor = columnAccessor;
		this.columnIndex = columnIndex;
	}

	/**
	 * @return the wantedObject
	 * 
	 * @since 3.0
	 */
	public final Object getObjectToMatch() {
		return matchOn;
	}

	/**
	 * @return the accessor
	 */
	protected final IColumnAccessor<Object> getColumnAccessor() {
		return columnAccessor;
	}

	/**
	 * @return the columnIndex
	 * 
	 * @since 3.0
	 */
	public final int getColumnIndex() {
		return columnIndex;
	}


	/**
	 * 
	 * @param item
	 *            an object (a row)
	 * @return
	 * 		the cell value for this row and the filtered column
	 */
	protected Object getCellValueFor(Object item) {
		return getColumnAccessor().getDataValue(item, getColumnIndex());
	}


}

Back to the top