01: /*******************************************************************************
02: * Copyright (c) 2004, 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM - Initial API and implementation
10: *******************************************************************************/package org.eclipse.ui.internal.ide.actions;
11:
12: import org.eclipse.core.resources.IProject;
13: import org.eclipse.core.resources.IncrementalProjectBuilder;
14: import org.eclipse.jface.action.Action;
15: import org.eclipse.jface.dialogs.MessageDialog;
16: import org.eclipse.jface.viewers.StructuredSelection;
17: import org.eclipse.swt.widgets.Event;
18: import org.eclipse.swt.widgets.MenuItem;
19: import org.eclipse.ui.IWorkbenchWindow;
20: import org.eclipse.ui.IWorkingSet;
21: import org.eclipse.ui.actions.BuildAction;
22: import org.eclipse.ui.application.IActionBarConfigurer;
23: import org.eclipse.ui.internal.ide.IDEWorkbenchMessages;
24:
25: /**
26: * This class will perform an incremental build on a working set.
27: *
28: * @since 3.0
29: */
30: public class BuildSetAction extends Action {
31: public static BuildSetAction lastBuilt;
32:
33: private IWorkingSet workingSet;
34:
35: private IWorkbenchWindow window;
36:
37: private IActionBarConfigurer actionBars;
38:
39: /**
40: * Creates a new action that builds the provided working set when run
41: */
42: public BuildSetAction(IWorkingSet set, IWorkbenchWindow window,
43: IActionBarConfigurer actionBars) {
44: super (set == null ? "" : set.getLabel(), AS_RADIO_BUTTON); //$NON-NLS-1$
45: this .window = window;
46: this .actionBars = actionBars;
47: this .workingSet = set;
48: }
49:
50: /**
51: * Returns the working set that this instance is building
52: */
53: public IWorkingSet getWorkingSet() {
54: return workingSet;
55: }
56:
57: public void run() {
58: //register this action instance as the global handler for the build last action
59: setActionDefinitionId("org.eclipse.ui.project.buildLast"); //$NON-NLS-1$
60: actionBars.registerGlobalAction(this );
61:
62: window.getWorkbench().getWorkingSetManager()
63: .addRecentWorkingSet(workingSet);
64: IProject[] projects = BuildUtilities.extractProjects(workingSet
65: .getElements());
66: if (projects.length == 0) {
67: MessageDialog.openInformation(window.getShell(),
68: IDEWorkbenchMessages.BuildSetAction_noBuildTitle,
69: IDEWorkbenchMessages.BuildSetAction_noProjects);
70: return;
71: }
72: lastBuilt = this ;
73: BuildAction build = new BuildAction(window.getShell(),
74: IncrementalProjectBuilder.INCREMENTAL_BUILD);
75: build.selectionChanged(new StructuredSelection(projects));
76: build.run();
77: }
78:
79: public void runWithEvent(Event event) {
80: //radio buttons receive an event when they become unselected,
81: //so we must not run the action in this case
82: if (event.widget instanceof MenuItem) {
83: if (!((MenuItem) event.widget).getSelection()) {
84: return;
85: }
86: }
87: run();
88: }
89:
90: /* (non-Javadoc)
91: * For debugging purposes only.
92: */
93: public String toString() {
94: return "BuildSetAction(" + workingSet.getName() + ")"; //$NON-NLS-1$ //$NON-NLS-2$
95: }
96: }
|