KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > ui > mapping > ResourceModelActionProvider


1 /*******************************************************************************
2  * Copyright (c) 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.team.internal.ui.mapping;
12
13 import org.eclipse.jface.action.IContributionItem;
14 import org.eclipse.jface.action.IMenuManager;
15 import org.eclipse.jface.viewers.Viewer;
16 import org.eclipse.team.internal.ui.synchronize.actions.RefactorActionGroup;
17 import org.eclipse.team.ui.mapping.ITeamContentProviderManager;
18 import org.eclipse.team.ui.mapping.SynchronizationActionProvider;
19 import org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration;
20 import org.eclipse.ui.*;
21 import org.eclipse.ui.actions.ActionContext;
22 import org.eclipse.ui.navigator.*;
23
24 /**
25  * This is the synchronization action handler for the resources model
26  */

27 public class ResourceModelActionProvider extends SynchronizationActionProvider {
28
29     private RefactorActionGroup refactorActions;
30     
31     public ResourceModelActionProvider() {
32     }
33
34     /* (non-Javadoc)
35      * @see org.eclipse.team.ui.mapping.SynchronizationActionProvider#initialize()
36      */

37     protected void initialize() {
38         super.initialize();
39         // Register the merge, overwrite and mark-as-merged handlers
40
ResourceMergeHandler mergeHandler = new ResourceMergeHandler(
41                 (ISynchronizePageConfiguration)getExtensionStateModel().getProperty(ITeamContentProviderManager.P_SYNCHRONIZATION_PAGE_CONFIGURATION),
42                 false /* overwrite */);
43         registerHandler(MERGE_ACTION_ID, mergeHandler);
44         ResourceMergeHandler overwriteHandler = new ResourceMergeHandler(
45                 (ISynchronizePageConfiguration)getExtensionStateModel().getProperty(ITeamContentProviderManager.P_SYNCHRONIZATION_PAGE_CONFIGURATION),
46                 true /* overwrite */);
47         registerHandler(OVERWRITE_ACTION_ID, overwriteHandler);
48         ResourceMarkAsMergedHandler markAsMergedHandler = new ResourceMarkAsMergedHandler(
49                 (ISynchronizePageConfiguration)getExtensionStateModel().getProperty(ITeamContentProviderManager.P_SYNCHRONIZATION_PAGE_CONFIGURATION));
50         registerHandler(MARK_AS_MERGE_ACTION_ID, markAsMergedHandler);
51         
52         ICommonViewerSite cvs = getActionSite().getViewSite();
53         ISynchronizePageConfiguration configuration = getSynchronizePageConfiguration();
54         if (cvs instanceof ICommonViewerWorkbenchSite && configuration != null) {
55             ICommonViewerWorkbenchSite cvws = (ICommonViewerWorkbenchSite) cvs;
56             final IWorkbenchPartSite wps = cvws.getSite();
57             if (wps instanceof IViewSite) {
58                 refactorActions = new RefactorActionGroup(configuration.getSite(), getNavigatorContentService(configuration));
59             }
60         }
61     }
62     
63     private INavigatorContentService getNavigatorContentService(ISynchronizePageConfiguration configuration) {
64         Viewer v = configuration.getPage().getViewer();
65         if (v instanceof CommonViewer) {
66             CommonViewer cv = (CommonViewer) v;
67             return cv.getNavigatorContentService();
68         }
69         return null;
70     }
71
72     /* (non-Javadoc)
73      * @see org.eclipse.team.ui.mapping.SynchronizationActionProvider#fillActionBars(org.eclipse.ui.IActionBars)
74      */

75     public void fillActionBars(IActionBars actionBars) {
76         super.fillActionBars(actionBars);
77         if (refactorActions != null) refactorActions.fillActionBars(actionBars);
78     }
79     
80     /* (non-Javadoc)
81      * @see org.eclipse.team.ui.mapping.SynchronizationActionProvider#fillContextMenu(org.eclipse.jface.action.IMenuManager)
82      */

83     public void fillContextMenu(IMenuManager menu) {
84         super.fillContextMenu(menu);
85         IContributionItem editGroup = menu.find(ISynchronizePageConfiguration.EDIT_GROUP);
86         if (refactorActions != null && editGroup != null) {
87             refactorActions.fillContextMenu(menu, editGroup.getId());
88         }
89     }
90     
91     /* (non-Javadoc)
92      * @see org.eclipse.ui.actions.ActionGroup#updateActionBars()
93      */

94     public void updateActionBars() {
95         super.updateActionBars();
96          if (refactorActions != null) refactorActions.updateActionBars();
97     }
98     
99     /* (non-Javadoc)
100      * @see org.eclipse.team.ui.synchronize.SynchronizePageActionGroup#dispose()
101      */

102     public void dispose() {
103         super.dispose();
104         if (refactorActions != null) refactorActions.dispose();
105     }
106     
107     /* (non-Javadoc)
108      * @see org.eclipse.ui.actions.ActionGroup#setContext(org.eclipse.ui.actions.ActionContext)
109      */

110     public void setContext(ActionContext context) {
111         super.setContext(context);
112         if (refactorActions != null) refactorActions.setContext(context);
113     }
114 }
115
Popular Tags