KickJava   Java API By Example, From Geeks To Geeks.

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


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 cut a behaviors tree node
41  *
42  * @author JC Meillaud
43  * @author A Peyrard
44  */

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

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

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