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.NoSuchInterfaceException; 35 import org.objectweb.fractal.api.control.ContentController; 36 import org.objectweb.fractal.api.control.LifeCycleController; 37 import org.objectweb.util.browser.api.MenuItem; 38 import org.objectweb.util.browser.api.MenuItemTreeView; 39 import org.objectweb.util.browser.api.TreeView; 40 import org.objectweb.util.browser.core.common.DynamicTree; 41 import org.objectweb.util.browser.gui.api.DialogAction; 42 import org.objectweb.util.browser.gui.api.DialogBox; 43 import org.objectweb.util.browser.gui.api.TreeProvider; 44 import org.objectweb.util.browser.gui.lib.DefaultDialogBox; 45 import org.objectweb.util.browser.gui.lib.DefaultTreeProvider; 46 import org.objectweb.util.browser.gui.lib.TreeBox; 47 import org.objectweb.util.browser.plugins.fractal.FcBrowser; 48 49 54 public class AddSubComponentAction 55 implements MenuItem, 56 DialogAction 57 { 58 64 65 protected TreeBox treeBox_; 66 67 68 protected ContentController contentInterface_; 69 70 76 82 88 91 public int getStatus(TreeView treeView) { 92 ContentController contentInterface = (ContentController)treeView.getSelectedObject(); 93 Component component = FcBrowser.getComponent(contentInterface); 94 try { 95 LifeCycleController lcc = FcBrowser.getLifeCycleController(component); 96 String status = lcc.getFcState(); 97 if (status.equals(LifeCycleController.STARTED)) 98 return MenuItem.DISABLED_STATUS; 99 } catch (NoSuchInterfaceException e) { } 100 return MenuItem.ENABLED_STATUS; 101 } 102 103 106 public void actionPerformed(MenuItemTreeView e) throws Exception { 107 contentInterface_ = (ContentController)e.getSelectedObject(); 108 109 TreeProvider treeProvider = new DefaultTreeProvider(); 110 DynamicTree tree = treeProvider.createDynamicTree(e); 111 112 treeBox_ = new TreeBox(tree); 113 treeBox_.setPreferredSize(new Dimension (450, 350)); 114 115 DialogBox dialog = new DefaultDialogBox("Select a component to add"); 116 dialog.setValidateAction(this); 117 dialog.addElementBox(treeBox_); 118 dialog.show(); 119 } 120 121 127 130 public void executeAction() throws Exception { 131 Object o = treeBox_.getObject(); 132 try{ 133 Component subComponent = (Component)o; 134 contentInterface_.addFcSubComponent(subComponent); 135 }catch(ClassCastException e){ 136 throw new Exception ("You must select a component!"); 137 } 138 } 139 140 } | Popular Tags |