KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > ide > actions > BuildSetAction


1 /*******************************************************************************
2  * Copyright (c) 2004, 2006 IBM Corporation 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  * IBM - Initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.ui.internal.ide.actions;
12
13 import org.eclipse.core.resources.IProject;
14 import org.eclipse.core.resources.IncrementalProjectBuilder;
15 import org.eclipse.jface.action.Action;
16 import org.eclipse.jface.dialogs.MessageDialog;
17 import org.eclipse.jface.viewers.StructuredSelection;
18 import org.eclipse.swt.widgets.Event;
19 import org.eclipse.swt.widgets.MenuItem;
20 import org.eclipse.ui.IWorkbenchWindow;
21 import org.eclipse.ui.IWorkingSet;
22 import org.eclipse.ui.actions.BuildAction;
23 import org.eclipse.ui.application.IActionBarConfigurer;
24 import org.eclipse.ui.internal.ide.IDEWorkbenchMessages;
25
26 /**
27  * This class will perform an incremental build on a working set.
28  *
29  * @since 3.0
30  */

31 public class BuildSetAction extends Action {
32     public static BuildSetAction lastBuilt;
33
34     private IWorkingSet workingSet;
35
36     private IWorkbenchWindow window;
37
38     private IActionBarConfigurer actionBars;
39
40     /**
41      * Creates a new action that builds the provided working set when run
42      */

43     public BuildSetAction(IWorkingSet set, IWorkbenchWindow window, 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().addRecentWorkingSet(workingSet);
63         IProject[] projects = BuildUtilities.extractProjects(workingSet.getElements());
64         if (projects.length == 0) {
65             MessageDialog.openInformation(window.getShell(),
66                     IDEWorkbenchMessages.BuildSetAction_noBuildTitle,
67                     IDEWorkbenchMessages.BuildSetAction_noProjects);
68             return;
69         }
70         lastBuilt = this;
71         BuildAction build = new BuildAction(window.getShell(), IncrementalProjectBuilder.INCREMENTAL_BUILD);
72         build.selectionChanged(new StructuredSelection(projects));
73         build.run();
74     }
75
76     public void runWithEvent(Event event) {
77         //radio buttons receive an event when they become unselected,
78
//so we must not run the action in this case
79
if (event.widget instanceof MenuItem) {
80             if (!((MenuItem) event.widget).getSelection()) {
81                 return;
82             }
83         }
84         run();
85     }
86
87     /* (non-Javadoc)
88      * For debugging purposes only.
89      */

90     public String JavaDoc toString() {
91         return "BuildSetAction(" + workingSet.getName() + ")"; //$NON-NLS-1$ //$NON-NLS-2$
92
}
93 }
94
Popular Tags