~vil/pydev/upstream

« back to all changes in this revision

Viewing changes to org.python.pydev/src/org/python/pydev/outline/RawPartitionLabelProvider.java

  • Committer: Vladimír Lapáček
  • Date: 2006-08-30 18:38:44 UTC
  • Revision ID: vladimir.lapacek@gmail.com-20060830183844-f4d82c1239a7770a
Initial import of upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Author: atotic
 
3
 * Created: Jul 25, 2003
 
4
 * License: Common Public License v1.0
 
5
 */
 
6
package org.python.pydev.outline;
 
7
 
 
8
import org.eclipse.jface.text.BadLocationException;
 
9
import org.eclipse.jface.text.IDocument;
 
10
import org.eclipse.jface.text.Position;
 
11
import org.eclipse.jface.viewers.LabelProvider;
 
12
 
 
13
 
 
14
/*
 
15
 * In RawPartition, elements are Position markers inside the document
 
16
 * we need reference to the document to get its text.
 
17
 * I whish I had access to DocumentAdapter in SourceViewer, but I do not
 
18
 */
 
19
class RawPartitionLabelProvider extends LabelProvider {
 
20
 
 
21
        IDocument document;
 
22
 
 
23
        RawPartitionLabelProvider(IDocument document) {
 
24
                this.document = document;
 
25
        }
 
26
        
 
27
        /** 
 
28
         * @param element is a org.eclipse.jface.text.Position
 
29
         */
 
30
        public String getText(Object element) {
 
31
                Position p = (Position)element;
 
32
                try {
 
33
                        // get the text from the document, truncate if needed
 
34
                        boolean trim = p.length > 50;
 
35
                        String text = document.get(p.offset, trim ? 30 : p.length);
 
36
                        if (trim) {
 
37
                                text += "...";
 
38
                        }
 
39
                        return text;
 
40
                } catch (BadLocationException e) {
 
41
                        System.err.println(
 
42
                                "PyOutlinePage::OutlineLabelProvider unexpected error");
 
43
                        e.printStackTrace();
 
44
                        return "";
 
45
                }
 
46
        }
 
47
}
 
 
b'\\ No newline at end of file'