DODSAction.java :  » J2EE » enhydra-IDE-plugin » org » enhydra » kelp » eclipse » actions » Java Open Source

Java Open Source » J2EE » enhydra IDE plugin 
enhydra IDE plugin » org » enhydra » kelp » eclipse » actions » DODSAction.java
package org.enhydra.kelp.eclipse.actions;

import java.io.File;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.IWorkbenchWindowActionDelegate;
import org.enhydra.kelp.ant.dods.KelpDODSGenerator;
import org.enhydra.kelp.ant.node.AntProject;
import org.eclipse.debug.ui.DebugUITools;
import org.eclipse.debug.internal.ui.DebugUIPlugin;
import org.eclipse.swt.widgets.Shell;

/**
 * Insert the type's description here.
 * @see IWorkbenchWindowActionDelegate
 */
public class DODSAction implements IWorkbenchWindowActionDelegate {
  /**
   * The constructor.
   */
  public DODSAction() {
  }

  /**
   * Insert the method's description here.
   * @see IWorkbenchWindowActionDelegate#run
   */
  public void run(IAction action)  {
    IProject project = null;
    String prjPath = null;

    IResource res = DebugUITools.getSelectedResource();
    project = res.getProject();
    
    if (project != null) {
      prjPath = project.getLocation().toString();
    
      try{
        if(prjPath!=null){
          AntProject antProject = new AntProject(prjPath);
                  String enhydraDir = antProject.getProperty(AntProject.ENHYDRA_DIR);
                  File dodsDirFile = new File(enhydraDir,"dods");
                  System.setProperty("DODS_HOME", dodsDirFile.getAbsolutePath());
                   KelpDODSGenerator.main(new String[]{prjPath});
        }    
      }catch(Exception e){
        e.printStackTrace();
      }
      // Refresh project, so the generated files could be visible  
      try {
        project.refreshLocal(IResource.DEPTH_INFINITE, null);        
      } catch (CoreException ce) {
          DebugUIPlugin.errorDialog(getShell(), "Error refreshing application project", "Please, sellect valid application project before starting this action!", ce);
      }
    }else  
      //System.err.println("Fail to start DODS Generator, no project is selected!");
        DebugUIPlugin.errorDialog(getShell(), "Error getting application project", "Please, sellect valid application project before starting this action!", new Exception("Project is null!"));

  }
  
  protected Shell getShell() {
    return DebugUIPlugin.getShell();
  }

  /**
   * Insert the method's description here.
   * @see IWorkbenchWindowActionDelegate#selectionChanged
   */
  public void selectionChanged(IAction action, ISelection selection)  {
  }

  /**
   * Insert the method's description here.
   * @see IWorkbenchWindowActionDelegate#dispose
   */
  public void dispose()  {
  }

  /**
   * Insert the method's description here.
   * @see IWorkbenchWindowActionDelegate#init
   */
  public void init(IWorkbenchWindow window)  {
  }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.