KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > navigator > resources > actions > WorkManagementActionProvider


1 /*******************************************************************************
2  * Copyright (c) 2005, 2006 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.ui.internal.navigator.resources.actions;
12
13 import org.eclipse.jface.viewers.IStructuredSelection;
14 import org.eclipse.jface.viewers.StructuredSelection;
15 import org.eclipse.swt.widgets.Shell;
16 import org.eclipse.ui.IActionBars;
17 import org.eclipse.ui.actions.ActionContext;
18 import org.eclipse.ui.actions.AddBookmarkAction;
19 import org.eclipse.ui.actions.AddTaskAction;
20 import org.eclipse.ui.ide.IDEActionFactory;
21 import org.eclipse.ui.navigator.CommonActionProvider;
22 import org.eclipse.ui.navigator.ICommonActionExtensionSite;
23
24 /**
25  * Supports Add Task and Add Bookmark actions.
26  *
27  * @since 3.2
28  *
29  */

30 public class WorkManagementActionProvider extends CommonActionProvider {
31
32     private AddTaskAction addTaskAction;
33
34     private AddBookmarkAction addBookmarkAction;
35
36     public void init(ICommonActionExtensionSite aSite) {
37         Shell shell = aSite.getViewSite().getShell();
38         addBookmarkAction = new AddBookmarkAction(shell);
39         addTaskAction = new AddTaskAction(shell);
40     }
41
42     /*
43      * (non-Javadoc)
44      *
45      * @see org.eclipse.ui.actions.ActionGroup#fillActionBars(org.eclipse.ui.IActionBars)
46      */

47     public void fillActionBars(IActionBars actionBars) {
48         super.fillActionBars(actionBars);
49         actionBars.setGlobalActionHandler(IDEActionFactory.BOOKMARK.getId(),
50                 addBookmarkAction);
51         actionBars.setGlobalActionHandler(IDEActionFactory.ADD_TASK.getId(),
52                 addTaskAction);
53     }
54
55     /*
56      * (non-Javadoc)
57      *
58      * @see org.eclipse.ui.actions.ActionGroup#setContext(org.eclipse.ui.actions.ActionContext)
59      */

60     public void setContext(ActionContext context) {
61         super.setContext(context);
62         if (context != null && context.getSelection() instanceof IStructuredSelection) {
63             IStructuredSelection sSel = (IStructuredSelection) context
64                     .getSelection();
65             addBookmarkAction.selectionChanged(sSel);
66             addTaskAction.selectionChanged(sSel);
67         } else {
68             addBookmarkAction.selectionChanged(StructuredSelection.EMPTY);
69             addTaskAction.selectionChanged(StructuredSelection.EMPTY);
70         }
71     }
72
73 }
74
Popular Tags