upload tizen1.0 source
[sdk/ide/product.git] / org.eclipse.cdt.ui / src / org / eclipse / cdt / ui / actions / WorkingSetConfigAction.java
1 /*******************************************************************************
2  * Copyright (c) 2008, 2009 Intel Corporation, QNX Software Systems, 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  *     Intel Corporation - initial API and implementation
10  *     QNX Software Systems - [272416] Rework the config sets dialog 
11  *******************************************************************************/
12 package org.eclipse.cdt.ui.actions;
13
14 import org.eclipse.jface.action.IAction;
15 import org.eclipse.jface.util.IPropertyChangeListener;
16 import org.eclipse.jface.util.PropertyChangeEvent;
17 import org.eclipse.jface.viewers.ISelection;
18 import org.eclipse.ui.IWorkbenchWindow;
19 import org.eclipse.ui.IWorkbenchWindowActionDelegate;
20 import org.eclipse.ui.IWorkingSet;
21 import org.eclipse.ui.IWorkingSetManager;
22
23 import org.eclipse.cdt.ui.CUIPlugin;
24
25 import org.eclipse.cdt.internal.ui.workingsets.WorkingSetConfigurationDialog;
26
27 /**
28  */
29 public class WorkingSetConfigAction implements IWorkbenchWindowActionDelegate, IPropertyChangeListener {
30         private static final IWorkingSetManager wsm = CUIPlugin.getDefault().getWorkbench().getWorkingSetManager();  
31         private boolean enabled = true;
32         
33         private IWorkbenchWindow window;
34         
35         public void run(IAction action) {
36                 new WorkingSetConfigurationDialog(window.getShell()).open();
37         }
38         
39         public void selectionChanged(IAction action, ISelection selection) {
40                 checkWS();
41                 if (action.isEnabled() != enabled)
42                         action.setEnabled(enabled);
43         }
44         public void dispose() {
45                 wsm.removePropertyChangeListener(this);
46                 
47         }
48         public void init(IWorkbenchWindow window) {
49                 this.window = window;
50                 wsm.addPropertyChangeListener(this);
51                 checkWS();
52         }
53         
54         private IWorkingSet[] checkWS() {
55                 IWorkingSet[] w = wsm.getWorkingSets();
56                 if (w == null)
57                         w = new IWorkingSet[0]; 
58                 enabled = w.length > 0;
59                 return w;
60         }
61
62         public void propertyChange(PropertyChangeEvent event) {
63                 checkWS();
64         }
65 }