Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: d0bbb8df3a97c094cf198d3afdc845302293451a (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
121
122
123
124
125
126
127
/*****************************************************************************
 * Copyright (c) 2013 CEA LIST.
 *
 *    
 * 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
 *
 *****************************************************************************/
package org.eclipse.papyrus.infra.nattable.utils;

import org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager;
import org.eclipse.papyrus.infra.nattable.model.nattable.Table;
import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxis.IAxis;
import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxis.IdAxis;
import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisprovider.AbstractAxisProvider;

/**
 * Common methods for axis management
 * 
 * @author Vincent Lorenzo
 * 
 */
public class AxisUtils {

	private AxisUtils() {
		//to prevent instanciation
	}

	/**
	 * This regex allows to find all word character (letters + numbers)+ the whitespace
	 */
	public static final String REGEX = "[^\\w\\s]";

	/**
	 * This methods avoid to duplicate these some lines
	 * 
	 * @param axisElement
	 *        an axis element
	 * @return
	 *         if the axis element is a String returns it and if the axis element is an instance of IdAxis, returns the String represented by this
	 *         axis
	 */
	public static final String getPropertyId(final Object axisElement) {
		String id = null;
		if(axisElement instanceof IdAxis) {
			id = ((IdAxis)axisElement).getElement();
		} else if(axisElement instanceof String) {
			id = (String)axisElement;
		}
		return id;
	}

	/**
	 * 
	 * @param axisElement
	 *        an axis element
	 * @return
	 *         if axisElement is an IAxis, we return the element represented by the IAxis using IAxis.getElement() else we return the element itself
	 */
	public static final Object getRepresentedElement(final Object axisElement) {
		Object representedElement;
		if(axisElement instanceof IAxis) {
			representedElement = ((IAxis)axisElement).getElement();
		} else {
			representedElement = axisElement;
		}
		return representedElement;
	}

	/**
	 * 
	 * @param table
	 *        a table
	 * @return
	 *         the axismanager used for rows, managing the invert axis
	 */
	public static final AbstractAxisProvider getAxisProviderUsedForRows(final Table table) {
		AbstractAxisProvider provider = table.getCurrentRowAxisProvider();
		if(table.isInvertAxis()) {
			provider = table.getCurrentColumnAxisProvider();
		}
		return provider;
	}

	/**
	 * 
	 * @param table
	 *        a table
	 * @return
	 *         the axismanager used for columns, managing the invert axis
	 */
	public static final AbstractAxisProvider getAxisProviderUsedForColumns(final Table table) {
		AbstractAxisProvider provider = table.getCurrentColumnAxisProvider();
		if(table.isInvertAxis()) {
			provider = table.getCurrentRowAxisProvider();
		}
		return provider;
	}

	/**
	 * 
	 * @param manager
	 *        a table manager
	 * @return
	 *         the axismanager used for rows, managing the invert axis
	 */
	public static final AbstractAxisProvider getAxisProviderUsedForRows(final INattableModelManager manager) {
		return getAxisProviderUsedForRows(manager.getTable());
	}

	/**
	 * 
	 * @param manager
	 *        a table manager
	 * @return
	 *         the axismanager used for columns, managing the invert axis
	 */
	public static final AbstractAxisProvider getAxisProviderUsedForColumns(final INattableModelManager manager) {
		return getAxisProviderUsedForColumns(manager.getTable());
	}

}

Back to the top