KickJava   Java API By Example, From Geeks To Geeks.

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


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.mapping;
12
13 import org.eclipse.core.resources.mapping.IModelProviderDescriptor;
14 import org.eclipse.core.resources.mapping.ModelProvider;
15 import org.eclipse.core.runtime.CoreException;
16 import org.eclipse.jface.dialogs.IDialogSettings;
17 import org.eclipse.osgi.util.NLS;
18 import org.eclipse.swt.widgets.Composite;
19 import org.eclipse.team.core.mapping.ISynchronizationContext;
20 import org.eclipse.team.internal.ui.*;
21 import org.eclipse.team.internal.ui.synchronize.*;
22 import org.eclipse.team.internal.ui.synchronize.actions.RefreshActionContribution;
23 import org.eclipse.team.ui.mapping.ITeamContentProviderManager;
24 import org.eclipse.team.ui.synchronize.*;
25
26 /**
27  * A synchronize page for displaying a {@link ModelSynchronizeParticipant}.
28  *
29  * @since 3.2
30  **/

31 public class ModelSynchronizePage extends AbstractSynchronizePage {
32
33     private ModelSynchronizeParticipant participant;
34
35     /**
36      * Create a page from the given configuration
37      * @param configuration a page configuration
38      */

39     public ModelSynchronizePage(ISynchronizePageConfiguration configuration) {
40         super(configuration);
41         this.participant = (ModelSynchronizeParticipant)configuration.getParticipant();
42         configuration.setComparisonType(isThreeWay()
43                         ? ISynchronizePageConfiguration.THREE_WAY
44                         : ISynchronizePageConfiguration.TWO_WAY);
45         configuration.addActionContribution(new RefreshActionContribution());
46     }
47
48     private boolean isThreeWay() {
49         return getParticipant().getContext().getType() == ISynchronizationContext.THREE_WAY;
50     }
51
52     /* (non-Javadoc)
53      * @see org.eclipse.team.internal.ui.synchronize.AbstractSynchronizePage#reset()
54      */

55     public void reset() {
56         // TODO Auto-generated method stub
57

58     }
59
60     /* (non-Javadoc)
61      * @see org.eclipse.team.internal.ui.synchronize.AbstractSynchronizePage#updateMode(int)
62      */

63     protected void updateMode(int mode) {
64         // Nothing to do
65
}
66
67     /**
68      * Return the participant of this page.
69      * @return the participant of this page
70      */

71     protected ModelSynchronizeParticipant getParticipant() {
72         return participant;
73     }
74
75     /* (non-Javadoc)
76      * @see org.eclipse.team.internal.ui.synchronize.AbstractSynchronizePage#createViewerAdvisor(org.eclipse.swt.widgets.Composite)
77      */

78     protected AbstractViewerAdvisor createViewerAdvisor(Composite parent) {
79         CommonViewerAdvisor commonViewerAdvisor = new CommonViewerAdvisor(parent, getConfiguration());
80         commonViewerAdvisor.addEmptyTreeListener((DiffTreeChangesSection)getChangesSection());
81         updateMode(getConfiguration().getMode());
82         return commonViewerAdvisor;
83     }
84     
85     /* (non-Javadoc)
86      * @see org.eclipse.team.internal.ui.synchronize.AbstractSynchronizePage#createChangesSection()
87      */

88     protected ChangesSection createChangesSection(Composite parent) {
89         return new DiffTreeChangesSection(parent, this, getConfiguration());
90     }
91     
92     public void init(ISynchronizePageSite site) {
93         super.init(site);
94         IDialogSettings pageSettings = site.getPageSettings();
95         if(pageSettings != null) {
96             String JavaDoc savedId = pageSettings.get(ModelSynchronizeParticipant.P_VISIBLE_MODEL_PROVIDER);
97             if (savedId != null && ! savedId.equals(ModelSynchronizeParticipant.ALL_MODEL_PROVIDERS_VISIBLE)) {
98                 getConfiguration().setProperty(ModelSynchronizeParticipant.P_VISIBLE_MODEL_PROVIDER, savedId);
99             }
100             String JavaDoc layout = pageSettings.get(ITeamContentProviderManager.PROP_PAGE_LAYOUT);
101             if (layout != null) {
102                 getConfiguration().setProperty(ITeamContentProviderManager.PROP_PAGE_LAYOUT, layout);
103             }
104         }
105     }
106     
107     public boolean aboutToChangeProperty(ISynchronizePageConfiguration configuration, String JavaDoc key, Object JavaDoc newValue) {
108         if (key.equals(ModelSynchronizeParticipant.P_VISIBLE_MODEL_PROVIDER)) {
109             if (!(newValue instanceof String JavaDoc)) {
110                 return false;
111             }
112             String JavaDoc currentSetting = (String JavaDoc)configuration.getProperty(ModelSynchronizeParticipant.P_VISIBLE_MODEL_PROVIDER);
113             if (currentSetting != null && currentSetting.equals(newValue))
114                 return false;
115             
116             Object JavaDoc input = getViewerInput(configuration,(String JavaDoc) newValue);
117             if (input instanceof ModelProvider) {
118                 ModelProvider provider = (ModelProvider) input;
119                 configuration.setProperty(
120                         ISynchronizePageConfiguration.P_PAGE_DESCRIPTION,
121                         NLS.bind(TeamUIMessages.ShowModelProviderAction_0, new String JavaDoc[] {Utils.getLabel(provider), Utils.shortenText(SynchronizeView.MAX_NAME_LENGTH, configuration.getParticipant().getName()) }));
122             } else if (input != null) {
123                 configuration.setProperty(
124                         ISynchronizePageConfiguration.P_PAGE_DESCRIPTION,
125                         Utils.shortenText(SynchronizeView.MAX_NAME_LENGTH, configuration.getParticipant().getName()));
126             }
127             if (input != null) {
128                 IDialogSettings pageSettings = configuration.getSite().getPageSettings();
129                 if(pageSettings != null) {
130                     pageSettings.put(ModelSynchronizeParticipant.P_VISIBLE_MODEL_PROVIDER, (String JavaDoc) newValue);
131                 }
132                 return true;
133             }
134             return false;
135         }
136         if (key.equals(ITeamContentProviderManager.PROP_PAGE_LAYOUT)) {
137             if (!(newValue instanceof String JavaDoc)) {
138                 return false;
139             }
140             String JavaDoc currentSetting = (String JavaDoc)configuration.getProperty(ITeamContentProviderManager.PROP_PAGE_LAYOUT);
141             if (currentSetting != null && currentSetting.equals(newValue))
142                 return false;
143             
144             IDialogSettings pageSettings = configuration.getSite().getPageSettings();
145             if(pageSettings != null) {
146                 pageSettings.put(ITeamContentProviderManager.PROP_PAGE_LAYOUT, (String JavaDoc) newValue);
147             }
148             return true;
149         }
150         return super.aboutToChangeProperty(configuration, key, newValue);
151     }
152
153     /**
154      * Return the input for the viewer.
155      * @param configuration the page configuration
156      * @param providerId the provider id or ModelSynchronizeParticipant.ALL_MODEL_PROVIDERS_VISIBLE
157      * @return the input for the viewer.
158      */

159     public static Object JavaDoc getViewerInput(ISynchronizePageConfiguration configuration, String JavaDoc providerId) {
160         Object JavaDoc input = null;
161         if (!providerId.equals(ModelSynchronizeParticipant.ALL_MODEL_PROVIDERS_VISIBLE)) {
162             ModelProvider provider = getModelProvider(providerId);
163             if (provider != null) {
164                 input = provider;
165             }
166         } else {
167             input = (ISynchronizationContext)configuration.getProperty(ITeamContentProviderManager.P_SYNCHRONIZATION_CONTEXT);
168         }
169         return input;
170     }
171
172     private static ModelProvider getModelProvider(String JavaDoc id) {
173         try {
174             IModelProviderDescriptor desc = ModelProvider.getModelProviderDescriptor((String JavaDoc)id);
175             if (desc != null) {
176                 return desc.getModelProvider();
177             }
178         } catch (CoreException e) {
179             TeamUIPlugin.log(e);
180         }
181         return null;
182     }
183
184 }
185
Popular Tags