Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'sandbox')
-rw-r--r--sandbox/org.eclipse.papyrus.infra.table.efacet.nestededitor/META-INF/MANIFEST.MF6
-rw-r--r--sandbox/org.eclipse.papyrus.infra.table.efacet.nestededitor/src/org/eclipse/papyrus/infra/table/efacet/nestededitor/editor/HideNewColumnsListener.java141
-rw-r--r--sandbox/org.eclipse.papyrus.infra.table.efacet.nestededitor/src/org/eclipse/papyrus/infra/table/efacet/nestededitor/editor/NestedEditorTableEditor.java29
-rw-r--r--sandbox/org.eclipse.papyrus.infra.table.efacet.nestededitor/src/org/eclipse/papyrus/infra/table/efacet/nestededitor/internal/copy/CustomizationUtils.java84
-rw-r--r--sandbox/org.eclipse.papyrus.infra.table.efacet.nestededitor/src/org/eclipse/papyrus/infra/table/efacet/nestededitor/internal/copy/TableInstanceCommandFactory.java285
5 files changed, 544 insertions, 1 deletions
diff --git a/sandbox/org.eclipse.papyrus.infra.table.efacet.nestededitor/META-INF/MANIFEST.MF b/sandbox/org.eclipse.papyrus.infra.table.efacet.nestededitor/META-INF/MANIFEST.MF
index c33edaeca9b..900d602a729 100644
--- a/sandbox/org.eclipse.papyrus.infra.table.efacet.nestededitor/META-INF/MANIFEST.MF
+++ b/sandbox/org.eclipse.papyrus.infra.table.efacet.nestededitor/META-INF/MANIFEST.MF
@@ -15,6 +15,10 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.emf.facet.util.emf.core,
org.eclipse.emf.facet.query.java.core,
org.eclipse.papyrus.infra.emf,
- org.eclipse.papyrus.infra.tools;bundle-version="0.9.0"
+ org.eclipse.papyrus.infra.tools;bundle-version="0.9.0",
+ org.eclipse.emf.transaction;bundle-version="1.4.0",
+ org.eclipse.emf.facet.custom.ui,
+ org.eclipse.emf.facet.widgets.table.ui,
+ org.eclipse.gmf.runtime.diagram.ui;bundle-version="1.6.0"
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Bundle-ActivationPolicy: lazy
diff --git a/sandbox/org.eclipse.papyrus.infra.table.efacet.nestededitor/src/org/eclipse/papyrus/infra/table/efacet/nestededitor/editor/HideNewColumnsListener.java b/sandbox/org.eclipse.papyrus.infra.table.efacet.nestededitor/src/org/eclipse/papyrus/infra/table/efacet/nestededitor/editor/HideNewColumnsListener.java
new file mode 100644
index 00000000000..3ec2e5d9a99
--- /dev/null
+++ b/sandbox/org.eclipse.papyrus.infra.table.efacet.nestededitor/src/org/eclipse/papyrus/infra/table/efacet/nestededitor/editor/HideNewColumnsListener.java
@@ -0,0 +1,141 @@
+package org.eclipse.papyrus.infra.table.efacet.nestededitor.editor;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.common.notify.Notification;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.ecore.ETypedElement;
+import org.eclipse.emf.facet.custom.metamodel.v0_2_0.custom.Customization;
+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.TableFactory;
+import org.eclipse.emf.facet.widgets.table.metamodel.v0_2_0.table.TablePackage;
+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.TransactionalEditingDomain;
+import org.eclipse.emf.validation.internal.modeled.model.validation.Feature;
+import org.eclipse.papyrus.infra.core.editor.CoreMultiDiagramEditor;
+import org.eclipse.papyrus.infra.table.efacet.common.listener.AbstractTableTriggerListener;
+import org.eclipse.papyrus.infra.table.efacet.metamodel.papyrustable.PapyrusTable;
+import org.eclipse.papyrus.infra.table.efacet.nestededitor.internal.copy.TableInstanceCommandFactory;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.PlatformUI;
+
+
+public class HideNewColumnsListener extends AbstractTableTriggerListener {
+
+ /**
+ * features already managed
+ */
+ private Set<ETypedElement> featuresAlreadyManaged = new HashSet<ETypedElement>();
+
+ public HideNewColumnsListener(final PapyrusTable table) {
+ super(table);
+ for(final Column column : table.getTable().getColumns()) {
+ if(column instanceof FeatureColumn) {
+ final ETypedElement element = ((FeatureColumn)column).getFeature();
+ if(element instanceof EStructuralFeature) {
+ featuresAlreadyManaged.add((EStructuralFeature)element);
+ }
+ }
+ }
+ }
+
+ /**
+ *
+ * @param notification
+ * a notification
+ * @return
+ * all the features of the object added in the table
+ */
+ private Set<ETypedElement> getAllFeaturesObject(final Notification notification) {
+ final Set<ETypedElement> newFeatures = new HashSet<ETypedElement>();
+ final Object newValue = notification.getNewValue();
+ if(newValue instanceof Row) {
+ Row row = (Row)newValue;
+ EObject element = row.getElement();
+ Collection<EStructuralFeature> allFeatures = element.eClass().getEAllStructuralFeatures();
+ newFeatures.addAll(allFeatures);
+ newFeatures.removeAll(featuresAlreadyManaged);
+ }
+
+ return newFeatures;
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.table.efacet.common.listener.AbstractTableTriggerListener#isManagedNotification(org.eclipse.emf.common.notify.Notification)
+ *
+ * @param notification
+ * @return
+ */
+ @Override
+ protected boolean isManagedNotification(Notification notification) {
+ if(notification.getEventType() == Notification.ADD && notification.getNotifier() == this.table.getTable() && notification.getFeature() == TableFactory.eINSTANCE.getTablePackage().getTable_Rows()) {
+ Object newValue = notification.getNewValue();
+ if(newValue != null && newValue instanceof Row) {
+ return true;//there is something to do for each new row
+ }
+ }
+ return false;
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.table.efacet.common.listener.AbstractTableTriggerListener#getCommandName(org.eclipse.emf.common.notify.Notification)
+ *
+ * @param notification
+ * @return
+ */
+ @Override
+ protected String getCommandName(Notification notification) {
+ return "Hide new columns command";
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.table.efacet.common.listener.AbstractTableTriggerListener#getSynchronizationCommand(org.eclipse.emf.transaction.TransactionalEditingDomain, org.eclipse.emf.common.notify.Notification)
+ *
+ * @param domain
+ * @param notification
+ * @return
+ */
+ @Override
+ protected Command getSynchronizationCommand(final TransactionalEditingDomain domain, final Notification notification) {
+ final Collection<ETypedElement> features = getAllFeaturesObject(notification);
+ if(!features.isEmpty()) {
+ featuresAlreadyManaged.addAll(features);
+ final ITableWidgetInternal widget = getWidget();
+ return TableInstanceCommandFactory.createHideColumnCommand(widget, domain, table.getTable(), features);
+ }
+ return null;
+ }
+
+ /**
+ * TODO EMF-Facet should provides a best way to hide columns programmatically
+ * @return
+ */
+ private ITableWidgetInternal getWidget() {
+ final IEditorPart editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
+ Assert.isTrue(editor instanceof CoreMultiDiagramEditor);
+ final IEditorPart activeEditor = ((CoreMultiDiagramEditor)editor).getActiveEditor();
+ ITableWidgetProvider provider = (ITableWidgetProvider)activeEditor.getAdapter(ITableWidgetProvider.class);
+ ITableWidget widget = provider.getTableWidget();
+ if(widget instanceof ITableWidgetInternal) {
+ return (ITableWidgetInternal)widget;
+ }
+ return null;
+ }
+
+
+}
diff --git a/sandbox/org.eclipse.papyrus.infra.table.efacet.nestededitor/src/org/eclipse/papyrus/infra/table/efacet/nestededitor/editor/NestedEditorTableEditor.java b/sandbox/org.eclipse.papyrus.infra.table.efacet.nestededitor/src/org/eclipse/papyrus/infra/table/efacet/nestededitor/editor/NestedEditorTableEditor.java
index 1044e542f44..393d9a95db6 100644
--- a/sandbox/org.eclipse.papyrus.infra.table.efacet.nestededitor/src/org/eclipse/papyrus/infra/table/efacet/nestededitor/editor/NestedEditorTableEditor.java
+++ b/sandbox/org.eclipse.papyrus.infra.table.efacet.nestededitor/src/org/eclipse/papyrus/infra/table/efacet/nestededitor/editor/NestedEditorTableEditor.java
@@ -13,6 +13,10 @@
*****************************************************************************/
package org.eclipse.papyrus.infra.table.efacet.nestededitor.editor;
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.emf.transaction.TriggerListener;
import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
import org.eclipse.papyrus.infra.table.efacet.common.editor.AbstractSynchronizedTableEditor;
import org.eclipse.papyrus.infra.table.efacet.metamodel.papyrustable.PapyrusTable;
@@ -27,6 +31,11 @@ public class NestedEditorTableEditor extends AbstractSynchronizedTableEditor {
public static final String DEFAULT_NAME = "NestedEditorTable"; //$NON-NLS-1$
/**
+ * This listener allows to hide all new columns
+ */
+ private TriggerListener hideNewColmumnsListener;
+
+ /**
* @param servicesRegistry
* @param rawModel
*
@@ -35,5 +44,25 @@ public class NestedEditorTableEditor extends AbstractSynchronizedTableEditor {
super(servicesRegistry, rawModel);
}
+ /**
+ * add listeners on the context of the table and on the table itself
+ */
+ @Override
+ protected void configureEditorEditingDomain() {
+ super.configureEditorEditingDomain();
+ final EditingDomain editingDomain = getEditingDomain();
+ Assert.isTrue(editingDomain instanceof TransactionalEditingDomain);
+
+ this.hideNewColmumnsListener = new HideNewColumnsListener(this.rawModel);
+ ((TransactionalEditingDomain)editingDomain).addResourceSetListener(this.hideNewColmumnsListener);
+
+
+ }
+
+ @Override
+ public void dispose() {
+ super.dispose();
+ ((TransactionalEditingDomain)getEditingDomain()).removeResourceSetListener(this.hideNewColmumnsListener);
+ }
}
diff --git a/sandbox/org.eclipse.papyrus.infra.table.efacet.nestededitor/src/org/eclipse/papyrus/infra/table/efacet/nestededitor/internal/copy/CustomizationUtils.java b/sandbox/org.eclipse.papyrus.infra.table.efacet.nestededitor/src/org/eclipse/papyrus/infra/table/efacet/nestededitor/internal/copy/CustomizationUtils.java
new file mode 100644
index 00000000000..9d88cfbf75c
--- /dev/null
+++ b/sandbox/org.eclipse.papyrus.infra.table.efacet.nestededitor/src/org/eclipse/papyrus/infra/table/efacet/nestededitor/internal/copy/CustomizationUtils.java
@@ -0,0 +1,84 @@
+/*******************************************************************************
+ * Copyright (c) 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:
+ * 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 376576 - [EFacet] Change the multiplicity of Facet::extendedFacet
+ *******************************************************************************/
+package org.eclipse.papyrus.infra.table.efacet.nestededitor.internal.copy;
+
+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.nestededitor/src/org/eclipse/papyrus/infra/table/efacet/nestededitor/internal/copy/TableInstanceCommandFactory.java b/sandbox/org.eclipse.papyrus.infra.table.efacet.nestededitor/src/org/eclipse/papyrus/infra/table/efacet/nestededitor/internal/copy/TableInstanceCommandFactory.java
new file mode 100644
index 00000000000..12842edd2ef
--- /dev/null
+++ b/sandbox/org.eclipse.papyrus.infra.table.efacet.nestededitor/src/org/eclipse/papyrus/infra/table/efacet/nestededitor/internal/copy/TableInstanceCommandFactory.java
@@ -0,0 +1,285 @@
+/*******************************************************************************
+ * 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 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
+ *******************************************************************************/
+package org.eclipse.papyrus.infra.table.efacet.nestededitor.internal.copy;
+
+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.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.FeatureColumn;
+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;
+
+//TODO duplicated and adapted code from EMF-Facet
+//EMF-Facet should provides a best way to hide columns
+public final class TableInstanceCommandFactory {
+
+
+ /**
+ *
+ * @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;
+ }
+
+ private TableInstanceCommandFactory() {
+ // Prevents instantiation
+ }
+
+
+ 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;
+ }
+ }
+}

Back to the top