KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > kelp > jdev > EnhydraTools


1 package org.enhydra.kelp.jdev;
2 import java.io.BufferedReader JavaDoc;
3 import java.io.File JavaDoc;
4 import java.io.InputStream JavaDoc;
5 import java.io.InputStreamReader JavaDoc;
6
7 import java.net.URL JavaDoc;
8
9 import javax.swing.Icon JavaDoc;
10 import javax.swing.ImageIcon JavaDoc;
11 import javax.swing.JMenu JavaDoc;
12 import javax.swing.JMenuItem JavaDoc;
13
14 import oracle.ide.ContextMenu;
15 import oracle.ide.IdeAction;
16 import oracle.ide.MainWindow;
17 import oracle.ide.addin.Addin;
18 import oracle.ide.addin.Context;
19 import oracle.ide.addin.ContextMenuListener;
20 import oracle.ide.addin.Controller;
21 import oracle.ide.model.Element;
22 import oracle.ide.model.TextNode;
23
24 import org.enhydra.kelp.ant.deployer.AntDeployTool;
25 import org.enhydra.kelp.ant.dods.KelpDODSGenerator;
26 import org.enhydra.kelp.ant.xmlc.AntXMLCTool;
27 import org.enhydra.tool.ToolBoxInfo;
28 import org.enhydra.kelp.ant.node.AntProject;
29 import oracle.ide.Ide;
30 import oracle.ide.model.Project;
31 import oracle.ide.model.Workspace;
32 import oracle.jdeveloper.model.JProject;
33 import oracle.ideimpl.explorer.ExplorerNode;
34 import oracle.ideimpl.navigator.NavigatorWindowImpl;
35
36 public class EnhydraTools implements Addin, Controller, ContextMenuListener
37 {
38   private static JMenuItem JavaDoc contextMenuItem = null;
39
40   public static final int XMLC_CMD_ID = Ide.newCmd("org.enhydra.kelp.jdev.EnhydraTools.XMLC_CMD_ID");
41   public static final int DEPLOYER_CMD_ID = Ide.newCmd("org.enhydra.kelp.jdev.EnhydraTools.DEPLOYER_CMD_ID");
42   public static final int DODS_CMD_ID = Ide.newCmd("org.enhydra.kelp.jdev.EnhydraTools.DODS_CMD_ID");
43   public static final int ANT_REBUILD_CMD_ID = Ide.newCmd("org.enhydra.kelp.jdev.EnhydraTools.ANT_REBUILD_CMD_ID");
44
45   private final static String JavaDoc MENU_ICON = "/media/menu_16x16.gif";
46
47
48   private JMenuItem JavaDoc menuItem = null;
49   public EnhydraTools()
50   {
51   }
52
53   public void initialize()
54   {
55     // Do not do major initialization here, it can slow down the startup of JDeveloper
56
JMenu JavaDoc enhydraGroup = Ide.getMenubar().createSubMenu("Enhydra Tools", new Integer JavaDoc('E'));
57     JMenuItem JavaDoc menuItemXMLC = createMenu_XMLC_CMD_ID(MENU_ICON, "XML Compiler", 88); // X
58
JMenuItem JavaDoc menuItemDeployer = createMenu_DEPLOYER_CMD_ID(null, "Deployer", 68); // D
59
JMenuItem JavaDoc menuItemDODS = createMenu_DODS_CMD_ID(MENU_ICON, "DODS", 79); // O
60
enhydraGroup.add(menuItemXMLC);
61     enhydraGroup.add(menuItemDeployer);
62     enhydraGroup.add(menuItemDODS);
63     JMenu JavaDoc mainMenu = MainWindow.Tools;
64     mainMenu.add(enhydraGroup);
65     Ide.getNavigatorManager().addContextMenuListener(this, null);
66   }
67
68   public void shutdown()
69   {
70     // Do any necessary cleanup here
71
}
72
73   public float version()
74   {
75     // return the version of your extension
76
return 1.0f;
77   }
78
79   public float ideVersion()
80   {
81     return Ide.IDE_VERSION;
82   }
83
84   public boolean canShutdown()
85   {
86     return true;
87   }
88
89   private Icon JavaDoc loadIcon(String JavaDoc iconName)
90   {
91     URL JavaDoc url = getClass().getResource(iconName);
92     Icon JavaDoc icon = null;
93     if (url != null)
94     {
95       icon = new ImageIcon JavaDoc(url);
96     }
97     return icon;
98   }
99
100   private JMenuItem JavaDoc createMenu_XMLC_CMD_ID(String JavaDoc iconName, String JavaDoc menuLabel, int mnemonic)
101   {
102     // String class name which extends oracle.ide.addin.AbstractCommand or null
103
String JavaDoc cmdClass = null;
104     // Category of the keymap to which this entry belongs
105
String JavaDoc category = null;
106     // Icon for the menu item
107
Icon JavaDoc icon = null;
108     if (iconName != null)
109       icon = loadIcon(iconName);
110     // Data to be associated with the Action
111
Object JavaDoc data = null;
112     // Should the action be enabled by default
113
boolean enabled = true;
114
115     IdeAction action;
116     // Create the IdeAction
117
action = IdeAction.get(XMLC_CMD_ID, cmdClass, menuLabel, category, new Integer JavaDoc(mnemonic), icon, data, enabled);
118     // Set the default controller for this action
119
action.setController(this);
120     // Create MenuItem
121
JMenuItem JavaDoc menuItem = Ide.getMenubar().createMenuItem(action);
122
123     return menuItem;
124   }
125
126   private JMenuItem JavaDoc createMenu_DEPLOYER_CMD_ID(String JavaDoc iconName, String JavaDoc menuLabel, int mnemonic)
127   {
128     // String class name which extends oracle.ide.addin.AbstractCommand or null
129
String JavaDoc cmdClass = null;
130     // Category of the keymap to which this entry belongs
131
String JavaDoc category = null;
132     // Icon for the menu item
133
Icon JavaDoc icon = null;
134     if (iconName != null)
135       icon = loadIcon(iconName);
136     // Data to be associated with the Action
137
Object JavaDoc data = null;
138     // Should the action be enabled by default
139
boolean enabled = true;
140
141     IdeAction action;
142     // Create the IdeAction
143
action = IdeAction.get(DEPLOYER_CMD_ID, cmdClass, menuLabel, category, new Integer JavaDoc(mnemonic), icon, data, enabled);
144     // Set the default controller for this action
145
action.setController(this);
146     // Create MenuItem
147
JMenuItem JavaDoc menuItem = Ide.getMenubar().createMenuItem(action);
148
149     return menuItem;
150   }
151
152   private JMenuItem JavaDoc createMenu_DODS_CMD_ID(String JavaDoc iconName, String JavaDoc menuLabel, int mnemonic)
153   {
154     // String class name which extends oracle.ide.addin.AbstractCommand or null
155
String JavaDoc cmdClass = null;
156     // Category of the keymap to which this entry belongs
157
String JavaDoc category = null;
158     // Icon for the menu item
159
Icon JavaDoc icon = null;
160     if (iconName != null)
161       icon = loadIcon(iconName);
162     // Data to be associated with the Action
163
Object JavaDoc data = null;
164     // Should the action be enabled by default
165
boolean enabled = true;
166
167     IdeAction action;
168     // Create the IdeAction
169
action = IdeAction.get(DODS_CMD_ID, cmdClass, menuLabel, category, new Integer JavaDoc(mnemonic), icon, data, enabled);
170     // Set the default controller for this action
171
action.setController(this);
172     // Create MenuItem
173
JMenuItem JavaDoc menuItem = Ide.getMenubar().createMenuItem(action);
174
175     return menuItem;
176   }
177
178   public Controller supervisor()
179   {
180     return null;
181   }
182
183   public boolean handleEvent(IdeAction action, Context context)
184   {
185     final int cmdId = action.getCommandId();
186     String JavaDoc prjPath = Ide.getActiveWorkspace().getActiveProjectURL().getFile();
187 // vl
188
if (prjPath.charAt(0) == '/'){
189       prjPath=prjPath.substring(1);
190     }
191 // vl
192
prjPath = prjPath.substring(0, prjPath.lastIndexOf("/"));
193     boolean refresh = false;
194     if (cmdId == XMLC_CMD_ID)
195     {
196       AntXMLCTool.main(new String JavaDoc[]{prjPath});
197       refresh = true;
198     }
199     else if (cmdId == DEPLOYER_CMD_ID)
200     {
201       AntDeployTool.main(new String JavaDoc[]{prjPath});
202       refresh = true;
203     }
204     else if (cmdId == DODS_CMD_ID)
205     {
206       try {
207         System.out.println("prjPath="+prjPath);
208         AntProject antProject = new AntProject(prjPath);
209         String JavaDoc enhydraDir = antProject.getProperty(AntProject.ENHYDRA_DIR);
210         System.out.println("enhydraDir="+enhydraDir);
211         File JavaDoc dodsDirFile = new File JavaDoc(enhydraDir, "dods");
212         System.out.println("dodsDirFile="+dodsDirFile.getPath());
213         System.setProperty("DODS_HOME", dodsDirFile.getAbsolutePath());
214         System.out.println("2-DODS_HOME="+dodsDirFile.getAbsolutePath());
215         System.out.println("2.1-dodsDirFile="+prjPath);
216         KelpDODSGenerator.main(new String JavaDoc[]{prjPath});
217         System.out.println("3-dodsDirFile="+dodsDirFile.getPath());
218         refresh = true;
219       } catch (Exception JavaDoc e) {
220         e.printStackTrace();
221       }
222     }
223     if (refresh)
224     {
225       Workspace ws = Ide.getActiveWorkspace();
226       JProject activeProj = (JProject)Ide.getActiveProject();
227       refreshNavigator(ws, activeProj);
228       return true;
229     }
230     else
231       return false;
232   }
233
234   public boolean update(IdeAction action, Context context)
235   {
236     final int cmdId = action.getCommandId();
237     if (cmdId == org.enhydra.kelp.jdev.EnhydraTools.XMLC_CMD_ID)
238     {
239       action.setEnabled(is_XMLC_CMD_ID_Available(context));
240       return true;
241     }
242     return false;
243   }
244
245   private boolean is_XMLC_CMD_ID_Available(Context context)
246   {
247     if (context == null)
248     {
249       return false;
250     }
251     Element element = context.getElement();
252     if (element == null)
253     {
254       return false;
255     }
256     if (element instanceof Project)
257     {
258       return true;
259     }
260     else
261     {
262       return false;
263     }
264   }
265
266   public void checkCommands(Context action, Controller controller)
267   {
268     // If your command is on the main menu and has an accelerator you need to call update from here
269
// If your command is on the toolbar then you also must call update from here
270
}
271
272   private JMenuItem JavaDoc getContextMenuItem()
273   {
274     if (contextMenuItem == null)
275     {
276       contextMenuItem = createMenu_XMLC_CMD_ID(MENU_ICON, "XMLC", 88);
277     }
278     return contextMenuItem;
279   }
280
281   public void poppingUp(ContextMenu popup)
282   {
283     // The getContextMenuItem function will lazily instantiate the menu item
284
popup.add(getContextMenuItem());
285   }
286
287   public void poppingDown(ContextMenu popup)
288   {
289   }
290
291   public boolean handleDefaultAction(Context context)
292   {
293     // Return false since this is not the default action
294
return false;
295   }
296
297   private void refreshNavigator(Workspace ws, JProject enhydraProj)
298   {
299     NavigatorWindowImpl navWin = (NavigatorWindowImpl)
300             Ide.getNavigatorManager().getSystemNavigator();
301     navWin.show();
302     ExplorerNode eNode = (ExplorerNode)navWin.getTreeExplorer().getRoot();
303     eNode = (ExplorerNode)navWin.findTNode(ws, eNode);
304     navWin.refresh(eNode);
305     eNode = (ExplorerNode)navWin.findTNode(enhydraProj, eNode);
306     navWin.expand(eNode, true);
307     navWin.show();
308   }
309
310 }
Popular Tags