1 23 package org.enhydra.kelp.jbuilder.tool; 24 25 import java.io.File ; 26 import com.borland.jbuilder.JBuilderHelp; 28 import com.borland.jbuilder.node.JBProject; 29 import com.borland.primetime.help.ZipHelpBook; 30 import com.borland.primetime.help.ZipHelpTopic; 31 import com.borland.primetime.ide.Browser; 32 import com.borland.primetime.ide.BrowserAction; 33 import com.borland.primetime.vfs.Filesystem; 34 import com.borland.primetime.vfs.VFS; 35 36 import com.borland.primetime.node.FileType; 37 import com.borland.primetime.wizard.WizardAction; 38 import com.borland.primetime.ide.ContextActionProvider; 39 import com.borland.primetime.node.Node; 40 import com.borland.primetime.ide.ContentManager; 41 import javax.swing.Action ; 42 import com.borland.primetime.ide.BrowserIcons; 43 import com.borland.primetime.wizard.Wizard; 44 import org.enhydra.kelp.jbuilder.wizard.Enhydra3AppWizard; 45 import com.borland.primetime.ide.ProjectView; 46 47 import org.enhydra.kelp.KelpInfo; 49 import org.enhydra.kelp.common.Constants; 50 import org.enhydra.kelp.common.ResUtil; 51 import org.enhydra.kelp.common.node.OtterNode; 52 import org.enhydra.kelp.common.swing.KelpIconSet; 53 import org.enhydra.kelp.common.dods.CoreDodsTool; 54 import org.enhydra.kelp.jbuilder.node.PrimeProject; 55 56 import com.borland.jbuilder.paths.PathSet; 57 import com.borland.jbuilder.paths.PathSetManager; 58 import com.borland.primetime.vfs.Url; 59 import com.borland.jbuilder.paths.JDKPathSet; 60 import com.borland.primetime.node.Project; 61 import com.borland.jbuilder.node.PackageNode; 62 import com.borland.primetime.node.FileNode; 63 64 import org.enhydra.dods.generator.DODSGenerator; 65 66 public class DodsTool extends AbstractBasicTool { 68 69 70 private final String HELP_LINK = KelpInfo.getAddinHelpURL(); 73 public static void initOpenTool(byte majorVersion, byte minorVersion) { 75 AbstractBasicTool.initAllTools(majorVersion, minorVersion); 76 FileType ft = FileType.getFileType("doml"); 78 if (ft == null) { 79 ft.registerFileType("doml", FileType.getFileType("xml")); 80 } 81 82 ContentManager.registerContextActionProvider(new ContextActionProvider() { 85 public Action getContextAction(Browser browser, Node[] nodes) { 86 try { 87 if (browser.getActiveProject() != null) { 88 if (browser.getActiveNode().getDisplayName().indexOf(".doml") != -1) { 89 return ActionDodsGenerator; 90 } } 91 return null; 92 } catch (NullPointerException ex) { 93 return null; 94 } 95 } 96 }); 97 98 ProjectView.registerContextActionProvider(new ContextActionProvider() { 101 public Action getContextAction(Browser browser, Node[] nodes) { 102 try { 103 if (browser.getActiveProject() != null) { 104 if (browser.getActiveNode().getDisplayName().indexOf(".doml") != -1) { 105 return ActionDodsGenerator; 106 } 107 } 108 return null; 109 } catch (NullPointerException ex) { 110 return null; 111 } 112 } 113 }); 114 } 115 116 public static final BrowserAction ActionDodsGenerator = new BrowserAction ( 118 "DODS Generator", 'w', "DODS Generator", 119 KelpIconSet.getSmallIcon(), 120 "DODS Generator" ) { 121 122 public void actionPerformed(Browser browser) { 123 DodsTool dt = new DodsTool(); 124 dt.actionPerformed(browser); 125 } 126 127 public void update(Browser browser) { 128 setEnabled(true); 129 } 130 }; 131 132 public DodsTool() { 134 putValue(BrowserAction.SMALL_ICON, KelpIconSet.getSmallIcon()); 135 } 136 137 public String getTitle() { 139 return CoreDodsTool.getDefaultTitle(); 140 } 141 142 public String getDescription() { 144 return res.getString("Dods_content"); 145 } 146 147 public void actionPerformed(Browser browser) { 149 150 PrimeProject primeProject = null; 151 OtterNode[] inputNodes = new OtterNode[0]; 152 CoreDodsTool coreTool = null; 153 154 setNativeProject((JBProject) browser.getProjectView().getActiveProject()); 155 if (getNativeProject() == null) { 156 157 } else { 159 primeProject = new PrimeProject(getNativeProject()); 160 primeProject.save(); 161 inputNodes = primeProject.getAllInput(); 162 saveNodes(inputNodes); 163 primeProject.setProjectJavaPath(getNativeProject()); 164 primeProject.setEnhydraPath(getNativeProject()); 165 167 if (verifyAllClassPaths(browser.getOwner())) { 168 System.setProperty("DODS_HOME", primeProject.getEnhydraPath()+ 169 File.separator+"dods"); 170 coreTool = new CoreDodsTool(); 171 coreTool.addHelpListener(this); 172 coreTool.setProject(primeProject); 173 coreTool.showDialog(browser); 174 browser.getProjectView().refreshTree(); 175 176 Project project = browser.getActiveProject(); 177 178 if ((project != null) && (project instanceof JBProject)) { 179 final JBProject jbProject = (JBProject)project; 180 String rootPath=primeProject.getDodsRootPath(); 183 Url url = new Url(new File (rootPath)); 184 try { 185 doAddPackages(jbProject, url.getFile(), url); 186 doAddFiles(jbProject, url); 187 } 188 catch (Exception ex) { 189 ex.printStackTrace(); 190 } 191 } 192 193 } 194 } 195 } 196 197 198 210 private void doAddPackages(JBProject jbProject, 211 String rootDir, 212 Url url) throws Exception { 213 Url[] urls = VFS.getChildren(url, Filesystem.TYPE_DIRECTORY); 214 if (urls.length > 0) { 215 for (int j = 0; j < urls.length; j++) { 216 String name = urls[j].getFileObject().getAbsolutePath(); 217 String [] files = (new File (name)).list(); 218 boolean isPackage = false; 219 for (int i=0; i<files.length; i++) { 220 if(files[i].toLowerCase().endsWith(".java")) 221 isPackage = true; 222 } 223 name = name.substring(rootDir.length() + 1); 224 if ((name.indexOf(' ') == -1) 225 && (name.indexOf('-') == -1) 226 && (name.indexOf('.') == -1)) { 227 name = name.replace(File.separatorChar, '.'); 228 if(isPackage) { 229 if (jbProject.findNodes(name).length == 0) { 230 new PackageNode(jbProject, jbProject, name); 231 } 232 } 233 doAddPackages(jbProject, rootDir, urls[j]); 234 } 235 } 236 } 237 } 238 239 240 241 250 private void doAddFiles(JBProject jbProject, 251 Url url) throws Exception { 252 Url[] urls = VFS.getChildren(url, Filesystem.TYPE_FILE); 253 if (urls.length > 0) { 254 for (int j = 0; j < urls.length; j++) { 255 if(urls[j].getFile().toLowerCase().endsWith(".doml")) { 256 if (jbProject.findNode(urls[j]) == null) { 257 FileNode node = jbProject.getNode(urls[j]); 258 node.setParent(jbProject); 259 } 260 } 261 } 262 } 263 } 264 265 266 public String getHelpAnchor() { 267 return HELP_LINK; 268 } 269 } 270 | Popular Tags |