1 11 package org.eclipse.pde.internal.ui.editor; 12 13 import org.eclipse.jface.text.IDocument; 14 import org.eclipse.jface.text.source.ISourceViewer; 15 import org.eclipse.jface.viewers.Viewer; 16 import org.eclipse.jface.viewers.ViewerComparator; 17 import org.eclipse.pde.internal.core.text.IDocumentKey; 18 import org.eclipse.pde.internal.core.util.PropertiesUtil; 19 20 public abstract class KeyValueSourcePage extends PDEProjectionSourcePage { 21 22 public KeyValueSourcePage(PDEFormEditor editor, String id, String title) { 23 super(editor, id, title); 24 } 25 26 29 public ViewerComparator createDefaultOutlineComparator() { 30 return new ViewerComparator() { 31 public int compare(Viewer viewer, Object e1, Object e2) { 32 if ((e1 instanceof IDocumentKey) && 33 (e2 instanceof IDocumentKey)) { 34 IDocumentKey key1 = (IDocumentKey)e1; 35 IDocumentKey key2 = (IDocumentKey)e2; 36 return key1.getOffset() < key2.getOffset() ? -1 : 1; 37 } 38 return 0; 41 } 42 }; 43 } 44 45 public void setHighlightRange(IDocumentKey key) { 46 ISourceViewer sourceViewer = getSourceViewer(); 47 if (sourceViewer == null) 48 return; 49 50 IDocument document = sourceViewer.getDocument(); 51 if (document == null) 52 return; 53 54 int offset = key.getOffset(); 55 int length = key.getLength(); 56 57 if (offset == -1 || length == -1) 58 return; 59 setHighlightRange(offset, length, true); 60 int nameLength = PropertiesUtil.createWritableName(key.getName()) 61 .length(); 62 sourceViewer.setSelectedRange(offset, Math.min(nameLength, length)); 63 } 64 65 68 public ViewerComparator createOutlineComparator() { 69 return new ViewerComparator(); 70 } 71 72 75 public boolean isQuickOutlineEnabled() { 76 return true; 77 } 78 79 } 80 | Popular Tags |