Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemi Schnekenburger2016-10-05 16:03:22 +0000
committerGerrit Code Review @ Eclipse.org2016-10-06 08:24:32 +0000
commit916ea484cf72e938aaabc59e8831d6e072037785 (patch)
tree5683af7ee6f11afbbe5367755316463510448c94
parentfacda7aa1bf13b1d0703388acf238a148fad2157 (diff)
downloadorg.eclipse.papyrus-rt-916ea484cf72e938aaabc59e8831d6e072037785.tar.gz
org.eclipse.papyrus-rt-916ea484cf72e938aaabc59e8831d6e072037785.tar.xz
org.eclipse.papyrus-rt-916ea484cf72e938aaabc59e8831d6e072037785.zip
Bug 503083: [Table] Fail to create NattablePropertyEditor
https://bugs.eclipse.org/bugs/show_bug.cgi?id=503083 - using command stack to modify the table, but commandstack from table editing domain, not the one from Papyrus editor Change-Id: Iff3268704389f60a41c862d577b5fdacb20ce8df Signed-off-by: Remi Schnekenburger <remi.schnekenburger@cea.fr>
-rw-r--r--plugins/umlrt/tooling/org.eclipse.papyrusrt.umlrt.tooling.properties/src/org/eclipse/papyrusrt/umlrt/tooling/properties/widget/OwnedParameterOperationPropertyEditor.java138
1 files changed, 138 insertions, 0 deletions
diff --git a/plugins/umlrt/tooling/org.eclipse.papyrusrt.umlrt.tooling.properties/src/org/eclipse/papyrusrt/umlrt/tooling/properties/widget/OwnedParameterOperationPropertyEditor.java b/plugins/umlrt/tooling/org.eclipse.papyrusrt.umlrt.tooling.properties/src/org/eclipse/papyrusrt/umlrt/tooling/properties/widget/OwnedParameterOperationPropertyEditor.java
index ef2ddc33b..98c700fb1 100644
--- a/plugins/umlrt/tooling/org.eclipse.papyrusrt.umlrt.tooling.properties/src/org/eclipse/papyrusrt/umlrt/tooling/properties/widget/OwnedParameterOperationPropertyEditor.java
+++ b/plugins/umlrt/tooling/org.eclipse.papyrusrt.umlrt.tooling.properties/src/org/eclipse/papyrusrt/umlrt/tooling/properties/widget/OwnedParameterOperationPropertyEditor.java
@@ -15,12 +15,19 @@ package org.eclipse.papyrusrt.umlrt.tooling.properties.widget;
import static java.lang.Math.abs;
+import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Collection;
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.EStructuralFeature;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.transaction.RecordingCommand;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.nebula.widgets.nattable.NatTable;
@@ -33,9 +40,11 @@ import org.eclipse.nebula.widgets.nattable.selection.SelectionLayer;
import org.eclipse.nebula.widgets.nattable.selection.SelectionLayer.MoveDirectionEnum;
import org.eclipse.nebula.widgets.nattable.selection.command.MoveSelectionCommand;
import org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand;
+import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
import org.eclipse.papyrus.infra.emf.nattable.selection.EObjectSelectionExtractor;
import org.eclipse.papyrus.infra.nattable.layerstack.BodyLayerStack;
import org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager;
+import org.eclipse.papyrus.infra.nattable.manager.table.NattableModelManager;
import org.eclipse.papyrus.infra.nattable.model.nattable.Table;
import org.eclipse.papyrus.infra.nattable.painter.CustomizedCellPainter;
import org.eclipse.papyrus.infra.nattable.provider.TableSelectionProvider;
@@ -43,6 +52,7 @@ import org.eclipse.papyrus.infra.nattable.provider.TableStructuredSelection;
import org.eclipse.papyrus.infra.nattable.utils.AxisUtils;
import org.eclipse.papyrus.infra.nattable.utils.NattableModelManagerFactory;
import org.eclipse.papyrus.infra.nattable.utils.TableSelectionWrapper;
+import org.eclipse.papyrusrt.umlrt.tooling.properties.Activator;
import org.eclipse.papyrusrt.umlrt.tooling.properties.editors.ParameterControlEditor;
import org.eclipse.papyrusrt.umlrt.tooling.ui.Messages;
import org.eclipse.swt.SWT;
@@ -139,6 +149,113 @@ public class OwnedParameterOperationPropertyEditor extends RTNatTablePropertyEdi
}
/**
+ * This allow to create the table widget or to reuse a table previously used in the property view
+ *
+ * @param sourceElement
+ * The source Element.
+ * @param feature
+ * The parent structural feature.
+ * @param rows
+ * The rows of the table.
+ *
+ * @since 2.0
+ */
+ @Override
+ protected void createTableWidget(final EObject sourceElement, final EStructuralFeature feature, final Collection<?> rows) {
+ // 1. we initialize a service registry
+
+ ServicesRegistry privateSuperServiceRegistry = getField(this, "serviceRegistry");
+ if (privateSuperServiceRegistry == null) {
+ try {
+ setField(this, "serviceRegistry", createServiceRegistry(sourceElement));
+ } catch (Exception e) {
+ Activator.log.error(e);
+ }
+ }
+ privateSuperServiceRegistry = getField(this, "serviceRegistry");
+ if (privateSuperServiceRegistry == null) {
+ displayError("Cannot initialize the service registry"); //$NON-NLS-1$
+ return;
+ }
+
+ // 2. get the editing domain
+ TransactionalEditingDomain domain = getTableEditingDomain();
+ if (domain == null) {
+ displayError("Cannot found the editing domain"); //$NON-NLS-1$
+ return;
+ }
+
+ // 3. Create the table or get an existing one
+ setField(this, "table", getOrCreateTable(sourceElement, feature, rows));
+
+ Table privateSuperTable = getField(this, "table");
+ if (privateSuperTable == null) {
+ displayError("Cannot initialize the table"); //$NON-NLS-1$
+ return;
+ }
+
+ // 4. we configure the table
+ final CompoundCommand cc = new CompoundCommand("Configure table command");//$NON-NLS-1$
+
+ Resource privateSuperResource = getField(this, "resource");
+
+ // 4.1 we register it into a resource if required
+ if (privateSuperTable.eResource() == null) {
+ cc.append(addTableToResource(domain, privateSuperResource, privateSuperTable));
+ }
+
+ // 4.2 we configure the table
+ configureTable(domain, privateSuperTable, sourceElement, feature, rows, cc);
+
+ if (!cc.canExecute()) {
+ displayError("The table can't be initialized");//$NON-NLS-1$
+ return;
+ }
+
+ final ResourceSet resourceSet = getResourceSet();
+ // Bug 502160: Remove the resource from the resource set to execute the command without using the editing command stack
+ resourceSet.getResources().remove(privateSuperResource);
+ domain.getCommandStack().execute(cc);
+ // Bug 502160: Re-add the removed resource before the command execute
+ resourceSet.getResources().add(privateSuperResource);
+
+ if (privateSuperTable.getContext() == null) {
+ displayError("The context of the table hasn't be set");//$NON-NLS-1$
+ return;
+ }
+ // 5. Create the widget
+ this.nattableManager = NattableModelManagerFactory.INSTANCE.createNatTableModelManager(privateSuperTable, new EObjectSelectionExtractor());
+ this.natTableWidget = createNatTableWidget(this.nattableManager, self, SWT.NONE, rows);
+
+ self.addDisposeListener(getDisposeListener());
+ // Configure the layout and the layout data
+ configureLayout();
+
+ ((NattableModelManager) nattableManager).refreshNatTable();
+ }
+
+
+ /**
+ * @param ownedParameterOperationPropertyEditor
+ * @param string
+ * @param createServiceRegistry
+ */
+ @SuppressWarnings("unchecked")
+ protected static void setField(Object object, String fieldName, Object value) {
+ for (Class<?> search = object.getClass(); search != null; search = search.getSuperclass()) {
+ try {
+ Field field = search.getDeclaredField(fieldName);
+ field.setAccessible(true);
+ field.set(object, value);
+ break;
+ } catch (Exception e) {
+ // Try superclass
+ }
+ }
+
+ }
+
+ /**
* Configure layout of the different Composite
*
* @param sourceElement
@@ -220,6 +337,27 @@ public class OwnedParameterOperationPropertyEditor extends RTNatTablePropertyEdi
}
/**
+ *
+ * @param domain
+ * the editing domain to use
+ * @param resource
+ * the resource where the table must be saved
+ * @param table
+ * the table to add to the resource
+ * @return
+ * the command to add the table to the resource
+ */
+ private static final Command addTableToResource(final TransactionalEditingDomain domain, final Resource resource, final Table table) {
+ return new RecordingCommand(domain) {
+
+ @Override
+ protected void doExecute() {
+ resource.getContents().add(table);
+ }
+ };
+ }
+
+ /**
* Create the Control button widget to manipulate the Owned Parameters
*
* @param parent

Back to the top