KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > actions > AddTaskAction


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 IBM Corporation 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  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

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 JavaDoc element= selection.getFirstElement();
53         if (!(element instanceof IAdaptable))
54             return null;
55         return (IResource)((IAdaptable)element).getAdapter(IResource.class);
56     }
57 }
58
Popular Tags