01: /*******************************************************************************
02: * Copyright (c) 2000, 2005 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.jdt.internal.ui.actions;
11:
12: import org.eclipse.core.resources.IResource;
13: import org.eclipse.core.runtime.IAdaptable;
14:
15: import org.eclipse.jface.viewers.IStructuredSelection;
16:
17: import org.eclipse.ui.IWorkbenchSite;
18: import org.eclipse.ui.PlatformUI;
19: import org.eclipse.ui.views.tasklist.TaskPropertiesDialog;
20:
21: import org.eclipse.jdt.ui.actions.SelectionDispatchAction;
22:
23: import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
24:
25: public class AddTaskAction extends SelectionDispatchAction {
26:
27: public AddTaskAction(IWorkbenchSite site) {
28: super (site);
29: setEnabled(false);
30: PlatformUI.getWorkbench().getHelpSystem().setHelp(this ,
31: 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(
44: getShell());
45: dialog.setResource(resource);
46: dialog.open();
47: }
48:
49: private IResource getElement(IStructuredSelection selection) {
50: if (selection.size() != 1)
51: return null;
52:
53: Object element = selection.getFirstElement();
54: if (!(element instanceof IAdaptable))
55: return null;
56: return (IResource) ((IAdaptable) element)
57: .getAdapter(IResource.class);
58: }
59: }
|