KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > fractal > explorer > 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.3 2004/11/15 16:44:24 moroy Exp $
27  ====================================================================*/

28
29 package org.objectweb.fractal.explorer.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.fractal.explorer.FcExplorer;
42 import org.objectweb.fractal.explorer.context.ClientInterfaceWrapper;
43 import org.objectweb.util.explorer.api.MenuItem;
44 import org.objectweb.util.explorer.api.MenuItemTreeView;
45 import org.objectweb.util.explorer.api.TreeView;
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 MenuItem interface.
77
//
78
//==================================================================
79

80     /* (non-Javadoc)
81      * @see org.objectweb.util.explorer.api.MenuItem#getStatus(org.objectweb.util.explorer.api.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 = FcExplorer.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 = FcExplorer.getBindingController(component);
100             bindInterface = (Interface)bc.lookupFc(ir.getFcItfName());
101         }catch(Exception JavaDoc e) {
102             //System.err.println("GetStatus Error : " + e.getMessage());
103
return MenuItem.NOT_VISIBLE_STATUS;
104         }
105         if(bindInterface != null && !started) { // Bound and not started
106
return MenuItem.ENABLED_STATUS;
107         } else if (bindInterface != null && started) { // Bound but started
108
return MenuItem.DISABLED_STATUS;
109         } else if (bindInterface == null) { // Not bound
110
return MenuItem.NOT_VISIBLE_STATUS;
111         }
112         return MenuItem.DISABLED_STATUS;
113     }
114     
115     /* (non-Javadoc)
116      * @see org.objectweb.util.explorer.api.MenuItem#actionPerformed(org.objectweb.util.explorer.api.MenuItemTreeView)
117      */

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