|
Added
Link Here
|
| 1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2010 Markus Knittig and others. |
| 3 |
* All rights reserved. This program and the accompanying materials |
| 4 |
* are made available under the terms of the Eclipse Public License v1.0 |
| 5 |
* which accompanies this distribution, and is available at |
| 6 |
* http://www.eclipse.org/legal/epl-v10.html |
| 7 |
* |
| 8 |
* Contributors: |
| 9 |
* Markus Knittig - initial API and implementation |
| 10 |
*******************************************************************************/ |
| 11 |
|
| 12 |
package org.eclipse.mylyn.internal.builds.ui.view; |
| 13 |
|
| 14 |
import org.eclipse.core.runtime.CoreException; |
| 15 |
import org.eclipse.core.runtime.IProgressMonitor; |
| 16 |
import org.eclipse.core.runtime.IStatus; |
| 17 |
import org.eclipse.core.runtime.NullProgressMonitor; |
| 18 |
import org.eclipse.core.runtime.OperationCanceledException; |
| 19 |
import org.eclipse.core.runtime.Status; |
| 20 |
import org.eclipse.core.runtime.jobs.Job; |
| 21 |
import org.eclipse.jface.viewers.IStructuredSelection; |
| 22 |
import org.eclipse.mylyn.builds.core.IBuildPlan; |
| 23 |
import org.eclipse.mylyn.builds.core.util.ProgressUtil; |
| 24 |
import org.eclipse.mylyn.internal.builds.core.BuildsCorePlugin; |
| 25 |
import org.eclipse.mylyn.internal.builds.ui.BuildImages; |
| 26 |
import org.eclipse.osgi.util.NLS; |
| 27 |
import org.eclipse.ui.actions.BaseSelectionListenerAction; |
| 28 |
|
| 29 |
/** |
| 30 |
* @author Markus Knittig |
| 31 |
*/ |
| 32 |
public class RunBuildAction extends BaseSelectionListenerAction { |
| 33 |
|
| 34 |
protected RunBuildAction() { |
| 35 |
super("Run Build"); |
| 36 |
setToolTipText("Run Build"); |
| 37 |
setImageDescriptor(BuildImages.RUN); |
| 38 |
setDisabledImageDescriptor(BuildImages.RUN_DISABLED); |
| 39 |
} |
| 40 |
|
| 41 |
@Override |
| 42 |
protected boolean updateSelection(IStructuredSelection selection) { |
| 43 |
return (selection.getFirstElement() instanceof IBuildPlan); |
| 44 |
} |
| 45 |
|
| 46 |
@Override |
| 47 |
public void run() { |
| 48 |
|
| 49 |
IStructuredSelection selection = getStructuredSelection(); |
| 50 |
for (Object object : selection.toList()) { |
| 51 |
if (object instanceof IBuildPlan) { |
| 52 |
final IBuildPlan plan = (IBuildPlan) object; |
| 53 |
new Job("Running build...") { |
| 54 |
@Override |
| 55 |
protected IStatus run(IProgressMonitor monitor) { |
| 56 |
try { |
| 57 |
return plan.run(ProgressUtil.convert(monitor)); |
| 58 |
} catch (CoreException e) { |
| 59 |
return new Status(IStatus.ERROR, BuildsCorePlugin.ID_PLUGIN, NLS.bind( |
| 60 |
"Run of build ''{0}'' failed", plan.getName(), e)); |
| 61 |
} catch (OperationCanceledException e) { |
| 62 |
return Status.CANCEL_STATUS; |
| 63 |
} |
| 64 |
} |
| 65 |
}.run(new NullProgressMonitor()); |
| 66 |
} |
| 67 |
} |
| 68 |
} |
| 69 |
} |