KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > editor > KeyValueSourcePage


1 /*******************************************************************************
2  * Copyright (c) 2003, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

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 JavaDoc id, String JavaDoc title) {
23         super(editor, id, title);
24     }
25
26     /* (non-Javadoc)
27      * @see org.eclipse.pde.internal.ui.neweditor.PDESourcePage#createViewerSorter()
28      */

29     public ViewerComparator createDefaultOutlineComparator() {
30         return new ViewerComparator() {
31             public int compare(Viewer viewer, Object JavaDoc e1, Object JavaDoc 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                 // Bundle manifest header elements
39
// Do not sort by default
40
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     /* (non-Javadoc)
66      * @see org.eclipse.pde.internal.ui.editor.PDESourcePage#createOutlineSorter()
67      */

68     public ViewerComparator createOutlineComparator() {
69         return new ViewerComparator();
70     }
71
72     /* (non-Javadoc)
73      * @see org.eclipse.pde.internal.ui.editor.PDEProjectionSourcePage#isQuickOutlineEnabled()
74      */

75     public boolean isQuickOutlineEnabled() {
76         return true;
77     }
78     
79 }
80
Popular Tags