KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > freemarker > eclipse > outline > OutlinePage


1 package freemarker.eclipse.outline;
2
3 import org.eclipse.jface.viewers.ISelection;
4 import org.eclipse.jface.viewers.IStructuredSelection;
5 import org.eclipse.jface.viewers.SelectionChangedEvent;
6 import org.eclipse.jface.viewers.TreeViewer;
7 import org.eclipse.swt.widgets.Composite;
8 import org.eclipse.swt.widgets.Control;
9 import org.eclipse.ui.views.contentoutline.ContentOutlinePage;
10
11 import freemarker.eclipse.editors.FreemarkerEditor;
12
13 /**
14  * @version $Id: OutlinePage.java,v 1.3 2003/08/15 19:49:08 stephanmueller Exp $
15  * @author <a HREF="mailto:stephan@chaquotay.net">Stephan Mueller</a>
16  */

17 public class OutlinePage extends ContentOutlinePage {
18     private FreemarkerEditor fEditor;
19     private Object JavaDoc fInput;
20     private String JavaDoc fSelectedNodeID;
21     private OutlineLabelProvider fLabelProvider;
22     
23     /**
24      * Creates a content outline page using the given editor.
25      */

26     public OutlinePage(FreemarkerEditor anEditor) {
27         fEditor = anEditor;
28     }
29
30     /**
31      * @see org.eclipse.ui.part.IPart#createControl(Composite)
32      */

33     public void createControl(Composite aParent) {
34         super.createControl(aParent);
35
36         fLabelProvider = new OutlineLabelProvider();
37
38         // Init tree viewer
39
TreeViewer viewer = getTreeViewer();
40         viewer.setContentProvider(new OutlineContentProvider(fEditor));
41         viewer.setLabelProvider(fLabelProvider);
42         viewer.addSelectionChangedListener(this);
43         if (fInput != null) {
44             viewer.setInput(fInput);
45         }
46         // Refresh outline according to initial cursor position
47
update();
48     }
49
50     /**
51      * @see org.eclipse.jface.viewers.ISelectionProvider#selectionChanged(SelectionChangedEvent)
52      */

53     public void selectionChanged(SelectionChangedEvent anEvent) {
54         super.selectionChanged(anEvent);
55         ISelection selection = anEvent.getSelection();
56
57         if (!selection.isEmpty()) {
58             Object JavaDoc tmp = ((IStructuredSelection) selection).getFirstElement();
59             if (tmp instanceof MacroNode) {
60                 MacroNode node = (MacroNode) tmp;
61                 fEditor.selectTextRange(
62                     node.getBeginLine(),
63                     node.getBeginColumn(),
64                     1);
65             }
66         }
67     }
68
69     /**
70      * Sets the input of the outline page.
71      */

72     public void setInput(Object JavaDoc aInput) {
73         fInput = aInput;
74         update();
75     }
76
77     /**
78      * Updates the outline page.
79      */

80     public void update() {
81         TreeViewer viewer = getTreeViewer();
82         if (viewer != null) {
83             Control control = viewer.getControl();
84             if (control != null && !control.isDisposed()) {
85                 viewer.removeSelectionChangedListener(this);
86                 control.setRedraw(false);
87                 viewer.setInput(fInput);
88                 control.setRedraw(true);
89                 viewer.addSelectionChangedListener(this);
90             }
91         }
92     }
93
94     /**
95      * @see org.eclipse.ui.part.Page#dispose()
96      */

97     public void dispose() {
98         super.dispose();
99     }
100
101 }
102
Popular Tags