Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 0a622a4778f9b9df435e62d8c2828e79028c39e6 (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
128
129
130
131
/*****************************************************************************
 * Copyright (c) 2014 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.dataprovider;

import org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager;
import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxis.ITreeItemAxis;
import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisconfiguration.AbstractHeaderAxisConfiguration;
import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisconfiguration.AxisIndexStyle;
import org.eclipse.papyrus.infra.nattable.utils.HeaderAxisConfigurationManagementUtils;
import org.eclipse.papyrus.infra.nattable.utils.TableHelper;

/**
 *
 * @author Vincent Lorenzo
 *         DataProvider for row index header
 */
public class RowIndexHeaderDataProvider extends AbstractIndexHeaderDataProvider {

	/**
	 *
	 * Constructor.
	 *
	 * @param tableModelManager
	 */
	public RowIndexHeaderDataProvider(final INattableModelManager tableModelManager) {
		super(tableModelManager);
	}


	/**
	 *
	 * @see org.eclipse.nebula.widgets.nattable.data.IDataProvider#setDataValue(int, int, java.lang.Object)
	 *
	 * @param columnIndex
	 * @param rowIndex
	 * @param newValue
	 */
	@Override
	public void setDataValue(final int columnIndex, final int rowIndex, final Object newValue) {
		throw new UnsupportedOperationException();
	}

	/**
	 *
	 * @see org.eclipse.papyrus.infra.nattable.dataprovider.AbstractHeaderDataProvider#getAxisConfiguration()
	 *
	 * @return
	 */
	@Override
	protected AbstractHeaderAxisConfiguration getAxisConfiguration() {
		return HeaderAxisConfigurationManagementUtils.getRowAbstractHeaderAxisConfigurationUsedInTable(this.manager.getTable());
	}

	/**
	 *
	 * @see org.eclipse.papyrus.infra.nattable.dataprovider.AbstractDataProvider#getColumnCount()
	 *
	 * @return
	 */
	@Override
	public int getColumnCount() {
		if (this.displayIndex) {
			return 1;
		}
		return 0;
	}

	/**
	 *
	 * @see org.eclipse.papyrus.infra.nattable.dataprovider.AbstractIndexHeaderDataProvider#getDataValue(int, int)
	 *
	 * @param columnIndex
	 * @param rowIndex
	 * @return
	 */
	@Override
	public Object getDataValue(int columnIndex, int rowIndex) {
		if (this.style == AxisIndexStyle.NUMERIC && displayIndexWithDepth() && TableHelper.isTreeTable(manager)) {
			return getTreeRowIndex(rowIndex);
		}
		return getAxisIndex(rowIndex);
	}

	/**
	 *
	 * @return
	 *         <code>true</code> if the index must be displayed as depth
	 */
	protected boolean displayIndexWithDepth() {
		return false;
	}

	/**
	 *
	 * @param rowIndex
	 *            a row index
	 * @return
	 *         a tree row index (1.0.0.1) ...
	 */
	private Object getTreeRowIndex(int rowIndex) {
		// not finished just here for try
		ITreeItemAxis axis = (ITreeItemAxis) manager.getRowElementsList().get(rowIndex);
		StringBuilder builder = new StringBuilder();
		ITreeItemAxis parent = axis;
		while (parent != null) {
			ITreeItemAxis p = parent.getParent();
			if (p != null) {
				int index = p.getChildren().indexOf(parent);
				builder.append(index);
				builder.append(".");//$NON-NLS-1$
			} else {
				builder.append("1");//$//$NON-NLS-1$
			}

			parent = p;

		}
		return builder.reverse().toString();
	}
}

Back to the top