KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > clif > scenario > util > isac > gui > action > CopyAction


1 /*
2  * CLIF is a Load Injection Framework
3  * Copyright (C) 2004 France Telecom R&D
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * CLIF
20  *
21  * Contact: clif@objectweb.org
22  */

23 package org.objectweb.clif.scenario.util.isac.gui.action;
24
25 import java.net.URL JavaDoc;
26
27 import org.apache.log4j.Category;
28 import org.eclipse.jface.action.Action;
29 import org.eclipse.jface.resource.ImageDescriptor;
30 import org.eclipse.jface.window.ApplicationWindow;
31 import org.eclipse.swt.dnd.Clipboard;
32 import org.eclipse.swt.dnd.Transfer;
33 import org.objectweb.clif.scenario.util.isac.FileName;
34 import org.objectweb.clif.scenario.util.isac.gui.ScenarioGUIEditor;
35 import org.objectweb.clif.scenario.util.isac.gui.tree.ScenarioTreeViewer;
36 import org.objectweb.clif.scenario.util.isac.gui.tree.dnd.ScenarioTreeTransfer;
37 import org.objectweb.clif.scenario.util.isac.util.tree.ScenarioNode;
38 import org.objectweb.clif.scenario.util.isac.util.tree.TreeManager;
39 /**
40  * Action which copy a behaviors tree node
41  *
42  * @author JC Meillaud
43  * @author A Peyrard
44  */

45 public class CopyAction extends Action {
46     /**
47      * The application window, which launch this action
48      */

49     ScenarioGUIEditor window;
50     ScenarioTreeViewer viewer;
51     static Category cat = Category.getInstance(CopyAction.class.getName());
52     /**
53      * Build a new copy node action
54      *
55      * @param w
56      * The application window, in wich we will use this action
57      */

58     public CopyAction(ApplicationWindow w) {
59         cat.debug("-> constructor");
60         this.window = (ScenarioGUIEditor) w;
61         this.setText("Copy@Ctrl+C");
62         this.setToolTipText("Copy the selected node or selected text");
63         try {
64             this.setImageDescriptor(ImageDescriptor.createFromURL(new URL JavaDoc(
65                     "file:" + FileName.COPY_ICON)));
66         } catch (Exception JavaDoc e) {
67             cat.warn("Unable to find copy icon file");
68         }
69     }
70
71     public void run() {
72         cat.debug("-> run");
73
74         switch (this.window.getEditorShowed()) {
75             case ScenarioGUIEditor.GUI_EDITOR :
76                 this.viewer = this.window.getTreeViewer();
77                 Clipboard clipboard = this.viewer.getClipboard();
78                 // get the previous value
79
ScenarioNode oldClipboard = (ScenarioNode) clipboard
80                         .getContents(ScenarioTreeTransfer.getInstance());
81                 if (oldClipboard != null) {
82                     // delete the previous value
83
TreeManager.getTreeManager(null).deleteBehaviorsTreeNode(
84                             oldClipboard);
85                 }
86                 ScenarioNode node = this.viewer.getSelectedNode();
87                 if (node == null)
88                     return;
89                 cat.warn("SET THE CLIPBOARD : " + node);
90                 // Create a copy of the node copied
91
ScenarioNode copy = TreeManager.getTreeManager(null)
92                         .copyScenarioNode(node);
93                 clipboard.setContents(new Object JavaDoc[]{copy},
94                         new Transfer[]{ScenarioTreeTransfer.getInstance()});
95                 // enable paste action
96
this.window.getPasteNodeAction().setEnabled(true) ;
97                 break;
98             case ScenarioGUIEditor.XML_EDITOR :
99                 cat.warn("XML EDITOR COPY") ;
100                 this.window.getStyledText().copy();
101                 break;
102             default :
103         // there is none other choice
104
}
105     }
106 }
Popular Tags