1 13 package org.eclipse.ui.internal; 14 15 16 import org.eclipse.jface.action.MenuManager; 17 import org.eclipse.jface.internal.provisional.action.IToolBarManager2; 18 import org.eclipse.jface.util.IPropertyChangeListener; 19 import org.eclipse.jface.util.PropertyChangeEvent; 20 import org.eclipse.swt.SWT; 21 import org.eclipse.swt.events.MouseAdapter; 22 import org.eclipse.swt.events.MouseEvent; 23 import org.eclipse.swt.graphics.Point; 24 import org.eclipse.swt.graphics.Rectangle; 25 import org.eclipse.swt.widgets.Composite; 26 import org.eclipse.swt.widgets.Control; 27 import org.eclipse.swt.widgets.Menu; 28 import org.eclipse.swt.widgets.Shell; 29 import org.eclipse.swt.widgets.ToolBar; 30 import org.eclipse.ui.IViewReference; 31 import org.eclipse.ui.IWorkbenchPart; 32 import org.eclipse.ui.internal.dnd.DragUtil; 33 import org.eclipse.ui.internal.provisional.presentations.IActionBarPresentationFactory; 34 import org.eclipse.ui.presentations.IPresentablePart; 35 import org.eclipse.ui.presentations.StackPresentation; 36 37 42 public class ViewPane extends PartPane { 43 44 private IToolBarManager2 isvToolBarMgr = null; 47 48 private MenuManager isvMenuMgr; 49 50 boolean hasFocus; 51 52 55 private boolean hadViewMenu = false; 56 57 60 private class ISVPropListener implements IPropertyChangeListener { 61 private Control toolBar; 62 63 67 public ISVPropListener (Control toolBar) { 68 this.toolBar = toolBar; 69 } 70 71 74 public void propertyChange(PropertyChangeEvent event) { 75 String property = event.getProperty(); 76 Integer newValue = (Integer )event.getNewValue(); 77 if (IToolBarManager2.PROP_LAYOUT.equals(property)) { 78 toolBarResized(toolBar, newValue != null ? newValue.intValue() : 0); 79 if (toolBar instanceof Composite) { 80 ((Composite)toolBar).layout(); 81 } else { 82 toolBar.getParent().layout(); 83 } 84 } 85 } 86 } 87 88 91 class PaneMenuManager extends MenuManager { 92 public PaneMenuManager() { 93 super("View Local Menu"); } 95 96 protected void update(boolean force, boolean recursive) { 97 super.update(force, recursive); 98 99 boolean hasMenu = !isEmpty(); 100 if (hasMenu != hadViewMenu) { 101 hadViewMenu = hasMenu; 102 firePropertyChange(IPresentablePart.PROP_PANE_MENU); 103 } 104 } 105 } 106 107 110 public ViewPane(IViewReference ref, WorkbenchPage page) { 111 super(ref, page); 112 IActionBarPresentationFactory actionBarPresentation = ((WorkbenchWindow) page 113 .getWorkbenchWindow()).getActionBarPresentationFactory(); 114 115 isvToolBarMgr = actionBarPresentation.createViewToolBarManager(); 116 } 117 118 121 public void createControl(Composite parent) { 122 if (getControl() != null && !getControl().isDisposed()) { 124 return; 125 } 126 127 super.createControl(parent); 128 } 129 130 136 protected void createTitleBar() { 137 139 updateTitles(); 140 141 getPartReference().addPropertyListener(this); 143 144 createToolBars(); 145 146 } 147 148 private void toolBarResized(Control toolBar, int newSize) { 149 150 Control toolbar = isvToolBarMgr.getControl2(); 151 if (toolbar != null) { 152 Control ctrl = getControl(); 153 154 boolean visible = ctrl != null && ctrl.isVisible() 155 && toolbarIsVisible(); 156 157 toolbar.setVisible(visible); 158 } 159 160 firePropertyChange(IPresentablePart.PROP_TOOLBAR); 161 } 162 163 166 private void createToolBars() { 167 Composite parentControl = control; 168 169 final Control isvToolBar = isvToolBarMgr.createControl2(parentControl.getParent()); 172 173 isvToolBarMgr.addPropertyChangeListener(new ISVPropListener(isvToolBar)); 174 175 isvToolBar.addMouseListener(new MouseAdapter() { 176 public void mouseDoubleClick(MouseEvent event) { 177 if (event.widget instanceof ToolBar) { 178 179 if (((ToolBar)event.widget).getItem(new Point(event.x, event.y)) == null) { 180 doZoom(); 181 } 182 } 183 } 184 }); 185 186 187 isvToolBar.addListener(SWT.Activate, this); 188 isvToolBar.moveAbove(control); 189 } 190 191 public void dispose() { 192 super.dispose(); 193 194 200 if (isvMenuMgr != null) { 201 isvMenuMgr.dispose(); 202 } 203 if (isvToolBarMgr != null) { 204 isvToolBarMgr.dispose(); 205 } 206 } 207 208 211 public void doHide() { 212 getPage().hideView(getViewReference()); 213 } 214 215 Rectangle getParentBounds() { 216 Control ctrl = getControl(); 217 218 if (getContainer() != null && getContainer() instanceof LayoutPart) { 219 LayoutPart part = (LayoutPart) getContainer(); 220 221 if (part.getControl() != null) { 222 ctrl = part.getControl(); 223 } 224 } 225 226 return DragUtil.getDisplayBounds(ctrl); 227 } 228 229 232 public void doMakeFast() { 233 WorkbenchWindow window = (WorkbenchWindow) getPage() 234 .getWorkbenchWindow(); 235 236 FastViewBar fastViewBar = window.getFastViewBar(); 237 if (fastViewBar == null || getPage().getActivePerspective() == null) 238 return; 239 240 Shell shell = window.getShell(); 241 242 RectangleAnimation animation = new RectangleAnimation(shell, 243 getParentBounds(), fastViewBar.getLocationOfNextIcon()); 244 245 animation.schedule(); 246 247 FastViewManager fvm = getPage().getActivePerspective().getFastViewManager(); 248 fvm.addViewReference(FastViewBar.FASTVIEWBAR_ID, -1, getViewReference(), true); 249 } 250 251 public void doRemoveFast() { 252 if (getPage().getActivePerspective() == null) 253 return; 254 255 Shell shell = getControl().getShell(); 256 257 Rectangle initialBounds = getParentBounds(); 258 259 FastViewManager fvm = getPage().getActivePerspective().getFastViewManager(); 260 fvm.removeViewReference(getViewReference(), true, true); 261 262 IWorkbenchPart toActivate = getViewReference().getPart(true); 263 if (toActivate != null) { 264 getPage().activate(toActivate); 265 } 266 267 Rectangle finalBounds = getParentBounds(); 268 269 RectangleAnimation animation = new RectangleAnimation(shell, 270 initialBounds, finalBounds); 271 272 animation.schedule(); 273 } 274 275 278 protected void doDock() { 279 Perspective persp = getPage().getActivePerspective(); 280 if (persp != null) { 281 persp.getFastViewManager().removeViewReference(getViewReference(), true, true); 282 } 283 } 284 285 public void doDetach() { 286 getPage().detachView(getViewReference()); 287 } 288 289 public void doAttach() { 290 getPage().attachView(getViewReference()); 291 } 292 293 296 public String getCompoundId() { 297 IViewReference ref = getViewReference(); 298 if (ref != null) { 299 return ViewFactory.getKey(ref); 300 } 301 302 return super.getCompoundId(); 303 } 304 305 308 public Control getDragHandle() { 309 return control; 310 } 311 312 315 public MenuManager getMenuManager() { 316 if (isvMenuMgr == null) { 317 isvMenuMgr = new PaneMenuManager(); 318 } 319 return isvMenuMgr; 320 } 321 322 326 public Control[] getTabList() { 327 Control c = getControl(); 328 if (getContainer() instanceof ViewStack) { 329 ViewStack tf = (ViewStack) getContainer(); 330 return tf.getTabList(this); 331 } 332 return new Control[] { c }; 333 } 334 335 338 public IToolBarManager2 getToolBarManager() { 339 return isvToolBarMgr; 340 } 341 342 345 public IViewReference getViewReference() { 346 return (IViewReference) getPartReference(); 347 } 348 349 354 public void setFast(boolean b) { 355 } 356 357 360 361 void shellActivated() { 362 } 363 364 367 368 void shellDeactivated() { 369 } 370 371 375 void setActive(boolean active) { 376 hasFocus = active; 377 378 if (getContainer() instanceof PartStack) { 379 ((PartStack) getContainer()) 380 .setActive(active ? StackPresentation.AS_ACTIVE_FOCUS 381 : StackPresentation.AS_INACTIVE); 382 } 383 } 384 385 388 public void showFocus(boolean inFocus) { 389 setActive(inFocus); 390 } 391 392 395 private boolean isFastView() { 396 return page.isFastView(getViewReference()); 397 } 398 399 402 boolean isMoveable() { 403 return !page.isFixedLayout(); 404 } 405 406 412 public boolean hasViewMenu() { 413 414 if (isvMenuMgr != null) { 415 return !isvMenuMgr.isEmpty(); 416 } 417 418 return false; 419 } 420 421 public void showViewMenu(Point location) { 422 if (!hasViewMenu()) { 423 return; 424 } 425 426 if (isFastView() && (page.getActiveFastView() != getViewReference())) { 428 return; 429 } 430 431 Menu aMenu = isvMenuMgr.createContextMenu(getControl().getParent()); 432 aMenu.setLocation(location.x, location.y); 433 aMenu.setVisible(true); 434 } 435 436 public String toString() { 437 438 return getClass().getName() + "@" + Integer.toHexString(hashCode()); } 440 441 444 public void updateActionBars() { 445 if (isvMenuMgr != null) { 446 isvMenuMgr.updateAll(false); 447 } 448 if (isvToolBarMgr != null) { 449 isvToolBarMgr.update(false); 450 } 451 452 } 453 454 457 public void updateTitles() { 458 firePropertyChange(IPresentablePart.PROP_TITLE); 459 } 460 461 464 public void addSizeMenuItem(Menu menu, int index) { 465 if (isMoveable()) { 466 super.addSizeMenuItem(menu, index); 467 } 468 } 469 470 473 protected void doZoom() { 474 if (isMoveable()) { 475 super.doZoom(); 476 } 477 } 478 479 482 public void setContainer(ILayoutContainer container) { 483 ILayoutContainer oldContainer = getContainer(); 484 if (hasFocus) { 485 if (oldContainer != null && oldContainer instanceof PartStack) { 486 ((PartStack) oldContainer) 487 .setActive(StackPresentation.AS_INACTIVE); 488 } 489 490 if (container != null && container instanceof PartStack) { 491 ((PartStack) container) 492 .setActive(StackPresentation.AS_ACTIVE_FOCUS); 493 } 494 } 495 496 super.setContainer(container); 497 } 498 499 502 public void reparent(Composite newParent) { 503 super.reparent(newParent); 504 505 if (isvToolBarMgr != null) { 506 Control bar = isvToolBarMgr.getControl2(); 507 if (bar != null) { 508 bar.setParent(newParent); 509 bar.moveAbove(control); 510 } 511 } 512 } 513 514 517 public void moveAbove(Control refControl) { 518 super.moveAbove(refControl); 519 520 Control toolbar = internalGetToolbar(); 521 522 if (toolbar != null) { 523 toolbar.moveAbove(control); 524 } 525 } 526 527 530 public void setVisible(boolean makeVisible) { 531 super.setVisible(makeVisible); 532 533 Control toolbar = internalGetToolbar(); 534 535 if (toolbar != null) { 536 boolean visible = makeVisible && toolbarIsVisible(); 537 toolbar.setVisible(visible); 538 } 539 } 540 541 public boolean toolbarIsVisible() { 542 IToolBarManager2 toolbarManager = getToolBarManager(); 543 544 if (toolbarManager == null) { 545 return false; 546 } 547 548 Control control = toolbarManager.getControl2(); 549 550 if (control == null || control.isDisposed()) { 551 return false; 552 } 553 554 return toolbarManager.getItemCount() > 0; 555 } 556 557 560 public void showHighlight() { 561 firePropertyChange(IPresentablePart.PROP_HIGHLIGHT_IF_BACK); 562 } 563 564 567 public String getPlaceHolderId() { 568 return ViewFactory.getKey(getViewReference()); 569 } 570 571 574 public Control getToolBar() { 575 576 if (!toolbarIsVisible()) { 577 return null; 578 } 579 580 return internalGetToolbar(); 581 } 582 583 private Control internalGetToolbar() { 584 if (isvToolBarMgr == null) { 585 return null; 586 } 587 588 return isvToolBarMgr.getControl2(); 589 } 590 591 594 public boolean isCloseable() { 595 Perspective perspective = page.getActivePerspective(); 596 if (perspective == null) { 597 return true; 600 } 601 return perspective.isCloseable(getViewReference()); 602 } 603 604 public void showSystemMenu() { 605 if (isFastView()) { 606 Perspective perspective = page.getActivePerspective(); 607 if (perspective != null) { 608 perspective.getFastViewPane().showSystemMenu(); 609 } 610 } else { 611 super.showSystemMenu(); 612 } 613 } 614 615 public void showPaneMenu() { 616 if (isFastView()) { 617 Perspective perspective = page.getActivePerspective(); 618 if (perspective != null) { 619 perspective.getFastViewPane().showPaneMenu(); 620 } 621 } else { 622 super.showPaneMenu(); 623 } 624 } 625 626 public void removeContributions() { 627 super.removeContributions(); 628 629 if (isvMenuMgr != null) { 630 isvMenuMgr.removeAll(); 631 } 632 if (isvToolBarMgr != null) { 633 isvToolBarMgr.removeAll(); 634 } 635 } 636 } 637 | Popular Tags |