1 11 package org.eclipse.team.internal.ui.synchronize; 12 13 import org.eclipse.compare.structuremergeviewer.IDiffElement; 14 import org.eclipse.core.resources.IResource; 15 import org.eclipse.core.resources.ResourcesPlugin; 16 import org.eclipse.jface.resource.ImageDescriptor; 17 import org.eclipse.jface.viewers.ViewerSorter; 18 import org.eclipse.team.core.synchronize.*; 19 import org.eclipse.team.internal.ui.*; 20 import org.eclipse.team.ui.TeamImages; 21 import org.eclipse.team.ui.synchronize.ISynchronizeModelElement; 22 import org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration; 23 24 39 public class HierarchicalModelProvider extends SynchronizeModelProvider { 40 41 public static class HierarchicalModelProviderDescriptor implements ISynchronizeModelProviderDescriptor { 42 public static final String ID = TeamUIPlugin.ID + ".modelprovider_hierarchical"; public String getId() { 44 return ID; 45 } 46 public String getName() { 47 return TeamUIMessages.HierarchicalModelProvider_0; 48 } 49 public ImageDescriptor getImageDescriptor() { 50 return TeamImages.getImageDescriptor(ITeamUIImages.IMG_HIERARCHICAL); 51 } 52 } 53 private static final HierarchicalModelProviderDescriptor hierarchicalDescriptor = new HierarchicalModelProviderDescriptor(); 54 55 61 public HierarchicalModelProvider(ISynchronizePageConfiguration configuration, SyncInfoSet set) { 62 super(configuration, set); 63 } 64 65 public HierarchicalModelProvider( 66 AbstractSynchronizeModelProvider parentProvider, 67 ISynchronizeModelElement modelRoot, 68 ISynchronizePageConfiguration configuration, SyncInfoSet set) { 69 super(parentProvider, modelRoot, configuration, set); 70 } 71 72 75 public ISynchronizeModelProviderDescriptor getDescriptor() { 76 return hierarchicalDescriptor; 77 } 78 79 public ViewerSorter getViewerSorter() { 80 return new SynchronizeModelElementSorter(); 81 } 82 83 protected SyncInfoTree getSyncInfoTree() { 84 return (SyncInfoTree)getSyncInfoSet(); 85 } 86 87 94 protected IDiffElement[] createModelObjects(ISynchronizeModelElement container) { 95 IResource resource = null; 96 if (container == getModelRoot()) { 97 resource = ResourcesPlugin.getWorkspace().getRoot(); 98 } else { 99 resource = container.getResource(); 100 } 101 if(resource != null) { 102 SyncInfoTree infoTree = getSyncInfoTree(); 103 IResource[] children = infoTree.members(resource); 104 ISynchronizeModelElement[] nodes = new ISynchronizeModelElement[children.length]; 105 for (int i = 0; i < children.length; i++) { 106 nodes[i] = createModelObject(container, children[i]); 107 } 108 return nodes; 109 } 110 return new IDiffElement[0]; 111 } 112 113 protected ISynchronizeModelElement createModelObject(ISynchronizeModelElement parent, IResource resource) { 114 SyncInfo info = getSyncInfoTree().getSyncInfo(resource); 115 SynchronizeModelElement newNode; 116 if(info != null) { 117 newNode = new SyncInfoModelElement(parent, info); 118 } else { 119 newNode = new UnchangedResourceModelElement(parent, resource); 120 } 121 addToViewer(newNode); 122 return newNode; 123 } 124 125 131 protected Object [] getModelObjects(IResource[] resources) { 132 Object [] result = new Object [resources.length]; 133 for (int i = 0; i < resources.length; i++) { 134 result[i] = getModelObject(resources[i]); 135 } 136 return result; 137 } 138 139 protected void addResources(IResource[] added) { 140 for (int i = 0; i < added.length; i++) { 141 IResource resource = added[i]; 142 addResource(resource); 143 } 144 } 145 146 private void addResource(IResource resource) { 147 ISynchronizeModelElement node = getModelObject(resource); 148 if (node != null) { 149 removeFromViewer(resource); 152 } 153 ISynchronizeModelElement parent = getModelObject(resource.getParent()); 155 if (parent != null) { 156 node = createModelObject(parent, resource); 157 buildModelObjects(node); 158 } 159 } 160 161 164 protected IDiffElement[] buildModelObjects(ISynchronizeModelElement node) { 165 IDiffElement[] children = createModelObjects(node); 166 for (int i = 0; i < children.length; i++) { 167 IDiffElement element = children[i]; 168 if (element instanceof ISynchronizeModelElement) { 169 buildModelObjects((ISynchronizeModelElement) element); 170 } 171 } 172 return children; 173 } 174 175 178 protected void handleResourceAdditions(ISyncInfoTreeChangeEvent event) { 179 IResource[] added = event.getAddedSubtreeRoots(); 180 addResources(added); 181 } 182 183 186 protected void handleResourceRemovals(ISyncInfoTreeChangeEvent event) { 187 IResource[] removedRoots = event.getRemovedSubtreeRoots(); 189 removeFromViewer(removedRoots); 190 IResource[] removedResources = event.getRemovedResources(); 193 for (int i = 0; i < removedResources.length; i++) { 194 IResource resource = removedResources[i]; 195 if (resource.getType() != IResource.FILE) { 196 ISynchronizeModelElement node = getModelObject(resource); 197 if (node != null) { 198 removeFromViewer(resource); 199 addResources(new IResource[] {resource}); 200 } 201 } 202 } 203 } 204 205 208 protected ISynchronizeModelElement createModelObject(ISynchronizeModelElement parent, SyncInfo info) { 209 return createModelObject(parent, info.getLocal()); 210 } 211 212 215 protected void addResource(SyncInfo info) { 216 addResource(info.getLocal()); 217 } 218 } 219 | Popular Tags |