Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicolas FAUVERGUE2016-07-08 11:21:05 +0000
committerGerrit Code Review @ Eclipse.org2016-07-08 12:58:47 +0000
commitc003fea8a4acffa11d5f70e3bf83c79a489ed0dd (patch)
tree53354bc69b7fe84d68114d1cb4166887ecd3791d /plugins/infra/nattable
parent3925cee6ff6ad93baadbcca649b073d6082809e0 (diff)
downloadorg.eclipse.papyrus-c003fea8a4acffa11d5f70e3bf83c79a489ed0dd.tar.gz
org.eclipse.papyrus-c003fea8a4acffa11d5f70e3bf83c79a489ed0dd.tar.xz
org.eclipse.papyrus-c003fea8a4acffa11d5f70e3bf83c79a489ed0dd.zip
Bug 494625: [Table] Random failures in Copy-Paste tests in the Tables
https://bugs.eclipse.org/bugs/show_bug.cgi?id=494625 - It seems handler have some random failures. To resolve this, a util class was created and used in JUnit tests. - Change the Fill handle copy check. Change-Id: Ic8655beee95791fc73c794936a14f51a9e956944 Signed-off-by: Nicolas FAUVERGUE <nicolas.fauvergue@all4tec.net>
Diffstat (limited to 'plugins/infra/nattable')
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/handler/InsertInTableHandler.java58
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/handler/PasteInTableHandler.java62
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/utils/AbstractPasteInsertInTableHandler.java4
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/utils/PasteInsertUtil.java207
4 files changed, 217 insertions, 114 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 1ac580df7bc..6ea4da7015d 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
@@ -15,20 +15,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;
-import org.eclipse.papyrus.infra.nattable.utils.TableClipboardUtils;
+import org.eclipse.papyrus.infra.nattable.utils.PasteInsertUtil;
import org.eclipse.papyrus.infra.nattable.utils.TableSelectionWrapper;
-import org.eclipse.papyrus.infra.nattable.utils.UserActionConstants;
import org.eclipse.ui.handlers.HandlerUtil;
/**
@@ -37,59 +30,14 @@ import org.eclipse.ui.handlers.HandlerUtil;
public class InsertInTableHandler extends AbstractPasteInsertInTableHandler {
/**
- * This field is used to determine if we want open a dialog to prevent the user that the command creation and the command execution can take a
- * long time
- */
- protected final boolean useProgressMonitorDialog = true;
-
- /**
* {@inheritDoc}
*
* @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
*/
+ @SuppressWarnings("unchecked")
@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
- final CSVPasteHelper pasteHelper = new CSVPasteHelper();
-
- boolean openProgressMonitor = useProgressMonitorDialog;
- final Object value = event.getParameters().get(OPEN__PROGRESS_MONITOR_DIALOG);
- if (value instanceof Boolean) {
- openProgressMonitor = ((Boolean) value).booleanValue();
- }
- final INattableModelManager currentNattableModelManager = getCurrentNattableModelManager();
- // Try to get the selection in the nattable editor
- final ISelection currentSelection = HandlerUtil.getCurrentSelection(event);
- TableSelectionWrapper tableSelectionWrapper = null;
- if (currentSelection instanceof TableStructuredSelection) {
- tableSelectionWrapper = (TableSelectionWrapper) ((TableStructuredSelection) currentSelection).getAdapter(TableSelectionWrapper.class);
- if (tableSelectionWrapper.getSelectedCells().isEmpty()) {
- tableSelectionWrapper = null;
- }
- }
-
- // Calculate if the dialog must be opened during the process
- final Object res = event.getParameters().get(OPEN_DIALOG_ON_FAIL_BOOLEAN_PARAMETER);
- final boolean openDialog = ((null == res) || Boolean.TRUE.equals(res));
-
- 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 Object textToPaste = event.getParameters().get(TEXT_TO_PASTE);
- final String clipboardContentsAsString = null != textToPaste ? (String) textToPaste : TableClipboardUtils.getClipboardContentsAsString();
-
- IStatus result = null;
- if (null != clipboardContentsAsString && !clipboardContentsAsString.isEmpty()) {
- final InsertInNattableManager pasteManager = new InsertInNattableManager(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) {
- displayDialog(result);
- }
- return result;
+ return PasteInsertUtil.insert(getCurrentNattableModelManager(), HandlerUtil.getCurrentSelection(event), event.getParameters());
}
/**
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 ec01eece16c..d1237b9b18d 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
@@ -17,19 +17,8 @@ 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;
-import org.eclipse.papyrus.infra.nattable.utils.TableClipboardUtils;
-import org.eclipse.papyrus.infra.nattable.utils.TableSelectionWrapper;
-import org.eclipse.papyrus.infra.nattable.utils.UserActionConstants;
+import org.eclipse.papyrus.infra.nattable.utils.PasteInsertUtil;
import org.eclipse.ui.handlers.HandlerUtil;
/**
@@ -38,59 +27,14 @@ import org.eclipse.ui.handlers.HandlerUtil;
public class PasteInTableHandler extends AbstractPasteInsertInTableHandler {
/**
- * This field is used to determine if we want open a dialog to prevent the user that the command creation and the command execution can take a
- * long time
- */
- protected final boolean useProgressMonitorDialog = true;
-
- /**
* {@inheritDoc}
*
* @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
*/
+ @SuppressWarnings("unchecked")
@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
- final CSVPasteHelper pasteHelper = new CSVPasteHelper();
-
- boolean openProgressMonitor = useProgressMonitorDialog;
- final Object value = event.getParameters().get(OPEN__PROGRESS_MONITOR_DIALOG);
- if (value instanceof Boolean) {
- openProgressMonitor = ((Boolean) value).booleanValue();
- }
- final INattableModelManager currentNattableModelManager = getCurrentNattableModelManager();
- // Try to get the selection in the nattable editor
- final ISelection currentSelection = HandlerUtil.getCurrentSelection(event);
- TableSelectionWrapper tableSelectionWrapper = null;
- if (currentSelection instanceof TableStructuredSelection) {
- tableSelectionWrapper = (TableSelectionWrapper) ((TableStructuredSelection) currentSelection).getAdapter(TableSelectionWrapper.class);
- if (tableSelectionWrapper.getSelectedCells().isEmpty()) {
- tableSelectionWrapper = null;
- }
- }
-
- // Calculate if the dialog must be opened during the process
- final Object res = event.getParameters().get(OPEN_DIALOG_ON_FAIL_BOOLEAN_PARAMETER);
- final boolean openDialog = ((res == null) || Boolean.TRUE.equals(res));
-
- 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 Object textToPaste = event.getParameters().get(TEXT_TO_PASTE);
- final String clipboardContentsAsString = null != textToPaste ? (String) textToPaste : TableClipboardUtils.getClipboardContentsAsString();
-
- IStatus result = null;
- 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) {
- displayDialog(result);
- }
- return result;
+ return PasteInsertUtil.paste(getCurrentNattableModelManager(), HandlerUtil.getCurrentSelection(event), event.getParameters());
}
}
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/utils/AbstractPasteInsertInTableHandler.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/utils/AbstractPasteInsertInTableHandler.java
index 7c9a1a1901d..0dad7395334 100644
--- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/utils/AbstractPasteInsertInTableHandler.java
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/utils/AbstractPasteInsertInTableHandler.java
@@ -63,7 +63,9 @@ public abstract class AbstractPasteInsertInTableHandler extends AbstractTableHan
*
* @param result
* the result status of the paste process
+ * @deprecated since 2.0
*/
+ @Deprecated
protected void displayDialog(final IStatus result) {
if (null != result) {
// If the error is caracterized by the paste configuration error status, use the dialog concerning the paste configuration error
@@ -113,7 +115,9 @@ public abstract class AbstractPasteInsertInTableHandler extends AbstractTableHan
* @param status
* the status
* @return <code>true </code> if the status is a paste configuration error status, <code>false</code> otherwise.
+ * @deprecated since 2.0
*/
+ @Deprecated
protected boolean isPasteConfigurationStatus(final IStatus status) {
boolean result = false;
switch (status.getSeverity()) {
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/utils/PasteInsertUtil.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/utils/PasteInsertUtil.java
new file mode 100644
index 00000000000..bc9c2a2978a
--- /dev/null
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/utils/PasteInsertUtil.java
@@ -0,0 +1,207 @@
+/*****************************************************************************
+ * Copyright (c) 2016 CEA LIST and others.
+ *
+ * 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:
+ * Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.nattable.utils;
+
+import java.util.Map;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.dialogs.ErrorDialog;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.papyrus.infra.nattable.Activator;
+import org.eclipse.papyrus.infra.nattable.dialog.PasteImportStatusDialog;
+import org.eclipse.papyrus.infra.nattable.manager.AbstractPasteImportInsertInNattableManager;
+import org.eclipse.papyrus.infra.nattable.manager.InsertInNattableManager;
+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.widgets.util.ImageConstants;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+
+/**
+ * This allows to manage paste or insert util methods.
+ */
+public class PasteInsertUtil {
+
+ /**
+ * This field is used to determine if we want open a dialog to prevent the user that the command creation and the command execution can take a
+ * long time
+ */
+ private final static boolean useProgressMonitorDialog = true;
+
+ /**
+ * This allows to paste.
+ *
+ * @param currentNattableModelManager
+ * The nattable model manager.
+ * @param currentSelection
+ * The current selection.
+ * @param parameters
+ * The parameters.
+ * @return The result of the paste.
+ */
+ public static Object paste(final INattableModelManager currentNattableModelManager, final ISelection currentSelection, final Map<Object, Object> parameters) {
+ return doAction(currentNattableModelManager, currentSelection, parameters, true);
+ }
+
+ /**
+ * This allows to insert.
+ *
+ * @param currentNattableModelManager
+ * The nattable model manager.
+ * @param currentSelection
+ * The current selection.
+ * @param parameters
+ * The parameters.
+ * @return The result of the insert.
+ */
+ public static Object insert(final INattableModelManager currentNattableModelManager, final ISelection currentSelection, final Map<Object, Object> parameters) {
+ return doAction(currentNattableModelManager, currentSelection, parameters, false);
+ }
+
+ /**
+ * This allows to paste or insert.
+ *
+ * @param currentNattableModelManager
+ * The nattable model manager.
+ * @param currentSelection
+ * The current selection.
+ * @param parameters
+ * The parameters.
+ * @param isPaste
+ * <code>true</code> if this is a paste, <code>false</code> otherwise.
+ * @return The result of the action.
+ */
+ protected static Object doAction(final INattableModelManager currentNattableModelManager, final ISelection currentSelection, final Map<Object, Object> parameters, final boolean isPaste) {
+ final CSVPasteHelper pasteHelper = new CSVPasteHelper();
+
+ boolean openProgressMonitor = useProgressMonitorDialog;
+ final Object value = parameters.get(AbstractPasteInsertInTableHandler.OPEN__PROGRESS_MONITOR_DIALOG);
+ if (value instanceof Boolean) {
+ openProgressMonitor = ((Boolean) value).booleanValue();
+ }
+
+ // Try to get the selection in the nattable editor
+ TableSelectionWrapper tableSelectionWrapper = null;
+ if (currentSelection instanceof TableStructuredSelection) {
+ tableSelectionWrapper = (TableSelectionWrapper) ((TableStructuredSelection) currentSelection).getAdapter(TableSelectionWrapper.class);
+ if (tableSelectionWrapper.getSelectedCells().isEmpty()) {
+ tableSelectionWrapper = null;
+ }
+ }
+
+ // Calculate if the dialog must be opened during the process
+ final Object res = parameters.get(AbstractPasteInsertInTableHandler.OPEN_DIALOG_ON_FAIL_BOOLEAN_PARAMETER);
+ final boolean openDialog = ((null == res) || Boolean.TRUE.equals(res));
+
+ final Object userAction = parameters.get(AbstractPasteInsertInTableHandler.USER_ACTION__PREFERRED_USER_ACTION);
+ final int preferredUserAction = null == userAction ? UserActionConstants.UNDEFINED_USER_ACTION : Integer.parseInt(userAction.toString());
+
+ final Object textToPaste = parameters.get(AbstractPasteInsertInTableHandler.TEXT_TO_PASTE);
+ final String clipboardContentsAsString = null != textToPaste ? (String) textToPaste : TableClipboardUtils.getClipboardContentsAsString();
+
+ IStatus result = null;
+ if (null != clipboardContentsAsString && !clipboardContentsAsString.isEmpty()) {
+ AbstractPasteImportInsertInNattableManager pasteManager = null;
+ if (isPaste) {
+ pasteManager = new PasteAxisInNattableManager(currentNattableModelManager, pasteHelper, openProgressMonitor, openDialog, preferredUserAction, tableSelectionWrapper, clipboardContentsAsString);
+ } else {
+ pasteManager = new InsertInNattableManager(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) {
+ displayDialog(result);
+ }
+ return result;
+ }
+
+ /**
+ * This allows to display the error message when this is a paste configuration error type.
+ *
+ * @param result
+ * the result status of the paste process
+ */
+ protected static void displayDialog(final IStatus result) {
+ if (null != result) {
+ // If the error is caracterized by the paste configuration error status, use the dialog concerning the paste configuration error
+ if (isPasteConfigurationStatus(result)) {
+ new PasteImportStatusDialog(Display.getDefault().getActiveShell(), result).open();
+ // If this is not a paste configuration error status, open an error status to display the problem
+ } else if (IStatus.OK != result.getSeverity()) {
+ String messageDialog = null;
+ switch (result.getSeverity()) {
+ case IStatus.INFO:
+ messageDialog = Messages.PasteInTableHandler_PasteInformation;
+ break;
+ case IStatus.WARNING:
+ messageDialog = Messages.PasteInTableHandler_PasteWarning;
+ break;
+ case IStatus.ERROR:
+ messageDialog = Messages.PasteInTableHandler_PasteError;
+ break;
+ case IStatus.CANCEL:
+ messageDialog = Messages.PasteInTableHandler_PasteCancelled;
+ break;
+ }
+
+ final ErrorDialog errorDialog = new ErrorDialog(Display.getDefault().getActiveShell(), Messages.PasteImportStatusDialog_ImportPasteDialogTitle, messageDialog, result, IStatus.OK
+ | IStatus.INFO | IStatus.WARNING | IStatus.ERROR) {
+
+ /**
+ * Redefine this method to manage the papyrus icon in shell.
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.jface.dialogs.ErrorDialog#configureShell(org.eclipse.swt.widgets.Shell)
+ */
+ @Override
+ protected void configureShell(Shell shell) {
+ super.configureShell(shell);
+ shell.setImage(org.eclipse.papyrus.infra.widgets.Activator.getDefault().getImage(ImageConstants.PAPYRUS_ICON_PATH));
+ }
+ };
+ errorDialog.open();
+ }
+ }
+ }
+
+ /**
+ * This allows to determinate if the status is a paste configuration error status.
+ *
+ * @param status
+ * the status
+ * @return <code>true </code> if the status is a paste configuration error status, <code>false</code> otherwise.
+ */
+ protected static boolean isPasteConfigurationStatus(final IStatus status) {
+ boolean result = false;
+ switch (status.getSeverity()) {
+ case IPapyrusNattableStatus.PASTE_CONFIGURATiON_INFO:
+ case IPapyrusNattableStatus.PASTE_CONFIGURATiON_WARNING:
+ case IPapyrusNattableStatus.PASTE_CONFIGURATiON_ERROR:
+ result = true;
+ break;
+ default:
+ result = false;
+ break;
+ }
+ return result;
+ }
+
+}

Back to the top