Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjmallet2018-09-05 07:47:55 +0000
committerjmallet2018-09-12 07:53:03 +0000
commit317db527f7ea3bb2d9067518848c7ad4adbc3873 (patch)
treef60e4571c238cdf7bff17747d9c5cd824819e9bd
parentd152db3ba04b807fb140e1b89b9b643145479c7c (diff)
downloadorg.eclipse.sirius-317db527f7ea3bb2d9067518848c7ad4adbc3873.tar.gz
org.eclipse.sirius-317db527f7ea3bb2d9067518848c7ad4adbc3873.tar.xz
org.eclipse.sirius-317db527f7ea3bb2d9067518848c7ad4adbc3873.zip
[507887] Allow for negative initial table width to hide header column.
Actually the initialHeaderColumndWidth setting from the VSM is used to set the initial/default width on tables. Because the default value "0" already means "auto-size", and any positive value is taken as an explicit width, "-1" is now used to mean "hide the header column". Bug: 507887 Change-Id: I34c3e5917663a9706f23b072739bda95c97fce08 Signed-off-by: jmallet <jessy.mallet@obeo.fr>
-rw-r--r--plugins/org.eclipse.sirius.doc/doc/specifier/tables/Tables.html2
-rw-r--r--plugins/org.eclipse.sirius.doc/doc/specifier/tables/Tables.textile2
-rw-r--r--plugins/org.eclipse.sirius.editor.table/src-gen/org/eclipse/sirius/table/editor/properties/sections/description/tabledescription/TableDescriptionInitialHeaderColumnWidthPropertySection.java4
-rw-r--r--plugins/org.eclipse.sirius.table.ui/src/org/eclipse/sirius/table/ui/tools/internal/editor/DTableViewerManager.java7
-rw-r--r--plugins/org.eclipse.sirius.table/src/org/eclipse/sirius/table/business/internal/refresh/DTableSynchronizerImpl.java5
-rw-r--r--plugins/org.eclipse.sirius.tests.junit/data/table/unit/bugzilla-507887/sample.aird7
-rw-r--r--plugins/org.eclipse.sirius.tests.junit/data/table/unit/bugzilla-507887/sample.ecore7
-rw-r--r--plugins/org.eclipse.sirius.tests.junit/data/table/unit/bugzilla-507887/tables.odesign14
-rw-r--r--plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/suite/table/AllTablePluginTests.java4
-rw-r--r--plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/table/unit/TableWithHeaderColumnWidthTest.java252
10 files changed, 299 insertions, 5 deletions
diff --git a/plugins/org.eclipse.sirius.doc/doc/specifier/tables/Tables.html b/plugins/org.eclipse.sirius.doc/doc/specifier/tables/Tables.html
index a7c428ec89..3850a5a624 100644
--- a/plugins/org.eclipse.sirius.doc/doc/specifier/tables/Tables.html
+++ b/plugins/org.eclipse.sirius.doc/doc/specifier/tables/Tables.html
@@ -125,7 +125,7 @@
</p>
<p>Finally, the
<em>Initial Header Column Width</em> (
- <em>Advanced</em> category) is specific to table descriptions (both edition tables and cross tables). It can be used to specify the default size (in pixels) of the left-most column of the table, which contains the labels of the elements represented by each line. If the value if 0 (the default), the column width will be computed from the initial content when the table is created.
+ <em>Advanced</em> category) is specific to table descriptions (both edition tables and cross tables). It can be used to specify the default size (in pixels) of the left-most column of the table, which contains the labels of the elements represented by each line. If the value is 0 (the default), the column width will be computed from the initial content when the table is created. In case of edition tables, if the value is -1, the header Column is hidden. In case of cross tables, -1 value has the same behavior than 0 value.
</p>
<h3 id="table_tools">Table Tools</h3>
<p>Some tools which apply to the whole table are specified directly inside the
diff --git a/plugins/org.eclipse.sirius.doc/doc/specifier/tables/Tables.textile b/plugins/org.eclipse.sirius.doc/doc/specifier/tables/Tables.textile
index 11fd872578..773b6f6ae7 100644
--- a/plugins/org.eclipse.sirius.doc/doc/specifier/tables/Tables.textile
+++ b/plugins/org.eclipse.sirius.doc/doc/specifier/tables/Tables.textile
@@ -39,7 +39,7 @@ It is recommended that the _Edition Table Description_ be explicitly associated
The _Initialization_ and _Show on startup_ flags control whether table instances are created and/or opened automatically without user intervention. If _Initialization_ is set, then when the viewpoint which contains this table description is enabled, instances of this table description will be automatically created on all compatible semantic elements. If _Show on startup_ in set, then when a modeling project is opened which contains instances of this table description, they will be opened: if only one such representation exist, it will be opened automatically; is there are more than one, a dialog box will appear to allow the user to select which one(s) to open.
-Finally, the _Initial Header Column Width_ (_Advanced_ category) is specific to table descriptions (both edition tables and cross tables). It can be used to specify the default size (in pixels) of the left-most column of the table, which contains the labels of the elements represented by each line. If the value if 0 (the default), the column width will be computed from the initial content when the table is created.
+Finally, the _Initial Header Column Width_ (_Advanced_ category) is specific to table descriptions (both edition tables and cross tables). It can be used to specify the default size (in pixels) of the left-most column of the table, which contains the labels of the elements represented by each line. If the value is 0 (the default), the column width will be computed from the initial content when the table is created. In case of edition tables, if the value is -1, the header Column is hidden. In case of cross tables, -1 value has the same behavior than 0 value.
h3(#table_tools). Table Tools
diff --git a/plugins/org.eclipse.sirius.editor.table/src-gen/org/eclipse/sirius/table/editor/properties/sections/description/tabledescription/TableDescriptionInitialHeaderColumnWidthPropertySection.java b/plugins/org.eclipse.sirius.editor.table/src-gen/org/eclipse/sirius/table/editor/properties/sections/description/tabledescription/TableDescriptionInitialHeaderColumnWidthPropertySection.java
index 584fba1c9c..26c3abd6b6 100644
--- a/plugins/org.eclipse.sirius.editor.table/src-gen/org/eclipse/sirius/table/editor/properties/sections/description/tabledescription/TableDescriptionInitialHeaderColumnWidthPropertySection.java
+++ b/plugins/org.eclipse.sirius.editor.table/src-gen/org/eclipse/sirius/table/editor/properties/sections/description/tabledescription/TableDescriptionInitialHeaderColumnWidthPropertySection.java
@@ -120,6 +120,10 @@ public class TableDescriptionInitialHeaderColumnWidthPropertySection extends Abs
help.setToolTipText("The initial width of the column header (calculated if not available).");
// Start of user code create controls
+ }
+
+ public TableDescriptionInitialHeaderColumnWidthPropertySection() {
+ this.minimumValue = -1;
// End of user code create controls
}
}
diff --git a/plugins/org.eclipse.sirius.table.ui/src/org/eclipse/sirius/table/ui/tools/internal/editor/DTableViewerManager.java b/plugins/org.eclipse.sirius.table.ui/src/org/eclipse/sirius/table/ui/tools/internal/editor/DTableViewerManager.java
index 696abc0af6..1987c2c136 100644
--- a/plugins/org.eclipse.sirius.table.ui/src/org/eclipse/sirius/table/ui/tools/internal/editor/DTableViewerManager.java
+++ b/plugins/org.eclipse.sirius.table.ui/src/org/eclipse/sirius/table/ui/tools/internal/editor/DTableViewerManager.java
@@ -332,12 +332,12 @@ public class DTableViewerManager extends AbstractDTableViewerManager {
};
headerTreeColumn.setLabelProvider(lineheaderColumnLabelProvider);
int headerColumnWidth = ((DTable) dRepresentation).getHeaderColumnWidth();
- if (headerColumnWidth != 0) {
+ if (headerColumnWidth > 0) {
theTreeLayout.setColumnData(headerTreeColumn.getColumn(), new ColumnPixelData(headerColumnWidth));
if (headerTreeColumn.getColumn().getWidth() != headerColumnWidth) {
headerTreeColumn.getColumn().setWidth(headerColumnWidth);
}
- } else {
+ } else if (headerColumnWidth == 0 || ((DTable) dRepresentation).getDescription() instanceof CrossTableDescription) {
theTreeLayout.setColumnData(headerTreeColumn.getColumn(), new ColumnWeightData(1));
if (IS_GTK_OS) {
// Do not launch treeViewerColumn.getColumn().pack() here
@@ -348,6 +348,9 @@ public class DTableViewerManager extends AbstractDTableViewerManager {
// Not really understood...
headerTreeColumn.getColumn().pack();
}
+ } else {
+ // Negative width means "hide the header"
+ treeLayout.setColumnData(headerTreeColumn.getColumn(), new ColumnPixelData(0));
}
headerTreeColumn.getColumn().addListener(SWT.Selection, sortListener);
diff --git a/plugins/org.eclipse.sirius.table/src/org/eclipse/sirius/table/business/internal/refresh/DTableSynchronizerImpl.java b/plugins/org.eclipse.sirius.table/src/org/eclipse/sirius/table/business/internal/refresh/DTableSynchronizerImpl.java
index d3a7a7d54c..fd16cde314 100644
--- a/plugins/org.eclipse.sirius.table/src/org/eclipse/sirius/table/business/internal/refresh/DTableSynchronizerImpl.java
+++ b/plugins/org.eclipse.sirius.table/src/org/eclipse/sirius/table/business/internal/refresh/DTableSynchronizerImpl.java
@@ -49,6 +49,7 @@ import org.eclipse.sirius.table.metamodel.table.DTableElement;
import org.eclipse.sirius.table.metamodel.table.DTargetColumn;
import org.eclipse.sirius.table.metamodel.table.LineContainer;
import org.eclipse.sirius.table.metamodel.table.TableFactory;
+import org.eclipse.sirius.table.metamodel.table.TablePackage;
import org.eclipse.sirius.table.metamodel.table.description.ColumnMapping;
import org.eclipse.sirius.table.metamodel.table.description.CrossTableDescription;
import org.eclipse.sirius.table.metamodel.table.description.DescriptionPackage;
@@ -124,6 +125,10 @@ public class DTableSynchronizerImpl implements DTableSynchronizer {
final Map<TableMapping, Collection<DTableElement>> mappingToElements = new HashMap<TableMapping, Collection<DTableElement>>();
ECrossReferenceAdapter xref = ECrossReferenceAdapter.getCrossReferenceAdapter(table.getTarget());
+ if (!table.eIsSet(TablePackage.Literals.DTABLE__HEADER_COLUMN_WIDTH)) {
+ table.setHeaderColumnWidth(description.getInitialHeaderColumnWidth());
+ }
+
refreshLines(new SubProgressMonitor(monitor, 1), mappingToElements, xref);
refreshColumns(new SubProgressMonitor(monitor, 1), mappingToElements, xref);
diff --git a/plugins/org.eclipse.sirius.tests.junit/data/table/unit/bugzilla-507887/sample.aird b/plugins/org.eclipse.sirius.tests.junit/data/table/unit/bugzilla-507887/sample.aird
new file mode 100644
index 0000000000..1fbbf97a0d
--- /dev/null
+++ b/plugins/org.eclipse.sirius.tests.junit/data/table/unit/bugzilla-507887/sample.aird
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<viewpoint:DAnalysis xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:description="http://www.eclipse.org/sirius/description/1.1.0" xmlns:viewpoint="http://www.eclipse.org/sirius/1.1.0" xsi:schemaLocation="http://www.eclipse.org/sirius/description/1.1.0 http://www.eclipse.org/sirius/1.1.0#//description" xmi:id="_oFScgLAKEeag-KyOdePObw" selectedViews="_pJ4tELAKEeag-KyOdePObw" version="11.1.0.201608251200">
+ <semanticResources>sample.ecore</semanticResources>
+ <ownedViews xmi:type="viewpoint:DView" xmi:id="_pJ4tELAKEeag-KyOdePObw">
+ <viewpoint xmi:type="description:Viewpoint" href="fixture.odesign#//@ownedViewpoints[name='Bugzilla-507887']"/>
+ </ownedViews>
+</viewpoint:DAnalysis>
diff --git a/plugins/org.eclipse.sirius.tests.junit/data/table/unit/bugzilla-507887/sample.ecore b/plugins/org.eclipse.sirius.tests.junit/data/table/unit/bugzilla-507887/sample.ecore
new file mode 100644
index 0000000000..490bf84eff
--- /dev/null
+++ b/plugins/org.eclipse.sirius.tests.junit/data/table/unit/bugzilla-507887/sample.ecore
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ecore:EPackage xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="p">
+ <eClassifiers xsi:type="ecore:EClass" name="A"/>
+ <eClassifiers xsi:type="ecore:EClass" name="B"/>
+ <eSubpackages name="P1"/>
+</ecore:EPackage>
diff --git a/plugins/org.eclipse.sirius.tests.junit/data/table/unit/bugzilla-507887/tables.odesign b/plugins/org.eclipse.sirius.tests.junit/data/table/unit/bugzilla-507887/tables.odesign
new file mode 100644
index 0000000000..b40ef88755
--- /dev/null
+++ b/plugins/org.eclipse.sirius.tests.junit/data/table/unit/bugzilla-507887/tables.odesign
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<description:Group xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:description="http://www.eclipse.org/sirius/description/1.1.0" xmlns:description_1="http://www.eclipse.org/sirius/table/description/1.1.0" name="fixture.odesign" version="12.0.0.2017041100">
+ <ownedViewpoints name="Bugzilla-507887">
+ <ownedRepresentations xsi:type="description_1:EditionTableDescription" name="testEditionTable" domainClass="ecore.EPackage" initialHeaderColumnWidth="-1">
+ <ownedLineMappings name="Class" domainClass="ecore.EClass" semanticCandidatesExpression="feature:eClassifiers"/>
+ <ownedColumnMappings name="Names" label="Names" headerLabelExpression="Name" featureName="name" labelExpression="feature:name"/>
+ </ownedRepresentations>
+ <ownedRepresentations xsi:type="description_1:CrossTableDescription" name="testCrossTable" domainClass="EPackage">
+ <ownedLineMappings name="Packages" domainClass="EPackage"/>
+ <ownedColumnMappings name="Classes" domainClass="EClass"/>
+ <intersection name="Interaction" lineMapping="//@ownedViewpoints[name='Bugzilla-507887']/@ownedRepresentations[name='testCrossTable']/@ownedLineMappings[name='Packages']" columnMapping="//@ownedViewpoints[name='Bugzilla-507887']/@ownedRepresentations[name='testCrossTable']/@ownedColumnMappings.0" labelExpression="X"/>
+ </ownedRepresentations>
+ </ownedViewpoints>
+</description:Group>
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 719818e8ac..b706828520 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010, 2014 THALES GLOBAL SERVICES.
+ * Copyright (c) 2010, 2018 THALES GLOBAL SERVICES 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
@@ -14,6 +14,7 @@ import org.eclipse.sirius.tests.unit.table.tests.provider.TreeLabelProviderTest;
import org.eclipse.sirius.tests.unit.table.tests.srs.ExploitArrays_Test;
import org.eclipse.sirius.tests.unit.table.tests.srs.SpecifyArrays_Test;
import org.eclipse.sirius.tests.unit.table.unit.TableContentTest;
+import org.eclipse.sirius.tests.unit.table.unit.TableWithHeaderColumnWidthTest;
import org.eclipse.sirius.tests.unit.table.unit.TableWithMultivaluedAttributeTest;
import org.eclipse.sirius.tests.unit.table.unit.dialect.DialectManagerTest;
import org.eclipse.sirius.tests.unit.table.unit.export.ExportToCsvTest;
@@ -105,6 +106,7 @@ public class AllTablePluginTests extends TestCase {
suite.addTestSuite(VariableOnTableCreationToolsTest.class);
suite.addTestSuite(TableStyleRefreshTest.class);
suite.addTestSuite(TableWithMultivaluedAttributeTest.class);
+ suite.addTestSuite(TableWithHeaderColumnWidthTest.class);
return suite;
}
diff --git a/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/table/unit/TableWithHeaderColumnWidthTest.java b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/table/unit/TableWithHeaderColumnWidthTest.java
new file mode 100644
index 0000000000..7d11230972
--- /dev/null
+++ b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/table/unit/TableWithHeaderColumnWidthTest.java
@@ -0,0 +1,252 @@
+/*******************************************************************************
+ * Copyright (c) 2018 Obeo.
+ * 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;
+
+import java.io.IOException;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Optional;
+
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
+import org.eclipse.emf.edit.provider.ComposedAdapterFactory;
+import org.eclipse.emf.transaction.RecordingCommand;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.emf.transaction.impl.TransactionalEditingDomainImpl;
+import org.eclipse.sirius.business.api.dialect.DialectManager;
+import org.eclipse.sirius.table.metamodel.table.description.TableDescription;
+import org.eclipse.sirius.table.ui.tools.internal.editor.AbstractDTableEditor;
+import org.eclipse.sirius.tests.SiriusTestsPlugin;
+import org.eclipse.sirius.tests.support.api.SiriusTestCase;
+import org.eclipse.sirius.tests.support.api.TestsUtil;
+import org.eclipse.sirius.tools.api.command.ICommandFactory;
+import org.eclipse.sirius.ui.business.api.dialect.DialectUIManager;
+import org.eclipse.sirius.viewpoint.DRepresentation;
+import org.eclipse.sirius.viewpoint.description.Group;
+import org.eclipse.sirius.viewpoint.description.RepresentationDescription;
+import org.eclipse.swt.widgets.Tree;
+import org.eclipse.swt.widgets.TreeColumn;
+import org.eclipse.ui.IEditorPart;
+
+/**
+ * Test width initialization of header column table.
+ *
+ * @author jmallet
+ */
+public class TableWithHeaderColumnWidthTest extends SiriusTestCase {
+
+ private static final String CROSS_TABLE_NAME = "testCrossTable"; //$NON-NLS-1$
+
+ private static final String EDITION_TABLE_NAME = "testEditionTable"; //$NON-NLS-1$
+
+ private static final String VIEWPOINT_NAME = "Bugzilla-507887"; //$NON-NLS-1$
+
+ public static final String FOLDER_PATH = "/data/table/unit/bugzilla-507887/"; //$NON-NLS-1$
+
+ private static final String SEMANTIC_MODEL_FILENAME = "sample.ecore"; //$NON-NLS-1$
+
+ private static final String VSM_NAME = "tables.odesign"; //$NON-NLS-1$
+
+ private static final String SESSION_MODEL_FILENAME = "sample.aird"; //$NON-NLS-1$
+
+ private DRepresentation drep;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ copyFilesToTestProject(SiriusTestsPlugin.PLUGIN_ID, FOLDER_PATH, SEMANTIC_MODEL_FILENAME, SESSION_MODEL_FILENAME, VSM_NAME);
+ genericSetUp(TEMPORARY_PROJECT_NAME + "/" + SEMANTIC_MODEL_FILENAME, TEMPORARY_PROJECT_NAME + "/" + VSM_NAME, TEMPORARY_PROJECT_NAME + "/" + SESSION_MODEL_FILENAME);
+
+ activateViewpoint(VIEWPOINT_NAME);
+ }
+
+ /**
+ * Test that positive Header column width set in VSM is taken into account
+ * on edition table.
+ */
+ public void testWidthHeaderColumnTo50_onEditionTable() {
+ int expectedSize = 50;
+
+ // Modify VSM, set Header column size to 50
+ setNewHeaderColumnWidth(expectedSize, EDITION_TABLE_NAME);
+
+ // create Edition Table
+ createTable(EDITION_TABLE_NAME);
+
+ assertEquals("The header column width should be 50 px as specified in VSM.", expectedSize, getHeaderColumn().getWidth());
+ }
+
+ /**
+ * Test that Header column width to zero in VSM shows columns auto-size on
+ * edition table.
+ */
+ public void testWidthHeaderColumnTo0_onEditionTable() {
+ // Modify VSM, set Header column size to 0
+ setNewHeaderColumnWidth(0, EDITION_TABLE_NAME);
+
+ // create Edition Table
+ createTable(EDITION_TABLE_NAME);
+
+ assertTrue("Header column size should be greater than 0 to be adapted to column content.", getHeaderColumn().getWidth() > 0); //$NON-NLS-1$
+ }
+
+ /**
+ * Test that Header column is hidden if its size is set to -1 in the VSM on
+ * edition table.
+ */
+ public void testHideHeaderColumn_onEditionTable() {
+ // Modify VSM, set Header column size to -1
+ setNewHeaderColumnWidth(-1, EDITION_TABLE_NAME);
+
+ // create Edition Table
+ createTable(EDITION_TABLE_NAME);
+
+ assertEquals("Header column should be hidden.", 0, getHeaderColumn().getWidth());
+ }
+
+ /**
+ * Test that Header column positive width set in VSM is taken into account
+ * on Cross Table.
+ */
+ public void testWidthHeaderColumnTo50_onCrossTable() {
+ int expectedSize = 50;
+
+ // Modify VSM, set Header column size to 50
+ setNewHeaderColumnWidth(expectedSize, CROSS_TABLE_NAME);
+
+ // create Cross Table
+ createTable(CROSS_TABLE_NAME);
+
+ assertEquals("The header column width should be 50 px as specified in VSM.", expectedSize, getHeaderColumn().getWidth());
+ }
+
+ /**
+ * Test that Header column width to zero in VSM shows columns auto-size on
+ * Cross Table.
+ */
+ public void testWidthHeaderColumnTo0_onCrossTable() {
+ // Modify VSM, set Header column size to 0
+ setNewHeaderColumnWidth(0, CROSS_TABLE_NAME);
+
+ // create Cross Table
+ createTable(CROSS_TABLE_NAME);
+
+ assertTrue("Header column size should be greater than 0 to be adapted to column content.", getHeaderColumn().getWidth() > 0); //$NON-NLS-1$
+ }
+
+ /**
+ * Test that Header column width to -1 in VSM shows columns auto-size on
+ * Cross Table.
+ */
+ public void testWidthHeaderColumnToMinus1_onCrossTable() {
+ // Modify VSM, set Header column size to -1
+ setNewHeaderColumnWidth(-1, CROSS_TABLE_NAME);
+
+ // create Cross Table
+ createTable(CROSS_TABLE_NAME);
+
+ assertTrue("Header column size should be greater than 0 to be adapted to column content.", getHeaderColumn().getWidth() > 0); //$NON-NLS-1$
+ }
+
+ /**
+ * Set new Header column width in VSM.
+ *
+ * @param size
+ * width of the Header column to set in VSM
+ * @param representationName
+ * name of the description to modify
+ */
+ private void setNewHeaderColumnWidth(Integer size, String representationName) {
+ try {
+ // Get Table description
+ ResourceSet set = new ResourceSetImpl();
+ Resource vsm = set.getResource(URI.createPlatformResourceURI(TEMPORARY_PROJECT_NAME + "/" + VSM_NAME, true), true);
+ Group group = (Group) vsm.getContents().get(0);
+ Optional<RepresentationDescription> description = group.getOwnedViewpoints().stream().flatMap(vp -> vp.getOwnedRepresentations().stream())
+ .filter(d -> d.getName().equals(representationName)).findFirst();
+
+ if (description.isPresent()) {
+ final TableDescription desc = (TableDescription) description.get();
+ // Modify header column width value
+ TransactionalEditingDomain domain = new TransactionalEditingDomainImpl(new ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE));
+ domain.getCommandStack().execute(new RecordingCommand(domain) {
+ /** {@inheritDoc} */
+ @Override
+ protected void doExecute() {
+ desc.setInitialHeaderColumnWidth(size);
+ }
+ });
+
+ // Save modification
+ vsm.save(Collections.emptyMap());
+ }
+ } catch (IOException e) {
+ fail(e.getMessage());
+ }
+ }
+
+ /**
+ * Create a table representation on the root package of the model.
+ *
+ * @param representationName
+ * name of the representation description to use
+ */
+ private void createTable(String representationName) {
+ session.getTransactionalEditingDomain().getCommandStack().execute(new RecordingCommand(session.getTransactionalEditingDomain()) {
+ @Override
+ protected void doExecute() {
+ drep = DialectManager.INSTANCE.createRepresentation("new " + representationName, semanticModel, getRepDescription(representationName), session, new NullProgressMonitor()); //$NON-NLS-1$
+ DialectManager.INSTANCE.refresh(drep, new NullProgressMonitor());
+ }
+ });
+ }
+
+ /**
+ * Get representation description that the user might use to create a new
+ * {@link DRepresentation}.
+ *
+ * @param name
+ * name of the representation description
+ *
+ * @return representation description
+ */
+ private RepresentationDescription getRepDescription(String name) {
+ final Collection<RepresentationDescription> descriptions = DialectManager.INSTANCE.getAvailableRepresentationDescriptions(session.getSelectedViewpoints(false), semanticModel);
+ Optional<RepresentationDescription> description = descriptions.stream().filter(d -> d.getName().equals(name)).findFirst();
+ if (description.isPresent()) {
+ return description.get();
+ } else {
+ return null;
+ }
+ }
+
+ /**
+ * Get header column of the new table representation.
+ *
+ * @return header column of the new table representation.
+ */
+ private TreeColumn getHeaderColumn() {
+ IEditorPart openedEditor = DialectUIManager.INSTANCE.openEditor(session, drep, new NullProgressMonitor());
+ TestsUtil.synchronizationWithUIThread();
+ AbstractDTableEditor tableEditor = (AbstractDTableEditor) openedEditor;
+ Tree tree = tableEditor.getTableViewer().getTreeViewer().getTree();
+ return tree.getColumn(0);
+ }
+
+ @Override
+ protected ICommandFactory getCommandFactory() {
+ return null;
+ }
+
+}

Back to the top