1 26 27 package org.objectweb.fractal.explorer.menu; 28 29 import java.awt.Dimension ; 30 31 import org.objectweb.fractal.api.Component; 32 import org.objectweb.fractal.api.Interface; 33 import org.objectweb.fractal.api.NoSuchInterfaceException; 34 import org.objectweb.fractal.api.control.ContentController; 35 import org.objectweb.fractal.api.control.LifeCycleController; 36 import org.objectweb.util.explorer.api.MenuItem; 37 import org.objectweb.util.explorer.api.MenuItemTreeView; 38 import org.objectweb.util.explorer.api.Tree; 39 import org.objectweb.util.explorer.api.TreeView; 40 import org.objectweb.util.explorer.swing.gui.api.DialogAction; 41 import org.objectweb.util.explorer.swing.gui.api.DialogBox; 42 import org.objectweb.util.explorer.swing.gui.lib.DefaultDialogBox; 43 import org.objectweb.util.explorer.swing.gui.lib.TreeBox; 44 45 51 public class RemoveSubComponentAction 52 implements MenuItem, DialogAction 53 { 54 55 61 62 protected TreeBox treeBox_; 63 64 65 protected ContentController contentInterface_; 66 67 73 79 85 88 public int getStatus(TreeView treeView) { 89 ContentController contentInterface = (ContentController)treeView.getSelectedObject(); 90 Component component = ((Interface)contentInterface).getFcItfOwner(); 91 try { 92 LifeCycleController lcc = (LifeCycleController)component.getFcInterface("lifecycle-controller"); 93 String status = lcc.getFcState(); 94 if (status.equals("STARTED")) 95 return MenuItem.DISABLED_STATUS; 96 } catch (NoSuchInterfaceException e) { 97 } 99 return MenuItem.ENABLED_STATUS; 100 } 101 102 105 public void actionPerformed(MenuItemTreeView e) throws Exception { 106 107 contentInterface_ = (ContentController)e.getSelectedObject(); 108 109 Component treeComponent = e.getTree().duplicate(false); 110 Tree treeItf = (Tree)treeComponent.getFcInterface(Tree.TREE); 111 treeItf.addEntry("Content Interface",contentInterface_,1); 112 113 treeBox_ = new TreeBox(treeComponent); 114 treeBox_.setPreferredSize(new Dimension (450, 350)); 115 116 DialogBox dialog = new DefaultDialogBox("Select a component to remove"); 117 dialog.setValidateAction(this); 118 dialog.addElementBox(treeBox_); 119 dialog.show(); 120 } 121 122 128 131 public void executeAction() throws Exception { 132 Object o = treeBox_.getObject(); 133 try{ 134 Component subComponent = (Component)o; 135 contentInterface_.removeFcSubComponent(subComponent); 136 }catch(ClassCastException e1){ 137 throw new Exception ("You must select a ComponentIdentity !"); 138 } 139 } 140 141 142 } | Popular Tags |