diff options
13 files changed, 1023 insertions, 44 deletions
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.emf.nattable/src/org/eclipse/papyrus/infra/emf/nattable/manager/axis/EObjectTreeAxisManagerForEventList.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.emf.nattable/src/org/eclipse/papyrus/infra/emf/nattable/manager/axis/EObjectTreeAxisManagerForEventList.java index 4ec66ede8b2..50d4c426794 100644 --- a/plugins/infra/nattable/org.eclipse.papyrus.infra.emf.nattable/src/org/eclipse/papyrus/infra/emf/nattable/manager/axis/EObjectTreeAxisManagerForEventList.java +++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.emf.nattable/src/org/eclipse/papyrus/infra/emf/nattable/manager/axis/EObjectTreeAxisManagerForEventList.java @@ -9,31 +9,38 @@ * * Contributors: * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation + * Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Bug 487496 * *****************************************************************************/ package org.eclipse.papyrus.infra.emf.nattable.manager.axis; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import org.eclipse.emf.common.command.Command; import org.eclipse.emf.common.notify.Notification; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.edit.command.AddCommand; import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest; import org.eclipse.papyrus.infra.core.sashwindows.di.PageRef; import org.eclipse.papyrus.infra.core.sashwindows.di.Window; -import org.eclipse.papyrus.infra.nattable.dataprovider.HierarchicalRowLabelHeaderDataProvider; +import org.eclipse.papyrus.infra.emf.gmf.command.GMFtoEMFCommandWrapper; +import org.eclipse.papyrus.infra.emf.utils.EMFHelper; import org.eclipse.papyrus.infra.nattable.manager.axis.AbstractTreeAxisManagerForEventList; import org.eclipse.papyrus.infra.nattable.manager.axis.IAxisManagerForEventList; import org.eclipse.papyrus.infra.nattable.manager.axis.ITreeItemAxisManagerForEventList; import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxis.EObjectAxis; +import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxis.EObjectTreeItemAxis; import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxis.IAxis; import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxis.ITreeItemAxis; import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxis.NattableaxisFactory; import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisconfiguration.TreeFillingConfiguration; import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisprovider.NattableaxisproviderPackage; import org.eclipse.papyrus.infra.nattable.tree.ITreeItemAxisHelper; +import org.eclipse.papyrus.infra.services.edit.service.ElementEditServiceUtils; +import org.eclipse.papyrus.infra.services.edit.service.IElementEditService; //import org.eclipse.nebula.widgets.nattable.ui.NatEventData; @@ -61,7 +68,7 @@ public class EObjectTreeAxisManagerForEventList extends AbstractTreeAxisManagerF return null; } - + /** * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractAxisManager#getAddAxisCommand(org.eclipse.emf.transaction.TransactionalEditingDomain, java.util.Collection, int) * @@ -78,14 +85,15 @@ public class EObjectTreeAxisManagerForEventList extends AbstractTreeAxisManagerF } return null; } - + /** * Get the axis to add from the objects to add. * - * @param objectToAdd The objects to add. + * @param objectToAdd + * The objects to add. * @return The axis to add. */ - protected Collection<IAxis> getAxisToAdd(final Collection<Object> objectToAdd){ + protected Collection<IAxis> getAxisToAdd(final Collection<Object> objectToAdd) { final Collection<IAxis> toAdd = new ArrayList<IAxis>(); for (final Object object : objectToAdd) { if (isAllowedContents(object, null, null, 0) && !isAlreadyManaged(object)) { @@ -185,4 +193,35 @@ public class EObjectTreeAxisManagerForEventList extends AbstractTreeAxisManagerF // return true; return false; } + + /** + * {@inheritDoc} + * + * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractTreeAxisManagerForEventList#canDestroyAxisElement(java.lang.Integer) + */ + @Override + public boolean canDestroyAxisElement(final Integer axisIndex) { + final Object current = getElements().get(axisIndex); + if (current instanceof EObjectTreeItemAxis && !(((EObjectTreeItemAxis) current).getElement() instanceof TreeFillingConfiguration)) { + return !EMFHelper.isReadOnly(((EObjectTreeItemAxis) current).getElement()); + } + return false; + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.papyrus.infra.nattable.manager.axis.AbstractTreeAxisManagerForEventList#getDestroyAxisElementCommand(org.eclipse.emf.transaction.TransactionalEditingDomain, java.lang.Integer) + */ + @Override + public Command getDestroyAxisElementCommand(final TransactionalEditingDomain domain, final Integer axisPosition) { + final Object current = getElements().get(axisPosition); + if (current instanceof EObjectTreeItemAxis) { + final EObject element = ((EObjectTreeItemAxis) current).getElement(); + final DestroyElementRequest request = new DestroyElementRequest(getContextEditingDomain(), element, false); + final IElementEditService provider = ElementEditServiceUtils.getCommandProvider(element); + return new RemoveCommandWrapper(new GMFtoEMFCommandWrapper(provider.getEditCommand(request)), Collections.singleton((Object) ((EObjectTreeItemAxis) current).getElement())); + } + return null; + } } diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/axis/AbstractTreeAxisManagerForEventList.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/axis/AbstractTreeAxisManagerForEventList.java index 8cb3575b947..f08fb40fd8f 100644 --- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/axis/AbstractTreeAxisManagerForEventList.java +++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/axis/AbstractTreeAxisManagerForEventList.java @@ -206,7 +206,7 @@ public abstract class AbstractTreeAxisManagerForEventList extends AbstractAxisMa @Override public boolean canDestroyAxis(Integer axisPosition) { IAxis axis = (IAxis) getTableManager().getRowElementsList().get(axisPosition.intValue());// we need to have the tree list here and not the basic event list! - if (axis instanceof ITreeItemAxis) { + if (axis instanceof ITreeItemAxis && !(((ITreeItemAxis)axis).getElement() instanceof TreeFillingConfiguration)) { return ((ITreeItemAxis) axis).getParent() == null; } return false; @@ -515,7 +515,10 @@ public abstract class AbstractTreeAxisManagerForEventList extends AbstractAxisMa EventListHelper.removeFromEventList(eventList, axis); this.alreadyExpanded.remove(axis); ITreeItemAxisHelper.unlinkITreeItemAxisToSemanticElement(this.managedElements, axis); - ITreeItemAxisHelper.destroyITreeItemAxis(getTableEditingDomain(), axis); + final TransactionalEditingDomain tableEditingDomain = getTableEditingDomain(); + if(null != tableEditingDomain){ + ITreeItemAxisHelper.destroyITreeItemAxis(tableEditingDomain, axis); + } if (parentAxis != null) { final Object representedElement = parentAxis.getElement(); if (representedElement instanceof TreeFillingConfiguration && parentAxis.getChildren().size() == 0) { @@ -859,18 +862,20 @@ public abstract class AbstractTreeAxisManagerForEventList extends AbstractAxisMa Collection<ITreeItemAxis> itemAxisRepresentations = new ArrayList<ITreeItemAxis>(this.managedElements.get(object)); for (final ITreeItemAxis current : itemAxisRepresentations) { ITreeItemAxis parent = current.getParent(); - // must always be a TreeFillingConfiguration - TreeFillingConfiguration conf = (TreeFillingConfiguration) parent.getElement(); - Object context; - ITreeItemAxis greatParent = parent.getParent(); - if (greatParent == null) { - context = getTableContext(); - } else { - context = greatParent.getElement(); - } - Collection<?> values = getCellValueAsCollection(conf.getAxisUsedAsAxisProvider(), context); - if (!values.contains(object)) { - removeObject(current); + if(null != parent){ + // must always be a TreeFillingConfiguration + TreeFillingConfiguration conf = (TreeFillingConfiguration) parent.getElement(); + Object context; + ITreeItemAxis greatParent = parent.getParent(); + if (greatParent == null) { + context = getTableContext(); + } else { + context = greatParent.getElement(); + } + Collection<?> values = getCellValueAsCollection(conf.getAxisUsedAsAxisProvider(), context); + if (!values.contains(object)) { + removeObject(current); + } } } } diff --git a/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.clazz.config.tests/resources/bugs/bug487496/DeleteRowElement.di b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.clazz.config.tests/resources/bugs/bug487496/DeleteRowElement.di new file mode 100644 index 00000000000..bf9abab340f --- /dev/null +++ b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.clazz.config.tests/resources/bugs/bug487496/DeleteRowElement.di @@ -0,0 +1,2 @@ +<?xml version="1.0" encoding="UTF-8"?> +<xmi:XMI xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI"/> diff --git a/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.clazz.config.tests/resources/bugs/bug487496/DeleteRowElement.notation b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.clazz.config.tests/resources/bugs/bug487496/DeleteRowElement.notation new file mode 100644 index 00000000000..5082ef760bf --- /dev/null +++ b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.clazz.config.tests/resources/bugs/bug487496/DeleteRowElement.notation @@ -0,0 +1,14 @@ +<?xml version="1.0" encoding="UTF-8"?> +<nattable:Table xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:configuration="http://www.eclipse.org/papyrus/infra/viewpoints/configuration" xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" xmlns:nattable="http://www.eclipse.org/papyrus/nattable/model" xmlns:nattableaxis="http://www.eclipse.org/papyrus/nattable/model/table/nattableaxis" xmlns:nattableaxisconfiguration="http://www.eclipse.org/papyrus/nattable/model/table/nattableaxisconfiguration" xmlns:nattableaxisprovider="http://www.eclipse.org/papyrus/nattable/model/table/nattableaxisprovider" xmlns:nattableconfiguration="http://www.eclipse.org/papyrus/nattable/model/nattableconfiguration" xmlns:uml="http://www.eclipse.org/uml2/5.0.0/UML" xsi:schemaLocation="http://www.eclipse.org/papyrus/nattable/model/table/nattableaxis http://www.eclipse.org/papyrus/nattable/model#//nattableaxis http://www.eclipse.org/papyrus/nattable/model/table/nattableaxisconfiguration http://www.eclipse.org/papyrus/nattable/model#//nattableaxisconfiguration http://www.eclipse.org/papyrus/nattable/model/table/nattableaxisprovider http://www.eclipse.org/papyrus/nattable/model#//nattableaxisprovider http://www.eclipse.org/papyrus/nattable/model/nattableconfiguration http://www.eclipse.org/papyrus/nattable/model#//nattableconfiguration" xmi:id="_R5KLQNZCEeWcBd_Kg9H0rA" name="ClassTreeTable0" currentRowAxisProvider="_R5KLQ9ZCEeWcBd_Kg9H0rA" currentColumnAxisProvider="_R5KLQdZCEeWcBd_Kg9H0rA"> + <context xmi:type="uml:Model" href="DeleteRowElement.uml#_Te6_sNDSEeWied91nosKvw"/> + <owner xmi:type="uml:Model" href="DeleteRowElement.uml#_Te6_sNDSEeWied91nosKvw"/> + <prototype xmi:type="configuration:PapyrusSyncTable" href="platform:/plugin/org.eclipse.papyrus.uml.nattable.clazz.config/configs/classTreeTable.configuration#_P3J1cEr7EeSVGbM3cmVSqQ"/> + <tableConfiguration xmi:type="nattableconfiguration:TableConfiguration" href="platform:/plugin/org.eclipse.papyrus.uml.nattable.clazz.config/configs/class_synchronized_tree.nattableconfiguration#/"/> + <columnAxisProvidersHistory xmi:type="nattableaxisprovider:SlaveObjectAxisProvider" xmi:id="_R5KLQdZCEeWcBd_Kg9H0rA" description="This axis provider provides available columns according to the rows of the table (features of the object displayed on the other axis)" name="UML Feature axis provider"> + <axis xmi:type="nattableaxis:EStructuralFeatureAxis" xmi:id="_R5KLQtZCEeWcBd_Kg9H0rA"> + <manager xmi:type="nattableaxisconfiguration:AxisManagerRepresentation" href="platform:/plugin/org.eclipse.papyrus.uml.nattable.clazz.config/configs/class_synchronized_tree.nattableconfiguration#//@columnHeaderAxisConfiguration/@axisManagers.0"/> + <element xmi:type="ecore:EAttribute" href="http://www.eclipse.org/uml2/5.0.0/UML#//NamedElement/name"/> + </axis> + </columnAxisProvidersHistory> + <rowAxisProvidersHistory xmi:type="nattableaxisprovider:MasterObjectAxisProvider" xmi:id="_R5KLQ9ZCEeWcBd_Kg9H0rA" description="This axis provider manages the rows, according to the wanted hierarchy" name="HierarchicalRowaAxisManager" disconnectSlave="true"/> +</nattable:Table> diff --git a/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.clazz.config.tests/resources/bugs/bug487496/DeleteRowElement.uml b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.clazz.config.tests/resources/bugs/bug487496/DeleteRowElement.uml new file mode 100644 index 00000000000..46849860b4e --- /dev/null +++ b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.clazz.config.tests/resources/bugs/bug487496/DeleteRowElement.uml @@ -0,0 +1,9 @@ +<?xml version="1.0" encoding="UTF-8"?> +<uml:Model xmi:version="20131001" xmlns:xmi="http://www.omg.org/spec/XMI/20131001" xmlns:uml="http://www.eclipse.org/uml2/5.0.0/UML" xmi:id="_Te6_sNDSEeWied91nosKvw" name="RootElement"> + <packagedElement xmi:type="uml:Class" xmi:id="_VI3ZANDSEeWied91nosKvw" name="Class1"> + <ownedAttribute xmi:type="uml:Property" xmi:id="_byVYkAPaEdWyWsChflzPjA" name="Attribute1"/> + <ownedOperation xmi:type="uml:Operation" xmi:id="_egBG0APaEdWyWsChflzPjA" name="Operation1"> + <ownedParameter xmi:type="uml:Parameter" xmi:id="_fLshEAPaEdWyWsChflzPjA" name="Parameter1"/> + </ownedOperation> + </packagedElement> +</uml:Model> diff --git a/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.clazz.config.tests/src/org/eclipse/papyrus/uml/nattable/clazz/config/tests/bugs/DeleteRowElementTest.java b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.clazz.config.tests/src/org/eclipse/papyrus/uml/nattable/clazz/config/tests/bugs/DeleteRowElementTest.java new file mode 100644 index 00000000000..aba4c027e98 --- /dev/null +++ b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.clazz.config.tests/src/org/eclipse/papyrus/uml/nattable/clazz/config/tests/bugs/DeleteRowElementTest.java @@ -0,0 +1,439 @@ +/***************************************************************************** + * Copyright (c) 2016 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.clazz.config.tests.bugs; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +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.axis.IAxisManager; +import org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager; +import org.eclipse.papyrus.infra.nattable.manager.table.TreeNattableModelManager; +import org.eclipse.papyrus.infra.nattable.model.nattable.Table; +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.tree.CollapseAndExpandActionsEnum; +import org.eclipse.papyrus.junit.framework.classification.tests.AbstractPapyrusTest; +import org.eclipse.papyrus.junit.utils.TableUtils; +import org.eclipse.papyrus.junit.utils.rules.PapyrusEditorFixture; +import org.eclipse.papyrus.junit.utils.rules.PluginResource; +import org.eclipse.ui.IEditorPart; +import org.eclipse.uml2.uml.Model; +import org.eclipse.uml2.uml.UMLPackage; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +/** + * This class allows to test the delete row elements action. + */ +@PluginResource("resources/bugs/bug487496/DeleteRowElement.di") //$NON-NLS-1$ +public class DeleteRowElementTest extends AbstractPapyrusTest { + + /** + * The class name in the model. + */ + private static final String CLASS_NAME = "Class1"; //$NON-NLS-1$ + + /** + * The attribute name in the model. + */ + private static final String ATTRIBUTE_NAME = "Attribute1"; //$NON-NLS-1$ + + /** + * The operation name in the model. + */ + private static final String OPERATION_NAME = "Operation1"; //$NON-NLS-1$ + + /** + * The parameter name in the model. + */ + private static final String PARAMETER_NAME = "Parameter1"; //$NON-NLS-1$ + + + /** + * The table name. + */ + private static final String TABLE_NAME = "ClassTreeTable0"; //$NON-NLS-1$ + + /** + * The papyrus fixture. + */ + @Rule + public final PapyrusEditorFixture fixture = new PapyrusEditorFixture(); + + /** + * The current model. + */ + public Model model = null; + + /** + * The nattable model manager. + */ + public INattableModelManager currentManager = null; + + /** + * Constructor. + */ + public DeleteRowElementTest() { + super(); + } + + /** + * Initialize. + */ + @Before + public void init() { + // Get the model + model = (Model) fixture.getModel(); + Assert.assertNotNull("RootModel is null", model); //$NON-NLS-1$ + + // Get the table and open it + final Table mainTable = TableUtils.getNotationFirstTable(fixture.getModelSet(), TABLE_NAME); + fixture.getPageManager().openPage(mainTable); + fixture.flushDisplayEvents(); + + // Get the table and its manager + final IPageManager pageManager = fixture.getPageManager(); + final List<Object> pages = pageManager.allPages(); + pageManager.openPage(pages.get(0)); + final IEditorPart part = fixture.getEditor().getActiveEditor(); + Assert.assertTrue(part instanceof NatTableEditor); + final NatTableEditor editor = (NatTableEditor) part; + currentManager = (INattableModelManager) editor.getAdapter(INattableModelManager.class); + Assert.assertTrue("The table manage must be a tree table manager", currentManager instanceof TreeNattableModelManager); //$NON-NLS-1$ + + ((TreeNattableModelManager) currentManager).doCollapseExpandAction(CollapseAndExpandActionsEnum.EXPAND_ALL, null); + fixture.flushDisplayEvents(); + } + + /** + * This allows to test the deletion of the class row element. + * + * @throws Exception + * The caught exception. + */ + @Test + public void testClassDestroyRowElement() throws Exception { + checkInitialContent(); + + // Get the editing domain + final TransactionalEditingDomain editingDomain = fixture.getEditingDomain(); + Assert.assertNotNull("The editing domain cannot be null", editingDomain); //$NON-NLS-1$ + + // Destroy the row element + final IAxisManager axisManager = currentManager.getRowAxisManager(); + Assert.assertNotNull(axisManager); + + // The list of indexes to delete + final List<Integer> indexes = new ArrayList<Integer>(); + + // Test that this is not possible to destroy row element on tree filling + indexes.add(0); + axisManager.destroyAxisElement(indexes); + + Assert.assertNull("The command stack must be null because the destroy of tree filling musn't be possible", editingDomain.getCommandStack().getMostRecentCommand()); //$NON-NLS-1$ + + // Destroy class + indexes.clear(); + indexes.add(1); + axisManager.destroyAxisElement(indexes); + fixture.flushDisplayEvents(); + checkWithoutClass(); + + undo(editingDomain); + checkInitialContent(); + + redo(editingDomain); + checkWithoutClass(); + } + + /** + * This allows to test the deletion of the attribute row element. + * + * @throws Exception + * The caught exception. + */ + @Test + public void testAttributeDestroyRowElement() throws Exception { + checkInitialContent(); + + // Get the editing domain + final TransactionalEditingDomain editingDomain = fixture.getEditingDomain(); + Assert.assertNotNull("The editing domain cannot be null", editingDomain); //$NON-NLS-1$ + + // Destroy the row element + final IAxisManager axisManager = currentManager.getRowAxisManager(); + Assert.assertNotNull(axisManager); + + // The list of indexes to delete + final List<Integer> indexes = new ArrayList<Integer>(); + + // Test that this is not possible to destroy row element on tree filling + indexes.add(2); + axisManager.destroyAxisElement(indexes); + + Assert.assertNull("The command stack must be null because the destroy of tree filling musn't be possible", editingDomain.getCommandStack().getMostRecentCommand()); //$NON-NLS-1$ + + // Destroy attribute + indexes.clear(); + indexes.add(3); + axisManager.destroyAxisElement(indexes); + fixture.flushDisplayEvents(); + checkWithoutAttribute(); + + undo(editingDomain); + checkInitialContent(); + + redo(editingDomain); + checkWithoutAttribute(); + } + + /** + * This allows to test the deletion of the operation row element. + * + * @throws Exception + * The caught exception. + */ + @Test + public void testOperationDestroyRowElement() throws Exception { + checkInitialContent(); + + // Get the editing domain + final TransactionalEditingDomain editingDomain = fixture.getEditingDomain(); + Assert.assertNotNull("The editing domain cannot be null", editingDomain); //$NON-NLS-1$ + + // Destroy the row element + final IAxisManager axisManager = currentManager.getRowAxisManager(); + Assert.assertNotNull(axisManager); + + // The list of indexes to delete + final List<Integer> indexes = new ArrayList<Integer>(); + + // Test that this is not possible to destroy row element on tree filling + indexes.add(4); + axisManager.destroyAxisElement(indexes); + + Assert.assertNull("The command stack must be null because the destroy of tree filling musn't be possible", editingDomain.getCommandStack().getMostRecentCommand()); //$NON-NLS-1$ + + // Destroy operation + indexes.clear(); + indexes.add(5); + axisManager.destroyAxisElement(indexes); + fixture.flushDisplayEvents(); + checkWithoutOperation(); + + undo(editingDomain); + checkInitialContent(); + + redo(editingDomain); + checkWithoutOperation(); + } + + /** + * This allows to test the parameter of the class row element. + * + * @throws Exception + * The caught exception. + */ + @Test + public void testParameterDestroyRowElement() throws Exception { + checkInitialContent(); + + // Get the editing domain + final TransactionalEditingDomain editingDomain = fixture.getEditingDomain(); + Assert.assertNotNull("The editing domain cannot be null", editingDomain); //$NON-NLS-1$ + + // Destroy the row element + final IAxisManager axisManager = currentManager.getRowAxisManager(); + Assert.assertNotNull(axisManager); + + // The list of indexes to delete + final List<Integer> indexes = new ArrayList<Integer>(); + + // Test that this is not possible to destroy row element on tree filling + indexes.add(6); + axisManager.destroyAxisElement(indexes); + + Assert.assertNull("The command stack must be null because the destroy of tree filling musn't be possible", editingDomain.getCommandStack().getMostRecentCommand()); //$NON-NLS-1$ + + // Destroy parameter + indexes.clear(); + indexes.add(7); + axisManager.destroyAxisElement(indexes); + fixture.flushDisplayEvents(); + checkWithoutParameter(); + + undo(editingDomain); + checkInitialContent(); + + redo(editingDomain); + checkWithoutParameter(); + } + + /** + * This allows to undo the previous command. + * + * @param editingDomain + * The current editing domain. + * @throws Exception + * The caught exception. + */ + protected void undo(final TransactionalEditingDomain editingDomain) throws Exception { + editingDomain.getCommandStack().undo(); + ((TreeNattableModelManager) currentManager).doCollapseExpandAction(CollapseAndExpandActionsEnum.EXPAND_ALL, null); + fixture.flushDisplayEvents(); + } + + /** + * This allows to redo the previous command. + * + * @param editingDomain + * The current editing domain. + * @throws Exception + * The caught exception. + */ + protected void redo(final TransactionalEditingDomain editingDomain) throws Exception { + editingDomain.getCommandStack().redo(); + ((TreeNattableModelManager) currentManager).doCollapseExpandAction(CollapseAndExpandActionsEnum.EXPAND_ALL, null); + fixture.flushDisplayEvents(); + } + + /** + * This allows to test the initial content of the table (size and row elements). + * + * @throws Exception + * The caught exception. + */ + protected void checkInitialContent() throws Exception { + final List<Object> rowElements = currentManager.getRowElementsList(); + Assert.assertEquals("The table content size is not the correct one", 8, rowElements.size()); //$NON-NLS-1$ + + checkTableContent(true, true, true); + } + + /** + * This allows to test the content of the table (size and row elements) when the class is removed. + * + * @throws Exception + * The caught exception. + */ + protected void checkWithoutClass() throws Exception { + final List<Object> rowElements = currentManager.getRowElementsList(); + Assert.assertEquals("The table content size is not the correct one", 0, rowElements.size()); //$NON-NLS-1$ + } + + /** + * This allows to test the content of the table (size and row elements) when the attribute is removed. + * + * @throws Exception + * The caught exception. + */ + protected void checkWithoutAttribute() throws Exception { + final List<Object> rowElements = currentManager.getRowElementsList(); + Assert.assertEquals("The table content size is not the correct one", 6, rowElements.size()); //$NON-NLS-1$ + + checkTableContent(false, true, true); + } + + /** + * This allows to test the content of the table (size and row elements) when the operation is removed. + * + * @throws Exception + * The caught exception. + */ + protected void checkWithoutOperation() throws Exception { + final List<Object> rowElements = currentManager.getRowElementsList(); + Assert.assertEquals("The table content size is not the correct one", 4, rowElements.size()); //$NON-NLS-1$ + + checkTableContent(true, false, false); + } + + /** + * This allows to test the content of the table (size and row elements) when the parameter is removed. + * + * @throws Exception + * The caught exception. + */ + protected void checkWithoutParameter() throws Exception { + final List<Object> rowElements = currentManager.getRowElementsList(); + Assert.assertEquals("The table content size is not the correct one", 6, rowElements.size()); //$NON-NLS-1$ + + checkTableContent(true, true, false); + } + + /** + * This allows to check the table content with/without attribute, operation and parameter. + * + * @param hasAttribute + * Boolean to determinate if the attribute must be available. + * @param hasOperation + * Boolean to determinate if the operation must be available. + * @param hasParameter + * Boolean to determinate if the parameter must be available. + * @throws Exception + * The caught exception. + */ + protected void checkTableContent(final boolean hasAttribute, final boolean hasOperation, final boolean hasParameter) throws Exception { + int index = 0; + + final List<Object> rowElements = currentManager.getRowElementsList(); + + final IAxis firstRow = (IAxis) rowElements.get(index++); + final Object firstRowRepresentedElement = firstRow.getElement(); + Assert.assertTrue("The first row must be a tree filling configuration", firstRowRepresentedElement instanceof TreeFillingConfiguration); //$NON-NLS-1$ + + final IAxis secondRow = (IAxis) rowElements.get(index++); + final Object secondRowRepresentedElement = secondRow.getElement(); + Assert.assertEquals("The first element must be a class", UMLPackage.eINSTANCE.getClass_(), ((EObject) secondRowRepresentedElement).eClass()); //$NON-NLS-1$ + Assert.assertEquals("The name of the first element is not corresponding to the class", CLASS_NAME, ((org.eclipse.uml2.uml.Class) secondRowRepresentedElement).getName()); //$NON-NLS-1$ + + if (hasAttribute) { + final IAxis thirdRow = (IAxis) rowElements.get(index++); + final Object thirdRowRepresentedElement = thirdRow.getElement(); + Assert.assertTrue("The third row must be a tree filling configuration", thirdRowRepresentedElement instanceof TreeFillingConfiguration); //$NON-NLS-1$ + + final IAxis fourthRow = (IAxis) rowElements.get(index++); + final Object fourthRowRepresentedElement = fourthRow.getElement(); + Assert.assertEquals("The second element must be a class", UMLPackage.eINSTANCE.getProperty(), ((EObject) fourthRowRepresentedElement).eClass()); //$NON-NLS-1$ + Assert.assertEquals("The name of the second element is not corresponding to the attribute", ATTRIBUTE_NAME, ((org.eclipse.uml2.uml.Property) fourthRowRepresentedElement).getName()); //$NON-NLS-1$ + } + + if (hasOperation) { + final IAxis fifthRow = (IAxis) rowElements.get(index++); + final Object fifthRowRepresentedElement = fifthRow.getElement(); + Assert.assertTrue("The fifth row must be a tree filling configuration", fifthRowRepresentedElement instanceof TreeFillingConfiguration); //$NON-NLS-1$ + + final IAxis sixthRow = (IAxis) rowElements.get(index++); + final Object sixthRowRepresentedElement = sixthRow.getElement(); + Assert.assertEquals("The third element must be a package", UMLPackage.eINSTANCE.getOperation(), ((EObject) sixthRowRepresentedElement).eClass()); //$NON-NLS-1$ + Assert.assertEquals("The name of the third element is not corresponding to the operation", OPERATION_NAME, ((org.eclipse.uml2.uml.Operation) sixthRowRepresentedElement).getName()); //$NON-NLS-1$ + + if (hasParameter) { + final IAxis seventhRow = (IAxis) rowElements.get(index++); + final Object seventhRowRepresentedElement = seventhRow.getElement(); + Assert.assertTrue("The seventh row must be a tree filling configuration", seventhRowRepresentedElement instanceof TreeFillingConfiguration); //$NON-NLS-1$ + + final IAxis eighthRow = (IAxis) rowElements.get(index++); + final Object eighthRowRepresentedElement = eighthRow.getElement(); + Assert.assertEquals("The fourth element must be a package", UMLPackage.eINSTANCE.getParameter(), ((EObject) eighthRowRepresentedElement).eClass()); //$NON-NLS-1$ + Assert.assertEquals("The name of the fourth element is not corresponding to the parameter", PARAMETER_NAME, ((org.eclipse.uml2.uml.Parameter) eighthRowRepresentedElement).getName()); //$NON-NLS-1$ + } + } + } +}
\ No newline at end of file diff --git a/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.clazz.config.tests/src/org/eclipse/papyrus/uml/nattable/clazz/config/tests/tests/AllTests.java b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.clazz.config.tests/src/org/eclipse/papyrus/uml/nattable/clazz/config/tests/tests/AllTests.java index 5025b0a13e9..fcca5f4bc54 100644 --- a/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.clazz.config.tests/src/org/eclipse/papyrus/uml/nattable/clazz/config/tests/tests/AllTests.java +++ b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.clazz.config.tests/src/org/eclipse/papyrus/uml/nattable/clazz/config/tests/tests/AllTests.java @@ -18,6 +18,7 @@ import org.eclipse.papyrus.junit.framework.classification.ClassificationSuite; import org.eclipse.papyrus.uml.nattable.clazz.config.tests.bugs.AxisChangeIndexWithConfigurationTest; import org.eclipse.papyrus.uml.nattable.clazz.config.tests.bugs.AxisChangeIndexWithoutConfigurationTest; import org.eclipse.papyrus.uml.nattable.clazz.config.tests.bugs.DeleteRequirementsWithNestedClassifier; +import org.eclipse.papyrus.uml.nattable.clazz.config.tests.bugs.DeleteRowElementTest; import org.eclipse.papyrus.uml.nattable.clazz.config.tests.bugs.EditInvalidPastedText_V1_V3_V1; import org.eclipse.papyrus.uml.nattable.clazz.config.tests.bugs.MoveElementsTreeTableTest; import org.eclipse.papyrus.uml.nattable.clazz.config.tests.bugs.NoDepth0TreeFillingConfigurationTest; @@ -196,6 +197,9 @@ import org.junit.runners.Suite.SuiteClasses; // Move elements MoveElementsTreeTableTest.class, + + // Delete row elements + DeleteRowElementTest.class, ContentsAndExpandWithCategories_0_1_2_Tests.class, ContentsAndExpandWithoutCategories_H0_H1_H2_Tests.class, diff --git a/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.tests/META-INF/MANIFEST.MF b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.tests/META-INF/MANIFEST.MF index 4dc55c1c865..3efddfbe533 100644 --- a/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.tests/META-INF/MANIFEST.MF +++ b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.tests/META-INF/MANIFEST.MF @@ -1,24 +1,29 @@ -Manifest-Version: 1.0
-Require-Bundle: org.eclipse.ui,
- org.eclipse.core.runtime,
- org.junit;bundle-version="4.11.0",
- org.eclipse.uml2.uml,
- org.eclipse.papyrus.infra.nattable;bundle-version="1.2.0",
- org.eclipse.papyrus.infra.nattable.model;bundle-version="1.2.0",
- org.eclipse.papyrus.uml.nattable;bundle-version="1.2.0",
- org.eclipse.papyrus.infra.widgets;bundle-version="1.2.0",
- org.eclipse.papyrus.infra.emf;bundle-version="1.2.0",
- org.eclipse.papyrus.infra.core.log;bundle-version="1.2.0",
- org.eclipse.papyrus.junit.framework;bundle-version="1.2.0",
- org.eclipse.papyrus.junit.utils;bundle-version="1.2.0"
-Export-Package: org.eclipse.papyrus.uml.nattable.tests,
- org.eclipse.papyrus.uml.nattable.tests.tests
-Bundle-Vendor: %Bundle-Vendor
-Bundle-ActivationPolicy: lazy
-Bundle-Version: 1.2.0.qualifier
-Bundle-Name: %Bundle-Name
-Bundle-ManifestVersion: 2
-Bundle-Activator: org.eclipse.papyrus.uml.nattable.tests.Activator
-Bundle-Description: %pluginDescription
-Bundle-SymbolicName: org.eclipse.papyrus.uml.nattable.tests
-Bundle-RequiredExecutionEnvironment: J2SE-1.5
+Manifest-Version: 1.0 +Require-Bundle: org.eclipse.ui, + org.eclipse.core.runtime, + org.junit;bundle-version="4.11.0", + org.eclipse.uml2.uml, + org.eclipse.papyrus.infra.nattable;bundle-version="1.2.0", + org.eclipse.papyrus.infra.nattable.model;bundle-version="1.2.0", + org.eclipse.papyrus.uml.nattable;bundle-version="1.2.0", + org.eclipse.papyrus.infra.widgets;bundle-version="1.2.0", + org.eclipse.papyrus.infra.emf;bundle-version="1.2.0", + org.eclipse.papyrus.infra.core.log;bundle-version="1.2.0", + org.eclipse.papyrus.junit.framework;bundle-version="1.2.0", + org.eclipse.papyrus.junit.utils;bundle-version="1.2.0", + org.eclipse.emf.transaction, + org.eclipse.papyrus.infra.nattable.common;bundle-version="1.2.0", + org.eclipse.papyrus.infra.ui;bundle-version="1.2.0", + org.eclipse.papyrus.infra.core.sashwindows.di;bundle-version="1.2.0", + org.eclipse.papyrus.infra.core;bundle-version="1.2.0" +Export-Package: org.eclipse.papyrus.uml.nattable.tests, + org.eclipse.papyrus.uml.nattable.tests.tests +Bundle-Vendor: %Bundle-Vendor +Bundle-ActivationPolicy: lazy +Bundle-Version: 1.2.0.qualifier +Bundle-Name: %Bundle-Name +Bundle-ManifestVersion: 2 +Bundle-Activator: org.eclipse.papyrus.uml.nattable.tests.Activator +Bundle-Description: %pluginDescription +Bundle-SymbolicName: org.eclipse.papyrus.uml.nattable.tests +Bundle-RequiredExecutionEnvironment: J2SE-1.5 diff --git a/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.tests/resources/bugs/bug487496/DeleteRowElement.di b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.tests/resources/bugs/bug487496/DeleteRowElement.di new file mode 100644 index 00000000000..bf9abab340f --- /dev/null +++ b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.tests/resources/bugs/bug487496/DeleteRowElement.di @@ -0,0 +1,2 @@ +<?xml version="1.0" encoding="UTF-8"?> +<xmi:XMI xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI"/> diff --git a/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.tests/resources/bugs/bug487496/DeleteRowElement.notation b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.tests/resources/bugs/bug487496/DeleteRowElement.notation new file mode 100644 index 00000000000..2a75a4cab92 --- /dev/null +++ b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.tests/resources/bugs/bug487496/DeleteRowElement.notation @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="UTF-8"?> +<nattable:Table xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:configuration="http://www.eclipse.org/papyrus/infra/viewpoints/configuration" xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" xmlns:nattable="http://www.eclipse.org/papyrus/nattable/model" xmlns:nattableaxis="http://www.eclipse.org/papyrus/nattable/model/table/nattableaxis" xmlns:nattableaxisconfiguration="http://www.eclipse.org/papyrus/nattable/model/table/nattableaxisconfiguration" xmlns:nattableaxisprovider="http://www.eclipse.org/papyrus/nattable/model/table/nattableaxisprovider" xmlns:nattableconfiguration="http://www.eclipse.org/papyrus/nattable/model/nattableconfiguration" xmlns:nattablestyle="http://www.eclipse.org/papyrus/nattable/model/table/nattablestyle" xmlns:uml="http://www.eclipse.org/uml2/5.0.0/UML" xsi:schemaLocation="http://www.eclipse.org/papyrus/nattable/model/table/nattableaxis http://www.eclipse.org/papyrus/nattable/model#//nattableaxis http://www.eclipse.org/papyrus/nattable/model/table/nattableaxisconfiguration http://www.eclipse.org/papyrus/nattable/model#//nattableaxisconfiguration http://www.eclipse.org/papyrus/nattable/model/table/nattableaxisprovider http://www.eclipse.org/papyrus/nattable/model#//nattableaxisprovider http://www.eclipse.org/papyrus/nattable/model/nattableconfiguration http://www.eclipse.org/papyrus/nattable/model#//nattableconfiguration http://www.eclipse.org/papyrus/nattable/model/table/nattablestyle http://www.eclipse.org/papyrus/nattable/model#//nattablestyle" xmi:id="_0JVPoNbhEeWbNsm9a-cNFA" name="GenericTreeTable0" currentRowAxisProvider="_0JVPo9bhEeWbNsm9a-cNFA" currentColumnAxisProvider="_0JVPodbhEeWbNsm9a-cNFA"> + <context xmi:type="uml:Model" href="DeleteRowElement.uml#_Te6_sNDSEeWied91nosKvw"/> + <owner xmi:type="uml:Model" href="DeleteRowElement.uml#_Te6_sNDSEeWied91nosKvw"/> + <prototype xmi:type="configuration:PapyrusSyncTable" href="platform:/plugin/org.eclipse.papyrus.uml.nattable/configs/genericTreeTable.configuration#_P3J1cEr7EeSVGbM3cmVSqQ"/> + <tableConfiguration xmi:type="nattableconfiguration:TableConfiguration" href="platform:/plugin/org.eclipse.papyrus.uml.nattable/configs/genericTreeTable.nattableconfiguration#/"/> + <columnAxisProvidersHistory xmi:type="nattableaxisprovider:SlaveObjectAxisProvider" xmi:id="_0JVPodbhEeWbNsm9a-cNFA" description="This axis provider provides available columns according to the rows of the table (features of the object displayed on the other axis)" name="UML Feature axis provider"> + <axis xmi:type="nattableaxis:EStructuralFeatureAxis" xmi:id="_0JVPotbhEeWbNsm9a-cNFA"> + <manager xmi:type="nattableaxisconfiguration:AxisManagerRepresentation" href="platform:/plugin/org.eclipse.papyrus.uml.nattable/configs/genericTreeTable.nattableconfiguration#//@columnHeaderAxisConfiguration/@axisManagers.0"/> + <element xmi:type="ecore:EAttribute" href="http://www.eclipse.org/uml2/5.0.0/UML#//NamedElement/name"/> + </axis> + </columnAxisProvidersHistory> + <rowAxisProvidersHistory xmi:type="nattableaxisprovider:MasterObjectAxisProvider" xmi:id="_0JVPo9bhEeWbNsm9a-cNFA" description="This axis provider manages the rows, according to the wanted hierarchy" name="HierarchicalRowAxisManager" disconnectSlave="true"/> + <localRowHeaderAxisConfiguration xmi:type="nattableaxisconfiguration:LocalTableHeaderAxisConfiguration" xmi:id="_01ej8NbhEeWbNsm9a-cNFA" indexStyle="NUMERIC"> + <styles xmi:type="nattablestyle:IntValueStyle" xmi:id="_01fyENbhEeWbNsm9a-cNFA" name="rowLabelWidth" intValue="232"/> + </localRowHeaderAxisConfiguration> +</nattable:Table> diff --git a/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.tests/resources/bugs/bug487496/DeleteRowElement.uml b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.tests/resources/bugs/bug487496/DeleteRowElement.uml new file mode 100644 index 00000000000..46849860b4e --- /dev/null +++ b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.tests/resources/bugs/bug487496/DeleteRowElement.uml @@ -0,0 +1,9 @@ +<?xml version="1.0" encoding="UTF-8"?> +<uml:Model xmi:version="20131001" xmlns:xmi="http://www.omg.org/spec/XMI/20131001" xmlns:uml="http://www.eclipse.org/uml2/5.0.0/UML" xmi:id="_Te6_sNDSEeWied91nosKvw" name="RootElement"> + <packagedElement xmi:type="uml:Class" xmi:id="_VI3ZANDSEeWied91nosKvw" name="Class1"> + <ownedAttribute xmi:type="uml:Property" xmi:id="_byVYkAPaEdWyWsChflzPjA" name="Attribute1"/> + <ownedOperation xmi:type="uml:Operation" xmi:id="_egBG0APaEdWyWsChflzPjA" name="Operation1"> + <ownedParameter xmi:type="uml:Parameter" xmi:id="_fLshEAPaEdWyWsChflzPjA" name="Parameter1"/> + </ownedOperation> + </packagedElement> +</uml:Model> diff --git a/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.tests/src/org/eclipse/papyrus/uml/nattable/tests/bugs/DeleteRowElementTest.java b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.tests/src/org/eclipse/papyrus/uml/nattable/tests/bugs/DeleteRowElementTest.java new file mode 100644 index 00000000000..63e8f04af55 --- /dev/null +++ b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.tests/src/org/eclipse/papyrus/uml/nattable/tests/bugs/DeleteRowElementTest.java @@ -0,0 +1,430 @@ +/***************************************************************************** + * Copyright (c) 2016 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.tests.bugs; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +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.axis.IAxisManager; +import org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager; +import org.eclipse.papyrus.infra.nattable.manager.table.TreeNattableModelManager; +import org.eclipse.papyrus.infra.nattable.model.nattable.Table; +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.tree.CollapseAndExpandActionsEnum; +import org.eclipse.papyrus.junit.framework.classification.tests.AbstractPapyrusTest; +import org.eclipse.papyrus.junit.utils.TableUtils; +import org.eclipse.papyrus.junit.utils.rules.PapyrusEditorFixture; +import org.eclipse.papyrus.junit.utils.rules.PluginResource; +import org.eclipse.ui.IEditorPart; +import org.eclipse.uml2.uml.Model; +import org.eclipse.uml2.uml.UMLPackage; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +/** + * This class allows to test the delete row elements action. + */ +@PluginResource("resources/bugs/bug487496/DeleteRowElement.di") //$NON-NLS-1$ +public class DeleteRowElementTest extends AbstractPapyrusTest { + + /** + * The class name in the model. + */ + private static final String CLASS_NAME = "Class1"; //$NON-NLS-1$ + + /** + * The attribute name in the model. + */ + private static final String ATTRIBUTE_NAME = "Attribute1"; //$NON-NLS-1$ + + /** + * The operation name in the model. + */ + private static final String OPERATION_NAME = "Operation1"; //$NON-NLS-1$ + + /** + * The parameter name in the model. + */ + private static final String PARAMETER_NAME = "Parameter1"; //$NON-NLS-1$ + + + /** + * The table name. + */ + private static final String TABLE_NAME = "GenericTreeTable0"; //$NON-NLS-1$ + + /** + * The papyrus fixture. + */ + @Rule + public final PapyrusEditorFixture fixture = new PapyrusEditorFixture(); + + /** + * The current model. + */ + public Model model = null; + + /** + * The nattable model manager. + */ + public INattableModelManager currentManager = null; + + /** + * Constructor. + */ + public DeleteRowElementTest() { + super(); + } + + /** + * Initialize. + */ + @Before + public void init() { + // Get the model + model = (Model) fixture.getModel(); + Assert.assertNotNull("RootModel is null", model); //$NON-NLS-1$ + + // Get the table and open it + final Table mainTable = TableUtils.getNotationFirstTable(fixture.getModelSet(), TABLE_NAME); + fixture.getPageManager().openPage(mainTable); + fixture.flushDisplayEvents(); + + // Get the table and its manager + final IPageManager pageManager = fixture.getPageManager(); + final List<Object> pages = pageManager.allPages(); + pageManager.openPage(pages.get(0)); + final IEditorPart part = fixture.getEditor().getActiveEditor(); + Assert.assertTrue(part instanceof NatTableEditor); + final NatTableEditor editor = (NatTableEditor) part; + currentManager = (INattableModelManager) editor.getAdapter(INattableModelManager.class); + Assert.assertTrue("The table manage must be a tree table manager", currentManager instanceof TreeNattableModelManager); //$NON-NLS-1$ + + ((TreeNattableModelManager) currentManager).doCollapseExpandAction(CollapseAndExpandActionsEnum.EXPAND_ALL, null); + fixture.flushDisplayEvents(); + } + + /** + * This allows to test the deletion of the class row element. + * + * @throws Exception + * The caught exception. + */ + @Test + public void testClassDestroyRowElement() throws Exception { + checkInitialContent(); + + // Get the editing domain + final TransactionalEditingDomain editingDomain = fixture.getEditingDomain(); + Assert.assertNotNull("The editing domain cannot be null", editingDomain); //$NON-NLS-1$ + + // Destroy the row element + final IAxisManager axisManager = currentManager.getRowAxisManager(); + Assert.assertNotNull(axisManager); + + // The list of indexes to delete + final List<Integer> indexes = new ArrayList<Integer>(); + + // Test that this is not possible to destroy row element on tree filling + indexes.add(0); + axisManager.destroyAxisElement(indexes); + + Assert.assertNull("The command stack must be null because the destroy of tree filling musn't be possible", editingDomain.getCommandStack().getMostRecentCommand()); //$NON-NLS-1$ + + // Destroy class + indexes.clear(); + indexes.add(1); + axisManager.destroyAxisElement(indexes); + fixture.flushDisplayEvents(); + checkWithoutClass(); + + undo(editingDomain); + checkInitialContent(); + + redo(editingDomain); + checkWithoutClass(); + } + + /** + * This allows to test the deletion of the attribute row element. + * + * @throws Exception + * The caught exception. + */ + @Test + public void testAttributeDestroyRowElement() throws Exception { + checkInitialContent(); + + // Get the editing domain + final TransactionalEditingDomain editingDomain = fixture.getEditingDomain(); + Assert.assertNotNull("The editing domain cannot be null", editingDomain); //$NON-NLS-1$ + + // Destroy the row element + final IAxisManager axisManager = currentManager.getRowAxisManager(); + Assert.assertNotNull(axisManager); + + // The list of indexes to delete + final List<Integer> indexes = new ArrayList<Integer>(); + + // Test that this is not possible to destroy row element on tree filling + indexes.add(2); + axisManager.destroyAxisElement(indexes); + + Assert.assertNull("The command stack must be null because the destroy of tree filling musn't be possible", editingDomain.getCommandStack().getMostRecentCommand()); //$NON-NLS-1$ + + // Destroy attribute + indexes.clear(); + indexes.add(3); + axisManager.destroyAxisElement(indexes); + fixture.flushDisplayEvents(); + checkWithoutAttribute(); + + undo(editingDomain); + checkInitialContent(); + + redo(editingDomain); + checkWithoutAttribute(); + } + + /** + * This allows to test the deletion of the operation row element. + * + * @throws Exception + * The caught exception. + */ + @Test + public void testOperationDestroyRowElement() throws Exception { + checkInitialContent(); + + // Get the editing domain + final TransactionalEditingDomain editingDomain = fixture.getEditingDomain(); + Assert.assertNotNull("The editing domain cannot be null", editingDomain); //$NON-NLS-1$ + + // Destroy the row element + final IAxisManager axisManager = currentManager.getRowAxisManager(); + Assert.assertNotNull(axisManager); + + // The list of indexes to delete + final List<Integer> indexes = new ArrayList<Integer>(); + + // Destroy operation + indexes.add(4); + axisManager.destroyAxisElement(indexes); + fixture.flushDisplayEvents(); + checkWithoutOperation(); + + undo(editingDomain); + checkInitialContent(); + + redo(editingDomain); + checkWithoutOperation(); + } + + /** + * This allows to test the parameter of the class row element. + * + * @throws Exception + * The caught exception. + */ + @Test + public void testParameterDestroyRowElement() throws Exception { + checkInitialContent(); + + // Get the editing domain + final TransactionalEditingDomain editingDomain = fixture.getEditingDomain(); + Assert.assertNotNull("The editing domain cannot be null", editingDomain); //$NON-NLS-1$ + + // Destroy the row element + final IAxisManager axisManager = currentManager.getRowAxisManager(); + Assert.assertNotNull(axisManager); + + // The list of indexes to delete + final List<Integer> indexes = new ArrayList<Integer>(); + + // Test that this is not possible to destroy row element on tree filling + indexes.add(5); + axisManager.destroyAxisElement(indexes); + + Assert.assertNull("The command stack must be null because the destroy of tree filling musn't be possible", editingDomain.getCommandStack().getMostRecentCommand()); //$NON-NLS-1$ + + // Destroy parameter + indexes.clear(); + indexes.add(6); + axisManager.destroyAxisElement(indexes); + fixture.flushDisplayEvents(); + checkWithoutParameter(); + + undo(editingDomain); + checkInitialContent(); + + redo(editingDomain); + checkWithoutParameter(); + } + + /** + * This allows to undo the previous command. + * + * @param editingDomain + * The current editing domain. + * @throws Exception + * The caught exception. + */ + protected void undo(final TransactionalEditingDomain editingDomain) throws Exception { + editingDomain.getCommandStack().undo(); + ((TreeNattableModelManager) currentManager).doCollapseExpandAction(CollapseAndExpandActionsEnum.EXPAND_ALL, null); + fixture.flushDisplayEvents(); + } + + /** + * This allows to redo the previous command. + * + * @param editingDomain + * The current editing domain. + * @throws Exception + * The caught exception. + */ + protected void redo(final TransactionalEditingDomain editingDomain) throws Exception { + editingDomain.getCommandStack().redo(); + ((TreeNattableModelManager) currentManager).doCollapseExpandAction(CollapseAndExpandActionsEnum.EXPAND_ALL, null); + fixture.flushDisplayEvents(); + } + + /** + * This allows to test the initial content of the table (size and row elements). + * + * @throws Exception + * The caught exception. + */ + protected void checkInitialContent() throws Exception { + final List<Object> rowElements = currentManager.getRowElementsList(); + Assert.assertEquals("The table content size is not the correct one", 7, rowElements.size()); //$NON-NLS-1$ + + checkTableContent(true, true, true); + } + + /** + * This allows to test the content of the table (size and row elements) when the class is removed. + * + * @throws Exception + * The caught exception. + */ + protected void checkWithoutClass() throws Exception { + final List<Object> rowElements = currentManager.getRowElementsList(); + Assert.assertEquals("The table content size is not the correct one", 0, rowElements.size()); //$NON-NLS-1$ + } + + /** + * This allows to test the content of the table (size and row elements) when the attribute is removed. + * + * @throws Exception + * The caught exception. + */ + protected void checkWithoutAttribute() throws Exception { + final List<Object> rowElements = currentManager.getRowElementsList(); + Assert.assertEquals("The table content size is not the correct one", 6, rowElements.size()); //$NON-NLS-1$ + + checkTableContent(false, true, true); + } + + /** + * This allows to test the content of the table (size and row elements) when the operation is removed. + * + * @throws Exception + * The caught exception. + */ + protected void checkWithoutOperation() throws Exception { + final List<Object> rowElements = currentManager.getRowElementsList(); + Assert.assertEquals("The table content size is not the correct one", 4, rowElements.size()); //$NON-NLS-1$ + + checkTableContent(true, false, false); + } + + /** + * This allows to test the content of the table (size and row elements) when the parameter is removed. + * + * @throws Exception + * The caught exception. + */ + protected void checkWithoutParameter() throws Exception { + final List<Object> rowElements = currentManager.getRowElementsList(); + Assert.assertEquals("The table content size is not the correct one", 5, rowElements.size()); //$NON-NLS-1$ + + checkTableContent(true, true, false); + } + + /** + * This allows to check the table content with/without attribute, operation and parameter. + * + * @param hasAttribute + * Boolean to determinate if the attribute must be available. + * @param hasOperation + * Boolean to determinate if the operation must be available. + * @param hasParameter + * Boolean to determinate if the parameter must be available. + * @throws Exception + * The caught exception. + */ + protected void checkTableContent(final boolean hasAttribute, final boolean hasOperation, final boolean hasParameter) throws Exception { + int index = 0; + + final List<Object> rowElements = currentManager.getRowElementsList(); + + final IAxis firstRow = (IAxis) rowElements.get(index++); + final Object firstRowRepresentedElement = firstRow.getElement(); + Assert.assertTrue("The first row must be a tree filling configuration", firstRowRepresentedElement instanceof TreeFillingConfiguration); //$NON-NLS-1$ + + final IAxis secondRow = (IAxis) rowElements.get(index++); + final Object secondRowRepresentedElement = secondRow.getElement(); + Assert.assertEquals("The first element must be a class", UMLPackage.eINSTANCE.getClass_(), ((EObject) secondRowRepresentedElement).eClass()); //$NON-NLS-1$ + Assert.assertEquals("The name of the first element is not corresponding to the class", CLASS_NAME, ((org.eclipse.uml2.uml.Class) secondRowRepresentedElement).getName()); //$NON-NLS-1$ + + if (hasAttribute || hasOperation) { + final IAxis thirdRow = (IAxis) rowElements.get(index++); + final Object thirdRowRepresentedElement = thirdRow.getElement(); + Assert.assertTrue("The third row must be a tree filling configuration", thirdRowRepresentedElement instanceof TreeFillingConfiguration); //$NON-NLS-1$ + } + + if (hasAttribute) { + final IAxis fourthRow = (IAxis) rowElements.get(index++); + final Object fourthRowRepresentedElement = fourthRow.getElement(); + Assert.assertEquals("The second element must be a class", UMLPackage.eINSTANCE.getProperty(), ((EObject) fourthRowRepresentedElement).eClass()); //$NON-NLS-1$ + Assert.assertEquals("The name of the second element is not corresponding to the attribute", ATTRIBUTE_NAME, ((org.eclipse.uml2.uml.Property) fourthRowRepresentedElement).getName()); //$NON-NLS-1$ + } + + if (hasOperation) { + final IAxis fifthRow = (IAxis) rowElements.get(index++); + final Object fifthRowRepresentedElement = fifthRow.getElement(); + Assert.assertEquals("The third element must be a package", UMLPackage.eINSTANCE.getOperation(), ((EObject) fifthRowRepresentedElement).eClass()); //$NON-NLS-1$ + Assert.assertEquals("The name of the third element is not corresponding to the operation", OPERATION_NAME, ((org.eclipse.uml2.uml.Operation) fifthRowRepresentedElement).getName()); //$NON-NLS-1$ + + if (hasParameter) { + final IAxis sixthRow = (IAxis) rowElements.get(index++); + final Object sixthRowRepresentedElement = sixthRow.getElement(); + Assert.assertTrue("The seventh row must be a tree filling configuration", sixthRowRepresentedElement instanceof TreeFillingConfiguration); //$NON-NLS-1$ + + final IAxis seventhRow = (IAxis) rowElements.get(index++); + final Object seventhRowRepresentedElement = seventhRow.getElement(); + Assert.assertEquals("The fourth element must be a package", UMLPackage.eINSTANCE.getParameter(), ((EObject) seventhRowRepresentedElement).eClass()); //$NON-NLS-1$ + Assert.assertEquals("The name of the fourth element is not corresponding to the parameter", PARAMETER_NAME, ((org.eclipse.uml2.uml.Parameter) seventhRowRepresentedElement).getName()); //$NON-NLS-1$ + } + } + } +}
\ No newline at end of file diff --git a/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.tests/src/org/eclipse/papyrus/uml/nattable/tests/tests/AllTests.java b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.tests/src/org/eclipse/papyrus/uml/nattable/tests/tests/AllTests.java index bd734f00d5a..083bdb1726f 100644 --- a/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.tests/src/org/eclipse/papyrus/uml/nattable/tests/tests/AllTests.java +++ b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.tests/src/org/eclipse/papyrus/uml/nattable/tests/tests/AllTests.java @@ -12,6 +12,7 @@ package org.eclipse.papyrus.uml.nattable.tests.tests; +import org.eclipse.papyrus.uml.nattable.tests.bugs.DeleteRowElementTest; import org.eclipse.papyrus.uml.nattable.tests.tests.configs.GenericTreeTableConfigurationTest; import org.eclipse.papyrus.uml.nattable.tests.tests.configs.GenericTreeTableNattableConfigurationTest; import org.junit.runner.RunWith; @@ -21,7 +22,10 @@ import org.junit.runners.Suite.SuiteClasses; @RunWith(ClassificationSuite.class) @SuiteClasses({ UMLRestrictedContentProviderTest.class, UMLRestrictedContentProviderTestCustomProfile.class, GenericTreeTableConfigurationTest.class, - GenericTreeTableNattableConfigurationTest.class + GenericTreeTableNattableConfigurationTest.class, + + // Delete row elements + DeleteRowElementTest.class }) public class AllTests { |