KickJava   Java API By Example, From Geeks To Geeks.

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


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.objectweb.clif.scenario.util.isac.gui.Icons;
32 import org.objectweb.clif.scenario.util.isac.gui.ScenarioGUIEditor;
33 import org.objectweb.clif.scenario.util.isac.gui.tree.ScenarioTreeViewer;
34 import org.objectweb.clif.scenario.util.isac.util.tree.Node;
35 import org.objectweb.clif.scenario.util.isac.util.tree.NodeDescription;
36 import org.objectweb.clif.scenario.util.isac.util.tree.ScenarioNode;
37 import org.objectweb.clif.scenario.util.isac.util.tree.TreeManager;
38 /**
39  * Action which add a new action specified by a plugin
40  *
41  * @author JC Meillaud
42  * @author A Peyrard
43  */

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

48     ScenarioGUIEditor window;
49     NodeDescription node;
50     static Category cat = Category.getInstance(AddPluginAction.class
51             .getName());
52     /**
53      * Build a new 'save scenario' action
54      *
55      * @param w
56      * The application window, in wich we will use this action
57      * @param node
58      * The node description of the action which could be added with
59      * this action
60      */

61     public AddPluginAction(ApplicationWindow w, NodeDescription node) {
62         cat.debug("-> constructor");
63         this.window = (ScenarioGUIEditor) w;
64         this.node = node;
65         // get the node help
66
// get the node type
67
String JavaDoc type = node.getType();
68         if (Node.isPluginNode(type)) {
69             this.setText(type + "." + node.getPlugin() + "."
70                     + node.getActionName());
71             this.setToolTipText("Add a new " + type + "." + node.getPlugin()
72                     + "." + node.getActionName() + "to the tree");
73         } else {
74             this.setText(node.getType());
75             this.setToolTipText("Add a new " + node.getType() + "to the tree");
76         }
77         // set the icon
78
String JavaDoc fileName = (String JavaDoc)Icons.getImageDescriptorFileName().get(type) ;
79         if (fileName != null) {
80             try {
81                 this.setImageDescriptor(ImageDescriptor.createFromURL(
82                     new URL JavaDoc("file:" + fileName)));
83             } catch (Exception JavaDoc e) {
84                 cat.warn("Unable to find "+fileName+" icon file");
85             }
86         }
87     }
88
89     public void run() {
90         cat.debug("-> run");
91         // get scenarioTreeViewer
92
ScenarioTreeViewer viewer = this.window.getTreeViewer();
93         ScenarioNode temp = null;
94         if (Node.isStructureNode(this.node.getType()))
95             temp = (TreeManager.getTreeManager(null)).addNode(this.node, null);
96         else
97             temp = (TreeManager.getTreeManager(null)).addNode(this.node, viewer
98                     .getSelectedNode());
99         // expand the element
100
viewer.expand(temp, true);
101
102         // check if it's a new plugin to be used
103
String JavaDoc type = node.getType();
104         if (type.equals(Node.USE)) {
105             // add the plugin in the used table
106
(TreeManager.getTreeManager(null)).idGenerator(this.node);
107         }
108         // update the add menu
109
this.window.updateAddMenu(viewer.getSelectedNode());
110         // refresh the viewer
111
viewer.refresh();
112         // set the saved state
113
this.window.setScenarioSavedState(false) ;
114     }
115 }
Popular Tags