KickJava   Java API By Example, From Geeks To Geeks.

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


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.dialogs.MessageDialog;
17 import org.eclipse.jface.window.Window;
18 import org.eclipse.jface.wizard.WizardDialog;
19 import org.eclipse.swt.widgets.Shell;
20 import org.eclipse.ui.IWorkingSet;
21 import org.eclipse.ui.IWorkingSetManager;
22 import org.eclipse.ui.PlatformUI;
23 import org.eclipse.ui.actions.WorkingSetFilterActionGroup;
24 import org.eclipse.ui.dialogs.IWorkingSetEditWizard;
25 import org.eclipse.ui.internal.IWorkbenchHelpContextIds;
26 import org.eclipse.ui.internal.WorkbenchMessages;
27
28 /**
29  * Displays an IWorkingSetEditWizard for editing a working set.
30  *
31  * @since 2.1
32  */

33 public class EditWorkingSetAction extends Action {
34     private Shell shell;
35
36     private WorkingSetFilterActionGroup actionGroup;
37
38     /**
39      * Creates a new instance of the receiver.
40      *
41      * @param actionGroup the action group this action is created in
42      * @param shell the parent shell
43      */

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

61     public void run() {
62         IWorkingSetManager manager = PlatformUI.getWorkbench()
63                 .getWorkingSetManager();
64         IWorkingSet workingSet = actionGroup.getWorkingSet();
65
66         if (workingSet == null) {
67             setEnabled(false);
68             return;
69         }
70         IWorkingSetEditWizard wizard = manager
71                 .createWorkingSetEditWizard(workingSet);
72         if (wizard == null) {
73             String JavaDoc title = WorkbenchMessages.EditWorkingSetAction_error_nowizard_title;
74             String JavaDoc message = WorkbenchMessages.EditWorkingSetAction_error_nowizard_message;
75             MessageDialog.openError(shell, title, message);
76             return;
77         }
78         WizardDialog dialog = new WizardDialog(shell, wizard);
79         dialog.create();
80         if (dialog.open() == Window.OK) {
81             actionGroup.setWorkingSet(wizard.getSelection());
82         }
83     }
84 }
85
Popular Tags