1 28 29 package org.objectweb.fractal.explorer.menu; 30 31 import javax.swing.JOptionPane ; 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 52 public class UnbindAction 53 implements MenuItem 54 { 55 56 62 68 74 80 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 status = lcc.getFcState(); 91 if (status.equals(LifeCycleController.STARTED)) 92 started = true; 93 } catch (NoSuchInterfaceException e1) { 94 e1.printStackTrace(); 95 } 96 Interface bindInterface = null; 98 try{ 99 BindingController bc = FcExplorer.getBindingController(component); 100 bindInterface = (Interface)bc.lookupFc(ir.getFcItfName()); 101 }catch(Exception e) { 102 return MenuItem.NOT_VISIBLE_STATUS; 104 } 105 if(bindInterface != null && !started) { return MenuItem.ENABLED_STATUS; 107 } else if (bindInterface != null && started) { return MenuItem.DISABLED_STATUS; 109 } else if (bindInterface == null) { return MenuItem.NOT_VISIBLE_STATUS; 111 } 112 return MenuItem.DISABLED_STATUS; 113 } 114 115 118 public void actionPerformed(MenuItemTreeView e) throws Exception { 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 message = new StringBuffer (); 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 |