1 11 package org.eclipse.ui.texteditor.quickdiff; 12 13 import java.util.Collections ; 14 import java.util.Iterator ; 15 import java.util.List ; 16 import java.util.ListIterator ; 17 18 import org.eclipse.core.runtime.Assert; 19 20 import org.eclipse.jface.text.source.IAnnotationModel; 21 22 import org.eclipse.ui.internal.texteditor.TextEditorPlugin; 23 import org.eclipse.ui.internal.texteditor.quickdiff.DocumentLineDiffer; 24 import org.eclipse.ui.internal.texteditor.quickdiff.QuickDiffExtensionsRegistry; 25 import org.eclipse.ui.texteditor.ITextEditor; 26 27 34 public class QuickDiff { 35 36 39 public QuickDiff() { 40 } 41 42 50 public ReferenceProviderDescriptor getDefaultProvider() { 51 QuickDiffExtensionsRegistry registry= TextEditorPlugin.getDefault().getQuickDiffExtensionRegistry(); 52 if (registry != null) 53 return registry.getDefaultProvider(); 54 55 return null; 56 } 57 58 67 public List getReferenceProviderDescriptors() { 68 QuickDiffExtensionsRegistry registry= TextEditorPlugin.getDefault().getQuickDiffExtensionRegistry(); 69 if (registry != null) 70 return registry.getReferenceProviderDescriptors(); 71 72 return Collections.EMPTY_LIST; 73 } 74 75 88 public IQuickDiffReferenceProvider getReferenceProviderOrDefault(ITextEditor editor, String id) { 89 Assert.isNotNull(editor); 90 Assert.isNotNull(id); 91 92 List descs= getReferenceProviderDescriptors(); 93 for (Iterator iter= descs.iterator(); iter.hasNext();) { 95 ReferenceProviderDescriptor desc= (ReferenceProviderDescriptor) iter.next(); 96 if (desc.getId().equals(id)) { 97 IQuickDiffReferenceProvider provider= desc.createProvider(); 98 if (provider != null) { 99 provider.setActiveEditor(editor); 100 if (provider.isEnabled()) 101 return provider; 102 provider.dispose(); 103 provider= null; 104 } 105 } 106 } 107 108 for (ListIterator iter= descs.listIterator(descs.size()); iter.hasPrevious();) { 109 ReferenceProviderDescriptor desc= (ReferenceProviderDescriptor) iter.previous(); 110 IQuickDiffReferenceProvider provider= desc.createProvider(); 111 if (provider != null) { 112 provider.setActiveEditor(editor); 113 if (provider.isEnabled()) 114 return provider; 115 provider.dispose(); 116 provider= null; 117 } 118 } 119 120 return null; 121 } 122 123 131 public IAnnotationModel createQuickDiffAnnotationModel(ITextEditor editor, String id) { 132 IQuickDiffReferenceProvider provider= getReferenceProviderOrDefault(editor, id); 133 if (provider != null) { 134 DocumentLineDiffer differ= new DocumentLineDiffer(); 135 differ.setReferenceProvider(provider); 136 return differ; 137 } 138 return null; 139 } 140 141 150 public Object getConfiguredQuickDiffProvider(IAnnotationModel differ) { 151 if (differ instanceof DocumentLineDiffer) { 152 DocumentLineDiffer lineDiffer= (DocumentLineDiffer) differ; 153 IQuickDiffReferenceProvider provider= lineDiffer.getReferenceProvider(); 154 if (provider != null) 155 return provider.getId(); 156 } 157 return ""; } 159 160 } 161 | Popular Tags |