Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVincent Lorenzo2013-10-01 08:46:34 +0000
committerVincent Lorenzo2013-10-01 08:46:34 +0000
commit3b0a2e167a404c7d7eed3319e17e27e4d59cd467 (patch)
tree773826f3d83c2bd52c4795b1589d6a844ae03915 /plugins
parent32a32111736a8acc5ed17a458e7ea22d35d108f2 (diff)
downloadorg.eclipse.papyrus-3b0a2e167a404c7d7eed3319e17e27e4d59cd467.tar.gz
org.eclipse.papyrus-3b0a2e167a404c7d7eed3319e17e27e4d59cd467.tar.xz
org.eclipse.papyrus-3b0a2e167a404c7d7eed3319e17e27e4d59cd467.zip
401764: [Table 2] The classes managing the table model and Nattable must
be refactored https://bugs.eclipse.org/bugs/show_bug.cgi?id=401764
Diffstat (limited to 'plugins')
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.emf.nattable/src/org/eclipse/papyrus/infra/emf/nattable/manager/cell/EMFFeatureValueCellManager.java161
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/paste/AddToResource.java73
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/paste/IValueSetter.java36
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/paste/ReferenceValueSetter.java17
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/provider/PasteEObjectAxisInTableCommandProvider.java14
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/utils/CellHelper.java231
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/utils/PasteConfigurationUtils.java10
7 files changed, 374 insertions, 168 deletions
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.emf.nattable/src/org/eclipse/papyrus/infra/emf/nattable/manager/cell/EMFFeatureValueCellManager.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.emf.nattable/src/org/eclipse/papyrus/infra/emf/nattable/manager/cell/EMFFeatureValueCellManager.java
index 8786c4f9f1c..825c7343238 100644
--- a/plugins/infra/nattable/org.eclipse.papyrus.infra.emf.nattable/src/org/eclipse/papyrus/infra/emf/nattable/manager/cell/EMFFeatureValueCellManager.java
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.emf.nattable/src/org/eclipse/papyrus/infra/emf/nattable/manager/cell/EMFFeatureValueCellManager.java
@@ -14,11 +14,9 @@
package org.eclipse.papyrus.infra.emf.nattable.manager.cell;
import java.util.ArrayList;
-import java.util.Collections;
import java.util.List;
import java.util.Map;
-import org.eclipse.core.runtime.IStatus;
import org.eclipse.emf.common.command.Command;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EReference;
@@ -32,23 +30,15 @@ import org.eclipse.papyrus.commands.wrappers.GMFtoEMFCommandWrapper;
import org.eclipse.papyrus.infra.emf.utils.EMFStringValueConverter;
import org.eclipse.papyrus.infra.nattable.manager.cell.AbstractCellManager;
import org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager;
-import org.eclipse.papyrus.infra.nattable.model.nattable.NattablePackage;
-import org.eclipse.papyrus.infra.nattable.model.nattable.Table;
-import org.eclipse.papyrus.infra.nattable.model.nattable.nattablecell.Cell;
-import org.eclipse.papyrus.infra.nattable.model.nattable.nattablecell.ICellAxisWrapper;
-import org.eclipse.papyrus.infra.nattable.model.nattable.nattablecell.IdAxisWrapper;
-import org.eclipse.papyrus.infra.nattable.model.nattable.nattablecell.NattablecellFactory;
-import org.eclipse.papyrus.infra.nattable.model.nattable.nattablecell.NattablecellPackage;
-import org.eclipse.papyrus.infra.nattable.model.nattable.nattableproblem.NattableproblemFactory;
-import org.eclipse.papyrus.infra.nattable.model.nattable.nattableproblem.StringResolutionProblem;
+import org.eclipse.papyrus.infra.nattable.paste.IValueSetter;
import org.eclipse.papyrus.infra.nattable.paste.ReferenceValueSetter;
import org.eclipse.papyrus.infra.nattable.utils.AxisUtils;
+import org.eclipse.papyrus.infra.nattable.utils.CellHelper;
import org.eclipse.papyrus.infra.nattable.utils.Constants;
import org.eclipse.papyrus.infra.services.edit.service.ElementEditServiceUtils;
import org.eclipse.papyrus.infra.services.edit.service.IElementEditService;
import org.eclipse.papyrus.infra.tools.converter.AbstractStringValueConverter;
import org.eclipse.papyrus.infra.tools.converter.ConvertedValueContainer;
-import org.eclipse.papyrus.infra.tools.converter.StringValueConverterStatus;
/**
* Cell Manager which allows to get the value of an {@link EStructuralFeature} for an {@link EObject}
@@ -235,80 +225,10 @@ public class EMFFeatureValueCellManager extends AbstractCellManager {
* @return
* the command to create a String resolution Problem
*/
+ @Deprecated
+ //use CellHelper.getCreateStringResolutionProblemCommand(
protected Command getCreateStringResolutionProblemCommand(final TransactionalEditingDomain domain, final INattableModelManager tableManager, final Object columnElement, final Object rowElement, final String pastedText, final ConvertedValueContainer<?> valueContainer) {
- final IStatus status = valueContainer.getStatus();
- if(!status.isOK()) {
- if(status.matches(IStatus.ERROR)) {
- final CompositeCommand command = new CompositeCommand("Create Cell For Error Command"); //$NON-NLS-1$
- Cell cell = tableManager.getCell(columnElement, rowElement);
-
- if(cell == null) {
- //we create the cell
- final Table table = tableManager.getTable();
- cell = NattablecellFactory.eINSTANCE.createCell();
-
- SetRequest request = new SetRequest(domain, table, NattablePackage.eINSTANCE.getTable_Cells(), cell);
- IElementEditService provider = ElementEditServiceUtils.getCommandProvider(table);
- command.add(provider.getEditCommand(request));
-
- //create the columnWrapper;
- final Object column = AxisUtils.getRepresentedElement(columnElement);
- ICellAxisWrapper columnWrapper = null;
- if(column instanceof String) {
- columnWrapper = NattablecellFactory.eINSTANCE.createIdAxisWrapper();
- provider = ElementEditServiceUtils.getCommandProvider(columnWrapper);
- request = new SetRequest(domain, columnWrapper, NattablecellPackage.eINSTANCE.getIdAxisWrapper_Element(), column);
- command.add(provider.getEditCommand(request));
- } else if(column instanceof EObject) {
- columnWrapper = NattablecellFactory.eINSTANCE.createEObjectAxisWrapper();
- provider = ElementEditServiceUtils.getCommandProvider(columnWrapper);
- request = new SetRequest(domain, columnWrapper, NattablecellPackage.eINSTANCE.getEObjectAxisWrapper_Element(), column);
- command.add(provider.getEditCommand(request));
- }
-
- final Object row = AxisUtils.getRepresentedElement(rowElement);
- ICellAxisWrapper rowWrapper = null;
- if(row instanceof String) {
- rowWrapper = NattablecellFactory.eINSTANCE.createIdAxisWrapper();
- provider = ElementEditServiceUtils.getCommandProvider(rowWrapper);
- request = new SetRequest(domain, rowWrapper, NattablecellPackage.eINSTANCE.getIdAxisWrapper_Element(), row);
- command.add(provider.getEditCommand(request));
- } else if(row instanceof EObject) {
- rowWrapper = NattablecellFactory.eINSTANCE.createEObjectAxisWrapper();
- provider = ElementEditServiceUtils.getCommandProvider(rowWrapper);
- request = new SetRequest(domain, rowWrapper, NattablecellPackage.eINSTANCE.getEObjectAxisWrapper_Element(), row);
- command.add(provider.getEditCommand(request));
- }
-
- if(rowWrapper == null || columnWrapper == null) {
- throw new UnsupportedOperationException("Case not managed"); //$NON-NLS-1$
- }
-
-
- provider = ElementEditServiceUtils.getCommandProvider(cell);
- request = new SetRequest(domain, cell, NattablecellPackage.eINSTANCE.getCell_ColumnWrapper(), columnWrapper);
- command.add(provider.getEditCommand(request));
- request = new SetRequest(domain, cell, NattablecellPackage.eINSTANCE.getCell_RowWrapper(), rowWrapper);
- command.add(provider.getEditCommand(request));
- }
-
-
- final StringResolutionProblem problem = NattableproblemFactory.eINSTANCE.createStringResolutionProblem();
- problem.setName("Set Value As Text Problem"); //$NON-NLS-1$
- problem.setDescription(status.getMessage());
- problem.setValueAsString(pastedText);
-
- if(status instanceof StringValueConverterStatus) {
- problem.getUnresolvedString().addAll(((StringValueConverterStatus)status).getUnresolvedString());
- }
-
- SetRequest setProblemRequest = new SetRequest(domain, cell, NattablecellPackage.eINSTANCE.getCell_Problems(), problem);
- IElementEditService provider = ElementEditServiceUtils.getCommandProvider(cell);
- command.add(provider.getEditCommand(setProblemRequest));
- return new GMFtoEMFCommandWrapper(command);
- }
- }
- return null;
+ return CellHelper.getCreateStringResolutionProblemCommand(domain, tableManager, columnElement, rowElement, pastedText, valueContainer);
}
/**
@@ -364,73 +284,10 @@ public class EMFFeatureValueCellManager extends AbstractCellManager {
* @param valueContainer
* @param sharedMap
*/
+ @Deprecated
+ //use CellHelper.createStringResolutionProblem
protected void createStringResolutionProblem(final INattableModelManager tableManager, final Object columnElement, final Object rowElement, final String pastedText, final ConvertedValueContainer<?> valueContainer, final Map<?, ?> sharedMap) {
- final IStatus status = valueContainer.getStatus();
- if(!status.isOK()) {
- if(status.matches(IStatus.ERROR)) {
- @SuppressWarnings("unchecked")
- final List<ReferenceValueSetter> references = (List<ReferenceValueSetter>)sharedMap.get(Constants.REFERENCES_TO_SET_KEY);
- if(status.matches(IStatus.ERROR)) {
- Cell cell = tableManager.getCell(columnElement, rowElement);
-
- if(cell == null) {
- //we create the cell
- cell = NattablecellFactory.eINSTANCE.createCell();
-
- //create the columnWrapper;
- final Object column = AxisUtils.getRepresentedElement(columnElement);
- ICellAxisWrapper columnWrapper = null;
- if(column instanceof String) {
- columnWrapper = NattablecellFactory.eINSTANCE.createIdAxisWrapper();
- ((IdAxisWrapper)columnWrapper).setElement((String)column);
- } else if(column instanceof EObject) {
- columnWrapper = NattablecellFactory.eINSTANCE.createEObjectAxisWrapper();
- ReferenceValueSetter structure = new ReferenceValueSetter(columnWrapper, NattablecellPackage.eINSTANCE.getEObjectAxisWrapper_Element(), column);
- references.add(structure);
- }
-
- final Object row = AxisUtils.getRepresentedElement(rowElement);
- ICellAxisWrapper rowWrapper = null;
- if(row instanceof String) {
- rowWrapper = NattablecellFactory.eINSTANCE.createIdAxisWrapper();
- ((IdAxisWrapper)rowWrapper).setElement((String)row);
- } else if(row instanceof EObject) {
- rowWrapper = NattablecellFactory.eINSTANCE.createEObjectAxisWrapper();
- ReferenceValueSetter structure = new ReferenceValueSetter(rowWrapper, NattablecellPackage.eINSTANCE.getEObjectAxisWrapper_Element(), row);
- references.add(structure);
- }
-
- if(rowWrapper == null || columnWrapper == null) {
- throw new UnsupportedOperationException("Case not managed"); //$NON-NLS-1$
- }
- cell.setColumnWrapper(columnWrapper);
- cell.setRowWrapper(rowWrapper);
- @SuppressWarnings("unchecked")
- final List<Cell> cells = (List<Cell>)sharedMap.get(Constants.CELLS_TO_ADD_KEY);
- cells.add(cell);
-
-
- }
-
-
- final StringResolutionProblem problem = NattableproblemFactory.eINSTANCE.createStringResolutionProblem();
- problem.setName("Set Value As Text Problem"); //$NON-NLS-1$
- problem.setDescription(status.getMessage());
- problem.setValueAsString(pastedText);
-
- if(status instanceof StringValueConverterStatus) {
- problem.getUnresolvedString().addAll(((StringValueConverterStatus)status).getUnresolvedString());
- }
-
- if(cell.eContainer() == null) {
- cell.eSet(NattablecellPackage.eINSTANCE.getCell_Problems(), Collections.singleton(problem));
- } else {
- final ReferenceValueSetter structure = new ReferenceValueSetter(cell, NattablecellPackage.eINSTANCE.getCell_Problems(), problem);
- references.add(structure);
- }
- }
- }
- }
+ CellHelper.createStringResolutionProblem(tableManager, columnElement, rowElement, pastedText, valueContainer, sharedMap);
}
/**
@@ -454,7 +311,7 @@ public class EMFFeatureValueCellManager extends AbstractCellManager {
ConvertedValueContainer<?> solvedValue = valueConverter.deduceValueFromString(editedFeature, valueAsString);
if(editedFeature instanceof EReference) {
@SuppressWarnings("unchecked")
- final List<ReferenceValueSetter> references = (List<ReferenceValueSetter>)sharedMap.get(Constants.REFERENCES_TO_SET_KEY);
+ final List<IValueSetter> references = (List<IValueSetter>)sharedMap.get(Constants.REFERENCES_TO_SET_KEY);
final ReferenceValueSetter structure = new ReferenceValueSetter(editedObject, (EReference)editedFeature, solvedValue.getConvertedValue());
references.add(structure);
} else {
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/paste/AddToResource.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/paste/AddToResource.java
new file mode 100644
index 00000000000..d78b1f7c48f
--- /dev/null
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/paste/AddToResource.java
@@ -0,0 +1,73 @@
+/*****************************************************************************
+ * Copyright (c) 2013 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.nattable.paste;
+
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.emf.transaction.RecordingCommand;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+
+
+/**
+ *
+ * @author vl222926
+ *
+ */
+public class AddToResource implements IValueSetter {
+
+ /**
+ * the managed resource
+ */
+ private final Resource resource;
+
+ /**
+ * the object to add to the resource
+ */
+ private final EObject toAdd;
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param resource
+ * @param feature
+ * @param toAdd
+ */
+ public AddToResource(final Resource resource, final EObject toAdd) {
+ this.resource = resource;
+ this.toAdd = toAdd;
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.nattable.paste.IValueSetter#doSetValue(org.eclipse.emf.edit.domain.EditingDomain)
+ *
+ * @param domain
+ */
+ @Override
+ public void doSetValue(EditingDomain domain) {
+ if(resource != null && toAdd != null) {
+ final Command cmd = new RecordingCommand((TransactionalEditingDomain)domain) {
+
+ @Override
+ protected void doExecute() {
+ resource.getContents().add((EObject)toAdd);
+ }
+ };
+ cmd.execute();
+ }
+ }
+}
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/paste/IValueSetter.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/paste/IValueSetter.java
new file mode 100644
index 00000000000..00b7a22eed8
--- /dev/null
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/paste/IValueSetter.java
@@ -0,0 +1,36 @@
+/*****************************************************************************
+ * Copyright (c) 2013 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.nattable.paste;
+
+import org.eclipse.emf.edit.domain.EditingDomain;
+
+/**
+ * Common interface used by the paste framework when we are not in the service edit.
+ *
+ *
+ *
+ * @author vl222926
+ *
+ */
+public interface IValueSetter {
+
+ /**
+ *
+ * This method will be used to set references, without using the service edit
+ *
+ * @param domain
+ * the editing domain
+ */
+ public void doSetValue(final EditingDomain domain);
+}
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/paste/ReferenceValueSetter.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/paste/ReferenceValueSetter.java
index d4c832b7afe..3de2b8b4950 100644
--- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/paste/ReferenceValueSetter.java
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/paste/ReferenceValueSetter.java
@@ -27,7 +27,7 @@ import org.eclipse.emf.edit.domain.EditingDomain;
* @author vl222926
*
*/
-public class ReferenceValueSetter {
+public class ReferenceValueSetter implements IValueSetter {
/**
* the feature to edit
@@ -42,7 +42,7 @@ public class ReferenceValueSetter {
/**
* the new value
*/
- private final Object value;
+ protected final Object value;
/**
* if true, the current value will be erased
@@ -72,17 +72,17 @@ public class ReferenceValueSetter {
* the edited object
* @param feature
* the edited feature
- * @param tutu
+ * @param value
* the value for this feature.
* @param eraseExistingMultiValueValue
* if <code>true</code>, in case of multivalued references, the current value will be replaced by {@code tutu} , if <code>false</code> we
* will add {@code tutu} to the current value
* , will be added to the current value
*/
- public ReferenceValueSetter(final EObject editedObject, final EReference feature, final Object tutu, final boolean eraseExistingMultiValueValue) {
+ public ReferenceValueSetter(final EObject editedObject, final EReference feature, final Object value, final boolean eraseExistingMultiValueValue) {
this.eReference = feature;
this.editedObject = editedObject;
- this.value = tutu;
+ this.value = value;
this.eraseExistingMultiValueValue = eraseExistingMultiValueValue;
}
@@ -92,7 +92,14 @@ public class ReferenceValueSetter {
* @param domain
* the editing domain used to do the action
*/
+ @Deprecated
+ //deprecated since october 2013. use doSetValue instead of this method
public void setReferenceValue(final EditingDomain domain) {
+ doSetValue(domain);
+ }
+
+ @Override
+ public void doSetValue(final EditingDomain domain) {
if(this.eReference.isMany() && !this.eraseExistingMultiValueValue && this.value instanceof Collection<?>) {
Collection<?> collection = (Collection<?>)value;
AddCommand.create(domain, editedObject, eReference, collection).execute();
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/provider/PasteEObjectAxisInTableCommandProvider.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/provider/PasteEObjectAxisInTableCommandProvider.java
index cc66b1298a7..1b0f206265f 100644
--- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/provider/PasteEObjectAxisInTableCommandProvider.java
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/provider/PasteEObjectAxisInTableCommandProvider.java
@@ -54,8 +54,8 @@ import org.eclipse.papyrus.infra.nattable.model.nattable.Table;
import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisconfiguration.NattableaxisconfigurationPackage;
import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisconfiguration.PasteEObjectConfiguration;
import org.eclipse.papyrus.infra.nattable.model.nattable.nattablecell.Cell;
+import org.eclipse.papyrus.infra.nattable.paste.IValueSetter;
import org.eclipse.papyrus.infra.nattable.paste.PastePostActionRegistry;
-import org.eclipse.papyrus.infra.nattable.paste.ReferenceValueSetter;
import org.eclipse.papyrus.infra.nattable.utils.AxisConfigurationUtils;
import org.eclipse.papyrus.infra.nattable.utils.AxisUtils;
import org.eclipse.papyrus.infra.nattable.utils.Constants;
@@ -339,7 +339,7 @@ public class PasteEObjectAxisInTableCommandProvider {
final EFactory eFactory = eClassToCreate.getEPackage().getEFactoryInstance();
//the map used to store useful information for the paste
sharedMap.put(Constants.PASTED_ELEMENT_CONTAINER_KEY, tableContext);
- sharedMap.put(Constants.REFERENCES_TO_SET_KEY, new ArrayList<ReferenceValueSetter>());
+ sharedMap.put(Constants.REFERENCES_TO_SET_KEY, new ArrayList<IValueSetter>());
sharedMap.put(Constants.CELLS_TO_ADD_KEY, new ArrayList<Cell>());
//2.3 create the axis
int index = 1;
@@ -411,13 +411,13 @@ public class PasteEObjectAxisInTableCommandProvider {
//initialize lists
final Collection<String> postActions = getPostActions();
final List<Cell> cells = (List<Cell>)sharedMap.get(Constants.CELLS_TO_ADD_KEY);
- final List<ReferenceValueSetter> referencesToSet = (List<ReferenceValueSetter>)sharedMap.get(Constants.REFERENCES_TO_SET_KEY);
+ final List<IValueSetter> valueToSet = (List<IValueSetter>)sharedMap.get(Constants.REFERENCES_TO_SET_KEY);
int nbTasks = 1; //to add created elements to the model
nbTasks = nbTasks + 1; //to add createds elements to the table
nbTasks = nbTasks + postActions.size();//to do post actions after the attachment to the model
nbTasks = nbTasks + 1; //to attach the cells to the model
- nbTasks = nbTasks + referencesToSet.size(); //to set the references values
+ nbTasks = nbTasks + valueToSet.size(); //to set the references values
if(progressMonitor != null) {
if(progressMonitor.isCanceled()) {
@@ -472,9 +472,9 @@ public class PasteEObjectAxisInTableCommandProvider {
//we set the references
- if(referencesToSet.size() > 0) {
- for(final ReferenceValueSetter current : referencesToSet) {
- current.setReferenceValue(contextEditingDomain);
+ if(valueToSet.size() > 0) {
+ for(final IValueSetter current : valueToSet) {
+ current.doSetValue(contextEditingDomain);
if(progressMonitor != null) {
if(progressMonitor.isCanceled()) {
return CommandResult.newCancelledCommandResult();
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/utils/CellHelper.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/utils/CellHelper.java
new file mode 100644
index 00000000000..2f5f4688765
--- /dev/null
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/utils/CellHelper.java
@@ -0,0 +1,231 @@
+package org.eclipse.papyrus.infra.nattable.utils;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gmf.runtime.common.core.command.CompositeCommand;
+import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest;
+import org.eclipse.papyrus.commands.wrappers.GMFtoEMFCommandWrapper;
+import org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager;
+import org.eclipse.papyrus.infra.nattable.model.nattable.NattablePackage;
+import org.eclipse.papyrus.infra.nattable.model.nattable.Table;
+import org.eclipse.papyrus.infra.nattable.model.nattable.nattablecell.Cell;
+import org.eclipse.papyrus.infra.nattable.model.nattable.nattablecell.ICellAxisWrapper;
+import org.eclipse.papyrus.infra.nattable.model.nattable.nattablecell.IdAxisWrapper;
+import org.eclipse.papyrus.infra.nattable.model.nattable.nattablecell.NattablecellFactory;
+import org.eclipse.papyrus.infra.nattable.model.nattable.nattablecell.NattablecellPackage;
+import org.eclipse.papyrus.infra.nattable.model.nattable.nattableconfiguration.NattableconfigurationPackage;
+import org.eclipse.papyrus.infra.nattable.model.nattable.nattableproblem.NattableproblemFactory;
+import org.eclipse.papyrus.infra.nattable.model.nattable.nattableproblem.NattableproblemPackage;
+import org.eclipse.papyrus.infra.nattable.model.nattable.nattableproblem.Problem;
+import org.eclipse.papyrus.infra.nattable.model.nattable.nattableproblem.StringResolutionProblem;
+import org.eclipse.papyrus.infra.nattable.paste.IValueSetter;
+import org.eclipse.papyrus.infra.nattable.paste.ReferenceValueSetter;
+import org.eclipse.papyrus.infra.services.edit.service.ElementEditServiceUtils;
+import org.eclipse.papyrus.infra.services.edit.service.IElementEditService;
+import org.eclipse.papyrus.infra.tools.converter.ConvertedValueContainer;
+import org.eclipse.papyrus.infra.tools.converter.StringValueConverterStatus;
+
+
+public class CellHelper {
+
+ private CellHelper() {
+ //to prevent instanciation
+ }
+
+ /**
+ * Create the string problems if required
+ *
+ * @param tableManager
+ * @param columnElement
+ * @param rowElement
+ * @param pastedText
+ * @param valueContainer
+ * @param sharedMap
+ */
+ public static final void createStringResolutionProblem(final INattableModelManager tableManager, final Object columnElement, final Object rowElement, final String pastedText, final ConvertedValueContainer<?> valueContainer, final Map<?, ?> sharedMap) {
+ final IStatus status = valueContainer.getStatus();
+ if(!status.isOK()) {
+ if(status.matches(IStatus.ERROR)) {
+ @SuppressWarnings("unchecked")
+ final List<IValueSetter> references = (List<IValueSetter>)sharedMap.get(Constants.REFERENCES_TO_SET_KEY);
+ if(status.matches(IStatus.ERROR)) {
+ Cell cell = tableManager.getCell(columnElement, rowElement);
+
+ if(cell == null) {
+ //we create the cell
+ cell = NattablecellFactory.eINSTANCE.createCell();
+
+ //create the columnWrapper;
+ final Object column = AxisUtils.getRepresentedElement(columnElement);
+ ICellAxisWrapper columnWrapper = null;
+ if(column instanceof String) {
+ columnWrapper = NattablecellFactory.eINSTANCE.createIdAxisWrapper();
+ ((IdAxisWrapper)columnWrapper).setElement((String)column);
+ } else if(column instanceof EObject) {
+ columnWrapper = NattablecellFactory.eINSTANCE.createEObjectAxisWrapper();
+ ReferenceValueSetter structure = new ReferenceValueSetter(columnWrapper, NattablecellPackage.eINSTANCE.getEObjectAxisWrapper_Element(), column);
+ references.add(structure);
+ }
+
+ final Object row = AxisUtils.getRepresentedElement(rowElement);
+ ICellAxisWrapper rowWrapper = null;
+ if(row instanceof String) {
+ rowWrapper = NattablecellFactory.eINSTANCE.createIdAxisWrapper();
+ ((IdAxisWrapper)rowWrapper).setElement((String)row);
+ } else if(row instanceof EObject) {
+ rowWrapper = NattablecellFactory.eINSTANCE.createEObjectAxisWrapper();
+ ReferenceValueSetter structure = new ReferenceValueSetter(rowWrapper, NattablecellPackage.eINSTANCE.getEObjectAxisWrapper_Element(), row);
+ references.add(structure);
+ }
+
+ if(rowWrapper == null || columnWrapper == null) {
+ throw new UnsupportedOperationException("Case not managed"); //$NON-NLS-1$
+ }
+ cell.setColumnWrapper(columnWrapper);
+ cell.setRowWrapper(rowWrapper);
+ @SuppressWarnings("unchecked")
+ final List<Cell> cells = (List<Cell>)sharedMap.get(Constants.CELLS_TO_ADD_KEY);
+ cells.add(cell);
+
+
+ }
+
+
+ final StringResolutionProblem problem = NattableproblemFactory.eINSTANCE.createStringResolutionProblem();
+ problem.setName("Set Value As Text Problem"); //$NON-NLS-1$
+ problem.setDescription(status.getMessage());
+ problem.setValueAsString(pastedText);
+
+ if(status instanceof StringValueConverterStatus) {
+ problem.getUnresolvedString().addAll(((StringValueConverterStatus)status).getUnresolvedString());
+ }
+
+ if(cell.eContainer() == null) {
+ cell.eSet(NattablecellPackage.eINSTANCE.getCell_Problems(), Collections.singleton(problem));
+ } else {
+ final ReferenceValueSetter structure = new ReferenceValueSetter(cell, NattablecellPackage.eINSTANCE.getCell_Problems(), problem);
+ references.add(structure);
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ *
+ * @param domain
+ * the editing domain
+ * @param tableManager
+ * the table manager
+ * @param rowElement
+ * the row element
+ * @param columnElement
+ * the column element
+ * @param pastedText
+ * the pasted text
+ * @param valueContainer
+ * the converted value
+ * @return
+ * the command to create a String resolution Problem
+ */
+ public static final Command getCreateStringResolutionProblemCommand(final TransactionalEditingDomain domain, final INattableModelManager tableManager, final Object columnElement, final Object rowElement, final String pastedText, final ConvertedValueContainer<?> valueContainer) {
+ final IStatus status = valueContainer.getStatus();
+ if(!status.isOK()) {
+ if(status.matches(IStatus.ERROR)) {
+ final CompositeCommand command = new CompositeCommand("Create Cell For Error Command"); //$NON-NLS-1$
+ Cell cell = tableManager.getCell(columnElement, rowElement);
+
+ if(cell == null) {
+ //we create the cell
+ final Table table = tableManager.getTable();
+ cell = NattablecellFactory.eINSTANCE.createCell();
+
+ SetRequest request = new SetRequest(domain, table, NattablePackage.eINSTANCE.getTable_Cells(), cell);
+ IElementEditService provider = ElementEditServiceUtils.getCommandProvider(table);
+ command.add(provider.getEditCommand(request));
+
+ //create the columnWrapper;
+ final Object column = AxisUtils.getRepresentedElement(columnElement);
+ ICellAxisWrapper columnWrapper = null;
+ if(column instanceof String) {
+ columnWrapper = NattablecellFactory.eINSTANCE.createIdAxisWrapper();
+ provider = ElementEditServiceUtils.getCommandProvider(columnWrapper);
+ request = new SetRequest(domain, columnWrapper, NattablecellPackage.eINSTANCE.getIdAxisWrapper_Element(), column);
+ command.add(provider.getEditCommand(request));
+ } else if(column instanceof EObject) {
+ columnWrapper = NattablecellFactory.eINSTANCE.createEObjectAxisWrapper();
+ provider = ElementEditServiceUtils.getCommandProvider(columnWrapper);
+ request = new SetRequest(domain, columnWrapper, NattablecellPackage.eINSTANCE.getEObjectAxisWrapper_Element(), column);
+ command.add(provider.getEditCommand(request));
+ }
+
+ final Object row = AxisUtils.getRepresentedElement(rowElement);
+ ICellAxisWrapper rowWrapper = null;
+ if(row instanceof String) {
+ rowWrapper = NattablecellFactory.eINSTANCE.createIdAxisWrapper();
+ provider = ElementEditServiceUtils.getCommandProvider(rowWrapper);
+ request = new SetRequest(domain, rowWrapper, NattablecellPackage.eINSTANCE.getIdAxisWrapper_Element(), row);
+ command.add(provider.getEditCommand(request));
+ } else if(row instanceof EObject) {
+ rowWrapper = NattablecellFactory.eINSTANCE.createEObjectAxisWrapper();
+ provider = ElementEditServiceUtils.getCommandProvider(rowWrapper);
+ request = new SetRequest(domain, rowWrapper, NattablecellPackage.eINSTANCE.getEObjectAxisWrapper_Element(), row);
+ command.add(provider.getEditCommand(request));
+ }
+
+ if(rowWrapper == null || columnWrapper == null) {
+ throw new UnsupportedOperationException("Case not managed"); //$NON-NLS-1$
+ }
+
+
+ provider = ElementEditServiceUtils.getCommandProvider(cell);
+ request = new SetRequest(domain, cell, NattablecellPackage.eINSTANCE.getCell_ColumnWrapper(), columnWrapper);
+ command.add(provider.getEditCommand(request));
+ request = new SetRequest(domain, cell, NattablecellPackage.eINSTANCE.getCell_RowWrapper(), rowWrapper);
+ command.add(provider.getEditCommand(request));
+ }
+ final List<Problem> problems = cell.getProblems();
+ StringResolutionProblem problem = null;
+ for(final Problem current : problems) {
+ if(current instanceof StringResolutionProblem) {
+ problem = (StringResolutionProblem)current;
+ break;
+ }
+ }
+
+ //we create a new string problem
+ if(problem == null) {
+ problem = NattableproblemFactory.eINSTANCE.createStringResolutionProblem();
+ problem.setName("Set Value As Text Problem"); //$NON-NLS-1$
+ problem.setDescription(status.getMessage());
+ problem.setValueAsString(pastedText);
+
+ if(status instanceof StringValueConverterStatus) {
+ problem.getUnresolvedString().addAll(((StringValueConverterStatus)status).getUnresolvedString());
+ SetRequest setProblemRequest = new SetRequest(domain, cell, NattablecellPackage.eINSTANCE.getCell_Problems(), problem);
+ IElementEditService provider = ElementEditServiceUtils.getCommandProvider(cell);
+ command.add(provider.getEditCommand(setProblemRequest));
+ } else {//we update the string problem
+ IElementEditService provider = ElementEditServiceUtils.getCommandProvider(problem);
+ SetRequest request = new SetRequest(domain, problem, NattableproblemPackage.eINSTANCE.getStringResolutionProblem_ValueAsString(), pastedText);
+ command.add(provider.getEditCommand(request));
+ request = new SetRequest(domain, problem, NattableproblemPackage.eINSTANCE.getStringResolutionProblem_UnresolvedString(), ((StringValueConverterStatus)status).getUnresolvedString());
+ command.add(provider.getEditCommand(request));
+ request = new SetRequest(domain, problem, NattableconfigurationPackage.eINSTANCE.getTableNamedElement_Description(), status.getMessage());
+ command.add(provider.getEditCommand(request));
+ }
+ }
+
+ return new GMFtoEMFCommandWrapper(command);
+ }
+ }
+ return null;
+ }
+
+}
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/utils/PasteConfigurationUtils.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/utils/PasteConfigurationUtils.java
index f8392084e83..bbd3d6aeae1 100644
--- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/utils/PasteConfigurationUtils.java
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/utils/PasteConfigurationUtils.java
@@ -47,11 +47,13 @@ public class PasteConfigurationUtils {
final EStructuralFeature feature = pasteConfiguration.getPasteElementContainementFeature();
if(feature instanceof EReference) {
final String elementId = pasteConfiguration.getPastedElementId();
- if(elementId != null && !elementId.equals("")) {
+ if(elementId != null && !elementId.equals("")) { //$NON-NLS-1$
final IElementType elementType = ElementTypeRegistry.getInstance().getType(elementId);
- final EClass elementTypeMetaclass = elementType.getEClass();
- final EClass containmentFeatureEClass = (EClass)feature.getEType();
- result = elementTypeMetaclass == containmentFeatureEClass || containmentFeatureEClass.isSuperTypeOf(elementTypeMetaclass);
+ if(elementType != null) {
+ final EClass elementTypeMetaclass = elementType.getEClass();
+ final EClass containmentFeatureEClass = (EClass)feature.getEType();
+ result = elementTypeMetaclass == containmentFeatureEClass || containmentFeatureEClass.isSuperTypeOf(elementTypeMetaclass);
+ }
}
}
}

Back to the top