KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 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.IResource;
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.ui.synchronize.*;
20 import org.eclipse.ui.IActionBars;
21
22 /**
23  * Provides the actions to be associated with a synchronize page
24  */

25 public final class SubscriberActionContribution extends SynchronizePageActionGroup {
26     
27     // the changes viewer are contributed via the viewer and not the page.
28
private Action configureSchedule;
29     private Action refreshSelectionAction;
30     private RemoveFromViewAction removeFromViewAction;
31     private RestoreRemovedItemsAction restoreRemovedItemsAction;
32
33     /* (non-Javadoc)
34      * @see org.eclipse.team.ui.synchronize.IActionContribution#initialize(org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration)
35      */

36     public void initialize(final ISynchronizePageConfiguration configuration) {
37         super.initialize(configuration);
38         final SubscriberParticipant participant = (SubscriberParticipant)configuration.getParticipant();
39         final ISynchronizePageSite site = configuration.getSite();
40         // toolbar
41
if(participant.doesSupportSynchronize()) {
42
43             refreshSelectionAction = new Action() {
44                 public void run() {
45                     IStructuredSelection selection = (IStructuredSelection)site.getSelectionProvider().getSelection();
46                     IResource[] resources = Utils.getResources(selection.toArray());
47                     if (resources.length == 0) {
48                         // Refresh all participant resources
49
resources = participant.getResources();
50                     }
51                     participant.refresh(resources, null, null, site.getWorkbenchSite()); //
52
}
53             };
54             Utils.initAction(refreshSelectionAction, "action.refreshWithRemote."); //$NON-NLS-1$
55
refreshSelectionAction.setActionDefinitionId("org.eclipse.team.ui.synchronizeLast"); //$NON-NLS-1$
56
refreshSelectionAction.setId("org.eclipse.team.ui.synchronizeLast"); //$NON-NLS-1$
57

58             configureSchedule = new Action() {
59                 public void run() {
60                     ConfigureRefreshScheduleDialog d = new ConfigureRefreshScheduleDialog(
61                             site.getShell(), participant.getRefreshSchedule());
62                     d.setBlockOnOpen(false);
63                     d.open();
64                 }
65             };
66             Utils.initAction(configureSchedule, "action.configureSchedulel."); //$NON-NLS-1$
67
}
68         
69         removeFromViewAction = new RemoveFromViewAction(configuration);
70         restoreRemovedItemsAction = new RestoreRemovedItemsAction(configuration);
71         appendToGroup(ISynchronizePageConfiguration.P_VIEW_MENU, ISynchronizePageConfiguration.SYNCHRONIZE_GROUP, restoreRemovedItemsAction);
72     }
73
74     /* (non-Javadoc)
75      * @see org.eclipse.team.ui.synchronize.IActionContribution#fillContextMenu(org.eclipse.jface.action.IMenuManager)
76      */

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

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