KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > workingsets > 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 package org.eclipse.jdt.internal.ui.workingsets;
12
13 import org.eclipse.core.runtime.Assert;
14
15 import org.eclipse.swt.widgets.Shell;
16
17 import org.eclipse.jface.action.Action;
18 import org.eclipse.jface.dialogs.MessageDialog;
19 import org.eclipse.jface.window.Window;
20 import org.eclipse.jface.wizard.WizardDialog;
21
22 import org.eclipse.ui.IWorkbenchPartSite;
23 import org.eclipse.ui.IWorkingSet;
24 import org.eclipse.ui.IWorkingSetManager;
25 import org.eclipse.ui.PlatformUI;
26 import org.eclipse.ui.dialogs.IWorkingSetEditWizard;
27
28 import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
29 import org.eclipse.jdt.internal.ui.JavaPlugin;
30
31 /**
32  * Displays an IWorkingSetEditWizard for editing a working set.
33  *
34  * @since 2.1
35  */

36 public class EditWorkingSetAction extends Action {
37     private IWorkbenchPartSite fSite;
38     private Shell fShell;
39     private WorkingSetFilterActionGroup fActionGroup;
40
41     public EditWorkingSetAction(WorkingSetFilterActionGroup actionGroup, IWorkbenchPartSite site) {
42         this(actionGroup);
43         fSite= site;
44     }
45     
46     public EditWorkingSetAction(WorkingSetFilterActionGroup actionGroup, Shell shell) {
47         this(actionGroup);
48         fShell= shell;
49     }
50     
51     private EditWorkingSetAction(WorkingSetFilterActionGroup actionGroup) {
52         super(WorkingSetMessages.EditWorkingSetAction_text);
53         Assert.isNotNull(actionGroup);
54         setToolTipText(WorkingSetMessages.EditWorkingSetAction_toolTip);
55         setEnabled(actionGroup.getWorkingSet() != null);
56         fActionGroup= actionGroup;
57         PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.EDIT_WORKING_SET_ACTION);
58     }
59     
60     /*
61      * Overrides method from Action
62      */

63     public void run() {
64         Shell shell= getShell();
65         IWorkingSetManager manager= PlatformUI.getWorkbench().getWorkingSetManager();
66         IWorkingSet workingSet= fActionGroup.getWorkingSet();
67         if (workingSet == null || workingSet.isAggregateWorkingSet()) {
68             setEnabled(false);
69             return;
70         }
71         IWorkingSetEditWizard wizard= manager.createWorkingSetEditWizard(workingSet);
72         if (wizard == null) {
73             String JavaDoc title= WorkingSetMessages.EditWorkingSetAction_error_nowizard_title;
74             String JavaDoc message= WorkingSetMessages.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             fActionGroup.setWorkingSet(wizard.getSelection(), true);
82     }
83     
84     private Shell getShell() {
85         if (fSite != null) {
86             return fSite.getShell();
87         } else if (fShell != null) {
88             return fShell;
89         } else {
90             return JavaPlugin.getActiveWorkbenchShell();
91         }
92     }
93 }
94
Popular Tags