1 11 package org.eclipse.compare; 12 13 import org.eclipse.core.runtime.*; 14 import org.eclipse.jface.action.ToolBarManager; 15 import org.eclipse.jface.viewers.*; 16 import org.eclipse.swt.SWT; 17 import org.eclipse.swt.accessibility.*; 18 import org.eclipse.swt.custom.CLabel; 19 import org.eclipse.swt.custom.ViewForm; 20 import org.eclipse.swt.events.*; 21 import org.eclipse.swt.graphics.Image; 22 import org.eclipse.swt.graphics.Point; 23 import org.eclipse.swt.widgets.*; 24 25 37 public class CompareViewerPane extends ViewForm implements ISelectionProvider, 38 IDoubleClickListener, ISelectionChangedListener, IOpenListener, IAdaptable { 39 40 private ToolBarManager fToolBarManager; 41 private Object fInput; 42 private ListenerList fSelectionListeners= new ListenerList(); 43 private ListenerList fDoubleClickListener= new ListenerList(); 44 private ListenerList fOpenListener= new ListenerList(); 45 46 60 public CompareViewerPane(Composite container, int style) { 61 super(container, style); 62 63 marginWidth= 0; 64 marginHeight= 0; 65 66 CLabel label= new CLabel(this, SWT.NONE) { 67 public Point computeSize(int wHint, int hHint, boolean changed) { 68 return super.computeSize(wHint, Math.max(24, hHint), changed); 69 } 70 }; 71 setTopLeft(label); 72 73 MouseAdapter ml= new MouseAdapter() { 74 public void mouseDoubleClick(MouseEvent e) { 75 Control content= getContent(); 76 if (content != null && content.getBounds().contains(e.x, e.y)) 77 return; 78 Control parent= getParent(); 79 if (parent instanceof Splitter) 80 ((Splitter)parent).setMaximizedControl(CompareViewerPane.this); 81 } 82 }; 83 84 addMouseListener(ml); 85 label.addMouseListener(ml); 86 87 addDisposeListener(new DisposeListener() { 88 public void widgetDisposed(DisposeEvent e) { 89 if (fToolBarManager != null) { 90 fToolBarManager.removeAll(); 91 fToolBarManager.dispose(); 92 } 93 fInput= null; 94 fSelectionListeners= null; 95 setImage(null); 96 } 97 }); 98 } 99 100 106 public void setText(String label) { 107 CLabel cl= (CLabel) getTopLeft(); 108 if (cl != null && !cl.isDisposed()) 109 cl.setText(label); 110 } 111 112 118 public void setImage(Image image) { 119 CLabel cl= (CLabel) getTopLeft(); 120 if (cl != null) 121 cl.setImage(image); 122 } 123 124 131 public static ToolBarManager getToolBarManager(Composite parent) { 132 if (parent instanceof CompareViewerPane) { 133 CompareViewerPane pane= (CompareViewerPane) parent; 134 return pane.getToolBarManager(); 135 } 136 return null; 137 } 138 139 144 public static void clearToolBar(Composite parent) { 145 ToolBarManager tbm= getToolBarManager(parent); 146 if (tbm != null) { 147 tbm.removeAll(); 148 tbm.update(true); 149 } 150 } 151 152 154 private ToolBarManager getToolBarManager() { 155 if (fToolBarManager != null && fToolBarManager.getControl() == null) 156 return null; 157 if (fToolBarManager == null) { 158 final ToolBar tb = new ToolBar(this, SWT.FLAT); 159 setTopCenter(tb); 160 fToolBarManager = new ToolBarManager(tb); 161 tb.getAccessible().addAccessibleListener(new AccessibleAdapter() { 162 public void getName(AccessibleEvent e) { 163 if (e.childID != ACC.CHILDID_SELF) { 164 ToolItem item = tb.getItem(e.childID); 165 if (item != null) { 166 String toolTip = item.getToolTipText(); 167 if (toolTip != null) { 168 e.result = toolTip; 169 } 170 } 171 } 172 } 173 }); 174 } 175 return fToolBarManager; 176 } 177 178 185 public Object getInput() { 186 return fInput; 187 } 188 189 195 public void setInput(Object input) { 196 if (fInput != input) 197 fInput= input; 198 } 199 200 203 public void addSelectionChangedListener(ISelectionChangedListener l) { 204 fSelectionListeners.add(l); 205 } 206 207 210 public void removeSelectionChangedListener(ISelectionChangedListener l) { 211 fSelectionListeners.remove(l); 212 } 213 214 217 public ISelection getSelection() { 218 return null; 219 } 220 221 224 public void setSelection(ISelection s) { 225 } 227 228 231 public void selectionChanged(SelectionChangedEvent ev) { 232 Object [] listeners= fSelectionListeners.getListeners(); 233 for (int i= 0; i < listeners.length; i++) 234 ((ISelectionChangedListener) listeners[i]).selectionChanged(ev); 235 } 236 237 240 public void doubleClick(DoubleClickEvent event) { 241 Object [] listeners= fDoubleClickListener.getListeners(); 242 for (int i= 0; i < listeners.length; i++) 243 ((IDoubleClickListener) listeners[i]).doubleClick(event); 244 } 245 246 253 public void addDoubleClickListener(IDoubleClickListener listener) { 254 fDoubleClickListener.add(listener); 255 } 256 257 263 public void removeDoubleClickListener(IDoubleClickListener listener) { 264 fDoubleClickListener.remove(listener); 265 } 266 267 274 public void addOpenListener(IOpenListener listener) { 275 fOpenListener.add(listener); 276 } 277 278 284 public void removeOpenListener(IOpenListener listener) { 285 fOpenListener.remove(listener); 286 } 287 288 291 public void open(OpenEvent event) { 292 Object [] listeners= fOpenListener.getListeners(); 293 for (int i= 0; i < listeners.length; i++) 294 ((IOpenListener) listeners[i]).open(event); 295 } 296 297 300 public Object getAdapter(Class adapter) { 301 return Platform.getAdapterManager().getAdapter(this, adapter); 302 } 303 } 304 | Popular Tags |