1 11 package org.eclipse.team.ui.mapping; 12 13 import java.util.*; 14 15 import org.eclipse.compare.structuremergeviewer.ICompareInput; 16 import org.eclipse.core.resources.IFile; 17 import org.eclipse.core.resources.IResource; 18 import org.eclipse.core.resources.mapping.ModelProvider; 19 import org.eclipse.core.resources.mapping.ResourceMapping; 20 import org.eclipse.core.runtime.*; 21 import org.eclipse.jface.resource.ImageDescriptor; 22 import org.eclipse.team.core.diff.IDiff; 23 import org.eclipse.team.core.mapping.ISynchronizationContext; 24 import org.eclipse.team.internal.ui.TeamUIMessages; 25 import org.eclipse.team.internal.ui.Utils; 26 import org.eclipse.team.internal.ui.mapping.ResourceDiffCompareInput; 27 import org.eclipse.team.ui.TeamUI; 28 import org.eclipse.ui.model.IWorkbenchAdapter; 29 30 39 public abstract class SynchronizationCompareAdapter implements ISynchronizationCompareAdapter { 40 41 47 public ICompareInput asCompareInput(ISynchronizationContext context, Object o) { 48 IResource resource = Utils.getResource(o); 49 if (resource != null) { 50 if (resource.getType() == IResource.FILE) { 51 IDiff node = context.getDiffTree().getDiff(resource); 52 if (node != null) 53 return new ResourceDiffCompareInput(node, context); 54 } 55 } 56 return null; 57 } 58 59 62 public boolean hasCompareInput(ISynchronizationContext context, Object object) { 63 return asCompareInput(context, object) != null; 64 } 65 66 69 public String getName(ResourceMapping mapping) { 70 Object object = mapping.getModelObject(); 71 IWorkbenchAdapter adapter = (IWorkbenchAdapter) Utils.getAdapter( 72 object, IWorkbenchAdapter.class); 73 if (adapter != null) { 74 String label = adapter.getLabel(object); 75 if (label != null) 76 return label; 77 } 78 IResource resource = Utils.getResource(object); 79 if (resource != null) 80 return resource.getName(); 81 if (object instanceof ModelProvider) { 82 ModelProvider provider = (ModelProvider) object; 83 if (provider.getId().equals(ModelProvider.RESOURCE_MODEL_PROVIDER_ID)) { 84 return TeamUIMessages.SynchronizationCompareAdapter_0; 85 } 86 return provider.getDescriptor().getLabel(); 87 } 88 return ""; } 90 91 94 public String getPathString(ResourceMapping mapping) { 95 Object object = mapping.getModelObject(); 96 IWorkbenchAdapter adapter = (IWorkbenchAdapter) Utils.getAdapter( 97 object, IWorkbenchAdapter.class); 98 if (adapter != null) { 99 List segments = new ArrayList(); 100 Object parent = object; 101 do { 102 String segment = adapter.getLabel(parent); 103 if (segment != null && segment.length() > 0) 104 segments.add(0, segment); 105 parent = adapter.getParent(parent); 106 } while (parent != null); 107 if (!segments.isEmpty()) { 108 IPath path = Path.EMPTY; 109 for (Iterator iter = segments.iterator(); iter.hasNext();) { 110 String segment = (String ) iter.next(); 111 path = path.append(segment); 112 } 113 return path.toString(); 114 } 115 } 116 return getName(mapping); 117 } 118 119 122 public ImageDescriptor getImageDescriptor(ResourceMapping mapping) { 123 Object object = mapping.getModelObject(); 124 ImageDescriptor image = getImageDescriptorFromWorkbenchAdapter(object); 125 if (image != null) 126 return image; 127 IResource resource = Utils.getResource(object); 128 if (resource != null) { 129 image = getImageDescriptorFromWorkbenchAdapter(resource); 130 if (image != null) 131 return image; 132 } 133 if (object instanceof ModelProvider) { 134 ModelProvider provider = (ModelProvider) object; 135 ITeamContentProviderDescriptor desc = TeamUI.getTeamContentProviderManager().getDescriptor(provider.getId()); 136 if (desc != null) 137 return desc.getImageDescriptor(); 138 } 139 return null; 140 } 141 142 private ImageDescriptor getImageDescriptorFromWorkbenchAdapter(Object object) { 143 IWorkbenchAdapter adapter = (IWorkbenchAdapter) Utils.getAdapter( 144 object, IWorkbenchAdapter.class); 145 if (adapter != null) { 146 return adapter.getImageDescriptor(object); 147 } 148 return null; 149 } 150 151 171 public int getSynchronizationState(ITeamStateProvider provider, ResourceMapping mapping, int stateMask, IProgressMonitor monitor) throws CoreException { 172 return -1; 173 } 174 175 } 176 | Popular Tags |