1 13 package org.eclipse.ui.internal; 14 15 import org.eclipse.swt.SWT; 16 import org.eclipse.swt.graphics.Point; 17 import org.eclipse.swt.graphics.Rectangle; 18 import org.eclipse.swt.widgets.Composite; 19 import org.eclipse.swt.widgets.Control; 20 import org.eclipse.swt.widgets.Shell; 21 import org.eclipse.ui.ISizeProvider; 22 import org.eclipse.ui.IWorkbenchWindow; 23 import org.eclipse.ui.internal.dnd.IDropTarget; 24 import org.eclipse.ui.internal.dnd.SwtUtil; 25 26 30 abstract public class LayoutPart implements ISizeProvider { 31 protected ILayoutContainer container; 32 33 protected String id; 34 35 public static final String PROP_VISIBILITY = "PROP_VISIBILITY"; 37 41 private int deferCount = 0; 42 43 46 public LayoutPart(String id) { 47 super(); 48 this.id = id; 49 } 50 51 63 public boolean allowsAutoFocus() { 64 if (container != null) { 65 return container.allowsAutoFocus(); 66 } 67 return true; 68 } 69 70 71 74 abstract public void createControl(Composite parent); 75 76 79 public void dispose() { 80 } 81 82 85 public Rectangle getBounds() { 86 return new Rectangle(0, 0, 0, 0); 87 } 88 89 104 public ILayoutContainer getContainer() { 105 return container; 106 } 107 108 111 abstract public Control getControl(); 112 113 116 public String getID() { 117 return id; 118 } 119 120 126 public String getCompoundId() { 127 return getID(); 128 } 129 130 public boolean isCompressible() { 131 return false; 132 } 133 134 137 public Point getSize() { 138 Rectangle r = getBounds(); 139 Point ptSize = new Point(r.width, r.height); 140 return ptSize; 141 } 142 143 148 public int getSizeFlags(boolean horizontal) { 149 return SWT.MIN; 150 } 151 152 157 public int computePreferredSize(boolean width, int availableParallel, int availablePerpendicular, int preferredParallel) { 158 159 return preferredParallel; 160 } 161 162 public IDropTarget getDropTarget(Object draggedObject, Point displayCoordinates) { 163 return null; 164 } 165 166 public boolean isDocked() { 167 Shell s = getShell(); 168 if (s == null) { 169 return false; 170 } 171 172 return s.getData() instanceof IWorkbenchWindow; 173 } 174 175 public Shell getShell() { 176 Control ctrl = getControl(); 177 if (!SwtUtil.isDisposed(ctrl)) { 178 return ctrl.getShell(); 179 } 180 return null; 181 } 182 183 189 public IWorkbenchWindow getWorkbenchWindow() { 190 Shell s = getShell(); 191 if (s==null) { 192 return null; 193 } 194 Object data = s.getData(); 195 if (data instanceof IWorkbenchWindow) { 196 return (IWorkbenchWindow)data; 197 } else if (data instanceof DetachedWindow) { 198 return ((DetachedWindow) data).getWorkbenchPage() 199 .getWorkbenchWindow(); 200 } 201 202 return null; 203 204 } 205 206 209 public void moveAbove(Control refControl) { 210 } 211 212 215 public void reparent(Composite newParent) { 216 Control control = getControl(); 217 if ((control == null) || (control.getParent() == newParent)) { 218 return; 219 } 220 221 if (control.isReparentable()) { 222 boolean enabled = control.getEnabled(); 228 control.setEnabled(false); 229 control.setParent(newParent); 230 control.setEnabled(enabled); 231 control.moveAbove(null); 232 } 233 } 234 235 240 public boolean getVisible() { 241 Control ctrl = getControl(); 242 if (!SwtUtil.isDisposed(ctrl)) { 243 return ctrl.getVisible(); 244 } 245 return false; 246 } 247 248 252 public boolean isVisible() { 253 Control ctrl = getControl(); 254 if (ctrl != null && !ctrl.isDisposed()) { 255 return ctrl.isVisible(); 256 } 257 return false; 258 } 259 260 263 public void setVisible(boolean makeVisible) { 264 Control ctrl = getControl(); 265 if (!SwtUtil.isDisposed(ctrl)) { 266 if (makeVisible == ctrl.getVisible()) { 267 return; 268 } 269 270 if (!makeVisible && isFocusAncestor(ctrl)) { 271 ctrl.getShell().forceFocus(); 277 } 278 279 ctrl.setVisible(makeVisible); 280 } 281 } 282 283 286 private boolean isFocusAncestor(Control ctrl) { 287 Control f = ctrl.getDisplay().getFocusControl(); 288 while (f != null && f != ctrl) { 289 f = f.getParent(); 290 } 291 return f == ctrl; 292 } 293 294 297 public void setBounds(Rectangle r) { 298 Control ctrl = getControl(); 299 if (!SwtUtil.isDisposed(ctrl)) { 300 ctrl.setBounds(r); 301 } 302 } 303 304 307 public void setContainer(ILayoutContainer container) { 308 309 this.container = container; 310 311 if (container != null) { 312 setZoomed(container.childIsZoomed(this)); 313 } 314 } 315 316 319 public void setFocus() { 320 } 321 322 325 public void setID(String str) { 326 id = str; 327 } 328 329 332 public LayoutPart getPart() { 333 return this; 334 } 335 336 public void childRequestZoomIn(LayoutPart toZoom) { 337 338 } 339 340 public void childRequestZoomOut() { 341 342 } 343 344 public final void requestZoomOut() { 345 ILayoutContainer container = getContainer(); 346 if (container != null) { 347 container.childRequestZoomOut(); 348 } 349 } 350 351 public final void requestZoomIn() { 352 ILayoutContainer container = getContainer(); 353 if (container != null) { 354 container.childRequestZoomIn(this); 355 } 356 } 357 358 public final boolean isObscuredByZoom() { 359 ILayoutContainer container = getContainer(); 360 361 if (container != null) { 362 return container.childObscuredByZoom(this); 363 } 364 365 return false; 366 } 367 368 public boolean childObscuredByZoom(LayoutPart toTest) { 369 return false; 370 } 371 372 public boolean childIsZoomed(LayoutPart childToTest) { 373 return false; 374 } 375 376 public void setZoomed(boolean isZoomed) { 377 378 } 379 380 390 public final void deferUpdates(boolean shouldDefer) { 391 if (shouldDefer) { 392 if (deferCount == 0) { 393 startDeferringEvents(); 394 } 395 deferCount++; 396 } else { 397 if (deferCount > 0) { 398 deferCount--; 399 if (deferCount == 0) { 400 handleDeferredEvents(); 401 } 402 } 403 } 404 } 405 406 411 protected void startDeferringEvents() { 412 413 } 414 415 421 protected void handleDeferredEvents() { 422 423 } 424 425 434 protected final boolean isDeferred() { 435 return deferCount > 0; 436 } 437 438 448 public void describeLayout(StringBuffer buf) { 449 450 } 451 452 457 public String getPlaceHolderId() { 458 return getID(); 459 } 460 461 public void resizeChild(LayoutPart childThatChanged) { 462 463 } 464 465 public void flushLayout() { 466 ILayoutContainer container = getContainer(); 467 if (getContainer() != null) { 468 container.resizeChild(this); 469 } 470 } 471 472 478 public boolean allowsAdd(LayoutPart toAdd) { 479 return false; 480 } 481 482 486 public void testInvariants() { 487 } 488 } 489 | Popular Tags |