KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > util > browser > plugins > fractal > menu > RemoveSubComponentAction


1 /*====================================================================
2
3 Objectweb Browser Framework
4 Copyright (C) 2000-2003 INRIA & USTL - LIFL - GOAL
5 Contact: openccm@objectweb.org
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 USA
21
22 Initial developer(s): Jerome Moroy.
23 Contributor(s): ______________________________________.
24
25 ====================================================================*/

26
27 package org.objectweb.util.browser.plugins.fractal.menu;
28
29 /** The console's imports */
30 import java.awt.Dimension JavaDoc;
31
32 /** The Fractal API's imports */
33 import org.objectweb.fractal.api.Component;
34 import org.objectweb.fractal.api.Interface;
35 import org.objectweb.fractal.api.NoSuchInterfaceException;
36 import org.objectweb.fractal.api.control.ContentController;
37 import org.objectweb.fractal.api.control.LifeCycleController;
38
39 /** The Browser API's imports */
40 import org.objectweb.util.browser.api.MenuItem;
41 import org.objectweb.util.browser.api.MenuItemTreeView;
42 import org.objectweb.util.browser.api.TreeView;
43 import org.objectweb.util.browser.core.common.DynamicTree;
44 import org.objectweb.util.browser.gui.api.DialogAction;
45 import org.objectweb.util.browser.gui.api.DialogBox;
46 import org.objectweb.util.browser.gui.api.TreeProvider;
47 import org.objectweb.util.browser.gui.lib.DefaultDialogBox;
48 import org.objectweb.util.browser.gui.lib.DefaultTreeProvider;
49 import org.objectweb.util.browser.gui.lib.TreeBox;
50
51 /**
52  * This action allows to unbind an interface.
53  *
54  * @author <a HREF="mailto:Jerome.Moroy@lifl.fr">Jerome Moroy</a>
55  * @version 0.1
56  */

57 public class RemoveSubComponentAction
58     implements MenuItem, DialogAction {
59
60     //==================================================================
61
//
62
// Internal states.
63
//
64
//==================================================================
65

66     /** TheTreeBox used */
67     protected TreeBox treeBox_;
68
69     /** The controller used to add a new component component */
70     protected ContentController contentInterface_;
71
72     //==================================================================
73
//
74
// No constructor.
75
//
76
//==================================================================
77

78     //==================================================================
79
//
80
// No Internal method.
81
//
82
//==================================================================
83

84     //==================================================================
85
//
86
// Public methods for ExtendedActionListener interface.
87
//
88
//==================================================================
89

90     /**
91      * @see org.objectweb.util.browser.api.MenuItem#getStatus(org.objectweb.util.browser.gui.common.TreeView)
92      */

93     public int getStatus(TreeView treeView) {
94         ContentController contentInterface = (ContentController)treeView.getSelectedObject();
95         Component component = ((Interface)contentInterface).getFcItfOwner();
96         try {
97             LifeCycleController lcc = (LifeCycleController)component.getFcInterface("lifecycle-controller");
98             String JavaDoc status = lcc.getFcState();
99             if (status.equals("STARTED"))
100                 return MenuItem.DISABLED_STATUS;
101         } catch (NoSuchInterfaceException e) {
102            // e.printStackTrace();
103
}
104         return MenuItem.ENABLED_STATUS;
105     }
106
107     /**
108      * The action event
109      */

110     public void actionPerformed(MenuItemTreeView e) throws Exception JavaDoc{
111         
112         contentInterface_ = (ContentController)e.getSelectedObject();
113         
114         TreeProvider treeProvider = new DefaultTreeProvider();
115         DynamicTree tree = treeProvider.createDynamicTree(e,false);
116         tree.addEntry("Content Interface",contentInterface_,1);
117
118         treeBox_ = new TreeBox(tree);
119         treeBox_.setPreferredSize(new Dimension JavaDoc(450, 350));
120
121         DialogBox dialog = new DefaultDialogBox("Select a component to remove");
122         dialog.setValidateAction(this);
123         dialog.addElementBox(treeBox_);
124         dialog.show();
125     }
126     
127     //==================================================================
128
//
129
// Public methods for DialogAction interface.
130
//
131
//==================================================================
132

133     /**
134      * Executes an action
135      */

136     public void executeAction() throws Exception JavaDoc {
137         Object JavaDoc o = treeBox_.getObject();
138         try{
139             Component subComponent = (Component)o;
140             contentInterface_.removeFcSubComponent(subComponent);
141         }catch(ClassCastException JavaDoc e1){
142             throw new Exception JavaDoc("You must select a ComponentIdentity !");
143         }
144     }
145
146
147 }
Popular Tags