1 28 29 package org.objectweb.fractal.explorer.menu; 30 31 import java.util.HashMap ; 32 import java.util.Map ; 33 34 import org.objectweb.fractal.adl.Factory; 35 import org.objectweb.fractal.explorer.api.FractalBrowserConstants; 36 import org.objectweb.fractal.explorer.context.FactoryWrapper; 37 import org.objectweb.fractal.explorer.lib.JFileChooserSingleton; 38 import org.objectweb.util.explorer.api.MenuItem; 39 import org.objectweb.util.explorer.api.MenuItemTreeView; 40 import org.objectweb.util.explorer.api.TreeView; 41 import org.objectweb.util.explorer.swing.gui.api.DialogAction; 42 import org.objectweb.util.explorer.swing.gui.api.DialogBox; 43 import org.objectweb.util.explorer.swing.gui.lib.BooleanBox; 44 import org.objectweb.util.explorer.swing.gui.lib.DefaultDialogBox; 45 import org.objectweb.util.explorer.swing.gui.lib.FileChooserBox; 46 47 52 public class LoadTemplateAction 53 implements MenuItem, 54 DialogAction 55 { 56 62 63 protected FileChooserBox file_ = null; 64 65 66 protected BooleanBox withTemplate_ = null; 67 68 69 protected Factory factory_ = null; 70 71 72 protected TreeView treeView_; 73 74 80 86 89 protected void createBox(DialogBox dialogBox) { 90 file_ = new FileChooserBox("File",JFileChooserSingleton.getInstance(FractalBrowserConstants.FRACTAL_FILE_FILTER)); 91 dialogBox.addElementBox(file_); 92 withTemplate_ = new BooleanBox("Type","Template","Component",false); 93 dialogBox.addElementBox(withTemplate_); 94 } 95 96 102 105 public void actionPerformed(MenuItemTreeView e) throws Exception { 106 treeView_ = e; 107 factory_ = ((FactoryWrapper)e.getSelectedObject()).getFactory(); 108 DialogBox dialog = new DefaultDialogBox("Load a template"); 109 createBox(dialog); 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 String fileName = file_.getFile().getName(); 132 String name = fileName.substring(0,fileName.lastIndexOf(".")); 133 Map map = new HashMap (); 134 String entryName = name; 135 if(withTemplate_.getValue()){ 136 map.put("template","true"); 137 entryName = entryName + "Tmpl"; 138 } 139 treeView_.getTree().addEntry(entryName, factory_.newComponent(name,map)); 140 } 141 142 } | Popular Tags |