1 11 package org.eclipse.ui.internal; 12 13 import java.util.ArrayList ; 14 import java.util.HashMap ; 15 import java.util.Map ; 16 17 import org.eclipse.core.runtime.IStatus; 18 import org.eclipse.jface.action.CoolBarManager; 19 import org.eclipse.jface.action.IAction; 20 import org.eclipse.jface.action.IContributionItem; 21 import org.eclipse.jface.action.ICoolBarManager; 22 import org.eclipse.jface.action.IMenuManager; 23 import org.eclipse.jface.action.IStatusLineManager; 24 import org.eclipse.jface.action.IToolBarManager; 25 import org.eclipse.jface.internal.provisional.action.ICoolBarManager2; 26 import org.eclipse.jface.internal.provisional.action.IToolBarContributionItem; 27 import org.eclipse.jface.window.Window; 28 import org.eclipse.osgi.util.TextProcessor; 29 import org.eclipse.swt.SWT; 30 import org.eclipse.swt.dnd.DropTarget; 31 import org.eclipse.swt.dnd.DropTargetListener; 32 import org.eclipse.swt.dnd.Transfer; 33 import org.eclipse.swt.graphics.Point; 34 import org.eclipse.swt.widgets.Composite; 35 import org.eclipse.swt.widgets.Control; 36 import org.eclipse.swt.widgets.Menu; 37 import org.eclipse.swt.widgets.Shell; 38 import org.eclipse.ui.IMemento; 39 import org.eclipse.ui.IWorkbenchPage; 40 import org.eclipse.ui.IWorkbenchPreferenceConstants; 41 import org.eclipse.ui.IWorkbenchWindow; 42 import org.eclipse.ui.application.IActionBarConfigurer; 43 import org.eclipse.ui.application.IWorkbenchConfigurer; 44 import org.eclipse.ui.application.IWorkbenchWindowConfigurer; 45 import org.eclipse.ui.application.WorkbenchAdvisor; 46 import org.eclipse.ui.internal.StartupThreading.StartupRunnable; 47 import org.eclipse.ui.internal.presentations.r33.WorkbenchPresentationFactory_33; 48 import org.eclipse.ui.internal.provisional.application.IActionBarConfigurer2; 49 import org.eclipse.ui.internal.provisional.presentations.IActionBarPresentationFactory; 50 import org.eclipse.ui.internal.util.PrefUtil; 51 import org.eclipse.ui.presentations.AbstractPresentationFactory; 52 53 65 public final class WorkbenchWindowConfigurer implements 66 IWorkbenchWindowConfigurer { 67 68 71 private WorkbenchWindow window; 72 73 76 private int shellStyle = SWT.SHELL_TRIM | Window.getDefaultOrientation(); 77 78 81 private String windowTitle; 82 83 86 private boolean showFastViewBars = false; 87 88 91 private boolean showPerspectiveBar = false; 92 93 96 private boolean showStatusLine = true; 97 98 101 private boolean showToolBar = true; 102 103 106 private boolean showMenuBar = true; 107 108 111 private boolean showProgressIndicator = false; 112 113 118 private Map extraData = new HashMap (1); 119 120 124 private ArrayList transferTypes = new ArrayList (3); 125 126 130 private DropTargetListener dropTargetListener = null; 131 132 136 private WindowActionBarConfigurer actionBarConfigurer = null; 137 138 141 private Point initialSize = new Point(1024, 768); 142 143 147 private AbstractPresentationFactory presentationFactory = null; 148 149 153 class WindowActionBarConfigurer implements IActionBarConfigurer2 { 154 155 private IActionBarConfigurer2 proxy; 156 157 162 public void setProxy(IActionBarConfigurer2 proxy) { 163 this.proxy = proxy; 164 } 165 166 169 public IWorkbenchWindowConfigurer getWindowConfigurer() { 170 return window.getWindowConfigurer(); 171 } 172 173 180 boolean containsCoolItem(String id) { 181 ICoolBarManager cbManager = getCoolBarManager(); 182 if (cbManager == null) { 183 return false; 184 } 185 IContributionItem cbItem = cbManager.find(id); 186 if (cbItem == null) { 187 return false; 188 } 189 return true; 191 } 192 193 196 public IStatusLineManager getStatusLineManager() { 197 if (proxy != null) { 198 return proxy.getStatusLineManager(); 199 } 200 return window.getStatusLineManager(); 201 } 202 203 206 public IMenuManager getMenuManager() { 207 if (proxy != null) { 208 return proxy.getMenuManager(); 209 } 210 return window.getMenuManager(); 211 } 212 213 216 public ICoolBarManager getCoolBarManager() { 217 if (proxy != null) { 218 return proxy.getCoolBarManager(); 219 } 220 return window.getCoolBarManager2(); 221 } 222 223 226 public void registerGlobalAction(IAction action) { 227 if (proxy != null) { 228 proxy.registerGlobalAction(action); 229 } 230 window.registerGlobalAction(action); 231 } 232 233 private IActionBarPresentationFactory getActionBarPresentationFactory() { 234 WorkbenchWindow window = (WorkbenchWindow)getWindowConfigurer().getWindow(); 235 return window.getActionBarPresentationFactory(); 236 } 237 238 241 public IToolBarManager createToolBarManager() { 242 if (proxy != null) { 243 return proxy.createToolBarManager(); 244 } 245 return getActionBarPresentationFactory().createToolBarManager(); 246 } 247 248 251 public IToolBarContributionItem createToolBarContributionItem(IToolBarManager toolBarManager, String id) { 252 if (proxy != null) { 253 return proxy.createToolBarContributionItem(toolBarManager, id); 254 } 255 return getActionBarPresentationFactory().createToolBarContributionItem(toolBarManager, id); 256 } 257 } 258 259 270 WorkbenchWindowConfigurer(WorkbenchWindow window) { 271 if (window == null) { 272 throw new IllegalArgumentException (); 273 } 274 this.window = window; 275 windowTitle = WorkbenchPlugin.getDefault().getProductName(); 276 if (windowTitle == null) { 277 windowTitle = ""; } 279 } 280 281 284 public IWorkbenchWindow getWindow() { 285 return window; 286 } 287 288 291 public IWorkbenchConfigurer getWorkbenchConfigurer() { 292 return Workbench.getInstance().getWorkbenchConfigurer(); 293 } 294 295 300 String basicGetTitle() { 301 return windowTitle; 302 } 303 304 307 public String getTitle() { 308 Shell shell = window.getShell(); 309 if (shell != null) { 310 windowTitle = shell.getText(); 312 } 313 return windowTitle; 314 } 315 316 319 public void setTitle(String title) { 320 if (title == null) { 321 throw new IllegalArgumentException (); 322 } 323 windowTitle = title; 324 Shell shell = window.getShell(); 325 if (shell != null && !shell.isDisposed()) { 326 shell.setText(TextProcessor.process(title, WorkbenchWindow.TEXT_DELIMITERS)); 327 } 328 } 329 330 333 public boolean getShowMenuBar() { 334 return showMenuBar; 335 } 336 337 340 public void setShowMenuBar(boolean show) { 341 showMenuBar = show; 342 WorkbenchWindow win = (WorkbenchWindow) getWindow(); 343 Shell shell = win.getShell(); 344 if (shell != null) { 345 boolean showing = shell.getMenuBar() != null; 346 if (show != showing) { 347 if (show) { 348 shell.setMenuBar(win.getMenuBarManager().getMenu()); 349 } else { 350 shell.setMenuBar(null); 351 } 352 } 353 } 354 } 355 356 359 public boolean getShowCoolBar() { 360 return showToolBar; 361 } 362 363 366 public void setShowCoolBar(boolean show) { 367 showToolBar = show; 368 window.setCoolBarVisible(show); 369 } 371 372 375 public boolean getShowFastViewBars() { 376 return showFastViewBars; 377 } 378 379 382 public void setShowFastViewBars(boolean show) { 383 showFastViewBars = show; 384 window.setFastViewBarVisible(show); 385 } 387 388 391 public boolean getShowPerspectiveBar() { 392 return showPerspectiveBar; 393 } 394 395 398 public void setShowPerspectiveBar(boolean show) { 399 showPerspectiveBar = show; 400 window.setPerspectiveBarVisible(show); 401 } 403 404 407 public boolean getShowStatusLine() { 408 return showStatusLine; 409 } 410 411 414 public void setShowStatusLine(boolean show) { 415 showStatusLine = show; 416 } 418 419 422 public boolean getShowProgressIndicator() { 423 return showProgressIndicator; 424 } 425 426 429 public void setShowProgressIndicator(boolean show) { 430 showProgressIndicator = show; 431 } 433 434 437 public Object getData(String key) { 438 if (key == null) { 439 throw new IllegalArgumentException (); 440 } 441 return extraData.get(key); 442 } 443 444 447 public void setData(String key, Object data) { 448 if (key == null) { 449 throw new IllegalArgumentException (); 450 } 451 if (data != null) { 452 extraData.put(key, data); 453 } else { 454 extraData.remove(key); 455 } 456 } 457 458 461 public void addEditorAreaTransfer(Transfer tranfer) { 462 if (tranfer != null && !transferTypes.contains(tranfer)) { 463 transferTypes.add(tranfer); 464 Transfer[] transfers = new Transfer[transferTypes.size()]; 465 transferTypes.toArray(transfers); 466 IWorkbenchPage[] pages = window.getPages(); 467 for (int i = 0; i < pages.length; i++) { 468 WorkbenchPage page = (WorkbenchPage) pages[i]; 469 DropTarget dropTarget = ((EditorSashContainer) page 470 .getEditorPresentation().getLayoutPart()) 471 .getDropTarget(); 472 if (dropTarget != null) { 473 dropTarget.setTransfer(transfers); 474 } 475 } 476 } 477 } 478 479 482 public void configureEditorAreaDropListener( 483 DropTargetListener dropTargetListener) { 484 if (dropTargetListener != null) { 485 this.dropTargetListener = dropTargetListener; 486 IWorkbenchPage[] pages = window.getPages(); 487 for (int i = 0; i < pages.length; i++) { 488 WorkbenchPage page = (WorkbenchPage) pages[i]; 489 DropTarget dropTarget = ((EditorSashContainer) page 490 .getEditorPresentation().getLayoutPart()) 491 .getDropTarget(); 492 if (dropTarget != null) { 493 dropTarget.addDropListener(this.dropTargetListener); 494 } 495 } 496 } 497 } 498 499 502 Transfer[] getTransfers() { 503 Transfer[] transfers = new Transfer[transferTypes.size()]; 504 transferTypes.toArray(transfers); 505 return transfers; 506 } 507 508 511 DropTargetListener getDropTargetListener() { 512 return dropTargetListener; 513 } 514 515 518 public IActionBarConfigurer getActionBarConfigurer() { 519 if (actionBarConfigurer == null) { 520 actionBarConfigurer = new WindowActionBarConfigurer(); 522 } 523 return actionBarConfigurer; 524 } 525 526 533 boolean containsCoolItem(String id) { 534 getActionBarConfigurer(); 536 return actionBarConfigurer.containsCoolItem(id); 537 } 538 539 542 public int getShellStyle() { 543 return shellStyle; 544 } 545 546 549 public void setShellStyle(int shellStyle) { 550 this.shellStyle = shellStyle; 551 } 552 553 556 public Point getInitialSize() { 557 return initialSize; 558 } 559 560 563 public void setInitialSize(Point size) { 564 initialSize = size; 565 } 566 567 570 public AbstractPresentationFactory getPresentationFactory() { 571 if (presentationFactory == null) { 572 presentationFactory = createDefaultPresentationFactory(); 573 } 574 return presentationFactory; 575 } 576 577 583 private AbstractPresentationFactory createDefaultPresentationFactory() { 584 final String factoryId = ((Workbench) window.getWorkbench()) 585 .getPresentationId(); 586 587 if (factoryId != null && factoryId.length() > 0) { 588 final AbstractPresentationFactory [] factory = new AbstractPresentationFactory[1]; 589 StartupThreading.runWithoutExceptions(new StartupRunnable() { 590 591 public void runWithException() throws Throwable { 592 factory[0] = WorkbenchPlugin.getDefault() 593 .getPresentationFactory(factoryId); 594 } 595 }); 596 597 if (factory[0] != null) { 598 return factory[0]; 599 } 600 } 601 PrefUtil.getAPIPreferenceStore().setValue( 603 IWorkbenchPreferenceConstants.PRESENTATION_FACTORY_ID, 604 IWorkbenchConstants.DEFAULT_PRESENTATION_ID); 605 return new WorkbenchPresentationFactory_33(); 606 } 607 608 611 public void setPresentationFactory(AbstractPresentationFactory factory) { 612 if (factory == null) { 613 throw new IllegalArgumentException (); 614 } 615 presentationFactory = factory; 616 } 617 618 623 public void createDefaultContents(Shell shell) { 624 window.createDefaultContents(shell); 625 } 626 627 630 public Menu createMenuBar() { 631 return window.getMenuManager().createMenuBar(window.getShell()); 632 } 633 634 637 public Control createCoolBarControl(Composite parent) { 638 ICoolBarManager coolBarManager = window.getCoolBarManager2(); 639 if (coolBarManager != null) { 640 if (coolBarManager instanceof ICoolBarManager2) { 641 return ((ICoolBarManager2) coolBarManager).createControl2(parent); 642 } 643 if (coolBarManager instanceof CoolBarManager) { 644 return ((CoolBarManager) coolBarManager).createControl(parent); 645 } 646 } 647 return null; 648 } 649 650 653 public Control createStatusLineControl(Composite parent) { 654 return window.getStatusLineManager().createControl(parent); 655 } 656 657 660 public Control createPageComposite(Composite parent) { 661 return window.createPageComposite(parent); 662 } 663 664 667 public IStatus saveState(IMemento memento) { 668 return window.saveState(memento); 669 } 670 671 } 672 | Popular Tags |