summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenoit Maggi2014-02-28 05:08:35 (EST)
committerVincent Lorenzo2014-03-18 09:58:39 (EDT)
commit38987f2559764e1f12b9c9edc60213665502c78a (patch)
treec85390fa86b326e1ebfebfd4d667a8ad6f1d7ead
parente8cdcec7b368b739a9e645af8f07509a65e55e01 (diff)
downloadorg.eclipse.papyrus-38987f2559764e1f12b9c9edc60213665502c78a.zip
org.eclipse.papyrus-38987f2559764e1f12b9c9edc60213665502c78a.tar.gz
org.eclipse.papyrus-38987f2559764e1f12b9c9edc60213665502c78a.tar.bz2
[Usability] Papyrus shall provide a copy/paste/cut feature :
- PapyrusClipboard: a clipboard that keeps mapping between source copy and target - IClipboardAdditionalData: Interface to be used to add any data needed by pasting strategies Signed-off-by: Benoit Maggi <benoit.maggi@cea.fr> Conflicts: plugins/infra/core/org.eclipse.papyrus.infra.core/META-INF/MANIFEST.MF
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core/META-INF/MANIFEST.MF1
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/clipboard/IClipboardAdditionalData.java22
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/clipboard/PapyrusClipboard.java158
3 files changed, 181 insertions, 0 deletions
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/META-INF/MANIFEST.MF b/plugins/infra/core/org.eclipse.papyrus.infra.core/META-INF/MANIFEST.MF
index 5593b50..72fe68e 100644
--- a/plugins/infra/core/org.eclipse.papyrus.infra.core/META-INF/MANIFEST.MF
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/META-INF/MANIFEST.MF
@@ -1,5 +1,6 @@
Manifest-Version: 1.0
Export-Package: org.eclipse.papyrus.infra.core,
+ org.eclipse.papyrus.infra.core.clipboard,
org.eclipse.papyrus.infra.core.contentoutline,
org.eclipse.papyrus.infra.core.editor,
org.eclipse.papyrus.infra.core.editorsfactory,
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/clipboard/IClipboardAdditionalData.java b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/clipboard/IClipboardAdditionalData.java
new file mode 100644
index 0000000..39462e3
--- /dev/null
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/clipboard/IClipboardAdditionalData.java
@@ -0,0 +1,22 @@
+/*****************************************************************************
+ * 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 benoit.maggi@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.core.clipboard;
+
+/**
+ * The Interface IClipboardAdditionalData.
+ * Only class implemented this interface can be added to the PapyrusClipboard
+ */
+public interface IClipboardAdditionalData {
+
+}
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/clipboard/PapyrusClipboard.java b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/clipboard/PapyrusClipboard.java
new file mode 100644
index 0000000..bb13df5
--- /dev/null
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/clipboard/PapyrusClipboard.java
@@ -0,0 +1,158 @@
+/*****************************************************************************
+ * 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 benoit.maggi@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.core.clipboard;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.eclipse.emf.ecore.EObject;
+/**
+ * Clipboard for Papyrus Copy : cross Editor and cross model
+ * @param <E>
+ */
+public class PapyrusClipboard<E> extends ArrayList<E> {
+
+ private static final long serialVersionUID = -6902170636133989420L;
+
+ /**
+ * Current papyrus clipboard instance
+ */
+ public static PapyrusClipboard<Object> instance = null;
+
+ public static PapyrusClipboard<Object> getInstance() {
+ if (instance == null) {
+ instance = new PapyrusClipboard<Object>();
+ }
+ return instance;
+ }
+
+ /**
+ * Init a new instance for a new copy selection
+ * @return
+ */
+ public static PapyrusClipboard<Object> getNewInstance() {
+ instance = new PapyrusClipboard<Object>();
+ return instance;
+ }
+
+ /**
+ * Clean the clipboard (target data) before pasting
+ */
+ public static void resetTarget() {
+ // TODO : clean all target data
+ }
+
+ /**
+ * Keeps the mapping between the source and the temporary copy in clipboard
+ * (Can be use for a reference copy strategy)
+ */
+ private Map<EObject, Object> sourceToInternalClipboard = new HashMap<EObject, Object>();
+
+
+ /**
+ * Keeps the mapping between the internal clipboard copy and the target copy
+ * (Used by paste strategies)
+ */
+ private Map<Object, EObject> internalClipboardToTargetCopy = new HashMap<Object, EObject>();
+
+ /**
+ * Store all additional data needed for paste stregies application
+ * key: Strategy id ; Map<E,ClipboardAdditionalData> data for each object
+ */
+ private Map<String,Map<E,IClipboardAdditionalData>> strategiesAdditionalData = new HashMap<String,Map<E,IClipboardAdditionalData>>();
+
+ /**
+ * Store internal copy in clipboard while keeping mapping
+ * @param source the copied selection
+ * @param copy the temporary copy stored in clipboard
+ */
+ public void addInternalCopyInClipboard(EObject source, Object copy) {
+ getInstance().add(copy);
+ sourceToInternalClipboard.put(source, copy);
+ }
+
+ /**
+ * Store internal copy in clipboard while keeping mapping
+ * @param source the copied selection
+ * @param copy the temporary copy stored in clipboard
+ */
+ public void addAllInternalToTargetCopy(Map<Object, EObject> mapInternalClipboardToTargetCopy) {
+ internalClipboardToTargetCopy.putAll(mapInternalClipboardToTargetCopy);
+ }
+
+ /**
+ * Add target for internal copy
+ * @param copy
+ * @param target
+ */
+ public void addTargetForInternalCopy(Object copy, EObject target) {
+ internalClipboardToTargetCopy.put(copy, target);
+ }
+
+ /**
+ * Iterate on the copy selection
+ * (Use by paste strategy to prepare IAdditionalData)
+ * @return
+ */
+ public Iterator<EObject> iterateOnSource() {
+ return sourceToInternalClipboard.keySet().iterator();
+ }
+
+ /**
+ * Get the internal clipboard copy from the source selection
+ * (Use by paste strategy to prepare IAdditionalData)
+ * @return the internal clipboard copy
+ */
+ public Object getCopyFromSource(EObject eObject){
+ return sourceToInternalClipboard.get(eObject);
+ }
+
+ /**
+ * Get Additional data for all strategies
+ * @return
+ */
+ public Map<String, Map<E, IClipboardAdditionalData>> getStrategiesAdditionalData() {
+ return strategiesAdditionalData;
+ }
+
+ /**
+ * push data for a specific strategy
+ * @param key of the strategy
+ * @param strategyAdditionalData
+ */
+ public void pushAdditionalData(String key, Map<E,IClipboardAdditionalData> strategyAdditionalData) {
+ getStrategiesAdditionalData().put(key, strategyAdditionalData);
+ }
+
+ /**
+ * Get Additional Data for a strategy
+ * @param key of the strategy
+ * @return
+ */
+ public Map<E,IClipboardAdditionalData> getAdditionalDataForStrategy(String key) {
+ return getStrategiesAdditionalData().get(key);
+ }
+
+ /**
+ * Get the target copy from the internal clipboard copy
+ * @param object
+ * @return
+ */
+ public EObject getTragetCopyFromInternalClipboardCopy(Object object) {
+ return internalClipboardToTargetCopy.get(object);
+ }
+
+}