1 28 29 package org.objectweb.util.browser.plugins.fractal.menu; 30 31 import org.objectweb.fractal.api.Type; 32 import org.objectweb.fractal.api.factory.GenericFactory; 33 import org.objectweb.util.browser.api.MenuItem; 34 import org.objectweb.util.browser.api.MenuItemTreeView; 35 import org.objectweb.util.browser.api.TreeView; 36 import org.objectweb.util.browser.core.api.ContextContainer; 37 import org.objectweb.util.browser.core.common.DynamicTree; 38 import org.objectweb.util.browser.gui.api.DialogAction; 39 import org.objectweb.util.browser.gui.api.DialogBox; 40 import org.objectweb.util.browser.gui.api.TreeProvider; 41 import org.objectweb.util.browser.gui.lib.DefaultDialogBox; 42 import org.objectweb.util.browser.gui.lib.DefaultTreeProvider; 43 import org.objectweb.util.browser.gui.lib.LabelBox; 44 import org.objectweb.util.browser.gui.lib.TreeChooserBox; 45 import org.objectweb.util.browser.plugins.fractal.FcBrowser; 46 47 52 public class CreateInstanceAction 53 implements MenuItem, DialogAction 54 { 55 56 62 63 protected TreeChooserBox type_; 64 65 66 protected LabelBox name_, controllerDesc_, contentDesc_; 67 68 69 protected ContextContainer cc_; 70 71 77 83 86 protected void createBox(DialogBox dialogBox, DynamicTree tree) { 87 name_ = new LabelBox("Name"); 88 dialogBox.addElementBox(name_); 89 type_ = new TreeChooserBox("Type", tree); 90 dialogBox.addElementBox(type_); 91 controllerDesc_ = new LabelBox("Controller Desc"); 92 dialogBox.addElementBox(controllerDesc_); 93 contentDesc_ = new LabelBox("Content Desc"); 94 dialogBox.addElementBox(contentDesc_); 95 } 96 97 103 public void actionPerformed(MenuItemTreeView e) throws Exception { 104 105 cc_ = (ContextContainer)e.getSelectedObject(); 106 TreeProvider treeProvider = new DefaultTreeProvider(); 107 DynamicTree tree = treeProvider.createDynamicTree(e); 108 109 DialogBox dialog = new DefaultDialogBox("Create a new Instance"); 110 createBox(dialog, tree); 111 dialog.setValidateAction(this); 112 dialog.show(); 113 } 114 115 118 public int getStatus(TreeView treeView) { 119 return MenuItem.ENABLED_STATUS; 120 } 121 122 128 131 public void executeAction() throws Exception { 132 Type type = null; 133 if(type_.getObject()!=null && Type.class.isAssignableFrom(type_.getObject().getClass())) { 134 type = (Type)type_.getObject(); 135 } else { 136 throw new Exception ("You must select an org.objectweb.fractal.api.Type object !"); 137 } 138 String name = name_.getLabel(); 139 String controllerDesc = controllerDesc_.getLabel(); 140 String contentDesc = contentDesc_.getLabel(); 141 GenericFactory gf = FcBrowser.getGenericFactory(FcBrowser.getBootstrapComponent()); 142 cc_.addEntry(name, gf.newFcInstance(type, controllerDesc, contentDesc)); 143 } 144 } | Popular Tags |