Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: e06024fd5253f2449508617e4b64e105eeab4b29 (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
/*****************************************************************************
 * Copyright (c) 2017 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:
 *   Nicolas FAUVERGUE (CEA LIST) nicolas.fauvergue@all4tec.net - Initial API and implementation
 *   Thanh Liem PHAN (ALL4TEC) thanhliem.phan@all4tec.net - Bug 515806
 *****************************************************************************/

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

import java.util.Collection;
import java.util.Iterator;

import org.eclipse.nebula.widgets.nattable.config.IConfigRegistry;
import org.eclipse.nebula.widgets.nattable.data.validate.IDataValidator;
import org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell;
import org.eclipse.papyrus.infra.nattable.utils.CellHelper;

/**
 * The validator used for boolean editor in the filter row header.
 *
 * @since 3.0
 */
public class BooleanFilterDataValidator implements IDataValidator {

	/**
	 * {@inheritDoc}
	 *
	 * @see org.eclipse.nebula.widgets.nattable.data.validate.IDataValidator#validate(int, int, java.lang.Object)
	 */
	@Override
	public boolean validate(int columnIndex, int rowIndex, Object newValue) {
		return false;
	}

	/**
	 * {@inheritDoc}
	 *
	 * @see org.eclipse.nebula.widgets.nattable.data.validate.IDataValidator#validate(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell, org.eclipse.nebula.widgets.nattable.config.IConfigRegistry, java.lang.Object)
	 */
	@Override
	public boolean validate(ILayerCell cell, IConfigRegistry configRegistry, Object newValue) {
		if (null == newValue) {
			return true;
		}
		if (newValue instanceof Boolean) {
			return true;
		} else if (newValue instanceof String && newValue.equals(CellHelper.getUnsupportedCellContentsText())) {
			return true;
		} else if (newValue instanceof Collection<?>) {
			boolean result = true;
			final Iterator<?> values = ((Collection<?>) newValue).iterator();
			while (values.hasNext() && result) {
				final Object value = values.next();
				result = validate(cell, configRegistry, value);
			}
			return result;
		}
		return false;
	}

}

Back to the top