KickJava   Java API By Example, From Geeks To Geeks.

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


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.jface.action.Action;
14 import org.eclipse.ui.IWorkbenchWindow;
15 import org.eclipse.ui.IWorkingSet;
16 import org.eclipse.ui.IWorkingSetManager;
17 import org.eclipse.ui.actions.ActionFactory;
18 import org.eclipse.ui.application.IActionBarConfigurer;
19 import org.eclipse.ui.dialogs.IWorkingSetSelectionDialog;
20 import org.eclipse.ui.internal.ide.IDEWorkbenchMessages;
21
22 /**
23  * This action asks the user to select a working set, and then creates
24  * and runs a corresponding BuildSetAction.
25  *
26  * @since 3.0
27  */

28 public class SelectBuildWorkingSetAction extends Action implements
29         ActionFactory.IWorkbenchAction {
30     private IWorkbenchWindow window;
31
32     private IActionBarConfigurer actionBars;
33
34     public SelectBuildWorkingSetAction(IWorkbenchWindow window,
35             IActionBarConfigurer actionBars) {
36         super(IDEWorkbenchMessages.SelectWorkingSetAction_text);
37         this.window = window;
38         this.actionBars = actionBars;
39     }
40
41     private IWorkingSet queryForWorkingSet() {
42         IWorkingSetManager manager = window.getWorkbench()
43                 .getWorkingSetManager();
44         IWorkingSetSelectionDialog dialog = manager
45                 .createWorkingSetSelectionDialog(window.getShell(), false);
46         dialog.open();
47         IWorkingSet[] sets = dialog.getSelection();
48         //check for cancel
49
if (sets == null || sets.length == 0) {
50             return null;
51         }
52         return sets[0];
53     }
54
55     public void run() {
56         IWorkingSet set = queryForWorkingSet();
57         if (set != null) {
58             new BuildSetAction(set, window, actionBars).run();
59         }
60     }
61
62     public void dispose() {
63     }
64
65     public void setActionBars(IActionBarConfigurer actionBars) {
66         this.actionBars = actionBars;
67     }
68 }
69
Popular Tags