diff options
author | Nicolas FAUVERGUE | 2016-01-05 14:41:04 +0000 |
---|---|---|
committer | Gerrit Code Review @ Eclipse.org | 2016-02-18 13:12:41 +0000 |
commit | 42519e5017f327886d638c8b186356d9b740a561 (patch) | |
tree | 12cb2e1b180e9629165d06596856b37ea04e2641 /plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus | |
parent | 7ba44c7a4107388464ddbea256ed6072a063b1a6 (diff) | |
download | org.eclipse.papyrus-42519e5017f327886d638c8b186356d9b740a561.tar.gz org.eclipse.papyrus-42519e5017f327886d638c8b186356d9b740a561.tar.xz org.eclipse.papyrus-42519e5017f327886d638c8b186356d9b740a561.zip |
Bug 454858: [Table] Undo redo after paste doesn't work
https://bugs.eclipse.org/bugs/show_bug.cgi?id=454858
Manage the basic paste with a global compound command which allows the
undo/redo of this paste/import.
Change-Id: If0091e28b9c2466a2c02b5b68de692d8265879aa
Signed-off-by: Nicolas FAUVERGUE <nicolas.fauvergue@all4tec.net>
Diffstat (limited to 'plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus')
6 files changed, 216 insertions, 49 deletions
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/messages/Messages.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/messages/Messages.java index 71115e9060e..59feb5454c7 100644 --- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/messages/Messages.java +++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/messages/Messages.java @@ -324,6 +324,8 @@ public class Messages extends NLS { public static String PasteConfigurationUtils_PasteConfigurationIsConsistent; public static String PasteEObjectAxisInTableCommandProvider_AddingElementToTheTable; + + public static String PasteEObjectAxisInTableCommandProvider_AddRowsCommandName; public static String PasteEObjectAxisInTableCommandProvider_CommandCreationHasBeenCancelled; @@ -340,6 +342,8 @@ public class Messages extends NLS { public static String PasteEObjectAxisInTableCommandProvider_PasteColumns; public static String PasteEObjectAxisInTableCommandProvider_PasteFromStringCommand; + + public static String PasteEObjectAxisInTableCommandProvider_PasteInTableCommandName; public static String PasteEObjectAxisInTableCommandProvider_PasteRows; diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/messages/messages.properties b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/messages/messages.properties index 3a5a4145310..9fc640fc39f 100644 --- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/messages/messages.properties +++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/messages/messages.properties @@ -151,6 +151,7 @@ PasteConfigurationUtils_ElementIdNotDefined=The element id describing the kind o PasteConfigurationUtils_ElementTypeCantBeFound=The element type for {0} can be found. PasteConfigurationUtils_PasteConfigurationIsConsistent=The paste configuration is consistent. PasteEObjectAxisInTableCommandProvider_AddingElementToTheTable=Adding Elements To The table +PasteEObjectAxisInTableCommandProvider_AddRowsCommandName=Add rows PasteEObjectAxisInTableCommandProvider_CommandCreationHasBeenCancelled=Command creation has been cancelled PasteEObjectAxisInTableCommandProvider_CreatingAnumberXonY=\ Creating {0} number {1}/{2} PasteEObjectAxisInTableCommandProvider_DoingAdditionalActions=Doing additional actions @@ -159,6 +160,7 @@ PasteEObjectAxisInTableCommandProvider_LinkingReferencesToTheModel=Linking refer PasteEObjectAxisInTableCommandProvider_PasteAction=Paste Action PasteEObjectAxisInTableCommandProvider_PasteColumns=Paste Columns PasteEObjectAxisInTableCommandProvider_PasteFromStringCommand=Paste from String Command +PasteEObjectAxisInTableCommandProvider_PasteInTableCommandName=Paste in table PasteEObjectAxisInTableCommandProvider_PasteRows=Paste Rows PasteEObjectTreeAxisInNatTableCommandProvider_CantPasteColumnsInTreeTable=We can't paste columns in a tree table PasteImportHandler_EmptyClipboardString=Can't paste/insert with empty clipboard diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/provider/PasteEObjectAxisInNattableCommandProvider.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/provider/PasteEObjectAxisInNattableCommandProvider.java index a503c21fae0..7f4b963a302 100644 --- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/provider/PasteEObjectAxisInNattableCommandProvider.java +++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/provider/PasteEObjectAxisInNattableCommandProvider.java @@ -39,9 +39,11 @@ import org.eclipse.core.commands.ExecutionException; import org.eclipse.core.runtime.IAdaptable; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.MultiStatus; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.Status; import org.eclipse.emf.common.command.Command; +import org.eclipse.emf.common.command.CompoundCommand; import org.eclipse.emf.ecore.EClass; import org.eclipse.emf.ecore.EFactory; import org.eclipse.emf.ecore.EObject; @@ -59,7 +61,9 @@ import org.eclipse.nebula.widgets.nattable.selection.SelectionLayer; import org.eclipse.nebula.widgets.nattable.selection.command.SelectRowsCommand; import org.eclipse.osgi.util.NLS; import org.eclipse.papyrus.infra.emf.gmf.command.CheckedOperationHistory; +import org.eclipse.papyrus.infra.emf.gmf.command.GMFtoEMFCommandWrapper; import org.eclipse.papyrus.infra.nattable.Activator; +import org.eclipse.papyrus.infra.nattable.command.ErrorTransactionalCommand; import org.eclipse.papyrus.infra.nattable.manager.cell.CellManagerFactory; import org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager; import org.eclipse.papyrus.infra.nattable.messages.Messages; @@ -76,6 +80,7 @@ import org.eclipse.papyrus.infra.nattable.paste.PastePostActionRegistry; import org.eclipse.papyrus.infra.nattable.utils.AxisConfigurationUtils; import org.eclipse.papyrus.infra.nattable.utils.CSVPasteHelper; import org.eclipse.papyrus.infra.nattable.utils.Constants; +import org.eclipse.papyrus.infra.nattable.utils.ExtendedCompoundCommand; import org.eclipse.papyrus.infra.nattable.utils.TableEditingDomainUtils; import org.eclipse.papyrus.infra.services.edit.service.ElementEditServiceUtils; import org.eclipse.papyrus.infra.services.edit.service.IElementEditService; @@ -476,6 +481,8 @@ public class PasteEObjectAxisInNattableCommandProvider implements PasteNattableC @Override protected CommandResult doExecuteWithResult(final IProgressMonitor monitor, final IAdaptable info) throws ExecutionException { + final ExtendedCompoundCommand compoundCommand = new ExtendedCompoundCommand(Messages.PasteEObjectAxisInTableCommandProvider_PasteInTableCommandName); + // initialize lists final Collection<String> postActions = getPostActions(); @@ -506,7 +513,7 @@ public class PasteEObjectAxisInNattableCommandProvider implements PasteNattableC } // 1. Add the elements to the context - AddCommand.create(contextEditingDomain, tableContext, containmentFeature, createdElements).execute(); + compoundCommand.append(AddCommand.create(contextEditingDomain, tableContext, containmentFeature, createdElements)); if (progressMonitor != null) { if (progressMonitor.isCanceled()) { @@ -522,8 +529,8 @@ public class PasteEObjectAxisInNattableCommandProvider implements PasteNattableC } else { cmd = tableManager.getAddRowElementCommand(createdElements); } - if (cmd != null) {// could be null - cmd.execute(); + if (null != cmd) {// could be null + compoundCommand.append(cmd); } if (progressMonitor != null) { @@ -572,7 +579,12 @@ public class PasteEObjectAxisInNattableCommandProvider implements PasteNattableC } // add the created cells to the table - AddCommand.create(tableEditingDomain, table, NattablePackage.eINSTANCE.getTable_Cells(), cells).execute(); + compoundCommand.append(AddCommand.create(tableEditingDomain, table, NattablePackage.eINSTANCE.getTable_Cells(), cells)); + + // Execute the global command + if (null != compoundCommand && !compoundCommand.isEmpty() && compoundCommand.canExecute()) { + tableEditingDomain.getCommandStack().execute(compoundCommand); + } if (progressMonitor != null) { progressMonitor.done(); @@ -641,6 +653,10 @@ public class PasteEObjectAxisInNattableCommandProvider implements PasteNattableC */ @Override protected CommandResult doExecuteWithResult(final IProgressMonitor monitor, final IAdaptable info) throws ExecutionException { + final ExtendedCompoundCommand compoundCommand = new ExtendedCompoundCommand(Messages.PasteEObjectAxisInTableCommandProvider_PasteInTableCommandName); + + final List<IStatus> resultStatus = new ArrayList<IStatus>(); + long readChar = 0; long previousreadChar = 0; @@ -667,12 +683,15 @@ public class PasteEObjectAxisInNattableCommandProvider implements PasteNattableC final ICommand commandCreation = tableContextCommandProvider.getEditCommand(createRequest); if (commandCreation.canExecute()) { // 1. we create the element - commandCreation.execute(monitor, info); // we execute the creation command + final Command emfCommandCreation = GMFtoEMFCommandWrapper.wrap(commandCreation); + emfCommandCreation.execute(); + + // Add the creation command to the compound command + compoundCommand.append(emfCommandCreation); // 2. we add it to the table final CommandResult res = commandCreation.getCommandResult(); - commandCreation.dispose(); final Object createdElement = res.getReturnValue(); final Command addCommand; @@ -681,9 +700,8 @@ public class PasteEObjectAxisInNattableCommandProvider implements PasteNattableC } else { addCommand = tableManager.getAddRowElementCommand(Collections.singleton(createdElement)); } - if (addCommand != null) {// can be null - addCommand.execute(); - addCommand.dispose(); + if (null != addCommand) {// can be null + compoundCommand.append(addCommand); } // 3. we set the values @@ -707,9 +725,13 @@ public class PasteEObjectAxisInNattableCommandProvider implements PasteNattableC if (isEditable) { final AbstractStringValueConverter converter = CellManagerFactory.INSTANCE.getOrCreateStringValueConverterClass(columnObject, rowObject, tableManager, existingConverters, pasteHelper.getMultiValueSeparator()); final Command setValueCommand = CellManagerFactory.INSTANCE.getSetStringValueCommand(contextEditingDomain, columnObject, rowObject, valueAsString, converter, tableManager); - if (setValueCommand != null && setValueCommand.canExecute()) { - setValueCommand.execute(); - setValueCommand.dispose(); + final IStatus commandStatus = getStatusCommand(setValueCommand); + if (!commandStatus.isOK()) { + resultStatus.add(commandStatus); + } else { + if (null != setValueCommand) { + compoundCommand.append(setValueCommand); + } } } } @@ -719,14 +741,55 @@ public class PasteEObjectAxisInNattableCommandProvider implements PasteNattableC } } } + + // Execute the global command + if (null != compoundCommand && !compoundCommand.isEmpty() && compoundCommand.canExecute()) { + tableEditingDomain.getCommandStack().execute(compoundCommand); + } + progressMonitor.done(); localDispose(); - return CommandResult.newOKCommandResult(); + if (resultStatus.isEmpty()) { + return CommandResult.newOKCommandResult(); + } else { + final IStatus resultingStatus = new MultiStatus(Activator.PLUGIN_ID, IStatus.OK, resultStatus.toArray(new IStatus[resultStatus.size()]), "The paste has been done, but we found some problems", null); + return new CommandResult(resultingStatus); + } } }; return pasteAllCommand; } + /** + * Get the status of the EMF command (containing compound command or gmf command). + * + * @param command + * The command. + * @return The status of the corresponding command. + */ + protected IStatus getStatusCommand(final Command command) { + IStatus resultStatus = Status.OK_STATUS; + + if (command instanceof CompoundCommand) { + final Iterator<Command> subCommandIterator = ((CompoundCommand) command).getCommandList().iterator(); + while (subCommandIterator.hasNext() && resultStatus.isOK()) { + final Command subCommand = subCommandIterator.next(); + if (command instanceof CompoundCommand) { + IStatus subStatus = getStatusCommand(subCommand); + if (!subStatus.isOK()) { + resultStatus = subStatus; + } + } + } + } else if (command instanceof GMFtoEMFCommandWrapper) { + ICommand gmfCommand = ((GMFtoEMFCommandWrapper) command).getGMFCommand(); + if (gmfCommand instanceof ErrorTransactionalCommand) { + resultStatus = ((ErrorTransactionalCommand) gmfCommand).getStatus(); + } + } + + return resultStatus; + } /** * @@ -760,6 +823,10 @@ public class PasteEObjectAxisInNattableCommandProvider implements PasteNattableC */ @Override protected CommandResult doExecuteWithResult(final IProgressMonitor monitor, final IAdaptable info) throws ExecutionException { + final ExtendedCompoundCommand compoundCommand = new ExtendedCompoundCommand(Messages.PasteEObjectAxisInTableCommandProvider_PasteInTableCommandName); + + final List<IStatus> resultStatus = new ArrayList<IStatus>(); + long readChar = 0; long previousreadChar = 0; @@ -786,12 +853,15 @@ public class PasteEObjectAxisInNattableCommandProvider implements PasteNattableC final ICommand commandCreation = tableContextCommandProvider.getEditCommand(createRequest); if (commandCreation.canExecute()) { // 1. we create the element - commandCreation.execute(monitor, info); // we execute the creation command + final Command emfCommandCreation = GMFtoEMFCommandWrapper.wrap(commandCreation); + emfCommandCreation.execute(); + + // Add the creation command to the compound command + compoundCommand.append(emfCommandCreation); // 2. we add it to the table final CommandResult res = commandCreation.getCommandResult(); - commandCreation.dispose(); final Object createdElement = res.getReturnValue(); final Command addCommand; @@ -800,9 +870,8 @@ public class PasteEObjectAxisInNattableCommandProvider implements PasteNattableC } else { addCommand = tableManager.getAddRowElementCommand(Collections.singleton(createdElement)); } - if (addCommand != null) {// can be null - addCommand.execute(); - addCommand.dispose(); + if (null != addCommand) {// can be null + compoundCommand.append(addCommand); } // 3. we set the values @@ -825,9 +894,13 @@ public class PasteEObjectAxisInNattableCommandProvider implements PasteNattableC if (isEditable) { final AbstractStringValueConverter converter = CellManagerFactory.INSTANCE.getOrCreateStringValueConverterClass(columnObject, rowObject, tableManager, existingConverters, pasteHelper.getMultiValueSeparator()); final Command setValueCommand = CellManagerFactory.INSTANCE.getSetStringValueCommand(contextEditingDomain, columnObject, rowObject, valueAsString, converter, tableManager); - if (setValueCommand != null && setValueCommand.canExecute()) { - setValueCommand.execute(); - setValueCommand.dispose(); + final IStatus commandStatus = getStatusCommand(setValueCommand); + if (!commandStatus.isOK()) { + resultStatus.add(commandStatus); + } else { + if (null != setValueCommand) { + compoundCommand.append(setValueCommand); + } } } } @@ -837,9 +910,20 @@ public class PasteEObjectAxisInNattableCommandProvider implements PasteNattableC } } } + + // Execute the global command + if (null != compoundCommand && !compoundCommand.isEmpty() && compoundCommand.canExecute()) { + tableEditingDomain.getCommandStack().execute(compoundCommand); + } + progressMonitor.done(); localDispose(); - return CommandResult.newOKCommandResult(); + if (resultStatus.isEmpty()) { + return CommandResult.newOKCommandResult(); + } else { + final IStatus resultingStatus = new MultiStatus(Activator.PLUGIN_ID, IStatus.OK, resultStatus.toArray(new IStatus[resultStatus.size()]), "The paste has been done, but we found some problems", null); + return new CommandResult(resultingStatus); + } } }; return pasteAllCommand; diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/provider/PasteEObjectTreeAxisInNattableCommandProvider.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/provider/PasteEObjectTreeAxisInNattableCommandProvider.java index b3b6c7042aa..8863552fa75 100644 --- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/provider/PasteEObjectTreeAxisInNattableCommandProvider.java +++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/provider/PasteEObjectTreeAxisInNattableCommandProvider.java @@ -33,11 +33,14 @@ import org.eclipse.core.runtime.MultiStatus; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.Status; import org.eclipse.emf.common.command.Command; +import org.eclipse.emf.common.command.CompoundCommand; import org.eclipse.emf.ecore.EClass; import org.eclipse.emf.ecore.EFactory; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.EReference; import org.eclipse.emf.ecore.EStructuralFeature; +import org.eclipse.emf.edit.command.AddCommand; +import org.eclipse.emf.edit.command.SetCommand; import org.eclipse.emf.transaction.TransactionalEditingDomain; import org.eclipse.emf.workspace.EMFCommandOperation; import org.eclipse.gmf.runtime.common.core.command.CommandResult; @@ -54,6 +57,7 @@ import org.eclipse.osgi.util.NLS; import org.eclipse.papyrus.infra.emf.gmf.command.CheckedOperationHistory; import org.eclipse.papyrus.infra.emf.gmf.command.GMFtoEMFCommandWrapper; import org.eclipse.papyrus.infra.nattable.Activator; +import org.eclipse.papyrus.infra.nattable.command.ErrorTransactionalCommand; import org.eclipse.papyrus.infra.nattable.manager.cell.CellManagerFactory; import org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager; import org.eclipse.papyrus.infra.nattable.messages.Messages; @@ -72,6 +76,7 @@ import org.eclipse.papyrus.infra.nattable.paste.IValueSetter; import org.eclipse.papyrus.infra.nattable.utils.AxisConfigurationUtils; import org.eclipse.papyrus.infra.nattable.utils.CSVPasteHelper; import org.eclipse.papyrus.infra.nattable.utils.Constants; +import org.eclipse.papyrus.infra.nattable.utils.ExtendedCompoundCommand; import org.eclipse.papyrus.infra.nattable.utils.FillingConfigurationUtils; import org.eclipse.papyrus.infra.nattable.utils.PasteSeverityCode; import org.eclipse.papyrus.infra.nattable.utils.PasteTreeUtils; @@ -546,6 +551,11 @@ public class PasteEObjectTreeAxisInNattableCommandProvider implements PasteNatta @SuppressWarnings("unchecked") @Override protected CommandResult doExecuteWithResult(final IProgressMonitor monitor, final IAdaptable info) throws ExecutionException { + final ExtendedCompoundCommand compoundCommand = new ExtendedCompoundCommand(Messages.PasteEObjectAxisInTableCommandProvider_PasteInTableCommandName); + + // Manage a list of created elements to create a unique add command for all created elements + final List<Object> objectsToAdd = new ArrayList<Object>(); + final List<IStatus> resultStatus = new ArrayList<IStatus>(); long readChar = 0; @@ -656,9 +666,9 @@ public class PasteEObjectTreeAxisInNattableCommandProvider implements PasteNatta final EObject context = contextMap.get(depth - 1); final EStructuralFeature containmentFeature = pasteConfToUse.getPasteElementContainementFeature(); if (containmentFeature.isMany()) { - ((Collection<EObject>) context.eGet(containmentFeature)).add(eobject); + compoundCommand.append(AddCommand.create(getEditingDomain(), context, containmentFeature, eobject)); } else { - context.eSet(containmentFeature, createdElement); + compoundCommand.append(SetCommand.create(getEditingDomain(), context, containmentFeature, eobject)); } // get the feature used as ID for the element @@ -667,13 +677,8 @@ public class PasteEObjectTreeAxisInNattableCommandProvider implements PasteNatta eobject.eSet(nameFeature, valueAsString); } // we add the created element to the table, only if its parent is the context of the table and if the table is filled by DnD - if (!FillingConfigurationUtils.hasTreeFillingConfigurationForDepth(table, 0) && ((EObject) createdElement).eContainer() == tableContext) { - final Command addCommand = tableManager.getAddRowElementCommand(Collections.singleton(createdElement)); - - if (addCommand != null) {// can be null - addCommand.execute(); - addCommand.dispose(); - } + if (!FillingConfigurationUtils.hasTreeFillingConfigurationForDepth(table, 0) && context.equals(tableContext)) { + objectsToAdd.add(createdElement); } } @@ -716,6 +721,23 @@ public class PasteEObjectTreeAxisInNattableCommandProvider implements PasteNatta } } + // Manage the rows to add by a final command (manage it at the end of the global command) + final CompoundCommand addRowsCommand = new CompoundCommand(Messages.PasteEObjectAxisInTableCommandProvider_AddRowsCommandName); + for (final Object createdElement : objectsToAdd) { + final Command addRowElementCommand = tableManager.getAddRowElementCommand(Collections.singleton(createdElement)); + if (addRowElementCommand.canExecute()) { + addRowsCommand.append(addRowElementCommand); + } + } + if (!addRowsCommand.isEmpty()) { + compoundCommand.append(addRowsCommand); + } + + // Execute the global command + if (null != compoundCommand && !compoundCommand.isEmpty() && compoundCommand.canExecute()) { + tableEditingDomain.getCommandStack().execute(compoundCommand); + } + progressMonitor.done(); localDispose(); if (resultStatus.isEmpty()) { @@ -953,6 +975,11 @@ public class PasteEObjectTreeAxisInNattableCommandProvider implements PasteNatta */ @Override protected CommandResult doExecuteWithResult(final IProgressMonitor monitor, final IAdaptable info) throws ExecutionException { + final ExtendedCompoundCommand compoundCommand = new ExtendedCompoundCommand(Messages.PasteEObjectAxisInTableCommandProvider_PasteInTableCommandName); + + // Manage a list of created elements to create a unique add command for all created elements + final List<Object> objectsToAdd = new ArrayList<Object>(); + final List<IStatus> resultStatus = new ArrayList<IStatus>(); long readChar = 0; @@ -1068,11 +1095,14 @@ public class PasteEObjectTreeAxisInNattableCommandProvider implements PasteNatta if (null != commandCreation && commandCreation.canExecute()) { // 1. we create the element - commandCreation.execute(monitor, info); + final Command emfCommandCreation = GMFtoEMFCommandWrapper.wrap(commandCreation); + emfCommandCreation.execute(); + + // Add the creation command to the compound command + compoundCommand.append(emfCommandCreation); // 2. we get the result of the command final CommandResult res = commandCreation.getCommandResult(); - commandCreation.dispose(); // 3 we update the map final Object createdElement = res.getReturnValue(); @@ -1092,18 +1122,19 @@ public class PasteEObjectTreeAxisInNattableCommandProvider implements PasteNatta if (createdElementCommandProvider != null) { final ICommand setName = createdElementCommandProvider.getEditCommand(setNameRequest); if (setName != null && setName.canExecute()) { - setName.execute(monitor, info); + + // 1. we create the element + final Command emfSetNameCommandCreation = GMFtoEMFCommandWrapper.wrap(setName); + emfSetNameCommandCreation.execute(); + + // Add the set name command to the compound command + compoundCommand.append(emfSetNameCommandCreation); } } } // we add the created element to the table, only if its parent is the context of the table and if the table is filled by DnD if (!FillingConfigurationUtils.hasTreeFillingConfigurationForDepth(table, 0) && ((EObject) createdElement).eContainer() == tableContext) { - final Command addCommand = tableManager.getAddRowElementCommand(Collections.singleton(createdElement)); - - if (addCommand != null) {// can be null - addCommand.execute(); - addCommand.dispose(); - } + objectsToAdd.add(createdElement); } } @@ -1138,14 +1169,13 @@ public class PasteEObjectTreeAxisInNattableCommandProvider implements PasteNatta if (isEditable) { final AbstractStringValueConverter converter = CellManagerFactory.INSTANCE.getOrCreateStringValueConverterClass(columnObject, rowObject, tableManager, existingConverters, pasteHelper.getMultiValueSeparator()); final Command setValueCommand = CellManagerFactory.INSTANCE.getSetStringValueCommand(contextEditingDomain, columnObject, rowObject, valueAsString, converter, tableManager); - if (setValueCommand != null && setValueCommand.canExecute()) { - try { - setValueCommand.execute(); - } catch (final Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); + final IStatus commandStatus = getStatusCommand(setValueCommand); + if (!commandStatus.isOK()) { + resultStatus.add(commandStatus); + } else { + if (null != setValueCommand) { + compoundCommand.append(setValueCommand); } - setValueCommand.dispose(); } } } @@ -1164,6 +1194,24 @@ public class PasteEObjectTreeAxisInNattableCommandProvider implements PasteNatta } } } + + // Manage the rows to add by a final command (manage it at the end of the global command) + final CompoundCommand addRowsCommand = new CompoundCommand(Messages.PasteEObjectAxisInTableCommandProvider_AddRowsCommandName); + for (final Object createdElement : objectsToAdd) { + final Command addRowElementCommand = tableManager.getAddRowElementCommand(Collections.singleton(createdElement)); + if (addRowElementCommand.canExecute()) { + addRowsCommand.append(addRowElementCommand); + } + } + if (!addRowsCommand.isEmpty()) { + compoundCommand.append(addRowsCommand); + } + + // Execute the global command + if (null != compoundCommand && !compoundCommand.isEmpty() && compoundCommand.canExecute()) { + tableEditingDomain.getCommandStack().execute(compoundCommand); + } + progressMonitor.done(); localDispose(); if (resultStatus.isEmpty()) { @@ -1178,6 +1226,37 @@ public class PasteEObjectTreeAxisInNattableCommandProvider implements PasteNatta } /** + * Get the status of the EMF command (containing compound command or gmf command). + * + * @param command + * The command. + * @return The status of the corresponding command. + */ + protected IStatus getStatusCommand(final Command command) { + IStatus resultStatus = Status.OK_STATUS; + + if (command instanceof CompoundCommand) { + final Iterator<Command> subCommandIterator = ((CompoundCommand) command).getCommandList().iterator(); + while (subCommandIterator.hasNext() && resultStatus.isOK()) { + final Command subCommand = subCommandIterator.next(); + if (command instanceof CompoundCommand) { + IStatus subStatus = getStatusCommand(subCommand); + if (!subStatus.isOK()) { + resultStatus = subStatus; + } + } + } + } else if (command instanceof GMFtoEMFCommandWrapper) { + ICommand gmfCommand = ((GMFtoEMFCommandWrapper) command).getGMFCommand(); + if (gmfCommand instanceof ErrorTransactionalCommand) { + resultStatus = ((ErrorTransactionalCommand) gmfCommand).getStatus(); + } + } + + return resultStatus; + } + + /** * Get the paste command for the attached mode. * * @param contextEditingDomain diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/provider/PasteInSelectionNattableCommandProvider.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/provider/PasteInSelectionNattableCommandProvider.java index e517050a77f..bb9f9c4c7b5 100644 --- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/provider/PasteInSelectionNattableCommandProvider.java +++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/provider/PasteInSelectionNattableCommandProvider.java @@ -167,7 +167,6 @@ public class PasteInSelectionNattableCommandProvider extends AbstractPasteInSele // we add it to the table final CommandResult res = commandCreation.getCommandResult(); - commandCreation.dispose(); createdElement = res.getReturnValue(); } diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/provider/PasteInSelectionTreeNattableCommandProvider.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/provider/PasteInSelectionTreeNattableCommandProvider.java index 1f73858476b..1a5bd3f28ef 100644 --- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/provider/PasteInSelectionTreeNattableCommandProvider.java +++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/provider/PasteInSelectionTreeNattableCommandProvider.java @@ -259,7 +259,6 @@ public class PasteInSelectionTreeNattableCommandProvider extends PasteInSelectio // we get the result of the command final CommandResult res = commandCreation.getCommandResult(); - commandCreation.dispose(); // we update the map createdElement = res.getReturnValue(); |