diff options
author | Vincent Lorenzo | 2020-06-16 11:26:53 +0000 |
---|---|---|
committer | Vincent Lorenzo | 2020-06-25 15:05:18 +0000 |
commit | 4e88f8511802fd00252736078238b8225e087738 (patch) | |
tree | 367fd55d66bd213bda7dd17347e48ec86d2b41d0 /tests/junit/plugins/infra/nattable | |
parent | 14112315bfbffc042f66d5659eeab3bd00c7a1d8 (diff) | |
download | org.eclipse.papyrus-4e88f8511802fd00252736078238b8225e087738.tar.gz org.eclipse.papyrus-4e88f8511802fd00252736078238b8225e087738.tar.xz org.eclipse.papyrus-4e88f8511802fd00252736078238b8225e087738.zip |
Bug 517617: [Table] Refresh method reset a bad selection in the table and move the scrollbar
Bug 532452: [Table] Table editor shall not change the current selection when a column is resized.
- change the storage method for the selection
- update paste/insert/overwrite methods and Junit tests when required
- fill the api changes plugin
Change-Id: I9e9851cd9d9772b633ac42db040d3d5c8f7e376f
Signed-off-by: Vincent Lorenzo <vincent.lorenzo@cea.fr>
Diffstat (limited to 'tests/junit/plugins/infra/nattable')
2 files changed, 60 insertions, 154 deletions
diff --git a/tests/junit/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.tests/src/org/eclipse/papyrus/infra/nattable/tests/tests/AllTests.java b/tests/junit/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.tests/src/org/eclipse/papyrus/infra/nattable/tests/tests/AllTests.java index 65d62b980b9..65d62b980b9 100644..100755 --- a/tests/junit/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.tests/src/org/eclipse/papyrus/infra/nattable/tests/tests/AllTests.java +++ b/tests/junit/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.tests/src/org/eclipse/papyrus/infra/nattable/tests/tests/AllTests.java diff --git a/tests/junit/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.tests/src/org/eclipse/papyrus/infra/nattable/tests/tests/TableSelectionProviderTest.java b/tests/junit/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.tests/src/org/eclipse/papyrus/infra/nattable/tests/tests/TableSelectionProviderTest.java index ab020db2fb7..99450b62564 100644 --- a/tests/junit/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.tests/src/org/eclipse/papyrus/infra/nattable/tests/tests/TableSelectionProviderTest.java +++ b/tests/junit/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.tests/src/org/eclipse/papyrus/infra/nattable/tests/tests/TableSelectionProviderTest.java @@ -1,7 +1,7 @@ /***************************************************************************** - * Copyright (c) 2014 CEA LIST. + * Copyright (c) 2014, 2020 CEA LIST. + * * - * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -11,35 +11,26 @@ * * Contributors: * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation - * + * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - bug 517617, 532452 (just rewrite the test to use a fixture) *****************************************************************************/ package org.eclipse.papyrus.infra.nattable.tests.tests; -import java.io.IOException; import java.util.ArrayList; import java.util.List; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IAdaptable; -import org.eclipse.emf.ecore.resource.Resource; -import org.eclipse.emf.ecore.resource.ResourceSet; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.nebula.widgets.nattable.NatTable; import org.eclipse.nebula.widgets.nattable.print.command.TurnViewportOffCommand; import org.eclipse.nebula.widgets.nattable.print.command.TurnViewportOnCommand; -import org.eclipse.nebula.widgets.nattable.selection.SelectionLayer; import org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand; import org.eclipse.nebula.widgets.nattable.selection.command.SelectRowsCommand; -import org.eclipse.papyrus.infra.core.resource.sasheditor.DiModel; -import org.eclipse.papyrus.infra.core.services.ServiceException; -import org.eclipse.papyrus.infra.gmfdiag.common.model.NotationModel; import org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager; -import org.eclipse.papyrus.infra.nattable.model.nattable.Table; import org.eclipse.papyrus.infra.nattable.provider.TableStructuredSelection; -import org.eclipse.papyrus.infra.nattable.tests.Activator; -import org.eclipse.papyrus.junit.utils.tests.AbstractEditorTest; -import org.eclipse.papyrus.uml.tools.model.UmlModel; +import org.eclipse.papyrus.junit.framework.classification.tests.AbstractPapyrusTest; +import org.eclipse.papyrus.junit.utils.rules.ActiveTable; +import org.eclipse.papyrus.junit.utils.rules.PapyrusEditorFixture; +import org.eclipse.papyrus.junit.utils.rules.PluginResource; import org.eclipse.ui.ISelectionService; import org.eclipse.ui.PlatformUI; import org.eclipse.uml2.uml.Model; @@ -47,119 +38,54 @@ import org.eclipse.uml2.uml.NamedElement; import org.eclipse.uml2.uml.Package; import org.junit.Assert; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; -import org.osgi.framework.Bundle; /** - * + * * @author Vincent Lorenzo - * + * * This class tests the selection provider of the table - * + * */ -public class TableSelectionProviderTest extends AbstractEditorTest { - - //TODO : this class could be refactored with other class tests used for table (reveal semantic element) - protected Resource di; - - protected Resource notation; - - protected Resource uml; - - protected Table table; - +@PluginResource("resources/model.di") +public class TableSelectionProviderTest extends AbstractPapyrusTest { protected Model root; - - private INattableModelManager tableManager; - - private NatTable nattable; - private NamedElement class1; - // private NamedElement class2; - private Package _package; private NamedElement nestedClass1; private NamedElement nestedClass2; - /** - * - * Constructor. - * This plugin test the ModelExplorerView - */ - public TableSelectionProviderTest() { - super(); - } - - - private String modelRoot = "model"; + @Rule + public final PapyrusEditorFixture fixture = new PapyrusEditorFixture(); @Before - public void initTests() throws CoreException, IOException { - try { - initModel("testSelectionProvider", "model", getBundle()); - } catch (Exception e) { - e.printStackTrace(); - } - - ResourceSet set = null; - try { - set = getModelSet(); - } catch (ServiceException e) { - Activator.log.error(e); - } - final List<Resource> resources = set.getResources(); - - final StringBuffer model_uml = new StringBuffer(this.modelRoot); - model_uml.append("."); - model_uml.append(UmlModel.UML_FILE_EXTENSION); - final StringBuffer model_notation = new StringBuffer(this.modelRoot); - model_notation.append("."); - model_notation.append(NotationModel.NOTATION_FILE_EXTENSION); - final StringBuffer model_di = new StringBuffer(this.modelRoot); - model_di.append("."); - model_di.append(DiModel.DI_FILE_EXTENSION); - for(Resource current : resources) { - if(current.getURI().lastSegment().equals(model_uml.toString())) { - this.uml = current; - } else if(current.getURI().lastSegment().equals(model_notation.toString())) { - this.notation = current; - } else if(current.getURI().lastSegment().equals(model_di.toString())) { - this.di = current; - } - - - } - this.table = (Table)this.notation.getAllContents().next(); - this.root = (Model)this.uml.getContents().get(0); - - this.tableManager = (INattableModelManager)this.editor.getAdapter(INattableModelManager.class); - this.nattable = (NatTable)((IAdaptable)this.tableManager).getAdapter(NatTable.class); - + public void init() { + this.root = (Model) fixture.getModel(); this.class1 = this.root.getMember("Class1"); - // this.class2 = this.root.getMember("Class2"); - this._package = (Package)this.root.getMember("Package"); + this._package = (Package) this.root.getMember("Package"); this.nestedClass1 = this._package.getMember("NestedClass1"); this.nestedClass2 = this._package.getMember("NestedClass2"); } - /** * test the selection of a single row */ @Test + @ActiveTable("GenericTable0") public void testRowSelection() { - SelectionLayer selectionLayer = this.tableManager.getBodyLayerStack().getSelectionLayer(); - selectionLayer.clear(); + final INattableModelManager tableManager = this.fixture.getActiveTableManager(); + final NatTable nattable = tableManager.getAdapter(NatTable.class); Assert.assertTrue("The selection (even if empty) must be a TableSelectionProvider", getCurrentSelection() instanceof TableStructuredSelection); //$NON-NLS-1$ - Assert.assertEquals("The empty selection must have table context as selection", table.getContext(), ((TableStructuredSelection)getCurrentSelection()).getFirstElement()); //$NON-NLS-1$ - this.nattable.doCommand(new TurnViewportOffCommand()); - this.nattable.doCommand(new SelectRowsCommand(this.nattable, 2, 3, false, false));//select the row representing class1 - this.nattable.doCommand(new TurnViewportOnCommand()); - final List<Object> wantedSelection = new ArrayList<Object>(); + Assert.assertEquals("The empty selection must have table context as selection", tableManager.getTable().getContext(), ((TableStructuredSelection) getCurrentSelection()).getFirstElement()); //$NON-NLS-1$ + nattable.doCommand(new TurnViewportOffCommand()); + nattable.doCommand(new SelectRowsCommand(nattable, 2, 3, false, false));// select the row representing class1 + nattable.doCommand(new TurnViewportOnCommand()); + final List<Object> wantedSelection = new ArrayList<>(); wantedSelection.add(this.class1); verifyCurrentSelection(wantedSelection); } @@ -168,16 +94,17 @@ public class TableSelectionProviderTest extends AbstractEditorTest { * Test the selection of several rows */ @Test + @ActiveTable("GenericTable0") public void test_RowSelectionWithCTRL() { - SelectionLayer selectionLayer = this.tableManager.getBodyLayerStack().getSelectionLayer(); - selectionLayer.clear(); + final INattableModelManager tableManager = this.fixture.getActiveTableManager(); + final NatTable nattable = tableManager.getAdapter(NatTable.class); Assert.assertTrue("The selection (even if empty) must be a TableSelectionProvider", getCurrentSelection() instanceof TableStructuredSelection); //$NON-NLS-1$ - Assert.assertEquals("The empty selection must have table context as selection", table.getContext(), ((TableStructuredSelection)getCurrentSelection()).getFirstElement()); //$NON-NLS-1$ - this.nattable.doCommand(new TurnViewportOffCommand()); - this.nattable.doCommand(new SelectRowsCommand(this.nattable, 2, 3, false, false));//select the row representing class1 - this.nattable.doCommand(new SelectRowsCommand(this.nattable, 2, 5, false, true));//select the row representing package - this.nattable.doCommand(new TurnViewportOnCommand()); - final List<Object> wantedSelection = new ArrayList<Object>(); + Assert.assertEquals("The empty selection must have table context as selection", tableManager.getTable().getContext(), ((TableStructuredSelection) getCurrentSelection()).getFirstElement()); //$NON-NLS-1$ + nattable.doCommand(new TurnViewportOffCommand()); + nattable.doCommand(new SelectRowsCommand(nattable, 2, 3, false, false));// select the row representing class1 + nattable.doCommand(new SelectRowsCommand(nattable, 2, 5, false, true));// select the row representing package + nattable.doCommand(new TurnViewportOnCommand()); + final List<Object> wantedSelection = new ArrayList<>(); wantedSelection.add(this._package); wantedSelection.add(this.class1); verifyCurrentSelection(wantedSelection); @@ -187,16 +114,17 @@ public class TableSelectionProviderTest extends AbstractEditorTest { * test the selection of one row, followed by the selection of a cell, with CTRL */ @Test + @ActiveTable("GenericTable0") public void test_RowThenCellSelection() { - SelectionLayer selectionLayer = this.tableManager.getBodyLayerStack().getSelectionLayer(); - selectionLayer.clear(); + final INattableModelManager tableManager = this.fixture.getActiveTableManager(); + final NatTable nattable = tableManager.getAdapter(NatTable.class); Assert.assertTrue("The selection (even if empty) must be a TableSelectionProvider", getCurrentSelection() instanceof TableStructuredSelection); //$NON-NLS-1$ - Assert.assertEquals("The empty selection must have table context as selection", table.getContext(), ((TableStructuredSelection)getCurrentSelection()).getFirstElement()); //$NON-NLS-1$ - this.nattable.doCommand(new TurnViewportOffCommand()); - this.nattable.doCommand(new SelectRowsCommand(this.nattable, 2, 3, false, false));//select the row representing class1 - this.nattable.doCommand(new SelectCellCommand(this.nattable, 5, 5, false, true));//select the cell package/members - this.nattable.doCommand(new TurnViewportOnCommand()); - final List<Object> wantedSelection = new ArrayList<Object>(); + Assert.assertEquals("The empty selection must have table context as selection", tableManager.getTable().getContext(), ((TableStructuredSelection) getCurrentSelection()).getFirstElement()); //$NON-NLS-1$ + nattable.doCommand(new TurnViewportOffCommand()); + nattable.doCommand(new SelectRowsCommand(nattable, 2, 3, false, false));// select the row representing class1 + nattable.doCommand(new SelectCellCommand(nattable, 5, 5, false, true));// select the cell package/members + nattable.doCommand(new TurnViewportOnCommand()); + final List<Object> wantedSelection = new ArrayList<>(); wantedSelection.add(this.class1); wantedSelection.add(this.nestedClass1); wantedSelection.add(this.nestedClass2); @@ -207,16 +135,17 @@ public class TableSelectionProviderTest extends AbstractEditorTest { * test the selection of one cell, followed by the selection of one row, with CTRL */ @Test + @ActiveTable("GenericTable0") public void test_CellThenRowSelection() { - SelectionLayer selectionLayer = this.tableManager.getBodyLayerStack().getSelectionLayer(); - selectionLayer.clear(); + final INattableModelManager tableManager = this.fixture.getActiveTableManager(); + final NatTable nattable = tableManager.getAdapter(NatTable.class); Assert.assertTrue("The selection (even if empty) must be a TableSelectionProvider", getCurrentSelection() instanceof TableStructuredSelection); //$NON-NLS-1$ - Assert.assertEquals("The empty selection must have table context as selection", table.getContext(), ((TableStructuredSelection)getCurrentSelection()).getFirstElement()); //$NON-NLS-1$ - this.nattable.doCommand(new TurnViewportOffCommand()); - this.nattable.doCommand(new SelectCellCommand(this.nattable, 5, 5, false, false));//select the cell package/members - this.nattable.doCommand(new SelectRowsCommand(this.nattable, 2, 3, false, true));//select the row representing class1 - this.nattable.doCommand(new TurnViewportOnCommand()); - final List<Object> wantedSelection = new ArrayList<Object>(); + Assert.assertEquals("The empty selection must have table context as selection", tableManager.getTable().getContext(), ((TableStructuredSelection) getCurrentSelection()).getFirstElement()); //$NON-NLS-1$ + nattable.doCommand(new TurnViewportOffCommand()); + nattable.doCommand(new SelectCellCommand(nattable, 5, 5, false, false));// select the cell package/members + nattable.doCommand(new SelectRowsCommand(nattable, 2, 3, false, true));// select the row representing class1 + nattable.doCommand(new TurnViewportOnCommand()); + final List<Object> wantedSelection = new ArrayList<>(); wantedSelection.add(this.class1); wantedSelection.add(this.nestedClass1); wantedSelection.add(this.nestedClass2); @@ -224,23 +153,23 @@ public class TableSelectionProviderTest extends AbstractEditorTest { } /** - * + * * @param wantedSelection - * compare the wanted selection and the current selection + * compare the wanted selection and the current selection */ protected void verifyCurrentSelection(final List<Object> wantedSelection) { ISelection selection = getCurrentSelection(); - if(selection instanceof IStructuredSelection) { - List<?> currentSelection = ((IStructuredSelection)selection).toList(); + if (selection instanceof IStructuredSelection) { + List<?> currentSelection = ((IStructuredSelection) selection).toList(); Assert.assertEquals(wantedSelection.size(), currentSelection.size()); - for(Object current : currentSelection) { + for (Object current : currentSelection) { Assert.assertTrue(wantedSelection.contains(current)); } } } /** - * + * * @return * the current eclipse selection */ @@ -249,7 +178,7 @@ public class TableSelectionProviderTest extends AbstractEditorTest { } /** - * + * * @return * the selection service */ @@ -257,27 +186,4 @@ public class TableSelectionProviderTest extends AbstractEditorTest { return PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService(); } - - - /** - * - * @see org.eclipse.papyrus.junit.utils.tests.AbstractEditorTest#getBundle() - * - * @return - */ - @Override - protected Bundle getBundle() { - return Activator.getDefault().getBundle(); - } - - /** - * - * @see org.eclipse.papyrus.junit.utils.tests.AbstractEditorTest#getSourcePath() - * - * @return - */ - @Override - protected String getSourcePath() { - return "resources/"; - } } |