KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > actions > SelectWorkingSetAction


1 /*******************************************************************************
2  * Copyright (c) 2000, 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 Corporation - initial API and implementation
10  *******************************************************************************/

11
12 package org.eclipse.ui.internal.actions;
13
14 import org.eclipse.core.runtime.Assert;
15 import org.eclipse.jface.action.Action;
16 import org.eclipse.jface.window.Window;
17 import org.eclipse.swt.widgets.Shell;
18 import org.eclipse.ui.IWorkingSet;
19 import org.eclipse.ui.IWorkingSetManager;
20 import org.eclipse.ui.PlatformUI;
21 import org.eclipse.ui.actions.WorkingSetFilterActionGroup;
22 import org.eclipse.ui.dialogs.IWorkingSetSelectionDialog;
23 import org.eclipse.ui.internal.IWorkbenchHelpContextIds;
24 import org.eclipse.ui.internal.WorkbenchMessages;
25
26 /**
27  * Displays an IWorkingSetSelectionDialog and sets the selected
28  * working set in the action group.
29  *
30  * @since 2.1
31  */

32 public class SelectWorkingSetAction extends Action {
33     private Shell shell;
34
35     private WorkingSetFilterActionGroup actionGroup;
36
37     /**
38      * Creates a new instance of the receiver.
39      *
40      * @param actionGroup the action group this action is created in
41      * @param shell shell to use for opening working set selection dialog.
42      */

43     public SelectWorkingSetAction(WorkingSetFilterActionGroup actionGroup,
44             Shell shell) {
45         super(WorkbenchMessages.SelectWorkingSetAction_text);
46         Assert.isNotNull(actionGroup);
47         setToolTipText(WorkbenchMessages.SelectWorkingSetAction_toolTip);
48
49         this.shell = shell;
50         this.actionGroup = actionGroup;
51         PlatformUI.getWorkbench().getHelpSystem().setHelp(this,
52                 IWorkbenchHelpContextIds.SELECT_WORKING_SET_ACTION);
53     }
54
55     /**
56      * Overrides method from Action
57      *
58      * @see Action#run()
59      */

60     public void run() {
61         IWorkingSetManager manager = PlatformUI.getWorkbench()
62                 .getWorkingSetManager();
63         IWorkingSetSelectionDialog dialog = manager
64                 .createWorkingSetSelectionDialog(shell, false);
65         IWorkingSet workingSet = actionGroup.getWorkingSet();
66
67         if (workingSet != null) {
68             dialog.setSelection(new IWorkingSet[] { workingSet });
69         }
70
71         if (dialog.open() == Window.OK) {
72             IWorkingSet[] result = dialog.getSelection();
73             if (result != null && result.length > 0) {
74                 actionGroup.setWorkingSet(result[0]);
75                 manager.addRecentWorkingSet(result[0]);
76             } else {
77                 actionGroup.setWorkingSet(null);
78             }
79         } else {
80             actionGroup.setWorkingSet(workingSet);
81         }
82     }
83 }
84
Popular Tags