01: /*******************************************************************************
02: * Copyright (c) 2003, 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.pde.internal.ui.editor;
11:
12: import org.eclipse.jface.text.IDocument;
13: import org.eclipse.jface.text.source.ISourceViewer;
14: import org.eclipse.jface.viewers.Viewer;
15: import org.eclipse.jface.viewers.ViewerComparator;
16: import org.eclipse.pde.internal.core.text.IDocumentKey;
17: import org.eclipse.pde.internal.core.util.PropertiesUtil;
18:
19: public abstract class KeyValueSourcePage extends
20: PDEProjectionSourcePage {
21:
22: public KeyValueSourcePage(PDEFormEditor editor, String id,
23: String title) {
24: super (editor, id, title);
25: }
26:
27: /* (non-Javadoc)
28: * @see org.eclipse.pde.internal.ui.neweditor.PDESourcePage#createViewerSorter()
29: */
30: public ViewerComparator createDefaultOutlineComparator() {
31: return new ViewerComparator() {
32: public int compare(Viewer viewer, Object e1, Object e2) {
33: if ((e1 instanceof IDocumentKey)
34: && (e2 instanceof IDocumentKey)) {
35: IDocumentKey key1 = (IDocumentKey) e1;
36: IDocumentKey key2 = (IDocumentKey) e2;
37: return key1.getOffset() < key2.getOffset() ? -1 : 1;
38: }
39: // Bundle manifest header elements
40: // Do not sort by default
41: return 0;
42: }
43: };
44: }
45:
46: public void setHighlightRange(IDocumentKey key) {
47: ISourceViewer sourceViewer = getSourceViewer();
48: if (sourceViewer == null)
49: return;
50:
51: IDocument document = sourceViewer.getDocument();
52: if (document == null)
53: return;
54:
55: int offset = key.getOffset();
56: int length = key.getLength();
57:
58: if (offset == -1 || length == -1)
59: return;
60: setHighlightRange(offset, length, true);
61: int nameLength = PropertiesUtil.createWritableName(
62: key.getName()).length();
63: sourceViewer.setSelectedRange(offset, Math.min(nameLength,
64: length));
65: }
66:
67: /* (non-Javadoc)
68: * @see org.eclipse.pde.internal.ui.editor.PDESourcePage#createOutlineSorter()
69: */
70: public ViewerComparator createOutlineComparator() {
71: return new ViewerComparator();
72: }
73:
74: /* (non-Javadoc)
75: * @see org.eclipse.pde.internal.ui.editor.PDEProjectionSourcePage#isQuickOutlineEnabled()
76: */
77: public boolean isQuickOutlineEnabled() {
78: return true;
79: }
80:
81: }
|