1 28 29 package org.objectweb.fractal.explorer.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.fractal.explorer.FcExplorer; 39 import org.objectweb.fractal.explorer.context.ClientInterfaceWrapper; 40 import org.objectweb.util.explorer.api.MenuItem; 41 import org.objectweb.util.explorer.api.MenuItemTreeView; 42 import org.objectweb.util.explorer.api.TreeView; 43 import org.objectweb.util.explorer.swing.gui.api.DialogAction; 44 import org.objectweb.util.explorer.swing.gui.api.DialogBox; 45 import org.objectweb.util.explorer.swing.gui.lib.DefaultDialogBox; 46 import org.objectweb.util.explorer.swing.gui.lib.TreeBox; 47 48 53 public class BindAction 54 implements MenuItem, 55 DialogAction 56 { 57 63 64 protected TreeBox treeBox_; 65 66 67 protected Interface clientInterface_; 68 69 75 81 87 90 public int getStatus(TreeView treeView) { 91 try { 92 boolean started = false; 93 ClientInterfaceWrapper cirw = (ClientInterfaceWrapper) treeView.getSelectedObject(); 94 Interface ir = cirw.getItf(); 95 Component component = ir.getFcItfOwner(); 96 LifeCycleController lcc = FcExplorer.getLifeCycleController(component); 98 String status = lcc.getFcState(); 99 if (status.equals(LifeCycleController.STARTED)) 100 started = true; 101 Interface bindInterface = null; 103 try{ 104 BindingController bc = FcExplorer.getBindingController(component); 105 bindInterface = (Interface)bc.lookupFc(ir.getFcItfName()); 106 }catch(Exception e) { 107 return MenuItem.NOT_VISIBLE_STATUS; 109 } 110 if(bindInterface == null && !started){ 111 return MenuItem.ENABLED_STATUS; 113 } else if (bindInterface == null && started) { 114 return MenuItem.DISABLED_STATUS; 116 } else if (bindInterface != null){ 117 return MenuItem.NOT_VISIBLE_STATUS; 119 } 120 } catch (NoSuchInterfaceException e) { 121 e.printStackTrace(); 122 } 123 return MenuItem.DISABLED_STATUS; 124 } 125 126 129 public void actionPerformed(MenuItemTreeView e) throws Exception { 130 ClientInterfaceWrapper clientWrapper = (ClientInterfaceWrapper)e.getSelectedObject(); 131 clientInterface_ = clientWrapper.getItf(); 132 133 treeBox_ = new TreeBox(e.getTree().duplicate()); 134 treeBox_.setPreferredSize(new Dimension (450, 350)); 135 136 DialogBox dialog = new DefaultDialogBox("Select the interface to bind"); 137 dialog.setValidateAction(this); 138 dialog.addElementBox(treeBox_); 139 dialog.show(); 140 } 141 142 148 151 public void executeAction() throws Exception { 152 Object o = treeBox_.getObject(); 153 Interface serverInterface = (Interface)o; 154 FcExplorer.getBindingController(clientInterface_.getFcItfOwner()).bindFc(clientInterface_.getFcItfName(),serverInterface); 155 } 156 157 } 158 | Popular Tags |