Using standard dialog org.eclipse.ui.dialogs.ElementListSelectionDialog instead of...
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / ui / actions / AddTaskAction.java
1 /*******************************************************************************
2  * Copyright (c) 2002 International Business Machines Corp. and others.
3  * All rights reserved. This program and the accompanying materials 
4  * are made available under the terms of the Common Public License v0.5 
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v05.html
7  * 
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  ******************************************************************************/
11 package net.sourceforge.phpdt.internal.ui.actions;
12
13 import net.sourceforge.phpdt.ui.actions.SelectionDispatchAction;
14
15 import org.eclipse.core.resources.IResource;
16 import org.eclipse.core.runtime.IAdaptable;
17 import org.eclipse.jface.viewers.IStructuredSelection;
18 import org.eclipse.ui.IWorkbenchSite;
19 import org.eclipse.ui.views.tasklist.TaskPropertiesDialog;
20
21 public class AddTaskAction extends SelectionDispatchAction {
22
23         public AddTaskAction(IWorkbenchSite site) {
24                 super(site);
25                 setEnabled(false);
26                 // WorkbenchHelp.setHelp(this, IJavaHelpContextIds.ADD_TASK_ACTION);
27         }
28
29         protected void selectionChanged(IStructuredSelection selection) {
30                 setEnabled(getElement(selection) != null);
31         }
32
33         protected void run(IStructuredSelection selection) {
34                 IResource resource = getElement(selection);
35                 if (resource == null)
36                         return;
37
38                 TaskPropertiesDialog dialog = new TaskPropertiesDialog(getShell());
39                 dialog.setResource(resource);
40                 dialog.open();
41         }
42
43         private IResource getElement(IStructuredSelection selection) {
44                 if (selection.size() != 1)
45                         return null;
46
47                 Object element = selection.getFirstElement();
48                 if (!(element instanceof IAdaptable))
49                         return null;
50                 return (IResource) ((IAdaptable) element).getAdapter(IResource.class);
51         }
52 }