misc changes
[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 java.util.HashMap;
14 import java.util.Map;
15
16 import org.eclipse.jface.viewers.IStructuredSelection;
17 import org.eclipse.jface.dialogs.IDialogConstants;
18 import org.eclipse.jface.dialogs.InputDialog;
19
20 import org.eclipse.core.resources.IMarker;
21 import org.eclipse.core.resources.IResource;
22 import org.eclipse.core.runtime.CoreException;
23 import org.eclipse.core.runtime.IAdaptable;
24
25 import org.eclipse.ui.IWorkbenchSite;
26 import org.eclipse.ui.help.WorkbenchHelp;
27 import org.eclipse.ui.texteditor.MarkerUtilities;
28 import org.eclipse.ui.views.tasklist.TaskPropertiesDialog;
29
30 //import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
31 import net.sourceforge.phpdt.internal.ui.util.ExceptionHandler;
32
33 import net.sourceforge.phpdt.ui.actions.SelectionDispatchAction;
34
35 public class AddTaskAction extends SelectionDispatchAction {
36
37         public AddTaskAction(IWorkbenchSite site) {
38                 super(site);
39                 setEnabled(false);
40         //      WorkbenchHelp.setHelp(this, IJavaHelpContextIds.ADD_TASK_ACTION);
41         }
42
43         protected void selectionChanged(IStructuredSelection selection) {
44                 setEnabled(getElement(selection) != null);
45         }
46
47         protected void run(IStructuredSelection selection) {
48                 IResource resource= getElement(selection);
49                 if (resource == null)
50                         return;
51
52                 TaskPropertiesDialog dialog= new TaskPropertiesDialog(getShell());
53                 dialog.setResource(resource);
54                 dialog.open();
55         }
56         
57         private IResource getElement(IStructuredSelection selection) {
58                 if (selection.size() != 1)
59                         return null;
60
61                 Object element= selection.getFirstElement();
62                 if (!(element instanceof IAdaptable))
63                         return null;
64                 return (IResource)((IAdaptable)element).getAdapter(IResource.class);
65         }       
66 }