Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: f96d8d6d3566e7af15e77cf7032754b5a902ca6e (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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
/*******************************************************************************
 * Copyright (c) 2012, 2013 Original authors 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:
 *     Original authors and others - initial API and implementation
 ******************************************************************************/
package org.eclipse.papyrus.infra.nattable.sort;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.eclipse.nebula.widgets.nattable.NatTable;
import org.eclipse.nebula.widgets.nattable.config.IConfigRegistry;
import org.eclipse.nebula.widgets.nattable.data.IColumnAccessor;
import org.eclipse.nebula.widgets.nattable.data.IColumnPropertyResolver;
//import org.eclipse.nebula.widgets.nattable.extension.glazedlists.NatColumnTableFormat;
import org.eclipse.nebula.widgets.nattable.layer.ILayer;
import org.eclipse.nebula.widgets.nattable.layer.event.ILayerEvent;
import org.eclipse.nebula.widgets.nattable.layer.event.StructuralRefreshEvent;
import org.eclipse.nebula.widgets.nattable.sort.SortDirectionEnum;
import org.eclipse.papyrus.infra.nattable.glazedlists.PapyrusSortingState;
import org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager;
import org.eclipse.papyrus.infra.nattable.sort.copy.NatTableComparatorChooser;

import ca.odell.glazedlists.SortedList;


/**
 * 
 * @author VL222926
 *         This class provides the sort model for an axis
 */
public class PapyrusGlazedListsSortModel extends AbstractGlazedListSortModel {
	
	/**
	 * the column accessor
	 */
	protected IColumnAccessor<Object> columnAccessor;

	/**
	 * the sorted list
	 */
	protected SortedList<Object> sortedList;

	// TODO : useful
	private NatTableComparatorChooser<Object> comparatorChooser;
	// protected SortedList<T> sortedList;

	// TODO : useful ?
	protected IColumnPropertyResolver columnPropertyResolver;

	// TODO : useful ?
	protected ILayer columnHeaderDataLayer;


	/**
	 * Constructor.
	 *
	 * @param manager
	 * @param sortedList
	 * @param columnAccessor
	 */
	public PapyrusGlazedListsSortModel(INattableModelManager manager, SortedList<Object> sortedList, IColumnAccessor<Object> columnAccessor) {
		super(manager);
		this.columnAccessor = columnAccessor;
		this.sortedList = sortedList;
	}


	
	protected PapyrusNatColumnTableFormat<Object> f;

	protected NatTableComparatorChooser<Object> getComparatorChooser() {

		if (comparatorChooser == null) {
			f = new PapyrusNatColumnTableFormat<Object>(columnAccessor, getTableManager(), columnHeaderDataLayer);
			comparatorChooser =
					new PapyrusNatTableComparatorChooser(sortedList, f) {

						/**
						 * @see ca.odell.glazedlists.gui.AbstractTableComparatorChooser#createSortingState()
						 *
						 * @return
						 */
						@Override
						protected org.eclipse.papyrus.infra.nattable.glazedlists.copy.SortingState createSortingState() {
							return new PapyrusSortingState(this, getTableManager());
						}
					};
		}

		return comparatorChooser;
	}

	protected IConfigRegistry getConfigRegistry() {
		NatTable nat = (NatTable) getTableManager().getAdapter(NatTable.class);
		return nat.getConfigRegistry();
	}

	@Override
	public List<Integer> getSortedColumnIndexes() {
		return getComparatorChooser().getSortingColumns();
	}

	@Override
	public int getSortOrder(int columnIndex) {
		return getComparatorChooser().getClickSequence(columnIndex);
	}

	@Override
	public SortDirectionEnum getSortDirection(int columnIndex) {
		return getComparatorChooser().getSortDirectionForColumnIndex(columnIndex);
	}

	@Override
	public boolean isColumnIndexSorted(int columnIndex) {
		return getComparatorChooser().isColumnIndexSorted(columnIndex);
	}

	@Override
	public List<Comparator> getComparatorsForColumnIndex(int columnIndex) {
		return getComparatorChooser().getComparatorsForColumn(columnIndex);
	}

	@Override
	public void sort(int columnIndex, SortDirectionEnum sortDirection, boolean accumulate) {
		getComparatorChooser().sort(columnIndex, sortDirection, accumulate);
	}

	@Override
	public void clear() {
		getComparatorChooser().clearComparator();
	}

	@Override
	public void handleLayerEvent(ILayerEvent event) {
		if (event instanceof StructuralRefreshEvent && ((StructuralRefreshEvent) event).isHorizontalStructureChanged()) {
			String test = getComparatorChooser().toString();
			this.comparatorChooser = null;
			getComparatorChooser().fromString(test);
		}
	}

	/**
	 * @param compositeLayer
	 */
	// TODO : try to remove me
	public void setColumnHeaderLayer(ILayer compositeLayer) {
		this.columnHeaderDataLayer = compositeLayer;
		this.columnHeaderDataLayer.addLayerListener(this);// useful ?
		if (f != null) {
			f.setColumnHeaderDataLayer(columnHeaderDataLayer);
		}
	}

	/**
	 * @see org.eclipse.papyrus.infra.nattable.sort.IPapyrusSortModel#updateSort()
	 *
	 */
	// @Override
	public void updateSort() {
		// TODO Auto-generated method stub

	}

	/**
	 * @see org.eclipse.nebula.widgets.nattable.sort.ISortModel#getColumnComparator(int)
	 *
	 * @param columnIndex
	 * @return
	 */
	@Override
	public Comparator<?> getColumnComparator(int columnIndex) {
		// TODO Auto-generated method stub
		return null;
	}
}

Back to the top