01: /*******************************************************************************
02: * Copyright (c) 2000, 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 Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.ui.internal.actions;
11:
12: import org.eclipse.core.runtime.Assert;
13: import org.eclipse.jface.action.Action;
14: import org.eclipse.jface.window.Window;
15: import org.eclipse.swt.widgets.Shell;
16: import org.eclipse.ui.IWorkingSet;
17: import org.eclipse.ui.IWorkingSetManager;
18: import org.eclipse.ui.PlatformUI;
19: import org.eclipse.ui.actions.WorkingSetFilterActionGroup;
20: import org.eclipse.ui.dialogs.IWorkingSetSelectionDialog;
21: import org.eclipse.ui.internal.IWorkbenchHelpContextIds;
22: import org.eclipse.ui.internal.WorkbenchMessages;
23:
24: /**
25: * Displays an IWorkingSetSelectionDialog and sets the selected
26: * working set in the action group.
27: *
28: * @since 2.1
29: */
30: public class SelectWorkingSetAction extends Action {
31: private Shell shell;
32:
33: private WorkingSetFilterActionGroup actionGroup;
34:
35: /**
36: * Creates a new instance of the receiver.
37: *
38: * @param actionGroup the action group this action is created in
39: * @param shell shell to use for opening working set selection dialog.
40: */
41: public SelectWorkingSetAction(
42: WorkingSetFilterActionGroup actionGroup, Shell shell) {
43: super (WorkbenchMessages.SelectWorkingSetAction_text);
44: Assert.isNotNull(actionGroup);
45: setToolTipText(WorkbenchMessages.SelectWorkingSetAction_toolTip);
46:
47: this .shell = shell;
48: this .actionGroup = actionGroup;
49: PlatformUI.getWorkbench().getHelpSystem().setHelp(this ,
50: IWorkbenchHelpContextIds.SELECT_WORKING_SET_ACTION);
51: }
52:
53: /**
54: * Overrides method from Action
55: *
56: * @see Action#run()
57: */
58: public void run() {
59: IWorkingSetManager manager = PlatformUI.getWorkbench()
60: .getWorkingSetManager();
61: IWorkingSetSelectionDialog dialog = manager
62: .createWorkingSetSelectionDialog(shell, false);
63: IWorkingSet workingSet = actionGroup.getWorkingSet();
64:
65: if (workingSet != null) {
66: dialog.setSelection(new IWorkingSet[] { workingSet });
67: }
68:
69: if (dialog.open() == Window.OK) {
70: IWorkingSet[] result = dialog.getSelection();
71: if (result != null && result.length > 0) {
72: actionGroup.setWorkingSet(result[0]);
73: manager.addRecentWorkingSet(result[0]);
74: } else {
75: actionGroup.setWorkingSet(null);
76: }
77: } else {
78: actionGroup.setWorkingSet(workingSet);
79: }
80: }
81: }
|