KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > ui > synchronize > actions > RefreshActionContribution


1 /*******************************************************************************
2  * Copyright (c) 2006, 2007 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.team.internal.ui.synchronize.actions;
12
13 import org.eclipse.core.resources.mapping.ResourceMapping;
14 import org.eclipse.jface.action.Action;
15 import org.eclipse.jface.action.IMenuManager;
16 import org.eclipse.jface.viewers.IStructuredSelection;
17 import org.eclipse.team.internal.ui.Utils;
18 import org.eclipse.team.internal.ui.synchronize.ConfigureRefreshScheduleDialog;
19 import org.eclipse.team.internal.ui.synchronize.IRefreshable;
20 import org.eclipse.team.ui.synchronize.*;
21 import org.eclipse.ui.IActionBars;
22
23 public class RefreshActionContribution extends SynchronizePageActionGroup {
24     // the changes viewer are contributed via the viewer and not the page.
25
private Action configureSchedule;
26     private Action refreshSelectionAction;
27     private org.eclipse.team.internal.ui.mapping.RemoveFromViewAction removeFromViewAction;
28     private org.eclipse.team.internal.ui.mapping.RestoreRemovedItemsAction restoreRemovedItemsAction;
29
30     /* (non-Javadoc)
31      * @see org.eclipse.team.ui.synchronize.IActionContribution#initialize(org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration)
32      */

33     public void initialize(final ISynchronizePageConfiguration configuration) {
34         super.initialize(configuration);
35         final ISynchronizePageSite site = configuration.getSite();
36         final ModelSynchronizeParticipant participant = (ModelSynchronizeParticipant)configuration.getParticipant();
37         // toolbar
38
if (participant.doesSupportSynchronize()) {
39             refreshSelectionAction = new Action() {
40                 public void run() {
41                     IStructuredSelection selection = (IStructuredSelection)site.getSelectionProvider().getSelection();
42                     ResourceMapping[] mappings = Utils.getResourceMappings(selection.toArray());
43                     participant.refresh(site.getWorkbenchSite(), mappings);
44                 }
45             };
46             Utils.initAction(refreshSelectionAction, "action.refreshWithRemote."); //$NON-NLS-1$
47
refreshSelectionAction.setActionDefinitionId("org.eclipse.team.ui.synchronizeLast"); //$NON-NLS-1$
48
refreshSelectionAction.setId("org.eclipse.team.ui.synchronizeLast"); //$NON-NLS-1$
49

50             Object JavaDoc o = participant.getAdapter(IRefreshable.class);
51             if (o instanceof IRefreshable) {
52                 final IRefreshable refreshable = (IRefreshable) o;
53                 configureSchedule = new Action() {
54                     public void run() {
55                         ConfigureRefreshScheduleDialog d = new ConfigureRefreshScheduleDialog(
56                                 site.getShell(), refreshable.getRefreshSchedule());
57                         d.setBlockOnOpen(false);
58                         d.open();
59                     }
60                 };
61                 Utils.initAction(configureSchedule, "action.configureSchedulel."); //$NON-NLS-1$
62
}
63         }
64         removeFromViewAction = new org.eclipse.team.internal.ui.mapping.RemoveFromViewAction(configuration);
65         restoreRemovedItemsAction = new org.eclipse.team.internal.ui.mapping.RestoreRemovedItemsAction(configuration);
66         appendToGroup(ISynchronizePageConfiguration.P_VIEW_MENU, ISynchronizePageConfiguration.SYNCHRONIZE_GROUP, restoreRemovedItemsAction);
67     }
68
69     /* (non-Javadoc)
70      * @see org.eclipse.team.ui.synchronize.IActionContribution#fillContextMenu(org.eclipse.jface.action.IMenuManager)
71      */

72     public void fillContextMenu(IMenuManager manager) {
73         if (findGroup(manager, ISynchronizePageConfiguration.SYNCHRONIZE_GROUP) != null
74             && findGroup(manager, ISynchronizePageConfiguration.NAVIGATE_GROUP) != null) {
75             // Place synchronize with navigate to save space
76
appendToGroup(manager, ISynchronizePageConfiguration.NAVIGATE_GROUP, refreshSelectionAction);
77             appendToGroup(manager, ISynchronizePageConfiguration.NAVIGATE_GROUP, removeFromViewAction);
78         } else {
79             appendToGroup(manager, ISynchronizePageConfiguration.SYNCHRONIZE_GROUP, refreshSelectionAction);
80             appendToGroup(manager, ISynchronizePageConfiguration.SYNCHRONIZE_GROUP, removeFromViewAction);
81         }
82     }
83
84     /* (non-Javadoc)
85      * @see org.eclipse.team.ui.synchronize.IActionContribution#setActionBars(org.eclipse.ui.IActionBars)
86      */

87     public void fillActionBars(IActionBars actionBars) {
88         super.fillActionBars(actionBars);
89         if(actionBars != null) {
90             // view menu
91
IMenuManager menu = actionBars.getMenuManager();
92             if (findGroup(menu, ISynchronizePageConfiguration.SYNCHRONIZE_GROUP) != null
93                     && findGroup(menu, ISynchronizePageConfiguration.PREFERENCES_GROUP) != null) {
94                 appendToGroup(menu, ISynchronizePageConfiguration.PREFERENCES_GROUP, configureSchedule);
95             } else {
96                 appendToGroup(menu, ISynchronizePageConfiguration.SYNCHRONIZE_GROUP, configureSchedule);
97             }
98         }
99     }
100 }
101
Popular Tags