Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 9210a4acd41ff90fbbf2d84665f2869c1266fb62 (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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
/*****************************************************************************
 * Copyright (c) 2015 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 (ALL4TEC) nicolas.fauvergue@all4tec.net - Initial API and implementation
 *   
 *****************************************************************************/

package org.eclipse.papyrus.uml.nattable.generic.tests.bugs;

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

import org.eclipse.core.commands.Command;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.IHandler;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.nebula.widgets.nattable.grid.layer.RowHeaderLayer;
import org.eclipse.nebula.widgets.nattable.layer.AbstractLayer;
import org.eclipse.nebula.widgets.nattable.layer.DataLayer;
import org.eclipse.papyrus.infra.core.sashwindows.di.service.IPageManager;
import org.eclipse.papyrus.infra.nattable.common.editor.NatTableEditor;
import org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager;
import org.eclipse.papyrus.infra.nattable.manager.table.NattableModelManager;
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.ui.util.EclipseCommandUtils;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.commands.ICommandService;
import org.eclipse.ui.handlers.RadioState;
import org.junit.Assert;
import org.junit.Test;

/**
 * This abstract class allow to define the tests for the change axis index style when the axis are inverted.
 */
public abstract class AbstractInvertedAxisChangeIndexTest extends AbstractAxisChangeIndexTest {
	
	/**
	 * Constructor.
	 */
	public AbstractInvertedAxisChangeIndexTest() {
		super();
	}

	/**
	 * 
	 * @see org.eclipse.papyrus.uml.nattable.generic.tests.bugs.AbstractAxisChangeIndexTest#testChangeIndexInitialColumn()
	 *
	 * @throws Exception
	 */
	@Override
	@Test
	public void testChangeIndexInitialColumn() throws Exception {
		// Try to execute a resize command to check the re-creation
		IPageManager pageManager = fixture.getPageManager();
		List<Object> pages = pageManager.allPages();
		pageManager.openPage(pages.get(0));
		IEditorPart part = fixture.getEditor().getActiveEditor();
		Assert.assertTrue(part instanceof NatTableEditor);
		NatTableEditor editor = (NatTableEditor) part;
		INattableModelManager currentManager = (INattableModelManager) editor.getAdapter(INattableModelManager.class);
		Assert.assertTrue(currentManager instanceof INattableModelManager);

		// check the initial data
		checkNumericColumn(currentManager);

		// Get the command service
		ICommandService commandService = EclipseCommandUtils.getCommandService();
		Assert.assertNotNull(commandService);

		// Get the command and the handler
		Command cmd = commandService.getCommand("org.eclipse.papyrus.infra.nattable.column.index.style"); //$NON-NLS-1$
		IHandler handler = cmd.getHandler();
		Assert.assertTrue(handler.isEnabled());

		// Put the numeric parameter
		Map<String, String> parameter = new HashMap<String, String>(1);
		parameter.put(RadioState.PARAMETER_ID, AxisIndexStyle.ALPHABETIC.getName()); // $NON-NLS-1$

		// Execute the command with the correct parameter and check its result
		ExecutionEvent event = new ExecutionEvent(cmd, parameter, null, null);
		fixture.flushDisplayEvents();
		Object res = cmd.executeWithChecks(event);
		Assert.assertTrue(res instanceof IStatus);
		IStatus iStatus = (IStatus) res;
		Assert.assertTrue("Returned status is not OK", iStatus.isOK()); //$NON-NLS-1$

		// Check the numeric column data
		checkAlphabeticColumn(currentManager);

		// Put the alphabetic parameter
		parameter.clear();
		parameter.put(RadioState.PARAMETER_ID, AxisIndexStyle.NUMERIC.getName()); // $NON-NLS-1$

		// Execute the command with the correct parameter and check its result
		event = new ExecutionEvent(cmd, parameter, null, null);
		fixture.flushDisplayEvents();
		res = cmd.executeWithChecks(event);
		Assert.assertTrue(res instanceof IStatus);
		iStatus = (IStatus) res;
		Assert.assertTrue("Returned status is not OK", iStatus.isOK()); //$NON-NLS-1$

		// check the initial data
		checkNumericColumn(currentManager);
	}

	/**
	 * 
	 * @see org.eclipse.papyrus.uml.nattable.generic.tests.bugs.AbstractAxisChangeIndexTest#testChangeIndexInitialRow()
	 *
	 * @throws Exception
	 */
	@Override
	@Test
	public void testChangeIndexInitialRow() throws Exception {
		// Try to execute a resize command to check the re-creation
		IPageManager pageManager = fixture.getPageManager();
		List<Object> pages = pageManager.allPages();
		pageManager.openPage(pages.get(0));
		IEditorPart part = fixture.getEditor().getActiveEditor();
		Assert.assertTrue(part instanceof NatTableEditor);
		NatTableEditor editor = (NatTableEditor) part;
		INattableModelManager currentManager = (INattableModelManager) editor.getAdapter(INattableModelManager.class);
		Assert.assertTrue(currentManager instanceof INattableModelManager);

		// check the initial data
		checkAlphabeticRow(currentManager);

		// Get the command service
		ICommandService commandService = EclipseCommandUtils.getCommandService();
		Assert.assertNotNull(commandService);

		// Get the command and the handler
		Command cmd = commandService.getCommand("org.eclipse.papyrus.infra.nattable.row.index.style"); //$NON-NLS-1$
		IHandler handler = cmd.getHandler();
		Assert.assertTrue(handler.isEnabled());

		// Put the numeric parameter
		Map<String, String> parameter = new HashMap<String, String>(1);
		parameter.put(RadioState.PARAMETER_ID, AxisIndexStyle.NUMERIC.getName()); // $NON-NLS-1$

		// Execute the command with the correct parameter and check its result
		ExecutionEvent event = new ExecutionEvent(cmd, parameter, null, null);
		fixture.flushDisplayEvents();
		Object res = cmd.executeWithChecks(event);
		Assert.assertTrue(res instanceof IStatus);
		IStatus iStatus = (IStatus) res;
		Assert.assertTrue("Returned status is not OK", iStatus.isOK()); //$NON-NLS-1$

		// Check the numeric column data
		checkNumericRow(currentManager);

		// Put the alphabetic parameter
		parameter.clear();
		parameter.put(RadioState.PARAMETER_ID, AxisIndexStyle.ALPHABETIC.getName());

		// Execute the command with the correct parameter and check its result
		event = new ExecutionEvent(cmd, parameter, null, null);
		fixture.flushDisplayEvents();
		res = cmd.executeWithChecks(event);
		Assert.assertTrue(res instanceof IStatus);
		iStatus = (IStatus) res;
		Assert.assertTrue("Returned status is not OK", iStatus.isOK()); //$NON-NLS-1$

		// check the initial data
		checkAlphabeticRow(currentManager);
	}
	
	/**
	 * @see org.eclipse.papyrus.uml.nattable.generic.tests.bugs.AbstractAxisChangeIndexTest#checkAlphabeticColumn(org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager)
	 *
	 * @param currentManager
	 */
	@Override
	public void checkAlphabeticColumn(final INattableModelManager currentManager) {
		// Check the index style
		AbstractHeaderAxisConfiguration headerConfiguration = HeaderAxisConfigurationManagementUtils.getColumnAbstractHeaderAxisInTable(currentManager.getTable());
		if (null == headerConfiguration) {
			headerConfiguration = HeaderAxisConfigurationManagementUtils.getColumnAbstractHeaderAxisInTableConfiguration(currentManager.getTable());
		}
		Assert.assertEquals("This is not the alphabetic style", headerConfiguration.getIndexStyle(), AxisIndexStyle.ALPHABETIC); //$NON-NLS-1$

		// Check the data
		final AbstractLayer columnHeaderLayerIndex = ((NattableModelManager) currentManager).getColumnHeaderLayerStack().getColumnIndexDataLayer();
		Assert.assertTrue("The column layer is not a data layer", columnHeaderLayerIndex instanceof DataLayer); //$NON-NLS-1$
		Assert.assertEquals("The first column index is not corresponding to 'A'", INDEX_A, ((DataLayer) columnHeaderLayerIndex).getDataValueByPosition(0, 0)); //$NON-NLS-1$
		Assert.assertEquals("The second column index is not corresponding to 'B'", INDEX_B, ((DataLayer) columnHeaderLayerIndex).getDataValueByPosition(1, 0)); //$NON-NLS-1$
	}

	/**
	 * @see org.eclipse.papyrus.uml.nattable.generic.tests.bugs.AbstractAxisChangeIndexTest#checkNumericColumn(org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager)
	 *
	 * @param currentManager
	 */
	@Override
	public void checkNumericColumn(final INattableModelManager currentManager) {
		// Check the index style
		AbstractHeaderAxisConfiguration headerConfiguration = HeaderAxisConfigurationManagementUtils.getColumnAbstractHeaderAxisInTable(currentManager.getTable());
		if (null == headerConfiguration) {
			headerConfiguration = HeaderAxisConfigurationManagementUtils.getColumnAbstractHeaderAxisInTableConfiguration(currentManager.getTable());
		}
		Assert.assertEquals("This is not the numeric style", headerConfiguration.getIndexStyle(), AxisIndexStyle.NUMERIC); //$NON-NLS-1$

		// Check the data
		final AbstractLayer columnHeaderLayerIndex = ((NattableModelManager) currentManager).getColumnHeaderLayerStack().getColumnIndexDataLayer();
		Assert.assertTrue("The column layer is not a data layer", columnHeaderLayerIndex instanceof DataLayer); //$NON-NLS-1$
		Assert.assertEquals("The first column index is not corresponding to '0'", INDEX_0, ((DataLayer) columnHeaderLayerIndex).getDataValueByPosition(0, 0)); //$NON-NLS-1$
		Assert.assertEquals("The second column index is not corresponding to '1'", INDEX_1, ((DataLayer) columnHeaderLayerIndex).getDataValueByPosition(1, 0)); //$NON-NLS-1$
	}

	/**
	 * @see org.eclipse.papyrus.uml.nattable.generic.tests.bugs.AbstractAxisChangeIndexTest#checkNumericRow(org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager)
	 *
	 * @param currentManager
	 */
	@Override
	public void checkNumericRow(final INattableModelManager currentManager) {
		// Check the index style
		AbstractHeaderAxisConfiguration headerConfiguration = HeaderAxisConfigurationManagementUtils.getRowAbstractHeaderAxisInTable(currentManager.getTable());
		if (null == headerConfiguration) {
			headerConfiguration = HeaderAxisConfigurationManagementUtils.getRowAbstractHeaderAxisInTableConfiguration(currentManager.getTable());
		}
		Assert.assertEquals("This is not the numeric style", headerConfiguration.getIndexStyle(), AxisIndexStyle.NUMERIC); //$NON-NLS-1$

		// check the data
		final AbstractLayer rowHeaderLayerIndex = ((NattableModelManager) currentManager).getRowHeaderLayerStack().getRowHeaderLayerIndex();
		Assert.assertTrue("The row layer is not a row header layer", rowHeaderLayerIndex instanceof RowHeaderLayer); //$NON-NLS-1$
		Assert.assertEquals("The first row index is not corresponding to '0'", INDEX_0, ((RowHeaderLayer) rowHeaderLayerIndex).getDataValueByPosition(0, 0)); //$NON-NLS-1$
		Assert.assertEquals("The second row index is not corresponding to '1'", INDEX_1, ((RowHeaderLayer) rowHeaderLayerIndex).getDataValueByPosition(0, 1)); //$NON-NLS-1$
		Assert.assertEquals("The third row index is not corresponding to '2'", INDEX_2, ((RowHeaderLayer) rowHeaderLayerIndex).getDataValueByPosition(0, 2)); //$NON-NLS-1$
	}

	/**
	 * @see org.eclipse.papyrus.uml.nattable.generic.tests.bugs.AbstractAxisChangeIndexTest#checkAlphabeticRow(org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager)
	 *
	 * @param currentManager
	 */
	@Override
	public void checkAlphabeticRow(final INattableModelManager currentManager) {
		// Check the index style
		AbstractHeaderAxisConfiguration headerConfiguration = HeaderAxisConfigurationManagementUtils.getRowAbstractHeaderAxisInTable(currentManager.getTable());
		if (null == headerConfiguration) {
			headerConfiguration = HeaderAxisConfigurationManagementUtils.getRowAbstractHeaderAxisInTableConfiguration(currentManager.getTable());
		}
		Assert.assertEquals("This is not the alphabetic style", headerConfiguration.getIndexStyle(), AxisIndexStyle.ALPHABETIC); //$NON-NLS-1$

		// check the data
		final AbstractLayer rowHeaderLayerIndex = ((NattableModelManager) currentManager).getRowHeaderLayerStack().getRowHeaderLayerIndex();
		Assert.assertTrue("The row layer is not a row header layer", rowHeaderLayerIndex instanceof RowHeaderLayer); //$NON-NLS-1$
		Assert.assertEquals("The first row index is not corresponding to 'A'", INDEX_A, ((RowHeaderLayer) rowHeaderLayerIndex).getDataValueByPosition(0, 0)); //$NON-NLS-1$
		Assert.assertEquals("The second row index is not corresponding to 'B'", INDEX_B, ((RowHeaderLayer) rowHeaderLayerIndex).getDataValueByPosition(0, 1)); //$NON-NLS-1$
		Assert.assertEquals("The third row index is not corresponding to 'C'", INDEX_C, ((RowHeaderLayer) rowHeaderLayerIndex).getDataValueByPosition(0, 2)); //$NON-NLS-1$
	}

}

Back to the top