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 17 public class OutlinePage extends ContentOutlinePage { 18 private FreemarkerEditor fEditor; 19 private Object fInput; 20 private String fSelectedNodeID; 21 private OutlineLabelProvider fLabelProvider; 22 23 26 public OutlinePage(FreemarkerEditor anEditor) { 27 fEditor = anEditor; 28 } 29 30 33 public void createControl(Composite aParent) { 34 super.createControl(aParent); 35 36 fLabelProvider = new OutlineLabelProvider(); 37 38 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 update(); 48 } 49 50 53 public void selectionChanged(SelectionChangedEvent anEvent) { 54 super.selectionChanged(anEvent); 55 ISelection selection = anEvent.getSelection(); 56 57 if (!selection.isEmpty()) { 58 Object 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 72 public void setInput(Object aInput) { 73 fInput = aInput; 74 update(); 75 } 76 77 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 97 public void dispose() { 98 super.dispose(); 99 } 100 101 } 102 | Popular Tags |