1 11 package org.eclipse.compare.internal; 12 13 import org.eclipse.compare.*; 14 import org.eclipse.compare.structuremergeviewer.ICompareInput; 15 import org.eclipse.jface.util.IPropertyChangeListener; 16 import org.eclipse.jface.util.PropertyChangeEvent; 17 import org.eclipse.jface.viewers.*; 18 import org.eclipse.swt.SWT; 19 import org.eclipse.swt.widgets.Composite; 20 import org.eclipse.swt.widgets.Control; 21 import org.eclipse.ui.part.IPageSite; 22 import org.eclipse.ui.part.Page; 23 import org.eclipse.ui.views.contentoutline.IContentOutlinePage; 24 25 27 public class CompareOutlinePage extends Page implements IContentOutlinePage, IPropertyChangeListener { 28 29 private CompareEditor fCompareEditor; 30 private Control fControl; 31 private CompareViewerSwitchingPane fStructurePane; 32 private OutlineViewerCreator fCreator; 33 34 CompareOutlinePage(CompareEditor editor) { 35 fCompareEditor= editor; 36 } 37 38 41 public void createControl(Composite parent) { 42 final Splitter h= new Splitter(parent, SWT.HORIZONTAL); 43 fStructurePane= new CompareViewerSwitchingPane(h, SWT.BORDER | SWT.FLAT, true) { 44 protected Viewer getViewer(Viewer oldViewer, Object input) { 45 if (input instanceof ICompareInput) 46 return findStructureViewer(oldViewer, (ICompareInput)input, this); 47 return null; 48 } 49 }; 50 h.setVisible(fStructurePane, true); 51 fControl = h; 52 IPageSite site = getSite(); 53 site.setSelectionProvider(fStructurePane); 54 h.layout(); 55 reset(); 56 } 57 58 private Viewer findStructureViewer(Viewer oldViewer, ICompareInput input, Composite parent) { 59 OutlineViewerCreator creator = getCreator(); 60 if (creator != null) 61 return creator.findStructureViewer(oldViewer, input, parent, getCompareConfiguration()); 62 return null; 63 } 64 65 private CompareConfiguration getCompareConfiguration() { 66 return fCompareEditor.getCompareConfiguration(); 67 } 68 69 72 public Control getControl() { 73 return fControl; 74 } 75 76 79 public void setFocus() { 80 if (fStructurePane != null) 81 fStructurePane.setFocus(); 82 } 83 84 87 public void addSelectionChangedListener(ISelectionChangedListener listener) { 88 if (fStructurePane != null) 89 fStructurePane.addSelectionChangedListener(listener); 90 } 91 92 95 public ISelection getSelection() { 96 if (fStructurePane != null) 97 return fStructurePane.getSelection(); 98 return StructuredSelection.EMPTY; 99 } 100 101 104 public void removeSelectionChangedListener(ISelectionChangedListener listener) { 105 if (fStructurePane != null) 106 fStructurePane.removeSelectionChangedListener(listener); 107 } 108 109 112 public void setSelection(ISelection selection) { 113 if (fStructurePane != null) 114 fStructurePane.setSelection(selection); 115 } 116 117 private void setInput(Object input) { 118 if (fStructurePane != null) { 119 fStructurePane.setInput(input); 120 ((Splitter)fControl).layout(); 121 } 122 } 123 124 public OutlineViewerCreator getCreator() { 125 if (fCreator == null) { 126 fCreator = (OutlineViewerCreator)Utilities.getAdapter(fCompareEditor, OutlineViewerCreator.class); 127 if (fCreator != null) 128 fCreator.addPropertyChangeListener(this); 129 } 130 return fCreator; 131 } 132 133 public void propertyChange(PropertyChangeEvent event) { 134 if (event.getProperty().equals(OutlineViewerCreator.PROP_INPUT)) { 135 fStructurePane.setInput(event.getNewValue()); 136 ((Splitter)fControl).layout(); 137 } 138 } 139 140 public void dispose() { 141 super.dispose(); 142 if (fCreator != null) 143 fCreator.removePropertyChangeListener(this); 144 fCreator = null; 145 } 146 147 public void reset() { 148 if (fCreator != null) 149 fCreator.removePropertyChangeListener(this); 150 fCreator = null; 151 OutlineViewerCreator creator = getCreator(); 152 if (creator != null) 153 setInput(creator.getInput()); 154 else 155 setInput(null); 156 } 157 } 158 | Popular Tags |