diff options
author | Nicolas FAUVERGUE | 2016-06-02 12:12:57 +0000 |
---|---|---|
committer | Gerrit Code Review @ Eclipse.org | 2016-07-06 14:28:28 +0000 |
commit | 312d483433e09ba9242f261a519a8c052485a7d8 (patch) | |
tree | 281c5d13e689bd7d2c8a60964694719a8f504f4e /tests | |
parent | 6ca94f4eed71ecc8c0c501b9e0f8bab084e07c59 (diff) | |
download | org.eclipse.papyrus-312d483433e09ba9242f261a519a8c052485a7d8.tar.gz org.eclipse.papyrus-312d483433e09ba9242f261a519a8c052485a7d8.tar.xz org.eclipse.papyrus-312d483433e09ba9242f261a519a8c052485a7d8.zip |
Bug 495787: [Table][Tests] Create a file export to manage the paste
without using clipboard
https://bugs.eclipse.org/bugs/show_bug.cgi?id=495787
- Add the export to file of the table contents (not as menu item)
- Replace the selectAll+copy to check the table contents by the export
file check
- The first copy/paste is replaced by a command parameter with text to
copy.
Change-Id: I27d782da13f54fb7d368629a9c56716c46463f66
Signed-off-by: Nicolas FAUVERGUE <nicolas.fauvergue@all4tec.net>
Diffstat (limited to 'tests')
18 files changed, 216 insertions, 142 deletions
diff --git a/tests/junit/plugins/sysml/nattable/org.eclipse.papyrus.sysml.nattable.requirement.tests/src/org/eclipse/papyrus/sysml/nattable/requirement/tests/importfile/AbstractImportTest.java b/tests/junit/plugins/sysml/nattable/org.eclipse.papyrus.sysml.nattable.requirement.tests/src/org/eclipse/papyrus/sysml/nattable/requirement/tests/importfile/AbstractImportTest.java index 86cccaf970c..3c432ab0c72 100644 --- a/tests/junit/plugins/sysml/nattable/org.eclipse.papyrus.sysml.nattable.requirement.tests/src/org/eclipse/papyrus/sysml/nattable/requirement/tests/importfile/AbstractImportTest.java +++ b/tests/junit/plugins/sysml/nattable/org.eclipse.papyrus.sysml.nattable.requirement.tests/src/org/eclipse/papyrus/sysml/nattable/requirement/tests/importfile/AbstractImportTest.java @@ -13,16 +13,12 @@ package org.eclipse.papyrus.sysml.nattable.requirement.tests.importfile; -import java.net.URL; import java.util.HashMap; import java.util.Map; import org.eclipse.core.commands.Command; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.IHandler; -import org.eclipse.core.runtime.FileLocator; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Path; import org.eclipse.emf.common.util.URI; import org.eclipse.papyrus.infra.nattable.common.editor.NatTableEditor; import org.eclipse.papyrus.infra.nattable.handler.ImportTableHandler; @@ -30,13 +26,11 @@ import org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager; import org.eclipse.papyrus.infra.nattable.manager.table.NattableModelManager; import org.eclipse.papyrus.infra.tools.util.FileUtils; import org.eclipse.papyrus.infra.ui.util.EclipseCommandUtils; -import org.eclipse.papyrus.sysml.nattable.requirement.tests.Activator; import org.eclipse.papyrus.sysml.nattable.requirement.tests.paste.overwrite.AbstractPasteInsertTest; import org.eclipse.ui.IEditorPart; import org.eclipse.ui.commands.ICommandService; import org.junit.Assert; import org.junit.Test; -import org.osgi.framework.Bundle; /** * This class allows to manage the import CSV file tests. diff --git a/tests/junit/plugins/sysml/nattable/org.eclipse.papyrus.sysml.nattable.requirement.tests/src/org/eclipse/papyrus/sysml/nattable/requirement/tests/insert/AbstractInsertTest.java b/tests/junit/plugins/sysml/nattable/org.eclipse.papyrus.sysml.nattable.requirement.tests/src/org/eclipse/papyrus/sysml/nattable/requirement/tests/insert/AbstractInsertTest.java index 5a5252bce65..496b442ec7c 100644 --- a/tests/junit/plugins/sysml/nattable/org.eclipse.papyrus.sysml.nattable.requirement.tests/src/org/eclipse/papyrus/sysml/nattable/requirement/tests/insert/AbstractInsertTest.java +++ b/tests/junit/plugins/sysml/nattable/org.eclipse.papyrus.sysml.nattable.requirement.tests/src/org/eclipse/papyrus/sysml/nattable/requirement/tests/insert/AbstractInsertTest.java @@ -26,12 +26,10 @@ import org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager; import org.eclipse.papyrus.infra.nattable.manager.table.NattableModelManager; import org.eclipse.papyrus.infra.tools.util.FileUtils; import org.eclipse.papyrus.infra.ui.util.EclipseCommandUtils; -import org.eclipse.papyrus.junit.utils.GenericUtils; import org.eclipse.papyrus.sysml.nattable.requirement.tests.Activator; import org.eclipse.papyrus.sysml.nattable.requirement.tests.paste.overwrite.AbstractPasteInsertTest; import org.eclipse.ui.IEditorPart; import org.eclipse.ui.commands.ICommandService; -import org.junit.AfterClass; import org.junit.Assert; import org.junit.Test; @@ -80,7 +78,7 @@ public abstract class AbstractInsertTest extends AbstractPasteInsertTest { Assert.assertNotNull("The command service must not be null", commandService); //$NON-NLS-1$ final String fileName = getSuffixStateFileName(manager, TOCOPY_POST_FILE_NAME); final String str = FileUtils.getStringFromPlatformFile(Activator.PLUGIN_ID, getSourcePath(), fileName); - fillClipboard(str); + fillClipboard("Fill the clipboard to enable the handler"); //$NON-NLS-1$ // Get the paste command final Command cmd = commandService.getCommand(getCommandId()); // $NON-NLS-1$ @@ -91,6 +89,8 @@ public abstract class AbstractInsertTest extends AbstractPasteInsertTest { final Map<Object, Object> parameters = new HashMap<Object, Object>(); parameters.put(PasteInTableHandler.OPEN_DIALOG_ON_FAIL_BOOLEAN_PARAMETER, Boolean.FALSE); parameters.put(PasteInTableHandler.OPEN__PROGRESS_MONITOR_DIALOG, Boolean.FALSE); + // This parameters allows to set the text to paste instead of copy/paste it programmatically (this may be overwrite by other copy) + parameters.put(PasteInTableHandler.TEXT_TO_PASTE, str); manageParameters(parameters); final ExecutionEvent event = new ExecutionEvent(cmd, parameters, null, null); flushDisplayEvents(); diff --git a/tests/junit/plugins/sysml/nattable/org.eclipse.papyrus.sysml.nattable.requirement.tests/src/org/eclipse/papyrus/sysml/nattable/requirement/tests/paste/overwrite/AbstractPasteEmptyOverwriteTest.java b/tests/junit/plugins/sysml/nattable/org.eclipse.papyrus.sysml.nattable.requirement.tests/src/org/eclipse/papyrus/sysml/nattable/requirement/tests/paste/overwrite/AbstractPasteEmptyOverwriteTest.java index 3318fab087f..5227cff1da4 100644 --- a/tests/junit/plugins/sysml/nattable/org.eclipse.papyrus.sysml.nattable.requirement.tests/src/org/eclipse/papyrus/sysml/nattable/requirement/tests/paste/overwrite/AbstractPasteEmptyOverwriteTest.java +++ b/tests/junit/plugins/sysml/nattable/org.eclipse.papyrus.sysml.nattable.requirement.tests/src/org/eclipse/papyrus/sysml/nattable/requirement/tests/paste/overwrite/AbstractPasteEmptyOverwriteTest.java @@ -68,7 +68,7 @@ public abstract class AbstractPasteEmptyOverwriteTest extends AbstractPasteOverw Assert.assertNotNull("The command service must not be null", commandService); //$NON-NLS-1$ final String fileName = getSuffixStateFileName(manager, TOCOPY_POST_FILE_NAME); final String str = FileUtils.getStringFromPlatformFile(Activator.PLUGIN_ID, getSourcePath(), fileName); - fillClipboard(str); + fillClipboard("Fill the clipboard to enable the handler"); //$NON-NLS-1$ // Get the paste command final Command cmd = commandService.getCommand("org.eclipse.ui.edit.paste"); //$NON-NLS-1$ @@ -79,6 +79,8 @@ public abstract class AbstractPasteEmptyOverwriteTest extends AbstractPasteOverw final Map<Object, Object> parameters = new HashMap<Object, Object>(); parameters.put(PasteInTableHandler.OPEN_DIALOG_ON_FAIL_BOOLEAN_PARAMETER, Boolean.FALSE); parameters.put(PasteInTableHandler.OPEN__PROGRESS_MONITOR_DIALOG, Boolean.FALSE); + // This parameters allows to set the text to paste instead of copy/paste it programmatically (this may be overwrite by other copy) + parameters.put(PasteInTableHandler.TEXT_TO_PASTE, str); manageParameters(parameters); final ExecutionEvent event = new ExecutionEvent(cmd, parameters, null, null); flushDisplayEvents(); diff --git a/tests/junit/plugins/sysml/nattable/org.eclipse.papyrus.sysml.nattable.requirement.tests/src/org/eclipse/papyrus/sysml/nattable/requirement/tests/paste/overwrite/AbstractPasteInsertTest.java b/tests/junit/plugins/sysml/nattable/org.eclipse.papyrus.sysml.nattable.requirement.tests/src/org/eclipse/papyrus/sysml/nattable/requirement/tests/paste/overwrite/AbstractPasteInsertTest.java index de37bb27a2c..1e7a98aba7c 100644 --- a/tests/junit/plugins/sysml/nattable/org.eclipse.papyrus.sysml.nattable.requirement.tests/src/org/eclipse/papyrus/sysml/nattable/requirement/tests/paste/overwrite/AbstractPasteInsertTest.java +++ b/tests/junit/plugins/sysml/nattable/org.eclipse.papyrus.sysml.nattable.requirement.tests/src/org/eclipse/papyrus/sysml/nattable/requirement/tests/paste/overwrite/AbstractPasteInsertTest.java @@ -15,13 +15,21 @@ package org.eclipse.papyrus.sysml.nattable.requirement.tests.paste.overwrite; import java.awt.Toolkit; import java.awt.datatransfer.StringSelection; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.List; +import org.eclipse.core.resources.IWorkspace; +import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.IStatus; import org.eclipse.emf.common.util.URI; import org.eclipse.nebula.widgets.nattable.NatTable; -import org.eclipse.nebula.widgets.nattable.selection.command.ClearAllSelectionsCommand; +import org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer; +import org.eclipse.papyrus.infra.nattable.export.file.PapyrusFileExportCommandHandler; +import org.eclipse.papyrus.infra.nattable.export.file.PapyrusFileExporter; +import org.eclipse.papyrus.infra.nattable.export.file.command.PapyrusFileExportCommand; import org.eclipse.papyrus.infra.nattable.manager.table.NattableModelManager; -import org.eclipse.papyrus.infra.nattable.utils.TableClipboardUtils; +import org.eclipse.papyrus.infra.nattable.style.configattribute.PapyrusExportConfigAttributes; import org.eclipse.papyrus.infra.tools.util.FileUtils; import org.eclipse.papyrus.junit.utils.GenericUtils; import org.eclipse.papyrus.sysml.nattable.requirement.tests.Activator; @@ -126,15 +134,32 @@ public abstract class AbstractPasteInsertTest extends AbstractOpenTableTest { protected void checkTableContent(final NattableModelManager manager, final String suffixFileName) throws Exception { final NatTable natTable = (NatTable) manager.getAdapter(NatTable.class); flushDisplayEvents(); - natTable.doCommand(new ClearAllSelectionsCommand()); - manager.selectAll(); - manager.copyToClipboard(); - String clipboard = getClipboardContent(); - // we check than the contents of the clipboard (so the displayed table) is the same than the wanted result - Assert.assertNotNull("Clipboard must not be null", clipboard); //$NON-NLS-1$ - String str = getWantedString(getSuffixStateFileName(manager, suffixFileName)); + + // Unregister and register the papyrus file export to manage it without the shell + final GridLayer gridLayer = manager.getGridLayer(); + gridLayer.unregisterCommandHandler(PapyrusFileExportCommand.class); + gridLayer.registerCommandHandler(new PapyrusFileExportCommandHandler(gridLayer.getBodyLayer(), false)); + + // Modify the config attribute of the file export to use the file name without the shell + IWorkspace workspace = ResourcesPlugin.getWorkspace(); + final String wsFolder = workspace.getRoot().getLocation().toFile().getPath().toString(); + final String contentFile = wsFolder + "\\content.txt"; //$NON-NLS-1$ + natTable.getConfigRegistry().unregisterConfigAttribute(PapyrusExportConfigAttributes.SIMPLE_FILE_EXPORTER); + natTable.getConfigRegistry().registerConfigAttribute(PapyrusExportConfigAttributes.SIMPLE_FILE_EXPORTER, new PapyrusFileExporter(contentFile)); + manager.exportToFile(); + + final StringBuilder content = new StringBuilder(); + final List<String> allLines = Files.readAllLines(Paths.get(contentFile)); + for (int index = 0; index < allLines.size(); index++) { + content.append(allLines.get(index)); + if (index < allLines.size() - 1) { + content.append(FileUtils.getSystemPropertyLineSeparator()); + } + } + + final String str = getWantedString(getSuffixStateFileName(manager, suffixFileName)); // we check than the contents of the clipboard (so the displayed table) is the same than the wanted result - Assert.assertEquals("The clipboard must be equals to string which one it is filled", str, clipboard); //$NON-NLS-1$ + Assert.assertEquals("The clipboard must be equals to string which one it is filled", str, content.toString()); //$NON-NLS-1$ } /** @@ -169,17 +194,6 @@ public abstract class AbstractPasteInsertTest extends AbstractOpenTableTest { } /** - * Get the clipboard contents. - * - * @return - * the clipboard contents. - */ - protected String getClipboardContent() { - String clipboard = TableClipboardUtils.getClipboardContentsAsString(); - return clipboard; - } - - /** * This allows to fill the clipboard with the string in parameter. * * @param newClipBoardContents diff --git a/tests/junit/plugins/sysml/nattable/org.eclipse.papyrus.sysml.nattable.requirement.tests/src/org/eclipse/papyrus/sysml/nattable/requirement/tests/paste/overwrite/AbstractPasteOverwriteTest.java b/tests/junit/plugins/sysml/nattable/org.eclipse.papyrus.sysml.nattable.requirement.tests/src/org/eclipse/papyrus/sysml/nattable/requirement/tests/paste/overwrite/AbstractPasteOverwriteTest.java index 367ecdcbfd3..4d7b98dd425 100644 --- a/tests/junit/plugins/sysml/nattable/org.eclipse.papyrus.sysml.nattable.requirement.tests/src/org/eclipse/papyrus/sysml/nattable/requirement/tests/paste/overwrite/AbstractPasteOverwriteTest.java +++ b/tests/junit/plugins/sysml/nattable/org.eclipse.papyrus.sysml.nattable.requirement.tests/src/org/eclipse/papyrus/sysml/nattable/requirement/tests/paste/overwrite/AbstractPasteOverwriteTest.java @@ -72,7 +72,7 @@ public abstract class AbstractPasteOverwriteTest extends AbstractPasteInsertTest Assert.assertNotNull("The command service must not be null", commandService); //$NON-NLS-1$ final String fileName = getSuffixStateFileName(manager, TOCOPY_POST_FILE_NAME); final String str = FileUtils.getStringFromPlatformFile(Activator.PLUGIN_ID, getSourcePath(), fileName); - fillClipboard(str); + fillClipboard("Fill the clipboard to enable the handler"); //$NON-NLS-1$ // Get the paste command final Command cmd = commandService.getCommand("org.eclipse.ui.edit.paste"); //$NON-NLS-1$ @@ -83,6 +83,8 @@ public abstract class AbstractPasteOverwriteTest extends AbstractPasteInsertTest final Map<Object, Object> parameters = new HashMap<Object, Object>(); parameters.put(PasteInTableHandler.OPEN_DIALOG_ON_FAIL_BOOLEAN_PARAMETER, Boolean.FALSE); parameters.put(PasteInTableHandler.OPEN__PROGRESS_MONITOR_DIALOG, Boolean.FALSE); + // This parameters allows to set the text to paste instead of copy/paste it programmatically (this may be overwrite by other copy) + parameters.put(PasteInTableHandler.TEXT_TO_PASTE, str); final ExecutionEvent event = new ExecutionEvent(cmd, parameters, null, null); flushDisplayEvents(); final Object res = cmd.executeWithChecks(event); diff --git a/tests/junit/plugins/sysml/nattable/org.eclipse.papyrus.sysml.nattable.requirement.tests/src/org/eclipse/papyrus/sysml/nattable/requirement/tests/paste/without/service/edit/AbstractPasteTests.java b/tests/junit/plugins/sysml/nattable/org.eclipse.papyrus.sysml.nattable.requirement.tests/src/org/eclipse/papyrus/sysml/nattable/requirement/tests/paste/without/service/edit/AbstractPasteTests.java index c66bd73637b..ba5c9877cb2 100644 --- a/tests/junit/plugins/sysml/nattable/org.eclipse.papyrus.sysml.nattable.requirement.tests/src/org/eclipse/papyrus/sysml/nattable/requirement/tests/paste/without/service/edit/AbstractPasteTests.java +++ b/tests/junit/plugins/sysml/nattable/org.eclipse.papyrus.sysml.nattable.requirement.tests/src/org/eclipse/papyrus/sysml/nattable/requirement/tests/paste/without/service/edit/AbstractPasteTests.java @@ -202,16 +202,17 @@ public abstract class AbstractPasteTests extends AbstractOpenTableTest { Assert.assertNotNull(commandService); String fileName = getPasteFileName(); String str = FileUtils.getStringFromPlatformFile(Activator.PLUGIN_ID, getSourcePath(), fileName); - fillClipboard(str); + fillClipboard("Fill the clipboard to enable the handler"); //$NON-NLS-1$ Command cmd = commandService.getCommand("org.eclipse.ui.edit.paste"); //$NON-NLS-1$ IHandler handler = cmd.getHandler(); Assert.assertTrue(handler.isEnabled()); - Map<Object, Object> parameters = new HashMap<Object, Object>(); parameters.put(PasteInTableHandler.OPEN_DIALOG_ON_FAIL_BOOLEAN_PARAMETER, Boolean.FALSE); parameters.put(PasteInTableHandler.OPEN__PROGRESS_MONITOR_DIALOG, Boolean.FALSE); + // This parameters allows to set the text to paste instead of copy/paste it programmatically (this may be overwrite by other copy) + parameters.put(PasteInTableHandler.TEXT_TO_PASTE, str); ExecutionEvent event = new ExecutionEvent(cmd, parameters, null, null); flushDisplayEvents(); Object res = cmd.executeWithChecks(event); diff --git a/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.clazz.config.tests/src/org/eclipse/papyrus/uml/nattable/clazz/config/tests/fillhandle/AbstractFillHandleTest.java b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.clazz.config.tests/src/org/eclipse/papyrus/uml/nattable/clazz/config/tests/fillhandle/AbstractFillHandleTest.java index 362d52875ec..9af6020eeb6 100644 --- a/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.clazz.config.tests/src/org/eclipse/papyrus/uml/nattable/clazz/config/tests/fillhandle/AbstractFillHandleTest.java +++ b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.clazz.config.tests/src/org/eclipse/papyrus/uml/nattable/clazz/config/tests/fillhandle/AbstractFillHandleTest.java @@ -13,21 +13,30 @@ package org.eclipse.papyrus.uml.nattable.clazz.config.tests.fillhandle; -import java.awt.Toolkit; -import java.awt.datatransfer.StringSelection; - +import java.io.BufferedReader; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.URL; + +import org.eclipse.core.resources.IWorkspace; +import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.emf.common.util.URI; import org.eclipse.emf.transaction.TransactionalEditingDomain; import org.eclipse.nebula.widgets.nattable.NatTable; import org.eclipse.nebula.widgets.nattable.command.ILayerCommand; import org.eclipse.nebula.widgets.nattable.copy.command.CopyDataToClipboardCommand; -import org.eclipse.nebula.widgets.nattable.selection.command.ClearAllSelectionsCommand; +import org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer; import org.eclipse.papyrus.infra.nattable.common.editor.NatTableEditor; +import org.eclipse.papyrus.infra.nattable.export.file.PapyrusFileExportCommandHandler; +import org.eclipse.papyrus.infra.nattable.export.file.PapyrusFileExporter; +import org.eclipse.papyrus.infra.nattable.export.file.command.PapyrusFileExportCommand; import org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager; import org.eclipse.papyrus.infra.nattable.manager.table.ITreeNattableModelManager; import org.eclipse.papyrus.infra.nattable.manager.table.TreeNattableModelManager; +import org.eclipse.papyrus.infra.nattable.style.configattribute.PapyrusExportConfigAttributes; import org.eclipse.papyrus.infra.nattable.tree.CollapseAndExpandActionsEnum; -import org.eclipse.papyrus.infra.nattable.utils.TableClipboardUtils; import org.eclipse.papyrus.infra.tools.util.FileUtils; import org.eclipse.papyrus.junit.utils.GenericUtils; import org.eclipse.papyrus.junit.utils.rules.ActiveTable; @@ -349,16 +358,62 @@ public abstract class AbstractFillHandleTest extends AbstractTableTest { fixture.flushDisplayEvents(); treeManager.doCollapseExpandAction(CollapseAndExpandActionsEnum.EXPAND_ALL, null); final NatTable natTable = (NatTable) treeManager.getAdapter(NatTable.class); - fixture.flushDisplayEvents(); - natTable.doCommand(new ClearAllSelectionsCommand()); - treeManager.selectAll(); - treeManager.copyToClipboard(); - String clipboard = getClipboardContent(); - // we check than the contents of the clipboard (so the displayed table) is the same than the wanted result - Assert.assertNotNull("Clipboard must not be null", clipboard); //$NON-NLS-1$ - String str = getWantedString(getSuffixStateFileName(treeManager, suffixFileName)); + + // Unregister and register the papyrus file export to manage it without the shell + final GridLayer gridLayer = treeManager.getGridLayer(); + gridLayer.unregisterCommandHandler(PapyrusFileExportCommand.class); + gridLayer.registerCommandHandler(new PapyrusFileExportCommandHandler(gridLayer.getBodyLayer(), false)); + + // Modify the config attribute of the file export to use the file name without the shell + IWorkspace workspace = ResourcesPlugin.getWorkspace(); + final String wsFolder = workspace.getRoot().getLocation().toFile().getPath().toString(); + final String contentFile = wsFolder + "\\content.txt"; //$NON-NLS-1$ + natTable.getConfigRegistry().unregisterConfigAttribute(PapyrusExportConfigAttributes.SIMPLE_FILE_EXPORTER); + natTable.getConfigRegistry().registerConfigAttribute(PapyrusExportConfigAttributes.SIMPLE_FILE_EXPORTER, new PapyrusFileExporter(contentFile)); + treeManager.exportToFile(); + + final String content = getStringFromFile(contentFile); + + final String str = getWantedString(getSuffixStateFileName(treeManager, suffixFileName)); // we check than the contents of the clipboard (so the displayed table) is the same than the wanted result - Assert.assertEquals("The clipboard must be equals to string which one it is filled", str, clipboard); //$NON-NLS-1$ + Assert.assertEquals("The clipboard must be equals to string which one it is filled", str, content); //$NON-NLS-1$ + + // Remove the content file + File file = new File(contentFile); + file.delete(); + } + + /** + * Get the content file. + * + * @param fileName + * The file name. + * @return The content of the file. + */ + protected String getStringFromFile(final String fileName) { + final StringBuilder builder = new StringBuilder(); + final URL url; + try { + url = new URL("file:/" + fileName); //$NON-NLS-1$ + InputStream inputStream = url.openConnection().getInputStream(); + BufferedReader in = new BufferedReader(new InputStreamReader(inputStream)); + String inputLine = in.readLine(); + + while (inputLine != null) { + builder.append(inputLine); + inputLine = in.readLine(); + if (inputLine != null) { + builder.append(FileUtils.getSystemPropertyLineSeparator()); + } + } + + in.close(); + + } catch (final IOException e) { + Activator.log.error(e); + } + + return builder.toString(); } /** @@ -393,32 +448,6 @@ public abstract class AbstractFillHandleTest extends AbstractTableTest { } /** - * Get the clipboard contents. - * - * @return - * the clipboard contents. - */ - protected String getClipboardContent() { - String clipboard = TableClipboardUtils.getClipboardContentsAsString(); - return clipboard; - } - - /** - * This allows to fill the clipboard with the string in parameter. - * - * @param newClipBoardContents - * The string needed to fill the clipboard. - */ - protected void fillClipboard(final String newClipBoardContents) { - - // its seems that the clipboard must be filled with the same way than we read it! - java.awt.datatransfer.Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); - - StringSelection s = new StringSelection(newClipBoardContents); - clipboard.setContents(s, s); - } - - /** * {@inheritDoc} * * @see org.eclipse.papyrus.uml.nattable.clazz.config.tests.tests.AbstractOpenTableTest#getSourcePath() diff --git a/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.clazz.config.tests/src/org/eclipse/papyrus/uml/nattable/clazz/config/tests/importfile/AbstractImportTest.java b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.clazz.config.tests/src/org/eclipse/papyrus/uml/nattable/clazz/config/tests/importfile/AbstractImportTest.java index 3f61810a254..6bd8f3d79ed 100644 --- a/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.clazz.config.tests/src/org/eclipse/papyrus/uml/nattable/clazz/config/tests/importfile/AbstractImportTest.java +++ b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.clazz.config.tests/src/org/eclipse/papyrus/uml/nattable/clazz/config/tests/importfile/AbstractImportTest.java @@ -19,8 +19,6 @@ import java.util.Map; import org.eclipse.core.commands.Command; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.IHandler; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Path; import org.eclipse.emf.common.util.URI; import org.eclipse.papyrus.infra.nattable.common.editor.NatTableEditor; import org.eclipse.papyrus.infra.nattable.handler.ImportTableHandler; @@ -125,8 +123,8 @@ public abstract class AbstractImportTest extends AbstractPasteInsertTest { buffer.append(FileUtils.CSV_EXTENSIOn); String csvFileAsString = getWantedString(buffer.toString()); - - parameters.put(ImportTableHandler.SELECTED_FILE_PATH_STRING_PARAMETER, csvFileAsString); + + parameters.put(ImportTableHandler.SELECTED_FILE_PATH_STRING_PARAMETER, csvFileAsString); } /** diff --git a/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.clazz.config.tests/src/org/eclipse/papyrus/uml/nattable/clazz/config/tests/insert/AbstractInsertTest.java b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.clazz.config.tests/src/org/eclipse/papyrus/uml/nattable/clazz/config/tests/insert/AbstractInsertTest.java index 10a475a3c6f..ef8f08fbb3d 100644 --- a/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.clazz.config.tests/src/org/eclipse/papyrus/uml/nattable/clazz/config/tests/insert/AbstractInsertTest.java +++ b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.clazz.config.tests/src/org/eclipse/papyrus/uml/nattable/clazz/config/tests/insert/AbstractInsertTest.java @@ -79,7 +79,7 @@ public abstract class AbstractInsertTest extends AbstractPasteInsertTest { Assert.assertNotNull("The command service must not be null", commandService); //$NON-NLS-1$ final String fileName = getSuffixStateFileName(treeManager, TOCOPY_POST_FILE_NAME); final String str = FileUtils.getStringFromPlatformFile(Activator.PLUGIN_ID, getSourcePath(), fileName); - fillClipboard(str); + fillClipboard("Fill the clipboard to enable the handler"); //$NON-NLS-1$ // Get the paste command final Command cmd = commandService.getCommand(getCommandId()); //$NON-NLS-1$ @@ -90,6 +90,8 @@ public abstract class AbstractInsertTest extends AbstractPasteInsertTest { final Map<Object, Object> parameters = new HashMap<Object, Object>(); parameters.put(PasteInTableHandler.OPEN_DIALOG_ON_FAIL_BOOLEAN_PARAMETER, Boolean.FALSE); parameters.put(PasteInTableHandler.OPEN__PROGRESS_MONITOR_DIALOG, Boolean.FALSE); + // This parameters allows to set the text to paste instead of copy/paste it programmatically (this may be overwrite by other copy) + parameters.put(PasteInTableHandler.TEXT_TO_PASTE, str); manageParameters(parameters); final ExecutionEvent event = new ExecutionEvent(cmd, parameters, null, null); flushDisplayEvents(); @@ -115,9 +117,10 @@ public abstract class AbstractInsertTest extends AbstractPasteInsertTest { /** * This allows to add parameters if necessary * - * @param parameters The parameters for the command. + * @param parameters + * The parameters for the command. */ - public void manageParameters(final Map<Object, Object> parameters){ + public void manageParameters(final Map<Object, Object> parameters) { // Do nothing } diff --git a/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.clazz.config.tests/src/org/eclipse/papyrus/uml/nattable/clazz/config/tests/paste/overwrite/AbstractPasteEmptyOverwriteTest.java b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.clazz.config.tests/src/org/eclipse/papyrus/uml/nattable/clazz/config/tests/paste/overwrite/AbstractPasteEmptyOverwriteTest.java index 8a58af6089e..4c727bd020b 100644 --- a/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.clazz.config.tests/src/org/eclipse/papyrus/uml/nattable/clazz/config/tests/paste/overwrite/AbstractPasteEmptyOverwriteTest.java +++ b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.clazz.config.tests/src/org/eclipse/papyrus/uml/nattable/clazz/config/tests/paste/overwrite/AbstractPasteEmptyOverwriteTest.java @@ -70,7 +70,7 @@ public abstract class AbstractPasteEmptyOverwriteTest extends AbstractPasteOverw Assert.assertNotNull("The command service must not be null", commandService); //$NON-NLS-1$ final String fileName = getSuffixStateFileName(treeManager, TOCOPY_POST_FILE_NAME); final String str = FileUtils.getStringFromPlatformFile(Activator.PLUGIN_ID, getSourcePath(), fileName); - fillClipboard(str); + fillClipboard("Fill the clipboard to enable the handler"); //$NON-NLS-1$ // Get the paste command final Command cmd = commandService.getCommand("org.eclipse.ui.edit.paste"); //$NON-NLS-1$ @@ -81,6 +81,8 @@ public abstract class AbstractPasteEmptyOverwriteTest extends AbstractPasteOverw final Map<Object, Object> parameters = new HashMap<Object, Object>(); parameters.put(PasteInTableHandler.OPEN_DIALOG_ON_FAIL_BOOLEAN_PARAMETER, Boolean.FALSE); parameters.put(PasteInTableHandler.OPEN__PROGRESS_MONITOR_DIALOG, Boolean.FALSE); + // This parameters allows to set the text to paste instead of copy/paste it programmatically (this may be overwrite by other copy) + parameters.put(PasteInTableHandler.TEXT_TO_PASTE, str); manageParameters(parameters); final ExecutionEvent event = new ExecutionEvent(cmd, parameters, null, null); flushDisplayEvents(); diff --git a/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.clazz.config.tests/src/org/eclipse/papyrus/uml/nattable/clazz/config/tests/paste/overwrite/AbstractPasteInsertTest.java b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.clazz.config.tests/src/org/eclipse/papyrus/uml/nattable/clazz/config/tests/paste/overwrite/AbstractPasteInsertTest.java index cc4062a8b51..5acaacccacd 100644 --- a/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.clazz.config.tests/src/org/eclipse/papyrus/uml/nattable/clazz/config/tests/paste/overwrite/AbstractPasteInsertTest.java +++ b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.clazz.config.tests/src/org/eclipse/papyrus/uml/nattable/clazz/config/tests/paste/overwrite/AbstractPasteInsertTest.java @@ -15,19 +15,20 @@ package org.eclipse.papyrus.uml.nattable.clazz.config.tests.paste.overwrite; import java.awt.Toolkit; import java.awt.datatransfer.StringSelection; -import java.util.HashMap; +import java.nio.file.Files; +import java.nio.file.Paths; import java.util.List; -import java.util.Map; import org.eclipse.core.commands.Command; import org.eclipse.core.commands.ExecutionEvent; -import org.eclipse.core.commands.IHandler; +import org.eclipse.core.resources.IWorkspace; +import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.IStatus; import org.eclipse.emf.common.util.URI; import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.emf.transaction.TransactionalEditingDomain; import org.eclipse.nebula.widgets.nattable.NatTable; -import org.eclipse.nebula.widgets.nattable.selection.command.ClearAllSelectionsCommand; +import org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer; import org.eclipse.osgi.util.NLS; import org.eclipse.papyrus.commands.OpenDiagramCommand; import org.eclipse.papyrus.infra.core.resource.ModelSet; @@ -35,7 +36,9 @@ import org.eclipse.papyrus.infra.core.sashwindows.di.service.IPageManager; import org.eclipse.papyrus.infra.emf.gmf.command.GMFtoEMFCommandWrapper; import org.eclipse.papyrus.infra.gmfdiag.common.model.NotationUtils; import org.eclipse.papyrus.infra.nattable.common.editor.NatTableEditor; -import org.eclipse.papyrus.infra.nattable.handler.PasteInTableHandler; +import org.eclipse.papyrus.infra.nattable.export.file.PapyrusFileExportCommandHandler; +import org.eclipse.papyrus.infra.nattable.export.file.PapyrusFileExporter; +import org.eclipse.papyrus.infra.nattable.export.file.command.PapyrusFileExportCommand; import org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager; import org.eclipse.papyrus.infra.nattable.manager.table.ITreeNattableModelManager; import org.eclipse.papyrus.infra.nattable.manager.table.NattableModelManager; @@ -43,10 +46,10 @@ import org.eclipse.papyrus.infra.nattable.manager.table.TreeNattableModelManager import org.eclipse.papyrus.infra.nattable.model.nattable.Table; import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisconfiguration.PasteEObjectConfiguration; import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisconfiguration.TreeFillingConfiguration; +import org.eclipse.papyrus.infra.nattable.style.configattribute.PapyrusExportConfigAttributes; import org.eclipse.papyrus.infra.nattable.tree.CollapseAndExpandActionsEnum; import org.eclipse.papyrus.infra.nattable.utils.FillingConfigurationUtils; import org.eclipse.papyrus.infra.nattable.utils.StyleUtils; -import org.eclipse.papyrus.infra.nattable.utils.TableClipboardUtils; import org.eclipse.papyrus.infra.tools.util.FileUtils; import org.eclipse.papyrus.infra.ui.util.EclipseCommandUtils; import org.eclipse.papyrus.junit.utils.EditorUtils; @@ -54,7 +57,6 @@ import org.eclipse.papyrus.junit.utils.GenericUtils; import org.eclipse.papyrus.uml.nattable.clazz.config.tests.Activator; import org.eclipse.papyrus.uml.nattable.clazz.config.tests.tests.AbstractOpenTableTest; import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.commands.ICommandService; import org.junit.AfterClass; import org.junit.Assert; import org.junit.Before; @@ -196,7 +198,7 @@ public abstract class AbstractPasteInsertTest extends AbstractOpenTableTest { Assert.assertTrue("The pasted element id is not correctly defined", CLASS_ELEMENT_ID.equals(pasteConf.getPastedElementId())); //$NON-NLS-1$ } } - }else if (depth == 1) { + } else if (depth == 1) { boolean nestedClass = false; boolean operation = false; boolean property = false; @@ -223,7 +225,7 @@ public abstract class AbstractPasteInsertTest extends AbstractOpenTableTest { Assert.assertTrue("Table configuration must contains opration", operation); //$NON-NLS-1$ Assert.assertTrue("Table configuration must not contains nestedClass", !nestedClass); //$NON-NLS-1$ } - }else if (depth == 2) { + } else if (depth == 2) { for (TreeFillingConfiguration tmp : confs) { PasteEObjectConfiguration pasteConf = tmp.getPasteConfiguration(); Assert.assertNotNull("We don't have paste configuration for a TreeFillingConfiguration, depth=" + tmp.getDepth(), pasteConf); //$NON-NLS-1$ @@ -317,19 +319,35 @@ public abstract class AbstractPasteInsertTest extends AbstractOpenTableTest { * The caught exception. */ protected void checkTableContent(final TreeNattableModelManager treeManager, final String suffixFileName) throws Exception { - flushDisplayEvents(); treeManager.doCollapseExpandAction(CollapseAndExpandActionsEnum.EXPAND_ALL, null); final NatTable natTable = (NatTable) treeManager.getAdapter(NatTable.class); flushDisplayEvents(); - natTable.doCommand(new ClearAllSelectionsCommand()); - treeManager.selectAll(); - treeManager.copyToClipboard(); - String clipboard = getClipboardContent(); - // we check than the contents of the clipboard (so the displayed table) is the same than the wanted result - Assert.assertNotNull("Clipboard must not be null", clipboard); //$NON-NLS-1$ - String str = getWantedString(getSuffixStateFileName(treeManager, suffixFileName)); + + // Unregister and register the papyrus file export to manage it without the shell + final GridLayer gridLayer = treeManager.getGridLayer(); + gridLayer.unregisterCommandHandler(PapyrusFileExportCommand.class); + gridLayer.registerCommandHandler(new PapyrusFileExportCommandHandler(gridLayer.getBodyLayer(), false)); + + // Modify the config attribute of the file export to use the file name without the shell + IWorkspace workspace = ResourcesPlugin.getWorkspace(); + final String wsFolder = workspace.getRoot().getLocation().toFile().getPath().toString(); + final String contentFile = wsFolder + "\\content.txt"; //$NON-NLS-1$ + natTable.getConfigRegistry().unregisterConfigAttribute(PapyrusExportConfigAttributes.SIMPLE_FILE_EXPORTER); + natTable.getConfigRegistry().registerConfigAttribute(PapyrusExportConfigAttributes.SIMPLE_FILE_EXPORTER, new PapyrusFileExporter(contentFile)); + treeManager.exportToFile(); + + final StringBuilder content = new StringBuilder(); + final List<String> allLines = Files.readAllLines(Paths.get(contentFile)); + for (int index = 0; index < allLines.size(); index++) { + content.append(allLines.get(index)); + if (index < allLines.size() - 1) { + content.append(FileUtils.getSystemPropertyLineSeparator()); + } + } + + final String str = getWantedString(getSuffixStateFileName(treeManager, suffixFileName)); // we check than the contents of the clipboard (so the displayed table) is the same than the wanted result - Assert.assertEquals("The clipboard must be equals to string which one it is filled", str, clipboard); //$NON-NLS-1$ + Assert.assertEquals("The clipboard must be equals to string which one it is filled", str, content.toString()); //$NON-NLS-1$ } /** @@ -375,17 +393,6 @@ public abstract class AbstractPasteInsertTest extends AbstractOpenTableTest { } /** - * Get the clipboard contents. - * - * @return - * the clipboard contents. - */ - protected String getClipboardContent() { - String clipboard = TableClipboardUtils.getClipboardContentsAsString(); - return clipboard; - } - - /** * This allows to fill the clipboard with the string in parameter. * * @param newClipBoardContents diff --git a/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.clazz.config.tests/src/org/eclipse/papyrus/uml/nattable/clazz/config/tests/paste/overwrite/AbstractPasteOverwriteTest.java b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.clazz.config.tests/src/org/eclipse/papyrus/uml/nattable/clazz/config/tests/paste/overwrite/AbstractPasteOverwriteTest.java index 4672d95bf16..59afc8f9a86 100644 --- a/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.clazz.config.tests/src/org/eclipse/papyrus/uml/nattable/clazz/config/tests/paste/overwrite/AbstractPasteOverwriteTest.java +++ b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.clazz.config.tests/src/org/eclipse/papyrus/uml/nattable/clazz/config/tests/paste/overwrite/AbstractPasteOverwriteTest.java @@ -78,7 +78,7 @@ public abstract class AbstractPasteOverwriteTest extends AbstractPasteInsertTest Assert.assertNotNull("The command service must not be null", commandService); //$NON-NLS-1$ final String fileName = getSuffixStateFileName(treeManager, TOCOPY_POST_FILE_NAME); final String str = FileUtils.getStringFromPlatformFile(Activator.PLUGIN_ID, getSourcePath(), fileName); - fillClipboard(str); + fillClipboard("Fill the clipboard to enable the handler"); //$NON-NLS-1$ // Get the paste command final Command cmd = commandService.getCommand("org.eclipse.ui.edit.paste"); //$NON-NLS-1$ @@ -89,6 +89,8 @@ public abstract class AbstractPasteOverwriteTest extends AbstractPasteInsertTest final Map<Object, Object> parameters = new HashMap<Object, Object>(); parameters.put(PasteInTableHandler.OPEN_DIALOG_ON_FAIL_BOOLEAN_PARAMETER, Boolean.FALSE); parameters.put(PasteInTableHandler.OPEN__PROGRESS_MONITOR_DIALOG, Boolean.FALSE); + // This parameters allows to set the text to paste instead of copy/paste it programmatically (this may be overwrite by other copy) + parameters.put(PasteInTableHandler.TEXT_TO_PASTE, str); final ExecutionEvent event = new ExecutionEvent(cmd, parameters, null, null); flushDisplayEvents(); final Object res = cmd.executeWithChecks(event); diff --git a/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.clazz.config.tests/src/org/eclipse/papyrus/uml/nattable/clazz/config/tests/paste/tests/AbstractPasteWithCategoriesTests.java b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.clazz.config.tests/src/org/eclipse/papyrus/uml/nattable/clazz/config/tests/paste/tests/AbstractPasteWithCategoriesTests.java index 6ce9c34040b..67fc067005d 100644 --- a/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.clazz.config.tests/src/org/eclipse/papyrus/uml/nattable/clazz/config/tests/paste/tests/AbstractPasteWithCategoriesTests.java +++ b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.clazz.config.tests/src/org/eclipse/papyrus/uml/nattable/clazz/config/tests/paste/tests/AbstractPasteWithCategoriesTests.java @@ -39,6 +39,7 @@ import org.eclipse.papyrus.infra.emf.gmf.command.CheckedOperationHistory; import org.eclipse.papyrus.infra.emf.gmf.command.GMFtoEMFCommandWrapper; import org.eclipse.papyrus.infra.gmfdiag.common.model.NotationUtils; import org.eclipse.papyrus.infra.nattable.common.editor.NatTableEditor; +import org.eclipse.papyrus.infra.nattable.handler.PasteInTableHandler; import org.eclipse.papyrus.infra.nattable.manager.table.AbstractNattableWidgetManager; import org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager; import org.eclipse.papyrus.infra.nattable.manager.table.ITreeNattableModelManager; @@ -252,7 +253,7 @@ public abstract class AbstractPasteWithCategoriesTests extends AbstractOpenTable Assert.assertNotNull(commandService); final String fileName = getPasteFileName(); final String str = FileUtils.getStringFromPlatformFile(Activator.PLUGIN_ID, getSourcePath(), fileName); - fillClipboard(str); + fillClipboard("Fill the clipboard to enable the handler"); //$NON-NLS-1$ final Command cmd = commandService.getCommand("org.eclipse.ui.edit.paste"); //$NON-NLS-1$ final IHandler handler = cmd.getHandler(); @@ -262,6 +263,8 @@ public abstract class AbstractPasteWithCategoriesTests extends AbstractOpenTable final Map<Object, Object> parameters = new HashMap<Object, Object>(); parameters.put(AbstractPasteInsertInTableHandler.OPEN_DIALOG_ON_FAIL_BOOLEAN_PARAMETER, Boolean.FALSE); parameters.put(AbstractPasteInsertInTableHandler.OPEN__PROGRESS_MONITOR_DIALOG, Boolean.FALSE); + // This parameters allows to set the text to paste instead of copy/paste it programmatically (this may be overwrite by other copy) + parameters.put(PasteInTableHandler.TEXT_TO_PASTE, str); final ExecutionEvent event = new ExecutionEvent(cmd, parameters, null, null); flushDisplayEvents(); final Object res = cmd.executeWithChecks(event); diff --git a/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/importfile/AbstractImportTest.java b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/importfile/AbstractImportTest.java index 6dc078fc3f4..baa3dd1765f 100644 --- a/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/importfile/AbstractImportTest.java +++ b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/importfile/AbstractImportTest.java @@ -19,8 +19,6 @@ import java.util.Map; import org.eclipse.core.commands.Command; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.IHandler; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Path; import org.eclipse.emf.common.util.URI; import org.eclipse.papyrus.infra.nattable.common.editor.NatTableEditor; import org.eclipse.papyrus.infra.nattable.handler.ImportTableHandler; @@ -124,8 +122,8 @@ public abstract class AbstractImportTest extends AbstractPasteInsertTest { buffer.append(FileUtils.CSV_EXTENSIOn); String csvFileAsString = getWantedString(buffer.toString()); - - parameters.put(ImportTableHandler.SELECTED_FILE_PATH_STRING_PARAMETER, csvFileAsString); + + parameters.put(ImportTableHandler.SELECTED_FILE_PATH_STRING_PARAMETER, csvFileAsString); } /** diff --git a/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/insert/AbstractInsertTest.java b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/insert/AbstractInsertTest.java index 8779e83a5a7..1c5e9434e25 100644 --- a/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/insert/AbstractInsertTest.java +++ b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/insert/AbstractInsertTest.java @@ -78,7 +78,7 @@ public abstract class AbstractInsertTest extends AbstractPasteInsertTest { Assert.assertNotNull("The command service must not be null", commandService); //$NON-NLS-1$ final String fileName = getSuffixStateFileName(manager, TOCOPY_POST_FILE_NAME); final String str = FileUtils.getStringFromPlatformFile(Activator.PLUGIN_ID, getSourcePath(), fileName); - fillClipboard(str); + fillClipboard("Fill the clipboard to enable the handler"); //$NON-NLS-1$ // Get the paste command final Command cmd = commandService.getCommand(getCommandId()); // $NON-NLS-1$ @@ -89,6 +89,8 @@ public abstract class AbstractInsertTest extends AbstractPasteInsertTest { final Map<Object, Object> parameters = new HashMap<Object, Object>(); parameters.put(PasteInTableHandler.OPEN_DIALOG_ON_FAIL_BOOLEAN_PARAMETER, Boolean.FALSE); parameters.put(PasteInTableHandler.OPEN__PROGRESS_MONITOR_DIALOG, Boolean.FALSE); + // This parameters allows to set the text to paste instead of copy/paste it programmatically (this may be overwrite by other copy) + parameters.put(PasteInTableHandler.TEXT_TO_PASTE, str); manageParameters(parameters); final ExecutionEvent event = new ExecutionEvent(cmd, parameters, null, null); flushDisplayEvents(); diff --git a/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/paste/overwrite/AbstractPasteEmptyOverwriteTest.java b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/paste/overwrite/AbstractPasteEmptyOverwriteTest.java index cc15369d0f9..fe5c9777a89 100644 --- a/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/paste/overwrite/AbstractPasteEmptyOverwriteTest.java +++ b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/paste/overwrite/AbstractPasteEmptyOverwriteTest.java @@ -68,7 +68,7 @@ public abstract class AbstractPasteEmptyOverwriteTest extends AbstractPasteOverw Assert.assertNotNull("The command service must not be null", commandService); //$NON-NLS-1$ final String fileName = getSuffixStateFileName(manager, TOCOPY_POST_FILE_NAME); final String str = FileUtils.getStringFromPlatformFile(Activator.PLUGIN_ID, getSourcePath(), fileName); - fillClipboard(str); + fillClipboard("Fill the clipboard to enable the handler"); //$NON-NLS-1$ // Get the paste command final Command cmd = commandService.getCommand("org.eclipse.ui.edit.paste"); //$NON-NLS-1$ @@ -79,6 +79,8 @@ public abstract class AbstractPasteEmptyOverwriteTest extends AbstractPasteOverw final Map<Object, Object> parameters = new HashMap<Object, Object>(); parameters.put(PasteInTableHandler.OPEN_DIALOG_ON_FAIL_BOOLEAN_PARAMETER, Boolean.FALSE); parameters.put(PasteInTableHandler.OPEN__PROGRESS_MONITOR_DIALOG, Boolean.FALSE); + // This parameters allows to set the text to paste instead of copy/paste it programmatically (this may be overwrite by other copy) + parameters.put(PasteInTableHandler.TEXT_TO_PASTE, str); manageParameters(parameters); final ExecutionEvent event = new ExecutionEvent(cmd, parameters, null, null); flushDisplayEvents(); diff --git a/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/paste/overwrite/AbstractPasteInsertTest.java b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/paste/overwrite/AbstractPasteInsertTest.java index 387791ed45f..8ed51a8048a 100644 --- a/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/paste/overwrite/AbstractPasteInsertTest.java +++ b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/paste/overwrite/AbstractPasteInsertTest.java @@ -15,13 +15,21 @@ package org.eclipse.papyrus.uml.nattable.generic.tests.paste.overwrite; import java.awt.Toolkit; import java.awt.datatransfer.StringSelection; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.List; +import org.eclipse.core.resources.IWorkspace; +import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.IStatus; import org.eclipse.emf.common.util.URI; import org.eclipse.nebula.widgets.nattable.NatTable; -import org.eclipse.nebula.widgets.nattable.selection.command.ClearAllSelectionsCommand; +import org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer; +import org.eclipse.papyrus.infra.nattable.export.file.PapyrusFileExportCommandHandler; +import org.eclipse.papyrus.infra.nattable.export.file.PapyrusFileExporter; +import org.eclipse.papyrus.infra.nattable.export.file.command.PapyrusFileExportCommand; import org.eclipse.papyrus.infra.nattable.manager.table.NattableModelManager; -import org.eclipse.papyrus.infra.nattable.utils.TableClipboardUtils; +import org.eclipse.papyrus.infra.nattable.style.configattribute.PapyrusExportConfigAttributes; import org.eclipse.papyrus.infra.tools.util.FileUtils; import org.eclipse.papyrus.junit.utils.GenericUtils; import org.eclipse.papyrus.uml.nattable.generic.tests.Activator; @@ -121,15 +129,32 @@ public abstract class AbstractPasteInsertTest extends AbstractGenericTableTest { protected void checkTableContent(final NattableModelManager manager, final String suffixFileName) throws Exception { final NatTable natTable = (NatTable) manager.getAdapter(NatTable.class); flushDisplayEvents(); - natTable.doCommand(new ClearAllSelectionsCommand()); - manager.selectAll(); - manager.copyToClipboard(); - String clipboard = getClipboardContent(); - // we check than the contents of the clipboard (so the displayed table) is the same than the wanted result - Assert.assertNotNull("Clipboard must not be null", clipboard); //$NON-NLS-1$ - String str = getWantedString(getSuffixStateFileName(manager, suffixFileName)); + + // Unregister and register the papyrus file export to manage it without the shell + final GridLayer gridLayer = manager.getGridLayer(); + gridLayer.unregisterCommandHandler(PapyrusFileExportCommand.class); + gridLayer.registerCommandHandler(new PapyrusFileExportCommandHandler(gridLayer.getBodyLayer(), false)); + + // Modify the config attribute of the file export to use the file name without the shell + IWorkspace workspace = ResourcesPlugin.getWorkspace(); + final String wsFolder = workspace.getRoot().getLocation().toFile().getPath().toString(); + final String contentFile = wsFolder + "\\content.txt"; //$NON-NLS-1$ + natTable.getConfigRegistry().unregisterConfigAttribute(PapyrusExportConfigAttributes.SIMPLE_FILE_EXPORTER); + natTable.getConfigRegistry().registerConfigAttribute(PapyrusExportConfigAttributes.SIMPLE_FILE_EXPORTER, new PapyrusFileExporter(contentFile)); + manager.exportToFile(); + + final StringBuilder content = new StringBuilder(); + final List<String> allLines = Files.readAllLines(Paths.get(contentFile)); + for (int index = 0; index < allLines.size(); index++) { + content.append(allLines.get(index)); + if (index < allLines.size() - 1) { + content.append(FileUtils.getSystemPropertyLineSeparator()); + } + } + + final String str = getWantedString(getSuffixStateFileName(manager, suffixFileName)); // we check than the contents of the clipboard (so the displayed table) is the same than the wanted result - Assert.assertEquals("The clipboard must be equals to string which one it is filled", str, clipboard); //$NON-NLS-1$ + Assert.assertEquals("The clipboard must be equals to string which one it is filled", str, content.toString()); //$NON-NLS-1$ } /** @@ -164,17 +189,6 @@ public abstract class AbstractPasteInsertTest extends AbstractGenericTableTest { } /** - * Get the clipboard contents. - * - * @return - * the clipboard contents. - */ - protected String getClipboardContent() { - String clipboard = TableClipboardUtils.getClipboardContentsAsString(); - return clipboard; - } - - /** * This allows to fill the clipboard with the string in parameter. * * @param newClipBoardContents diff --git a/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/paste/overwrite/AbstractPasteOverwriteTest.java b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/paste/overwrite/AbstractPasteOverwriteTest.java index c95821ed365..d9d0b99d686 100644 --- a/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/paste/overwrite/AbstractPasteOverwriteTest.java +++ b/tests/junit/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable.generic.tests/src/org/eclipse/papyrus/uml/nattable/generic/tests/paste/overwrite/AbstractPasteOverwriteTest.java @@ -77,7 +77,7 @@ public abstract class AbstractPasteOverwriteTest extends AbstractPasteInsertTest Assert.assertNotNull("The command service must not be null", commandService); //$NON-NLS-1$ final String fileName = getSuffixStateFileName(manager, TOCOPY_POST_FILE_NAME); final String str = FileUtils.getStringFromPlatformFile(Activator.PLUGIN_ID, getSourcePath(), fileName); - fillClipboard(str); + fillClipboard("Fill the clipboard to enable the handler"); //$NON-NLS-1$ // Get the paste command final Command cmd = commandService.getCommand("org.eclipse.ui.edit.paste"); //$NON-NLS-1$ @@ -88,6 +88,8 @@ public abstract class AbstractPasteOverwriteTest extends AbstractPasteInsertTest final Map<Object, Object> parameters = new HashMap<Object, Object>(); parameters.put(PasteInTableHandler.OPEN_DIALOG_ON_FAIL_BOOLEAN_PARAMETER, Boolean.FALSE); parameters.put(PasteInTableHandler.OPEN__PROGRESS_MONITOR_DIALOG, Boolean.FALSE); + // This parameters allows to set the text to paste instead of copy/paste it programmatically (this may be overwrite by other copy) + parameters.put(PasteInTableHandler.TEXT_TO_PASTE, str); final ExecutionEvent event = new ExecutionEvent(cmd, parameters, null, null); flushDisplayEvents(); final Object res = cmd.executeWithChecks(event); @@ -106,7 +108,6 @@ public abstract class AbstractPasteOverwriteTest extends AbstractPasteInsertTest } } - /** * {@inheritDoc} * |