Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorvlorenzo2011-05-15 17:28:53 +0000
committervlorenzo2011-05-15 17:28:53 +0000
commit809172fabdfa05b369a40e518c556dd1641bc70c (patch)
treeb7634124a13eca0b6722956805eabaafd624be48
parentc154837935d6dd87a742f40f00916c1169c506be (diff)
downloadorg.eclipse.papyrus-809172fabdfa05b369a40e518c556dd1641bc70c.tar.gz
org.eclipse.papyrus-809172fabdfa05b369a40e518c556dd1641bc70c.tar.xz
org.eclipse.papyrus-809172fabdfa05b369a40e518c556dd1641bc70c.zip
NEW - bug 339650: [Enhancement][TableEditor] Table editor should be synchronized with the table context using filling queries.
https://bugs.eclipse.org/bugs/show_bug.cgi?id=339650
-rw-r--r--plugins/uml/org.eclipse.papyrus.table.common/src/org/eclipse/papyrus/table/common/editor/AbstractNattableEditor.java9
-rw-r--r--plugins/uml/org.eclipse.papyrus.table.common/src/org/eclipse/papyrus/table/common/internal/IPapyrusNatTableWidget.java42
-rw-r--r--plugins/uml/org.eclipse.papyrus.table.common/src/org/eclipse/papyrus/table/common/internal/NatTableEditor.java18
-rw-r--r--plugins/uml/org.eclipse.papyrus.table.common/src/org/eclipse/papyrus/table/common/internal/PapyrusNatTableWidget.java254
4 files changed, 316 insertions, 7 deletions
diff --git a/plugins/uml/org.eclipse.papyrus.table.common/src/org/eclipse/papyrus/table/common/editor/AbstractNattableEditor.java b/plugins/uml/org.eclipse.papyrus.table.common/src/org/eclipse/papyrus/table/common/editor/AbstractNattableEditor.java
index 8ea20340d08..d8e6645d783 100644
--- a/plugins/uml/org.eclipse.papyrus.table.common/src/org/eclipse/papyrus/table/common/editor/AbstractNattableEditor.java
+++ b/plugins/uml/org.eclipse.papyrus.table.common/src/org/eclipse/papyrus/table/common/editor/AbstractNattableEditor.java
@@ -40,6 +40,7 @@ import org.eclipse.emf.facet.widgets.nattable.internal.NatTableWidgetInternalUti
import org.eclipse.papyrus.core.services.ServiceException;
import org.eclipse.papyrus.core.services.ServicesRegistry;
import org.eclipse.papyrus.core.utils.ServiceUtils;
+import org.eclipse.papyrus.table.common.internal.IPapyrusNatTableWidget;
import org.eclipse.papyrus.table.common.internal.TableEditorInput;
import org.eclipse.papyrus.table.instance.papyrustableinstance.PapyrusTableInstance;
import org.eclipse.papyrus.table.instance.papyrustableinstance.PapyrustableinstancePackage;
@@ -126,6 +127,9 @@ public abstract class AbstractNattableEditor extends org.eclipse.papyrus.table.c
if(!elementsToDelete.isEmpty()){
//TODO : currently the Nattable API doesn't allow to delete lines programmatically
// ((INatTableWidget2)AbstractNattableEditor.this.natTableWidget).removeRows(elementsToDelete);
+ if(AbstractNattableEditor.this.natTableWidget instanceof IPapyrusNatTableWidget){
+ ((IPapyrusNatTableWidget)AbstractNattableEditor.this.natTableWidget).removeRowsOutOfCommandStack(elementsToDelete);
+ }
}
}
}
@@ -263,7 +267,10 @@ public abstract class AbstractNattableEditor extends org.eclipse.papyrus.table.c
}
}
if(!elementsToAdd.isEmpty()){
- this.natTableWidget.addRows(elementsToAdd);
+ // this.natTableWidget.addRows(elementsToAdd);
+ if(this.natTableWidget instanceof IPapyrusNatTableWidget){
+ ((IPapyrusNatTableWidget)this.natTableWidget).addRowsOutOfCommandStack(elementsToAdd);
+ }
}
}
diff --git a/plugins/uml/org.eclipse.papyrus.table.common/src/org/eclipse/papyrus/table/common/internal/IPapyrusNatTableWidget.java b/plugins/uml/org.eclipse.papyrus.table.common/src/org/eclipse/papyrus/table/common/internal/IPapyrusNatTableWidget.java
new file mode 100644
index 00000000000..9536abe3bb8
--- /dev/null
+++ b/plugins/uml/org.eclipse.papyrus.table.common/src/org/eclipse/papyrus/table/common/internal/IPapyrusNatTableWidget.java
@@ -0,0 +1,42 @@
+/*****************************************************************************
+ * 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
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.table.common.internal;
+
+import java.util.List;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.facet.widgets.nattable.INatTableWidget;
+
+/**
+ *
+ * This interface is used to add some useful method to INatTableWidget
+ *
+ *
+ */
+public interface IPapyrusNatTableWidget extends INatTableWidget {
+
+ /**
+ * This method allow to add elements in the table without execute the command in the command stack
+ * @param elementsToAdd
+ * the list of the elements to add
+ */
+ public void addRowsOutOfCommandStack(List<EObject> elementsToAdd);
+
+ /**
+ * This method allow to remove elements from the table without execute the command in the command stack
+ * @param elementsToDelete
+ * the list of the element to delete
+ */
+ public void removeRowsOutOfCommandStack(List<EObject> elementsToDelete);
+}
diff --git a/plugins/uml/org.eclipse.papyrus.table.common/src/org/eclipse/papyrus/table/common/internal/NatTableEditor.java b/plugins/uml/org.eclipse.papyrus.table.common/src/org/eclipse/papyrus/table/common/internal/NatTableEditor.java
index b3266a7e007..39eab9caac3 100644
--- a/plugins/uml/org.eclipse.papyrus.table.common/src/org/eclipse/papyrus/table/common/internal/NatTableEditor.java
+++ b/plugins/uml/org.eclipse.papyrus.table.common/src/org/eclipse/papyrus/table/common/internal/NatTableEditor.java
@@ -45,11 +45,11 @@ import org.eclipse.emf.edit.domain.EditingDomain;
import org.eclipse.emf.edit.domain.IEditingDomainProvider;
import org.eclipse.emf.edit.provider.ComposedAdapterFactory;
import org.eclipse.emf.facet.widgets.nattable.INatTableWidget;
-import org.eclipse.emf.facet.widgets.nattable.INatTableWidgetFactory;
import org.eclipse.emf.facet.widgets.nattable.INatTableWidgetProvider;
import org.eclipse.emf.facet.widgets.nattable.IWorkbenchPartProvider;
import org.eclipse.emf.facet.widgets.nattable.instance.tableinstance.TableInstance;
import org.eclipse.emf.facet.widgets.nattable.instance.tableinstance.TableinstancePackage;
+import org.eclipse.emf.facet.widgets.nattable.instance.tableinstance2.TableInstance2;
import org.eclipse.jface.action.GroupMarker;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.viewers.ISelection;
@@ -212,10 +212,18 @@ public class NatTableEditor extends EditorPart implements ISelectionProvider, IE
compositeTableGridLayout.verticalAlignment = SWT.FILL;
tableComposite.setLayoutData(compositeTableGridLayout);
- // the nattable widget itself
- this.natTableWidget = INatTableWidgetFactory.INSTANCE.createNatTableWidget(tableComposite, this, this.tableEditorInput.getPapyrusTableInstance().getTable(), this.menuMgr);
+ this.natTableWidget = createNattableWidget(tableComposite, this, this.tableEditorInput.getPapyrusTableInstance().getTable(), this.menuMgr);
+
+ getSite().setSelectionProvider(this);
+ getSite().registerContextMenu(this.menuMgr, this.natTableWidget);
+ }
+ private INatTableWidget createNattableWidget(final Composite tableComposite, final NatTableEditor natTableEditor, final TableInstance2 table, final MenuManager menuMgr2) {
+ // the nattable widget itself
+ //old instanciation
+ // this.natTableWidget = INatTableWidgetFactory.INSTANCE.createNatTableWidget(tableComposite, this, this.tableEditorInput.getPapyrusTableInstance().getTable(), this.menuMgr);
+ this.natTableWidget = new PapyrusNatTableWidget(tableComposite, natTableEditor, table, this.menuMgr);
final GridData tableGridData = new GridData();
tableGridData.grabExcessHorizontalSpace = true;
tableGridData.grabExcessVerticalSpace = true;
@@ -223,11 +231,9 @@ public class NatTableEditor extends EditorPart implements ISelectionProvider, IE
tableGridData.verticalAlignment = SWT.FILL;
this.natTableWidget.getComposite().setLayoutData(tableGridData);
- getSite().setSelectionProvider(this);
- getSite().registerContextMenu(this.menuMgr, this.natTableWidget);
+ return this.natTableWidget;
}
-
private Composite createCompositeCompositeWthTableBorder(final Composite parent){
Composite editorComposite = new Composite(parent, SWT.BORDER);
final GridLayout editorGridLayout = new GridLayout(1, true);
diff --git a/plugins/uml/org.eclipse.papyrus.table.common/src/org/eclipse/papyrus/table/common/internal/PapyrusNatTableWidget.java b/plugins/uml/org.eclipse.papyrus.table.common/src/org/eclipse/papyrus/table/common/internal/PapyrusNatTableWidget.java
new file mode 100644
index 00000000000..dbb780d62d7
--- /dev/null
+++ b/plugins/uml/org.eclipse.papyrus.table.common/src/org/eclipse/papyrus/table/common/internal/PapyrusNatTableWidget.java
@@ -0,0 +1,254 @@
+/*****************************************************************************
+ * 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
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.table.common.internal;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.common.command.CompoundCommand;
+import org.eclipse.emf.ecore.EAttribute;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.ecore.EReference;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.emf.edit.domain.IEditingDomainProvider;
+import org.eclipse.emf.facet.infra.browser.custom.MetamodelView;
+import org.eclipse.emf.facet.infra.browser.custom.util.UicustomUtil;
+import org.eclipse.emf.facet.widgets.celleditors.ICommandFactoriesRegistry;
+import org.eclipse.emf.facet.widgets.celleditors.ICommandFactory;
+import org.eclipse.emf.facet.widgets.nattable.instance.tableinstance.AttributeColumn;
+import org.eclipse.emf.facet.widgets.nattable.instance.tableinstance.Column;
+import org.eclipse.emf.facet.widgets.nattable.instance.tableinstance.FacetAttributeColumn;
+import org.eclipse.emf.facet.widgets.nattable.instance.tableinstance.FacetReferenceColumn;
+import org.eclipse.emf.facet.widgets.nattable.instance.tableinstance.ReferenceColumn;
+import org.eclipse.emf.facet.widgets.nattable.instance.tableinstance.Row;
+import org.eclipse.emf.facet.widgets.nattable.instance.tableinstance.TableInstance;
+import org.eclipse.emf.facet.widgets.nattable.instance.tableinstance.TableinstanceFactory;
+import org.eclipse.emf.facet.widgets.nattable.instance.tableinstance.TableinstancePackage;
+import org.eclipse.emf.facet.widgets.nattable.instance.tableinstance2.TableInstance2;
+import org.eclipse.emf.facet.widgets.nattable.internal.NatTableWidget;
+import org.eclipse.jface.action.MenuManager;
+import org.eclipse.swt.widgets.Composite;
+
+/**
+ *
+ * The Papyrus Nattable Widget. This widget provides 2 interesting methods for the synchronized table :
+ * <ul>
+ * <li> a method to add rows without execute the command in the command stack</li>
+ * <li> a method to remove rows without execute the command in the command stack</li>
+ * </ul>
+ *
+ *The synchronization of the table is done using listener on the context.
+ * We can't use the commadStack to add/remove element in the table, because in this case we add a command in the CommandStack :
+ * -> 2 Commands for the Undo
+ * -> moreover we add a new command executing the undo (thanks to the listener...)
+ *
+ * Another idea : maybe, we should use something like the ServiceEdit, which provides commands for each action,
+ * to chain the commands to execute.
+ *
+ */
+public class PapyrusNatTableWidget extends NatTableWidget implements IPapyrusNatTableWidget{
+
+ /**
+ * the editing domain
+ */
+ private final EditingDomain editingDomain;
+
+ /**
+ * the table instance
+ */
+ private final TableInstance tableInstance;
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param parent
+ * @param editingDomainProvider
+ * @param tableInstanceParam
+ * @param menuMgr
+ */
+ public PapyrusNatTableWidget(final Composite parent, final IEditingDomainProvider editingDomainProvider, final TableInstance tableInstanceParam, final MenuManager menuMgr) {
+ super(parent, editingDomainProvider, tableInstanceParam, menuMgr);
+ this.editingDomain = editingDomainProvider.getEditingDomain();
+ this.tableInstance = tableInstanceParam;
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.table.common.internal.IPapyrusNatTableWidget#addRowsOutOfCommandStack(java.util.List)
+ *
+ * {@inheritDoc}
+ */
+ public void addRowsOutOfCommandStack(final List<EObject> newElements) {
+ ICommandFactory commandFactory = ICommandFactoriesRegistry.INSTANCE
+ .getCommandFactoryFor(this.editingDomain);
+ CompoundCommand cmCommand = new CompoundCommand();
+ // the EPackage for which the MetamodelView has already been created
+ Set<EPackage> alreadyDone = new HashSet<EPackage>();
+ for (EObject eObject : newElements) {
+ if (!this.tableInstance.getElements().contains(eObject)) {
+ Row row = TableinstanceFactory.eINSTANCE.createRow();
+ Command cmd2 = commandFactory.createSetCommand(this.editingDomain, row,
+ TableinstancePackage.eINSTANCE.getRow_Element(), eObject);
+ cmCommand.append(cmd2);
+ Command cmd1 = commandFactory.createAddCommand(this.editingDomain,
+ this.tableInstance, TableinstancePackage.eINSTANCE.getTableInstance_Rows(),
+ row);
+ cmCommand.append(cmd1);
+ for (EStructuralFeature eStructuralFeature : eObject.eClass()
+ .getEAllStructuralFeatures()) {
+ if (!isColumnAlreadyDeclared(eStructuralFeature)) {
+ if (eStructuralFeature instanceof EReference) {
+ ReferenceColumn referenceColumn = TableinstanceFactory.eINSTANCE
+ .createReferenceColumn();
+ referenceColumn.setReference((EReference) eStructuralFeature);
+ Command cmd = commandFactory.createAddCommand(this.editingDomain,
+ this.tableInstance,
+ TableinstancePackage.eINSTANCE.getTableInstance_Columns(),
+ referenceColumn);
+ cmCommand.append(cmd);
+
+ } else if (eStructuralFeature instanceof EAttribute) {
+ AttributeColumn attributeColumn = TableinstanceFactory.eINSTANCE
+ .createAttributeColumn();
+ attributeColumn.setAttribute((EAttribute) eStructuralFeature);
+ Command cmd = commandFactory.createAddCommand(this.editingDomain,
+ this.tableInstance,
+ TableinstancePackage.eINSTANCE.getTableInstance_Columns(),
+ attributeColumn);
+ cmCommand.append(cmd);
+ }
+
+ // we add the local customization file
+ if (this.tableInstance instanceof TableInstance2) {
+ List<MetamodelView> localCustoms = getLocalCustomizations();
+ EObject container = eStructuralFeature.eContainer();
+ if (container != null) {
+ container = container.eContainer();
+ if (container instanceof EPackage) {
+ if (!alreadyDone.contains(container)) {
+ if (UicustomUtil.getMetamodelViewByEPackage(localCustoms,
+ (EPackage) container) == null) {
+ Command cmd = getCreateMetamodelViewCommand(
+ this.tableInstance,
+ ((EPackage) container).getNsURI());
+ if (cmd.canExecute()) {
+ cmCommand.append(cmd);
+ }
+ alreadyDone.add((EPackage) container);
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ // this.editingDomain.getCommandStack().execute(cmCommand);
+ cmCommand.execute();
+ if (this.tableInstance instanceof TableInstance2) {
+ TableInstance2 tableInstance2 = (TableInstance2) this.tableInstance;
+ try {
+ setFacets(tableInstance2.getFacets2());
+ } catch (CoreException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ loadCustomizations(this.tableInstance.getCustomizations());
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.table.common.internal.IPapyrusNatTableWidget#removeRowsOutOfCommandStack(java.util.List)
+ *
+ * {@inheritDoc}
+ */
+ public void removeRowsOutOfCommandStack(final List<EObject> elementsToDelete) {
+ // this.natTable.setRedraw(false);
+ try {
+ ICommandFactory commandFactory = ICommandFactoriesRegistry.INSTANCE
+ .getCommandFactoryFor(this.editingDomain);
+ CompoundCommand compoundCommand = new CompoundCommand();
+ for (int i = 0; i < this.tableInstance.getRows().size(); i++) {
+ if (elementsToDelete.contains(this.tableInstance.getRows().get(i).getElement())) {
+ Command removeRowCommand = commandFactory.createRemoveCommand(
+ this.editingDomain, this.tableInstance,
+ TableinstancePackage.eINSTANCE.getTableInstance_Rows(),
+ this.tableInstance.getRows().get(i));
+ compoundCommand.append(removeRowCommand);
+ }
+ }
+
+ if (!compoundCommand.isEmpty() && compoundCommand.canExecute()) {
+ // this.editingDomain.getCommandStack().execute(compoundCommand);
+ compoundCommand.execute();
+ }
+ } finally {
+ // this.natTable.setRedraw(true);
+ }
+ }
+
+
+ //TODO this method is duplicated from the super class
+ private List<MetamodelView> getLocalCustomizations() {
+ List<MetamodelView> locals = new ArrayList<MetamodelView>();
+ if (this.tableInstance.getLocalCustomization() != null) {
+ locals.add(this.tableInstance.getLocalCustomization());
+ }
+ if (this.tableInstance instanceof TableInstance2) {
+ locals.addAll(((TableInstance2) this.tableInstance).getLocalCustomizations());
+ }
+ return locals;
+ }
+
+ //TODO this method is duplicated from the super class
+ private boolean isColumnAlreadyDeclared(final EStructuralFeature eStructuralFeature) {
+ if (eStructuralFeature instanceof EReference) {
+ for (Column c : this.tableInstance.getColumns()) {
+ if (c instanceof ReferenceColumn) {
+ if (((ReferenceColumn) c).getReference() == eStructuralFeature) {
+ return true;
+ }
+ } else if (c instanceof FacetReferenceColumn) {
+ if (((FacetReferenceColumn) c).getReference() == eStructuralFeature) {
+ return true;
+ }
+ }
+ }
+ } else if (eStructuralFeature instanceof EAttribute) {
+ for (Column c : this.tableInstance.getColumns()) {
+ if (c instanceof AttributeColumn) {
+ if (((AttributeColumn) c).getAttribute() == eStructuralFeature) {
+ return true;
+ }
+ } else if (c instanceof FacetAttributeColumn) {
+ if (((FacetAttributeColumn) c).getAttribute() == eStructuralFeature) {
+ return true;
+ }
+ }
+ }
+ }
+
+ return false;
+ }
+
+
+}

Back to the top