1 23 package org.enhydra.kelp.forte.actions; 24 25 import org.openide.nodes.Node; 27 import org.openide.util.HelpCtx; 28 import org.openide.util.NbBundle; 29 import org.openide.util.actions.CallableSystemAction; 30 import org.openide.TopManager; 31 import org.openide.loaders.DataFolder; 32 import org.openide.loaders.DataObject; 33 import org.openide.src.ClassElement; 34 import org.openide.DialogDescriptor; 35 import org.openide.filesystems.FileSystem; 36 import org.openide.filesystems.FileObject; 37 38 import org.enhydra.tool.common.SwingUtil; 40 import org.enhydra.tool.common.event.HelpEvent; 41 import org.enhydra.tool.common.event.HelpListener; 42 43 import org.enhydra.kelp.KelpInfo; 45 import org.enhydra.kelp.common.deployer.CoreDeployTool; 46 import org.enhydra.kelp.common.deployer.DeployButtonPanel; 47 import org.enhydra.kelp.common.deployer.DeployButtonListener; 48 import org.enhydra.kelp.common.node.OtterFileNode; 49 50 import org.enhydra.kelp.forte.node.ForteProject; 52 53 import java.awt.Dialog ; 55 import java.awt.event.ActionListener ; 56 import java.awt.event.ActionEvent ; 57 import java.net.URL ; 58 import java.net.MalformedURLException ; 59 60 import java.io.File ; 62 import java.io.FileInputStream ; 63 import java.io.FileOutputStream ; 64 69 public class DeploymentAction extends CallableSystemAction implements HelpListener { 70 private static String anchor = "deploywizard"; 71 72 public void onHelp(HelpEvent event) { 74 URL url = null; 75 String [] home = new String [2]; 76 home[0] = System.getProperty("netbeans.home"); 77 home[1] = System.getProperty("netbeans.user"); 78 StringBuffer buf = new StringBuffer (); 79 buf.append(KelpInfo.getAddinHelpURL(home)); 80 buf.append('#').append(anchor); 81 try { 82 url = new URL (buf.toString()); 83 TopManager.getDefault().showUrl(url); 84 } catch (MalformedURLException e) { 85 e.printStackTrace(System.err); 86 } 87 } 88 89 public void performAction() { 90 String [] options = DeployButtonPanel.getOptions(); 94 CoreDeployTool tool = new CoreDeployTool(); 95 DeployButtonListener listener = new DeployButtonListener(tool); 96 ForteProject project = new ForteProject(); 97 tool.getInnerPanel().initPreferredSize(); 98 tool.setProject(project); 99 DialogDescriptor dscr = new DialogDescriptor(tool.getInnerPanel(), 100 tool.getTitle(), true, options, options[1], 101 DialogDescriptor.BOTTOM_ALIGN, HelpCtx.DEFAULT_HELP, 102 listener); 103 Dialog dlg = TopManager.getDefault().createDialog(dscr); 104 tool.addHelpListener(this); 105 dlg.show(); 106 107 if (project.getDeployType() == ForteProject.TYPE_WEBAPP) { 110 String prjRoot = project.getRootPath(); 111 112 File srcdir = new File (prjRoot+"/src/WEB-INF"); 113 File srcfile = new File (prjRoot+"/src/WEB-INF/web.xml"); 114 115 if (!(srcdir.exists() && srcfile.exists())) return; 116 117 File contentDir = new File (prjRoot+"/output/content"); 118 if (!contentDir.exists()) { 119 if(!contentDir.mkdir()) return; 120 } 121 122 File destdir = new File (prjRoot+"/output/content/WEB-INF"); 123 File destfile = new File (prjRoot+"/output/content/WEB-INF/web.xml"); 124 125 FileInputStream in; 126 FileOutputStream out; 127 128 if (!destdir.mkdir()) return; 129 try { 130 destfile.createNewFile(); 131 132 in = new FileInputStream (srcfile); 133 out = new FileOutputStream (destfile); 134 } 135 catch (Exception e) { 136 if (destfile.exists()) destfile.delete(); 137 destdir.delete(); 138 return; 139 } 140 141 byte buf[] = new byte[1024]; 142 int count, length; 143 144 count = 0; 145 length = 0; 146 147 try { 148 while (length != srcfile.length()) { 149 count = in.read(buf); 150 out.write(buf, 0, count); 151 length += count; 152 } 153 in.close(); 154 out.close(); 155 } 156 catch (Exception e) { 157 } 158 } 159 } 160 161 public String getName() { 162 return CoreDeployTool.getDefaultTitle(); 163 } 164 165 public boolean isEnabled() 166 { 167 FileObject root = new ForteProject().getRootFolder(); 168 if (root == null) 169 return false; 170 if (root.getChildren().length <= 0) 171 return false; 172 else 173 return true; 174 } 175 176 177 protected String iconResource() { 178 return "smallicon.gif"; 179 } 180 181 public HelpCtx getHelpCtx() { 182 return HelpCtx.DEFAULT_HELP; 183 184 } 187 188 192 protected void initialize() { 193 super.initialize(); 195 putProperty(javax.swing.Action.SHORT_DESCRIPTION, 196 NbBundle.getMessage(DeploymentAction.class, 197 "HINT_Deployment_Action")); 198 } 199 200 } 201 | Popular Tags |