KickJava   Java API By Example, From Geeks To Geeks.

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


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: UnbindAction.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 javax.swing.JOptionPane 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.Type;
37 import org.objectweb.fractal.api.control.BindingController;
38 import org.objectweb.fractal.api.control.LifeCycleController;
39 import org.objectweb.fractal.api.type.ComponentType;
40 import org.objectweb.fractal.api.type.InterfaceType;
41 import org.objectweb.util.browser.api.MenuItem;
42 import org.objectweb.util.browser.api.MenuItemTreeView;
43 import org.objectweb.util.browser.api.TreeView;
44 import org.objectweb.util.browser.plugins.fractal.FcBrowser;
45 import org.objectweb.util.browser.plugins.fractal.context.ClientInterfaceWrapper;
46
47 /**
48  * This action allows to unbind an interface.
49  * @author <a HREF="mailto:Jerome.Moroy@lifl.fr">Jerome Moroy</a>
50  * @version 0.1
51  */

52 public class UnbindAction
53   implements MenuItem
54 {
55     
56     //==================================================================
57
//
58
// No internal state.
59
//
60
//==================================================================
61

62     //==================================================================
63
//
64
// No constructor.
65
//
66
//==================================================================
67

68     //==================================================================
69
//
70
// No internal method.
71
//
72
//==================================================================
73

74     //==================================================================
75
//
76
// Public methods for ExtendedActionListener interface.
77
//
78
//==================================================================
79

80     /**
81      * @see org.objectweb.util.browser.api.MenuItem#isActive(org.objectweb.util.browser.gui.common.TreeView)
82      */

83     public int getStatus(TreeView treeView) {
84         boolean started = false;
85         ClientInterfaceWrapper cirw = (ClientInterfaceWrapper) treeView.getSelectedObject();
86         Interface ir = cirw.getItf();
87         Component component = ir.getFcItfOwner();
88         try {
89             LifeCycleController lcc = FcBrowser.getLifeCycleController(component);
90             String JavaDoc status = lcc.getFcState();
91             if (status.equals(LifeCycleController.STARTED))
92                 started = true;
93         } catch (NoSuchInterfaceException e1) {
94             e1.printStackTrace();
95         }
96         // Test if the component is bound
97
Interface bindInterface = null;
98         try{
99             BindingController bc = FcBrowser.getBindingController(component);
100             bindInterface = (Interface)bc.lookupFc(ir.getFcItfName());
101         }catch(Exception JavaDoc e) {
102             System.err.println("GetStatus Error : " + e.getMessage());
103         }
104         if(bindInterface != null && !started) { // Bound and not started
105
return MenuItem.ENABLED_STATUS;
106         } else if (bindInterface != null && started) { // Bound but started
107
return MenuItem.DISABLED_STATUS;
108         } else if (bindInterface == null) { // Not bound
109
return MenuItem.NOT_VISIBLE_STATUS;
110         }
111         return MenuItem.DISABLED_STATUS;
112     }
113     
114     /**
115      * The action event
116      */

117     public void actionPerformed(MenuItemTreeView e) throws Exception JavaDoc{
118         ClientInterfaceWrapper irWrapper = (ClientInterfaceWrapper)e.getSelectedObject();
119         Interface ir = irWrapper.getItf();
120         Component ci = ir.getFcItfOwner();
121         BindingController bc = FcBrowser.getBindingController(ci);
122         bc.unbindFc(ir.getFcItfName());
123         
124         StringBuffer JavaDoc message = new StringBuffer JavaDoc();
125         message.append("\"" + ir.getFcItfName() + "\" interface has been successfully unbound !\n");
126         Type t = ci.getFcType();
127         if(ComponentType.class.isAssignableFrom(t.getClass())) {
128             InterfaceType it = (InterfaceType) ir.getFcItfType();
129             if(!it.isFcOptionalItf()&&!it.isFcCollectionItf())
130                 message.append("This interface is mandatory, so, rebind it before starting the component again.");
131         }
132         JOptionPane.showMessageDialog(null,message.toString(),"Unbind success",JOptionPane.INFORMATION_MESSAGE);
133     }
134 }
Popular Tags