001: package org.enhydra.kelp.eclipse.actions;
002:
003: import java.io.File;
004: import org.eclipse.core.resources.IProject;
005: import org.eclipse.core.resources.IResource;
006: import org.eclipse.core.runtime.CoreException;
007: import org.eclipse.jface.action.IAction;
008: import org.eclipse.jface.viewers.ISelection;
009: import org.eclipse.ui.IWorkbenchWindow;
010: import org.eclipse.ui.IWorkbenchWindowActionDelegate;
011: import org.enhydra.kelp.ant.dods.KelpDODSGenerator;
012: import org.enhydra.kelp.ant.node.AntProject;
013: import org.eclipse.debug.ui.DebugUITools;
014: import org.eclipse.debug.internal.ui.DebugUIPlugin;
015: import org.eclipse.swt.widgets.Shell;
016:
017: /**
018: * Insert the type's description here.
019: * @see IWorkbenchWindowActionDelegate
020: */
021: public class DODSAction implements IWorkbenchWindowActionDelegate {
022: /**
023: * The constructor.
024: */
025: public DODSAction() {
026: }
027:
028: /**
029: * Insert the method's description here.
030: * @see IWorkbenchWindowActionDelegate#run
031: */
032: public void run(IAction action) {
033: IProject project = null;
034: String prjPath = null;
035:
036: IResource res = DebugUITools.getSelectedResource();
037: project = res.getProject();
038:
039: if (project != null) {
040: prjPath = project.getLocation().toString();
041:
042: try {
043: if (prjPath != null) {
044: AntProject antProject = new AntProject(prjPath);
045: String enhydraDir = antProject
046: .getProperty(AntProject.ENHYDRA_DIR);
047: File dodsDirFile = new File(enhydraDir, "dods");
048: System.setProperty("DODS_HOME", dodsDirFile
049: .getAbsolutePath());
050: KelpDODSGenerator.main(new String[] { prjPath });
051: }
052: } catch (Exception e) {
053: e.printStackTrace();
054: }
055: // Refresh project, so the generated files could be visible
056: try {
057: project.refreshLocal(IResource.DEPTH_INFINITE, null);
058: } catch (CoreException ce) {
059: DebugUIPlugin
060: .errorDialog(
061: getShell(),
062: "Error refreshing application project",
063: "Please, sellect valid application project before starting this action!",
064: ce);
065: }
066: } else
067: //System.err.println("Fail to start DODS Generator, no project is selected!");
068: DebugUIPlugin
069: .errorDialog(
070: getShell(),
071: "Error getting application project",
072: "Please, sellect valid application project before starting this action!",
073: new Exception("Project is null!"));
074:
075: }
076:
077: protected Shell getShell() {
078: return DebugUIPlugin.getShell();
079: }
080:
081: /**
082: * Insert the method's description here.
083: * @see IWorkbenchWindowActionDelegate#selectionChanged
084: */
085: public void selectionChanged(IAction action, ISelection selection) {
086: }
087:
088: /**
089: * Insert the method's description here.
090: * @see IWorkbenchWindowActionDelegate#dispose
091: */
092: public void dispose() {
093: }
094:
095: /**
096: * Insert the method's description here.
097: * @see IWorkbenchWindowActionDelegate#init
098: */
099: public void init(IWorkbenchWindow window) {
100: }
101: }
|