1 11 package org.eclipse.ltk.ui.refactoring.model; 12 13 import org.eclipse.team.core.diff.IDiff; 14 import org.eclipse.team.core.diff.IThreeWayDiff; 15 import org.eclipse.team.ui.mapping.SynchronizationLabelProvider; 16 17 import org.eclipse.ltk.core.refactoring.RefactoringDescriptorProxy; 18 import org.eclipse.ltk.core.refactoring.history.RefactoringHistory; 19 20 import org.eclipse.ltk.internal.ui.refactoring.model.RefactoringDescriptorDiff; 21 import org.eclipse.ltk.internal.ui.refactoring.model.RefactoringDescriptorSynchronizationProxy; 22 import org.eclipse.ltk.internal.ui.refactoring.model.RefactoringHistoryDiff; 23 24 42 public abstract class AbstractSynchronizationLabelProvider extends SynchronizationLabelProvider { 43 44 47 protected String decorateText(final String base, final Object element) { 48 if (element instanceof RefactoringDescriptorProxy) 49 return base; 50 return super.decorateText(base, element); 51 } 52 53 56 protected IDiff getDiff(final Object element) { 57 if (element instanceof RefactoringDescriptorProxy) 58 return new RefactoringDescriptorDiff((RefactoringDescriptorProxy) element, getKind(element), getDirection(element)); 59 else if (element instanceof RefactoringHistory) 60 return new RefactoringHistoryDiff((RefactoringHistory) element, getKind(element), getDirection(element)); 61 return super.getDiff(element); 62 } 63 64 79 protected int getDirection(Object element) { 80 if (element instanceof RefactoringHistory) { 81 final RefactoringHistory history= (RefactoringHistory) element; 82 final RefactoringDescriptorProxy[] descriptors= history.getDescriptors(); 83 int direction= 0; 84 if (descriptors.length > 0) { 85 if (descriptors[0] instanceof RefactoringDescriptorSynchronizationProxy) { 86 final RefactoringDescriptorSynchronizationProxy proxy= (RefactoringDescriptorSynchronizationProxy) descriptors[0]; 87 direction= proxy.getDirection(); 88 } 89 } 90 for (int index= 1; index < descriptors.length; index++) { 91 if (descriptors[index] instanceof RefactoringDescriptorSynchronizationProxy) { 92 final RefactoringDescriptorSynchronizationProxy proxy= (RefactoringDescriptorSynchronizationProxy) descriptors[index]; 93 if (proxy.getDirection() != direction) 94 return IThreeWayDiff.CONFLICTING; 95 } 96 } 97 return IDiff.NO_CHANGE; 98 } else if (element instanceof RefactoringDescriptorSynchronizationProxy) { 99 final RefactoringDescriptorSynchronizationProxy proxy= (RefactoringDescriptorSynchronizationProxy) element; 100 return proxy.getDirection(); 101 } 102 return IThreeWayDiff.CONFLICTING; 103 } 104 105 120 protected int getKind(Object element) { 121 if (element instanceof RefactoringHistory) 122 return IDiff.CHANGE; 123 return IDiff.ADD; 124 } 125 } 126 | Popular Tags |