KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > util > browser > plugins > fractal > 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.1 2004/04/20 16:37:27 moroy Exp $
27  ====================================================================*/

28
29 package org.objectweb.util.browser.plugins.fractal.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.util.browser.api.MenuItem;
39 import org.objectweb.util.browser.api.MenuItemTreeView;
40 import org.objectweb.util.browser.api.TreeView;
41 import org.objectweb.util.browser.core.common.DynamicTree;
42 import org.objectweb.util.browser.gui.api.DialogAction;
43 import org.objectweb.util.browser.gui.api.DialogBox;
44 import org.objectweb.util.browser.gui.api.TreeProvider;
45 import org.objectweb.util.browser.gui.lib.DefaultDialogBox;
46 import org.objectweb.util.browser.gui.lib.DefaultTreeProvider;
47 import org.objectweb.util.browser.gui.lib.TreeBox;
48 import org.objectweb.util.browser.plugins.fractal.FcBrowser;
49 import org.objectweb.util.browser.plugins.fractal.context.ClientInterfaceWrapper;
50
51 /**
52  * This action allows to bind an client interface to a server one.
53  * @author <a HREF="mailto:Jerome.Moroy@lifl.fr">Jerome Moroy</a>
54  * @version 0.1
55  */

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

66     /** The TreeBox used. */
67     protected TreeBox treeBox_;
68     
69     /** The InterfaceReference on which the interface will be bound. */
70     protected Interface clientInterface_;
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#isActive(org.objectweb.util.browser.gui.common.TreeView)
92      */

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

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

153     /**
154      * Executes an action
155      */

156     public void executeAction() throws Exception JavaDoc {
157         Object JavaDoc o = treeBox_.getObject();
158         Interface serverInterface = (Interface)o;
159         FcBrowser.getBindingController(clientInterface_.getFcItfOwner()).bindFc(clientInterface_.getFcItfName(),serverInterface);
160     }
161     
162 }
163
Popular Tags