package tool.commands.checkout;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ITreeSelection;
import org.eclipse.ui.ISelectionService;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.handlers.HandlerUtil;
public class CheckoutHandler extends AbstractHandler {
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
ISelectionService selectionService = window.getSelectionService();
ISelection selection = selectionService.getSelection();
if (selection instanceof ITreeSelection && (((ITreeSelection) selection).getFirstElement() instanceof IFile)){
ITreeSelection treeSelection = (ITreeSelection)selection;
IFile comp = (IFile) treeSelection.getFirstElement();
CheckoutJob runner = new CheckoutJob(comp);
runner.setPriority(Job.INTERACTIVE);
runner.schedule();
}
return null;
}
}