DeployAction.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 » DeployAction.java
package org.enhydra.kelp.eclipse.actions;

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.deployer.AntDeployTool;
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 DeployAction implements IWorkbenchWindowActionDelegate {
  /**
   * The constructor.
   */
  public DeployAction() {
  }

  /**
   * 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();
    
      AntDeployTool.main(new String[]{prjPath});
      // 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 Deployer, 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.