KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > workingsets > OpenPropertiesWorkingSetAction


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 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.jface.viewers.IStructuredSelection;
14 import org.eclipse.jface.wizard.WizardDialog;
15
16 import org.eclipse.ui.IWorkbenchSite;
17 import org.eclipse.ui.IWorkingSet;
18 import org.eclipse.ui.PlatformUI;
19 import org.eclipse.ui.dialogs.IWorkingSetEditWizard;
20
21 import org.eclipse.jdt.ui.actions.SelectionDispatchAction;
22
23
24 public class OpenPropertiesWorkingSetAction extends SelectionDispatchAction {
25
26     public OpenPropertiesWorkingSetAction(IWorkbenchSite site) {
27         super(site);
28         setText(WorkingSetMessages.OpenPropertiesWorkingSetAction_label);
29         setEnabled(false);
30     }
31     
32     public void selectionChanged(IStructuredSelection selection) {
33         setEnabled(getWorkingSet(selection) != null);
34     }
35
36     private IWorkingSet getWorkingSet(IStructuredSelection selection) {
37         if (selection.size() != 1)
38             return null;
39         Object JavaDoc element= selection.getFirstElement();
40         if (!(element instanceof IWorkingSet))
41             return null;
42         IWorkingSet ws= (IWorkingSet)element;
43         if (!ws.isEditable())
44             return null;
45         return ws;
46     }
47     
48     public void run(IStructuredSelection selection) {
49         IWorkingSet ws= getWorkingSet(selection);
50         if (ws == null)
51             return;
52         IWorkingSetEditWizard wizard= PlatformUI.getWorkbench().
53             getWorkingSetManager().createWorkingSetEditWizard(ws);
54         WizardDialog dialog= new WizardDialog(getShell(), wizard);
55         dialog.open();
56     }
57 }
58
Popular Tags