1 28 29 package org.objectweb.util.browser.plugins.fractal.menu; 30 31 import java.awt.Dimension ; 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 56 public class BindAction 57 implements MenuItem, 58 DialogAction 59 { 60 66 67 protected TreeBox treeBox_; 68 69 70 protected Interface clientInterface_; 71 72 78 84 90 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 LifeCycleController lcc = FcBrowser.getLifeCycleController(component); 101 String status = lcc.getFcState(); 102 if (status.equals(LifeCycleController.STARTED)) 103 started = true; 104 Interface bindInterface = null; 106 try{ 107 BindingController bc = FcBrowser.getBindingController(component); 108 bindInterface = (Interface)bc.lookupFc(ir.getFcItfName()); 109 }catch(Exception e) { 110 System.err.println("Error : " + e.getMessage()); 111 } 112 if(bindInterface == null && !started){ 113 return MenuItem.ENABLED_STATUS; 115 } else if (bindInterface == null && started) { 116 return MenuItem.DISABLED_STATUS; 118 } else if (bindInterface != null){ 119 return MenuItem.NOT_VISIBLE_STATUS; 121 } 122 } catch (NoSuchInterfaceException e) { 123 e.printStackTrace(); 124 } 125 return MenuItem.DISABLED_STATUS; 126 } 127 128 131 public void actionPerformed(MenuItemTreeView e) throws Exception { 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 (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 153 156 public void executeAction() throws Exception { 157 Object o = treeBox_.getObject(); 158 Interface serverInterface = (Interface)o; 159 FcBrowser.getBindingController(clientInterface_.getFcItfOwner()).bindFc(clientInterface_.getFcItfName(),serverInterface); 160 } 161 162 } 163 | Popular Tags |