diff options
author | Nicolas FAUVERGUE | 2015-12-18 10:46:35 +0000 |
---|---|---|
committer | Gerrit Code Review @ Eclipse.org | 2016-01-07 14:51:07 +0000 |
commit | e04253ba4cbc604774d4493271fdaf3b9a4877bb (patch) | |
tree | 520a7e6a1584c7d5c5bba0bbbc036094a05892e6 /plugins/infra | |
parent | fd7d122d0e2d3e7d1d314c9591c0a37eb6fc812d (diff) | |
download | org.eclipse.papyrus-e04253ba4cbc604774d4493271fdaf3b9a4877bb.tar.gz org.eclipse.papyrus-e04253ba4cbc604774d4493271fdaf3b9a4877bb.tar.xz org.eclipse.papyrus-e04253ba4cbc604774d4493271fdaf3b9a4877bb.zip |
Bug 484632: [Table] Paste with empty clipboard catch an exception
https://bugs.eclipse.org/bugs/show_bug.cgi?id=484632
Manage the paste/insert with empty string.
Change-Id: I5e60fb03e73dae79072af01ea240747a7d0ed0cb
Signed-off-by: Nicolas FAUVERGUE <nicolas.fauvergue@all4tec.net>
Diffstat (limited to 'plugins/infra')
4 files changed, 37 insertions, 16 deletions
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/handler/InsertInTableHandler.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/handler/InsertInTableHandler.java index 9b0bbba510d..ebec337bc98 100644 --- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/handler/InsertInTableHandler.java +++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/handler/InsertInTableHandler.java @@ -16,10 +16,13 @@ package org.eclipse.papyrus.infra.nattable.handler; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; import org.eclipse.jface.viewers.ISelection; +import org.eclipse.papyrus.infra.nattable.Activator; import org.eclipse.papyrus.infra.nattable.manager.InsertInNattableManager; import org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager; import org.eclipse.papyrus.infra.nattable.manager.table.NattableModelManager; +import org.eclipse.papyrus.infra.nattable.messages.Messages; import org.eclipse.papyrus.infra.nattable.provider.TableStructuredSelection; import org.eclipse.papyrus.infra.nattable.utils.AbstractPasteInsertInTableHandler; import org.eclipse.papyrus.infra.nattable.utils.CSVPasteHelper; @@ -71,8 +74,14 @@ public class InsertInTableHandler extends AbstractPasteInsertInTableHandler { final Object userAction = event.getParameters().get(USER_ACTION__PREFERRED_USER_ACTION); final int preferredUserAction = null == userAction ? UserActionConstants.UNDEFINED_USER_ACTION : Integer.parseInt(userAction.toString()); - final InsertInNattableManager pasteManager = new InsertInNattableManager(currentNattableModelManager, pasteHelper, openProgressMonitor, openDialog, preferredUserAction, tableSelectionWrapper, TableClipboardUtils.getClipboardContentsAsString()); - final IStatus result = pasteManager.doAction(); + IStatus result = null; + final String clipboardContentsAsString = TableClipboardUtils.getClipboardContentsAsString(); + if (null != clipboardContentsAsString && !clipboardContentsAsString.isEmpty()) { + final InsertInNattableManager pasteManager = new InsertInNattableManager(currentNattableModelManager, pasteHelper, openProgressMonitor, openDialog, preferredUserAction, tableSelectionWrapper, TableClipboardUtils.getClipboardContentsAsString()); + result = pasteManager.doAction(); + } else { + result = new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.PasteImportHandler_EmptyClipboardString); + } // Manage different types of dialog error depending of type error if (openDialog) { @@ -80,7 +89,7 @@ public class InsertInTableHandler extends AbstractPasteInsertInTableHandler { } return result; } - + /** * @see org.eclipse.papyrus.infra.nattable.handler.AbstractTableHandler#setEnabled(java.lang.Object) * @@ -89,25 +98,25 @@ public class InsertInTableHandler extends AbstractPasteInsertInTableHandler { @Override public void setEnabled(final Object evaluationContext) { super.setEnabled(evaluationContext); - if(isEnabled()){ + if (isEnabled()) { // Recalculate if the enable is allowed because the user can select cells and try to insert by click on rows for example. boolean canEnable = false; final INattableModelManager currentNattableModelManager = getCurrentNattableModelManager(); - if(null != currentNattableModelManager){ - final ISelection currentSelection = ((NattableModelManager)currentNattableModelManager).getSelectionInTable(); - if(null == currentSelection){ + if (null != currentNattableModelManager) { + final ISelection currentSelection = ((NattableModelManager) currentNattableModelManager).getSelectionInTable(); + if (null == currentSelection) { canEnable = true; - }else if (currentSelection instanceof TableStructuredSelection) { + } else if (currentSelection instanceof TableStructuredSelection) { TableSelectionWrapper tableSelectionWrapper = (TableSelectionWrapper) ((TableStructuredSelection) currentSelection).getAdapter(TableSelectionWrapper.class); - if(null != tableSelectionWrapper){ - if(tableSelectionWrapper.getSelectedCells().isEmpty() - || !tableSelectionWrapper.getFullySelectedRows().isEmpty() && tableSelectionWrapper.getFullySelectedColumns().isEmpty()){ - canEnable = true; + if (null != tableSelectionWrapper) { + if (tableSelectionWrapper.getSelectedCells().isEmpty() + || !tableSelectionWrapper.getFullySelectedRows().isEmpty() && tableSelectionWrapper.getFullySelectedColumns().isEmpty()) { + canEnable = true; } } } - } + } setBaseEnabled(canEnable); - } + } } } diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/handler/PasteInTableHandler.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/handler/PasteInTableHandler.java index 15882e88b29..afff4539851 100644 --- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/handler/PasteInTableHandler.java +++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/handler/PasteInTableHandler.java @@ -18,9 +18,12 @@ package org.eclipse.papyrus.infra.nattable.handler; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; import org.eclipse.jface.viewers.ISelection; +import org.eclipse.papyrus.infra.nattable.Activator; import org.eclipse.papyrus.infra.nattable.manager.PasteAxisInNattableManager; import org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager; +import org.eclipse.papyrus.infra.nattable.messages.Messages; import org.eclipse.papyrus.infra.nattable.provider.TableStructuredSelection; import org.eclipse.papyrus.infra.nattable.utils.AbstractPasteInsertInTableHandler; import org.eclipse.papyrus.infra.nattable.utils.CSVPasteHelper; @@ -72,8 +75,14 @@ public class PasteInTableHandler extends AbstractPasteInsertInTableHandler { final Object userAction = event.getParameters().get(USER_ACTION__PREFERRED_USER_ACTION); final int preferredUserAction = null == userAction ? UserActionConstants.UNDEFINED_USER_ACTION : Integer.parseInt(userAction.toString()); - final PasteAxisInNattableManager pasteManager = new PasteAxisInNattableManager(currentNattableModelManager, pasteHelper, openProgressMonitor, openDialog, preferredUserAction, tableSelectionWrapper, TableClipboardUtils.getClipboardContentsAsString()); - final IStatus result = pasteManager.doAction(); + IStatus result = null; + final String clipboardContentsAsString = TableClipboardUtils.getClipboardContentsAsString(); + if (null != clipboardContentsAsString && !clipboardContentsAsString.isEmpty()) { + final PasteAxisInNattableManager pasteManager = new PasteAxisInNattableManager(currentNattableModelManager, pasteHelper, openProgressMonitor, openDialog, preferredUserAction, tableSelectionWrapper, clipboardContentsAsString); + result = pasteManager.doAction(); + } else { + result = new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.PasteImportHandler_EmptyClipboardString); + } // Manage different types of dialog error depending of type error if (openDialog) { 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 73a8dc2205f..2eb46e23519 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 @@ -331,6 +331,8 @@ public class Messages extends NLS { public static String PasteEObjectTreeAxisInNatTableCommandProvider_CantPasteColumnsInTreeTable; + public static String PasteImportHandler_EmptyClipboardString; + public static String PasteImportStatusDialog_ImportPasteDialogTitle; public static String PasteImportStatusDialog_PasteConfigurationMessage; 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 fbb4f36ef35..d68ccbd2f3c 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 @@ -154,6 +154,7 @@ PasteEObjectAxisInTableCommandProvider_PasteColumns=Paste Columns PasteEObjectAxisInTableCommandProvider_PasteFromStringCommand=Paste from String Command PasteEObjectAxisInTableCommandProvider_PasteRows=Paste Rows PasteEObjectTreeAxisInNatTableCommandProvider_CantPasteColumnsInTreeTable=We can't paste columns in a tree table +PasteImportHandler_EmptyClipboardString=Can't paste/insert with empty clipboard PasteImportStatusDialog_ImportPasteDialogTitle=Import/Paste In Table PasteImportStatusDialog_PasteConfigurationMessage=You can configure the Paste/Import using the Property View of the table. PasteInPapyrusTableCommandProvider_0=The String {0} is not valid to create a {1}. |