1 11 package org.eclipse.team.ui.mapping; 12 13 import org.eclipse.core.resources.ResourcesPlugin; 14 import org.eclipse.core.resources.mapping.ModelProvider; 15 import org.eclipse.jface.viewers.*; 16 import org.eclipse.osgi.util.NLS; 17 import org.eclipse.swt.graphics.Image; 18 import org.eclipse.team.core.mapping.ISynchronizationContext; 19 import org.eclipse.team.core.mapping.ISynchronizationScope; 20 import org.eclipse.team.internal.ui.TeamUIMessages; 21 import org.eclipse.team.ui.synchronize.AbstractSynchronizeLabelProvider; 22 import org.eclipse.ui.IMemento; 23 import org.eclipse.ui.navigator.*; 24 25 31 public abstract class SynchronizationLabelProvider extends AbstractSynchronizeLabelProvider implements ICommonLabelProvider, IFontProvider { 32 33 private ISynchronizationScope scope; 34 private ISynchronizationContext context; 35 private ITreeContentProvider contentProvider; 36 private ICommonContentExtensionSite site; 37 38 private void init(ISynchronizationScope input, ISynchronizationContext context) { 39 this.scope = input; 40 this.context = context; 41 } 42 43 46 public void init(ICommonContentExtensionSite site) { 47 this.site = site; 48 contentProvider = site.getExtension().getContentProvider(); 49 init((ISynchronizationScope)site.getExtensionStateModel().getProperty(ITeamContentProviderManager.P_SYNCHRONIZATION_SCOPE), 50 (ISynchronizationContext)site.getExtensionStateModel().getProperty(ITeamContentProviderManager.P_SYNCHRONIZATION_CONTEXT)); 51 } 52 53 59 public ISynchronizationContext getContext() { 60 return context; 61 } 62 63 69 public ISynchronizationScope getScope() { 70 return scope; 71 } 72 73 76 public void restoreState(IMemento aMemento) { 77 ILabelProvider provider = getDelegateLabelProvider(); 78 if (provider instanceof ICommonLabelProvider) { 79 ((ICommonLabelProvider) provider).restoreState(aMemento); 80 } 81 } 82 83 86 public void saveState(IMemento aMemento) { 87 ILabelProvider provider = getDelegateLabelProvider(); 88 if (provider instanceof ICommonLabelProvider) { 89 ((ICommonLabelProvider) provider).saveState(aMemento); 90 } 91 } 92 93 96 public String getDescription(Object anElement) { 97 ILabelProvider provider = getDelegateLabelProvider(); 98 if (provider instanceof IDescriptionProvider) { 99 return ((IDescriptionProvider) provider).getDescription(internalGetElement(anElement)); 100 } 101 return null; 102 } 103 104 107 protected boolean isDecorationEnabled() { 108 return getContext() != null; 109 } 110 111 114 public Image getImage(Object element) { 115 Image image = super.getImage(element); 116 if (image == null && internalGetElement(element) instanceof ModelProvider) { 117 image = super.getImage(getModelRoot()); 118 } 119 return image; 120 } 121 122 128 protected Object getModelRoot() { 129 return ResourcesPlugin.getWorkspace().getRoot(); 130 } 131 132 135 public String getText(Object element) { 136 String text = super.getText(element); 137 if (contentProvider instanceof SynchronizationContentProvider) { 138 SynchronizationContentProvider scp = (SynchronizationContentProvider) contentProvider; 139 ISynchronizationContext context = getContext(); 140 if (context != null && !scp.isInitialized(context)) { 141 return NLS.bind(TeamUIMessages.SynchronizationLabelProvider_0, text); 142 } 143 } 144 return text; 145 } 146 147 153 public ICommonContentExtensionSite getExtensionSite() { 154 return site; 155 } 156 157 private Object internalGetElement(Object element) { 158 if (element instanceof TreePath) { 159 TreePath tp = (TreePath) element; 160 element = tp.getLastSegment(); 161 } 162 return element; 163 } 164 } 165 | Popular Tags |