KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > ccvs > ui > mappings > ModelSynchronizeWizard


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.ccvs.ui.mappings;
12
13 import org.eclipse.core.resources.IResource;
14 import org.eclipse.core.resources.mapping.ResourceMapping;
15 import org.eclipse.jface.wizard.IWizard;
16 import org.eclipse.jface.wizard.WizardPage;
17 import org.eclipse.swt.widgets.Shell;
18 import org.eclipse.team.core.mapping.ISynchronizationContext;
19 import org.eclipse.team.core.mapping.ISynchronizationScopeManager;
20 import org.eclipse.team.internal.ccvs.core.CVSProviderPlugin;
21 import org.eclipse.team.internal.ccvs.ui.*;
22 import org.eclipse.team.internal.ccvs.ui.actions.CommitAction;
23 import org.eclipse.team.internal.ccvs.ui.subscriber.WorkspaceSynchronizeParticipant;
24 import org.eclipse.team.internal.ccvs.ui.wizards.CheckoutWizard;
25 import org.eclipse.team.internal.ui.mapping.ModelElementSelectionPage;
26 import org.eclipse.team.internal.ui.synchronize.GlobalRefreshElementSelectionPage;
27 import org.eclipse.team.internal.ui.synchronize.GlobalRefreshResourceSelectionPage;
28 import org.eclipse.team.ui.TeamUI;
29 import org.eclipse.team.ui.synchronize.*;
30
31 public class ModelSynchronizeWizard extends ParticipantSynchronizeWizard {
32
33     private GlobalRefreshElementSelectionPage selectionPage;
34     
35     private boolean isShowModelSync() {
36         return CVSUIPlugin.getPlugin().getPreferenceStore().getBoolean(ICVSUIConstants.PREF_ENABLE_MODEL_SYNC);
37     }
38     
39     /* (non-Javadoc)
40      * @see org.eclipse.team.ui.synchronize.ParticipantSynchronizeWizard#createParticipant()
41      */

42     protected void createParticipant() {
43         if (isShowModelSync()) {
44             ISynchronizeParticipant participant = createParticipant(
45                     ((ModelElementSelectionPage)selectionPage).getSelectedMappings());
46             TeamUI.getSynchronizeManager().addSynchronizeParticipants(new ISynchronizeParticipant[]{participant});
47             // We don't know in which site to show progress because a participant could actually be shown in multiple sites.
48
participant.run(null /* no site */);
49         } else {
50             IResource[] resources = ((GlobalRefreshResourceSelectionPage)selectionPage).getRootResources();
51             if (resources != null && resources.length > 0) {
52                 SubscriberParticipant participant = createParticipant(((GlobalRefreshResourceSelectionPage)selectionPage).getSynchronizeScope());
53                 TeamUI.getSynchronizeManager().addSynchronizeParticipants(new ISynchronizeParticipant[]{participant});
54                 // We don't know in which site to show progress because a participant could actually be shown in multiple sites.
55
participant.run(null /* no site */);
56             }
57         }
58     }
59     
60     /* (non-Javadoc)
61      * @see org.eclipse.team.ui.synchronize.ParticipantSynchronizeWizard#createScopeSelectionPage()
62      */

63     protected final WizardPage createScopeSelectionPage() {
64         if (isShowModelSync())
65             selectionPage = new ModelElementSelectionPage(getRootResources());
66         else
67             selectionPage = new GlobalRefreshResourceSelectionPage(getRootResources());
68         return selectionPage;
69     }
70     
71     public static ISynchronizeParticipant createWorkspaceParticipant(ResourceMapping[] selectedMappings, Shell shell) {
72         ISynchronizationScopeManager manager = WorkspaceSubscriberContext.createWorkspaceScopeManager(selectedMappings, true, CommitAction.isIncludeChangeSets(shell, CVSUIMessages.SyncAction_1));
73         WorkspaceModelParticipant p = new WorkspaceModelParticipant(
74                 WorkspaceSubscriberContext.createContext(manager, ISynchronizationContext.THREE_WAY));
75         return p;
76     }
77     
78     public ModelSynchronizeWizard() {
79         super();
80         setNeedsProgressMonitor(isShowModelSync());
81     }
82
83     protected ISynchronizeParticipant createParticipant(ResourceMapping[] selectedMappings) {
84         return createWorkspaceParticipant(selectedMappings, getShell());
85     }
86
87     protected SubscriberParticipant createParticipant(ISynchronizeScope scope) {
88         // First check if there is an existing matching participant
89
IResource[] roots = scope.getRoots();
90         if (roots == null) {
91             roots = CVSProviderPlugin.getPlugin().getCVSWorkspaceSubscriber().roots();
92         }
93         WorkspaceSynchronizeParticipant participant = (WorkspaceSynchronizeParticipant)SubscriberParticipant.getMatchingParticipant(WorkspaceSynchronizeParticipant.ID, roots);
94         // If there isn't, create one and add to the manager
95
if (participant == null) {
96             return new WorkspaceSynchronizeParticipant(scope);
97         } else {
98             return participant;
99         }
100     }
101     
102     protected String JavaDoc getPageTitle() {
103         ISynchronizeParticipantDescriptor desc = TeamUI.getSynchronizeManager().getParticipantDescriptor(WorkspaceModelParticipant.ID);
104         if(desc != null) {
105             return desc.getName();
106         } else {
107             return CVSUIMessages.CVSSynchronizeWizard_0;
108         }
109     }
110
111     protected IWizard getImportWizard() {
112         return new CheckoutWizard();
113     }
114
115     protected IResource[] getRootResources() {
116         return CVSProviderPlugin.getPlugin().getCVSWorkspaceSubscriber().roots();
117     }
118
119 }
120
Popular Tags