KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > kelp > jbuilder > tool > DodsTool


1 /*
2  * Enhydra Java Application Server Project
3  *
4  * The contents of this file are subject to the Enhydra Public License
5  * Version 1.1 (the "License"); you may not use this file except in
6  * compliance with the License. You may obtain a copy of the License on
7  * the Enhydra web site ( http://www.enhydra.org/ ).
8  *
9  * Software distributed under the License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
11  * the License for the specific terms governing rights and limitations
12  * under the License.
13  *
14  * The Initial Devel doper of the Enhydra Application Server is Lutris
15  * Technologies, Inc. The Enhydra Application Server and portions created
16  * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
17  * All Rights Reserved.
18  *
19  * Contributor(s):
20  * Paul Mahar
21  *
22  */

23 package org.enhydra.kelp.jbuilder.tool;
24
25 import java.io.File JavaDoc;
26 // JBuilder imports
27
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 JavaDoc;
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 // Kelp imports
48
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 //
67
public class DodsTool extends AbstractBasicTool {
68
69
70     //
71
private final String JavaDoc HELP_LINK = KelpInfo.getAddinHelpURL(); // nores
72

73     //
74
public static void initOpenTool(byte majorVersion, byte minorVersion) {
75         AbstractBasicTool.initAllTools(majorVersion, minorVersion);
76             //Dusan 22.01.03.
77
FileType ft = FileType.getFileType("doml");
78             if (ft == null) {
79               ft.registerFileType("doml", FileType.getFileType("xml"));
80             }
81
82             //Dusan 22.01.03.
83
//Setting right click on Node tab in ContentManager
84
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 JavaDoc ex) {
93                   return null;
94                 }
95               }
96             });
97
98             //Dusan 25.01.03.
99
//Setting right click on Node tab in ProjectView
100
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 JavaDoc ex) {
110                  return null;
111               }
112               }
113             });
114     }
115
116     //Dusan 22.01.03.
117
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     //
133
public DodsTool() {
134         putValue(BrowserAction.SMALL_ICON, KelpIconSet.getSmallIcon());
135     }
136
137     // implement: org.enhydra.kelp.jbuilder.toolAbstractBasicWizard
138
public String JavaDoc getTitle() {
139         return CoreDodsTool.getDefaultTitle();
140     }
141
142     // implement: org.enhydra.kelp.jbuilder.toolAbstractBasicWizard
143
public String JavaDoc getDescription() {
144         return res.getString("Dods_content");
145     }
146
147     // implement: com.borland.primetime.ide.BrowserAction
148
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             // do nothing
158
} 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 // primeProject.setDODSGenerator(new DODSGenerator());
166

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.getSourcePathArray();
181
//Url url = new Url(new File(rootPath[0]));
182
String JavaDoc rootPath=primeProject.getDodsRootPath();
183                         Url url = new Url(new File JavaDoc(rootPath));
184                     try {
185                         doAddPackages(jbProject, url.getFile(), url);
186                         doAddFiles(jbProject, url);
187                     }
188                catch (Exception JavaDoc ex) {
189                 ex.printStackTrace();
190              }
191          }
192
193             }
194         }
195     }
196
197
198     /**
199    * Recursively add needed PackageNodes
200    *
201    * This routine uses recursive logic to locate all subdirectories under
202    * the given root directory and (if not already present) add a PackageNode
203    * for each of those subdirectories which is a legal package name and
204    * has files under it.
205    *
206    * @param jbProject Project where nodes are to be added.
207    * @param rootDir Root directory of the recursive search.
208    * @param url Current directory to examine for subdirectories.
209    */

210   private void doAddPackages(JBProject jbProject,
211                              String JavaDoc rootDir,
212                              Url url) throws Exception JavaDoc {
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 JavaDoc name = urls[j].getFileObject().getAbsolutePath();
217         String JavaDoc[] files = (new File JavaDoc(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   /**
242    * Add needed FileNodes
243    *
244    * This routine finds all the files in the provided directory and adds
245    * them to the given project if they are not there already.
246    *
247    * @param jbProject Project where nodes are to be added.
248    * @param url Current directory to examine for subdirectories.
249    */

250   private void doAddFiles(JBProject jbProject,
251                           Url url) throws Exception JavaDoc {
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 JavaDoc getHelpAnchor() {
267         return HELP_LINK;
268     }
269 }
270
Popular Tags