Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 5727ed91b99e21ac909cc6e7c65ea1b1c02c8bb8 (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
/*****************************************************************************
 * 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:
 *   CEA LIST - Initial API and implementation
 *   
 *****************************************************************************/

package org.eclipse.papyrus.uml.nattable.clazz.config.tests.bugs;

import java.util.Collection;
import java.util.List;

import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.osgi.util.NLS;
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.cell.CellManagerFactory;
import org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager;
import org.eclipse.papyrus.infra.nattable.manager.table.ITreeNattableModelManager;
import org.eclipse.papyrus.infra.nattable.model.nattable.Table;
import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxis.EStructuralFeatureAxis;
import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxis.IAxis;
import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisconfiguration.TreeFillingConfiguration;
import org.eclipse.papyrus.infra.nattable.model.nattable.nattablecell.Cell;
import org.eclipse.papyrus.infra.nattable.model.nattable.nattableproblem.Problem;
import org.eclipse.papyrus.infra.nattable.model.nattable.nattableproblem.StringResolutionProblem;
import org.eclipse.papyrus.infra.nattable.tree.CollapseAndExpandActionsEnum;
import org.eclipse.papyrus.infra.nattable.utils.AxisUtils;
import org.eclipse.papyrus.infra.nattable.utils.FillingConfigurationUtils;
import org.eclipse.papyrus.infra.nattable.utils.StyleUtils;
import org.eclipse.papyrus.infra.nattable.utils.TableClipboardUtils;
import org.eclipse.papyrus.infra.nattable.utils.TableEditingDomainUtils;
import org.eclipse.papyrus.infra.tools.util.FileUtils;
import org.eclipse.papyrus.junit.utils.rules.PapyrusEditorFixture;
import org.eclipse.papyrus.junit.utils.rules.PluginResource;
import org.eclipse.papyrus.uml.nattable.clazz.config.tests.Activator;
import org.eclipse.ui.IEditorPart;
import org.eclipse.uml2.uml.Class;
import org.eclipse.uml2.uml.Package;
import org.eclipse.uml2.uml.Property;
import org.eclipse.uml2.uml.UMLPackage;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;

/**
 * This test verifies than the problem created by a paste is destroyed after a set value
 *
 */
@PluginResource("resources/bugs/bug468914/EditInvalidPastedText_V1_V3_V1.di")
public class EditInvalidPastedText_V1_V3_V1 {

	@Rule
	public final PapyrusEditorFixture fixture = new PapyrusEditorFixture();

	/**
	 * the nattable editor
	 */
	private NatTableEditor editor;

	/**
	 * the tree table manager
	 */
	private ITreeNattableModelManager manager;

	/** the UML elements required by the tests */
	private Package root;

	private Class class1;

	private Class class2;

	private Property property1;

	private Property property2;


	private static final String CLASS_1 = "Class1"; //$NON-NLS-1$
	private static final String CLASS_2 = "Class2"; //$NON-NLS-1$

	private static final String PROPERTY_1 = "Property1"; //$NON-NLS-1$
	private static final String PROPERTY_2 = "Property2"; //$NON-NLS-1$

	private IAxis prop1Axis;

	private IAxis prop2Axis;

	private IAxis featureTypeAxis;

	/**
	 * load the table editor
	 */
	@Before
	public void init() {
		// TODO : a java annotation similar to diagram could be used to activate the table before the JUnit test
		IPageManager pageManager = fixture.getPageManager();
		List<Object> pages = pageManager.allPages();
		pageManager.openPage(pages.get(0));
		IEditorPart part = fixture.getEditor().getActiveEditor();
		Assert.assertTrue(part instanceof NatTableEditor);
		this.editor = (NatTableEditor) part;
		INattableModelManager m = (INattableModelManager) editor.getAdapter(INattableModelManager.class);
		Assert.assertTrue(m instanceof ITreeNattableModelManager);
		this.manager = (ITreeNattableModelManager) m;


		// we init the field of the class
		manager.doCollapseExpandAction(CollapseAndExpandActionsEnum.EXPAND_ALL, null);
		fixture.flushDisplayEvents();


		EObject context = this.manager.getTable().getContext();
		Assert.assertTrue(context instanceof Package);
		this.root = (Package) context;
		this.class1 = (Class) this.root.getMember(CLASS_1);
		this.class2 = (Class) this.root.getMember(CLASS_2);
		Assert.assertNotNull(class1);
		Assert.assertNotNull(class2);


		this.property1 = (Property) this.class1.getMember(PROPERTY_1);
		this.property2 = (Property) this.class1.getMember(PROPERTY_2);

		Assert.assertNotNull(property1);
		Assert.assertNotNull(property2);

		Assert.assertNull(property1.getType());
		Assert.assertNull(property2.getType());

		List<Object> rows = manager.getRowElementsList();
		List<Object> columns = manager.getColumnElementsList();

		for (Object current : columns) {
			if (current instanceof EStructuralFeatureAxis) {
				if (((EStructuralFeatureAxis) current).getElement() == UMLPackage.eINSTANCE.getTypedElement_Type()) {
					featureTypeAxis = (EStructuralFeatureAxis) current;
				}
			}
			if (featureTypeAxis != null) {
				break;
			}
		}

		Assert.assertNotNull(featureTypeAxis);

		for (Object current : rows) {
			Object representedElement = AxisUtils.getRepresentedElement(current);
			if (AxisUtils.getRepresentedElement(current) instanceof Property) {
				Property property = (Property) representedElement;
				if (property1 == property) {
					prop1Axis = (IAxis) current;
				}
				if (property2 == property) {
					prop2Axis = (IAxis) current;
				}
			}
		}

		Assert.assertNotNull(prop1Axis);
		Assert.assertNotNull(prop2Axis);

	}

	/**
	 * this test check than the StringResolutionProblem and its associated Cell are destroyed by a cell edition + Undo/Redo
	 */
	@Test
	public void test() {
		TransactionalEditingDomain contextEditingDomain = TableEditingDomainUtils.getTableContextEditingDomain(manager.getTable());

		// we check the returned value for property1/type
		Object cellValue1 = CellManagerFactory.INSTANCE.getCrossValue(featureTypeAxis, prop1Axis, manager);
		Assert.assertTrue(cellValue1 instanceof List<?>);
		List<?> pb1 = (List<?>) cellValue1;

		// we check the cell value saved in the table model
		Cell cell1 = manager.getCell(featureTypeAxis, prop1Axis);
		Assert.assertNotNull(cell1);
		Assert.assertEquals(pb1, cell1.getProblems());

		Problem problem = (Problem) pb1.get(0);
		Assert.assertTrue(problem instanceof StringResolutionProblem);
		StringResolutionProblem stringProblem1 = (StringResolutionProblem) problem;
		Assert.assertEquals(CLASS_2, stringProblem1.getValueAsString());


		// we set the value
		CellManagerFactory.INSTANCE.setCellValue(contextEditingDomain, featureTypeAxis, prop1Axis, class2, manager);
		fixture.flushDisplayEvents();

		// we check the set value
		Assert.assertEquals(class2, property1.getType());

		// we check the value returned by the cell manager
		cellValue1 = CellManagerFactory.INSTANCE.getCrossValue(featureTypeAxis, prop1Axis, manager);
		Assert.assertEquals(class2, cellValue1);

		// we check the cell value saved in the table model
		cell1 = manager.getCell(featureTypeAxis, prop1Axis);
		Assert.assertNull(cell1);

		// we check the undo
		contextEditingDomain.getCommandStack().undo();
		fixture.flushDisplayEvents();

		// we check the set value
		Assert.assertNull(property1.getType());

		cellValue1 = CellManagerFactory.INSTANCE.getCrossValue(featureTypeAxis, prop1Axis, manager);
		Assert.assertTrue(cellValue1 instanceof List<?>);
		pb1 = (List<?>) cellValue1;

		// we check the cell value saved in the table model
		cell1 = manager.getCell(featureTypeAxis, prop1Axis);
		Assert.assertNotNull(cell1);
		Assert.assertEquals(pb1, cell1.getProblems());

		problem = (Problem) pb1.get(0);
		Assert.assertTrue(problem instanceof StringResolutionProblem);
		stringProblem1 = (StringResolutionProblem) problem;
		Assert.assertEquals(CLASS_2, stringProblem1.getValueAsString());

		// we check the redo
		contextEditingDomain.getCommandStack().redo();
		fixture.flushDisplayEvents();

		// we check the set value
		Assert.assertEquals(class2, property1.getType());

		// we check the value returned by the cell manager
		cellValue1 = CellManagerFactory.INSTANCE.getCrossValue(featureTypeAxis, prop1Axis, manager);
		Assert.assertEquals(class2, cellValue1);

		// we check the cell value saved in the table model
		cell1 = manager.getCell(featureTypeAxis, prop1Axis);
		Assert.assertNull(cell1);
	}


}

Back to the top