ANIMATOR : ADD copy,cut and paste in timeline 54/20654/1
authorjinwooim.bae <jinwooim.bae@samsung.com>
Sun, 11 May 2014 10:30:43 +0000 (19:30 +0900)
committerjinwooim.bae <jinwooim.bae@samsung.com>
Sun, 11 May 2014 10:30:43 +0000 (19:30 +0900)
This is copy, cut and paste fuction in timeline.

Change-Id: I456c525afdb615b432f5d65f8a9a2d58feae5ec3
Signed-off-by: jinwooim.bae <jinwooim.bae@samsung.com>
org.tizen.webuibuilder/src/org/tizen/webuibuilder/animator/ui/views/timeline/TimelineClipboard.java [new file with mode: 0644]
org.tizen.webuibuilder/src/org/tizen/webuibuilder/animator/ui/views/timeline/TimelinePage.java
org.tizen.webuibuilder/src/org/tizen/webuibuilder/animator/ui/views/timeline/action/AddKeyFrameAction.java
org.tizen.webuibuilder/src/org/tizen/webuibuilder/animator/ui/views/timeline/action/AddPredefinedKeyFrameAction.java
org.tizen.webuibuilder/src/org/tizen/webuibuilder/animator/ui/views/timeline/action/CopyKeyFrameAction.java
org.tizen.webuibuilder/src/org/tizen/webuibuilder/animator/ui/views/timeline/action/CutKeyFrameAction.java
org.tizen.webuibuilder/src/org/tizen/webuibuilder/animator/ui/views/timeline/action/DeleteKeyFrameAction.java
org.tizen.webuibuilder/src/org/tizen/webuibuilder/animator/ui/views/timeline/action/PasteKeyFrameAction.java

diff --git a/org.tizen.webuibuilder/src/org/tizen/webuibuilder/animator/ui/views/timeline/TimelineClipboard.java b/org.tizen.webuibuilder/src/org/tizen/webuibuilder/animator/ui/views/timeline/TimelineClipboard.java
new file mode 100644 (file)
index 0000000..c813b1f
--- /dev/null
@@ -0,0 +1,70 @@
+\r
+\r
+package org.tizen.webuibuilder.animator.ui.views.timeline;\r
+\r
+import org.eclipse.gef.dnd.SimpleObjectTransfer;\r
+import org.eclipse.swt.dnd.Clipboard;\r
+import org.eclipse.swt.dnd.Transfer;\r
+import org.eclipse.swt.widgets.Display;\r
+\r
+\r
+/**\r
+ * This class is Clipboard in Timeline.\r
+ */\r
+public class TimelineClipboard {\r
+\r
+    private Clipboard clipboard = null;\r
+    private static final SimpleObjectTransfer timelineTransper = new SimpleObjectTransfer() {\r
+        private final String TYPE_NAME =\r
+                "org.tizen.webuibuilder.animator.ui.views.timeline.clipboard.transfer"; //$NON-NLS-1$\r
+        private final int TYPE_ID = registerType(TYPE_NAME);\r
+\r
+        protected int[] getTypeIds() {\r
+            return new int[] { TYPE_ID };\r
+        }\r
+\r
+        protected String[] getTypeNames() {\r
+            return new String[] { TYPE_NAME };\r
+        }\r
+    };\r
+\r
+    /**\r
+     * Construct\r
+     * \r
+     * @param display\r
+     *            {@link Display}\r
+     */\r
+    public TimelineClipboard(Display display) {\r
+        clipboard = new Clipboard(display);\r
+    }\r
+\r
+    /**\r
+     * Get Clipboard\r
+     */\r
+    public Clipboard getClipboard() {\r
+        return clipboard;\r
+    }\r
+\r
+    /**\r
+     * Get Object\r
+     */\r
+    public Object getContents() {\r
+        org.eclipse.swt.dnd.Clipboard cb = new org.eclipse.swt.dnd.Clipboard(null);\r
+        Object contents = cb.getContents(timelineTransper);\r
+        cb.dispose();\r
+        return contents;\r
+    }\r
+\r
+    /**\r
+     * Set Contents\r
+     * \r
+     * @param contents\r
+     *            {@link Object}\r
+     */\r
+    public void setContents(Object contents) {\r
+        org.eclipse.swt.dnd.Clipboard cb = new org.eclipse.swt.dnd.Clipboard(null);\r
+        cb.setContents(new Object[] { contents }, new Transfer[] { timelineTransper });\r
+        cb.dispose();\r
+    }\r
+\r
+}\r
index 9c8c705..30f07fc 100644 (file)
@@ -31,6 +31,7 @@ import org.eclipse.gef.ui.parts.ContentOutlinePage;
 import org.eclipse.gef.ui.parts.SelectionSynchronizer;
 import org.eclipse.jface.action.IAction;
 import org.eclipse.swt.SWT;
+import org.eclipse.swt.dnd.Clipboard;
 import org.eclipse.swt.layout.FormAttachment;
 import org.eclipse.swt.layout.FormData;
 import org.eclipse.swt.layout.FormLayout;
@@ -80,6 +81,8 @@ public class TimelinePage extends ContentOutlinePage {
     private ActionRegistry actionRegistry = null;
     private ActionRegistry timelineActionRegistry = null;
 
+    private TimelineClipboard clipboard = null;
+
     /**
      * Construct
      * 
@@ -118,6 +121,8 @@ public class TimelinePage extends ContentOutlinePage {
     public void init(IPageSite pageSite) {
         super.init(pageSite);
 
+        clipboard = new TimelineClipboard(pageSite.getShell().getDisplay());
+
         String id = ActionFactory.UNDO.getId();
         timelineActionRegistry.registerAction(getActionRegistry().getAction(id));
 
@@ -235,10 +240,10 @@ public class TimelinePage extends ContentOutlinePage {
      */
     public void initPage() {
         AppManager appManager = (AppManager) AnimatorUtils.getAppManager();
-        if(appManager != null) {
+        if (appManager != null) {
             AnimatorModelManager modelManager = appManager.getAnimatorModelManager();
-            if(modelManager != null) {
-                pagePart  = (AnimatorPagePart) modelManager.getPagePart();
+            if (modelManager != null) {
+                pagePart = (AnimatorPagePart) modelManager.getPagePart();
             }
         }
         refreshPage(pagePart);
@@ -445,8 +450,21 @@ public class TimelinePage extends ContentOutlinePage {
         this.actionRegistry = actionRegistry;
     }
 
+    /**
+     * Get TimelineActionRegistry
+     * 
+     * @return
+     */
     public ActionRegistry getTimelineActionRegistry() {
         return timelineActionRegistry;
     }
 
+    /**
+     * Get Clipboard
+     * 
+     * @return
+     */
+    public TimelineClipboard getClipboard() {
+        return clipboard;
+    }
 }
index 6f73e77..c1ae374 100644 (file)
@@ -18,10 +18,21 @@ import org.tizen.webuibuilder.animator.ui.views.timeline.tree.TimelineOutlineEle
 import org.tizen.webuibuilder.animator.utils.AnimatorUtils;\r
 \r
 \r
+/**\r
+ * This class is Action for adding KeyFrame.\r
+ */\r
 public class AddKeyFrameAction extends SelectionAction {\r
 \r
     EditPartViewer editPartViewer = null;\r
 \r
+    /**\r
+     * Construct\r
+     * \r
+     * @param text\r
+     *            {@link String}\r
+     * @param editPartViewer\r
+     *            {@link EditPartViewer}\r
+     */\r
     public AddKeyFrameAction(String text, EditPartViewer editPartViewer) {\r
         super(null);\r
 \r
@@ -32,6 +43,11 @@ public class AddKeyFrameAction extends SelectionAction {
         this.editPartViewer = editPartViewer;\r
     }\r
 \r
+    /*\r
+     * (non-Javadoc)\r
+     * \r
+     * @see org.eclipse.gef.ui.actions.WorkbenchPartAction#calculateEnabled()\r
+     */\r
     @Override\r
     protected boolean calculateEnabled() {\r
         if (editPartViewer == null) {\r
@@ -40,6 +56,11 @@ public class AddKeyFrameAction extends SelectionAction {
         return true;\r
     }\r
 \r
+    /*\r
+     * (non-Javadoc)\r
+     * \r
+     * @see org.eclipse.jface.action.Action#run()\r
+     */\r
     @Override\r
     public void run() {\r
         TimelineViewer viewer = (TimelineViewer) editPartViewer;\r
index 6489e9a..3b28c71 100644 (file)
@@ -25,11 +25,25 @@ import org.tizen.webuibuilder.model.app.AppManager;
 import org.tizen.webuibuilder.utility.ResourceManager;\r
 \r
 \r
+/**\r
+ * This class is Action for adding predefined keyframe.\r
+ * \r
+ * @author jinwoo\r
+ * \r
+ */\r
 public class AddPredefinedKeyFrameAction extends SelectionAction {\r
 \r
     private EditPartViewer editPartViewer = null;\r
     private CssAnimationDescriptor cssAnimation = null;\r
 \r
+    /**\r
+     * Construct\r
+     * \r
+     * @param cssAnimation\r
+     *            {@link CssAnimationDescriptor}\r
+     * @param editPartViewer\r
+     *            {@link EditPartViewer}\r
+     */\r
     public AddPredefinedKeyFrameAction(final CssAnimationDescriptor cssAnimation,\r
             EditPartViewer editPartViewer) {\r
         super(null);\r
@@ -53,10 +67,18 @@ public class AddPredefinedKeyFrameAction extends SelectionAction {
 \r
     }\r
 \r
+    /**\r
+     * Set DisplayName\r
+     */\r
     private void setDisplayName(String text) {\r
         setText(text);\r
     }\r
 \r
+    /*\r
+     * (non-Javadoc)\r
+     * \r
+     * @see org.eclipse.gef.ui.actions.WorkbenchPartAction#calculateEnabled()\r
+     */\r
     @Override\r
     protected boolean calculateEnabled() {\r
         if (editPartViewer == null) {\r
@@ -65,6 +87,11 @@ public class AddPredefinedKeyFrameAction extends SelectionAction {
         return true;\r
     }\r
 \r
+    /*\r
+     * (non-Javadoc)\r
+     * \r
+     * @see org.eclipse.jface.action.Action#run()\r
+     */\r
     @Override\r
     public void run() {\r
         TimelineViewer viewer = (TimelineViewer) editPartViewer;\r
@@ -78,15 +105,13 @@ public class AddPredefinedKeyFrameAction extends SelectionAction {
         Part partModel = model.getPartLink();\r
 \r
         String animationGroupId =\r
-                viewer.getMainContainer().getContentContainer().getContentHeaderContainer()\r
-                        .getOutlineHeader().getSelectedAnimationGroupId();\r
-        double pointTime =\r
-                viewer.getMainContainer().getContentContainer().getContentHeaderContainer()\r
-                        .getKeyframeHeader().getTimeBar().getPlayHeader().getCurrentPointTime();\r
+                AnimatorUtils.getActiveAnimatorBrowserViewer().getCurrentAnimationGroupId();\r
+        double pointTime = AnimatorUtils.getActiveAnimatorBrowserViewer().getPointTime();\r
+\r
         AppManager appManager = AnimatorUtils.getAppManager();\r
         Command command =\r
                 new AnimationCreateCommand(animationGroupId, cssAnimation, appManager,\r
-                                           AnimatorModelEvent.Origin.EDITOR, partModel,\r
+                                           AnimatorModelEvent.Origin.TIMELINE, partModel,\r
                                            partModel.getUiSelector(), pointTime);\r
 \r
         viewer.getEditDomain().getCommandStack().execute(command);\r
index a940bef..ce6af4e 100644 (file)
@@ -2,18 +2,34 @@
 \r
 package org.tizen.webuibuilder.animator.ui.views.timeline.action;\r
 \r
+import java.util.ArrayList;\r
 import java.util.List;\r
 \r
 import org.eclipse.gef.EditPartViewer;\r
 import org.eclipse.gef.ui.actions.SelectionAction;\r
 import org.eclipse.ui.ISharedImages;\r
 import org.eclipse.ui.PlatformUI;\r
+import org.tizen.webuibuilder.animator.model.AnimatorModel;\r
+import org.tizen.webuibuilder.animator.ui.views.timeline.TimelineClipboard;\r
+import org.tizen.webuibuilder.animator.ui.views.timeline.TimelinePage;\r
+import org.tizen.webuibuilder.animator.ui.views.timeline.TimelineViewer;\r
 \r
 \r
+/**\r
+ * This class is Action for coping KeyFrame.\r
+ */\r
 public class CopyKeyFrameAction extends SelectionAction {\r
 \r
     private EditPartViewer editPartViewer = null;\r
 \r
+    /**\r
+     * Construct\r
+     * \r
+     * @param text\r
+     *            {@link String}\r
+     * @param editPartViewer\r
+     *            {@link EditPartViewer}\r
+     */\r
     public CopyKeyFrameAction(String text, EditPartViewer editPartViewer) {\r
         super(null);\r
         setId(text);\r
@@ -24,24 +40,48 @@ public class CopyKeyFrameAction extends SelectionAction {
         this.editPartViewer = editPartViewer;\r
     }\r
 \r
+    /*\r
+     * (non-Javadoc)\r
+     * \r
+     * @see org.eclipse.gef.ui.actions.WorkbenchPartAction#calculateEnabled()\r
+     */\r
     @Override\r
     protected boolean calculateEnabled() {\r
         if (editPartViewer == null) {\r
             return false;\r
         }\r
-\r
         List<Object> selectedList = getSelectedObjects();\r
         int size = selectedList.size();\r
-        if (size > 0) {\r
-            return true;\r
+        if (size <= 0) {\r
+            return false;\r
+        }\r
+        TimelinePage page = ((TimelineViewer) editPartViewer).getPage();\r
+        TimelineClipboard clipboard = page.getClipboard();\r
+        if (clipboard == null) {\r
+            return false;\r
         }\r
 \r
-        return false;\r
+        return true;\r
     }\r
 \r
+    /*\r
+     * (non-Javadoc)\r
+     * \r
+     * @see org.eclipse.jface.action.Action#run()\r
+     */\r
     @Override\r
     public void run() {\r
 \r
+        List<Object> selectedList = getSelectedObjects();\r
+\r
+        // Animator model clone\r
+        List<AnimatorModel> cloneModels = new ArrayList<AnimatorModel>();\r
+\r
+        //\r
+        TimelinePage page = ((TimelineViewer) editPartViewer).getPage();\r
+        TimelineClipboard clipboard = page.getClipboard();\r
+        clipboard.setContents(cloneModels);\r
+\r
     }\r
 \r
 }\r
index c313274..b813dd7 100644 (file)
@@ -2,18 +2,34 @@
 \r
 package org.tizen.webuibuilder.animator.ui.views.timeline.action;\r
 \r
+import java.util.ArrayList;\r
 import java.util.List;\r
 \r
 import org.eclipse.gef.EditPartViewer;\r
 import org.eclipse.gef.ui.actions.SelectionAction;\r
 import org.eclipse.ui.ISharedImages;\r
 import org.eclipse.ui.PlatformUI;\r
+import org.tizen.webuibuilder.animator.model.AnimatorModel;\r
+import org.tizen.webuibuilder.animator.ui.views.timeline.TimelineClipboard;\r
+import org.tizen.webuibuilder.animator.ui.views.timeline.TimelinePage;\r
+import org.tizen.webuibuilder.animator.ui.views.timeline.TimelineViewer;\r
 \r
 \r
+/**\r
+ * This class is Action for cutting KeyFrame.\r
+ */\r
 public class CutKeyFrameAction extends SelectionAction {\r
 \r
     EditPartViewer editPartViewer = null;\r
 \r
+    /**\r
+     * Construct\r
+     * \r
+     * @param text\r
+     *            {@link String}\r
+     * @param editPartViewer\r
+     *            {@link EditPartViewer}\r
+     */\r
     public CutKeyFrameAction(String text, EditPartViewer editPartViewer) {\r
         super(null);\r
         setId(text);\r
@@ -25,24 +41,50 @@ public class CutKeyFrameAction extends SelectionAction {
         this.editPartViewer = editPartViewer;\r
     }\r
 \r
+    /*\r
+     * (non-Javadoc)\r
+     * \r
+     * @see org.eclipse.gef.ui.actions.WorkbenchPartAction#calculateEnabled()\r
+     */\r
     @Override\r
     protected boolean calculateEnabled() {\r
         if (editPartViewer == null) {\r
             return false;\r
         }\r
-\r
         List<Object> selectedList = getSelectedObjects();\r
         int size = selectedList.size();\r
-        if (size > 0) {\r
-            return true;\r
+        if (size <= 0) {\r
+            return false;\r
+        }\r
+        TimelinePage page = ((TimelineViewer) editPartViewer).getPage();\r
+        TimelineClipboard clipboard = page.getClipboard();\r
+        if (clipboard == null) {\r
+            return false;\r
         }\r
 \r
-        return false;\r
+        return true;\r
     }\r
 \r
+    /*\r
+     * (non-Javadoc)\r
+     * \r
+     * @see org.eclipse.jface.action.Action#run()\r
+     */\r
     @Override\r
     public void run() {\r
 \r
+        List<Object> selectedList = getSelectedObjects();\r
+\r
+        // Animator model clone\r
+        List<AnimatorModel> cloneModels = new ArrayList<AnimatorModel>();\r
+\r
+        // delete realModels\r
+\r
+        TimelinePage page = ((TimelineViewer) editPartViewer).getPage();\r
+        TimelineClipboard clipboard = page.getClipboard();\r
+\r
+        clipboard.setContents(cloneModels);\r
+\r
     }\r
 \r
 }\r
index 4150094..ab26ef2 100644 (file)
@@ -20,10 +20,21 @@ import org.tizen.webuibuilder.animator.ui.views.timeline.widget.KeyFrameComponen
 import org.tizen.webuibuilder.animator.ui.views.timeline.widget.KeyFrameUnit;\r
 \r
 \r
+/**\r
+ * This class is Action for deleting KeyFrame.\r
+ */\r
 public class DeleteKeyFrameAction extends SelectionAction {\r
 \r
     private EditPartViewer editPartViewer = null;\r
 \r
+    /**\r
+     * Construct\r
+     * \r
+     * @param text\r
+     *            {@link String}\r
+     * @param editPartViewer\r
+     *            {@link EditPartViewer}\r
+     */\r
     public DeleteKeyFrameAction(String text, EditPartViewer editPartViewer) {\r
         super(null);\r
         setId(text);\r
@@ -34,6 +45,11 @@ public class DeleteKeyFrameAction extends SelectionAction {
         this.editPartViewer = editPartViewer;\r
     }\r
 \r
+    /*\r
+     * (non-Javadoc)\r
+     * \r
+     * @see org.eclipse.gef.ui.actions.WorkbenchPartAction#calculateEnabled()\r
+     */\r
     @Override\r
     protected boolean calculateEnabled() {\r
         if (editPartViewer == null) {\r
@@ -49,6 +65,11 @@ public class DeleteKeyFrameAction extends SelectionAction {
         return false;\r
     }\r
 \r
+    /*\r
+     * (non-Javadoc)\r
+     * \r
+     * @see org.eclipse.jface.action.Action#run()\r
+     */\r
     @Override\r
     public void run() {\r
         List<Object> selectedList = getSelectedObjects();\r
index 39aa2f7..e125640 100644 (file)
@@ -2,16 +2,37 @@
 \r
 package org.tizen.webuibuilder.animator.ui.views.timeline.action;\r
 \r
+import java.util.ArrayList;\r
+import java.util.List;\r
+\r
 import org.eclipse.gef.EditPartViewer;\r
 import org.eclipse.gef.ui.actions.SelectionAction;\r
+import org.eclipse.swt.custom.TreeEditor;\r
+import org.eclipse.swt.widgets.TreeItem;\r
 import org.eclipse.ui.ISharedImages;\r
 import org.eclipse.ui.PlatformUI;\r
+import org.tizen.webuibuilder.animator.model.AnimatorModel;\r
+import org.tizen.webuibuilder.animator.ui.views.timeline.TimelineClipboard;\r
+import org.tizen.webuibuilder.animator.ui.views.timeline.TimelinePage;\r
+import org.tizen.webuibuilder.animator.ui.views.timeline.TimelineViewer;\r
+import org.tizen.webuibuilder.animator.ui.views.timeline.tree.TimelineOutlineElement;\r
 \r
 \r
+/**\r
+ * This class is Action for pasting KeyFrame.\r
+ */\r
 public class PasteKeyFrameAction extends SelectionAction {\r
 \r
     private EditPartViewer editPartViewer = null;\r
 \r
+    /**\r
+     * Construct\r
+     * \r
+     * @param text\r
+     *            {@link String}\r
+     * @param editPartViewer\r
+     *            {@link EditPartViewer}\r
+     */\r
     public PasteKeyFrameAction(String text, EditPartViewer editPartViewer) {\r
         super(null);\r
         setId(text);\r
@@ -23,23 +44,92 @@ public class PasteKeyFrameAction extends SelectionAction {
         this.editPartViewer = editPartViewer;\r
     }\r
 \r
+    /*\r
+     * (non-Javadoc)\r
+     * \r
+     * @see org.eclipse.gef.ui.actions.WorkbenchPartAction#calculateEnabled()\r
+     */\r
     @Override\r
     protected boolean calculateEnabled() {\r
         if (editPartViewer == null) {\r
             return false;\r
         }\r
 \r
-        /*\r
-         * List<Object> selectedList = getSelectedObjects(); int size = selectedList.size(); if\r
-         * (size > 0) { return true; }\r
-         */\r
+        if (((TimelineViewer) editPartViewer).getLastSelectedTreeItem() == null) {\r
+            return false;\r
+        }\r
+\r
+        TimelinePage page = ((TimelineViewer) editPartViewer).getPage();\r
+        TimelineClipboard clipboard = page.getClipboard();\r
+        if (clipboard == null) {\r
+            return false;\r
+        }\r
+        Object contents = clipboard.getContents();\r
+        if (contents == null) {\r
+            return false;\r
+        }\r
+\r
+        List<AnimatorModel> parts = null;\r
+        if (!(contents instanceof List<?>)) {\r
+            return false;\r
+        } else {\r
+            parts = (List<AnimatorModel>) contents;\r
+        }\r
+\r
+        if (parts == null || parts.size() == 0) {\r
+            return false;\r
+        }\r
+\r
+        return true;\r
 \r
-        return false;\r
     }\r
 \r
+    /*\r
+     * (non-Javadoc)\r
+     * \r
+     * @see org.eclipse.jface.action.Action#run()\r
+     */\r
     @Override\r
     public void run() {\r
+        TimelineViewer viewer = (TimelineViewer) editPartViewer;\r
+        TimelinePage page = viewer.getPage();\r
+        TimelineClipboard clipboard = page.getClipboard();\r
+        Object contents = clipboard.getContents();\r
 \r
-    }\r
+        // clone models for paste\r
+        List<AnimatorModel> cloneModels = (List<AnimatorModel>) contents;\r
+\r
+        TreeItem treeItem = viewer.getLastSelectedTreeItem();\r
+        TreeEditor outlineEditor = (TreeEditor) treeItem.getData("OutlineTreeEditor");\r
+        TimelineOutlineElement outlineElement = (TimelineOutlineElement) outlineEditor.getEditor();\r
+\r
+        TreeItem parentItem = treeItem.getParentItem();\r
+\r
+        List<AnimatorModel> children = null; // selectors\r
+        if (parentItem == null) {\r
+            children = ((AnimatorModel) outlineElement.getModel()).getChildren();\r
+        } else {\r
+            children = new ArrayList<AnimatorModel>();\r
+            children.add((AnimatorModel) outlineElement.getModel());\r
+        }\r
 \r
+        // Add KeyFrame or KeyFrame\r
+        // Predefined animation\r
+        // keyframe\r
+        // frame\r
+        /*\r
+         * Command command = new TimelineFrameCreateCommand(children, AnimatorUtils\r
+         * .getActiveAnimatorBrowserViewer().getPointTime());\r
+         * editPartViewer.getEditDomain().getCommandStack().execute(command);\r
+         */\r
+\r
+        /*\r
+         * viewer.getControl().getDisplay().syncExec(new Runnable() {\r
+         * \r
+         * @Override public void run() {\r
+         * viewer.setLastSelectedKeyframeComponent(lastSelectedKeyframeComponent);\r
+         * viewer.setLastSelectedTreeItem(lastSelectedTreeItem); } }); }\r
+         */\r
+\r
+    }\r
 }\r