diff options
| author | Laurent Redor | 2016-05-10 12:34:39 +0000 |
|---|---|---|
| committer | Maxime Porhel | 2016-05-11 12:56:23 +0000 |
| commit | 97dbdad00c8fe2767b8184ff3b0af992833739c3 (patch) | |
| tree | fe9759e4ff1be9a27ebfa906c53d9d423cee8e76 | |
| parent | 6d7e5a887dadb1a3c9a2f72722d08212d2dec9e7 (diff) | |
| download | org.eclipse.sirius-97dbdad00c8fe2767b8184ff3b0af992833739c3.tar.gz org.eclipse.sirius-97dbdad00c8fe2767b8184ff3b0af992833739c3.tar.xz org.eclipse.sirius-97dbdad00c8fe2767b8184ff3b0af992833739c3.zip | |
[485554] Fix NPE in case of precondition in CreateTargetColumn tool
Same fix as [1] for DLine but for DTargetColumn.
This commit also adds tests for both:
* The CreateLineToolTest has been renamed in
CreateTableWithToolWithPrecondtionTest to also address Column case.
* The case of line has also been fixed because despite the name of the
test, testOpenTableWithPreconditionOnCreateLineTool(), there is no
precondition in the corresponding table description.
[1]
http://git.eclipse.org/c/sirius/org.eclipse.sirius.git/commit/?id=ceae267a9fc56c3b80212f2b04bc411710c93b35
Bug: 485554
Cherry-picked-from:493350
Change-Id: I20728a3c2932ac8ebac97ff153998b085d8f0aaa
Signed-off-by: Laurent Redor <laurent.redor@obeo.fr>
5 files changed, 105 insertions, 75 deletions
diff --git a/plugins/org.eclipse.sirius.table.ui/src/org/eclipse/sirius/table/ui/tools/internal/editor/action/CreateTargetColumnAction.java b/plugins/org.eclipse.sirius.table.ui/src/org/eclipse/sirius/table/ui/tools/internal/editor/action/CreateTargetColumnAction.java index 6d9fd3b358..ee424d2406 100644 --- a/plugins/org.eclipse.sirius.table.ui/src/org/eclipse/sirius/table/ui/tools/internal/editor/action/CreateTargetColumnAction.java +++ b/plugins/org.eclipse.sirius.table.ui/src/org/eclipse/sirius/table/ui/tools/internal/editor/action/CreateTargetColumnAction.java @@ -59,14 +59,12 @@ public class CreateTargetColumnAction extends AbstractTargetColumnAction { @Override public void run() { super.run(); - EObject target; + EObject target = getTarget(); DTable columnContainer; DTargetColumn dTargetColumn = getColumn(); if (dTargetColumn != null) { - target = dTargetColumn.getTarget(); columnContainer = (DTable) dTargetColumn.eContainer(); } else { - target = table.getTarget(); columnContainer = table; } Command cmd = tableCommandFactory.buildCreateColumnCommandFromTool(columnContainer, target, getCreateTool()); @@ -75,6 +73,15 @@ public class CreateTargetColumnAction extends AbstractTargetColumnAction { getEditingDomain().getCommandStack().execute(cmd); } + private EObject getTarget() { + DTargetColumn dTargetColumn = getColumn(); + if (dTargetColumn != null) { + return dTargetColumn.getTarget(); + } else { + return getTable().getTarget(); + } + } + @Override public boolean canExecute() { boolean canExecute = true; @@ -83,21 +90,19 @@ public class CreateTargetColumnAction extends AbstractTargetColumnAction { canExecute = false; } else { if (getCreateTool().getPrecondition() != null && !StringUtil.isEmpty(getCreateTool().getPrecondition().trim())) { - IInterpreter interpreter; + EObject target = getTarget(); + IInterpreter interpreter = InterpreterUtil.getInterpreter(target); + interpreter.setVariable(IInterpreterSiriusVariables.ELEMENT, target); if (getColumn() != null) { - interpreter = InterpreterUtil.getInterpreter(getColumn().getTarget()); interpreter.setVariable(IInterpreterSiriusVariables.ROOT, TableHelper.getTable(getColumn()).getTarget()); - interpreter.setVariable(IInterpreterSiriusVariables.ELEMENT, getColumn().getTarget()); interpreter.setVariable(IInterpreterSiriusVariables.CONTAINER, ((DTable) getColumn().eContainer()).getTarget()); } else { - interpreter = InterpreterUtil.getInterpreter(getTable().getTarget()); interpreter.setVariable(IInterpreterSiriusVariables.ROOT, getTable().getTarget()); - interpreter.setVariable(IInterpreterSiriusVariables.ELEMENT, getTable().getTarget()); interpreter.setVariable(IInterpreterSiriusVariables.CONTAINER, null); } try { - canExecute = interpreter.evaluateBoolean(getColumn().getTarget(), getCreateTool().getPrecondition()); + canExecute = interpreter.evaluateBoolean(target, getCreateTool().getPrecondition()); } catch (final EvaluationException e) { RuntimeLoggerManager.INSTANCE.error(getCreateTool(), ToolPackage.eINSTANCE.getAbstractToolDescription_Precondition(), e); } diff --git a/plugins/org.eclipse.sirius.tests.junit/data/table/unit/tools/tests.odesign b/plugins/org.eclipse.sirius.tests.junit/data/table/unit/tools/tests.odesign index 4646a08c69..0acf31f824 100644 --- a/plugins/org.eclipse.sirius.tests.junit/data/table/unit/tools/tests.odesign +++ b/plugins/org.eclipse.sirius.tests.junit/data/table/unit/tools/tests.odesign @@ -14,7 +14,7 @@ <variables name="root" documentation="The semantic element corresponding to the current table."/> </delete> </ownedLineMappings> - <ownedCreateLine name="TestTableTools_Classes_CreateLine" forceRefresh="true" mapping="//@ownedViewpoints[name='TestTableTools']/@ownedRepresentations[name='TestTableTools_Classes']/@ownedLineMappings[name='classes']"> + <ownedCreateLine name="TestTableTools_Classes_CreateLine" precondition="true" forceRefresh="true" mapping="//@ownedViewpoints[name='TestTableTools']/@ownedRepresentations[name='TestTableTools_Classes']/@ownedLineMappings[name='classes']"> <variables name="root" documentation="The semantic element of the table."/> <variables name="element" documentation="The semantic currently edited element."/> <variables name="container" documentation="The semantic element corresponding to the view container."/> @@ -55,10 +55,11 @@ <mask mask="{0}"/> </create> </intersection> - <createColumn mapping="//@ownedViewpoints[name='TestTableTools']/@ownedRepresentations[name='TestTableTools_Columns']/@ownedColumnMappings.0"> + <createColumn precondition="true" mapping="//@ownedViewpoints[name='TestTableTools']/@ownedRepresentations[name='TestTableTools_Columns']/@ownedColumnMappings.0"> <variables name="root" documentation="The semantic element of the table."/> <variables name="element" documentation="The semantic currently edited element."/> <variables name="container" documentation="The semantic element corresponding to the view container."/> + <firstModelOperation xsi:type="tool:ChangeContext" browseExpression="var:self"/> </createColumn> </ownedRepresentations> </ownedViewpoints> diff --git a/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/suite/table/AllTablePluginTests.java b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/suite/table/AllTablePluginTests.java index 3b6ef6e9de..719818e8ac 100644 --- a/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/suite/table/AllTablePluginTests.java +++ b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/suite/table/AllTablePluginTests.java @@ -34,7 +34,7 @@ import org.eclipse.sirius.tests.unit.table.unit.sort.DTableSortByColumnTest; import org.eclipse.sirius.tests.unit.table.unit.sort.DTableSortByColumnTestWithEditor; import org.eclipse.sirius.tests.unit.table.unit.sort.DTableSortByLineTest; import org.eclipse.sirius.tests.unit.table.unit.sort.DTableSortByLineWithEditorTests; -import org.eclipse.sirius.tests.unit.table.unit.tools.CreateLineToolTest; +import org.eclipse.sirius.tests.unit.table.unit.tools.CreateTableWithToolWithPrecondtionTest; import org.eclipse.sirius.tests.unit.table.unit.tools.NoVariableDuplicationTest; import org.eclipse.sirius.tests.unit.table.unit.tools.RefreshToolActionBarTest; import org.eclipse.sirius.tests.unit.table.unit.tools.TableToolPreconditionCompletionTest; @@ -88,7 +88,7 @@ public class AllTablePluginTests extends TestCase { suite.addTestSuite(DefaultVariablesOnToolsTest.class); suite.addTestSuite(TableAdapterFactoryRegistryTest.class); suite.addTestSuite(SpecifyArrays_Test.class); - suite.addTestSuite(CreateLineToolTest.class); + suite.addTestSuite(CreateTableWithToolWithPrecondtionTest.class); suite.addTestSuite(RefreshToolActionBarTest.class); suite.addTestSuite(TableToolPreconditionCompletionTest.class); suite.addTestSuite(DTableSynchronizerVSMWithEditorTest.class); diff --git a/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/table/unit/tools/CreateLineToolTest.java b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/table/unit/tools/CreateLineToolTest.java deleted file mode 100644 index 77e391eefb..0000000000 --- a/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/table/unit/tools/CreateLineToolTest.java +++ /dev/null @@ -1,62 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010, 2014 THALES GLOBAL SERVICES. - * 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: - * Obeo - initial API and implementation - *******************************************************************************/ -package org.eclipse.sirius.tests.unit.table.unit.tools; - -import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.sirius.table.metamodel.table.DTable; -import org.eclipse.sirius.tests.SiriusTestsPlugin; -import org.eclipse.sirius.tests.support.api.EclipseTestsSupportHelper; -import org.eclipse.sirius.tests.support.api.SiriusDiagramTestCase; -import org.eclipse.sirius.tests.support.api.TestsUtil; -import org.eclipse.sirius.ui.business.api.dialect.DialectUIManager; -import org.eclipse.ui.IEditorPart; - -/** - * Test the good opening of table editor - * - * @author cnotot - */ -public class CreateLineToolTest extends SiriusDiagramTestCase { - - private static final String PATH = "/data/table/unit/tools/"; - - private static final String SEMANTIC_MODEL_FILENAME = "tests.ecore"; - - String MODELER_PATH = "/" + SiriusTestsPlugin.PLUGIN_ID + "/data/table/unit/tools/tests.odesign"; - - String VIEWPOINT_NAME = "TestTableTools"; - - String REPRESENTATION_DESC__NAME = "TestTableTools_Classes"; - - @Override - protected void setUp() throws Exception { - super.setUp(); - EclipseTestsSupportHelper.INSTANCE.copyFile(SiriusTestsPlugin.PLUGIN_ID, PATH + "/" + SEMANTIC_MODEL_FILENAME, "/" + TEMPORARY_PROJECT_NAME + "/" + SEMANTIC_MODEL_FILENAME); - - genericSetUp(TEMPORARY_PROJECT_NAME + "/" + SEMANTIC_MODEL_FILENAME, MODELER_PATH); - - initViewpoint(VIEWPOINT_NAME); - } - - public void testOpenTableWithPreconditionOnCreateLineTool() throws Exception { - final DTable dTable = (DTable) createRepresentation(REPRESENTATION_DESC__NAME, semanticModel); - IEditorPart editor = DialectUIManager.INSTANCE.openEditor(session, dTable, new NullProgressMonitor()); - TestsUtil.synchronizationWithUIThread(); - assertNotNull("The editor has not been correctly opened", editor); - - if (editor != null) { - // Close of the editor - DialectUIManager.INSTANCE.closeEditor(editor, false); - TestsUtil.synchronizationWithUIThread(); - } - } - -} diff --git a/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/table/unit/tools/CreateTableWithToolWithPrecondtionTest.java b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/table/unit/tools/CreateTableWithToolWithPrecondtionTest.java new file mode 100644 index 0000000000..e4987e77e8 --- /dev/null +++ b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/table/unit/tools/CreateTableWithToolWithPrecondtionTest.java @@ -0,0 +1,86 @@ +/******************************************************************************* + * Copyright (c) 2010, 2016 THALES GLOBAL SERVICES. + * 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: + * Obeo - initial API and implementation + *******************************************************************************/ +package org.eclipse.sirius.tests.unit.table.unit.tools; + +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.sirius.table.metamodel.table.DTable; +import org.eclipse.sirius.table.metamodel.table.description.CrossTableDescription; +import org.eclipse.sirius.table.metamodel.table.description.EditionTableDescription; +import org.eclipse.sirius.tests.SiriusTestsPlugin; +import org.eclipse.sirius.tests.support.api.EclipseTestsSupportHelper; +import org.eclipse.sirius.tests.support.api.SiriusDiagramTestCase; +import org.eclipse.sirius.tests.support.api.TestsUtil; +import org.eclipse.sirius.ui.business.api.dialect.DialectUIManager; +import org.eclipse.sirius.viewpoint.description.RepresentationDescription; +import org.eclipse.ui.IEditorPart; + +/** + * Test the good opening of table editor. + * + * @author cnotot + */ +public class CreateTableWithToolWithPrecondtionTest extends SiriusDiagramTestCase { + + private static final String PATH = "/data/table/unit/tools/"; + + private static final String SEMANTIC_MODEL_FILENAME = "tests.ecore"; + + String MODELER_PATH = "/" + SiriusTestsPlugin.PLUGIN_ID + "/data/table/unit/tools/tests.odesign"; + + String VIEWPOINT_NAME = "TestTableTools"; + + String EDITION_TABLE_DESC__NAME = "TestTableTools_Classes"; + + String CROSS_TABLE_DESC__NAME = "TestTableTools_Columns"; + + @Override + protected void setUp() throws Exception { + super.setUp(); + EclipseTestsSupportHelper.INSTANCE.copyFile(SiriusTestsPlugin.PLUGIN_ID, PATH + "/" + SEMANTIC_MODEL_FILENAME, "/" + TEMPORARY_PROJECT_NAME + "/" + SEMANTIC_MODEL_FILENAME); + + genericSetUp(TEMPORARY_PROJECT_NAME + "/" + SEMANTIC_MODEL_FILENAME, MODELER_PATH); + + initViewpoint(VIEWPOINT_NAME); + } + + public void testOpenTableWithPreconditionOnCreateLineTool() throws Exception { + RepresentationDescription repDescription = getRepresentationDescription(EDITION_TABLE_DESC__NAME, session.getSelectedViewpoints(false).iterator().next()); + assertTrue("No edition table description found for name " + EDITION_TABLE_DESC__NAME, repDescription instanceof EditionTableDescription); + assertFalse("The precondition of the line creation tool should be valuated.", ((EditionTableDescription) repDescription).getAllCreateLine().get(0).getPrecondition().isEmpty()); + final DTable dTable = (DTable) createRepresentation(EDITION_TABLE_DESC__NAME, semanticModel); + IEditorPart editor = DialectUIManager.INSTANCE.openEditor(session, dTable, new NullProgressMonitor()); + TestsUtil.synchronizationWithUIThread(); + assertNotNull("The editor has not been correctly opened", editor); + + if (editor != null) { + // Close of the editor + DialectUIManager.INSTANCE.closeEditor(editor, false); + TestsUtil.synchronizationWithUIThread(); + } + } + + public void testOpenTableWithPreconditionOnCreatColumnTool() throws Exception { + RepresentationDescription repDescription = getRepresentationDescription(CROSS_TABLE_DESC__NAME, session.getSelectedViewpoints(false).iterator().next()); + assertTrue("No cross table description found for name " + CROSS_TABLE_DESC__NAME, repDescription instanceof CrossTableDescription); + assertFalse("The precondition of the column creation tool should be valuated.", ((CrossTableDescription) repDescription).getCreateColumn().get(0).getPrecondition().isEmpty()); + + final DTable dTable = (DTable) createRepresentation(CROSS_TABLE_DESC__NAME, semanticModel); + IEditorPart editor = DialectUIManager.INSTANCE.openEditor(session, dTable, new NullProgressMonitor()); + TestsUtil.synchronizationWithUIThread(); + assertNotNull("The editor has not been correctly opened", editor); + + if (editor != null) { + // Close of the editor + DialectUIManager.INSTANCE.closeEditor(editor, false); + TestsUtil.synchronizationWithUIThread(); + } + } +} |
