Package tool.action

Source Code of tool.action.RunFromToolRepository

package tool.action;

import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IWorkbenchPart;

import tool.ToolPlugin;
import tool.ToolProjectSupport;
import tool.repository.LocalRun;

public class RunFromToolRepository  extends Action implements IObjectActionDelegate{
  private ISelection selection;
  private IAction action;
  private IWorkbenchPart part;
  @Override
  public void run(IAction action) {
    if (selection == null)
      return;
    IStructuredSelection sSelection = (IStructuredSelection) selection;
    if(sSelection.size() == 1 &&
        sSelection.getFirstElement() instanceof IFolder) {
      IFolder planFolder = (IFolder)sSelection.getFirstElement();
      if (ToolProjectSupport.isPlanFolder(planFolder)){
        try {
          LocalRun runner = new LocalRun(planFolder.getName(), planFolder.getProject(), false);
          IWorkspace workspace = ResourcesPlugin.getWorkspace();
          workspace.run(runner, planFolder.getProject(), IWorkspace.AVOID_UPDATE, null);//TODO add a progress monitor
        } catch (CoreException e) {
          ToolPlugin.showError("Error running plan: " + planFolder.getName(), e);
        }
      }
    }
  }

  @Override
  public void selectionChanged(IAction action, ISelection selection) {
    this.selection = selection;
    this.action = action;
   
  }

  @Override
  public void setActivePart(IAction action, IWorkbenchPart part) {
    this.action = action;
    this.part = part;
  }

}
TOP

Related Classes of tool.action.RunFromToolRepository

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.