Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorvlorenzo2012-09-14 14:48:55 +0000
committervlorenzo2012-09-14 14:48:55 +0000
commit1d0c181d7ecbfc6a67789fee79f1b551d2498e84 (patch)
tree5dcd17d91eec9c8063f91bd32f21b8f986276010 /sandbox
parent5b439d07ae34b32217af16b2d3af3f03a1cfe00c (diff)
downloadorg.eclipse.papyrus-1d0c181d7ecbfc6a67789fee79f1b551d2498e84.tar.gz
org.eclipse.papyrus-1d0c181d7ecbfc6a67789fee79f1b551d2498e84.tar.xz
org.eclipse.papyrus-1d0c181d7ecbfc6a67789fee79f1b551d2498e84.zip
389601: [Table] Papyrus should provides an easy way to edit the properties of the stereotypes using a Dialog Show/Hide columns
https://bugs.eclipse.org/bugs/show_bug.cgi?id=389601 Initial import
Diffstat (limited to 'sandbox')
-rw-r--r--sandbox/org.eclipse.papyrus.infra.table.efacet.menu/.classpath7
-rw-r--r--sandbox/org.eclipse.papyrus.infra.table.efacet.menu/.project28
-rw-r--r--sandbox/org.eclipse.papyrus.infra.table.efacet.menu/.settings/org.eclipse.jdt.core.prefs7
-rw-r--r--sandbox/org.eclipse.papyrus.infra.table.efacet.menu/META-INF/MANIFEST.MF24
-rw-r--r--sandbox/org.eclipse.papyrus.infra.table.efacet.menu/build.properties5
-rw-r--r--sandbox/org.eclipse.papyrus.infra.table.efacet.menu/plugin.xml28
-rw-r--r--sandbox/org.eclipse.papyrus.infra.table.efacet.menu/src/org/eclipse/papyrus/infra/table/efacet/menu/Activator.java53
-rw-r--r--sandbox/org.eclipse.papyrus.infra.table.efacet.menu/src/org/eclipse/papyrus/infra/table/efacet/menu/factory/CustomizationUtils.java83
-rw-r--r--sandbox/org.eclipse.papyrus.infra.table.efacet.menu/src/org/eclipse/papyrus/infra/table/efacet/menu/factory/ITableCommandFactory.java48
-rw-r--r--sandbox/org.eclipse.papyrus.infra.table.efacet.menu/src/org/eclipse/papyrus/infra/table/efacet/menu/factory/TableCommandFactory.java528
-rw-r--r--sandbox/org.eclipse.papyrus.infra.table.efacet.menu/src/org/eclipse/papyrus/infra/table/efacet/menu/factory/TableInstanceCommandFactory.java334
-rw-r--r--sandbox/org.eclipse.papyrus.infra.table.efacet.menu/src/org/eclipse/papyrus/infra/table/efacet/menu/factory/TableInstanceUtils.java223
-rw-r--r--sandbox/org.eclipse.papyrus.infra.table.efacet.menu/src/org/eclipse/papyrus/infra/table/efacet/menu/handler/ColumnsToHideDialog.java322
-rw-r--r--sandbox/org.eclipse.papyrus.infra.table.efacet.menu/src/org/eclipse/papyrus/infra/table/efacet/menu/handler/FacetFactory.java271
-rw-r--r--sandbox/org.eclipse.papyrus.infra.table.efacet.menu/src/org/eclipse/papyrus/infra/table/efacet/menu/handler/SelectColumnsHandler.java399
-rw-r--r--sandbox/org.eclipse.papyrus.infra.table.efacet.menu/src/org/eclipse/papyrus/infra/table/efacet/menu/handler/SortedColumnContentProvider.java150
16 files changed, 2510 insertions, 0 deletions
diff --git a/sandbox/org.eclipse.papyrus.infra.table.efacet.menu/.classpath b/sandbox/org.eclipse.papyrus.infra.table.efacet.menu/.classpath
new file mode 100644
index 00000000000..2d1a4302f04
--- /dev/null
+++ b/sandbox/org.eclipse.papyrus.infra.table.efacet.menu/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/sandbox/org.eclipse.papyrus.infra.table.efacet.menu/.project b/sandbox/org.eclipse.papyrus.infra.table.efacet.menu/.project
new file mode 100644
index 00000000000..6ca4b401b01
--- /dev/null
+++ b/sandbox/org.eclipse.papyrus.infra.table.efacet.menu/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.papyrus.infra.table.efacet.menu</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/sandbox/org.eclipse.papyrus.infra.table.efacet.menu/.settings/org.eclipse.jdt.core.prefs b/sandbox/org.eclipse.papyrus.infra.table.efacet.menu/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 00000000000..44217f8c068
--- /dev/null
+++ b/sandbox/org.eclipse.papyrus.infra.table.efacet.menu/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,7 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.5
diff --git a/sandbox/org.eclipse.papyrus.infra.table.efacet.menu/META-INF/MANIFEST.MF b/sandbox/org.eclipse.papyrus.infra.table.efacet.menu/META-INF/MANIFEST.MF
new file mode 100644
index 00000000000..c3869ecc38e
--- /dev/null
+++ b/sandbox/org.eclipse.papyrus.infra.table.efacet.menu/META-INF/MANIFEST.MF
@@ -0,0 +1,24 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Menu for EFacet Table (Incubation)
+Bundle-SymbolicName: org.eclipse.papyrus.infra.table.efacet.menu;singleton:=true
+Bundle-Version: 0.9.0.qualifier
+Bundle-Activator: org.eclipse.papyrus.infra.table.efacet.menu.Activator
+Bundle-Vendor: Eclispe Modeling Project
+Require-Bundle: org.eclipse.ui,
+ org.eclipse.core.runtime,
+ org.eclipse.emf.ecore;bundle-version="2.8.0",
+ org.eclipse.emf.transaction;bundle-version="1.4.0",
+ org.eclipse.papyrus.infra.core;bundle-version="0.9.1",
+ org.eclipse.emf.facet.widgets.table.metamodel;bundle-version="0.2.1",
+ org.eclipse.emf.facet.widgets.table.ui;bundle-version="0.2.1",
+ org.eclipse.papyrus.infra.emf;bundle-version="0.9.1",
+ org.eclipse.papyrus.infra.table.efacet.common;bundle-version="0.9.1",
+ org.eclipse.papyrus.infra.table.efacet.metamodel;bundle-version="0.9.1",
+ org.eclipse.uml2.uml;bundle-version="4.0.0",
+ org.eclipse.gmf.runtime.common.core;bundle-version="1.4.1",
+ org.eclipse.gmf.runtime.emf.commands.core;bundle-version="1.4.0",
+ org.eclipse.emf.facet.widgets.celleditors.ecore;bundle-version="0.2.1",
+ org.eclipse.emf.facet.efacet.core
+Bundle-RequiredExecutionEnvironment: J2SE-1.5
+Bundle-ActivationPolicy: lazy
diff --git a/sandbox/org.eclipse.papyrus.infra.table.efacet.menu/build.properties b/sandbox/org.eclipse.papyrus.infra.table.efacet.menu/build.properties
new file mode 100644
index 00000000000..6f20375d6c7
--- /dev/null
+++ b/sandbox/org.eclipse.papyrus.infra.table.efacet.menu/build.properties
@@ -0,0 +1,5 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .,\
+ plugin.xml
diff --git a/sandbox/org.eclipse.papyrus.infra.table.efacet.menu/plugin.xml b/sandbox/org.eclipse.papyrus.infra.table.efacet.menu/plugin.xml
new file mode 100644
index 00000000000..210ca285d87
--- /dev/null
+++ b/sandbox/org.eclipse.papyrus.infra.table.efacet.menu/plugin.xml
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.4"?>
+<plugin>
+ <extension
+ point="org.eclipse.ui.commands">
+ <command
+ categoryId="org.eclipse.papyrus.editor.category"
+ defaultHandler="org.eclipse.papyrus.infra.table.efacet.menu.handler.SelectColumnsHandler"
+ description="Select the Columns to display in the table"
+ id="org.eclipse.papyrus.infra.table.efacet.menu.command.select.columns"
+ name="Select Columns">
+ </command>
+ </extension>
+ <extension
+ point="org.eclipse.ui.menus">
+ <menuContribution
+ allPopups="false"
+ locationURI="popup:org.eclipse.ui.popup.any">
+ <command
+ commandId="org.eclipse.papyrus.infra.table.efacet.menu.command.select.columns"
+ label="Select Columns"
+ style="push"
+ tooltip="Select the columns to display">
+ </command>
+ </menuContribution>
+ </extension>
+
+</plugin>
diff --git a/sandbox/org.eclipse.papyrus.infra.table.efacet.menu/src/org/eclipse/papyrus/infra/table/efacet/menu/Activator.java b/sandbox/org.eclipse.papyrus.infra.table.efacet.menu/src/org/eclipse/papyrus/infra/table/efacet/menu/Activator.java
new file mode 100644
index 00000000000..34769f21524
--- /dev/null
+++ b/sandbox/org.eclipse.papyrus.infra.table.efacet.menu/src/org/eclipse/papyrus/infra/table/efacet/menu/Activator.java
@@ -0,0 +1,53 @@
+package org.eclipse.papyrus.infra.table.efacet.menu;
+
+import org.eclipse.papyrus.infra.core.log.LogHelper;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The activator class controls the plug-in life cycle
+ */
+public class Activator extends AbstractUIPlugin {
+
+ // The plug-in ID
+ public static final String PLUGIN_ID = "org.eclipse.papyrus.infra.table.efacet.menu"; //$NON-NLS-1$
+
+ // The shared instance
+ private static Activator plugin;
+
+ public static LogHelper log;
+ /**
+ * The constructor
+ */
+ public Activator() {
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
+ */
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ log = new LogHelper(this);
+ plugin = this;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
+ */
+ public void stop(BundleContext context) throws Exception {
+ plugin = null;
+ super.stop(context);
+ }
+
+ /**
+ * Returns the shared instance
+ *
+ * @return the shared instance
+ */
+ public static Activator getDefault() {
+ return plugin;
+ }
+
+}
diff --git a/sandbox/org.eclipse.papyrus.infra.table.efacet.menu/src/org/eclipse/papyrus/infra/table/efacet/menu/factory/CustomizationUtils.java b/sandbox/org.eclipse.papyrus.infra.table.efacet.menu/src/org/eclipse/papyrus/infra/table/efacet/menu/factory/CustomizationUtils.java
new file mode 100644
index 00000000000..16dafbfee7b
--- /dev/null
+++ b/sandbox/org.eclipse.papyrus.infra.table.efacet.menu/src/org/eclipse/papyrus/infra/table/efacet/menu/factory/CustomizationUtils.java
@@ -0,0 +1,83 @@
+/*****************************************************************************
+ * Copyright (c) 2012 CEA LIST.
+ *
+ *
+ * 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:
+ * Vincent Lorenzo (CEA LIST) Vincent.Lorenzo@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.table.efacet.menu.factory;
+
+import java.util.Collection;
+
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EClassifier;
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.facet.custom.metamodel.v0_2_0.custom.Customization;
+import org.eclipse.emf.facet.custom.metamodel.v0_2_0.custom.FacetCustomization;
+import org.eclipse.emf.facet.efacet.core.FacetUtils;
+import org.eclipse.emf.facet.efacet.metamodel.v0_2_0.efacet.Facet;
+import org.eclipse.emf.facet.efacet.metamodel.v0_2_0.efacet.FacetSet;
+
+//TODO duplicated and adapted code from EMF-Facet
+//EMF-Facet should provides a best way to hide columns
+public final class CustomizationUtils {
+
+ private CustomizationUtils() {
+ // Must not be used.
+ }
+
+ /** @return the {@link Facet}s customized by the given customizations. */
+ public static Set<FacetSet> findFacetsCustomizedBy(final List<Customization> customizations) {
+ final Set<FacetSet> referencedFS = new HashSet<FacetSet>();
+ for(Customization customization : customizations) {
+ for(EClassifier eClassifier : customization.getEClassifiers()) {
+ if(eClassifier instanceof FacetCustomization) {
+ final FacetCustomization facetCustom = (FacetCustomization)eClassifier;
+ for(Facet extFacet : facetCustom.getExtendedFacets()) {
+ referencedFS.add((FacetSet)extFacet.getEPackage());
+ }
+ }
+ }
+ }
+ return referencedFS;
+ }
+
+ /** Returns the first customization among the given list of customizations that extends the given EPackage. */
+ public static Customization findCustomizationExtendingEPackage(final List<Customization> customizations, final EPackage ePackage) {
+ if(ePackage == null) {
+ throw new IllegalArgumentException("ePackage must not be null"); //$NON-NLS-1$
+ }
+ Customization result = null;
+ for(Customization customization : customizations) {
+ if(customization != null && ePackage.equals(FacetUtils.getExtendedEPackage(customization))) {
+ result = customization;
+ break;
+ }
+ }
+ return result;
+ }
+
+ /** Returns the first {@link Facet} among the given list of facets that extends the given EClass. */
+ public static Facet findFacetByExtendedMetaclass(final Collection<Facet> facets, final EClass extendedMetaClass) {
+ Facet result = null;
+ for(Facet facet : facets) {
+ Facet candidate = facet;
+ if(candidate.getExtendedMetaclass() == extendedMetaClass) {
+ result = candidate;
+ break;
+ }
+ }
+ return result;
+ }
+
+}
diff --git a/sandbox/org.eclipse.papyrus.infra.table.efacet.menu/src/org/eclipse/papyrus/infra/table/efacet/menu/factory/ITableCommandFactory.java b/sandbox/org.eclipse.papyrus.infra.table.efacet.menu/src/org/eclipse/papyrus/infra/table/efacet/menu/factory/ITableCommandFactory.java
new file mode 100644
index 00000000000..1faa783424b
--- /dev/null
+++ b/sandbox/org.eclipse.papyrus.infra.table.efacet.menu/src/org/eclipse/papyrus/infra/table/efacet/menu/factory/ITableCommandFactory.java
@@ -0,0 +1,48 @@
+/*******************************************************************************
+ * Copyright (c) 2012 CEA-LIST
+ * 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:
+ * Gregoire Dupe (Mia-Software) - Bug 374903 - [Table] ITableWidget.setLoadedFacetSets
+ * Gregoire Dupe (Mia-Software) - Bug 375087 - [Table] ITableWidget.addColumn(List<ETypedElement>, List<FacetSet>)
+ * Gregoire Dupe (Mia-Software) - Bug 376158 - [Table] Unexpected columns when customizations are loaded
+ * Gregoire Dupe (Mia-Software) - Bug 378701 - [Unit Test Failure] org.eclipse.emf.facet.widgets.table.tests.internal.v0_2.notuithread.Bug354224Test*
+ * Gregoire Dupe (Mia-Software) - Bug 380126 - [Table] Row sort too long
+ *******************************************************************************/
+package org.eclipse.papyrus.infra.table.efacet.menu.factory;
+
+import java.util.List;
+
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.ecore.ETypedElement;
+import org.eclipse.emf.facet.custom.metamodel.v0_2_0.custom.Customization;
+import org.eclipse.emf.facet.efacet.metamodel.v0_2_0.efacet.FacetSet;
+import org.eclipse.emf.facet.widgets.table.metamodel.v0_2_0.table.Column;
+import org.eclipse.emf.facet.widgets.table.metamodel.v0_2_0.table.FeatureColumn;
+import org.eclipse.emf.facet.widgets.table.ui.internal.exported.ColumnSortDirection;
+
+/***
+ *
+ * @noextend This interface is not intended to be extended by clients.
+ * @noimplement This interface is not intended to be implemented by clients.
+ */
+public interface ITableCommandFactory {
+
+ Command createSetLoadedFacetSetsCommand(List<FacetSet> facetSets);
+
+ Command createRemoveColumnCommand(Column column);
+
+ Command createAddColumnCommand(List<ETypedElement> eTypedElements,
+ List<FacetSet> facetSets);
+
+ Command createSetCustomizationCommand(List<Customization> customizations);
+
+ Command createRemoveColumnsCommand(List<ETypedElement> elements);
+
+// Command createSortRowCommand(FeatureColumn featureColumn,
+// ColumnSortDirection direction);
+
+}
diff --git a/sandbox/org.eclipse.papyrus.infra.table.efacet.menu/src/org/eclipse/papyrus/infra/table/efacet/menu/factory/TableCommandFactory.java b/sandbox/org.eclipse.papyrus.infra.table.efacet.menu/src/org/eclipse/papyrus/infra/table/efacet/menu/factory/TableCommandFactory.java
new file mode 100644
index 00000000000..37f6d7b451e
--- /dev/null
+++ b/sandbox/org.eclipse.papyrus.infra.table.efacet.menu/src/org/eclipse/papyrus/infra/table/efacet/menu/factory/TableCommandFactory.java
@@ -0,0 +1,528 @@
+/*******************************************************************************
+ * Copyright (c) 2012 CEA-LIST
+ * 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:
+ * Gregoire Dupe (Mia-Software) - Bug 374903 - [Table] ITableWidget.setLoadedFacetSets
+ * Gregoire Dupe (Mia-Software) - Bug 375087 - [Table] ITableWidget.addColumn(List<ETypedElement>, List<FacetSet>)
+ * Gregoire Dupe (Mia-Software) - Bug 372626 - Aggregates
+ * Gregoire Dupe (Mia-Software) - Bug 376158 - [Table] Unexpected columns when customizations are loaded
+ * Gregoire Dupe (Mia-Software) - Bug 378701 - [Unit Test Failure] org.eclipse.emf.facet.widgets.table.tests.internal.v0_2.notuithread.Bug354224Test*
+ * Gregoire Dupe (Mia-Software) - Bug 380126 - [Table] Row sort too long
+ * Contributors imported from org.eclipse.emf.facet.widgets.table.ui.internal.TableInstanceCommandFactory (Bug 387008):
+ * Nicolas Bros (Mia-Software) - Bug 331203 - table model editor - initial API and implementation
+ * Nicolas Bros (Mia-Software) - Bug 332437 - NatTable : pluggable cell editors
+ * Nicolas Guyomar (Mia-Software) - Bug 331442 - To be able to add and remove lines (model elements) from the table
+ * Nicolas Bros (Mia-Software) - Bug 332226 - To be able to create or delete model element from the table
+ * Nicolas Guyomar (Mia-Software) - Bug 332226 - To be able to create or delete model element from the table
+ * Nicolas Bros (Mia-Software) - Bug 332438 - NatTable : table type
+ * Nicolas Bros (Mia-Software) - Bug 332440 - NatTable : force cell editors
+ * Nicolas Bros (Mia-Software) - Bug 331675 - NatTable : copy cells as text
+ * Nicolas Bros (Mia-Software) - Bug 331900 - customizable NatTable
+ * Nicolas Bros (Mia-Software) - Bug 332010 - view Facet customizations on NatTable
+ * Nicolas Bros (Mia-Software) - Bug 332215 - customizable NatTable column headers
+ * Nicolas Guyomar (Mia-Software) - Bug 332215 - customizable NatTable column headers
+ * Nicolas Guyomar (Mia-Software) - Bug 332924 - To be able to save the table
+ * Nicolas Guyomar (Mia-Software) - Bug 332998 - To be able to add a column and fill it with the result of a query
+ * Gregoire Dupe (Mia-Software) - Bug 332998 - To be able to add a column and fill it with the result of a query
+ * Gregoire Dupe (Mia-Software) - Bug 333015 - To be able to hide columns
+ * Nicolas Guyomar (Mia-Software) - Bug 333015 - To be able to hide columns
+ * Nicolas Guyomar (Mia-Software) - Bug 333029 - To be able to save the size of the lines and the columns
+ * Nicolas Guyomar (Mia-Software) - Bug 333414 - The user must be able to save the column order
+ * Nicolas Guyomar (Mia-Software) - Bug 335154 - Sort Column By Type : Cannot modify resource set without a write transaction
+ * Nicolas Guyomar (Mia-Software) - Bug 335155 - Hide Empty Column : Cannot modify resource set without a write transaction
+ * Nicolas Guyomar (Mia-Software) - Bug 335156 - Only Show Common column : Cannot modify resource set without a write transaction
+ * Nicolas Guyomar (Mia-Software) - Bug 335020 - Nattable widget should use the Eclipse framework
+ * Nicolas Guyomar (Mia-Software) - Bug 337322 - [TableConfiguration] Customization declared in the file tableconfiguration is not loaded
+ * Nicolas Guyomar (Mia-Software) - Bug 338536 - Problem with the refresh of the table : the scrollbar returns to this initial position
+ * Nicolas Bros (Mia-Software) - Bug 338536 - Problem with the refresh of the table : the scrollbar returns to this initial position
+ * Nicolas Guyomar (Mia-Software) - Bug 337454 - We can't delete a query Column
+ * Nicolas Guyomar (Mia-Software) - Bug 337395 - Unused columns should be destroyed
+ * Nicolas Guyomar (Mia-Software) - Bug 339554 - org.eclipse.emf.facet.widgets.celleditors API cleaning
+ * Nicolas Guyomar (Mia-Software) - Bug 339922 - INatTableWidget method isCellSelected should use the plural
+ * Nicolas Guyomar (Mia-Software) - Bug 340681 - Facet column implementation
+ * Vincent Lorenzo (CEA-LIST) - Bug 337326 - Show/Hide Column : Sort the columns by name
+ * Nicolas Guyomar (Mia-Software) - Bug 340940 - To be able to view facet attributes and facet references in a table
+ * Vincent Lorenzo (CEA-LIST) - Bug 337408 - Add an action to sort columns by name
+ * Nicolas Guyomar (Mia-Software) - Bug 336482 - KeyBinding to edit element in Table : F2
+ * Vincent Lorenzo (CEA-LIST) - Bug 341238 - We need to be able to specify which column have to be hidden/visible using the customization mechanism
+ * Gregoire Dupe (Mia-Software) - Bug 341238 - We need to be able to specify which column have to be hidden/visible using the customization mechanism
+ * Nicolas Guyomar (Mia-Software) - Bug 342451 - To be able to edit derived facet attributes and derived facet references in a table
+ * Vincent Lorenzo (CEA-LIST) - Bug 341238 - We need to be able to specify which column have to be hidden/visible using the customization mechanism
+ * Nicolas Guyomar (Mia-Software) - Bug 343411 - [Table] Create new elements does not support IJavaModelQuery anymore
+ * Gregoire Dupe (Mia-Software) - Bug 343811 - EMF Facet Regression : Created elements in a table are not serialized
+ * Vincent Lorenzo (CEA-LIST) - Bug 344125 - The API should provide a method selectRows(List<EObject> elementsToSelect)
+ * Nicolas Guyomar (Mia-Software) - Bug 344274 - SWT BOT fail on Hudson
+ * Nicolas Guyomar (Mia-Software) - Bug 344475 - To be able to select a cell by EStructuralFeature in the table
+ * Nicolas Guyomar (Mia-Software) - Bug 342028 - Field can be edited even if they are marked as N/A
+ * Nicolas Guyomar (Mia-Software) - Bug 344413 - Facet Columns are never created when we begin with an empty table
+ * Gregoire Dupe (Mia-Software) - Bug 343859 - The local customizations are not applied when we reopen a table
+ * Nicolas Guyomar (Mia-Software) - Bug 344670 - Problems with the columns creation : very slow + scrollbar blinked
+ * Vincent Lorenzo (CEA LIST) - Bug 341238 - We need to be able to specify which column have to be hidden/visible using the customization mechanism
+ * Nicolas Guyomar (Mia-Software) - Bug 344925 - Undo/Redo after the action Show Columns
+ * Gregoire Dupe (Mia-Software) - Bug 344925 - Undo/Redo after the action Show Columns - Regression fix
+ * Nicolas Guyomar (Mia-Software) - Bug 345665 - Columns are duplicated when you drop many elements in the same time
+ * Nicolas Guyomar (Mia-Software) - Bug 346465 - [EMF Facet Table] Remove line does not remove obsolete column
+ * Gregoire Dupe (Mia-Software) - Bug 345730 - Deleting an element in the model breaks the table
+ * Gregoire Dupe (Mia-Software) - Bug 354224 - mutually exclusive Facets
+ * Grégoire Dupé (Mia-Software) - Bug 356795 - [Unit Test Failure][0.2/4.2][0.2/3.8] org.eclipse.emf.facet.widgets.nattable.tests.Bug344413Test.testBug344413
+ * Gregoire Dupe (Mia-Software) - Bug 366804 - [Restructuring] Table widget upgrade
+ * Gregoire Dupe (Mia-Software) - Bug 367613 - Table widget refactoring
+ * Gregoire Dupe (Mia-Software) - Bug 367700 - [Unit Test Failure][0.2/3.8] org.eclipse.emf.facet.widgets.table.tests.internal.v0_2.swtbot.NatTableUITests.testOpenLoadCustomizationDialog
+ * Gregoire Dupe (Mia-Software) - Bug 369987 - [Restructuring][Table] Switch to the new customization and facet framework
+ * Gregoire Dupe (Mia-Software) - Bug 373078 - API Cleaning
+ * Gregoire Dupe (Mia-Software) - Bug 375087 - [Table] ITableWidget.addColumn(List<ETypedElement>, List<FacetSet>)
+ * Gregoire Dupe (Mia-Software) - Bug 372626 - Aggregates
+ * Gregoire Dupe (Mia-Software) - Bug 376158 - [Table] Unexpected columns when customizations are loaded
+ * Nicolas Bros (Mia-Software) - Bug 378475 - unit test failures after table refactoring
+ * Olivier Remaud (Soft-Maint) - Bug 378499 - optimizing table opening
+ * Gregoire Dupe (Mia-Software) - Bug 387008 - [Table] Papyrus needs methods provided by TableInstanceCommandFactory
+ * Contributors:
+ * Gregoire Dupe (Mia-Software) - Bug 387008 - [Table] Papyrus needs methods provided by TableInstanceCommandFactory
+ *******************************************************************************/
+package org.eclipse.papyrus.infra.table.efacet.menu.factory;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.LinkedHashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Set;
+
+import javax.management.RuntimeErrorException;
+
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.common.command.CompoundCommand;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.ecore.ETypedElement;
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.emf.facet.custom.metamodel.v0_2_0.custom.Customization;
+import org.eclipse.emf.facet.custom.ui.internal.exported.ICustomizationCommandFactory;
+import org.eclipse.emf.facet.custom.ui.internal.exported.ICustomizationCommandFactoryFactory;
+import org.eclipse.emf.facet.efacet.core.FacetUtils;
+import org.eclipse.emf.facet.efacet.core.IFacetManager;
+import org.eclipse.emf.facet.efacet.core.exception.FacetManagerException;
+import org.eclipse.emf.facet.efacet.metamodel.v0_2_0.efacet.DerivedTypedElement;
+import org.eclipse.emf.facet.efacet.metamodel.v0_2_0.efacet.FacetOperation;
+import org.eclipse.emf.facet.efacet.metamodel.v0_2_0.efacet.FacetSet;
+import org.eclipse.emf.facet.util.emf.core.command.ICommandFactoryResult;
+import org.eclipse.emf.facet.util.emf.core.command.ICommandFactoryResultFactory;
+import org.eclipse.emf.facet.widgets.celleditors.ICommandFactory;
+import org.eclipse.emf.facet.widgets.table.metamodel.v0_2_0.table.Column;
+import org.eclipse.emf.facet.widgets.table.metamodel.v0_2_0.table.FeatureColumn;
+import org.eclipse.emf.facet.widgets.table.metamodel.v0_2_0.table.Row;
+import org.eclipse.emf.facet.widgets.table.metamodel.v0_2_0.table.Table;
+import org.eclipse.emf.facet.widgets.table.metamodel.v0_2_0.table.TableFactory;
+import org.eclipse.emf.facet.widgets.table.metamodel.v0_2_0.table.TablePackage;
+import org.eclipse.emf.facet.widgets.table.ui.command.ITableCommandFactory;
+import org.eclipse.emf.facet.widgets.table.ui.internal.exported.TableWidgetUtils;
+import org.eclipse.osgi.util.NLS;
+
+//TODO Remove implementation of org.eclipse.emf.facet.widgets.table.ui.internal.ITableCommandFactory
+public class TableCommandFactory implements org.eclipse.papyrus.infra.table.efacet.menu.factory.ITableCommandFactory, ITableCommandFactory {
+
+ // private static final boolean DEBUG = DebugUtils.getDebugStatus(Activator.getDefault());
+
+ private final Table table;
+
+ private final EditingDomain editingDomain;
+
+ private final ICommandFactory commandFactory;
+
+ private final IFacetManager facetManager;
+
+ public TableCommandFactory(final Table table, final EditingDomain editingDomain, final ICommandFactory commandFactory, final IFacetManager facetManager) {
+ this.table = table;
+ this.editingDomain = editingDomain;
+ this.commandFactory = commandFactory;
+ this.facetManager = facetManager;
+ }
+
+ /**
+ * @param facetSets
+ * must not contains more than one reference to a same FacetSet
+ */
+ public Command createSetLoadedFacetSetsCommand(final List<FacetSet> facetSets) {
+ return this.createSetFacetSetsCommand(facetSets);
+ }
+
+ /**
+ * @param facetSets
+ * must not contains more than one reference to a same FacetSet
+ * @param manageCustoms
+ */
+ private Command createSetLoadedFacetSetsCommand(final List<? extends FacetSet> facetSets, final boolean manageCustoms) {
+ // It is expected that the column points to the override feature (the
+ // signature)
+ final List<Command> commandList = new CommandList();
+ final List<FeatureColumn> columnsToRemove = TableInstanceUtils.columnsToRemove(this.table, facetSets, this.table.getRows());
+ for(Column columnToRemove : columnsToRemove) {
+ final Command removeColumnCmd = createRemoveColumnCommand(columnToRemove);
+ commandList.add(removeColumnCmd);
+ }
+ if(!this.table.getFacetSets().equals(facetSets)) {
+ final Command setCommand = this.commandFactory.createSetCommand(this.editingDomain, this.table, TablePackage.eINSTANCE.getTable_FacetSets(), facetSets);
+ commandList.add(setCommand);
+ }
+ // If some added facetSet are also customizations they have to be
+ // loaded. This
+ // is required by this aggregate.
+ final List<Customization> addedCustoms = new LinkedList<Customization>();
+ for(FacetSet facetSet : facetSets) {
+ if(facetSet instanceof Customization) {
+ final Customization custom = (Customization)facetSet;
+ addedCustoms.add(custom);
+ }
+ }
+ if(manageCustoms) {
+ // If some removed facetSet are also customizations they have to be
+ // unloaded. This
+ // is required by this aggregate.
+
+ final List<FacetSet> removedFacetSet = new ArrayList<FacetSet>();
+ removedFacetSet.addAll(this.table.getFacetSets());
+ removedFacetSet.removeAll(facetSets);
+ final List<Customization> removedCustoms = new LinkedList<Customization>();
+ for(FacetSet facetSet : removedFacetSet) {
+ if(facetSet instanceof Customization) {
+ final Customization custom = (Customization)facetSet;
+ removedCustoms.add(custom);
+ }
+ }
+ if(!(addedCustoms.isEmpty() && removedCustoms.isEmpty())) {
+ final List<Customization> customizations = new ArrayList<Customization>();
+ customizations.addAll(this.table.getCustomizations());
+ customizations.removeAll(removedCustoms);
+ customizations.addAll(addedCustoms);
+ final Command loadCustom = createCoreSetCustomizationsCommand(customizations);
+ commandList.add(loadCustom);
+ }
+ }
+ return createResult(commandList, "Set loaded facetSets"); //$NON-NLS-1$
+ }
+
+ private static Command createResult(final List<Command> commandList, final String label) {
+ Command result = null;
+ while(commandList.contains(null)) {
+ commandList.remove(null);
+ }
+ if(!commandList.isEmpty()) {
+ result = new CompoundCommand(label, commandList);
+ }
+ return result;
+ }
+
+ public Command createRemoveColumnCommand(final Column column) {
+ final List<Command> commandList = new ArrayList<Command>();
+ if(this.table.getColumns().contains(column)) {
+ final Command command = this.commandFactory.createRemoveCommand(this.editingDomain, this.table, TablePackage.eINSTANCE.getTable_Columns(), column);
+ // This compoundCommand is only used to hold debug informations.
+ commandList.add(command);
+ }
+ return createResult(commandList, "Remove column"); //$NON-NLS-1$
+ }
+
+ public Command createAddColumnCommand(final List<ETypedElement> eTypedElements, final List<FacetSet> facetSets) {
+ final List<Command> commandList = new CommandList();
+ final Set<FacetSet> newFacetSets = new LinkedHashSet<FacetSet>();
+ newFacetSets.addAll(facetSets);
+ newFacetSets.addAll(this.table.getFacetSets());
+ for(ETypedElement eTypedElement : eTypedElements) {
+ final FacetSet signatureFS = getSignatureFacetSet(eTypedElement);
+ if(signatureFS != null) {
+ newFacetSets.add(signatureFS);
+ }
+ }
+ final Command addFacetCommand = createSetLoadedFacetSetsCommand(new ArrayList<FacetSet>(newFacetSets));
+ commandList.add(addFacetCommand);
+ final Command addColumn = createAddColumn(eTypedElements);
+ commandList.add(addColumn);
+ return createResult(commandList, "Add columns and facetSets"); //$NON-NLS-1$
+ }
+
+ private static FacetSet getSignatureFacetSet(final ETypedElement eTypedElement) {
+ FacetSet result = null;
+ if(eTypedElement instanceof DerivedTypedElement) {
+ final DerivedTypedElement derivedTE = (DerivedTypedElement)eTypedElement;
+ DerivedTypedElement signatureTE = null;
+ try {
+ signatureTE = FacetUtils.getTopOverrideFeature(derivedTE);
+ } catch (FacetManagerException e) {
+ //FIXME
+ throw new RuntimeException(e);
+// throw new TableWidgetRuntimeException(e);
+ }
+ if(derivedTE.getOverride() != null && signatureTE != null) {
+ final FacetSet signatureFS = FacetUtils.getFacetSet(signatureTE);
+ result = signatureFS;
+ }
+ }
+ return result;
+ }
+
+ private Command createAddColumn(final List<ETypedElement> eTypedElements) {
+ final List<Command> commandList = new CommandList();
+ for(ETypedElement eTypedElement : eTypedElements) {
+ final Command addColumn = createAddColumn(eTypedElement);
+ commandList.add(addColumn);
+ }
+ return createResult(commandList, "Add columns"); //$NON-NLS-1$
+ }
+
+ private Command createAddColumn(final ETypedElement eTypedElement) {
+ ETypedElement signature = eTypedElement;
+ if(eTypedElement instanceof FacetOperation) {
+ final FacetOperation facetOperation = (FacetOperation)eTypedElement;
+ signature = FacetUtils.getSignature(facetOperation);
+ }
+ Column existingColumn = null;
+ for(Column column : this.table.getColumns()) {
+ if(column instanceof FeatureColumn) {
+ final FeatureColumn featureColumn = (FeatureColumn)column;
+ if(featureColumn.getFeature().equals(signature)) {
+ existingColumn = column;
+ break;
+ }
+ }
+ }
+ final List<Command> commandList = new CommandList();
+ if(existingColumn == null) {
+ final FeatureColumn column = TableFactory.eINSTANCE.createFeatureColumn();
+ final Command setColumn = this.commandFactory.createAddCommand(this.editingDomain, this.table, TablePackage.eINSTANCE.getTable_Columns(), column);
+ commandList.add(setColumn);
+ final Command setETypedElement = this.commandFactory.createSetCommand(this.editingDomain, column, TablePackage.eINSTANCE.getFeatureColumn_Feature(), signature);
+ commandList.add(setETypedElement);
+ }
+ return createResult(commandList, "Add column"); //$NON-NLS-1$
+ }
+
+ public Command createSetCustomizationCommand(final List<Customization> customizations) {
+ final List<Command> commandList = new CommandList();
+ final Set<FacetSet> referredFS = CustomizationUtils.findFacetsCustomizedBy(customizations);
+ final List<FacetSet> alreadyLoaded = this.table.getFacetSets();
+ final List<Customization> removedCustoms = new ArrayList<Customization>();
+ removedCustoms.addAll(this.table.getCustomizations());
+ removedCustoms.removeAll(customizations);
+ final List<FacetSet> facetSets = new ArrayList<FacetSet>();
+ facetSets.addAll(customizations);
+ // This "remove" avoid to have a same object in twice in the list.
+ facetSets.removeAll(alreadyLoaded);
+ facetSets.addAll(alreadyLoaded);
+ // This "remove" avoid to have a same object in twice in the list.
+ facetSets.removeAll(referredFS);
+ facetSets.addAll(referredFS);
+ facetSets.removeAll(removedCustoms);
+ final Command facetLoad = createSetLoadedFacetSetsCommand(facetSets, false);
+ commandList.add(facetLoad);
+ final Command customLoad = createCoreSetCustomizationsCommand(customizations);
+ commandList.add(customLoad);
+ return createResult(commandList, "Load cutomizations and associated facet sets"); //$NON-NLS-1$
+ }
+
+ private Command createCoreSetCustomizationsCommand(final List<Customization> customizations) {
+ final List<Customization> sortedCustoms = new ArrayList<Customization>();
+ sortedCustoms.addAll(this.table.getLocalCustomizations());
+ for(Customization customization : customizations) {
+ if(!sortedCustoms.contains(customization)) {
+ sortedCustoms.add(customization);
+ }
+ }
+ final List<Command> commandList = new CommandList();
+ if(!this.table.getCustomizations().equals(sortedCustoms)) {
+ final Command command = this.commandFactory.createSetCommand(this.editingDomain, this.table, TablePackage.eINSTANCE.getTable_Customizations(), sortedCustoms);
+ commandList.add(command);
+ }
+ return createResult(commandList, "Set loaded cutomizations"); //$NON-NLS-1$
+ }
+
+ class CommandList extends LinkedList<Command> {
+
+ private static final long serialVersionUID = 8581553157248060152L;
+
+ @Override
+ public boolean add(final Command command) {
+ boolean result;
+ if(command == null) {
+ result = false;
+ } else {
+ result = super.add(command);
+ }
+ return result;
+ }
+ }
+
+ public Command createRemoveColumnsCommand(final List<ETypedElement> elements) {
+ final List<Command> commandList = new ArrayList<Command>();
+ if(elements != null && !elements.isEmpty()) {
+ for(Column column : this.table.getColumns()) {
+ if(column instanceof FeatureColumn) {
+ final FeatureColumn featureColumn = (FeatureColumn)column;
+ if(elements.contains(featureColumn.getFeature())) {
+ final Command rmCommand = this.commandFactory.createRemoveCommand(this.editingDomain, this.table, TablePackage.eINSTANCE.getTable_Columns(), featureColumn);
+ commandList.add(rmCommand);
+ }
+ }
+ }
+
+ }
+ return createResult(commandList, NLS.bind("Remove {0} columms", Integer.valueOf(commandList.size()))); //$NON-NLS-1$
+ }
+
+// public Command createSortRowCommand(final FeatureColumn featureColumn, final ColumnSortDirection direction) {
+// final List<Row> rows = new ArrayList<Row>(this.table.getRows());
+// final ETypedElement eTypedElement = featureColumn.getFeature();
+// final RowComparator comparator = new RowComparator(eTypedElement, direction, this.facetManager);
+// Collections.sort(rows, comparator);
+// return new BrutalListSetCommand(this.table, TablePackage.eINSTANCE.getTable_Rows(), rows, Messages.TableCommandFactory_row_sort_label, NLS.bind(Messages.TableCommandFactory_row_sort_description, eTypedElement.getName()));
+// }
+
+ public Command createRemoveRowByEObjectCommand(final Collection<? extends EObject> eObjectRows) {
+ final List<Row> rowsToRemove = new ArrayList<Row>();
+ for(Row row : this.table.getRows()) {
+ if(eObjectRows.contains(row.getElement())) {
+ rowsToRemove.add(row);
+ }
+ }
+ return createRemoveRowsCommand(rowsToRemove);
+ }
+
+ public Command createRemoveUselessColumnsCommand(final Collection<Row> rowsToRemove, final List<FacetSet> nextLoadedFS) {
+ final List<Command> commandList = new CommandList();
+ final List<Row> rowsToKeep = new ArrayList<Row>(this.table.getRows());
+ rowsToKeep.removeAll(rowsToRemove);
+ List<FacetSet> facetSets;
+ if(nextLoadedFS == null) {
+ facetSets = this.table.getFacetSets();
+ } else {
+ facetSets = nextLoadedFS;
+ }
+ final List<FeatureColumn> columns = TableInstanceUtils.columnsToRemove(this.table, facetSets, rowsToKeep);
+
+ for(FeatureColumn column : columns) {
+// DebugUtils.debug(TableCommandFactory.DEBUG, "column to remove: " //$NON-NLS-1$
+// + EcoreUtil.getURI(column.getFeature()));
+ final Command rmColumnCmd = this.commandFactory.createRemoveCommand(this.editingDomain, this.table, TablePackage.eINSTANCE.getTable_Columns(), column);
+ commandList.add(rmColumnCmd);
+ }
+// if(TableCommandFactory.DEBUG) {
+// DebugUtils.debug("Columns to be removed: " + commandList.size()); //$NON-NLS-1$
+// }
+ return createResult(commandList,"remove useless column");
+ }
+
+ public Command createRemoveRowsCommand(final Collection<Row> rows) {
+ final List<Command> cmdList = new CommandList();
+ for(Row row : rows) {
+ final Command removeRowCommand = this.commandFactory.createRemoveCommand(this.editingDomain, this.table, TablePackage.eINSTANCE.getTable_Rows(), row);
+ cmdList.add(removeRowCommand);
+ }
+ final Command updateColumnCmd = createRemoveUselessColumnsCommand(rows, null);
+ cmdList.add(updateColumnCmd);
+ return createResult(cmdList, NLS.bind("Remove {0} row(s)", Integer.valueOf(cmdList.size()))); //$NON-NLS-1$;
+ }
+
+ public Command createAddRowsCommand(final Collection<? extends EObject> eObjects) {
+ final List<Command> cmdList = new CommandList();
+ int nbRows = 0;
+ // the EPackage for which the MetamodelView has already been created
+ final Set<EPackage> alreadyDone = new HashSet<EPackage>();
+ final List<EStructuralFeature> processedSF = new ArrayList<EStructuralFeature>();
+ final List<EObject> tableContent = TableWidgetUtils.getElements(this.table);
+ for(EObject eObject : eObjects) {
+ if(!tableContent.contains(eObject)) {
+ final Row row = TableFactory.eINSTANCE.createRow();
+ final Command setToRowCmd = this.commandFactory.createSetCommand(this.editingDomain, row, TablePackage.eINSTANCE.getRow_Element(), eObject);
+ cmdList.add(setToRowCmd);
+ final Command addRowCmd = this.commandFactory.createAddCommand(this.editingDomain, this.table, TablePackage.eINSTANCE.getTable_Rows(), row);
+ cmdList.add(addRowCmd);
+ nbRows++;
+ for(EStructuralFeature eStructuralFeature : eObject.eClass().getEAllStructuralFeatures()) {
+ if(!processedSF.contains(eStructuralFeature)) {
+ processedSF.add(eStructuralFeature);
+ final Command createAddColumn = createAddColumn(alreadyDone, eStructuralFeature);
+ cmdList.add(createAddColumn);
+ }
+ }
+ }
+ }
+ return createResult(cmdList, NLS.bind("Add of {0} rows", Integer.valueOf(nbRows))); //$NON-NLS-1$
+ }
+
+ private Command createAddColumn(final Set<EPackage> alreadyDone, final EStructuralFeature structuralFeature) {
+ final List<Command> cmdList = new CommandList();
+ if(!TableInstanceUtils.isColumnAlreadyDeclared(this.table, structuralFeature)) {
+ final FeatureColumn referenceColumn = TableFactory.eINSTANCE.createFeatureColumn();
+ referenceColumn.setFeature(structuralFeature);
+ final Command cmd = this.commandFactory.createAddCommand(this.editingDomain, this.table, TablePackage.eINSTANCE.getTable_Columns(), referenceColumn);
+ cmdList.add(cmd);
+ // we add the local customization file
+ final List<Customization> localCustoms = this.table.getLocalCustomizations();
+ final EClass eClass = structuralFeature.getEContainingClass();
+ if(eClass != null) {
+ final EPackage ePackage = eClass.getEPackage();
+ if(!alreadyDone.contains(ePackage) && CustomizationUtils.findCustomizationExtendingEPackage(localCustoms, ePackage) == null) {
+ final Command localCustomCmd = createAddLocalCustomCommand(ePackage);
+ if(localCustomCmd.canExecute()) {
+ cmdList.add(localCustomCmd);
+ }
+ alreadyDone.add(ePackage);
+ }
+ }
+ }
+ return createResult(cmdList, NLS.bind("Add a column for {0}::{1}", //$NON-NLS-1$
+ structuralFeature.getEContainingClass().getName(), structuralFeature.getName()));
+ }
+
+ private Command createAddLocalCustomCommand(final EPackage ePackage) {
+ final List<Command> cmdList = new CommandList();
+ final ICommandFactoryResult<Customization> cmdFactoryResult = createCreateLocalCustom(ePackage);
+ final Customization newCustom = cmdFactoryResult.getResult();
+ cmdList.add(cmdFactoryResult.getCommand());
+ final List<Customization> customs = new ArrayList<Customization>();
+ customs.addAll(this.table.getCustomizations());
+ // we look for the index of the new local custom
+ final List<Customization> localCustoms = this.table.getLocalCustomizations();
+ int index = 0;
+ for(Customization custom : customs) {
+ if(localCustoms.contains(custom)) {
+ break;
+ }
+ index++;
+ }
+ customs.add(index, newCustom);
+ final Command setCustomCmd = this.commandFactory.createSetCommand(this.editingDomain, this.table, TablePackage.eINSTANCE.getTable_Customizations(), customs);
+ cmdList.add(setCustomCmd);
+ return createResult(cmdList, NLS.bind("Add of a new customization for the ePackage '{0}'", //$NON-NLS-1$
+ ePackage.getName()));
+ }
+
+ public ICommandFactoryResult<Customization> createCreateLocalCustom(final EPackage ePackage) {
+ final ICustomizationCommandFactory customCmdFactory = ICustomizationCommandFactoryFactory.DEFAULT.createCustomizationCommandFactory(this.editingDomain, this.commandFactory);
+ final List<Command> cmdList = new CommandList();
+ final ICommandFactoryResult<Customization> cmdFactoryResult = customCmdFactory.createCustomization("Column hiding customization for " //$NON-NLS-1$
+ + ePackage.getName());
+ final Customization customization = cmdFactoryResult.getResult();
+ cmdList.add(cmdFactoryResult.getCommand());
+ final Command addToLocalCmd = this.commandFactory.createAddCommand(this.editingDomain, this.table, TablePackage.eINSTANCE.getTable_LocalCustomizations(), customization);
+ cmdList.add(addToLocalCmd);
+ final Command addAllCmd = this.commandFactory.createAddCommand(this.editingDomain, this.table, TablePackage.eINSTANCE.getTable_Customizations(), customization);
+ cmdList.add(addAllCmd);
+ final Command cmd = createResult(cmdList, "Create a local custom."); //$NON-NLS-1$
+ return ICommandFactoryResultFactory.DEFAULT.createCommandFactoryResult(cmd, customization);
+
+ }
+
+ public Command createSetFacetSetsCommand(final List<? extends FacetSet> facetSets) {
+ return createSetLoadedFacetSetsCommand(facetSets, true);
+ }
+
+
+
+}
diff --git a/sandbox/org.eclipse.papyrus.infra.table.efacet.menu/src/org/eclipse/papyrus/infra/table/efacet/menu/factory/TableInstanceCommandFactory.java b/sandbox/org.eclipse.papyrus.infra.table.efacet.menu/src/org/eclipse/papyrus/infra/table/efacet/menu/factory/TableInstanceCommandFactory.java
new file mode 100644
index 00000000000..994fb134fb9
--- /dev/null
+++ b/sandbox/org.eclipse.papyrus.infra.table.efacet.menu/src/org/eclipse/papyrus/infra/table/efacet/menu/factory/TableInstanceCommandFactory.java
@@ -0,0 +1,334 @@
+/*****************************************************************************
+ * Copyright (c) 2012 CEA LIST.
+ *
+ *
+ * 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:
+ * Vincent Lorenzo (CEA LIST) Vincent.Lorenzo@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.table.efacet.menu.factory;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.common.command.CompoundCommand;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.ecore.ETypedElement;
+import org.eclipse.emf.ecore.EcorePackage;
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.emf.facet.custom.metamodel.v0_2_0.custom.Customization;
+import org.eclipse.emf.facet.custom.metamodel.v0_2_0.custom.EClassCustomization;
+import org.eclipse.emf.facet.custom.ui.internal.exported.ICustomizationCommandFactory;
+import org.eclipse.emf.facet.custom.ui.internal.exported.ICustomizationCommandFactoryFactory;
+import org.eclipse.emf.facet.efacet.core.FacetUtils;
+import org.eclipse.emf.facet.efacet.metamodel.v0_2_0.efacet.DerivedTypedElement;
+import org.eclipse.emf.facet.efacet.metamodel.v0_2_0.efacet.Facet;
+import org.eclipse.emf.facet.efacet.metamodel.v0_2_0.efacet.FacetOperation;
+import org.eclipse.emf.facet.efacet.metamodel.v0_2_0.efacet.extensible.Query;
+import org.eclipse.emf.facet.efacet.metamodel.v0_2_0.efacet.query.IsOneOfQuery;
+import org.eclipse.emf.facet.efacet.metamodel.v0_2_0.efacet.query.QueryFactory;
+import org.eclipse.emf.facet.efacet.metamodel.v0_2_0.efacet.query.QueryPackage;
+import org.eclipse.emf.facet.util.emf.core.command.ICommandFactoryResult;
+import org.eclipse.emf.facet.util.emf.core.command.ICommandFactoryResultFactory;
+import org.eclipse.emf.facet.widgets.celleditors.ICommandFactoriesRegistry;
+import org.eclipse.emf.facet.widgets.celleditors.ICommandFactory;
+import org.eclipse.emf.facet.widgets.table.metamodel.v0_2_0.table.Column;
+import org.eclipse.emf.facet.widgets.table.metamodel.v0_2_0.table.FeatureColumn;
+import org.eclipse.emf.facet.widgets.table.metamodel.v0_2_0.table.Row;
+import org.eclipse.emf.facet.widgets.table.metamodel.v0_2_0.table.SourceColumn;
+import org.eclipse.emf.facet.widgets.table.metamodel.v0_2_0.table.Table;
+import org.eclipse.emf.facet.widgets.table.metamodel.v0_2_0.table.TablePackage;
+import org.eclipse.emf.facet.widgets.table.ui.internal.exported.ITableWidgetInternal;
+
+
+//FIXME duplicated and adapted code from EMF-Facet
+//EMF-Facet should provides a best way to hide columns
+public final class TableInstanceCommandFactory {
+
+ public static Command createShowHideColumnCommand(final ITableWidgetInternal widgetController,final EditingDomain editingDomain, ICommandFactory commandFactory, final Table table, final List<Column> columnsToShow, final List<Column> columnsToHide, final boolean putOnTheTop) {
+ CompoundCommand compoundCommand = new CompoundCommand("Show/hide column"); //$NON-NLS-1$
+
+ for(Column current : columnsToShow) {
+ if(current instanceof SourceColumn) {
+ Command cmd = commandFactory.createSetCommand(editingDomain, current, TablePackage.eINSTANCE.getSourceColumn_IsHidden(), Boolean.FALSE);
+ if(cmd.canExecute()) {
+ compoundCommand.append(cmd);
+ }
+ }
+ }
+// HashSet<FeatureColumn> fColumnsToHide = new HashSet<FeatureColumn>();
+ HashSet<ETypedElement> featureToHide = new HashSet<ETypedElement>();
+ for(Column current : columnsToHide) {
+ if(current instanceof FeatureColumn) {
+// fColumnsToHide.add((FeatureColumn)current);
+ featureToHide.add(((FeatureColumn)current).getFeature());
+ } else {
+ Command cmd = commandFactory.createSetCommand(editingDomain, current, TablePackage.eINSTANCE.getSourceColumn_IsHidden(), Boolean.TRUE);
+ compoundCommand.append(cmd);
+ }
+ }
+ Command tmp = createHideColumnCommand(widgetController,editingDomain, table,featureToHide);
+
+ if(tmp != null) {
+ compoundCommand.append(tmp);
+ }
+ //FIXME : we ignore it in Papyrus...
+ // if (putOnTheTop) {
+ // Command cmd = createPutLocalCustomizationOnTheTopCommand(widgetController);
+ // if (cmd.canExecute()) {
+ // compoundCommand.append(cmd);
+ // }
+ // }
+ return compoundCommand;
+ }
+
+ //public static Command createPutLocalCustomizationOnTheTopCommand(final EditingDomain editingDomain
+ // final Object natTableWidget) {
+ // ICommandFactory commandFactory = natTableWidget.getCommandFactory();
+ // List<Customization> localCustoms = natTableWidget.getLocalCustomizations();
+ // List<Customization> customizations = new ArrayList<Customization>();
+ // customizations.addAll(natTableWidget.getTable().getCustomizations());
+ // customizations.removeAll(localCustoms);
+ // customizations.addAll(0, localCustoms);
+ // return commandFactory.createSetCommand(natTableWidget.getEditingDomain(),
+ // natTableWidget.getTable(),
+ // TablePackage.eINSTANCE.getTable_Customizations(),
+ // customizations);
+ //}
+
+
+
+ private TableInstanceCommandFactory() {
+ // Prevents instantiation
+ }
+
+ /**
+ * This method retruns an EMF command deleting the a collection of EObject
+ *
+ * @param label
+ * This label will be visible in the menu 'Edit'.
+ * @param eObjects
+ * @param controller
+ * @return
+ */
+ public static Command delete(final String label, final Collection<? extends EObject> eObjects, final EditingDomain domain, final ICommandFactory factory) {
+ List<Command> cmdList = new ArrayList<Command>();
+ for(EObject eObject : eObjects) {
+ Command command = factory.createDeleteCommand(domain, eObject);
+ cmdList.add(command);
+ }
+ Command result = null;
+ if(!cmdList.isEmpty()) {
+ result = new CompoundCommand(label, cmdList);
+ }
+ return result;
+ }
+
+ /**
+ * This method create a command deleting use less row and columns.
+ *
+ * @param controller
+ * @return null if no action has to be performed.
+ */
+ public static final Command createRemoveUselessRowsAndColumnsCommand(final EditingDomain domain, final ICommandFactory factory, final Table table) {
+ List<Command> cmdList = new ArrayList<Command>();
+ List<Row> rowsToRemove = TableInstanceUtils.findUselessRow(table);
+// if(TableWidgetController.DEBUG_REMOVE_USELESS_ROWS_AND_COLUMNS) {
+// DebugUtils.debug("Rows to be removed: " + rowsToRemove.size()); //$NON-NLS-1$
+// }
+ final Command deleteRows = TableInstanceCommandFactory.delete("Delete useless row", rowsToRemove,domain, factory);
+ if(deleteRows != null) {
+ cmdList.add(deleteRows);
+ }
+ final TableCommandFactory tableCmdFactory = new TableCommandFactory(table,domain, factory, null);
+ final Command removeColumnCommand = tableCmdFactory.createRemoveUselessColumnsCommand(rowsToRemove, null);
+ if(removeColumnCommand != null) {
+ if(!removeColumnCommand.canExecute()) {
+ //FIXME
+ throw new RuntimeException("Command cannot be executed");
+// throw new TableWidgetRuntimeException("Command cannot be executed"); //$NON-NLS-1$
+ }
+ cmdList.add(removeColumnCommand);
+ }
+ CompoundCommand command = null;
+ if(!cmdList.isEmpty()) {
+ command = new CompoundCommand("Remove useless columns", cmdList);
+ }
+ return command;
+ }
+
+ /**
+ *
+ * @param column
+ * a column
+ * @param isHidden
+ * the new feature value for this column
+ * @param customizedFeatureName
+ * the customized feature name
+ * @return
+ */
+ public static Command createHideColumnCommand(final ITableWidgetInternal widgetController, final EditingDomain domain, final Table table, final Collection<ETypedElement> featuresToHide) {
+ final FacetOperation isVisibleProperty = widgetController.getCustomPropertiesHandler().getIsVisible();
+ final CompoundCommand resultCmd = new CompoundCommand("Show/hide column"); //$NON-NLS-1$
+ final EditingDomain editingDomain = domain;
+ final ICommandFactory commandFactory = ICommandFactoriesRegistry.INSTANCE.getCommandFactoryFor(editingDomain);
+ // final EStructuralFeature featureOfTheColumn = featureColumn
+ // .getFeature();
+ // EObject packageLevel = featureOfTheColumn.eContainer().eContainer();
+ // if (!(packageLevel instanceof EPackage)) {
+ // throw new IllegalStateException(
+ // "Unexpected feature container type " + packageLevel + " found. (EPackage is execpected)"); //$NON-NLS-1$ //$NON-NLS-2$
+ // }
+ // final EPackage customizedEPackage = (EPackage) packageLevel;
+ // 1 we look for the corresponding customization
+ final List<Customization> localCustomizations = table.getLocalCustomizations();
+ Customization customization = null;
+ if(!localCustomizations.isEmpty()) {
+ customization = localCustomizations.get(0);
+ }
+ final ICustomizationCommandFactory customCmdFactory = ICustomizationCommandFactoryFactory.DEFAULT.createCustomizationCommandFactory(editingDomain, commandFactory);
+ // If the wanted customization does not exist then we create it.
+ if(customization == null) {
+ // final TableCommandFactory factory = new TableCommandFactory(table, domain, commandFactory, null);
+ final ICommandFactoryResult<Customization> cmdFactoryResult = createCreateLocalCustom(editingDomain, commandFactory, table, EcorePackage.eINSTANCE);
+ customization = cmdFactoryResult.getResult();
+ resultCmd.append(cmdFactoryResult.getCommand());
+ }
+ Facet typeCustomization = CustomizationUtils.findFacetByExtendedMetaclass(FacetUtils.getFacets(customization), EcorePackage.eINSTANCE.getETypedElement());
+ IsOneOfQuery conformanceQuery;
+ if(typeCustomization == null) {
+ conformanceQuery = QueryFactory.eINSTANCE.createIsOneOfQuery();
+ ICommandFactoryResult<EClassCustomization> createEClassCustom = customCmdFactory.createEClassCustomization(customization, EcorePackage.eINSTANCE.getETypedElement(), conformanceQuery);
+ typeCustomization = createEClassCustom.getResult();
+ resultCmd.append(createEClassCustom.getCommand());
+ } else {
+ if(!(typeCustomization instanceof EClassCustomization)) {
+ // throw new TableWidgetRuntimeException("Unexpected type for the variable 'featureContainer'"); //$NON-NLS-1$
+ //TODO
+ }
+ DerivedTypedElement conformanceTE = (DerivedTypedElement)typeCustomization.getConformanceTypedElement();
+ conformanceQuery = (IsOneOfQuery)conformanceTE.getQuery();
+ }
+ // final HashSet<ETypedElement> featuresToHide = new HashSet<ETypedElement>();
+ // for(FeatureColumn column : featureColumns) {
+ // featuresToHide.add(column.getFeature());
+ // }
+ final Command initQuery = commandFactory.createSetCommand(editingDomain, conformanceQuery, QueryPackage.eINSTANCE.getIsOneOfQuery_ExpectedEObjects(), new ArrayList<ETypedElement>(featuresToHide));
+ resultCmd.append(initQuery);
+ final Query query = QueryFactory.eINSTANCE.createFalseLiteralQuery();
+ final ICommandFactoryResult<Facet> propConfigCmd = customCmdFactory.setPropertyConfig(typeCustomization, null, isVisibleProperty, query);
+ resultCmd.append(propConfigCmd.getCommand());
+ return resultCmd;
+ }
+
+
+ public static ICommandFactoryResult<Customization> createCreateLocalCustom(final EditingDomain editingDomain, final ICommandFactory commandFactory, final Table table, final EPackage ePackage) {
+ final ICustomizationCommandFactory customCmdFactory = ICustomizationCommandFactoryFactory.DEFAULT.createCustomizationCommandFactory(editingDomain, commandFactory);
+ final List<Command> cmdList = new CommandList();
+ final ICommandFactoryResult<Customization> cmdFactoryResult = customCmdFactory.createCustomization("Column hiding customization for " //$NON-NLS-1$
+ + ePackage.getName());
+ final Customization customization = cmdFactoryResult.getResult();
+ cmdList.add(cmdFactoryResult.getCommand());
+ final Command addToLocalCmd = commandFactory.createAddCommand(editingDomain, table, TablePackage.eINSTANCE.getTable_LocalCustomizations(), customization);
+ cmdList.add(addToLocalCmd);
+ final Command addAllCmd = commandFactory.createAddCommand(editingDomain, table, TablePackage.eINSTANCE.getTable_Customizations(), customization);
+ cmdList.add(addAllCmd);
+ final Command cmd = createResult(cmdList, "Create a local custom."); //$NON-NLS-1$
+ return ICommandFactoryResultFactory.DEFAULT.createCommandFactoryResult(cmd, customization);
+
+ }
+
+ private static Command createResult(final List<Command> commandList, final String label) {
+ Command result = null;
+ while(commandList.contains(null)) {
+ commandList.remove(null);
+ }
+ if(!commandList.isEmpty()) {
+ result = new CompoundCommand(label, commandList);
+ }
+ return result;
+ }
+
+
+
+ // /**
+ // * This method retruns an EMF command deleting the a collection of EObject
+ // *
+ // * @param label
+ // * This label will be visible in the menu 'Edit'.
+ // * @param eObjects
+ // * @param controller
+ // * @return
+ // */
+ // public static Command delete(final String label, final Collection<? extends EObject> eObjects, final TableWidgetController controller) {
+ // List<Command> cmdList = new ArrayList<Command>();
+ // for(EObject eObject : eObjects) {
+ // Command command = controller.getCommandFactory().createDeleteCommand(controller.getEditingDomain(), eObject);
+ // cmdList.add(command);
+ // }
+ // Command result = null;
+ // if(!cmdList.isEmpty()) {
+ // result = new CompoundCommand(label, cmdList);
+ // }
+ // return result;
+ // }
+ //
+ // /**
+ // * This method create a command deleting use less row and columns.
+ // *
+ // * @param controller
+ // * @return null if no action has to be performed.
+ // */
+ // public static final Command createRemoveUselessRowsAndColumnsCommand(final TableWidgetController controller) {
+ // List<Command> cmdList = new ArrayList<Command>();
+ // List<Row> rowsToRemove = TableInstanceUtils.findUselessRow(controller.getTable());
+ // if(TableWidgetController.DEBUG_REMOVE_USELESS_ROWS_AND_COLUMNS) {
+ // DebugUtils.debug("Rows to be removed: " + rowsToRemove.size()); //$NON-NLS-1$
+ // }
+ // final Command deleteRows = TableInstanceCommandFactory.delete(Messages.TableWidgetController_DeleteUselessRows, rowsToRemove, controller);
+ // if(deleteRows != null) {
+ // cmdList.add(deleteRows);
+ // }
+ // final TableCommandFactory tableCmdFactory = new TableCommandFactory(controller.getTable(), controller.getEditingDomain(), controller.getCommandFactory(), null);
+ // final Command removeColumnCommand = tableCmdFactory.createRemoveUselessColumnsCommand(rowsToRemove, null);
+ // if(removeColumnCommand != null) {
+ // if(!removeColumnCommand.canExecute()) {
+ // throw new TableWidgetRuntimeException("Command cannot be executed"); //$NON-NLS-1$
+ // }
+ // cmdList.add(removeColumnCommand);
+ // }
+ // CompoundCommand command = null;
+ // if(!cmdList.isEmpty()) {
+ // command = new CompoundCommand(Messages.TableWidgetController_RemoveUselessRowsAndColumns, cmdList);
+ // }
+ // return command;
+ // }
+ private static class CommandList extends LinkedList<Command> {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 4393120485370832319L;
+
+ @Override
+ public boolean add(final Command command) {
+ boolean result;
+ if(command == null) {
+ result = false;
+ } else {
+ result = super.add(command);
+ }
+ return result;
+ }
+ }
+}
diff --git a/sandbox/org.eclipse.papyrus.infra.table.efacet.menu/src/org/eclipse/papyrus/infra/table/efacet/menu/factory/TableInstanceUtils.java b/sandbox/org.eclipse.papyrus.infra.table.efacet.menu/src/org/eclipse/papyrus/infra/table/efacet/menu/factory/TableInstanceUtils.java
new file mode 100644
index 00000000000..29514ec5451
--- /dev/null
+++ b/sandbox/org.eclipse.papyrus.infra.table.efacet.menu/src/org/eclipse/papyrus/infra/table/efacet/menu/factory/TableInstanceUtils.java
@@ -0,0 +1,223 @@
+/*******************************************************************************
+ * Copyright (c) 2010, 2011, 2012 Mia-Software.
+ * 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 Bros (Mia-Software) - Bug 331203 - table model editor - initial API and implementation
+ * Nicolas Bros (Mia-Software) - Bug 332437 - NatTable : pluggable cell editors
+ * Nicolas Guyomar (Mia-Software) - Bug 331442 - To be able to add and remove lines (model elements) from the table
+ * Nicolas Bros (Mia-Software) - Bug 332226 - To be able to create or delete model element from the table
+ * Nicolas Guyomar (Mia-Software) - Bug 332226 - To be able to create or delete model element from the table
+ * Nicolas Bros (Mia-Software) - Bug 332438 - NatTable : table type
+ * Nicolas Bros (Mia-Software) - Bug 332440 - NatTable : force cell editors
+ * Nicolas Bros (Mia-Software) - Bug 331675 - NatTable : copy cells as text
+ * Nicolas Bros (Mia-Software) - Bug 331900 - customizable NatTable
+ * Nicolas Bros (Mia-Software) - Bug 332010 - view Facet customizations on NatTable
+ * Nicolas Bros (Mia-Software) - Bug 332215 - customizable NatTable column headers
+ * Nicolas Guyomar (Mia-Software) - Bug 332215 - customizable NatTable column headers
+ * Nicolas Guyomar (Mia-Software) - Bug 332924 - To be able to save the table
+ * Nicolas Guyomar (Mia-Software) - Bug 332998 - To be able to add a column and fill it with the result of a query
+ * Gregoire Dupe (Mia-Software) - Bug 332998 - To be able to add a column and fill it with the result of a query
+ * Gregoire Dupe (Mia-Software) - Bug 333015 - To be able to hide columns
+ * Nicolas Guyomar (Mia-Software) - Bug 333015 - To be able to hide columns
+ * Nicolas Guyomar (Mia-Software) - Bug 333029 - To be able to save the size of the lines and the columns
+ * Nicolas Guyomar (Mia-Software) - Bug 333414 - The user must be able to save the column order
+ * Nicolas Guyomar (Mia-Software) - Bug 335154 - Sort Column By Type : Cannot modify resource set without a write transaction
+ * Nicolas Guyomar (Mia-Software) - Bug 335155 - Hide Empty Column : Cannot modify resource set without a write transaction
+ * Nicolas Guyomar (Mia-Software) - Bug 335156 - Only Show Common column : Cannot modify resource set without a write transaction
+ * Nicolas Guyomar (Mia-Software) - Bug 335020 - Nattable widget should use the Eclipse framework
+ * Nicolas Guyomar (Mia-Software) - Bug 337322 - [TableConfiguration] Customization declared in the file tableconfiguration is not loaded
+ * Nicolas Guyomar (Mia-Software) - Bug 338536 - Problem with the refresh of the table : the scrollbar returns to this initial position
+ * Nicolas Bros (Mia-Software) - Bug 338536 - Problem with the refresh of the table : the scrollbar returns to this initial position
+ * Nicolas Guyomar (Mia-Software) - Bug 337454 - We can't delete a query Column
+ * Nicolas Guyomar (Mia-Software) - Bug 337395 - Unused columns should be destroyed
+ * Nicolas Guyomar (Mia-Software) - Bug 339554 - org.eclipse.emf.facet.widgets.celleditors API cleaning
+ * Nicolas Guyomar (Mia-Software) - Bug 339922 - INatTableWidget method isCellSelected should use the plural
+ * Nicolas Guyomar (Mia-Software) - Bug 340681 - Facet column implementation
+ * Vincent Lorenzo (CEA-LIST) - Bug 337326 - Show/Hide Column : Sort the columns by name
+ * Nicolas Guyomar (Mia-Software) - Bug 340940 - To be able to view facet attributes and facet references in a table
+ * Vincent Lorenzo (CEA-LIST) - Bug 337408 - Add an action to sort columns by name
+ * Nicolas Guyomar (Mia-Software) - Bug 336482 - KeyBinding to edit element in Table : F2
+ * Vincent Lorenzo (CEA-LIST) - Bug 341238 - We need to be able to specify which column have to be hidden/visible using the customization mechanism
+ * Gregoire Dupe (Mia-Software) - Bug 341238 - We need to be able to specify which column have to be hidden/visible using the customization mechanism
+ * Nicolas Guyomar (Mia-Software) - Bug 342451 - To be able to edit derived facet attributes and derived facet references in a table
+ * Vincent Lorenzo (CEA-LIST) - Bug 341238 - We need to be able to specify which column have to be hidden/visible using the customization mechanism
+ * Nicolas Guyomar (Mia-Software) - Bug 343411 - [Table] Create new elements does not support IJavaModelQuery anymore
+ * Gregoire Dupe (Mia-Software) - Bug 343811 - EMF Facet Regression : Created elements in a table are not serialized
+ * Vincent Lorenzo (CEA-LIST) - Bug 344125 - The API should provide a method selectRows(List<EObject> elementsToSelect)
+ * Nicolas Guyomar (Mia-Software) - Bug 344274 - SWT BOT fail on Hudson
+ * Nicolas Guyomar (Mia-Software) - Bug 344475 - To be able to select a cell by EStructuralFeature in the table
+ * Nicolas Guyomar (Mia-Software) - Bug 342028 - Field can be edited even if they are marked as N/A
+ * Nicolas Guyomar (Mia-Software) - Bug 344413 - Facet Columns are never created when we begin with an empty table
+ * Gregoire Dupe (Mia-Software) - Bug 343859 - The local customizations are not applied when we reopen a table
+ * Nicolas Guyomar (Mia-Software) - Bug 344670 - Problems with the columns creation : very slow + scrollbar blinked
+ * Vincent Lorenzo (CEA LIST) - Bug 341238 - We need to be able to specify which column have to be hidden/visible using the customization mechanism
+ * Nicolas Guyomar (Mia-Software) - Bug 344925 - Undo/Redo after the action Show Columns
+ * Gregoire Dupe (Mia-Software) - Bug 344925 - Undo/Redo after the action Show Columns - Regression fix
+ * Nicolas Guyomar (Mia-Software) - Bug 345665 - Columns are duplicated when you drop many elements in the same time
+ * Nicolas Guyomar (Mia-Software) - Bug 346465 - [EMF Facet Table] Remove line does not remove obsolete column
+ * Gregoire Dupe (Mia-Software) - Bug 345730 - Deleting an element in the model breaks the table
+ * Gregoire Dupe (Mia-Software) - Bug 354224 - mutually exclusive Facets
+ * Grégoire Dupé (Mia-Software) - Bug 356795 - [Unit Test Failure][0.2/4.2][0.2/3.8] org.eclipse.emf.facet.widgets.nattable.tests.Bug344413Test.testBug344413
+ * Gregoire Dupe (Mia-Software) - Bug 366804 - [Restructuring] Table widget upgrade
+ * Gregoire Dupe (Mia-Software) - Bug 367613 - Table widget refactoring
+ * Gregoire Dupe (Mia-Software) - Bug 367700 - [Unit Test Failure][0.2/3.8] org.eclipse.emf.facet.widgets.table.tests.internal.v0_2.swtbot.NatTableUITests.testOpenLoadCustomizationDialog
+ * Gregoire Dupe (Mia-Software) - Bug 369987 - [Restructuring][Table] Switch to the new customization and facet framework
+ * Gregoire Dupe (Mia-Software) - Bug 373078 - API Cleaning
+ * Gregoire Dupe (Mia-Software) - Bug 374903 - [Table] ITableWidget.setLoadedFacetSets
+ * Gregoire Dupe (Mia-Software) - Bug 375087 - [Table] ITableWidget.addColumn(List<ETypedElement>, List<FacetSet>)
+ * Gregoire Dupe (Mia-Software) - Bug 372626 - Aggregates
+ * Gregoire Dupe (Mia-Software) - Bug 387008 - [Table] Papyrus needs methods provided by TableInstanceCommandFactory
+ * Gregoire Dupe (Mia-Software) - Bug 380293 - [Table] Columns declared in tableconfiguration are never created when we create an empty table
+ *******************************************************************************/
+package org.eclipse.papyrus.infra.table.efacet.menu.factory;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.ecore.ETypedElement;
+import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.emf.facet.efacet.core.FacetUtils;
+import org.eclipse.emf.facet.efacet.core.IFacetManager;
+import org.eclipse.emf.facet.efacet.core.IFacetManagerFactory;
+import org.eclipse.emf.facet.efacet.core.exception.FacetManagerException;
+import org.eclipse.emf.facet.efacet.core.internal.exported.IResolverManager;
+import org.eclipse.emf.facet.efacet.metamodel.v0_2_0.efacet.FacetSet;
+//import org.eclipse.emf.facet.util.core.Logger;
+import org.eclipse.emf.facet.widgets.table.metamodel.v0_2_0.table.Column;
+import org.eclipse.emf.facet.widgets.table.metamodel.v0_2_0.table.FeatureColumn;
+import org.eclipse.emf.facet.widgets.table.metamodel.v0_2_0.table.Row;
+import org.eclipse.emf.facet.widgets.table.metamodel.v0_2_0.table.Table;
+import org.eclipse.emf.facet.widgets.table.metamodel.v0_2_0.tableconfiguration.TableConfiguration;
+//import org.eclipse.emf.facet.widgets.table.ui.internal.exported.exception.UnresolvedProxyException;
+
+//FIXME : duplicted code used in the local tableinstancecommand factory -> EMF-Facet should open its API
+public final class TableInstanceUtils {
+
+ private TableInstanceUtils() {
+ // Must not be used
+ }
+
+ /**
+ * This methods the row referring a deleted or detached element.
+ *
+ * @param tableInstance
+ * @return
+ */
+ public static List<Row> findUselessRow(final Table tableInstance) {
+ final List<Row> rowsToRemove = new ArrayList<Row>();
+ for(Row row : tableInstance.getRows()) {
+ if(row.getElement() == null || row.getElement().eResource() == null) {
+ rowsToRemove.add(row);
+ }
+ }
+ return rowsToRemove;
+ }
+
+ /**
+ * This method returns the list of structural feature required to presents
+ * the chosen rows.
+ *
+ * @param table
+ * @param rowsToKeep
+ * @param nextLoadedFacets
+ * can be null.
+ * @param facetManager
+ * @return
+ */
+ public static Set<ETypedElement> getAllETypedElement(final Table table,
+ final List<Row> rowsToKeep,
+ final List<? extends FacetSet> nextLoadedFacets) {
+ final Set<ETypedElement> eTypedElements = new HashSet<ETypedElement>();
+ final IFacetManager facetManager = IFacetManagerFactory.DEFAULT
+ .getOrCreateFacetManager(new ResourceSetImpl());
+ if (nextLoadedFacets == null) {
+ facetManager.getManagedFacetSets().addAll(table.getFacetSets());
+ } else {
+ facetManager.getManagedFacetSets().addAll(nextLoadedFacets);
+ }
+ for (Row row : rowsToKeep) {
+ final EClass eClass = row.getElement().eClass();
+ eTypedElements.addAll(eClass.getEAllStructuralFeatures());
+ eTypedElements.addAll(eClass.getEAllOperations());
+ try {
+ final Set<ETypedElement> facetTEs = FacetUtils
+ .getETypedElements(row.getElement(),
+ ETypedElement.class, facetManager);
+ eTypedElements.addAll(facetTEs);
+ } catch (FacetManagerException e) {
+ //FIXME
+// Logger.logError(
+// e,
+// "An exception has occured while retrieving structural features of:" + row.getElement(), Activator.getDefault()); //$NON-NLS-1$
+ }
+ }
+ return eTypedElements;
+ }
+
+ public static List<FeatureColumn> columnsToRemove(final Table table, final List<? extends FacetSet> newFacetSets, final List<Row> rowsToKeep) {
+
+ final List<FeatureColumn> result = new LinkedList<FeatureColumn>();
+ if(rowsToKeep.isEmpty()) {
+ // If there is no rows, then there should not be any column
+ for(Column column : table.getColumns()) {
+ if(column instanceof FeatureColumn) {
+ final FeatureColumn featureColumn = (FeatureColumn)column;
+ addToListNotDefault(featureColumn, result, table);
+ }
+ }
+ } else {
+ final List<? extends ETypedElement> eTypedElements = new ArrayList<ETypedElement>(TableInstanceUtils.getAllETypedElement(table, rowsToKeep, newFacetSets));
+ for(Column column : table.getColumns()) {
+ if(column instanceof FeatureColumn) {
+ final FeatureColumn featureColumn = (FeatureColumn)column;
+ ETypedElement eTypedElement = featureColumn.getFeature();
+ eTypedElement = (ETypedElement)EcoreUtil.resolve(eTypedElement, table);
+ if(eTypedElement.eIsProxy()) {
+ throw new RuntimeException("The current structural feature should have been resolved. " + EcoreUtil.getURI(eTypedElement)); //$NON-NLS-1$
+ }
+ final ETypedElement resolvedTE = IResolverManager.DEFAULT.resolve(eTypedElement, ETypedElement.class);
+ if(resolvedTE != null) {
+ eTypedElement = resolvedTE;
+ }
+ if(!eTypedElements.contains(eTypedElement)) {
+ addToListNotDefault(featureColumn, result, table);
+ }
+ }
+ }
+ }
+ return result;
+ }
+
+ private static void addToListNotDefault(final FeatureColumn featureColumn, final List<FeatureColumn> list, final Table table) {
+ // The column declared as default in the table configuration must not be
+ // removed
+ final TableConfiguration tableConfig = table.getTableConfiguration();
+ if(tableConfig == null || !tableConfig.getDefaultColumns().contains(featureColumn.getFeature())) {
+ list.add(featureColumn);
+ }
+ }
+
+ public static boolean isColumnAlreadyDeclared(final Table table, final EStructuralFeature structuralFeature) {
+ boolean result = false;
+ for(Column column : table.getColumns()) {
+ if(column instanceof FeatureColumn) {
+ final FeatureColumn featureColumn = (FeatureColumn)column;
+ if(featureColumn.getFeature() == structuralFeature) {
+ result = true;
+ break;
+ }
+ }
+ }
+ return result;
+ }
+}
diff --git a/sandbox/org.eclipse.papyrus.infra.table.efacet.menu/src/org/eclipse/papyrus/infra/table/efacet/menu/handler/ColumnsToHideDialog.java b/sandbox/org.eclipse.papyrus.infra.table.efacet.menu/src/org/eclipse/papyrus/infra/table/efacet/menu/handler/ColumnsToHideDialog.java
new file mode 100644
index 00000000000..3105880d84a
--- /dev/null
+++ b/sandbox/org.eclipse.papyrus.infra.table.efacet.menu/src/org/eclipse/papyrus/infra/table/efacet/menu/handler/ColumnsToHideDialog.java
@@ -0,0 +1,322 @@
+/*****************************************************************************
+ * Copyright (c) 2011 CEA LIST.
+ *
+ *
+ * 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:
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ * Gregoire Dupe (Mia-Software) - Bug 341238 - We need to be able to specify which column have to be hidden/visible using the customization mechanism
+ * Vincent Lorenzo (CEA-LIST) - Bug 341238 - We need to be able to specify which column have to be hidden/visible using the customization mechanism
+ * Nicolas Bros (Mia-Software) - Bug 344247 - illegal API use in org.eclipse.emf.facet.widgets.nattable.internal.dialogs.ColumnsToHideDialog
+ * Gregoire Dupe (Mia-Software) - Bug 366804 - [Restructuring] Table widget upgrade
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.table.efacet.menu.handler;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EClassifier;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.ecore.ETypedElement;
+import org.eclipse.emf.facet.widgets.table.metamodel.v0_2_0.table.Column;
+
+//import org.eclipse.emf.facet.widgets.table.ui.internal.comparator.ColumnComparator;
+
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.viewers.CheckboxTableViewer;
+import org.eclipse.jface.viewers.CheckboxTreeViewer;
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.dialogs.SelectionDialog;
+
+public class ColumnsToHideDialog extends SelectionDialog {
+
+ // private final Object inputElement;
+ private final ILabelProvider labelProvider;
+
+ private final SortedColumnContentProvider contentProvider;
+
+ private CheckboxTreeViewer listViewer;
+
+ //
+ // private static final int DIALOG_WIDTH = 300;
+ // private static final int DIALOG_HEIGHT = 300;
+ //
+ // /** indicates if the local customization files should be set at the top */
+ // private boolean setAtTheTop;
+ //
+ // /** the initial selection */
+ // private List<Column> initialSelection;
+ //
+ // private final boolean askToPutOnTheTopTheLocalCustomization;Z
+ //
+ // private boolean mustAskTheUserNextTime;
+ //
+ // private PutOnTheTopQuestionDialog putOnTheTopQuestionDialog;
+
+ private final Collection<EObject> input;
+
+ private final Collection<ETypedElement> initialSelection;
+
+ public ColumnsToHideDialog(final Shell parentShell, final Collection<EObject> classifiers, final Collection<ETypedElement> initialSelection, final ILabelProvider labelProvider) {
+ super(parentShell);
+ setTitle("Select the columns to show");
+ this.input = classifiers;
+ this.labelProvider = labelProvider;
+ this.contentProvider = new SortedColumnContentProvider();
+ this.initialSelection = initialSelection;
+ }
+
+ // /**
+ // * Visually checks the previously-specified elements in this dialog's list
+ // * viewer.
+ // */
+ // private void checkInitialSelections() {
+ // Iterator<?> itemsToCheck = getInitialElementSelections().iterator();
+ //
+ // while(itemsToCheck.hasNext()) {
+ // this.listViewer.setChecked(itemsToCheck.next(), true);
+ // }
+ // }
+
+ @Override
+ protected void configureShell(final Shell shell) {
+ super.configureShell(shell);
+ // shell.setImage(ImageProvider.getInstance().getSelectColumnsToHide());
+ }
+
+ @Override
+ protected Control createDialogArea(final Composite parent) {
+ // page group
+ Composite composite = (Composite)super.createDialogArea(parent);
+
+ initializeDialogUnits(composite);
+
+ createMessageArea(composite);
+
+ this.listViewer = new CheckboxTreeViewer(composite, 0);
+ GridData data = new GridData(GridData.FILL_BOTH);
+ data.heightHint = 300;
+ // data.widthHint = ColumnsToHideDialog.DIALOG_WIDTH;
+ this.listViewer.getTree().setLayoutData(data);
+
+ this.listViewer.setLabelProvider(this.labelProvider);
+ this.listViewer.setContentProvider(this.contentProvider);
+
+ // addSelectionButtons(composite);
+
+ this.listViewer.setInput(input);
+ this.listViewer.setCheckedElements((this.initialSelection.toArray()));
+ this.listViewer.expandAll();
+ // initialize page
+ // if(!getInitialElementSelections().isEmpty()) {
+ // // checkInitialSelections();
+ // }
+
+ // this checkbox allows sorting the columns by name
+ // final Button cbSort = new Button(composite, SWT.CHECK);
+ // cbSort.setText("Sort Columns By Name"); //$NON-NLS-1$ // TODO should be externalized
+ // cbSort.pack();
+ // cbSort.addSelectionListener(new SelectionAdapter() {
+ //
+ // @Override
+ // public void widgetSelected(final SelectionEvent e) {
+ // ColumnsToHideDialog.this.contentProvider.setIsSorted(cbSort.getSelection());
+ // getViewer().refresh();
+ // }
+ // });
+ Dialog.applyDialogFont(composite);
+ return composite;
+
+ }
+
+ /**
+ * Returns the viewer used to show the list.
+ *
+ * @return the viewer, or <code>null</code> if not yet created
+ */
+ protected CheckboxTreeViewer getViewer() {
+ return this.listViewer;
+ }
+
+ //
+ // /** Add the selection and deselection buttons to the dialog. */
+ // private void addSelectionButtons(final Composite composite) {
+ // Composite buttonComposite = new Composite(composite, SWT.NONE);
+ // GridLayout layout = new GridLayout();
+ // layout.numColumns = 0;
+ // layout.marginWidth = 0;
+ // layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
+ // buttonComposite.setLayout(layout);
+ // buttonComposite.setLayoutData(new GridData(SWT.END, SWT.TOP, true, false));
+ //
+ // Button selectButton = createButton(buttonComposite, IDialogConstants.SELECT_ALL_ID, "&Select All", false); //$NON-NLS-1$ // TODO should be externalized
+ //
+ // SelectionListener listener = new SelectionAdapter() {
+ //
+ // @Override
+ // public void widgetSelected(final SelectionEvent e) {
+ // selectAll();
+ // }
+ // };
+ // selectButton.addSelectionListener(listener);
+ //
+ // Button deselectButton = createButton(buttonComposite, IDialogConstants.DESELECT_ALL_ID, "&Deselect All", false); //$NON-NLS-1$ // TODO should be externalized
+ //
+ // listener = new SelectionAdapter() {
+ //
+ // @Override
+ // public void widgetSelected(final SelectionEvent e) {
+ // deselectAll();
+ // }
+ // };
+ // deselectButton.addSelectionListener(listener);
+ // }
+
+ /**
+ *
+ * @see org.eclipse.jface.window.Window#open()
+ *
+ * @return
+ */
+ @Override
+ public int open() {
+ // if(this.askToPutOnTheTopTheLocalCustomization) {
+ // this.putOnTheTopQuestionDialog = openPutOnTheTopQuestionDialog();
+ // }
+ // this.initialSelection = getVisibleColumns(this.setAtTheTop);
+ // setInitialElementSelections(this.initialSelection);
+ return super.open();
+ }
+
+ // /**
+ // *
+ // * @return <ul>
+ // * <li>IDialogConstants.NO_ID</li>
+ // * <li>IDialogConstants.YES_ID</li>
+ // * <li><code>-1<code> in other cases</li>
+ // * </ul>
+ // */
+ // private PutOnTheTopQuestionDialog openPutOnTheTopQuestionDialog() {
+ // String message = TableWidgetPreferencePage.DISPLAYED_MESSAGE_1 + " " + TableWidgetPreferencePage.DISPLAYED_MESSAGE_2 + "\n\n" + TableWidgetPreferencePage.DISPLAYED_QUESTION; //$NON-NLS-1$//$NON-NLS-2$
+ // String toggleMessage = TableWidgetPreferencePage.DONT_DISPLAY_NEXT_TIME;
+ // final PutOnTheTopQuestionDialog dialog = new PutOnTheTopQuestionDialog(getShell(), Messages.NatTableWidget_selectColumnToShowHide, ImageProvider.getInstance().getSelectColumnsToHide(), message, MessageDialog.WARNING, new String[]{ IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 0, toggleMessage, false) {
+ //
+ // @Override
+ // public boolean close() {
+ // ColumnsToHideDialog.this.setAtTheTop = isPutOnTheTop();
+ // ColumnsToHideDialog.this.mustAskTheUserNextTime = this.isAskTheUserNextTime();
+ // return super.close();
+ // }
+ // };
+ // Display.getDefault().asyncExec(new Runnable() {
+ //
+ // public void run() {
+ // dialog.open();
+ // }
+ // });
+ // return dialog;
+ // }
+
+ // public boolean isPutOnTheTop() {
+ // return this.setAtTheTop;
+ // }
+
+ // /**
+ // *
+ // * @see org.eclipse.emf.facet.widgets.nattable.internal.IColumnsToHideDialog#getInitialSelection()
+ // *
+ // * @return the initial selection
+ // */
+ // public List<Column> getInitialSelection() {
+ // return this.initialSelection;
+ // }
+ //
+ // public IPutOnTheTopQuestionDialog isPutOnTheTopQuestionDialog() {
+ // return this.putOnTheTopQuestionDialog;
+ // }
+
+ public void pressOk() {
+ okPressed();
+ }
+
+ // public abstract List<Column> getVisibleColumns(boolean putOnTheTop);
+
+ public List<Column> getSelectedColumns() {
+ List<Column> resultList = new ArrayList<Column>();
+ for(Object result : getResult()) {
+ if(result instanceof Column) {
+ Column column = (Column)result;
+ resultList.add(column);
+ }
+ }
+ return resultList;
+ }
+
+ // public boolean isMustAskTheUserNextTime() {
+ // return this.mustAskTheUserNextTime;
+ // }
+
+ public void selectAll() {
+ getViewer().setAllChecked(true);
+ }
+
+ public void deselectAll() {
+ getViewer().setAllChecked(false);
+ }
+
+ /**
+ * The <code>ListSelectionDialog</code> implementation of this <code>Dialog</code> method builds a list of the selected elements for
+ * later retrieval by the client and closes this dialog.
+ */
+ @Override
+ protected void okPressed() {
+ setResult(Arrays.asList(this.listViewer.getCheckedElements()));
+ // // Get the input children.
+ // Object[] children = this.contentProvider.getElements(this.inputElement);
+ //
+ // // Build a list of selected children.
+ // if(children != null) {
+ // ArrayList<Object> list = new ArrayList<Object>();
+ // for(int i = 0; i < children.length; ++i) {
+ // Object element = children[i];
+ // if(this.listViewer.getChecked(element)) {
+ // list.add(element);
+ // }
+ // }
+ // setResult(list);
+ // }
+
+ super.okPressed();
+ }
+
+ // public IPutOnTheTopQuestionDialog getPutOnTheTopQuestionDialog() {
+ // return this.putOnTheTopQuestionDialog;
+ // }
+}
diff --git a/sandbox/org.eclipse.papyrus.infra.table.efacet.menu/src/org/eclipse/papyrus/infra/table/efacet/menu/handler/FacetFactory.java b/sandbox/org.eclipse.papyrus.infra.table.efacet.menu/src/org/eclipse/papyrus/infra/table/efacet/menu/handler/FacetFactory.java
new file mode 100644
index 00000000000..31224c33ba4
--- /dev/null
+++ b/sandbox/org.eclipse.papyrus.infra.table.efacet.menu/src/org/eclipse/papyrus/infra/table/efacet/menu/handler/FacetFactory.java
@@ -0,0 +1,271 @@
+package org.eclipse.papyrus.infra.table.efacet.menu.handler;
+
+import java.io.ObjectInputStream.GetField;
+
+import org.eclipse.emf.ecore.EAnnotation;
+import org.eclipse.emf.ecore.EAttribute;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EClassifier;
+import org.eclipse.emf.ecore.EcorePackage;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.facet.efacet.core.IFacetSetCatalogManager;
+import org.eclipse.emf.facet.efacet.core.IFacetSetCatalogManagerFactory;
+import org.eclipse.emf.facet.efacet.core.exception.FacetManagerException;
+import org.eclipse.emf.facet.efacet.metamodel.v0_2_0.efacet.EFacetFactory;
+import org.eclipse.emf.facet.efacet.metamodel.v0_2_0.efacet.Facet;
+import org.eclipse.emf.facet.efacet.metamodel.v0_2_0.efacet.FacetAttribute;
+import org.eclipse.emf.facet.efacet.metamodel.v0_2_0.efacet.FacetOperation;
+import org.eclipse.emf.facet.efacet.metamodel.v0_2_0.efacet.FacetReference;
+import org.eclipse.emf.facet.efacet.metamodel.v0_2_0.efacet.FacetSet;
+import org.eclipse.emf.facet.efacet.metamodel.v0_2_0.efacet.extensible.Query;
+import org.eclipse.emf.facet.efacet.metamodel.v0_2_0.efacet.query.EObjectLiteralQuery;
+import org.eclipse.emf.facet.efacet.metamodel.v0_2_0.efacet.query.OperationCallQuery;
+import org.eclipse.emf.facet.efacet.metamodel.v0_2_0.efacet.query.QueryFactory;
+import org.eclipse.emf.facet.efacet.metamodel.v0_2_0.efacet.query.StringLiteralQuery;
+import org.eclipse.emf.facet.efacet.metamodel.v0_2_0.efacetcatalog.EfacetcatalogFactory;
+import org.eclipse.uml2.uml.PrimitiveType;
+import org.eclipse.uml2.uml.Property;
+import org.eclipse.uml2.uml.Stereotype;
+import org.eclipse.uml2.uml.Type;
+import org.eclipse.uml2.uml.UMLPackage;
+import org.eclipse.emf.facet.efacet.core.*;
+
+public class FacetFactory {
+
+
+ private FacetFactory() {
+ //to prevent instanciation
+ }
+
+ public static final FacetSet createFacetSet(final String name, final String nsPrefix, final String nsURI, final String documentation) {
+ FacetSet set = EFacetFactory.eINSTANCE.createFacetSet();
+ set.setName(name);
+ set.setNsPrefix(nsPrefix);
+ set.setNsURI(nsURI);
+ set.setDocumentation(documentation);
+ return set;
+ }
+
+ public static final Facet createFacet(final Stereotype stereotype) {
+ Facet facet = EFacetFactory.eINSTANCE.createFacet();
+ facet.setName(stereotype.getName());
+ facet.setDocumentation("This facet represents the eClass " + stereotype.getName());
+ // facet.setConformanceTypedElement(value);//TODO
+ facet.setExtendedMetaclass(UMLPackage.eINSTANCE.getElement());//TODO
+ for(final Property attribute : stereotype.getOwnedAttributes()) {
+ FacetAttribute facetAttr = createFacetAttribute2(attribute, stereotype);
+ facet.getFacetElements().add(facetAttr);
+ }
+
+ //We create the query to get the reprensentedStereotype
+ FacetOperation operation = EFacetFactory.eINSTANCE.createFacetOperation();
+ operation.setLowerBound(1);
+ operation.setUpperBound(1);
+ operation.setDocumentation("Returns the qualified name of the represented stereotype");
+ operation.setName("getStereotypeQualifiedName");
+ // operation.setEType(); //string
+ StringLiteralQuery query = QueryFactory.eINSTANCE.createStringLiteralQuery();
+ query.setValue(stereotype.getQualifiedName());
+ operation.setQuery(query);
+ return facet;
+ }
+
+ private static FacetOperation singleStringValueOperation;
+ private static FacetOperation singleStringValueOperation2;
+
+ private static FacetOperation multiStringValueOperation;
+
+ private static FacetOperation singlePrimitiveTypeValueOperation;
+
+ private static FacetOperation multiPrimitiveTypeValueOperation;
+
+ private static Facet stereotypedElementFacet;
+
+
+
+ private static final Facet getStereotypedElementFacet(final ResourceSet resourceSet) {
+ if(stereotypedElementFacet == null) {
+ IFacetSetCatalogManager manager = IFacetSetCatalogManagerFactory.DEFAULT.getOrCreateFacetSetCatalogManager(resourceSet);
+ for(FacetSet set : manager.getRegisteredFacetSets()) {
+ if("org.eclipse.papyrus.uml.efacet/0.9/UML_stereotype".equals(set.getNsURI())) {
+ stereotypedElementFacet = (Facet)set.getEClassifier("stereotyped_element");
+ break;
+ }
+ }
+ }
+ return stereotypedElementFacet;
+ }
+
+ private static FacetOperation getMultiPrimitiveTypeValueOperation(final ResourceSet resourceSet) {
+ if(singleStringValueOperation == null) {
+ final Facet stereotypedElementFacet = getStereotypedElementFacet(resourceSet);
+ if(stereotypedElementFacet != null)
+ for(final FacetOperation op : stereotypedElementFacet.getFacetOperations()) {
+ if("getMultiPrimitiveTypeValue".equals(op.getName())) {
+ multiPrimitiveTypeValueOperation = op;
+ break;
+ }
+ }
+ }
+ return multiPrimitiveTypeValueOperation;
+ }
+
+ private static FacetOperation getSinglePrimitiveTypeValueOperation(final ResourceSet resourceSet) {
+ if(singleStringValueOperation == null) {
+ final Facet stereotypedElementFacet = getStereotypedElementFacet(resourceSet);
+ if(stereotypedElementFacet != null)
+ for(final FacetOperation op : stereotypedElementFacet.getFacetOperations()) {
+ if("getSinglePrimitiveTypeValue".equals(op.getName())) {
+ singlePrimitiveTypeValueOperation = op;
+ break;
+ }
+ }
+ }
+ return singlePrimitiveTypeValueOperation;
+ }
+
+ private static FacetOperation getSingleStringValueOperation(final ResourceSet resourceSet) {
+ if(singleStringValueOperation == null) {
+ final Facet stereotypedElementFacet = getStereotypedElementFacet(resourceSet);
+ if(stereotypedElementFacet != null)
+ for(final FacetOperation op : stereotypedElementFacet.getFacetOperations()) {
+ if("getSingleStringValue".equals(op.getName())) {
+ singleStringValueOperation = op;
+ break;
+ }
+ }
+ }
+ return singleStringValueOperation;
+ }
+
+ private static FacetOperation getSingleStringValueOperation2(final ResourceSet resourceSet) {
+ if(singleStringValueOperation2 == null) {
+ final Facet stereotypedElementFacet = getStereotypedElementFacet(resourceSet);
+ if(stereotypedElementFacet != null)
+ for(final FacetOperation op : stereotypedElementFacet.getFacetOperations()) {
+ if("getSingleStringValue2".equals(op.getName())) {
+ singleStringValueOperation2 = op;
+ break;
+ }
+ }
+ }
+ return singleStringValueOperation2;
+ }
+
+ //the first version with the qualifiedName
+ public static final FacetAttribute createFacetAttribute(Property attribute2, final Stereotype ste) {
+ FacetAttribute facetAttribute = EFacetFactory.eINSTANCE.createFacetAttribute();
+ facetAttribute.setName(attribute2.getName());
+ facetAttribute.setDocumentation("This Facet Attribute represents the stereotype property " + attribute2.getQualifiedName());
+ facetAttribute.setChangeable(!attribute2.isDerived());
+ facetAttribute.setDerived(true);
+ Type type = attribute2.getType();
+ EClassifier eType = null;
+ OperationCallQuery query;
+ FacetOperation facetOperationCalled = null;
+ int upperBound = facetAttribute.getUpperBound();
+ if(type instanceof PrimitiveType) {
+ PrimitiveType pType = (PrimitiveType)type;
+ final String name = pType.getName();
+ if("EString".equals(name)) {
+ eType = EcorePackage.eINSTANCE.getEString();
+ if(upperBound > 1) {
+ //TODO
+ } else {
+ facetOperationCalled = getSingleStringValueOperation(attribute2.eResource().getResourceSet());
+ }
+ } else if("EBoolean".equals(name)) {
+ eType = EcorePackage.eINSTANCE.getEBoolean();
+ } else if("EInt".equals(name)) {
+ eType = EcorePackage.eINSTANCE.getEInt();
+ }
+ //else TODO to finish
+
+
+
+
+
+ //we prepare the arguments
+ query = QueryFactory.eINSTANCE.createOperationCallQuery();
+ query.setCanHaveSideEffects(false);
+
+ StringLiteralQuery qualifiedNameQuery = QueryFactory.eINSTANCE.createStringLiteralQuery();
+ qualifiedNameQuery.setValue(ste.getQualifiedName());
+ query.getArguments().add(qualifiedNameQuery);
+
+ StringLiteralQuery propertyNameQuery = QueryFactory.eINSTANCE.createStringLiteralQuery();
+ propertyNameQuery.setValue(attribute2.getName());
+ query.getArguments().add(propertyNameQuery);
+ facetAttribute.setQuery(query);
+
+ query.setOperation(facetOperationCalled);
+
+ }
+ facetAttribute.setEType(eType);//TODO
+ // attribute.setQuery(query);////TODO
+ facetAttribute.setLowerBound(attribute2.getLower());
+ facetAttribute.setUpperBound(attribute2.getUpper());
+ return facetAttribute;
+ }
+
+ //the second version with references to property and stereitype
+ public static final FacetAttribute createFacetAttribute2(Property attribute2, final Stereotype ste) {
+ FacetAttribute facetAttribute = EFacetFactory.eINSTANCE.createFacetAttribute();
+ facetAttribute.setName(attribute2.getName());
+ facetAttribute.setDocumentation("This Facet Attribute represents the stereotype property " + attribute2.getQualifiedName());
+ facetAttribute.setChangeable(!attribute2.isDerived());
+ facetAttribute.setDerived(true);
+ Type type = attribute2.getType();
+ EClassifier eType = null;
+ OperationCallQuery query;
+ FacetOperation facetOperationCalled = null;
+ int upperBound = facetAttribute.getUpperBound();
+ if(type instanceof PrimitiveType) {
+ PrimitiveType pType = (PrimitiveType)type;
+ final String name = pType.getName();
+ if("EString".equals(name) || "String".equals(name)) {
+ eType = EcorePackage.eINSTANCE.getEString();
+ if(upperBound > 1) {
+ //TODO
+ } else {
+ facetOperationCalled = getSingleStringValueOperation2(attribute2.eResource().getResourceSet());
+ }
+ } else if("EBoolean".equals(name)) {
+ eType = EcorePackage.eINSTANCE.getEBoolean();
+ } else if("EInt".equals(name)) {
+ eType = EcorePackage.eINSTANCE.getEInt();
+ }
+ //else TODO to finish
+
+
+
+
+
+ //we prepare the arguments
+ query = QueryFactory.eINSTANCE.createOperationCallQuery();
+ query.setCanHaveSideEffects(false);
+
+ EObjectLiteralQuery qualifiedNameQuery = QueryFactory.eINSTANCE.createEObjectLiteralQuery();
+ qualifiedNameQuery.setElement(ste);
+ query.getArguments().add(qualifiedNameQuery);
+
+ EObjectLiteralQuery propertyNameQuery = QueryFactory.eINSTANCE.createEObjectLiteralQuery();
+ propertyNameQuery.setElement(attribute2);
+ query.getArguments().add(propertyNameQuery);
+ facetAttribute.setQuery(query);
+
+ query.setOperation(facetOperationCalled);
+
+ }
+ facetAttribute.setEType(eType);//TODO
+ // attribute.setQuery(query);////TODO
+ facetAttribute.setLowerBound(attribute2.getLower());
+ facetAttribute.setUpperBound(attribute2.getUpper());
+ return facetAttribute;
+ }
+
+ public static final FacetReference createFacetReference() {
+ FacetReference reference = EFacetFactory.eINSTANCE.createFacetReference();
+ return reference;
+ }
+}
diff --git a/sandbox/org.eclipse.papyrus.infra.table.efacet.menu/src/org/eclipse/papyrus/infra/table/efacet/menu/handler/SelectColumnsHandler.java b/sandbox/org.eclipse.papyrus.infra.table.efacet.menu/src/org/eclipse/papyrus/infra/table/efacet/menu/handler/SelectColumnsHandler.java
new file mode 100644
index 00000000000..d394e4e4138
--- /dev/null
+++ b/sandbox/org.eclipse.papyrus.infra.table.efacet.menu/src/org/eclipse/papyrus/infra/table/efacet/menu/handler/SelectColumnsHandler.java
@@ -0,0 +1,399 @@
+package org.eclipse.papyrus.infra.table.efacet.menu.handler;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.SortedSet;
+import java.util.TreeMap;
+import java.util.TreeSet;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.mapping.ModelStatus;
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.common.command.CompoundCommand;
+import org.eclipse.emf.common.notify.AdapterFactory;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EAttribute;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EClassifier;
+import org.eclipse.emf.ecore.ENamedElement;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EOperation;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.ecore.ETypedElement;
+import org.eclipse.emf.ecore.EcoreFactory;
+import org.eclipse.emf.ecore.EcorePackage;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.emf.edit.command.SetCommand;
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.emf.edit.provider.ComposedAdapterFactory;
+import org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider;
+import org.eclipse.emf.facet.efacet.core.IFacetManager;
+import org.eclipse.emf.facet.efacet.core.IFacetManagerFactory;
+import org.eclipse.emf.facet.efacet.core.IFacetSetCatalogManagerFactory;
+import org.eclipse.emf.facet.efacet.metamodel.v0_2_0.efacet.EFacetFactory;
+import org.eclipse.emf.facet.efacet.metamodel.v0_2_0.efacet.Facet;
+import org.eclipse.emf.facet.efacet.metamodel.v0_2_0.efacet.FacetAttribute;
+import org.eclipse.emf.facet.efacet.metamodel.v0_2_0.efacet.FacetElement;
+import org.eclipse.emf.facet.efacet.metamodel.v0_2_0.efacet.FacetOperation;
+import org.eclipse.emf.facet.efacet.metamodel.v0_2_0.efacet.FacetSet;
+import org.eclipse.emf.facet.efacet.metamodel.v0_2_0.efacet.query.EObjectLiteralQuery;
+import org.eclipse.emf.facet.efacet.metamodel.v0_2_0.efacet.query.OperationCallQuery;
+import org.eclipse.emf.facet.efacet.metamodel.v0_2_0.efacet.query.QueryFactory;
+import org.eclipse.emf.facet.efacet.metamodel.v0_2_0.efacet.query.StringLiteralQuery;
+import org.eclipse.emf.facet.widgets.celleditors.ICommandFactoriesRegistry;
+import org.eclipse.emf.facet.widgets.celleditors.ICommandFactory;
+import org.eclipse.emf.facet.widgets.table.metamodel.v0_2_0.table.Column;
+import org.eclipse.emf.facet.widgets.table.metamodel.v0_2_0.table.FeatureColumn;
+import org.eclipse.emf.facet.widgets.table.metamodel.v0_2_0.table.Table;
+import org.eclipse.emf.facet.widgets.table.ui.command.ITableCommandFactory;
+import org.eclipse.emf.facet.widgets.table.ui.command.ITableCommandFactoryFactory;
+import org.eclipse.emf.facet.widgets.table.ui.internal.exported.ITableWidget;
+import org.eclipse.emf.facet.widgets.table.ui.internal.exported.ITableWidgetInternal;
+import org.eclipse.emf.facet.widgets.table.ui.internal.exported.ITableWidgetProvider;
+import org.eclipse.emf.transaction.Transaction;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.emf.transaction.util.TransactionUtil;
+import org.eclipse.gmf.runtime.common.core.command.CommandResult;
+import org.eclipse.gmf.runtime.common.core.command.ICommand;
+import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
+import org.eclipse.jface.viewers.CheckboxTreeViewer;
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.viewers.ILabelProviderListener;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.jface.window.Window;
+import org.eclipse.papyrus.commands.wrappers.GMFtoEMFCommandWrapper;
+import org.eclipse.papyrus.infra.core.editor.CoreMultiDiagramEditor;
+import org.eclipse.papyrus.infra.core.resource.ModelSet;
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
+import org.eclipse.papyrus.infra.core.utils.ServiceUtils;
+import org.eclipse.papyrus.infra.core.utils.ServiceUtilsForActionHandlers;
+import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForResource;
+import org.eclipse.papyrus.infra.table.efacet.common.editor.AbstractTableEditor;
+import org.eclipse.papyrus.infra.table.efacet.menu.Activator;
+import org.eclipse.papyrus.infra.table.efacet.menu.factory.TableInstanceCommandFactory;
+import org.eclipse.papyrus.infra.table.efacet.metamodel.papyrustable.PapyrusTable;
+import org.eclipse.papyrus.infra.table.efacet.metamodel.papyrustable.TableContentsUtils;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.part.EditorPart;
+import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.Stereotype;
+import org.eclipse.uml2.uml.util.UMLUtil;
+
+
+//FIXME : uml dependency
+public class SelectColumnsHandler extends AbstractHandler {
+
+
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ final CompoundCommand compoundCmd = new CompoundCommand("Papyrus Show/Hide columns");
+ final PapyrusTable papyrusTable = getPapyrusTable();
+ final ITableWidget widget = getTableWidget();
+ TransactionalEditingDomain domain = getEditingDomain();
+ ICommand addFacetSetToResourceCommand = null;
+ if(papyrusTable != null && widget != null) {
+ //the contents of the table
+ final List<EObject> contents = TableContentsUtils.getTableContents(papyrusTable, papyrusTable.getTable().getContext(), false);
+
+ //all stereotypes used in the table
+ final Set<Stereotype> stereotypes = new HashSet<Stereotype>();
+
+ //all stereotypes identified by their qualified name
+ final Map<String, Stereotype> mapName_stereotypes = new HashMap<String, Stereotype>();
+
+ //all facets applied on the table + all applicable facets representing stereotypes
+ final Set<Facet> allFacets = new TreeSet<Facet>(new EcoreFeatureComparator());
+
+ final SortedSet<ETypedElement> allFeatures = new TreeSet<ETypedElement>(new EcoreFeatureComparator());
+ final Map<ETypedElement, Column> columnsFeatureMap = new HashMap<ETypedElement, Column>();
+ final Map<EClass, Stereotype> eClassSteMap = new TreeMap<EClass, Stereotype>(new EcoreFeatureComparator());
+
+
+ //1. Get all direct features and store all used stereotypes
+ for(EObject current : contents) {
+ allFeatures.addAll(current.eClass().getEAllStructuralFeatures());
+ if(current instanceof Element) {
+ stereotypes.addAll(((Element)current).getAppliedStereotypes());
+ }
+ }
+
+ //1. bis
+ // - complete the list of features with the features of the columns
+ // - map the columns with the features
+ for(final Column current : papyrusTable.getTable().getColumns()) {
+ if(current instanceof FeatureColumn) {
+ final FeatureColumn col = (FeatureColumn)current;
+ final ETypedElement feature = col.getFeature();
+ columnsFeatureMap.put(feature, col);
+ if(feature instanceof FacetElement) {
+ allFacets.add((Facet)feature.eContainer());
+ }
+ }
+ }
+
+ //2. look for an existing facetSet representing the stereotype
+ final String facetSetName = "localFacetSet";
+ final String facetSetURI = "http://www.eclipse.org/papyrustableefacet/localfacetset";
+ FacetSet localSet = null;
+ EcoreUtil.resolveAll(papyrusTable);
+ Resource res = papyrusTable.eResource();
+ if(res == null) {
+ if(domain == null) {
+ domain = TransactionUtil.getEditingDomain(contents.get(0));
+ }
+ try {
+ ServicesRegistry serviceRegistry = ServiceUtilsForActionHandlers.getInstance().getServiceRegistry();
+ domain = serviceRegistry.getService(TransactionalEditingDomain.class);
+ } catch (ServiceException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+
+ EList<Resource> resources = domain.getResourceSet().getResources();
+ for(Resource tmpRes : resources) {
+ URI uri = tmpRes.getURI();
+ if(uri.fileExtension().equals("notation")) {
+ int i = 0;
+ i++;
+ EList<EObject> allContents = res.getContents();
+ i++;
+ }
+ }
+ }
+ for(final EObject current : res.getContents()) {
+ if(current instanceof FacetSet && facetSetName.equals(((FacetSet)current).getName())) {
+ localSet = (FacetSet)current;
+ break;
+ }
+ }
+
+ //2. bis if the facetSet doesn't exist, we create it
+ if(localSet == null) {
+ final String documentation = "This FacetSet provides facet to edit easily the properties of the stereotypes. It had been generated by the Papyrus Show/Hide columns";
+ localSet = FacetFactory.createFacetSet("localfacetset", "localfacetset", "http://www.eclipse.org/papyrustableefacet/localfacetset", documentation);
+ final FacetSet set = localSet;
+ addFacetSetToResourceCommand = new AbstractTransactionalCommand(getEditingDomain(), "Attach local facetSet to the resource", null) {
+
+ @Override
+ protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+ papyrusTable.eResource().getContents().add(set);
+ return CommandResult.newOKCommandResult();
+ }
+ };
+ }
+
+ //3. we associate each stereotype to its qualified name
+ for(final Stereotype ste : stereotypes) {
+ mapName_stereotypes.put(ste.getQualifiedName(), ste);
+ }
+
+ //4. we map the stereotype with the existing Facet //TODO currently, we assume that the stereotype has not changed
+ List<Stereotype> unmappedStereotype = new ArrayList<Stereotype>(stereotypes);
+ for(final EClassifier currentFacet : localSet.getEClassifiers()) {
+ if(currentFacet instanceof Facet) {
+ for(final FacetOperation op : ((Facet)currentFacet).getFacetOperations()) {
+ if("getStereotypeQualifiedName".equals(op.getName())) {
+ final String qName = ((StringLiteralQuery)op.getQuery()).getValue();
+ unmappedStereotype.remove(mapName_stereotypes.get(qName));
+ break;
+ }
+ }
+ }
+ }
+
+ final List<Facet> createdEFacet = new ArrayList<Facet>();
+
+ //5. we create the Facet for the unmapped stereotypes
+ for(final Stereotype ste : unmappedStereotype) {
+ Facet facet = FacetFactory.createFacet(ste);
+ createdEFacet.add(facet);
+ }
+ allFacets.addAll(createdEFacet);
+
+ //6. we create the input
+ final Collection<EObject> dialogInput = new ArrayList<EObject>();
+ dialogInput.addAll(allFeatures);
+ dialogInput.addAll(allFacets);
+
+ //7. we build the initial selection
+ final Collection<ETypedElement> initialSelection = new ArrayList<ETypedElement>(columnsFeatureMap.keySet());
+
+ ColumnsToHideDialog dialog = new ColumnsToHideDialog(Display.getCurrent().getActiveShell(), dialogInput, initialSelection, getLabelProvider());
+ if(dialog.open() == Window.OK) {
+ final Object[] result = dialog.getResult();
+ final List<Object> resultAsList = Arrays.asList(result);
+
+ final List<Object> columnsToAdd = new ArrayList<Object>(resultAsList);
+ columnsToAdd.removeAll(initialSelection);
+ //these columns should be set To Visible OR created
+
+ List<Column> columnsToShow = new ArrayList<Column>();
+ List<ETypedElement> columnsToCreate = new ArrayList<ETypedElement>();
+ for(final Object currentColumn : columnsToAdd) {
+ if(columnsFeatureMap.containsKey(currentColumn)) {
+ columnsToShow.add(columnsFeatureMap.get(currentColumn));
+ } else {
+ columnsToCreate.add((ETypedElement)currentColumn);
+ }
+ }
+
+ List<Object> featureToHide = new ArrayList<Object>(initialSelection);
+ featureToHide.removeAll(resultAsList);
+
+
+ //these columns should be hidden
+ List<Column> columnsToHide = new ArrayList<Column>();
+ for(final Object current : featureToHide) {
+ Column toHide = columnsFeatureMap.get(current);
+ if(toHide != null) {
+ columnsToHide.add(toHide);
+ }
+ }
+
+ ITableWidgetInternal widgetController = (ITableWidgetInternal)widget;
+ ICommandFactory commandFactory = ICommandFactoriesRegistry.INSTANCE.getCommandFactoryFor(domain);
+ boolean putOnTheTop = false;
+
+ final Command showHideCommand = TableInstanceCommandFactory.createShowHideColumnCommand(widgetController, domain, commandFactory, papyrusTable.getTable(), columnsToShow, columnsToHide, putOnTheTop);
+ if(showHideCommand != null && showHideCommand.canExecute()) {
+ compoundCmd.append(showHideCommand);
+ }
+ if(addFacetSetToResourceCommand != null) { //TODO : test if the current selection need to it!
+ compoundCmd.append(new GMFtoEMFCommandWrapper(addFacetSetToResourceCommand));
+ }
+
+ //TODO : complete with the removeFacetSetFromResource command or remove Facet from facetSet command
+
+ if(!createdEFacet.isEmpty()) {
+ final FacetSet set = localSet;
+ ICommand cmd = new AbstractTransactionalCommand(getEditingDomain(), "Add Facet to the local facetSet", null) {
+
+ @Override
+ protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+ set.getEClassifiers().addAll(createdEFacet);
+ return CommandResult.newOKCommandResult();
+ }
+ };
+ compoundCmd.append(new GMFtoEMFCommandWrapper(cmd));
+ }
+
+
+ domain.getCommandStack().execute(compoundCmd);
+ IFacetSetCatalogManagerFactory.DEFAULT.getOrCreateFacetSetCatalogManager(res.getResourceSet()).registerFacetSet(localSet);
+ List<FacetSet> facetSetToAdd = new ArrayList<FacetSet>();
+ facetSetToAdd.add(localSet);
+
+ widget.addColumns(columnsToCreate, facetSetToAdd);//TODO should be chained with the previous command
+ }
+ }
+
+ return null;
+ }
+
+ protected Command getBuildedCommand() {
+ CompoundCommand compoundCommand = new CompoundCommand();
+
+ return compoundCommand;
+ }
+
+ protected Command getShowHideExistingColumnCommand() {
+ CompoundCommand compoundCommand = new CompoundCommand();
+
+ return compoundCommand;
+ }
+
+ protected Command getAddAndCreateNewColumnsCommand() {
+ CompoundCommand compoundCommand = new CompoundCommand();
+
+ return compoundCommand;
+ }
+
+
+ public class EcoreFeatureComparator implements Comparator<ENamedElement> {
+
+ public int compare(ENamedElement o1, ENamedElement o2) {
+ return o1.getName().compareToIgnoreCase(o2.getName());
+ }
+
+ }
+
+ public class StereotypeNameComparator implements Comparator<Stereotype> {//TODO rename into NamedElement Comparator
+
+ public int compare(Stereotype o1, Stereotype o2) {
+ return o1.getName().compareToIgnoreCase(o2.getName());
+ }
+
+ }
+
+ private TransactionalEditingDomain getEditingDomain() {
+ TransactionalEditingDomain domain = null;
+ domain = TransactionUtil.getEditingDomain(getPapyrusTable());
+ return domain;
+ }
+
+ private AbstractTableEditor getCurrentTableEditor() {
+
+ final IStructuredSelection selection = (IStructuredSelection)PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService().getSelection();
+ final Object current = selection.getFirstElement();
+ if(current instanceof EObject) {
+
+ IEditorPart part = null;
+ try {
+ part = ServiceUtilsForResource.getInstance().getNestedActiveIEditorPart(((EObject)current).eResource());
+ } catch (ServiceException e) {
+ Activator.log.error(e);
+ }
+ if(part instanceof AbstractTableEditor) {
+ return (AbstractTableEditor)part;
+ }
+
+ }
+ return null;
+ }
+
+ private PapyrusTable getPapyrusTable() {
+ IEditorPart part = getCurrentTableEditor();
+ if(part != null) {
+ return (PapyrusTable)part.getAdapter(PapyrusTable.class);
+ }
+ return null;
+ }
+
+ private ITableWidget getTableWidget() {
+ IAdaptable editor = getCurrentTableEditor();
+ final ITableWidgetProvider provider = (ITableWidgetProvider)editor.getAdapter(ITableWidgetProvider.class);
+ if(provider != null) {
+ return provider.getTableWidget();
+ }
+ return null;
+ }
+
+ private ILabelProvider getLabelProvider() {
+ AdapterFactory factory = new ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE);
+ final ILabelProvider labelProvider = new AdapterFactoryLabelProvider(factory);
+ return labelProvider;
+ }
+}
diff --git a/sandbox/org.eclipse.papyrus.infra.table.efacet.menu/src/org/eclipse/papyrus/infra/table/efacet/menu/handler/SortedColumnContentProvider.java b/sandbox/org.eclipse.papyrus.infra.table.efacet.menu/src/org/eclipse/papyrus/infra/table/efacet/menu/handler/SortedColumnContentProvider.java
new file mode 100644
index 00000000000..35b8bf75ddc
--- /dev/null
+++ b/sandbox/org.eclipse.papyrus.infra.table.efacet.menu/src/org/eclipse/papyrus/infra/table/efacet/menu/handler/SortedColumnContentProvider.java
@@ -0,0 +1,150 @@
+/*****************************************************************************
+ * Copyright (c) 2011 CEA LIST.
+ *
+ *
+ * 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:
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ * Vincent Lorenzo (CEA-LIST) - bug 337326 - Show/Hide Column : Sort the columns by name
+ * Gregoire Dupe (Mia-Software) - Bug 366804 - [Restructuring] Table widget upgrade
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.table.efacet.menu.handler;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.facet.efacet.metamodel.v0_2_0.efacet.Facet;
+import org.eclipse.emf.facet.efacet.metamodel.v0_2_0.efacet.FacetElement;
+import org.eclipse.emf.facet.widgets.table.metamodel.v0_2_0.table.Column;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.Feature;
+import org.eclipse.uml2.uml.Stereotype;
+import org.eclipse.uml2.uml.internal.impl.StereotypeImpl;
+
+/**
+ * A Content Provider which allows to sort the provided elements
+ *
+ *
+ *
+ */
+public class SortedColumnContentProvider implements ITreeContentProvider {
+
+ /** boolean to know if the returned content should be sorted or not */
+ private boolean isSorted = true;
+
+ /** the initial content */
+ private List<Column> initialList = new ArrayList<Column>();
+
+ /** the comparator used to sort the element */
+ private Comparator<Column> comparator = null;
+
+ public void inputChanged(final Viewer viewer, final Object oldInput, final Object newInput) {
+ if(newInput instanceof List) {
+ for(Object object : (List<?>)newInput) {
+ if(object instanceof Column) {
+ Column column = (Column)object;
+ this.initialList.add(column);
+ }
+ }
+ }
+ }
+
+ public void dispose() {
+ // Nothing
+ }
+
+ public Object[] getElements(final Object inputElement) {
+ if(inputElement instanceof Map<?, ?>) {//should be deleted
+ return ((Map)inputElement).keySet().toArray();
+ } else if(inputElement instanceof Collection<?>) {
+ return ((Collection)inputElement).toArray();
+ }
+ return new Object[0];
+ }
+
+ /**
+ * Setter for {@link #comparator}
+ *
+ * @param comparator
+ * the comparator used to sort the element
+ */
+ public void setComparator(final Comparator<Column> comparator) {
+ this.comparator = comparator;
+ }
+
+ /**
+ * Setter for {@link #isSorted}
+ *
+ * @param newValue
+ *
+ */
+ public void setIsSorted(final boolean newValue) {
+ this.isSorted = newValue;
+ }
+
+ public Object[] getChildren(Object parentElement) {
+ if(parentElement instanceof EClass) {
+ return ((EClass)parentElement).getEAllStructuralFeatures().toArray();
+ }
+ if(parentElement instanceof Set<?>) {
+ return ((Set)parentElement).toArray();
+ }
+ if(parentElement instanceof EStructuralFeature) {
+ return new Object[0];
+ } else if(parentElement instanceof Stereotype) {
+ EList<EStructuralFeature> allRef = ((Stereotype)parentElement).eClass().getEAllStructuralFeatures();
+ List<Feature> features = new ArrayList(((Stereotype)parentElement).allFeatures());
+ Collections.sort(features, new UMLFeatureComparator());
+ return features.toArray();
+ }
+ if(parentElement instanceof Facet){
+ return ((Facet)parentElement).getFacetElements().toArray();
+ }
+ return new Object[0];
+ }
+
+ public Object getParent(Object element) {
+ if(element instanceof Element){
+ return ((Element)element).eContainer();
+ }else if(element instanceof FacetElement){
+ return ((FacetElement)element).eContainer();
+ }
+ return null;
+ }
+
+ public boolean hasChildren(Object element) {
+ return getChildren(element).length != 0;
+ }
+
+ public class EcoreFeatureComparator implements Comparator<EStructuralFeature> {
+
+ public int compare(EStructuralFeature o1, EStructuralFeature o2) {
+ return o1.getName().compareToIgnoreCase(o2.getName());
+ }
+
+ }
+
+ public class UMLFeatureComparator implements Comparator<Feature> {
+
+ public int compare(Feature o1, Feature o2) {
+ return o1.getName().compareToIgnoreCase(o2.getName());
+ }
+
+ }
+
+}

Back to the top