1 package org.enhydra.kelp.jdev; 2 import java.io.BufferedReader ; 3 import java.io.File ; 4 import java.io.InputStream ; 5 import java.io.InputStreamReader ; 6 7 import java.net.URL ; 8 9 import javax.swing.Icon ; 10 import javax.swing.ImageIcon ; 11 import javax.swing.JMenu ; 12 import javax.swing.JMenuItem ; 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 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 MENU_ICON = "/media/menu_16x16.gif"; 46 47 48 private JMenuItem menuItem = null; 49 public EnhydraTools() 50 { 51 } 52 53 public void initialize() 54 { 55 JMenu enhydraGroup = Ide.getMenubar().createSubMenu("Enhydra Tools", new Integer ('E')); 57 JMenuItem menuItemXMLC = createMenu_XMLC_CMD_ID(MENU_ICON, "XML Compiler", 88); JMenuItem menuItemDeployer = createMenu_DEPLOYER_CMD_ID(null, "Deployer", 68); JMenuItem menuItemDODS = createMenu_DODS_CMD_ID(MENU_ICON, "DODS", 79); enhydraGroup.add(menuItemXMLC); 61 enhydraGroup.add(menuItemDeployer); 62 enhydraGroup.add(menuItemDODS); 63 JMenu mainMenu = MainWindow.Tools; 64 mainMenu.add(enhydraGroup); 65 Ide.getNavigatorManager().addContextMenuListener(this, null); 66 } 67 68 public void shutdown() 69 { 70 } 72 73 public float version() 74 { 75 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 loadIcon(String iconName) 90 { 91 URL url = getClass().getResource(iconName); 92 Icon icon = null; 93 if (url != null) 94 { 95 icon = new ImageIcon (url); 96 } 97 return icon; 98 } 99 100 private JMenuItem createMenu_XMLC_CMD_ID(String iconName, String menuLabel, int mnemonic) 101 { 102 String cmdClass = null; 104 String category = null; 106 Icon icon = null; 108 if (iconName != null) 109 icon = loadIcon(iconName); 110 Object data = null; 112 boolean enabled = true; 114 115 IdeAction action; 116 action = IdeAction.get(XMLC_CMD_ID, cmdClass, menuLabel, category, new Integer (mnemonic), icon, data, enabled); 118 action.setController(this); 120 JMenuItem menuItem = Ide.getMenubar().createMenuItem(action); 122 123 return menuItem; 124 } 125 126 private JMenuItem createMenu_DEPLOYER_CMD_ID(String iconName, String menuLabel, int mnemonic) 127 { 128 String cmdClass = null; 130 String category = null; 132 Icon icon = null; 134 if (iconName != null) 135 icon = loadIcon(iconName); 136 Object data = null; 138 boolean enabled = true; 140 141 IdeAction action; 142 action = IdeAction.get(DEPLOYER_CMD_ID, cmdClass, menuLabel, category, new Integer (mnemonic), icon, data, enabled); 144 action.setController(this); 146 JMenuItem menuItem = Ide.getMenubar().createMenuItem(action); 148 149 return menuItem; 150 } 151 152 private JMenuItem createMenu_DODS_CMD_ID(String iconName, String menuLabel, int mnemonic) 153 { 154 String cmdClass = null; 156 String category = null; 158 Icon icon = null; 160 if (iconName != null) 161 icon = loadIcon(iconName); 162 Object data = null; 164 boolean enabled = true; 166 167 IdeAction action; 168 action = IdeAction.get(DODS_CMD_ID, cmdClass, menuLabel, category, new Integer (mnemonic), icon, data, enabled); 170 action.setController(this); 172 JMenuItem 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 prjPath = Ide.getActiveWorkspace().getActiveProjectURL().getFile(); 187 if (prjPath.charAt(0) == '/'){ 189 prjPath=prjPath.substring(1); 190 } 191 prjPath = prjPath.substring(0, prjPath.lastIndexOf("/")); 193 boolean refresh = false; 194 if (cmdId == XMLC_CMD_ID) 195 { 196 AntXMLCTool.main(new String []{prjPath}); 197 refresh = true; 198 } 199 else if (cmdId == DEPLOYER_CMD_ID) 200 { 201 AntDeployTool.main(new String []{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 enhydraDir = antProject.getProperty(AntProject.ENHYDRA_DIR); 210 System.out.println("enhydraDir="+enhydraDir); 211 File dodsDirFile = new File (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 []{prjPath}); 217 System.out.println("3-dodsDirFile="+dodsDirFile.getPath()); 218 refresh = true; 219 } catch (Exception 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 } 271 272 private JMenuItem 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 popup.add(getContextMenuItem()); 285 } 286 287 public void poppingDown(ContextMenu popup) 288 { 289 } 290 291 public boolean handleDefaultAction(Context context) 292 { 293 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 |