Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: a85f3e926f2f842c06a506190fbd8f364066f12b (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
/*****************************************************************************
 * Copyright (c) 2012 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.layerstack;



import org.eclipse.nebula.widgets.nattable.data.IDataProvider;
import org.eclipse.nebula.widgets.nattable.grid.GridRegion;
import org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer;
import org.eclipse.nebula.widgets.nattable.layer.AbstractLayerTransform;
import org.eclipse.nebula.widgets.nattable.layer.CompositeLayer;
import org.eclipse.nebula.widgets.nattable.layer.DataLayer;
import org.eclipse.nebula.widgets.nattable.sort.ISortModel;
import org.eclipse.nebula.widgets.nattable.sort.SortHeaderLayer;
import org.eclipse.papyrus.infra.nattable.configuration.PapyrusColumnHeaderStyleConfiguration;
import org.eclipse.papyrus.infra.nattable.configuration.PapyrusColumnResizeBindingsConfiguration;
import org.eclipse.papyrus.infra.nattable.dataprovider.BodyDataProvider;
import org.eclipse.papyrus.infra.nattable.sort.IPapyrusSortModel;
import org.eclipse.papyrus.infra.nattable.utils.DefaultSizeUtils;

/**
 *
 * @author vl222926
 *
 */
public class ColumnHeaderLayerStack extends AbstractLayerTransform {


	DataLayer indexDataLayer;

	DataLayer labelDataLayer;

	/**
	 *
	 * Constructor.
	 *
	 * @param dataProvider
	 * @param bodyLayer
	 * @param bodyDataProvider
	 */
	@Deprecated
	public ColumnHeaderLayerStack(final IDataProvider dataProvider, final BodyLayerStack bodyLayer, final BodyDataProvider bodyDataProvider, final IPapyrusSortModel sortModel) {
		DataLayer dataLayer = new DataLayer(dataProvider, DefaultSizeUtils.getDefaultCellWidth(), DefaultSizeUtils.getDefaultCellHeight());
		ColumnHeaderLayer colHeaderLayer = new ColumnHeaderLayer(dataLayer, bodyLayer.getViewportLayer(), bodyLayer.getSelectionLayer(), false);
		colHeaderLayer.addConfiguration(new PapyrusColumnResizeBindingsConfiguration());
		colHeaderLayer.addConfiguration(new PapyrusColumnHeaderStyleConfiguration());
		SortHeaderLayer<ISortModel> sortHeaderLayer = new SortHeaderLayer<ISortModel>(colHeaderLayer, sortModel, false);

		setUnderlyingLayer(sortHeaderLayer);
		setRegionName(GridRegion.COLUMN_HEADER);
	}


	/**
	 *
	 * Constructor.
	 *
	 * @param indexDataProvider
	 *            the index data provider
	 * @param labelDataProvider
	 *            the label data provider
	 * @param bodyLayer
	 *            the body layer
	 */
	public ColumnHeaderLayerStack(final IDataProvider indexDataProvider, final IDataProvider labelDataProvider, final BodyLayerStack bodyLayer, final IPapyrusSortModel sortModel) {
		// 1. create the index row layer
		final DataLayer dataLayer = new DataLayer(indexDataProvider, DefaultSizeUtils.getDefaultCellWidth(), DefaultSizeUtils.getDefaultCellHeight());
		indexDataLayer = dataLayer;
		ColumnHeaderLayer indexHeader = new ColumnHeaderLayer(dataLayer, bodyLayer.getViewportLayer(), bodyLayer.getSelectionLayer(), false);

		// 2. create a composite layer to be able to have several columns in row header + add label header
		final CompositeLayer compositeLayer = new CompositeLayer(1, 2);
		compositeLayer.setChildLayer(GridRegion.COLUMN_HEADER, indexHeader, 0, 0);

		final DataLayer labelLayer = new DataLayer(labelDataProvider, DefaultSizeUtils.getDefaultCellWidth(), DefaultSizeUtils.getDefaultCellHeight());
		labelDataLayer = labelLayer;
		final ColumnHeaderLayer labelHeaderLayer = new ColumnHeaderLayer(labelLayer, bodyLayer.getViewportLayer(), bodyLayer.getSelectionLayer(), false);
		labelHeaderLayer.setRegionName(GridRegion.ROW_HEADER);

		compositeLayer.setChildLayer(GridRegion.COLUMN_HEADER, labelHeaderLayer, 0, 1);


		// 3. configure the layer
		indexHeader.addConfiguration(new PapyrusColumnResizeBindingsConfiguration());
		indexHeader.addConfiguration(new PapyrusColumnHeaderStyleConfiguration());


		compositeLayer.addConfiguration(new PapyrusColumnResizeBindingsConfiguration());
		compositeLayer.addConfiguration(new PapyrusColumnHeaderStyleConfiguration());

		SortHeaderLayer<ISortModel> sortHeaderLayer = new SortHeaderLayer<ISortModel>(compositeLayer, sortModel, false);

		setUnderlyingLayer(sortHeaderLayer);
		setRegionName(GridRegion.COLUMN_HEADER);
	}


	public DataLayer getColumnIndexDataLayer() {
		return indexDataLayer;
	}

	public DataLayer getColumnLabelDataLayer() {
		return labelDataLayer;
	}

}

Back to the top