1 11 package org.eclipse.jdt.internal.ui.actions; 12 13 import org.eclipse.core.resources.IResource; 14 import org.eclipse.core.runtime.IAdaptable; 15 16 import org.eclipse.jface.viewers.IStructuredSelection; 17 18 import org.eclipse.ui.IWorkbenchSite; 19 import org.eclipse.ui.PlatformUI; 20 import org.eclipse.ui.views.tasklist.TaskPropertiesDialog; 21 22 import org.eclipse.jdt.ui.actions.SelectionDispatchAction; 23 24 import org.eclipse.jdt.internal.ui.IJavaHelpContextIds; 25 26 public class AddTaskAction extends SelectionDispatchAction { 27 28 public AddTaskAction(IWorkbenchSite site) { 29 super(site); 30 setEnabled(false); 31 PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.ADD_TASK_ACTION); 32 } 33 34 public void selectionChanged(IStructuredSelection selection) { 35 setEnabled(getElement(selection) != null); 36 } 37 38 public void run(IStructuredSelection selection) { 39 IResource resource= getElement(selection); 40 if (resource == null) 41 return; 42 43 TaskPropertiesDialog dialog= new TaskPropertiesDialog(getShell()); 44 dialog.setResource(resource); 45 dialog.open(); 46 } 47 48 private IResource getElement(IStructuredSelection selection) { 49 if (selection.size() != 1) 50 return null; 51 52 Object element= selection.getFirstElement(); 53 if (!(element instanceof IAdaptable)) 54 return null; 55 return (IResource)((IAdaptable)element).getAdapter(IResource.class); 56 } 57 } 58 | Popular Tags |