KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > fractal > explorer > menu > BindAction


1 /*====================================================================
2  
3  Objectweb Browser Framework
4  Copyright (C) 2000-2004 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  $Id: BindAction.java,v 1.3 2004/11/15 16:44:24 moroy Exp $
27  ====================================================================*/

28
29 package org.objectweb.fractal.explorer.menu;
30
31 import java.awt.Dimension JavaDoc;
32
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.BindingController;
37 import org.objectweb.fractal.api.control.LifeCycleController;
38 import org.objectweb.fractal.explorer.FcExplorer;
39 import org.objectweb.fractal.explorer.context.ClientInterfaceWrapper;
40 import org.objectweb.util.explorer.api.MenuItem;
41 import org.objectweb.util.explorer.api.MenuItemTreeView;
42 import org.objectweb.util.explorer.api.TreeView;
43 import org.objectweb.util.explorer.swing.gui.api.DialogAction;
44 import org.objectweb.util.explorer.swing.gui.api.DialogBox;
45 import org.objectweb.util.explorer.swing.gui.lib.DefaultDialogBox;
46 import org.objectweb.util.explorer.swing.gui.lib.TreeBox;
47
48 /**
49  * This action allows to bind an client interface to a server one.
50  * @author <a HREF="mailto:Jerome.Moroy@lifl.fr">Jerome Moroy</a>
51  * @version 0.1
52  */

53 public class BindAction
54   implements MenuItem,
55              DialogAction
56 {
57     //==================================================================
58
//
59
// Internal states.
60
//
61
//==================================================================
62

63     /** The TreeBox used. */
64     protected TreeBox treeBox_;
65     
66     /** The InterfaceReference on which the interface will be bound. */
67     protected Interface clientInterface_;
68     
69     //==================================================================
70
//
71
// No constructor.
72
//
73
//==================================================================
74

75     //==================================================================
76
//
77
// No Internal method.
78
//
79
//==================================================================
80

81     //==================================================================
82
//
83
// Public methods for MenuItem interface.
84
//
85
//==================================================================
86

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

90     public int getStatus(TreeView treeView) {
91         try {
92             boolean started = false;
93             ClientInterfaceWrapper cirw = (ClientInterfaceWrapper) treeView.getSelectedObject();
94             Interface ir = cirw.getItf();
95             Component component = ir.getFcItfOwner();
96             // Test if the component is started
97
LifeCycleController lcc = FcExplorer.getLifeCycleController(component);
98             String JavaDoc status = lcc.getFcState();
99             if (status.equals(LifeCycleController.STARTED))
100                 started = true;
101             // Test if the component is bound
102
Interface bindInterface = null;
103             try{
104                 BindingController bc = FcExplorer.getBindingController(component);
105                 bindInterface = (Interface)bc.lookupFc(ir.getFcItfName());
106             }catch(Exception JavaDoc e) {
107                 //System.err.println("Error : " + e.getMessage());
108
return MenuItem.NOT_VISIBLE_STATUS;
109             }
110             if(bindInterface == null && !started){
111                 // Not bound and not started
112
return MenuItem.ENABLED_STATUS;
113             } else if (bindInterface == null && started) {
114                 // Not bound but started
115
return MenuItem.DISABLED_STATUS;
116             } else if (bindInterface != null){
117                 // Already bound
118
return MenuItem.NOT_VISIBLE_STATUS;
119             }
120         } catch (NoSuchInterfaceException e) {
121             e.printStackTrace();
122         }
123         return MenuItem.DISABLED_STATUS;
124     }
125     
126     /* (non-Javadoc)
127      * @see org.objectweb.util.explorer.api.MenuItem#actionPerformed(org.objectweb.util.explorer.api.MenuItemTreeView)
128      */

129     public void actionPerformed(MenuItemTreeView e) throws Exception JavaDoc{
130         ClientInterfaceWrapper clientWrapper = (ClientInterfaceWrapper)e.getSelectedObject();
131         clientInterface_ = clientWrapper.getItf();
132         
133         treeBox_ = new TreeBox(e.getTree().duplicate());
134         treeBox_.setPreferredSize(new Dimension JavaDoc(450, 350));
135         
136         DialogBox dialog = new DefaultDialogBox("Select the interface to bind");
137         dialog.setValidateAction(this);
138         dialog.addElementBox(treeBox_);
139         dialog.show();
140     }
141     
142     //==================================================================
143
//
144
// Public methods for DialogAction interface.
145
//
146
//==================================================================
147

148     /* (non-Javadoc)
149      * @see org.objectweb.util.explorer.swing.gui.api.DialogAction#executeAction()
150      */

151     public void executeAction() throws Exception JavaDoc {
152         Object JavaDoc o = treeBox_.getObject();
153         Interface serverInterface = (Interface)o;
154         FcExplorer.getBindingController(clientInterface_.getFcItfOwner()).bindFc(clientInterface_.getFcItfName(),serverInterface);
155     }
156     
157 }
158
Popular Tags