summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenoit Maggi2014-05-19 04:15:33 (EDT)
committerRemi Schnekenburger2014-05-21 05:57:59 (EDT)
commit2c08d24b7cbdd89b10f125b423c8a6a383fb5750 (patch)
tree3d891bd30232571df1efcd85ff18e853781c61e1
parent145a9ef0517cc70850e59f28ec2814fb3137e57b (diff)
downloadorg.eclipse.papyrus-2c08d24b7cbdd89b10f125b423c8a6a383fb5750.zip
org.eclipse.papyrus-2c08d24b7cbdd89b10f125b423c8a6a383fb5750.tar.gz
org.eclipse.papyrus-2c08d24b7cbdd89b10f125b423c8a6a383fb5750.tar.bz2
Bug 405565 -[Papyrus Model Explorer] Papyrus Model Explorer shall enablerefs/changes/19/26819/2
copy/past with views. - Add TablePasteStrategy for copy/paste in Model explorer - Active TableCopyPasteModelExplorerTest Change-Id: I696dced555d7cdc88af74e34f2f16b976b2c4bb3 Signed-off-by: Benoit Maggi <benoit.maggi@cea.fr>
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.common/plugin.xml462
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.common/src/org/eclipse/papyrus/infra/nattable/common/commands/InsertTableCommand.java60
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.common/src/org/eclipse/papyrus/infra/nattable/common/strategy/paste/TablePasteStrategy.java247
-rw-r--r--plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.common/src/org/eclipse/papyrus/infra/nattable/common/utils/TableUtil.java74
-rw-r--r--tests/junit/plugins/uml/modelexplorer/org.eclipse.papyrus.uml.modelexplorer.tests/src/org/eclipse/papyrus/uml/modelexplorer/tests/paste/TableCopyPasteModelExplorerTest.java1
5 files changed, 615 insertions, 229 deletions
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.common/plugin.xml b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.common/plugin.xml
index 93fcd4b..9c4ae1c 100644
--- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.common/plugin.xml
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.common/plugin.xml
@@ -1,229 +1,235 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<?eclipse version="3.4"?>
-<plugin>
-<!--We declare the model used for the Papyrus Table Editor -->
- <extension point="org.eclipse.papyrus.infra.core.model">
- <model classname="org.eclipse.papyrus.infra.nattable.common.modelresource.PapyrusNattableModel" description="Model for Papyrus Nattable editors">
- </model>
- </extension>
- <extension id="papyrus.table.menuspapyrus.table.menu" name="Papyrus Table Menus" point="org.eclipse.ui.menus">
- <menuContribution allPopups="false" locationURI="popup:org.eclipse.papyrus.views.modelexplorer.modelexplorer.popup?after=org.eclipse.papyrus.views.modelexplorer.popupmenu.creatediagram">
- <menu icon="platform:/plugin/org.eclipse.papyrus.infra.viewpoints.policy/icons/NewTable.gif" id="org.eclipse.papyrus.infra.nattable.popupmenu.createnattable" label="New Table" mnemonic="&amp;T" tooltip="The Papyrus Table Menu">
- <dynamic
- class="org.eclipse.papyrus.infra.nattable.common.handlers.DynamicTablesMenuContribution"
- id="org.eclipse.papyrus.infra.nattable.common.handlers.DynamicTablesMenuContribution">
- </dynamic>
- </menu>
- </menuContribution>
- <menuContribution allPopups="false" locationURI="menu:org.eclipse.papyrus.ui.menu?after=org.eclipse.papyrus.uml.diagram.ui.menu.diagrams">
- <menu
- icon="platform:/plugin/org.eclipse.papyrus.infra.viewpoints.policy/icons/NewTable.gif"
- id="org.eclipse.papyrus.infra.nattable.menu.createnattable"
- label="New Table"
- mnemonic="&amp;T"
- tooltip="The Papyrus Table Menu">
- <dynamic
- class="org.eclipse.papyrus.infra.nattable.common.handlers.DynamicTablesMenuContribution"
- id="org.eclipse.papyrus.infra.nattable.common.handlers.DynamicTablesMenuContribution">
- </dynamic>
- </menu>
- </menuContribution>
-
- <menuContribution locationURI="toolbar:org.eclipse.ui.main.toolbar?endof=org.eclipse.papyrus.uml.diagram.ui.toolbar">
- <toolbar id="org.eclipse.papyrus.infra.nattable.toolbar.createnattable" label="New Table Toolbar (New Version)">
- </toolbar>
- </menuContribution>
- <menuContribution
- allPopups="false"
- locationURI="menu:org.eclipse.papyrus.infra.nattable.menu.createnattable">
- <command
- commandId="org.eclipse.papyrus.infra.nattable.createFromCatalog.command"
- mnemonic="&amp;G"
- style="push">
- <visibleWhen>
- <with
- variable="activeEditorId">
- <equals
- value="org.eclipse.papyrus.infra.core.papyrusEditor">
- </equals>
- </with>
- </visibleWhen>
- </command>
- </menuContribution>
- <menuContribution
- allPopups="false"
- locationURI="toolbar:org.eclipse.papyrus.infra.nattable.toolbar.createnattable">
- <command
- commandId="org.eclipse.papyrus.infra.nattable.createFromCatalog.command"
- mnemonic="&amp;G"
- style="push">
- <visibleWhen>
- <with
- variable="activeEditorId">
- <equals
- value="org.eclipse.papyrus.infra.core.papyrusEditor">
- </equals>
- </with>
- </visibleWhen>
- </command>
- </menuContribution>
- <menuContribution
- allPopups="false"
- locationURI="popup:org.eclipse.papyrus.infra.nattable.popupmenu.createnattable">
- <command
- commandId="org.eclipse.papyrus.infra.nattable.createFromCatalog.command"
- mnemonic="&amp;G"
- style="push">
- <visibleWhen>
- <with
- variable="activeEditorId">
- <equals
- value="org.eclipse.papyrus.infra.core.papyrusEditor">
- </equals>
- </with>
- </visibleWhen>
- </command>
- </menuContribution>
- </extension>
- <extension
- point="org.eclipse.ui.commands">
- <command
- categoryId="org.eclipse.papyrus.editor.category"
- description="Create a NatTable from Configurations Catalog"
- id="org.eclipse.papyrus.infra.nattable.createFromCatalog.command"
- name="Create a new Table from the Configurations Catalog">
- </command>
- </extension>
- <extension
- point="org.eclipse.ui.handlers">
- <handler
- commandId="org.eclipse.papyrus.infra.nattable.createFromCatalog.command">
- <class
- class="org.eclipse.papyrus.infra.nattable.common.handlers.CreateNatTableFromCatalogHandler">
- </class>
- </handler>
- </extension>
-
- <extension
- point="org.eclipse.papyrus.infra.core.papyrusDiagram">
- <editorDiagram
- factoryClass="org.eclipse.papyrus.infra.nattable.common.factory.NattableEditorFactory"
- icon="icons/table.gif">
- </editorDiagram>
- </extension>
- <extension
- point="org.eclipse.ui.handlers">
- <handler
- class="org.eclipse.papyrus.infra.nattable.common.handlers.RenameTableHandler"
- commandId="org.eclipse.papyrus.infra.core.sasheditor.command.tabdoubleclick">
- <activeWhen>
- <and>
- <with
- variable="selection">
- <test
- property="org.eclipse.papyrus.infra.nattable.tester.isNattableWidget"
- value="true">
- </test>
- </with>
- </and>
- </activeWhen>
- </handler>
- </extension>
- <!-- ElementType bindings for diagram duplication with paste command -->
- <extension
- point="org.eclipse.gmf.runtime.emf.type.core.elementTypes">
- <!--metamodel
- nsURI="http://www.eclipse.org/uml2/5.0.0/UML"-->
- <metamodel
- nsURI="http://www.eclipse.org/uml2/5.0.0/UML">
- <adviceBinding
- class="org.eclipse.papyrus.infra.nattable.common.helper.advice.NatTableDuplicateEditHelperAdvice"
- id="org.eclipse.papyrus.infra.nattable.common.helper.advice.NatTableDuplicateEditHelperAdvice"
- inheritance="all"
- typeId="org.eclipse.papyrus.uml.Element">
- <!--typeId="org.eclipse.papyrus.uml.Element"-->
- </adviceBinding>
- </metamodel>
- </extension>
-
-<extension point="org.eclipse.gmf.runtime.emf.type.core.elementTypeBindings">
-
- <!-- Bindings declaration -->
- <binding context="org.eclipse.papyrus.infra.services.edit.TypeContext">
- <advice ref="org.eclipse.papyrus.infra.nattable.common.helper.advice.NatTableDuplicateEditHelperAdvice" />
- </binding>
-</extension>
-<extension
- point="org.eclipse.ui.commandImages">
- <image
- commandId="org.eclipse.papyrus.infra.nattable.createFromCatalog.command"
- icon="icons/tableCatalog.png">
- </image>
-</extension>
-<extension
- point="org.eclipse.core.runtime.adapters">
- <factory
- adaptableType="org.eclipse.papyrus.infra.nattable.model.nattable.Table"
- class="org.eclipse.papyrus.infra.nattable.common.adapter.NattableAdapterFactory">
- <adapter
- type="org.eclipse.papyrus.infra.core.sasheditor.di.contentprovider.IOpenable">
- </adapter>
- </factory>
-</extension>
-<extension
- point="org.eclipse.ui.menus">
- <menuContribution
- allPopups="false"
- locationURI="toolbar:org.eclipse.ui.main.toolbar">
- <toolbar
- id="org.eclipse.papyrus.infra.viewpoints.policy.toolbar">
- <command
- commandId="org.eclipse.papyrus.infra.viewpoints.policy.toolbar.tables.command"
- icon="platform:/plugin/org.eclipse.papyrus.infra.viewpoints.policy/icons/NewTable.gif"
- id="org.eclipse.papyrus.infra.viewpoints.policy.toolbar.tables.command"
- label="Create a new table ..."
- style="pulldown"
- tooltip="Create a new table ...">
- <visibleWhen
- checkEnabled="false">
- <with
- variable="activeEditorId">
- <equals
- value="org.eclipse.papyrus.infra.core.papyrusEditor">
- </equals>
- </with>
- </visibleWhen>
- </command>
- </toolbar>
- </menuContribution>
- <menuContribution
- allPopups="false"
- locationURI="menu:org.eclipse.papyrus.infra.viewpoints.policy.toolbar.tables.command">
- <dynamic
- class="org.eclipse.papyrus.infra.nattable.common.handlers.DynamicTablesMenuContribution"
- id="org.eclipse.papyrus.infra.nattable.common.handlers.DynamicTablesMenuContribution">
- </dynamic>
- </menuContribution>
-</extension>
-<extension
- point="org.eclipse.ui.commands">
- <command
- categoryId="org.eclipse.papyrus.infra.viewpoints.policy.commands"
- defaultHandler="org.eclipse.papyrus.infra.viewpoints.policy.DynamicCommandHandler"
- id="org.eclipse.papyrus.infra.viewpoints.policy.toolbar.tables.command"
- name="Create Dynamic Table Command">
- </command>
-</extension>
-<extension
- point="org.eclipse.papyrus.infra.viewpoints.policy.viewType">
- <helper
- class="org.eclipse.papyrus.infra.nattable.common.helper.TableCommandHelper">
- </helper>
-</extension>
-<extension
- point="org.eclipse.papyrus.infra.viewpoints.policy.viewType">
- <helper
- class="org.eclipse.papyrus.infra.nattable.common.helper.SyncTableCommandHelper">
- </helper>
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.4"?>
+<plugin>
+<!--We declare the model used for the Papyrus Table Editor -->
+ <extension point="org.eclipse.papyrus.infra.core.model">
+ <model classname="org.eclipse.papyrus.infra.nattable.common.modelresource.PapyrusNattableModel" description="Model for Papyrus Nattable editors">
+ </model>
+ </extension>
+ <extension id="papyrus.table.menuspapyrus.table.menu" name="Papyrus Table Menus" point="org.eclipse.ui.menus">
+ <menuContribution allPopups="false" locationURI="popup:org.eclipse.papyrus.views.modelexplorer.modelexplorer.popup?after=org.eclipse.papyrus.views.modelexplorer.popupmenu.creatediagram">
+ <menu icon="platform:/plugin/org.eclipse.papyrus.infra.viewpoints.policy/icons/NewTable.gif" id="org.eclipse.papyrus.infra.nattable.popupmenu.createnattable" label="New Table" mnemonic="&amp;T" tooltip="The Papyrus Table Menu">
+ <dynamic
+ class="org.eclipse.papyrus.infra.nattable.common.handlers.DynamicTablesMenuContribution"
+ id="org.eclipse.papyrus.infra.nattable.common.handlers.DynamicTablesMenuContribution">
+ </dynamic>
+ </menu>
+ </menuContribution>
+ <menuContribution allPopups="false" locationURI="menu:org.eclipse.papyrus.ui.menu?after=org.eclipse.papyrus.uml.diagram.ui.menu.diagrams">
+ <menu
+ icon="platform:/plugin/org.eclipse.papyrus.infra.viewpoints.policy/icons/NewTable.gif"
+ id="org.eclipse.papyrus.infra.nattable.menu.createnattable"
+ label="New Table"
+ mnemonic="&amp;T"
+ tooltip="The Papyrus Table Menu">
+ <dynamic
+ class="org.eclipse.papyrus.infra.nattable.common.handlers.DynamicTablesMenuContribution"
+ id="org.eclipse.papyrus.infra.nattable.common.handlers.DynamicTablesMenuContribution">
+ </dynamic>
+ </menu>
+ </menuContribution>
+
+ <menuContribution locationURI="toolbar:org.eclipse.ui.main.toolbar?endof=org.eclipse.papyrus.uml.diagram.ui.toolbar">
+ <toolbar id="org.eclipse.papyrus.infra.nattable.toolbar.createnattable" label="New Table Toolbar (New Version)">
+ </toolbar>
+ </menuContribution>
+ <menuContribution
+ allPopups="false"
+ locationURI="menu:org.eclipse.papyrus.infra.nattable.menu.createnattable">
+ <command
+ commandId="org.eclipse.papyrus.infra.nattable.createFromCatalog.command"
+ mnemonic="&amp;G"
+ style="push">
+ <visibleWhen>
+ <with
+ variable="activeEditorId">
+ <equals
+ value="org.eclipse.papyrus.infra.core.papyrusEditor">
+ </equals>
+ </with>
+ </visibleWhen>
+ </command>
+ </menuContribution>
+ <menuContribution
+ allPopups="false"
+ locationURI="toolbar:org.eclipse.papyrus.infra.nattable.toolbar.createnattable">
+ <command
+ commandId="org.eclipse.papyrus.infra.nattable.createFromCatalog.command"
+ mnemonic="&amp;G"
+ style="push">
+ <visibleWhen>
+ <with
+ variable="activeEditorId">
+ <equals
+ value="org.eclipse.papyrus.infra.core.papyrusEditor">
+ </equals>
+ </with>
+ </visibleWhen>
+ </command>
+ </menuContribution>
+ <menuContribution
+ allPopups="false"
+ locationURI="popup:org.eclipse.papyrus.infra.nattable.popupmenu.createnattable">
+ <command
+ commandId="org.eclipse.papyrus.infra.nattable.createFromCatalog.command"
+ mnemonic="&amp;G"
+ style="push">
+ <visibleWhen>
+ <with
+ variable="activeEditorId">
+ <equals
+ value="org.eclipse.papyrus.infra.core.papyrusEditor">
+ </equals>
+ </with>
+ </visibleWhen>
+ </command>
+ </menuContribution>
+ </extension>
+ <extension
+ point="org.eclipse.ui.commands">
+ <command
+ categoryId="org.eclipse.papyrus.editor.category"
+ description="Create a NatTable from Configurations Catalog"
+ id="org.eclipse.papyrus.infra.nattable.createFromCatalog.command"
+ name="Create a new Table from the Configurations Catalog">
+ </command>
+ </extension>
+ <extension
+ point="org.eclipse.ui.handlers">
+ <handler
+ commandId="org.eclipse.papyrus.infra.nattable.createFromCatalog.command">
+ <class
+ class="org.eclipse.papyrus.infra.nattable.common.handlers.CreateNatTableFromCatalogHandler">
+ </class>
+ </handler>
+ </extension>
+
+ <extension
+ point="org.eclipse.papyrus.infra.core.papyrusDiagram">
+ <editorDiagram
+ factoryClass="org.eclipse.papyrus.infra.nattable.common.factory.NattableEditorFactory"
+ icon="icons/table.gif">
+ </editorDiagram>
+ </extension>
+ <extension
+ point="org.eclipse.ui.handlers">
+ <handler
+ class="org.eclipse.papyrus.infra.nattable.common.handlers.RenameTableHandler"
+ commandId="org.eclipse.papyrus.infra.core.sasheditor.command.tabdoubleclick">
+ <activeWhen>
+ <and>
+ <with
+ variable="selection">
+ <test
+ property="org.eclipse.papyrus.infra.nattable.tester.isNattableWidget"
+ value="true">
+ </test>
+ </with>
+ </and>
+ </activeWhen>
+ </handler>
+ </extension>
+ <!-- ElementType bindings for diagram duplication with paste command -->
+ <extension
+ point="org.eclipse.gmf.runtime.emf.type.core.elementTypes">
+ <!--metamodel
+ nsURI="http://www.eclipse.org/uml2/5.0.0/UML"-->
+ <metamodel
+ nsURI="http://www.eclipse.org/uml2/5.0.0/UML">
+ <adviceBinding
+ class="org.eclipse.papyrus.infra.nattable.common.helper.advice.NatTableDuplicateEditHelperAdvice"
+ id="org.eclipse.papyrus.infra.nattable.common.helper.advice.NatTableDuplicateEditHelperAdvice"
+ inheritance="all"
+ typeId="org.eclipse.papyrus.uml.Element">
+ <!--typeId="org.eclipse.papyrus.uml.Element"-->
+ </adviceBinding>
+ </metamodel>
+ </extension>
+
+<extension point="org.eclipse.gmf.runtime.emf.type.core.elementTypeBindings">
+
+ <!-- Bindings declaration -->
+ <binding context="org.eclipse.papyrus.infra.services.edit.TypeContext">
+ <advice ref="org.eclipse.papyrus.infra.nattable.common.helper.advice.NatTableDuplicateEditHelperAdvice" />
+ </binding>
</extension>
-</plugin>
+<extension
+ point="org.eclipse.ui.commandImages">
+ <image
+ commandId="org.eclipse.papyrus.infra.nattable.createFromCatalog.command"
+ icon="icons/tableCatalog.png">
+ </image>
+</extension>
+<extension
+ point="org.eclipse.core.runtime.adapters">
+ <factory
+ adaptableType="org.eclipse.papyrus.infra.nattable.model.nattable.Table"
+ class="org.eclipse.papyrus.infra.nattable.common.adapter.NattableAdapterFactory">
+ <adapter
+ type="org.eclipse.papyrus.infra.core.sasheditor.di.contentprovider.IOpenable">
+ </adapter>
+ </factory>
+</extension>
+<extension
+ point="org.eclipse.ui.menus">
+ <menuContribution
+ allPopups="false"
+ locationURI="toolbar:org.eclipse.ui.main.toolbar">
+ <toolbar
+ id="org.eclipse.papyrus.infra.viewpoints.policy.toolbar">
+ <command
+ commandId="org.eclipse.papyrus.infra.viewpoints.policy.toolbar.tables.command"
+ icon="platform:/plugin/org.eclipse.papyrus.infra.viewpoints.policy/icons/NewTable.gif"
+ id="org.eclipse.papyrus.infra.viewpoints.policy.toolbar.tables.command"
+ label="Create a new table ..."
+ style="pulldown"
+ tooltip="Create a new table ...">
+ <visibleWhen
+ checkEnabled="false">
+ <with
+ variable="activeEditorId">
+ <equals
+ value="org.eclipse.papyrus.infra.core.papyrusEditor">
+ </equals>
+ </with>
+ </visibleWhen>
+ </command>
+ </toolbar>
+ </menuContribution>
+ <menuContribution
+ allPopups="false"
+ locationURI="menu:org.eclipse.papyrus.infra.viewpoints.policy.toolbar.tables.command">
+ <dynamic
+ class="org.eclipse.papyrus.infra.nattable.common.handlers.DynamicTablesMenuContribution"
+ id="org.eclipse.papyrus.infra.nattable.common.handlers.DynamicTablesMenuContribution">
+ </dynamic>
+ </menuContribution>
+</extension>
+<extension
+ point="org.eclipse.ui.commands">
+ <command
+ categoryId="org.eclipse.papyrus.infra.viewpoints.policy.commands"
+ defaultHandler="org.eclipse.papyrus.infra.viewpoints.policy.DynamicCommandHandler"
+ id="org.eclipse.papyrus.infra.viewpoints.policy.toolbar.tables.command"
+ name="Create Dynamic Table Command">
+ </command>
+</extension>
+<extension
+ point="org.eclipse.papyrus.infra.viewpoints.policy.viewType">
+ <helper
+ class="org.eclipse.papyrus.infra.nattable.common.helper.TableCommandHelper">
+ </helper>
+</extension>
+<extension
+ point="org.eclipse.papyrus.infra.viewpoints.policy.viewType">
+ <helper
+ class="org.eclipse.papyrus.infra.nattable.common.helper.SyncTableCommandHelper">
+ </helper>
+</extension>
+<extension
+ point="org.eclipse.papyrus.infra.gmfdiag.common.pasteStrategy">
+ <strategy
+ strategy="org.eclipse.papyrus.infra.nattable.common.strategy.paste.TablePasteStrategy">
+ </strategy>
+</extension>
+</plugin>
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.common/src/org/eclipse/papyrus/infra/nattable/common/commands/InsertTableCommand.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.common/src/org/eclipse/papyrus/infra/nattable/common/commands/InsertTableCommand.java
new file mode 100644
index 0000000..306907b
--- /dev/null
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.common/src/org/eclipse/papyrus/infra/nattable/common/commands/InsertTableCommand.java
@@ -0,0 +1,60 @@
+/*****************************************************************************
+ * Copyright (c) 2014 CEA LIST.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Benoit Maggi (CEA LIST) benoit.maggi@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.nattable.common.commands;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.transaction.RecordingCommand;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.papyrus.infra.gmfdiag.common.model.NotationUtils;
+import org.eclipse.papyrus.infra.nattable.model.nattable.Table;
+
+
+/**
+ * Insert a table with the specified owner
+ */
+public class InsertTableCommand extends RecordingCommand{
+
+ /** FIXME the domain of Recording command should be accessible */
+ protected TransactionalEditingDomain transactionalEditingDomain;
+
+ /** table to be inserted */
+ protected Table table;
+
+ /** owner of the table */
+ protected EObject owner;
+
+ /**
+ * @param transactionalEditingDomain
+ * @param label
+ * @param table to be inserted
+ * @param owner of the table
+ */
+ public InsertTableCommand(TransactionalEditingDomain transactionalEditingDomain, String label, Table table, EObject owner) {
+ super(transactionalEditingDomain, label);
+ this.transactionalEditingDomain = transactionalEditingDomain;
+ this.owner = owner;
+ this.table = table;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.emf.transaction.RecordingCommand#doExecute()
+ */
+ @Override
+ protected void doExecute() {
+ Resource targetResource = NotationUtils.getNotationResourceForDiagram(owner, transactionalEditingDomain);
+ table.setOwner(owner);
+ if(targetResource != null) {
+ targetResource.getContents().add(table);
+ }
+ }
+}
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.common/src/org/eclipse/papyrus/infra/nattable/common/strategy/paste/TablePasteStrategy.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.common/src/org/eclipse/papyrus/infra/nattable/common/strategy/paste/TablePasteStrategy.java
new file mode 100644
index 0000000..2b1604e
--- /dev/null
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.common/src/org/eclipse/papyrus/infra/nattable/common/strategy/paste/TablePasteStrategy.java
@@ -0,0 +1,247 @@
+/*****************************************************************************
+ * Copyright (c) 2014 CEA LIST.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Benoit Maggi (CEA LIST) benoit.maggi@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.nattable.common.strategy.paste;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.emf.common.command.CompoundCommand;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.papyrus.infra.core.clipboard.IClipboardAdditionalData;
+import org.eclipse.papyrus.infra.core.clipboard.PapyrusClipboard;
+import org.eclipse.papyrus.infra.gmfdiag.common.Activator;
+import org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.AbstractPasteStrategy;
+import org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.DefaultPasteStrategy;
+import org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.IPasteStrategy;
+import org.eclipse.papyrus.infra.nattable.common.commands.InsertTableCommand;
+import org.eclipse.papyrus.infra.nattable.common.utils.TableUtil;
+import org.eclipse.papyrus.infra.nattable.model.nattable.Table;
+
+
+/**
+ * Offer a strategy for copying tables.
+ */
+public class TablePasteStrategy extends AbstractPasteStrategy implements IPasteStrategy {
+
+ /** key to store tables with no owner */
+ protected static final String TABLE_WITH_NO_OWNER = "TABLE_WITH_NO_OWNER"; //$NON-NLS-1$
+
+ /** The instance. */
+ private static IPasteStrategy instance = new TablePasteStrategy();
+
+ /**
+ * Gets the single instance of TablePasteStrategy.
+ *
+ * @return single instance of TablePasteStrategy
+ */
+ public static IPasteStrategy getInstance() {
+ return instance;
+ }
+
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.IPasteStrategy#getLabel()
+ */
+ public String getLabel() {
+ return "Table Strategy"; //$NON-NLS-1$
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.IPasteStrategy#getID()
+ */
+ public String getID() {
+ return Activator.ID + ".TableStrategy"; //$NON-NLS-1$
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.IPasteStrategy#getDescription()
+ */
+ public String getDescription() {
+ return "Copy Table"; //$NON-NLS-1$
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.IPasteStrategy#getSemanticCommand(org.eclipse.emf.edit.domain.EditingDomain,
+ * org.eclipse.emf.ecore.EObject, org.eclipse.papyrus.infra.core.clipboard.PapyrusClipboard)
+ */
+ @Override
+ public org.eclipse.emf.common.command.Command getSemanticCommand(final EditingDomain domain, final EObject targetOwner, PapyrusClipboard<Object> papyrusClipboard) {
+ CompoundCommand compoundCommand = new CompoundCommand("Copy all tables"); //$NON-NLS-1$
+
+ Map internalClipboardToTargetCopy = papyrusClipboard.getInternalClipboardToTargetCopy();
+ Map<Object, ?> additionalDataMap = papyrusClipboard.getAdditionalDataForStrategy(getID());
+
+ if(additionalDataMap != null) {
+ Object additionalData = additionalDataMap.get(TABLE_WITH_NO_OWNER);
+ if(additionalData instanceof TableClipboardAdditionalData) {
+ TableClipboardAdditionalData tableAdditionalData = (TableClipboardAdditionalData)additionalData;
+ Collection<Table> duplicateTables = tableAdditionalData.getDuplicatedTables(internalClipboardToTargetCopy);
+ for(final Table table : duplicateTables) {
+ org.eclipse.emf.common.command.Command command = new InsertTableCommand((TransactionalEditingDomain)domain, "Insert a table whit no source owner", table, targetOwner); //$NON-NLS-1$
+ compoundCommand.append(command);
+ }
+ }
+
+ for(Iterator<Object> iterator = papyrusClipboard.iterator(); iterator.hasNext();) {
+ Object object = (Object)iterator.next();
+ // get target Element
+ EObject target = papyrusClipboard.getTragetCopyFromInternalClipboardCopy(object);
+ if(target != null && target instanceof EObject) {
+ // get affiliate additionalDataMap
+
+ additionalData = additionalDataMap.get(object);
+ if(additionalData instanceof TableClipboardAdditionalData) {
+ TableClipboardAdditionalData tableAdditionalData = (TableClipboardAdditionalData)additionalData;
+ Collection<Table> duplicateTables = tableAdditionalData.getDuplicatedTables(internalClipboardToTargetCopy);
+ for(final Table table : duplicateTables) {
+ org.eclipse.emf.common.command.Command command = new InsertTableCommand((TransactionalEditingDomain)domain, "InsertTableCommand", table, target); //$NON-NLS-1$
+ compoundCommand.append(command);
+ }
+ }
+ }
+ }
+ }
+
+ // An empty compound Command can't be executed
+ if(compoundCommand.getCommandList().isEmpty()) {
+ return null;
+ }
+ return compoundCommand;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.IPasteStrategy#dependsOn()
+ */
+ @Override
+ public IPasteStrategy dependsOn() {
+ return DefaultPasteStrategy.getInstance();
+ }
+
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.IPasteStrategy#prepare(org.eclipse.papyrus.infra.core.clipboard.PapyrusClipboard)
+ */
+ @Override
+ public void prepare(PapyrusClipboard<Object> papyrusClipboard, Collection<EObject> selection) {
+ Map sourceToInternalClipboard = papyrusClipboard.getSourceToInternalClipboard();
+ Map<Object, IClipboardAdditionalData> mapCopyToClipboardAdditionalData = new HashMap<Object, IClipboardAdditionalData>();
+
+ List<Table> extractSelectedWithoutOwner = extractTableWithoutOwner(selection);
+ if(extractSelectedWithoutOwner != null && !extractSelectedWithoutOwner.isEmpty()) {
+ TableClipboardAdditionalData diagramAdditionnalData = new TableClipboardAdditionalData(extractSelectedWithoutOwner, sourceToInternalClipboard);
+ mapCopyToClipboardAdditionalData.put(TABLE_WITH_NO_OWNER, diagramAdditionnalData);
+ }
+
+ for(Iterator<EObject> iterator = papyrusClipboard.iterateOnSource(); iterator.hasNext();) {
+ EObject eObjectSource = iterator.next();
+ ResourceSet resourceSet = eObjectSource.eResource().getResourceSet();
+ List<Table> associatedTables = TableUtil.getAssociatedTables(eObjectSource, resourceSet);
+ if(associatedTables != null) {
+ TableClipboardAdditionalData tabledAdditionalData = new TableClipboardAdditionalData(associatedTables, sourceToInternalClipboard);
+ Object copy = papyrusClipboard.getCopyFromSource(eObjectSource);
+ mapCopyToClipboardAdditionalData.put(copy, tabledAdditionalData);
+ }
+ }
+ papyrusClipboard.pushAdditionalData(getID(), mapCopyToClipboardAdditionalData);
+ }
+
+
+
+ /**
+ * Extract Table in which owner is not in the selection
+ *
+ * @param selection
+ * @return
+ */
+ protected List<Table> extractTableWithoutOwner(Collection<EObject> selection) {
+ List<Table> tableWithoutOwnerInSelection = new ArrayList<Table>();
+ if(selection != null) {
+ for(EObject eObject : selection) {
+ if(eObject instanceof Table) {
+ Table table = (Table)eObject;
+ EObject element = table.getOwner();
+ if(!selection.contains(element)) {
+ tableWithoutOwnerInSelection.add(table);
+ }
+ }
+ }
+ }
+ return tableWithoutOwnerInSelection;
+ }
+
+
+
+ protected class TableClipboardAdditionalData implements IClipboardAdditionalData {
+
+ /** The internal copies of tables */
+ protected Collection<Table> tables;
+
+ /**
+ * @param diagramCopier
+ * @param tables
+ */
+ public TableClipboardAdditionalData(Collection<Table> tables, Map<? extends EObject, ? extends EObject> alreadyCopied) {
+ this.tables = duplicateTables(tables, alreadyCopied);
+ }
+
+ /**
+ * @return
+ */
+ public Collection<Table> getDuplicatedTables(Map<? extends EObject, ? extends EObject> alreadyCopied) {
+ return duplicateTables(this.tables, alreadyCopied);
+ }
+
+ /**
+ * @param tables
+ * to duplicate
+ * @param alreadyCopied
+ * @return duplicated tables
+ */
+ protected Collection<Table> duplicateTables(Collection<Table> tables, Map<? extends EObject, ? extends EObject> alreadyCopied) {
+ Collection<Table> duplicatedTables = new ArrayList<Table>();
+ EcoreUtil.Copier copier = new EcoreUtil.Copier();
+ copier.putAll(alreadyCopied);
+ for(Table table : tables) {
+ copier.copy(table);
+ copier.copyReferences();
+ EObject copy = copier.get(table);
+ if(copy instanceof Table) {
+ duplicatedTables.add((Table)copy);
+ }
+ }
+ return duplicatedTables;
+ }
+
+
+ }
+
+}
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.common/src/org/eclipse/papyrus/infra/nattable/common/utils/TableUtil.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.common/src/org/eclipse/papyrus/infra/nattable/common/utils/TableUtil.java
new file mode 100644
index 0000000..e5f044a
--- /dev/null
+++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable.common/src/org/eclipse/papyrus/infra/nattable/common/utils/TableUtil.java
@@ -0,0 +1,74 @@
+/*****************************************************************************
+ * Copyright (c) 2014 CEA LIST.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Benoit Maggi (CEA LIST) benoit.maggi@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.nattable.common.utils;
+
+import java.util.Collections;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.papyrus.infra.core.resource.ModelSet;
+import org.eclipse.papyrus.infra.gmfdiag.common.model.NotationUtils;
+import org.eclipse.papyrus.infra.nattable.model.nattable.Table;
+
+
+public class TableUtil {
+
+ /**
+ * Gets the tables associated to element.
+ *
+ * @param element
+ * @param resourceSet
+ * can be null, it will then try to retrieve it from the element.
+ * @return the list of diagrams associated with the given element
+ */
+ public static List<Table> getAssociatedTables(EObject element, ResourceSet resourceSet) {
+ if(resourceSet == null) {
+ if(element != null && element.eResource() != null) {
+ resourceSet = element.eResource().getResourceSet();
+ }
+ }
+
+ if(resourceSet instanceof ModelSet) {
+ Resource notationResource = NotationUtils.getNotationResource((ModelSet)resourceSet);
+ return getAssociatedTablesFromNotationResource(element, notationResource);
+ }
+
+ return Collections.emptyList();
+ }
+
+ /**
+ * Gets the diagrams associated to element.
+ *
+ * @param element
+ * @param notationResource
+ * the notation resource where to look for diagrams
+ * @return the list of diagrams associated with the given element
+ */
+ public static List<Table> getAssociatedTablesFromNotationResource(EObject element, Resource notationResource) {
+ if(notationResource != null) {
+ LinkedList<Table> tables = new LinkedList<Table>();
+ for(EObject eObj : notationResource.getContents()) {
+ if(eObj instanceof Table) {
+ Table table = (Table)eObj;
+ if(element.equals(table.getOwner())) {
+ tables.add(table);
+ }
+ }
+ }
+ return tables;
+ }
+ return Collections.emptyList();
+ }
+}
diff --git a/tests/junit/plugins/uml/modelexplorer/org.eclipse.papyrus.uml.modelexplorer.tests/src/org/eclipse/papyrus/uml/modelexplorer/tests/paste/TableCopyPasteModelExplorerTest.java b/tests/junit/plugins/uml/modelexplorer/org.eclipse.papyrus.uml.modelexplorer.tests/src/org/eclipse/papyrus/uml/modelexplorer/tests/paste/TableCopyPasteModelExplorerTest.java
index 8c30def..e26eefc 100644
--- a/tests/junit/plugins/uml/modelexplorer/org.eclipse.papyrus.uml.modelexplorer.tests/src/org/eclipse/papyrus/uml/modelexplorer/tests/paste/TableCopyPasteModelExplorerTest.java
+++ b/tests/junit/plugins/uml/modelexplorer/org.eclipse.papyrus.uml.modelexplorer.tests/src/org/eclipse/papyrus/uml/modelexplorer/tests/paste/TableCopyPasteModelExplorerTest.java
@@ -74,7 +74,6 @@ public class TableCopyPasteModelExplorerTest extends AbstractEditorTest {
* here the purpose is to test the creation of constraint on variable elements.
*/
@Test
- @Ignore // TODO to activate with implementation of table strategy
public void copyPasteTableTest() throws Exception {
//get the rootModel