KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > fractal > explorer > 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.fractal.explorer.menu;
28
29 import java.awt.Dimension JavaDoc;
30
31 import org.objectweb.fractal.api.Component;
32 import org.objectweb.fractal.api.Interface;
33 import org.objectweb.fractal.api.NoSuchInterfaceException;
34 import org.objectweb.fractal.api.control.ContentController;
35 import org.objectweb.fractal.api.control.LifeCycleController;
36 import org.objectweb.util.explorer.api.MenuItem;
37 import org.objectweb.util.explorer.api.MenuItemTreeView;
38 import org.objectweb.util.explorer.api.Tree;
39 import org.objectweb.util.explorer.api.TreeView;
40 import org.objectweb.util.explorer.swing.gui.api.DialogAction;
41 import org.objectweb.util.explorer.swing.gui.api.DialogBox;
42 import org.objectweb.util.explorer.swing.gui.lib.DefaultDialogBox;
43 import org.objectweb.util.explorer.swing.gui.lib.TreeBox;
44
45 /**
46  * This action allows to unbind an interface.
47  *
48  * @author <a HREF="mailto:Jerome.Moroy@lifl.fr">Jerome Moroy</a>
49  * @version 0.1
50  */

51 public class RemoveSubComponentAction
52   implements MenuItem, DialogAction
53 {
54
55     //==================================================================
56
//
57
// Internal states.
58
//
59
//==================================================================
60

61     /** TheTreeBox used */
62     protected TreeBox treeBox_;
63
64     /** The controller used to add a new component component */
65     protected ContentController contentInterface_;
66
67     //==================================================================
68
//
69
// No constructor.
70
//
71
//==================================================================
72

73     //==================================================================
74
//
75
// No Internal method.
76
//
77
//==================================================================
78

79     //==================================================================
80
//
81
// Public methods for MenuItem interface.
82
//
83
//==================================================================
84

85     /* (non-Javadoc)
86      * @see org.objectweb.util.explorer.api.MenuItem#getStatus(org.objectweb.util.explorer.api.TreeView)
87      */

88     public int getStatus(TreeView treeView) {
89         ContentController contentInterface = (ContentController)treeView.getSelectedObject();
90         Component component = ((Interface)contentInterface).getFcItfOwner();
91         try {
92             LifeCycleController lcc = (LifeCycleController)component.getFcInterface("lifecycle-controller");
93             String JavaDoc status = lcc.getFcState();
94             if (status.equals("STARTED"))
95                 return MenuItem.DISABLED_STATUS;
96         } catch (NoSuchInterfaceException e) {
97             // e.printStackTrace();
98
}
99         return MenuItem.ENABLED_STATUS;
100     }
101
102     /* (non-Javadoc)
103      * @see org.objectweb.util.explorer.api.MenuItem#actionPerformed(org.objectweb.util.explorer.api.MenuItemTreeView)
104      */

105     public void actionPerformed(MenuItemTreeView e) throws Exception JavaDoc{
106         
107         contentInterface_ = (ContentController)e.getSelectedObject();
108         
109         Component treeComponent = e.getTree().duplicate(false);
110         Tree treeItf = (Tree)treeComponent.getFcInterface(Tree.TREE);
111         treeItf.addEntry("Content Interface",contentInterface_,1);
112
113         treeBox_ = new TreeBox(treeComponent);
114         treeBox_.setPreferredSize(new Dimension JavaDoc(450, 350));
115
116         DialogBox dialog = new DefaultDialogBox("Select a component to remove");
117         dialog.setValidateAction(this);
118         dialog.addElementBox(treeBox_);
119         dialog.show();
120     }
121     
122     //==================================================================
123
//
124
// Public methods for DialogAction interface.
125
//
126
//==================================================================
127

128     /* (non-Javadoc)
129      * @see org.objectweb.util.explorer.swing.gui.api.DialogAction#executeAction()
130      */

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