1 28 29 package org.objectweb.fractal.explorer.menu; 30 31 import org.objectweb.fractal.api.Component; 32 import org.objectweb.fractal.api.Type; 33 import org.objectweb.fractal.api.factory.GenericFactory; 34 import org.objectweb.fractal.explorer.FcExplorer; 35 import org.objectweb.util.explorer.api.MenuItem; 36 import org.objectweb.util.explorer.api.MenuItemTreeView; 37 import org.objectweb.util.explorer.api.TreeView; 38 import org.objectweb.util.explorer.core.common.api.ContextContainer; 39 import org.objectweb.util.explorer.swing.gui.api.DialogAction; 40 import org.objectweb.util.explorer.swing.gui.api.DialogBox; 41 import org.objectweb.util.explorer.swing.gui.lib.DefaultDialogBox; 42 import org.objectweb.util.explorer.swing.gui.lib.LabelBox; 43 import org.objectweb.util.explorer.swing.gui.lib.TreeChooserBox; 44 45 50 public class CreateInstanceAction 51 implements MenuItem, DialogAction 52 { 53 54 60 61 protected TreeChooserBox type_; 62 63 64 protected LabelBox name_, controllerDesc_, contentDesc_; 65 66 67 protected ContextContainer cc_; 68 69 75 81 84 protected void createBox(DialogBox dialogBox, Component treeComponent) { 85 name_ = new LabelBox("Name"); 86 dialogBox.addElementBox(name_); 87 type_ = new TreeChooserBox("Type", treeComponent); 88 dialogBox.addElementBox(type_); 89 controllerDesc_ = new LabelBox("Controller Desc"); 90 dialogBox.addElementBox(controllerDesc_); 91 contentDesc_ = new LabelBox("Content Desc"); 92 dialogBox.addElementBox(contentDesc_); 93 } 94 95 101 104 public void actionPerformed(MenuItemTreeView e) throws Exception { 105 106 cc_ = (ContextContainer)e.getSelectedObject(); 107 108 DialogBox dialog = new DefaultDialogBox("Create a new Instance"); 109 createBox(dialog, e.getTree().duplicate()); 110 dialog.setValidateAction(this); 111 dialog.show(); 112 } 113 114 117 public int getStatus(TreeView treeView) { 118 return MenuItem.ENABLED_STATUS; 119 } 120 121 127 130 public void executeAction() throws Exception { 131 Type type = null; 132 if(type_.getObject()!=null && Type.class.isAssignableFrom(type_.getObject().getClass())) { 133 type = (Type)type_.getObject(); 134 } else { 135 throw new Exception ("You must select an org.objectweb.fractal.api.Type object !"); 136 } 137 String name = name_.getLabel(); 138 String controllerDesc = controllerDesc_.getLabel(); 139 String contentDesc = contentDesc_.getLabel(); 140 GenericFactory gf = FcExplorer.getGenericFactory(FcExplorer.getBootstrapComponent()); 141 cc_.addEntry(name, gf.newFcInstance(type, controllerDesc, contentDesc)); 142 } 143 } | Popular Tags |