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.dialogs.MessageDialog;
15: import org.eclipse.jface.window.Window;
16: import org.eclipse.jface.wizard.WizardDialog;
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.IWorkingSetEditWizard;
23: import org.eclipse.ui.internal.IWorkbenchHelpContextIds;
24: import org.eclipse.ui.internal.WorkbenchMessages;
25:
26: /**
27: * Displays an IWorkingSetEditWizard for editing a working set.
28: *
29: * @since 2.1
30: */
31: public class EditWorkingSetAction extends Action {
32: private Shell shell;
33:
34: private WorkingSetFilterActionGroup actionGroup;
35:
36: /**
37: * Creates a new instance of the receiver.
38: *
39: * @param actionGroup the action group this action is created in
40: * @param shell the parent shell
41: */
42: public EditWorkingSetAction(
43: WorkingSetFilterActionGroup actionGroup, Shell shell) {
44: super (WorkbenchMessages.EditWorkingSetAction_text);
45: Assert.isNotNull(actionGroup);
46: setToolTipText(WorkbenchMessages.EditWorkingSetAction_toolTip);
47:
48: this .shell = shell;
49: this .actionGroup = actionGroup;
50: PlatformUI.getWorkbench().getHelpSystem().setHelp(this ,
51: IWorkbenchHelpContextIds.EDIT_WORKING_SET_ACTION);
52: }
53:
54: /**
55: * Overrides method from Action
56: *
57: * @see Action#run
58: */
59: public void run() {
60: IWorkingSetManager manager = PlatformUI.getWorkbench()
61: .getWorkingSetManager();
62: IWorkingSet workingSet = actionGroup.getWorkingSet();
63:
64: if (workingSet == null) {
65: setEnabled(false);
66: return;
67: }
68: IWorkingSetEditWizard wizard = manager
69: .createWorkingSetEditWizard(workingSet);
70: if (wizard == null) {
71: String title = WorkbenchMessages.EditWorkingSetAction_error_nowizard_title;
72: String message = WorkbenchMessages.EditWorkingSetAction_error_nowizard_message;
73: MessageDialog.openError(shell, title, message);
74: return;
75: }
76: WizardDialog dialog = new WizardDialog(shell, wizard);
77: dialog.create();
78: if (dialog.open() == Window.OK) {
79: actionGroup.setWorkingSet(wizard.getSelection());
80: }
81: }
82: }
|