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
9 * IBM Corporation - initial API and implementation
10 ******************************************************************************/
11 package net.sourceforge.phpdt.internal.ui.actions;
13 import net.sourceforge.phpdt.ui.actions.SelectionDispatchAction;
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;
21 public class AddTaskAction extends SelectionDispatchAction {
23 public AddTaskAction(IWorkbenchSite site) {
26 // WorkbenchHelp.setHelp(this, IJavaHelpContextIds.ADD_TASK_ACTION);
29 protected void selectionChanged(IStructuredSelection selection) {
30 setEnabled(getElement(selection) != null);
33 protected void run(IStructuredSelection selection) {
34 IResource resource = getElement(selection);
38 TaskPropertiesDialog dialog = new TaskPropertiesDialog(getShell());
39 dialog.setResource(resource);
43 private IResource getElement(IStructuredSelection selection) {
44 if (selection.size() != 1)
47 Object element = selection.getFirstElement();
48 if (!(element instanceof IAdaptable))
50 return (IResource) ((IAdaptable) element).getAdapter(IResource.class);