KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > workingsets > 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 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.window.Window;
19
20 import org.eclipse.ui.IWorkbenchPartSite;
21 import org.eclipse.ui.IWorkingSet;
22 import org.eclipse.ui.IWorkingSetManager;
23 import org.eclipse.ui.PlatformUI;
24 import org.eclipse.ui.dialogs.IWorkingSetSelectionDialog;
25
26 import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
27 import org.eclipse.jdt.internal.ui.JavaPlugin;
28
29 /**
30  * Displays an IWorkingSetSelectionDialog and sets the selected
31  * working set in the action group's view.
32  *
33  * @since 2.0
34  */

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

61     public void run() {
62         Shell shell= getShell();
63         IWorkingSetManager manager= PlatformUI.getWorkbench().getWorkingSetManager();
64         IWorkingSetSelectionDialog dialog= manager.createWorkingSetSelectionDialog(shell, false);
65         IWorkingSet workingSet= fActionGroup.getWorkingSet();
66         if (workingSet != null)
67             dialog.setSelection(new IWorkingSet[]{workingSet});
68
69         if (dialog.open() == Window.OK) {
70             IWorkingSet[] result= dialog.getSelection();
71             if (result != null && result.length > 0) {
72                 fActionGroup.setWorkingSet(result[0], true);
73                 manager.addRecentWorkingSet(result[0]);
74             }
75             else
76                 fActionGroup.setWorkingSet(null, true);
77         }
78     }
79     
80     private Shell getShell() {
81         if (fSite != null) {
82             return fSite.getShell();
83         } else if (fShell != null) {
84             return fShell;
85         } else {
86             return JavaPlugin.getActiveWorkbenchShell();
87         }
88     }
89 }
90
Popular Tags