1 11 12 package org.eclipse.pde.internal.ui.editor; 13 14 import java.util.ArrayList ; 15 16 import org.eclipse.jface.text.IDocument; 17 import org.eclipse.jface.viewers.IBaseLabelProvider; 18 import org.eclipse.jface.viewers.IContentProvider; 19 import org.eclipse.jface.viewers.ISelectionChangedListener; 20 import org.eclipse.jface.viewers.TreeViewer; 21 import org.eclipse.jface.viewers.ViewerComparator; 22 import org.eclipse.pde.internal.core.text.IEditingModel; 23 import org.eclipse.pde.internal.core.text.IReconcilingParticipant; 24 import org.eclipse.swt.widgets.Composite; 25 import org.eclipse.swt.widgets.Control; 26 import org.eclipse.ui.part.IPageSite; 27 28 31 public class SourceOutlinePage extends PDEOutlinePage implements IReconcilingParticipant, ISortableContentOutlinePage{ 32 33 private IEditingModel fModel; 34 private IBaseLabelProvider fLabelProvider; 35 private IContentProvider fContentProvider; 36 private ViewerComparator fDefaultComparator; 37 private ViewerComparator fViewerComparator; 38 private boolean sorted; 39 TreeViewer viewer; 40 41 46 private ArrayList fListenerList; 47 48 public SourceOutlinePage(IEditingModel model, IBaseLabelProvider lProvider, 49 IContentProvider cProvider, ViewerComparator defaultComparator, 50 ViewerComparator comparator) { 51 super(); 52 fModel = model; 53 fLabelProvider = lProvider; 54 fContentProvider = cProvider; 55 fDefaultComparator = defaultComparator; 56 fViewerComparator = comparator; 57 fListenerList = new ArrayList (); 58 } 59 60 63 public void createControl(Composite parent) { 64 super.createControl(parent); 65 viewer= getTreeViewer(); 66 viewer.setContentProvider(fContentProvider); 67 viewer.setLabelProvider(fLabelProvider); 68 if(sorted) 69 viewer.setComparator(fViewerComparator); 70 else 71 viewer.setComparator(fDefaultComparator); 72 viewer.setInput(fModel); 73 viewer.expandAll(); 74 } 75 76 79 public void init(IPageSite pageSite) { 80 super.init(pageSite); 81 } 82 83 84 87 public void reconciled(IDocument document) { 88 final Control control = getControl(); 89 if (control == null || control.isDisposed()) 90 return; 91 control.getDisplay().asyncExec(new Runnable () { 92 public void run() { 93 if (control.isDisposed()) 94 return; 95 control.setRedraw(false); 96 removeAllSelectionChangedListeners(); 101 getTreeViewer().refresh(); 102 addAllSelectionChangedListeners(); 103 getTreeViewer().expandAll(); 104 control.setRedraw(true); 105 } 106 }); 107 } 108 109 112 public void sort (boolean sorting) { 113 sorted = sorting; 114 if (isViewerDefined()) { 115 if (sorting) { 116 viewer.setComparator(fViewerComparator); 117 } else { 118 viewer.setComparator(fDefaultComparator); 119 } 120 } 121 } 122 123 126 public void addAllSelectionChangedListeners() { 127 if (isViewerDefined()) { 130 viewer.addSelectionChangedListener(this); 131 } 132 for (int i = 0; i < fListenerList.size(); i++) { 134 super.addSelectionChangedListener( 135 (ISelectionChangedListener)fListenerList.get(i)); 136 } 137 } 138 139 142 private boolean isViewerDefined() { 143 if (viewer == null) { 144 return false; 145 } else if (viewer.getTree().isDisposed()) { 146 return false; 147 } 148 return true; 149 } 150 151 154 public void removeAllSelectionChangedListeners() { 155 if (isViewerDefined()) { 158 viewer.removeSelectionChangedListener(this); 159 } 160 for (int i = 0; i < fListenerList.size(); i++) { 162 super.removeSelectionChangedListener( 163 (ISelectionChangedListener)fListenerList.get(i)); 164 } 165 } 166 167 170 public void addSelectionChangedListener(ISelectionChangedListener listener) { 171 fListenerList.add(listener); 173 super.addSelectionChangedListener(listener); 174 } 175 176 179 public void removeSelectionChangedListener( 180 ISelectionChangedListener listener) { 181 fListenerList.remove(listener); 183 super.removeSelectionChangedListener(listener); 184 } 185 } 186 | Popular Tags |