1 11 package org.eclipse.jdt.internal.ui.model; 12 13 import org.eclipse.core.resources.IFolder; 14 import org.eclipse.core.resources.IProject; 15 import org.eclipse.core.resources.IResource; 16 import org.eclipse.core.resources.ResourcesPlugin; 17 18 import org.eclipse.swt.graphics.Font; 19 import org.eclipse.swt.graphics.Image; 20 21 import org.eclipse.jface.viewers.DecoratingLabelProvider; 22 import org.eclipse.jface.viewers.ILabelProvider; 23 import org.eclipse.jface.viewers.ITreePathLabelProvider; 24 import org.eclipse.jface.viewers.TreePath; 25 import org.eclipse.jface.viewers.ViewerLabel; 26 27 import org.eclipse.team.core.diff.IDiff; 28 import org.eclipse.team.core.diff.IDiffTree; 29 import org.eclipse.team.core.mapping.ISynchronizationContext; 30 31 import org.eclipse.ltk.ui.refactoring.model.AbstractSynchronizationLabelProvider; 32 33 import org.eclipse.jdt.core.IPackageFragment; 34 import org.eclipse.jdt.core.JavaCore; 35 36 import org.eclipse.jdt.ui.ProblemsLabelDecorator; 37 38 import org.eclipse.jdt.internal.ui.JavaPluginImages; 39 40 45 public final class JavaSynchronizationLabelProvider extends AbstractSynchronizationLabelProvider implements ITreePathLabelProvider{ 46 47 48 private ILabelProvider fLabelProvider= null; 49 50 51 private Object fModelRoot= null; 52 53 54 private Image fPackageImage= null; 55 56 59 public void dispose() { 60 if (fPackageImage != null && !fPackageImage.isDisposed()) 61 fPackageImage.dispose(); 62 if (fLabelProvider != null) 63 fLabelProvider.dispose(); 64 super.dispose(); 65 } 66 67 70 public Image getDelegateImage(final Object element) { 71 if (element instanceof IPackageFragment) { 72 final IPackageFragment fragment= (IPackageFragment) element; 73 final IResource resource= fragment.getResource(); 74 if (resource == null || !resource.exists()) { 75 if (fPackageImage == null) 76 fPackageImage= JavaPluginImages.DESC_OBJS_PACKAGE.createImage(); 77 return fPackageImage; 78 } 79 } 80 return super.getDelegateImage(element); 81 } 82 83 86 protected ILabelProvider getDelegateLabelProvider() { 87 if (fLabelProvider == null) 88 fLabelProvider= new DecoratingLabelProvider(new JavaModelLabelProvider(ModelMessages.JavaModelLabelProvider_project_preferences_label, ModelMessages.JavaModelLabelProvider_refactorings_label), new ProblemsLabelDecorator(null)); 89 return fLabelProvider; 90 } 91 92 95 protected IDiff getDiff(final Object element) { 96 final ISynchronizationContext context= getContext(); 97 final IResource resource= JavaModelProvider.getResource(element); 98 if (context != null && resource != null) { 99 final IDiff[] diff= JavaSynchronizationContentProvider.getDiffs(context, element); 100 for (int index= 0; index < diff.length; index++) { 101 if (context.getDiffTree().getResource(diff[index]).equals(resource)) 102 return diff[index]; 103 } 104 } 105 return super.getDiff(element); 106 } 107 108 111 protected int getMarkerSeverity(final Object element) { 112 return -1; 114 } 115 116 119 protected Object getModelRoot() { 120 if (fModelRoot == null) 121 fModelRoot= JavaCore.create(ResourcesPlugin.getWorkspace().getRoot()); 122 return fModelRoot; 123 } 124 125 128 protected boolean hasDecendantConflicts(final Object element) { 129 final ISynchronizationContext context= getContext(); 130 final IResource resource= JavaModelProvider.getResource(element); 131 if (context != null && resource != null) 132 return context.getDiffTree().getProperty(resource.getFullPath(), IDiffTree.P_HAS_DESCENDANT_CONFLICTS); 133 return super.hasDecendantConflicts(element); 134 } 135 136 139 protected boolean isBusy(final Object element) { 140 final ISynchronizationContext context= getContext(); 141 final IResource resource= JavaModelProvider.getResource(element); 142 if (context != null && resource != null) 143 return context.getDiffTree().getProperty(resource.getFullPath(), IDiffTree.P_BUSY_HINT); 144 return super.isBusy(element); 145 } 146 147 150 protected boolean isIncludeOverlays() { 151 return true; 152 } 153 154 157 public void updateLabel(ViewerLabel label, TreePath elementPath) { 158 Object firstSegment = elementPath.getFirstSegment(); 159 if (firstSegment instanceof IProject && elementPath.getSegmentCount() == 2) { 160 IProject project = (IProject) firstSegment; 161 Object lastSegment = elementPath.getLastSegment(); 162 if (lastSegment instanceof IFolder) { 163 IFolder folder = (IFolder) lastSegment; 164 if (!folder.getParent().equals(project)) { 165 return; 171 } 172 } 173 } 174 label.setImage(getImage(elementPath.getLastSegment())); 175 label.setText(getText(elementPath.getLastSegment())); 176 Font f = getFont(elementPath.getLastSegment()); 177 if (f != null) 178 label.setFont(f); 179 } 180 } 181 | Popular Tags |