1 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 31 public class ModelSynchronizePage extends AbstractSynchronizePage { 32 33 private ModelSynchronizeParticipant participant; 34 35 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 55 public void reset() { 56 58 } 59 60 63 protected void updateMode(int mode) { 64 } 66 67 71 protected ModelSynchronizeParticipant getParticipant() { 72 return participant; 73 } 74 75 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 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 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 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 key, Object newValue) { 108 if (key.equals(ModelSynchronizeParticipant.P_VISIBLE_MODEL_PROVIDER)) { 109 if (!(newValue instanceof String )) { 110 return false; 111 } 112 String currentSetting = (String )configuration.getProperty(ModelSynchronizeParticipant.P_VISIBLE_MODEL_PROVIDER); 113 if (currentSetting != null && currentSetting.equals(newValue)) 114 return false; 115 116 Object input = getViewerInput(configuration,(String ) 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 [] {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 ) newValue); 131 } 132 return true; 133 } 134 return false; 135 } 136 if (key.equals(ITeamContentProviderManager.PROP_PAGE_LAYOUT)) { 137 if (!(newValue instanceof String )) { 138 return false; 139 } 140 String currentSetting = (String )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 ) newValue); 147 } 148 return true; 149 } 150 return super.aboutToChangeProperty(configuration, key, newValue); 151 } 152 153 159 public static Object getViewerInput(ISynchronizePageConfiguration configuration, String providerId) { 160 Object 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 id) { 173 try { 174 IModelProviderDescriptor desc = ModelProvider.getModelProviderDescriptor((String )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 |