1 28 29 package org.objectweb.util.browser.plugins.fractal.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.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 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 = FcBrowser.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 = FcBrowser.getBindingController(component); 100 bindInterface = (Interface)bc.lookupFc(ir.getFcItfName()); 101 }catch(Exception e) { 102 System.err.println("GetStatus Error : " + e.getMessage()); 103 } 104 if(bindInterface != null && !started) { return MenuItem.ENABLED_STATUS; 106 } else if (bindInterface != null && started) { return MenuItem.DISABLED_STATUS; 108 } else if (bindInterface == null) { return MenuItem.NOT_VISIBLE_STATUS; 110 } 111 return MenuItem.DISABLED_STATUS; 112 } 113 114 117 public void actionPerformed(MenuItemTreeView e) throws Exception { 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 message = new StringBuffer (); 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 |