KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > ccvs > ui > subscriber > WorkspaceSynchronizeParticipant


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  * Sebastian Davids <sdavids@gmx.de> - bug 69926
11  *******************************************************************************/

12 package org.eclipse.team.internal.ccvs.ui.subscriber;
13
14 import java.util.HashSet JavaDoc;
15 import java.util.Set JavaDoc;
16
17 import org.eclipse.compare.CompareConfiguration;
18 import org.eclipse.core.resources.IResource;
19 import org.eclipse.core.runtime.IProgressMonitor;
20 import org.eclipse.jface.preference.PreferencePage;
21 import org.eclipse.jface.viewers.ILabelDecorator;
22 import org.eclipse.jface.window.Window;
23 import org.eclipse.team.core.TeamException;
24 import org.eclipse.team.core.diff.IDiff;
25 import org.eclipse.team.core.mapping.provider.ResourceDiffTree;
26 import org.eclipse.team.internal.ccvs.core.CVSProviderPlugin;
27 import org.eclipse.team.internal.ccvs.ui.*;
28 import org.eclipse.team.internal.ccvs.ui.actions.*;
29 import org.eclipse.team.internal.core.subscribers.*;
30 import org.eclipse.team.internal.ui.synchronize.*;
31 import org.eclipse.team.ui.TeamUI;
32 import org.eclipse.team.ui.synchronize.*;
33 import org.eclipse.ui.*;
34
35 public class WorkspaceSynchronizeParticipant extends ScopableSubscriberParticipant implements IChangeSetProvider {
36
37     public static final String JavaDoc ID = "org.eclipse.team.cvs.ui.cvsworkspace-participant"; //$NON-NLS-1$
38

39     /**
40      * The id of a workspace action group to which additions actions can
41      * be added.
42      */

43     public static final String JavaDoc TOOLBAR_CONTRIBUTION_GROUP = "toolbar_group_1"; //$NON-NLS-1$
44

45     public static final String JavaDoc CONTEXT_MENU_CONTRIBUTION_GROUP_1 = "context_group_1"; //$NON-NLS-1$
46
public static final String JavaDoc CONTEXT_MENU_CONTRIBUTION_GROUP_2 = "context_group_2"; //$NON-NLS-1$
47
public static final String JavaDoc CONTEXT_MENU_CONTRIBUTION_GROUP_3 = "context_group_3"; //$NON-NLS-1$
48
public static final String JavaDoc CONTEXT_MENU_CONTRIBUTION_GROUP_4 = "context_group_4"; //$NON-NLS-1$
49

50     private WorkspaceChangeSetCapability capability;
51
52     /**
53      * CVS workspace action contribution
54      */

55     public class WorkspaceActionContribution extends SynchronizePageActionGroup {
56         private WorkspaceCommitAction commitToolbar;
57         private WorkspaceUpdateAction updateToolbar;
58         
59         public void initialize(ISynchronizePageConfiguration configuration) {
60             super.initialize(configuration);
61             
62             updateToolbar = new WorkspaceUpdateAction(
63                     configuration,
64                     getVisibleRootsSelectionProvider(),
65                     "WorkspaceToolbarUpdateAction."); //$NON-NLS-1$
66
updateToolbar.setPromptBeforeUpdate(true);
67             appendToGroup(
68                     ISynchronizePageConfiguration.P_TOOLBAR_MENU,
69                     TOOLBAR_CONTRIBUTION_GROUP,
70                     updateToolbar);
71             
72             commitToolbar = new WorkspaceCommitAction(
73                     configuration,
74                     getVisibleRootsSelectionProvider(),
75                     "WorkspaceToolbarCommitAction."); //$NON-NLS-1$
76
appendToGroup(
77                     ISynchronizePageConfiguration.P_TOOLBAR_MENU,
78                     TOOLBAR_CONTRIBUTION_GROUP,
79                     commitToolbar);
80             
81             appendToGroup(
82                     ISynchronizePageConfiguration.P_CONTEXT_MENU,
83                     CONTEXT_MENU_CONTRIBUTION_GROUP_1,
84                     new WorkspaceUpdateAction(configuration));
85             appendToGroup(
86                     ISynchronizePageConfiguration.P_CONTEXT_MENU,
87                     CONTEXT_MENU_CONTRIBUTION_GROUP_1,
88                     new WorkspaceCommitAction(configuration));
89             appendToGroup(
90                     ISynchronizePageConfiguration.P_CONTEXT_MENU,
91                     CONTEXT_MENU_CONTRIBUTION_GROUP_2,
92                     new OverrideAndUpdateAction(configuration));
93             appendToGroup(
94                     ISynchronizePageConfiguration.P_CONTEXT_MENU,
95                     CONTEXT_MENU_CONTRIBUTION_GROUP_2,
96                     new OverrideAndCommitAction(configuration));
97             appendToGroup(
98                     ISynchronizePageConfiguration.P_CONTEXT_MENU,
99                     CONTEXT_MENU_CONTRIBUTION_GROUP_2,
100                     new ConfirmMergedAction(configuration));
101             appendToGroup(
102                     ISynchronizePageConfiguration.P_CONTEXT_MENU,
103                     CONTEXT_MENU_CONTRIBUTION_GROUP_3,
104                     new CVSActionDelegateWrapper(new IgnoreAction(), configuration));
105             if (!configuration.getSite().isModal()) {
106                 appendToGroup(
107                         ISynchronizePageConfiguration.P_CONTEXT_MENU,
108                         CONTEXT_MENU_CONTRIBUTION_GROUP_3,
109                         new CreatePatchAction(configuration));
110                 appendToGroup(
111                         ISynchronizePageConfiguration.P_CONTEXT_MENU,
112                         CONTEXT_MENU_CONTRIBUTION_GROUP_3,
113                         new CVSActionDelegateWrapper(new BranchAction(), configuration));
114                 appendToGroup(
115                         ISynchronizePageConfiguration.P_CONTEXT_MENU,
116                         CONTEXT_MENU_CONTRIBUTION_GROUP_3,
117                         new CVSActionDelegateWrapper(new ShowAnnotationAction(), configuration));
118                 appendToGroup(
119                         ISynchronizePageConfiguration.P_CONTEXT_MENU,
120                         CONTEXT_MENU_CONTRIBUTION_GROUP_3,
121                         new CVSActionDelegateWrapper(new ShowResourceInHistoryAction(), configuration));
122                 appendToGroup(
123                         ISynchronizePageConfiguration.P_CONTEXT_MENU,
124                         CONTEXT_MENU_CONTRIBUTION_GROUP_3,
125                         new CVSActionDelegateWrapper(new SetKeywordSubstitutionAction(), configuration));
126             }
127             appendToGroup(
128                     ISynchronizePageConfiguration.P_CONTEXT_MENU,
129                     CONTEXT_MENU_CONTRIBUTION_GROUP_4,
130                     new RefreshDirtyStateAction(configuration));
131         }
132     }
133     
134     public class WorkspaceChangeSetCapability extends CVSChangeSetCapability {
135         /* (non-Javadoc)
136          * @see org.eclipse.team.ui.synchronize.ChangeSetCapability#createChangeSet(org.eclipse.team.core.synchronize.SyncInfo[])
137          */

138         public ActiveChangeSet createChangeSet(ISynchronizePageConfiguration configuration, IDiff[] infos) {
139             ActiveChangeSet set = getActiveChangeSetManager().createSet(CVSUIMessages.WorkspaceChangeSetCapability_1, new IDiff[0]);
140             CommitSetDialog dialog = new CommitSetDialog(configuration.getSite().getShell(), set, getResources(infos), CommitSetDialog.NEW);
141             dialog.open();
142             if (dialog.getReturnCode() != Window.OK) return null;
143             set.add(infos);
144             return set;
145         }
146
147         private IResource[] getResources(IDiff[] diffs) {
148             Set JavaDoc result = new HashSet JavaDoc();
149             for (int i = 0; i < diffs.length; i++) {
150                 IDiff diff = diffs[i];
151                 IResource resource = ResourceDiffTree.getResourceFor(diff);
152                 if (resource != null)
153                     result.add(resource);
154             }
155             return (IResource[]) result.toArray(new IResource[result.size()]);
156         }
157         
158         /* (non-Javadoc)
159          * @see org.eclipse.team.ui.synchronize.ChangeSetCapability#editChangeSet(org.eclipse.team.core.subscribers.ActiveChangeSet)
160          */

161         public void editChangeSet(ISynchronizePageConfiguration configuration, ActiveChangeSet set) {
162             CommitSetDialog dialog = new CommitSetDialog(configuration.getSite().getShell(), set, set.getResources(), CommitSetDialog.EDIT);
163             dialog.open();
164             if (dialog.getReturnCode() != Window.OK) return;
165             // Nothing to do here as the set was updated by the dialog
166
}
167
168         /* (non-Javadoc)
169          * @see org.eclipse.team.ui.synchronize.ChangeSetCapability#getActiveChangeSetManager()
170          */

171         public ActiveChangeSetManager getActiveChangeSetManager() {
172             return CVSUIPlugin.getPlugin().getChangeSetManager();
173         }
174     }
175     
176     /**
177      * No-arg constructor used for
178      * creation of persisted participant after startup
179      */

180     public WorkspaceSynchronizeParticipant() {
181     }
182     
183     public WorkspaceSynchronizeParticipant(ISynchronizeScope scope) {
184         super(scope);
185         setSubscriber(CVSProviderPlugin.getPlugin().getCVSWorkspaceSubscriber());
186     }
187     
188     /* (non-Javadoc)
189      * @see org.eclipse.team.ui.synchronize.ISynchronizeParticipant#init(org.eclipse.ui.IMemento)
190      */

191     public void init(String JavaDoc secondaryId, IMemento memento) throws PartInitException {
192         super.init(secondaryId, memento);
193         setSubscriber(CVSProviderPlugin.getPlugin().getCVSWorkspaceSubscriber());
194     }
195     
196     /* (non-Javadoc)
197      * @see org.eclipse.team.ui.synchronize.subscribers.SubscriberParticipant#initializeConfiguration(org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration)
198      */

199     protected void initializeConfiguration(ISynchronizePageConfiguration configuration) {
200         super.initializeConfiguration(configuration);
201         ILabelDecorator labelDecorator = getLabelDecorator(configuration);
202         configuration.addLabelDecorator(labelDecorator);
203         configuration.addMenuGroup(ISynchronizePageConfiguration.P_TOOLBAR_MENU, TOOLBAR_CONTRIBUTION_GROUP);
204         configuration.addActionContribution(new WorkspaceActionContribution());
205         configuration.setSupportedModes(ISynchronizePageConfiguration.ALL_MODES);
206         configuration.setMode(ISynchronizePageConfiguration.BOTH_MODE);
207         
208         // Add context menu groups here to give the client displaying the
209
// page a chance to remove the context menu
210
configuration.addMenuGroup(
211                 ISynchronizePageConfiguration.P_CONTEXT_MENU,
212                 CONTEXT_MENU_CONTRIBUTION_GROUP_1);
213         configuration.addMenuGroup(
214                 ISynchronizePageConfiguration.P_CONTEXT_MENU,
215                 CONTEXT_MENU_CONTRIBUTION_GROUP_2);
216         configuration.addMenuGroup(
217                 ISynchronizePageConfiguration.P_CONTEXT_MENU,
218                 CONTEXT_MENU_CONTRIBUTION_GROUP_3);
219         configuration.addMenuGroup(
220                 ISynchronizePageConfiguration.P_CONTEXT_MENU,
221                 CONTEXT_MENU_CONTRIBUTION_GROUP_4);
222     }
223     
224     protected ILabelDecorator getLabelDecorator(ISynchronizePageConfiguration configuration) {
225         return new CVSParticipantLabelDecorator(configuration);
226     }
227     
228     protected ISynchronizeParticipantDescriptor getDescriptor() {
229         return TeamUI.getSynchronizeManager().getParticipantDescriptor(ID);
230     }
231     
232     /* (non-Javadoc)
233      * @see org.eclipse.team.ui.synchronize.SubscriberParticipant#updateLabels(org.eclipse.team.ui.synchronize.ISynchronizeModelElement, org.eclipse.compare.CompareConfiguration, org.eclipse.core.runtime.IProgressMonitor)
234      */

235     public void prepareCompareInput(ISynchronizeModelElement element, CompareConfiguration config, IProgressMonitor monitor) throws TeamException {
236         monitor.beginTask(null, 100);
237         CVSParticipant.deriveBaseContentsFromLocal(element, Policy.subMonitorFor(monitor, 10));
238         super.prepareCompareInput(element, config, Policy.subMonitorFor(monitor, 80));
239         CVSParticipant.updateLabelsForCVS(element, config, Policy.subMonitorFor(monitor, 10));
240         monitor.done();
241     }
242     
243     /* (non-Javadoc)
244      * @see org.eclipse.team.ui.synchronize.AbstractSynchronizeParticipant#getPreferencePages()
245      */

246     public PreferencePage[] getPreferencePages() {
247         return CVSParticipant.addCVSPreferencePages(super.getPreferencePages());
248     }
249     
250     /* (non-Javadoc)
251      * @see org.eclipse.team.ui.synchronize.AbstractSynchronizeParticipant#getChangeSetCapability()
252      */

253     public ChangeSetCapability getChangeSetCapability() {
254         if (capability == null) {
255             capability = new WorkspaceChangeSetCapability();
256         }
257         return capability;
258     }
259     
260     /* (non-Javadoc)
261      * @see org.eclipse.team.ui.synchronize.AbstractSynchronizeParticipant#isViewerContributionsSupported()
262      */

263     protected boolean isViewerContributionsSupported() {
264         return true;
265     }
266
267     public void refresh(IResource[] resources, IWorkbenchPartSite site) {
268         refresh(resources, getShortTaskName(), getLongTaskName(resources), site);
269     }
270     
271 }
272
Popular Tags