1 11 package org.eclipse.team.ui.synchronize; 12 13 import org.eclipse.compare.CompareConfiguration; 14 import org.eclipse.core.runtime.*; 15 import org.eclipse.jface.preference.PreferencePage; 16 import org.eclipse.jface.resource.ImageDescriptor; 17 import org.eclipse.jface.util.IPropertyChangeListener; 18 import org.eclipse.jface.viewers.IBasicPropertyConstants; 19 import org.eclipse.team.core.TeamException; 20 import org.eclipse.team.core.synchronize.SyncInfo; 21 import org.eclipse.team.internal.ui.*; 22 import org.eclipse.team.internal.ui.preferences.SyncViewerPreferencePage; 23 import org.eclipse.team.internal.ui.registry.SynchronizeParticipantDescriptor; 24 import org.eclipse.team.internal.ui.synchronize.SyncInfoModelElement; 25 import org.eclipse.team.internal.ui.synchronize.SynchronizePageConfiguration; 26 import org.eclipse.team.ui.TeamImages; 27 import org.eclipse.ui.IMemento; 28 import org.eclipse.ui.PartInitException; 29 30 39 public abstract class AbstractSynchronizeParticipant extends PlatformObject implements ISynchronizeParticipant { 40 41 45 public static final String P_PINNED = "org.eclipse.team.pinned"; 47 52 public static final String P_SCHEDULED = "org.eclipse.team.schedule"; 54 private final static String CTX_PINNED = "root"; 57 private PropertyChangeHandler fChangeHandler; 59 60 private String fName; 61 private String fId; 62 private String fSecondaryId; 63 private boolean pinned; 64 private ImageDescriptor fImageDescriptor; 65 protected IConfigurationElement configElement; 66 67 71 public AbstractSynchronizeParticipant() { 72 } 73 74 77 public String getName() { 78 return fName; 79 } 80 81 84 public ImageDescriptor getImageDescriptor() { 85 return fImageDescriptor; 86 } 87 88 89 92 public String getId() { 93 return fId; 94 } 95 96 99 public String getSecondaryId() { 100 return fSecondaryId; 101 } 102 103 104 107 public final void setPinned(boolean pinned) { 108 this.pinned = pinned; 109 pinned(pinned); 110 firePropertyChange(this, P_PINNED, Boolean.valueOf(!pinned), Boolean.valueOf(pinned)); 111 } 112 113 116 public final boolean isPinned() { 117 return pinned; 118 } 119 120 125 protected void pinned(boolean pinned) { 126 } 128 129 132 public boolean equals(Object obj) { 133 if(obj == this) return true; 134 if( ! (obj instanceof ISynchronizeParticipant)) return false; 135 ISynchronizeParticipant other = (ISynchronizeParticipant)obj; 136 return getId().equals(other.getId()) && Utils.equalObject(getSecondaryId(), other.getSecondaryId()); 137 } 138 139 142 public int hashCode() { 143 return Utils.getKey(getId(), getSecondaryId()).hashCode(); 144 } 145 146 154 public boolean doesSupportSynchronize() { 155 return true; 156 } 157 158 161 public synchronized void addPropertyChangeListener(IPropertyChangeListener listener) { 162 if (fChangeHandler == null) { 163 fChangeHandler = new PropertyChangeHandler(); 164 } 165 fChangeHandler.addPropertyChangeListener(listener); 166 } 167 168 171 public void removePropertyChangeListener(IPropertyChangeListener listener) { 172 if (fChangeHandler != null) { 173 fChangeHandler.removePropertyChangeListener(listener); 174 } 175 } 176 177 185 public void firePropertyChange(Object source, String property, Object oldValue, Object newValue) { 186 if (fChangeHandler == null) { 187 return; 188 } 189 fChangeHandler.firePropertyChange(source, property, oldValue, newValue); 190 } 191 192 195 public void setInitializationData(IConfigurationElement config, String propertyName, Object data) throws CoreException { 196 configElement = config; 198 199 fId = config.getAttribute("id"); 202 fName = config.getAttribute("name"); if (config == null) { 205 fName = "Unknown"; } 207 208 String strIcon = config.getAttribute("icon"); if (strIcon != null) { 211 fImageDescriptor = TeamImages.getImageDescriptorFromExtension(configElement.getDeclaringExtension(), strIcon); 212 } 213 } 214 215 protected void setInitializationData(ISynchronizeParticipantDescriptor descriptor) throws CoreException { 216 if(descriptor instanceof SynchronizeParticipantDescriptor) { 217 setInitializationData(((SynchronizeParticipantDescriptor)descriptor).getConfigurationElement(), null, null); 218 } else { 219 throw new TeamException(TeamUIMessages.AbstractSynchronizeParticipant_4); 220 } 221 } 222 223 229 protected void setName(String name) { 230 String old = fName; 231 fName = name; 232 firePropertyChange(this, IBasicPropertyConstants.P_TEXT, old, name); 233 } 234 235 241 protected void setImageDescriptor(ImageDescriptor imageDescriptor) { 242 ImageDescriptor old = fImageDescriptor; 243 fImageDescriptor = imageDescriptor; 244 firePropertyChange(this, IBasicPropertyConstants.P_IMAGE, old, imageDescriptor); 245 } 246 247 252 protected void setSecondaryId(String secondaryId) { 253 this.fSecondaryId = secondaryId; 254 } 255 256 272 public void init(String secondaryId, IMemento memento) throws PartInitException { 273 setSecondaryId(secondaryId); 274 pinned = Boolean.valueOf(memento.getString(CTX_PINNED)).booleanValue(); 275 } 276 277 280 public void saveState(IMemento memento) { 281 memento.putString(CTX_PINNED, Boolean.toString(pinned)); 282 } 283 284 287 public final ISynchronizePageConfiguration createPageConfiguration() { 288 SynchronizePageConfiguration configuration = new SynchronizePageConfiguration(this); 289 if (isViewerContributionsSupported()) { 290 configuration.setProperty(ISynchronizePageConfiguration.P_OBJECT_CONTRIBUTION_ID, getId()); 291 } 292 initializeConfiguration(configuration); 293 return configuration; 294 } 295 296 303 protected abstract void initializeConfiguration(ISynchronizePageConfiguration configuration); 304 305 320 public void prepareCompareInput(ISynchronizeModelElement element, CompareConfiguration config, IProgressMonitor monitor) throws TeamException { 321 SyncInfo sync = getSyncInfo(element); 322 if (sync != null) 323 Utils.updateLabels(sync, config); 324 if (element instanceof SyncInfoModelElement) { 325 SyncInfoModelElement node = (SyncInfoModelElement)element; 326 (node).cacheContents(monitor); 327 } 328 } 329 330 336 private SyncInfo getSyncInfo(ISynchronizeModelElement element) { 337 if (element instanceof IAdaptable) { 338 return (SyncInfo)((IAdaptable)element).getAdapter(SyncInfo.class); 339 } 340 return null; 341 } 342 343 346 public PreferencePage[] getPreferencePages() { 347 return new PreferencePage[] { new SyncViewerPreferencePage() }; 348 } 349 350 381 protected boolean isViewerContributionsSupported() { 382 return false; 383 } 384 } 385 | Popular Tags |