1 11 12 package org.eclipse.ui.internal; 13 14 import java.lang.reflect.InvocationTargetException ; 15 import java.util.ArrayList ; 16 import java.util.Arrays ; 17 import java.util.Collection ; 18 import java.util.Collections ; 19 import java.util.Comparator ; 20 import java.util.HashSet ; 21 import java.util.Iterator ; 22 import java.util.List ; 23 import java.util.Set ; 24 import java.util.StringTokenizer ; 25 26 import org.eclipse.core.runtime.Assert; 27 import org.eclipse.core.runtime.IAdaptable; 28 import org.eclipse.core.runtime.IConfigurationElement; 29 import org.eclipse.core.runtime.IExtension; 30 import org.eclipse.core.runtime.IExtensionPoint; 31 import org.eclipse.core.runtime.IProgressMonitor; 32 import org.eclipse.core.runtime.IStatus; 33 import org.eclipse.core.runtime.ListenerList; 34 import org.eclipse.core.runtime.MultiStatus; 35 import org.eclipse.core.runtime.Platform; 36 import org.eclipse.core.runtime.Status; 37 import org.eclipse.core.runtime.dynamichelpers.ExtensionTracker; 38 import org.eclipse.core.runtime.dynamichelpers.IExtensionChangeHandler; 39 import org.eclipse.core.runtime.dynamichelpers.IExtensionTracker; 40 import org.eclipse.jface.dialogs.ErrorDialog; 41 import org.eclipse.jface.dialogs.IDialogConstants; 42 import org.eclipse.jface.dialogs.MessageDialog; 43 import org.eclipse.jface.internal.provisional.action.ICoolBarManager2; 44 import org.eclipse.jface.operation.IRunnableWithProgress; 45 import org.eclipse.jface.util.IPropertyChangeListener; 46 import org.eclipse.jface.util.PropertyChangeEvent; 47 import org.eclipse.jface.util.SafeRunnable; 48 import org.eclipse.jface.viewers.ISelection; 49 import org.eclipse.jface.window.Window; 50 import org.eclipse.osgi.util.NLS; 51 import org.eclipse.swt.SWT; 52 import org.eclipse.swt.custom.BusyIndicator; 53 import org.eclipse.swt.graphics.Rectangle; 54 import org.eclipse.swt.widgets.Composite; 55 import org.eclipse.swt.widgets.Control; 56 import org.eclipse.swt.widgets.Display; 57 import org.eclipse.swt.widgets.Shell; 58 import org.eclipse.ui.IActionBars; 59 import org.eclipse.ui.IEditorDescriptor; 60 import org.eclipse.ui.IEditorInput; 61 import org.eclipse.ui.IEditorPart; 62 import org.eclipse.ui.IEditorReference; 63 import org.eclipse.ui.IEditorRegistry; 64 import org.eclipse.ui.IMemento; 65 import org.eclipse.ui.INavigationHistory; 66 import org.eclipse.ui.IPartListener; 67 import org.eclipse.ui.IPartListener2; 68 import org.eclipse.ui.IPerspectiveDescriptor; 69 import org.eclipse.ui.IPerspectiveRegistry; 70 import org.eclipse.ui.IReusableEditor; 71 import org.eclipse.ui.ISaveablePart; 72 import org.eclipse.ui.ISaveablesLifecycleListener; 73 import org.eclipse.ui.ISelectionListener; 74 import org.eclipse.ui.IShowEditorInput; 75 import org.eclipse.ui.IViewPart; 76 import org.eclipse.ui.IViewReference; 77 import org.eclipse.ui.IWorkbench; 78 import org.eclipse.ui.IWorkbenchPage; 79 import org.eclipse.ui.IWorkbenchPart; 80 import org.eclipse.ui.IWorkbenchPartReference; 81 import org.eclipse.ui.IWorkbenchPartSite; 82 import org.eclipse.ui.IWorkbenchPreferenceConstants; 83 import org.eclipse.ui.IWorkbenchWindow; 84 import org.eclipse.ui.IWorkingSet; 85 import org.eclipse.ui.IWorkingSetManager; 86 import org.eclipse.ui.PartInitException; 87 import org.eclipse.ui.PlatformUI; 88 import org.eclipse.ui.SubActionBars; 89 import org.eclipse.ui.WorkbenchException; 90 import org.eclipse.ui.contexts.IContextService; 91 import org.eclipse.ui.internal.StartupThreading.StartupRunnable; 92 import org.eclipse.ui.internal.contexts.ContextAuthority; 93 import org.eclipse.ui.internal.dialogs.CustomizePerspectiveDialog; 94 import org.eclipse.ui.internal.dnd.SwtUtil; 95 import org.eclipse.ui.internal.intro.IIntroConstants; 96 import org.eclipse.ui.internal.misc.UIListenerLogging; 97 import org.eclipse.ui.internal.misc.UIStats; 98 import org.eclipse.ui.internal.registry.ActionSetRegistry; 99 import org.eclipse.ui.internal.registry.EditorDescriptor; 100 import org.eclipse.ui.internal.registry.EditorRegistry; 101 import org.eclipse.ui.internal.registry.IActionSetDescriptor; 102 import org.eclipse.ui.internal.registry.IWorkbenchRegistryConstants; 103 import org.eclipse.ui.internal.registry.PerspectiveDescriptor; 104 import org.eclipse.ui.internal.registry.UIExtensionTracker; 105 import org.eclipse.ui.internal.tweaklets.GrabFocus; 106 import org.eclipse.ui.internal.tweaklets.TabBehaviour; 107 import org.eclipse.ui.internal.tweaklets.Tweaklets; 108 import org.eclipse.ui.internal.util.PrefUtil; 109 import org.eclipse.ui.internal.util.Util; 110 import org.eclipse.ui.model.IWorkbenchAdapter; 111 import org.eclipse.ui.part.MultiEditor; 112 import org.eclipse.ui.presentations.IStackPresentationSite; 113 114 117 public class WorkbenchPage extends CompatibleWorkbenchPage implements 118 IWorkbenchPage { 119 120 private static final String ATT_AGGREGATE_WORKING_SET_ID = "aggregateWorkingSetId"; 122 private WorkbenchWindow window; 123 124 private IAdaptable input; 125 126 private IWorkingSet workingSet; 127 128 private AggregateWorkingSet aggregateWorkingSet; 129 130 private Composite composite; 131 132 private ActivationList activationList = new ActivationList(); 134 135 142 private boolean includeActiveFastViews = false; 143 144 private EditorManager editorMgr; 145 146 private EditorAreaHelper editorPresentation; 147 148 private ListenerList propertyChangeListeners = new ListenerList(); 149 150 private PageSelectionService selectionService = new PageSelectionService( 151 this); 152 153 private WorkbenchPagePartList partList = new WorkbenchPagePartList(selectionService); 154 155 private IActionBars actionBars; 156 157 private ActionSetManager actionSets; 158 159 private ViewFactory viewFactory; 160 161 private PerspectiveList perspList = new PerspectiveList(); 162 163 private PerspectiveDescriptor deferredActivePersp; 164 165 private NavigationHistory navigationHistory = new NavigationHistory(this); 166 167 private IStickyViewManager stickyViewMan = StickyViewManager.getInstance(this); 168 169 173 private IWorkbenchPartReference partBeingActivated = null; 174 175 179 private Set dirtyPerspectives = new HashSet (); 180 181 private IPropertyChangeListener workingSetPropertyChangeListener = new IPropertyChangeListener() { 182 185 public void propertyChange(PropertyChangeEvent event) { 186 String property = event.getProperty(); 187 if (IWorkingSetManager.CHANGE_WORKING_SET_REMOVE.equals(property)) { 188 if(event.getOldValue().equals(workingSet)) { 189 setWorkingSet(null); 190 } 191 192 List newList = new ArrayList (Arrays.asList(workingSets)); 194 if (newList.remove(event.getOldValue())) { 195 setWorkingSets((IWorkingSet []) newList 196 .toArray(new IWorkingSet [newList.size()])); 197 } 198 } 199 } 200 }; 201 202 private ActionSwitcher actionSwitcher = new ActionSwitcher(); 203 204 private IExtensionTracker tracker; 205 206 private int deferCount = 0; 208 private List pendingDisposals = new ArrayList (); 210 211 private IExtensionChangeHandler perspectiveChangeHandler = new IExtensionChangeHandler() { 212 213 216 public void removeExtension(IExtension extension, Object [] objects) { 217 boolean suggestReset = false; 218 for (int i = 0; i < objects.length; i++) { 219 if (objects[i] instanceof DirtyPerspectiveMarker) { 220 String id = ((DirtyPerspectiveMarker)objects[i]).perspectiveId; 221 if (!dirtyPerspectives.remove(id)) { 222 dirtyPerspectives.add(id); } 224 PerspectiveDescriptor persp = (PerspectiveDescriptor) getPerspective(); 225 if (persp == null || persp.hasCustomDefinition()) { 226 continue; 227 } 228 if (persp.getId().equals(id)) { 229 suggestReset = true; 230 } 231 } 232 } 233 if (suggestReset) { 234 suggestReset(); 235 } 236 } 237 238 241 public void addExtension(IExtensionTracker tracker, IExtension extension) { 242 if (WorkbenchPage.this != getWorkbenchWindow().getActivePage()) { 243 return; 244 } 245 246 PerspectiveDescriptor persp = (PerspectiveDescriptor) getPerspective(); 248 if (persp == null) { 249 return; 250 } 251 String currentId = persp.getId(); 252 IConfigurationElement[] elements = extension.getConfigurationElements(); 253 boolean suggestReset = false; 254 for (int i = 0; i < elements.length; i++) { 255 String id = elements[i].getAttribute(IWorkbenchRegistryConstants.ATT_TARGET_ID); 261 if (id == null) { 262 continue; 263 } 264 if (id.equals(currentId) && !persp.hasCustomDefinition()) { 265 suggestReset = true; 266 } 267 else { 268 dirtyPerspectives.add(id); 269 } 270 DirtyPerspectiveMarker marker = new DirtyPerspectiveMarker(id); 271 tracker.registerObject(extension, marker, IExtensionTracker.REF_STRONG); 272 } 273 if (suggestReset) { 274 suggestReset(); 275 } 276 277 } 278 }; 279 private IWorkingSet[] workingSets = new IWorkingSet[0]; 280 private String aggregateWorkingSetId; 281 282 private IExtensionPoint getPerspectiveExtensionPoint() { 283 return Platform.getExtensionRegistry().getExtensionPoint(PlatformUI.PLUGIN_ID, IWorkbenchRegistryConstants.PL_PERSPECTIVE_EXTENSIONS); 284 } 285 286 289 private class ActionSwitcher { 290 private IWorkbenchPart activePart; 291 292 private IEditorPart topEditor; 293 294 private ArrayList oldActionSets = new ArrayList (); 295 296 302 public void updateActivePart(IWorkbenchPart newPart) { 303 if (activePart == newPart) { 304 return; 305 } 306 307 boolean isNewPartAnEditor = newPart instanceof IEditorPart; 308 if (isNewPartAnEditor) { 309 String oldId = null; 310 if (topEditor != null) { 311 oldId = topEditor.getSite().getId(); 312 } 313 String newId = newPart.getSite().getId(); 314 315 if (activePart == topEditor && newId.equals(oldId)) { 319 activePart = newPart; 320 topEditor = (IEditorPart) newPart; 321 return; 322 } 323 324 if (oldId != null && !oldId.equals(newId)) { 327 deactivateContributions(topEditor, true); 328 } 329 330 if (activePart != null && activePart != topEditor) { 332 deactivateContributions(activePart, true); 333 } 334 335 if (!newId.equals(oldId) || activePart != topEditor) { 339 activateContributions(newPart, true); 340 } 341 342 } else if (newPart == null) { 343 if (activePart != null) { 344 deactivateContributions(activePart, true); 346 } 347 } else { 348 350 if (activePart != null) { 353 deactivateContributions(activePart, 354 activePart instanceof IViewPart); 355 } 356 357 activateContributions(newPart, true); 358 } 359 360 ArrayList newActionSets = null; 361 if (isNewPartAnEditor 362 || (activePart == topEditor && newPart == null)) { 363 newActionSets = calculateActionSets(newPart, null); 364 } else { 365 newActionSets = calculateActionSets(newPart, topEditor); 366 } 367 368 if (!updateActionSets(newActionSets)) { 369 updateActionBars(); 370 } 371 372 if (isNewPartAnEditor) { 373 topEditor = (IEditorPart) newPart; 374 } else if (activePart == topEditor && newPart == null) { 375 topEditor = null; 378 } 379 380 activePart = newPart; 381 } 382 383 389 public void updateTopEditor(IEditorPart newEditor) { 390 if (topEditor == newEditor) { 391 return; 392 } 393 394 if (activePart == topEditor) { 395 updateActivePart(newEditor); 396 return; 397 } 398 399 String oldId = null; 400 if (topEditor != null) { 401 oldId = topEditor.getSite().getId(); 402 } 403 String newId = null; 404 if (newEditor != null) { 405 newId = newEditor.getSite().getId(); 406 } 407 if (oldId == null ? newId == null : oldId.equals(newId)) { 408 topEditor = newEditor; 410 return; 411 } 412 413 if (topEditor != null) { 415 deactivateContributions(topEditor, true); 416 } 417 418 if (newEditor != null) { 420 activateContributions(newEditor, false); 421 } 422 423 ArrayList newActionSets = calculateActionSets(activePart, newEditor); 424 if (!updateActionSets(newActionSets)) { 425 updateActionBars(); 426 } 427 428 topEditor = newEditor; 429 } 430 431 442 private void activateContributions(IWorkbenchPart part, boolean enable) { 443 PartSite site = (PartSite) part.getSite(); 444 site.activateActionBars(enable); 445 } 446 447 458 private void deactivateContributions(IWorkbenchPart part, boolean remove) { 459 PartSite site = (PartSite) part.getSite(); 460 site.deactivateActionBars(remove); 461 } 462 463 473 private ArrayList calculateActionSets(IWorkbenchPart part, 474 IEditorPart editor) { 475 ArrayList newActionSets = new ArrayList (); 476 if (part != null) { 477 IActionSetDescriptor[] partActionSets = WorkbenchPlugin 478 .getDefault().getActionSetRegistry().getActionSetsFor( 479 part.getSite().getId()); 480 for (int i = 0; i < partActionSets.length; i++) { 481 newActionSets.add(partActionSets[i]); 482 } 483 } 484 if (editor != null && editor != part) { 485 IActionSetDescriptor[] editorActionSets = WorkbenchPlugin 486 .getDefault().getActionSetRegistry().getActionSetsFor( 487 editor.getSite().getId()); 488 for (int i = 0; i < editorActionSets.length; i++) { 489 newActionSets.add(editorActionSets[i]); 490 } 491 } 492 return newActionSets; 493 } 494 495 503 private boolean updateActionSets(ArrayList newActionSets) { 504 if (oldActionSets.equals(newActionSets)) { 505 return false; 506 } 507 508 IContextService service = (IContextService) window 509 .getService(IContextService.class); 510 try { 511 service.activateContext(ContextAuthority.DEFER_EVENTS); 512 513 for (int i = 0; i < newActionSets.size(); i++) { 515 actionSets.showAction((IActionSetDescriptor) newActionSets 516 .get(i)); 517 } 518 519 for (int i = 0; i < oldActionSets.size(); i++) { 521 actionSets.hideAction((IActionSetDescriptor) oldActionSets 522 .get(i)); 523 } 524 525 oldActionSets = newActionSets; 526 527 } finally { 528 service.activateContext(ContextAuthority.SEND_EVENTS); 529 } 530 Perspective persp = getActivePerspective(); 531 if (persp == null) { 532 return false; 533 } 534 535 window.updateActionSets(); window.firePerspectiveChanged(WorkbenchPage.this, getPerspective(), 537 CHANGE_ACTION_SET_SHOW); 538 return true; 539 } 540 541 } 542 543 555 public WorkbenchPage(WorkbenchWindow w, String layoutID, IAdaptable input) 556 throws WorkbenchException { 557 super(); 558 if (layoutID == null) { 559 throw new WorkbenchException(WorkbenchMessages.WorkbenchPage_UndefinedPerspective); 560 } 561 init(w, layoutID, input, true); 562 } 563 564 574 public WorkbenchPage(WorkbenchWindow w, IAdaptable input) 575 throws WorkbenchException { 576 super(); 577 init(w, null, input, false); 578 } 579 580 586 public void activate(IWorkbenchPart part) { 587 if (!certifyPart(part)) { 589 return; 590 } 591 592 if (window.isClosing()) { 593 return; 594 } 595 596 if (composite!=null && composite.isVisible() 597 && !((GrabFocus)Tweaklets.get(GrabFocus.KEY)).grabFocusAllowed(part)) { 598 return; 599 } 600 601 zoomOutIfNecessary(part); 603 604 if (part instanceof MultiEditor) { 605 part = ((MultiEditor) part).getActiveEditor(); 606 } 607 IWorkbenchPartReference ref = getReference(part); 610 internalBringToTop(ref); 611 setActivePart(part); 612 } 613 614 617 private void activatePart(final IWorkbenchPart part) { 618 Platform.run(new SafeRunnable(WorkbenchMessages.WorkbenchPage_ErrorActivatingView) { 619 public void run() { 620 if (part != null) { 621 PartPane pane = getPane(part); 623 pane.setFocus(); 624 PartSite site = (PartSite) part.getSite(); 625 pane.showFocus(true); 626 updateTabList(part); 627 SubActionBars bars = (SubActionBars) site 628 .getActionBars(); 629 bars.partChanged(part); 630 } 631 } 632 }); 633 } 634 635 638 public void addFastView(IViewReference ref) { 639 Perspective persp = getActivePerspective(); 640 if (persp == null) { 641 return; 642 } 643 644 persp.getFastViewManager().addViewReference(FastViewBar.FASTVIEWBAR_ID, -1, ref, true); 645 } 646 647 650 public void makeFastView(IViewReference ref) { 651 Perspective persp = getActivePerspective(); 652 if (persp == null) { 653 return; 654 } 655 656 FastViewManager fvm = persp.getFastViewManager(); 657 if (fvm.isFastView(ref)) { 658 return; 659 } 660 661 persp.makeFastView(ref); 663 664 updateActivePart(); 665 666 669 window.firePerspectiveChanged(this, getPerspective(), ref, 671 CHANGE_FAST_VIEW_ADD); 672 window.firePerspectiveChanged(this, getPerspective(), 673 CHANGE_FAST_VIEW_ADD); 674 } 675 676 679 public void addPartListener(IPartListener l) { 680 partList.getPartService().addPartListener(l); 681 } 682 683 686 public void addPartListener(IPartListener2 l) { 687 partList.getPartService().addPartListener(l); 688 } 689 690 700 public void addPropertyChangeListener(IPropertyChangeListener listener) { 701 propertyChangeListeners.add(listener); 702 } 703 704 707 public void addSelectionListener(ISelectionListener listener) { 708 selectionService.addSelectionListener(listener); 709 } 710 711 714 public void addSelectionListener(String partId, ISelectionListener listener) { 715 selectionService.addSelectionListener(partId, listener); 716 } 717 718 721 public void addPostSelectionListener(ISelectionListener listener) { 722 selectionService.addPostSelectionListener(listener); 723 } 724 725 728 public void addPostSelectionListener(String partId, 729 ISelectionListener listener) { 730 selectionService.addPostSelectionListener(partId, listener); 731 } 732 733 private ILayoutContainer getContainer(IWorkbenchPart part) { 734 PartPane pane = getPane(part); 735 if (pane == null) { 736 return null; 737 } 738 739 return pane.getContainer(); 740 } 741 742 private ILayoutContainer getContainer(IWorkbenchPartReference part) { 743 PartPane pane = getPane(part); 744 if (pane == null) { 745 return null; 746 } 747 748 return pane.getContainer(); 749 } 750 751 private PartPane getPane(IWorkbenchPart part) { 752 if (part == null) { 753 return null; 754 } 755 return getPane(getReference(part)); 756 } 757 758 private PartPane getPane(IWorkbenchPartReference part) { 759 if (part == null) { 760 return null; 761 } 762 763 return ((WorkbenchPartReference)part).getPane(); 764 } 765 766 767 775 private boolean internalBringToTop(IWorkbenchPartReference part) { 776 777 boolean broughtToTop = false; 778 779 if (part instanceof IEditorReference) { 781 ILayoutContainer container = getContainer(part); 782 if (container instanceof PartStack) { 783 PartStack stack = (PartStack)container; 784 PartPane newPart = getPane(part); 785 if (stack.getSelection() != newPart) { 786 stack.setSelection(newPart); 787 } 788 broughtToTop = true; 789 } 790 } else if (part instanceof IViewReference) { 791 Perspective persp = getActivePerspective(); 792 if (persp != null) { 793 broughtToTop = persp.bringToTop((IViewReference)part); 794 } 795 } 796 797 activationList.bringToTop(part); 800 801 return broughtToTop; 802 } 803 804 805 813 public void bringToTop(IWorkbenchPart part) { 814 Perspective persp = getActivePerspective(); 816 if (persp == null || !certifyPart(part)) { 817 return; 818 } 819 820 if (!((GrabFocus)Tweaklets.get(GrabFocus.KEY)).grabFocusAllowed(part)) { 821 return; 822 } 823 824 String label = null; if (UIStats.isDebugging(UIStats.BRING_PART_TO_TOP)) { 826 label = part != null ? part.getTitle() : "none"; } 828 829 try { 830 UIStats.start(UIStats.BRING_PART_TO_TOP, label); 831 832 IWorkbenchPartReference ref = getReference(part); 833 ILayoutContainer activeEditorContainer = getContainer(getActiveEditor()); 834 ILayoutContainer activePartContainer = getContainer(getActivePart()); 835 ILayoutContainer newPartContainer = getContainer(part); 836 837 if (newPartContainer == activePartContainer) { 838 makeActive(ref); 839 } else if (newPartContainer == activeEditorContainer) { 840 if (ref instanceof IEditorReference) { 841 if (part!=null) { 842 IWorkbenchPartSite site = part.getSite(); 843 if (site instanceof PartSite) { 844 ref = ((PartSite) site).getPane() 845 .getPartReference(); 846 } 847 } 848 makeActiveEditor((IEditorReference)ref); 849 } else { 850 makeActiveEditor(null); 851 } 852 } else { 853 internalBringToTop(ref); 854 if (ref != null) { 855 partList.firePartBroughtToTop(ref); 856 } 857 } 858 } finally { 859 UIStats.end(UIStats.BRING_PART_TO_TOP, part, label); 860 } 861 } 862 863 869 private void busyResetPerspective() { 870 871 ViewIntroAdapterPart introViewAdapter = ((WorkbenchIntroManager) getWorkbenchWindow() 872 .getWorkbench().getIntroManager()).getViewIntroAdapterPart(); 873 PartPane introPane = null; 874 boolean introFullScreen = false; 875 if (introViewAdapter != null) { 876 introPane = ((PartSite) introViewAdapter.getSite()).getPane(); 877 introViewAdapter.setHandleZoomEvents(false); 878 introFullScreen = introPane.isZoomed(); 879 } 880 881 if (introFullScreen) { 883 window.getShell().setRedraw(false); 884 } 885 886 try { 887 888 if (isZoomed()) { 890 zoomOut(); 891 } 892 893 Perspective oldPersp = getActivePerspective(); 897 898 IPerspectiveRegistry reg = WorkbenchPlugin.getDefault() 902 .getPerspectiveRegistry(); 903 PerspectiveDescriptor desc = (PerspectiveDescriptor) reg 904 .findPerspectiveWithId(oldPersp.getDesc().getId()); 905 if (desc == null) { 906 desc = (PerspectiveDescriptor) reg 907 .findPerspectiveWithId(((PerspectiveDescriptor) oldPersp 908 .getDesc()).getOriginalId()); 909 } 910 if (desc == null) { 911 return; 912 } 913 914 window.firePerspectiveChanged(this, desc, CHANGE_RESET); 916 917 Perspective newPersp = createPerspective(desc, false); 921 if (newPersp == null) { 922 window 924 .firePerspectiveChanged(this, desc, 925 CHANGE_RESET_COMPLETE); 926 return; 927 } 928 929 perspList.swap(oldPersp, newPersp); 931 932 setPerspective(newPersp); 934 935 disposePerspective(oldPersp, false); 937 938 resetToolBarLayout(); 940 941 if (introViewAdapter != null) { 943 try { 944 showView(IIntroConstants.INTRO_VIEW_ID); 946 if (introFullScreen) { 947 toggleZoom(introPane.getPartReference()); 948 } 949 } catch (PartInitException e) { 950 WorkbenchPlugin.log("Could not restore intro", WorkbenchPlugin.getStatus(e)); 952 } finally { 953 introViewAdapter.setHandleZoomEvents(true); 955 } 956 } 957 window.firePerspectiveChanged(this, desc, CHANGE_RESET_COMPLETE); 959 } finally { 960 if (introViewAdapter != null) { 963 introViewAdapter.setHandleZoomEvents(true); 964 } 965 966 if (introFullScreen) { 967 window.getShell().setRedraw(true); 968 } 969 } 970 971 } 972 973 981 private void busySetPerspective(IPerspectiveDescriptor desc) { 982 String label = desc.getId(); Perspective newPersp = null; 985 try { 986 UIStats.start(UIStats.SWITCH_PERSPECTIVE, label); 987 PerspectiveDescriptor realDesc = (PerspectiveDescriptor) desc; 988 newPersp = findPerspective(realDesc); 989 if (newPersp == null) { 990 newPersp = createPerspective(realDesc, true); 991 if (newPersp == null) { 992 return; 993 } 994 } 995 996 setPerspective(newPersp); 998 } finally { 999 UIStats.end(UIStats.SWITCH_PERSPECTIVE, desc.getId(), label); 1000 } 1001 } 1002 1003 1008 private IViewPart busyShowView(String viewID, String secondaryID, int mode) 1009 throws PartInitException { 1010 Perspective persp = getActivePerspective(); 1011 if (persp == null) { 1012 return null; 1013 } 1014 1015 IViewReference ref = persp.findView(viewID, secondaryID); 1017 IViewPart view = null; 1018 if (ref != null) { 1019 view = ref.getView(true); 1020 } 1021 if (view != null) { 1022 busyShowView(view, mode); 1023 return view; 1024 } 1025 1026 view = persp.showView(viewID, secondaryID); 1028 if (view != null) { 1029 busyShowView(view, mode); 1030 1031 IWorkbenchPartReference partReference = getReference(view); 1032 PartPane partPane = getPane(partReference); 1033 partPane.setInLayout(true); 1034 1035 window.firePerspectiveChanged(this, getPerspective(), 1036 partReference, CHANGE_VIEW_SHOW); 1037 window.firePerspectiveChanged(this, getPerspective(), 1038 CHANGE_VIEW_SHOW); 1039 } 1040 return view; 1041 } 1042 1043 1046 private void busyShowView(IViewPart part, int mode) { 1047 if (!((GrabFocus)Tweaklets.get(GrabFocus.KEY)).grabFocusAllowed(part)) { 1048 return; 1049 } 1050 if (mode == VIEW_ACTIVATE) { 1051 activate(part); 1052 } else if (mode == VIEW_VISIBLE) { 1053 IWorkbenchPartReference ref = getActivePartReference(); 1054 if (ref == null || !(ref instanceof IViewReference)) { 1056 bringToTop(part); 1057 } else { 1058 IViewReference activeView = (IViewReference) ref; 1060 IViewReference[] viewStack = getViewReferenceStack(part); 1061 for (int i = 0; i < viewStack.length; i++) { 1062 if (viewStack[i].equals(activeView)) { 1063 return; 1064 } 1065 } 1066 bringToTop(part); 1067 } 1068 } 1069 } 1070 1071 1074 private boolean certifyPart(IWorkbenchPart part) { 1075 if (part != null && !(part.getSite() instanceof PartSite)) { 1077 return false; 1078 } 1079 1080 if (part instanceof IEditorPart) { 1081 IEditorReference ref = (IEditorReference) getReference(part); 1082 return ref != null && getEditorManager().containsEditor(ref); 1083 } 1084 if (part instanceof IViewPart) { 1085 Perspective persp = getActivePerspective(); 1086 return persp != null && persp.containsView((IViewPart) part); 1087 } 1088 return false; 1089 } 1090 1091 1094 public boolean close() { 1095 final boolean[] ret = new boolean[1]; 1096 BusyIndicator.showWhile(null, new Runnable () { 1097 public void run() { 1098 ret[0] = window.closePage(WorkbenchPage.this, true); 1099 } 1100 }); 1101 return ret[0]; 1102 } 1103 1104 1107 public boolean closeAllSavedEditors() { 1108 IEditorReference editors[] = getEditorReferences(); 1110 IEditorReference savedEditors[] = new IEditorReference[editors.length]; 1111 int j = 0; 1112 for (int i = 0; i < editors.length; i++) { 1113 IEditorReference editor = editors[i]; 1114 if (!editor.isDirty()) { 1115 savedEditors[j++] = editor; 1116 } 1117 } 1118 if (j == 0) { 1120 return true; 1121 } 1122 IEditorReference[] newSaved = new IEditorReference[j]; 1123 System.arraycopy(savedEditors, 0, newSaved, 0, j); 1124 return closeEditors(newSaved, false); 1125 } 1126 1127 1130 public boolean closeAllEditors(boolean save) { 1131 return closeEditors(getEditorReferences(), save); 1132 } 1133 1134 private void updateActivePart() { 1135 1136 if (isDeferred()) { 1137 return; 1138 } 1139 1140 IWorkbenchPartReference oldActivePart = partList.getActivePartReference(); 1141 IWorkbenchPartReference oldActiveEditor = partList.getActiveEditorReference(); 1142 IWorkbenchPartReference newActivePart = null; 1143 IEditorReference newActiveEditor = null; 1144 1145 if (!window.isClosing()) { 1146 if (oldActivePart == oldActiveEditor) { 1148 newActiveEditor = (IEditorReference)activationList.getActiveReference(true); 1149 newActivePart = newActiveEditor; 1150 if (newActivePart == null) { 1151 newActivePart = activationList.getActiveReference(false); 1153 } 1154 } else { 1155 newActivePart = activationList.getActiveReference(false); 1157 1158 if (newActivePart instanceof IEditorReference) { 1159 newActiveEditor = (IEditorReference)newActivePart; 1161 } else { 1162 newActiveEditor = (IEditorReference)activationList.getActiveReference(true); 1164 } 1165 } 1166 } 1167 1168 if (newActiveEditor != oldActiveEditor) { 1169 makeActiveEditor(newActiveEditor); 1170 } 1171 1172 if (newActivePart != oldActivePart) { 1173 makeActive(newActivePart); 1174 } 1175 } 1176 1177 1185 private void makeActive(IWorkbenchPartReference ref) { 1186 if (ref == null) { 1187 setActivePart(null); 1188 } else { 1189 IWorkbenchPart newActive = ref.getPart(true); 1190 if (newActive == null) { 1191 setActivePart(null); 1192 } else { 1193 activate(newActive); 1194 } 1195 } 1196 } 1197 1198 1206 private void makeActiveEditor(IEditorReference ref) { 1207 if (ref == getActiveEditorReference()) { 1208 return; 1209 } 1210 1211 IEditorPart part = (ref == null) ? null : ref.getEditor(true); 1212 1213 if (part != null) { 1214 editorMgr.setVisibleEditor(ref, false); 1215 navigationHistory.markEditor(part); 1216 } 1217 1218 actionSwitcher.updateTopEditor(part); 1219 1220 if (ref != null) { 1221 activationList.bringToTop(getReference(part)); 1222 } 1223 1224 partList.setActiveEditor(ref); 1225 } 1226 1227 1230 public boolean closeEditors(IEditorReference[] refArray, boolean save) { 1231 if (refArray.length == 0) { 1232 return true; 1233 } 1234 1235 ArrayList toClose = new ArrayList (); 1238 for (int i = 0; i < refArray.length; i++) { 1239 IEditorReference reference = refArray[i]; 1240 1241 if (reference == partBeingActivated) { 1247 WorkbenchPlugin.log(new RuntimeException ("WARNING: Blocked recursive attempt to close part " + partBeingActivated.getId() + " while still in the middle of activating it")); return false; 1250 } 1251 1252 if(reference instanceof WorkbenchPartReference) { 1253 WorkbenchPartReference ref = (WorkbenchPartReference) reference; 1254 1255 if (ref.isDisposed()) { 1258 continue; 1259 } 1260 } 1261 1262 toClose.add(reference); 1263 } 1264 1265 IEditorReference[] editorRefs = (IEditorReference[]) toClose.toArray(new IEditorReference[toClose.size()]); 1266 1267 List partsToClose = new ArrayList (); 1269 for (int i = 0; i < editorRefs.length; i++) { 1270 IEditorPart refPart = editorRefs[i].getEditor(false); 1271 if (refPart != null) { 1272 partsToClose.add(refPart); 1273 } 1274 } 1275 SaveablesList modelManager = null; 1276 Object postCloseInfo = null; 1277 if(partsToClose.size()>0) { 1278 modelManager = (SaveablesList) getWorkbenchWindow().getService(ISaveablesLifecycleListener.class); 1279 postCloseInfo = modelManager.preCloseParts(partsToClose, save, getWorkbenchWindow()); 1281 if (postCloseInfo==null) { 1282 return false; 1283 } 1284 } 1285 1286 for (int i = 0; i < editorRefs.length; i++) { 1288 IEditorReference ref = editorRefs[i]; 1289 1290 window.firePerspectiveChanged(this, getPerspective(), ref, 1292 CHANGE_EDITOR_CLOSE); 1293 1294 } 1295 1296 deferUpdates(true); 1297 try { 1298 if(modelManager!=null) { 1299 modelManager.postClose(postCloseInfo); 1300 } 1301 1302 for (int i = 0; i < editorRefs.length; i++) { 1304 IEditorReference ref = editorRefs[i]; 1305 1306 editorPresentation.closeEditor(ref); 1308 1309 partRemoved((WorkbenchPartReference)ref); 1310 } 1311 } finally { 1312 deferUpdates(false); 1313 } 1314 1315 window.firePerspectiveChanged(this, getPerspective(), 1317 CHANGE_EDITOR_CLOSE); 1318 1319 return true; 1321 } 1322 1323 1329 private void deferUpdates(boolean shouldDefer) { 1330 if (shouldDefer) { 1331 if (deferCount == 0) { 1332 startDeferring(); 1333 } 1334 deferCount++; 1335 } else { 1336 deferCount--; 1337 if (deferCount == 0) { 1338 handleDeferredEvents(); 1339 } 1340 } 1341 } 1342 1343 private void startDeferring() { 1344 editorPresentation.getLayoutPart().deferUpdates(true); 1345 } 1346 1347 private void handleDeferredEvents() { 1348 editorPresentation.getLayoutPart().deferUpdates(false); 1349 updateActivePart(); 1350 WorkbenchPartReference[] disposals = (WorkbenchPartReference[]) pendingDisposals.toArray(new WorkbenchPartReference[pendingDisposals.size()]); 1351 pendingDisposals.clear(); 1352 for (int i = 0; i < disposals.length; i++) { 1353 WorkbenchPartReference reference = disposals[i]; 1354 disposePart(reference); 1355 } 1356 1357 } 1358 1359 private boolean isDeferred() { 1360 return deferCount > 0; 1361 } 1362 1363 1366 public boolean closeEditor(IEditorReference editorRef, boolean save) { 1367 return closeEditors(new IEditorReference[] {editorRef}, save); 1368 } 1369 1370 1373 public boolean closeEditor(IEditorPart editor, boolean save) { 1374 IWorkbenchPartReference ref = getReference(editor); 1375 if (ref instanceof IEditorReference) { 1376 return closeEditors(new IEditorReference[] {(IEditorReference) ref}, save); 1377 } 1378 return false; 1379 } 1380 1381 1384 public void closePerspective(IPerspectiveDescriptor desc, boolean saveParts, boolean closePage) { 1385 Perspective persp = findPerspective(desc); 1386 if (persp != null) { 1387 closePerspective(persp, saveParts, closePage); 1388 } 1389 } 1390 1391 1402 1403 void closePerspective(Perspective persp, boolean saveParts, boolean closePage) { 1404 1405 if (isZoomed()) { 1407 zoomOut(); 1408 } 1409 1410 List partsToSave = new ArrayList (); 1411 List viewsToClose = new ArrayList (); 1412 IViewReference[] viewReferences = persp.getViewReferences(); 1414 for (int i = 0; i < viewReferences.length; i++) { 1415 IViewReference reference = viewReferences[i]; 1416 if (getViewFactory().getReferenceCount(reference) == 1) { 1417 IViewPart viewPart = reference.getView(false); 1418 if (viewPart != null) { 1419 viewsToClose.add(viewPart); 1420 if (saveParts && reference.isDirty()) { 1421 partsToSave.add(viewPart); 1422 } 1423 } 1424 } 1425 } 1426 if (saveParts && perspList.size() == 1) { 1427 IEditorReference[] editorReferences = getEditorReferences(); 1429 for (int i = 0; i < editorReferences.length; i++) { 1430 IEditorReference reference = editorReferences[i]; 1431 if (reference.isDirty()) { 1432 IEditorPart editorPart = reference.getEditor(false); 1433 if (editorPart != null) { 1434 partsToSave.add(editorPart); 1435 } 1436 } 1437 } 1438 } 1439 if (saveParts && !partsToSave.isEmpty()) { 1440 if (!EditorManager.saveAll(partsToSave, true, true, false, window)) { 1441 return; 1443 } 1444 } 1445 if (perspList.size() == 1 && getEditorManager().getEditorCount() > 0) { 1447 if (!closeAllEditors(false)) { 1449 return; 1450 } 1451 } 1452 1453 SaveablesList saveablesList = (SaveablesList) getWorkbenchWindow().getWorkbench().getService(ISaveablesLifecycleListener.class); 1455 Object postCloseInfo = saveablesList.preCloseParts(viewsToClose, false, getWorkbenchWindow()); 1457 saveablesList.postClose(postCloseInfo); 1458 1459 boolean isActive = (perspList.getActive() == persp); 1461 if (isActive) { 1462 setPerspective(perspList.getNextActive()); 1463 } 1464 disposePerspective(persp, true); 1465 if (closePage && perspList.size() == 0) { 1466 close(); 1467 } 1468 } 1469 1470 1473 public void unzoomAllPerspectives() { 1474 for (Iterator perspIter = perspList.iterator(); perspIter.hasNext();) { 1475 Perspective persp = (Perspective) perspIter.next(); 1476 persp.getPresentation().forceNoZoom(); 1477 } 1478 } 1479 1480 1483 public void closeAllPerspectives(boolean saveEditors, boolean closePage) { 1484 1485 if (perspList.isEmpty()) { 1486 return; 1487 } 1488 1489 if (isZoomed()) { 1491 zoomOut(); 1492 } 1493 1494 if(saveEditors) { 1495 if (!saveAllEditors(true)) { 1496 return; 1497 } 1498 } 1499 if (!closeAllEditors(false)) { 1501 return; 1502 } 1503 1504 setPerspective((Perspective) null); 1506 1507 PerspectiveList oldList = perspList; 1509 perspList = new PerspectiveList(); 1510 Iterator itr = oldList.iterator(); 1511 while (itr.hasNext()) { 1512 closePerspective((Perspective) itr.next(), false, false); 1513 } 1514 if (closePage) { 1515 close(); 1516 } 1517 } 1518 1519 1522 private void createClientComposite() { 1523 final Composite parent = window.getPageComposite(); 1524 StartupThreading.runWithoutExceptions(new StartupRunnable() { 1525 1526 public void runWithException() { 1527 composite = new Composite(parent, SWT.NONE); 1528 composite.setVisible(false); parent.layout(); 1531 } 1532 }); 1533 1534 } 1535 1536 1542 private Perspective createPerspective(PerspectiveDescriptor desc, boolean notify) { 1543 String label = desc.getId(); try { 1545 UIStats.start(UIStats.CREATE_PERSPECTIVE, label); 1546 Perspective persp = new Perspective(desc, this); 1547 perspList.add(persp); 1548 if (notify) { 1549 window.firePerspectiveOpened(this, desc); 1550 } 1551 if (!desc.hasCustomDefinition()) { 1554 dirtyPerspectives.remove(desc.getId()); 1555 } 1556 return persp; 1557 } catch (WorkbenchException e) { 1558 if (!((Workbench) window.getWorkbench()).isStarting()) { 1559 MessageDialog 1560 .openError( 1561 window.getShell(), 1562 WorkbenchMessages.Error, 1563 NLS.bind(WorkbenchMessages.Workbench_showPerspectiveError,desc.getId() )); 1564 } 1565 return null; 1566 } finally { 1567 UIStats.end(UIStats.CREATE_PERSPECTIVE, desc.getId(), label); 1568 } 1569 } 1570 1571 1575 void partAdded(WorkbenchPartReference ref) { 1576 activationList.add(ref); 1577 partList.addPart(ref); 1578 1579 if (ref instanceof IEditorReference) { 1582 includeActiveFastViews = true; 1583 updateActivePart(); 1584 includeActiveFastViews = false; 1585 } 1586 else 1587 updateActivePart(); 1588 } 1589 1590 1594 void partRemoved(WorkbenchPartReference ref) { 1595 activationList.remove(ref); 1596 disposePart(ref); 1597 } 1598 1599 private void disposePart(WorkbenchPartReference ref) { 1600 if (isDeferred()) { 1601 pendingDisposals.add(ref); 1602 } else { 1603 partList.removePart(ref); 1604 ref.dispose(); 1605 } 1606 } 1607 1608 1611 private void deactivatePart(IWorkbenchPart part) { 1612 if (part != null) { 1613 PartSite site = (PartSite) part.getSite(); 1614 site.getPane().showFocus(false); 1615 } 1616 } 1617 1618 1621 public void detachView(IViewReference ref){ 1622 Perspective persp = getActivePerspective(); 1623 if(persp == null) { 1624 return; 1625 } 1626 1627 PerspectiveHelper presentation = persp.getPresentation(); 1628 presentation.detachPart(ref); 1629 } 1630 1631 1634 public void attachView(IViewReference ref){ 1635 PerspectiveHelper presentation = getPerspectivePresentation(); 1636 presentation.attachPart(ref); 1637 } 1638 1639 1642 public void dispose() { 1643 1644 if (isZoomed()) { 1646 zoomOut(); 1647 } 1648 1649 makeActiveEditor(null); 1650 makeActive(null); 1651 1652 closeAllEditors(false); 1654 1655 IWorkbenchPartReference[] partsToClose = getOpenParts(); 1659 List dirtyParts = new ArrayList (partsToClose.length); 1660 for (int i = 0; i < partsToClose.length; i++) { 1661 IWorkbenchPart part = partsToClose[i].getPart(false); 1662 if (part != null && part instanceof IViewPart) { 1663 dirtyParts.add(part); 1664 } 1665 } 1666 SaveablesList saveablesList = (SaveablesList) getWorkbenchWindow().getWorkbench().getService(ISaveablesLifecycleListener.class); 1667 Object postCloseInfo = saveablesList.preCloseParts(dirtyParts, false,getWorkbenchWindow()); 1668 saveablesList.postClose(postCloseInfo); 1669 1670 Iterator itr = perspList.iterator(); 1672 while (itr.hasNext()) { 1673 Perspective perspective = (Perspective) itr.next(); 1674 window.firePerspectiveClosed(this, perspective.getDesc()); 1675 perspective.dispose(); 1676 } 1677 perspList = new PerspectiveList(); 1678 1679 IViewReference refs[] = viewFactory.getViews(); 1681 1682 if (refs.length > 0) { 1683 for (int i = 0; i < refs.length; i++) { 1685 final WorkbenchPartReference ref = (WorkbenchPartReference) refs[i]; 1686 Platform.run(new SafeRunnable() { 1689 public void run() { 1690 1693 ref.dispose(); 1694 } 1695 1696 public void handleException(Throwable e) { 1697 } 1698 }); 1699 } 1700 } 1701 1702 activationList = new ActivationList(); 1703 1704 editorPresentation.dispose(); 1706 1707 composite.dispose(); 1709 1710 navigationHistory.dispose(); 1711 1712 stickyViewMan.clear(); 1713 1714 if (tracker != null) { 1715 tracker.close(); 1716 } 1717 1718 if (!window.getWorkbench().isClosing()) { 1721 if (aggregateWorkingSet != null) { 1722 PlatformUI.getWorkbench().getWorkingSetManager().removeWorkingSet(aggregateWorkingSet); 1723 } 1724 } 1725 } 1726 1727 1733 private void disposePerspective(Perspective persp, boolean notify) { 1734 perspList.remove(persp); 1736 if (notify) { 1737 window.firePerspectiveClosed(this, persp.getDesc()); 1738 } 1739 persp.dispose(); 1740 1741 stickyViewMan.remove(persp.getDesc().getId()); 1742 } 1743 1744 1747 public INavigationHistory getNavigationHistory() { 1748 return navigationHistory; 1749 } 1750 1751 1754 public boolean editActionSets() { 1755 Perspective persp = getActivePerspective(); 1756 if (persp == null) { 1757 return false; 1758 } 1759 1760 CustomizePerspectiveDialog dlg = window.createCustomizePerspectiveDialog(persp); 1762 1763 boolean ret = (dlg.open() == Window.OK); 1765 if (ret) { 1766 window.updateActionSets(); 1767 window.firePerspectiveChanged(this, getPerspective(), CHANGE_RESET); 1768 window.firePerspectiveChanged(this, getPerspective(), 1769 CHANGE_RESET_COMPLETE); 1770 } 1771 return ret; 1772 } 1773 1774 1777 public Perspective findPerspective(IPerspectiveDescriptor desc) { 1778 Iterator itr = perspList.iterator(); 1779 while (itr.hasNext()) { 1780 Perspective mgr = (Perspective) itr.next(); 1781 if (desc.getId().equals(mgr.getDesc().getId())) { 1782 return mgr; 1783 } 1784 } 1785 return null; 1786 } 1787 1788 1791 public IViewPart findView(String id) { 1792 IViewReference ref = findViewReference(id); 1793 if (ref == null) { 1794 return null; 1795 } 1796 return ref.getView(true); 1797 } 1798 1799 1804 public IViewReference findViewReference(String viewId) { 1805 return findViewReference(viewId, null); 1806 } 1807 1808 1813 public IViewReference findViewReference(String viewId, String secondaryId) { 1814 Perspective persp = getActivePerspective(); 1815 if (persp == null) { 1816 return null; 1817 } 1818 return persp.findView(viewId, secondaryId); 1819 } 1820 1821 1822 1832 private void firePropertyChange(String changeId, Object oldValue, 1833 Object newValue) { 1834 1835 UIListenerLogging.logPagePropertyChanged(this, changeId, oldValue, newValue); 1836 1837 Object [] listeners = propertyChangeListeners.getListeners(); 1838 PropertyChangeEvent event = new PropertyChangeEvent(this, changeId, 1839 oldValue, newValue); 1840 1841 for (int i = 0; i < listeners.length; i++) { 1842 ((IPropertyChangeListener) listeners[i]).propertyChange(event); 1843 } 1844 } 1845 1846 1849 public IActionBars getActionBars() { 1850 if (actionBars == null) { 1851 actionBars = new WWinActionBars(window); 1852 } 1853 return actionBars; 1854 } 1855 1856 1859 public IActionSetDescriptor[] getActionSets() { 1860 Collection collection = actionSets.getVisibleItems(); 1861 1862 return (IActionSetDescriptor[]) collection.toArray(new IActionSetDescriptor[collection.size()]); 1863 } 1864 1865 1868 public IEditorPart getActiveEditor() { 1869 return partList.getActiveEditor(); 1870 } 1871 1872 1878 public IEditorReference getActiveEditorReference() { 1879 return partList.getActiveEditorReference(); 1880 } 1881 1882 1885 public IWorkbenchPart getActivePart() { 1886 return partList.getActivePart(); 1887 } 1888 1889 1892 public IWorkbenchPartReference getActivePartReference() { 1893 return partList.getActivePartReference(); 1894 } 1895 1896 1900 public Perspective getActivePerspective() { 1901 return perspList.getActive(); 1902 } 1903 1904 1907 public Composite getClientComposite() { 1908 return composite; 1909 } 1910 1911 1916 public EditorManager getEditorManager() { 1917 return editorMgr; 1918 } 1919 1920 1923 public PerspectiveHelper getPerspectivePresentation() { 1924 if (getActivePerspective() != null) { 1925 return getActivePerspective().getPresentation(); 1926 } 1927 return null; 1928 } 1929 1930 1933 public EditorAreaHelper getEditorPresentation() { 1934 return editorPresentation; 1935 } 1936 1937 1940 public IEditorPart[] getEditors() { 1941 final IEditorReference refs[] = getEditorReferences(); 1942 final ArrayList result = new ArrayList (refs.length); 1943 Display d = getWorkbenchWindow().getShell().getDisplay(); 1944 d.syncExec(new Runnable () { 1946 public void run() { 1947 for (int i = 0; i < refs.length; i++) { 1948 IWorkbenchPart part = refs[i].getPart(true); 1949 if (part != null) { 1950 result.add(part); 1951 } 1952 } 1953 } 1954 }); 1955 final IEditorPart editors[] = new IEditorPart[result.size()]; 1956 return (IEditorPart[]) result.toArray(editors); 1957 } 1958 1959 public IEditorPart[] getDirtyEditors() { 1960 return getEditorManager().getDirtyEditors(); 1961 } 1962 1963 public ISaveablePart[] getDirtyParts() { 1964 List result = new ArrayList (3); 1965 IWorkbenchPartReference[] allParts = getAllParts(); 1966 for (int i = 0; i < allParts.length; i++) { 1967 IWorkbenchPartReference reference = allParts[i]; 1968 1969 IWorkbenchPart part = reference.getPart(false); 1970 if (part != null && part instanceof ISaveablePart) { 1971 ISaveablePart saveable = (ISaveablePart)part; 1972 if (saveable.isDirty()) { 1973 result.add(saveable); 1974 } 1975 } 1976 } 1977 1978 return (ISaveablePart[]) result.toArray(new ISaveablePart[result.size()]); 1979 } 1980 1981 1984 public IEditorPart findEditor(IEditorInput input) { 1985 return getEditorManager().findEditor(input); 1986 } 1987 1988 1991 public IEditorReference[] findEditors(IEditorInput input, String editorId, int matchFlags) { 1992 return getEditorManager().findEditors(input, editorId, matchFlags); 1993 } 1994 1995 1998 public IEditorReference[] getEditorReferences() { 1999 return editorPresentation.getEditors(); 2000 } 2001 2002 2005 public IViewReference[] getFastViews() { 2006 Perspective persp = getActivePerspective(); 2007 if (persp != null) { 2008 return persp.getFastViews(); 2009 } else { 2010 return new IViewReference[0]; 2011 } 2012 } 2013 2014 2017 public IAdaptable getInput() { 2018 return input; 2019 } 2020 2021 2025 public String getLabel() { 2026 String label = WorkbenchMessages.WorkbenchPage_UnknownLabel; 2027 IWorkbenchAdapter adapter = (IWorkbenchAdapter) Util.getAdapter(input, 2028 IWorkbenchAdapter.class); 2029 if (adapter != null) { 2030 label = adapter.getLabel(input); 2031 } 2032 Perspective persp = getActivePerspective(); 2033 if (persp != null) { 2034 label = NLS.bind(WorkbenchMessages.WorkbenchPage_PerspectiveFormat, label, persp.getDesc().getLabel()); 2035 } else if (deferredActivePersp != null) { 2036 label = NLS.bind(WorkbenchMessages.WorkbenchPage_PerspectiveFormat,label, deferredActivePersp.getLabel()); 2037 } 2038 return label; 2039 } 2040 2041 2044 public IPerspectiveDescriptor getPerspective() { 2045 if (deferredActivePersp != null) { 2046 return deferredActivePersp; 2047 } 2048 Perspective persp = getActivePerspective(); 2049 if (persp != null) { 2050 return persp.getDesc(); 2051 } else { 2052 return null; 2053 } 2054 } 2055 2056 2059 public ISelection getSelection() { 2060 return selectionService.getSelection(); 2061 } 2062 2063 2066 public ISelection getSelection(String partId) { 2067 return selectionService.getSelection(partId); 2068 } 2069 2070 2074 public ArrayList getShowInPartIds() { 2075 Perspective persp = getActivePerspective(); 2076 if (persp != null) { 2077 return persp.getShowInPartIds(); 2078 } else { 2079 return new ArrayList (); 2080 } 2081 } 2082 2083 2087 public void performedShowIn(String partId) { 2088 Perspective persp = getActivePerspective(); 2089 if (persp != null) { 2090 persp.performedShowIn(partId); 2091 } 2092 } 2093 2094 2097 public void sortShowInPartIds(ArrayList partIds) { 2098 final Perspective persp = getActivePerspective(); 2099 if (persp != null) { 2100 Collections.sort(partIds, new Comparator () { 2101 public int compare(Object a, Object b) { 2102 long ta = persp.getShowInTime((String ) a); 2103 long tb = persp.getShowInTime((String ) b); 2104 return (ta == tb) ? 0 : ((ta > tb) ? -1 : 1); 2105 } 2106 }); 2107 } 2108 } 2109 2110 2113 public ViewFactory getViewFactory() { 2114 if (viewFactory == null) { 2115 viewFactory = new ViewFactory(this, WorkbenchPlugin.getDefault() 2116 .getViewRegistry()); 2117 } 2118 return viewFactory; 2119 } 2120 2121 2124 public IViewReference[] getViewReferences() { 2125 Perspective persp = getActivePerspective(); 2126 if (persp != null) { 2127 return persp.getViewReferences(); 2128 } else { 2129 return new IViewReference[0]; 2130 } 2131 } 2132 2133 2136 public IViewPart[] getViews() { 2137 return getViews(null, true); 2138 } 2139 2140 2147 IViewPart[] getViews(Perspective persp, boolean restore) { 2148 if (persp == null) { 2149 persp = getActivePerspective(); 2150 } 2151 2152 if (persp != null) { 2153 IViewReference refs[] = persp.getViewReferences(); 2154 ArrayList parts = new ArrayList (refs.length); 2155 for (int i = 0; i < refs.length; i++) { 2156 IWorkbenchPart part = refs[i].getPart(restore); 2157 if (part != null) { 2158 parts.add(part); 2159 } 2160 } 2161 IViewPart[] result = new IViewPart[parts.size()]; 2162 return (IViewPart[]) parts.toArray(result); 2163 } 2164 return new IViewPart[0]; 2165 } 2166 2167 2170 public IWorkbenchWindow getWorkbenchWindow() { 2171 return window; 2172 } 2173 2174 2181 public IWorkingSet getWorkingSet() { 2182 return workingSet; 2183 } 2184 2185 2188 public void hideActionSet(String actionSetID) { 2189 Perspective persp = getActivePerspective(); 2190 if (persp != null) { 2191 persp.removeActionSet(actionSetID); 2192 window.updateActionSets(); 2193 window.firePerspectiveChanged(this, getPerspective(), 2194 CHANGE_ACTION_SET_HIDE); 2195 } 2196 } 2197 2198 2203 public void hideView(IViewReference ref) { 2204 2205 if (ref == null) { 2207 return; 2208 } 2209 2210 Perspective persp = getActivePerspective(); 2211 if (persp == null) { 2212 return; 2213 } 2214 2215 boolean promptedForSave = false; 2216 IViewPart view = ref.getView(false); 2217 if (view != null) { 2218 2219 if (!certifyPart(view)) { 2220 return; 2221 } 2222 2223 if (view instanceof ISaveablePart) { 2225 ISaveablePart saveable = (ISaveablePart)view; 2226 if (saveable.isSaveOnCloseNeeded()) { 2227 IWorkbenchWindow window = view.getSite().getWorkbenchWindow(); 2228 boolean success = EditorManager.saveAll(Collections.singletonList(view), true, true, false, window); 2229 if (!success) { 2230 return; 2232 } 2233 promptedForSave = true; 2234 } 2235 } 2236 } 2237 2238 int refCount = getViewFactory().getReferenceCount(ref); 2239 SaveablesList saveablesList = null; 2240 Object postCloseInfo = null; 2241 if (refCount == 1) { 2242 IWorkbenchPart actualPart = ref.getPart(false); 2243 if (actualPart != null) { 2244 saveablesList = (SaveablesList) actualPart 2245 .getSite().getService(ISaveablesLifecycleListener.class); 2246 postCloseInfo = saveablesList.preCloseParts(Collections 2247 .singletonList(actualPart), !promptedForSave, this 2248 .getWorkbenchWindow()); 2249 if (postCloseInfo==null) { 2250 return; 2252 } 2253 } 2254 } 2255 2256 window.firePerspectiveChanged(this, persp.getDesc(), ref, 2258 CHANGE_VIEW_HIDE); 2259 2260 PartPane pane = getPane(ref); 2261 pane.setInLayout(false); 2262 2263 updateActivePart(); 2264 2265 if (saveablesList != null) { 2266 saveablesList.postClose(postCloseInfo); 2267 } 2268 2269 persp.hideView(ref); 2271 2272 window.firePerspectiveChanged(this, getPerspective(), CHANGE_VIEW_HIDE); 2274 } 2275 2276 void refreshActiveView() { 2277 updateActivePart(); 2278 } 2279 2280 2283 public void hideView(IViewPart view) { 2284 hideView((IViewReference)getReference(view)); 2285 } 2286 2287 2299 private void init(WorkbenchWindow w, String layoutID, IAdaptable input, boolean openExtras) 2300 throws WorkbenchException { 2301 this.window = w; 2303 this.input = input; 2304 actionSets = new ActionSetManager(w); 2305 2306 createClientComposite(); 2308 editorPresentation = new EditorAreaHelper(this); 2309 editorMgr = new EditorManager(window, this, editorPresentation); 2310 2311 w.addPerspectiveReorderListener(new IReorderListener() { 2316 public void reorder(Object perspective, int newLoc) { 2317 perspList.reorder((IPerspectiveDescriptor)perspective, newLoc); 2318 } 2319 }); 2320 2321 if (openExtras) { 2322 openPerspectiveExtras(); 2323 } 2324 2325 if (layoutID != null) { 2327 PerspectiveDescriptor desc = (PerspectiveDescriptor) WorkbenchPlugin 2328 .getDefault().getPerspectiveRegistry() 2329 .findPerspectiveWithId(layoutID); 2330 if (desc == null) { 2331 throw new WorkbenchException( 2332 NLS.bind(WorkbenchMessages.WorkbenchPage_ErrorCreatingPerspective,layoutID )); 2333 } 2334 Perspective persp = findPerspective(desc); 2335 if (persp == null) { 2336 persp = createPerspective(desc, true); 2337 } 2338 perspList.setActive(persp); 2339 window.firePerspectiveActivated(this, desc); 2340 } 2341 2342 getExtensionTracker() 2343 .registerHandler( 2344 perspectiveChangeHandler, 2345 ExtensionTracker 2346 .createExtensionPointFilter(getPerspectiveExtensionPoint())); 2347 } 2348 2349 2352 public void openPerspectiveExtras() { 2353 String extras = PrefUtil.getAPIPreferenceStore().getString( 2354 IWorkbenchPreferenceConstants.PERSPECTIVE_BAR_EXTRAS); 2355 StringTokenizer tok = new StringTokenizer (extras, ", "); ArrayList descs = new ArrayList (); 2357 while (tok.hasMoreTokens()) { 2358 String id = tok.nextToken(); 2359 IPerspectiveDescriptor desc = WorkbenchPlugin.getDefault().getPerspectiveRegistry().findPerspectiveWithId(id); 2360 if (desc != null) { 2361 descs.add(desc); 2362 } 2363 } 2364 for (int i = descs.size(); --i >= 0;) { 2367 PerspectiveDescriptor desc = (PerspectiveDescriptor) descs.get(i); 2368 if (findPerspective(desc) == null) { 2369 createPerspective(desc, true); 2370 } 2371 } 2372 } 2373 2374 2377 public boolean isPartVisible(IWorkbenchPart part) { 2378 PartPane pane = getPane(part); 2379 return pane != null && pane.getVisible(); 2380 } 2381 2382 2385 public boolean isEditorAreaVisible() { 2386 Perspective persp = getActivePerspective(); 2387 if (persp == null) { 2388 return false; 2389 } 2390 return persp.isEditorAreaVisible(); 2391 } 2392 2393 2396 public boolean isFastView(IViewReference ref) { 2397 Perspective persp = getActivePerspective(); 2398 if (persp != null) { 2399 return persp.isFastView(ref); 2400 } else { 2401 return false; 2402 } 2403 } 2404 2405 2412 public boolean isCloseable(IViewReference ref) { 2413 Perspective persp = getActivePerspective(); 2414 if (persp != null) { 2415 return persp.isCloseable(ref); 2416 } 2417 return false; 2418 } 2419 2420 2427 public boolean isMoveable(IViewReference ref) { 2428 Perspective persp = getActivePerspective(); 2429 if (persp != null) { 2430 return persp.isMoveable(ref); 2431 } 2432 return false; 2433 } 2434 2435 2439 public boolean isFixedLayout() { 2440 Perspective persp = getActivePerspective(); 2441 if (persp != null) { 2442 return persp.isFixedLayout(); 2443 } else { 2444 return false; 2445 } 2446 } 2447 2448 2452 public IViewReference getActiveFastView() { 2453 Perspective persp = getActivePerspective(); 2454 if (persp != null) { 2455 return persp.getActiveFastView(); 2456 } else { 2457 return null; 2458 } 2459 } 2460 2461 2464 protected boolean isSaveNeeded() { 2465 return getEditorManager().isSaveAllNeeded(); 2466 } 2467 2468 2471 public boolean isPageZoomed() { 2472 Perspective persp = getActivePerspective(); 2473 if (persp == null) { 2474 return false; 2475 } 2476 if (persp.getPresentation() == null) { 2477 return false; 2478 } 2479 2480 if (Perspective.useNewMinMax(persp)) 2481 return persp.getPresentation().getMaximizedStack() != null; 2482 2483 return isZoomed(); 2485 } 2486 2487 2496 public boolean isZoomed() { 2497 Perspective persp = getActivePerspective(); 2498 if (persp == null) { 2499 return false; 2500 } 2501 if (persp.getPresentation() == null) { 2502 return false; 2503 } 2504 return persp.getPresentation().isZoomed(); 2505 } 2506 2507 2510 protected void onActivate() { 2511 composite.setVisible(true); 2512 Perspective persp = getActivePerspective(); 2513 2514 if (persp != null) { 2515 persp.onActivate(); 2516 updateVisibility(null, persp); 2517 } 2518 } 2519 2520 2523 protected void onDeactivate() { 2524 makeActiveEditor(null); 2525 makeActive(null); 2526 if (getActivePerspective() != null) { 2527 getActivePerspective().onDeactivate(); 2528 } 2529 composite.setVisible(false); 2530 } 2531 2532 2535 public void reuseEditor(IReusableEditor editor, IEditorInput input) { 2536 2537 IWorkbenchPartReference ref = getReference(editor); 2542 if (ref instanceof EditorReference) { 2543 EditorReference editorRef = (EditorReference) ref; 2544 2545 editorRef.setInput(input); 2546 } else { 2547 editor.setInput(input); 2548 } 2549 navigationHistory.markEditor(editor); 2550 } 2551 2552 2555 public IEditorPart openEditor(IEditorInput input, String editorID) 2556 throws PartInitException { 2557 return openEditor(input, editorID, true, MATCH_INPUT); 2558 } 2559 2560 2563 public IEditorPart openEditor(IEditorInput input, String editorID, 2564 boolean activate) throws PartInitException { 2565 return openEditor(input, editorID, activate, MATCH_INPUT); 2566 } 2567 2568 2571 public IEditorPart openEditor(final IEditorInput input, 2572 final String editorID, final boolean activate, final int matchFlags) 2573 throws PartInitException { 2574 return openEditor(input, editorID, activate, matchFlags, null); 2575 } 2576 2577 2580 public IEditorPart openEditor(final IEditorInput input, 2581 final String editorID, final boolean activate, final int matchFlags, 2582 final IMemento editorState) 2583 throws PartInitException { 2584 if (input == null || editorID == null) { 2585 throw new IllegalArgumentException (); 2586 } 2587 2588 final IEditorPart result[] = new IEditorPart[1]; 2589 final PartInitException ex[] = new PartInitException[1]; 2590 BusyIndicator.showWhile(window.getWorkbench().getDisplay(), 2591 new Runnable () { 2592 public void run() { 2593 try { 2594 result[0] = busyOpenEditor(input, editorID, 2595 activate, matchFlags, editorState); 2596 } catch (PartInitException e) { 2597 ex[0] = e; 2598 } 2599 } 2600 }); 2601 if (ex[0] != null) { 2602 throw ex[0]; 2603 } 2604 return result[0]; 2605 } 2606 2607 2608 2613 public IEditorPart openEditorFromDescriptor(final IEditorInput input, 2614 final IEditorDescriptor editorDescriptor, final boolean activate, 2615 final IMemento editorState) 2616 throws PartInitException { 2617 if (input == null || !(editorDescriptor instanceof EditorDescriptor)) { 2618 throw new IllegalArgumentException (); 2619 } 2620 2621 final IEditorPart result[] = new IEditorPart[1]; 2622 final PartInitException ex[] = new PartInitException[1]; 2623 BusyIndicator.showWhile(window.getWorkbench().getDisplay(), 2624 new Runnable () { 2625 public void run() { 2626 try { 2627 result[0] = busyOpenEditorFromDescriptor(input, (EditorDescriptor)editorDescriptor, 2628 activate, editorState); 2629 } catch (PartInitException e) { 2630 ex[0] = e; 2631 } 2632 } 2633 }); 2634 if (ex[0] != null) { 2635 throw ex[0]; 2636 } 2637 return result[0]; 2638 } 2639 2640 2643 private IEditorPart busyOpenEditor(IEditorInput input, String editorID, 2644 boolean activate, int matchFlags, IMemento editorState) throws PartInitException { 2645 2646 final Workbench workbench = (Workbench) getWorkbenchWindow() 2647 .getWorkbench(); 2648 workbench.largeUpdateStart(); 2649 2650 try { 2651 return busyOpenEditorBatched(input, editorID, activate, matchFlags, editorState); 2652 2653 } finally { 2654 workbench.largeUpdateEnd(); 2655 } 2656 } 2657 2658 2662 private IEditorPart busyOpenEditorFromDescriptor(IEditorInput input, EditorDescriptor editorDescriptor, 2663 boolean activate, IMemento editorState) throws PartInitException { 2664 2665 final Workbench workbench = (Workbench) getWorkbenchWindow() 2666 .getWorkbench(); 2667 workbench.largeUpdateStart(); 2668 2669 try { 2670 return busyOpenEditorFromDescriptorBatched(input, editorDescriptor, activate, editorState); 2671 2672 } finally { 2673 workbench.largeUpdateEnd(); 2674 } 2675 } 2676 2677 2682 private IEditorPart busyOpenEditorBatched(IEditorInput input, 2683 String editorID, boolean activate, int matchFlags, IMemento editorState) throws PartInitException { 2684 2685 IEditorPart editor = null; 2687 editor = getEditorManager().findEditor(editorID, input, ((TabBehaviour)Tweaklets.get(TabBehaviour.KEY)).getReuseEditorMatchFlags(matchFlags)); 2689 if (editor != null) { 2690 if (IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID.equals(editorID)) { 2691 if (editor.isDirty()) { 2692 MessageDialog dialog = new MessageDialog( 2693 getWorkbenchWindow().getShell(), 2694 WorkbenchMessages.Save, 2695 null, NLS.bind(WorkbenchMessages.WorkbenchPage_editorAlreadyOpenedMsg, input.getName()), 2697 MessageDialog.QUESTION, new String [] { 2698 IDialogConstants.YES_LABEL, 2699 IDialogConstants.NO_LABEL, 2700 IDialogConstants.CANCEL_LABEL }, 0); 2701 int saveFile = dialog.open(); 2702 if (saveFile == 0) { 2703 try { 2704 final IEditorPart editorToSave = editor; 2705 getWorkbenchWindow().run(false, false, 2706 new IRunnableWithProgress() { 2707 public void run(IProgressMonitor monitor) 2708 throws InvocationTargetException , 2709 InterruptedException { 2710 editorToSave.doSave(monitor); 2711 } 2712 }); 2713 } catch (InvocationTargetException e) { 2714 throw (RuntimeException ) e.getTargetException(); 2715 } catch (InterruptedException e) { 2716 return null; 2717 } 2718 } else if (saveFile == 2) { 2719 return null; 2720 } 2721 } 2722 } else { 2723 if (editor instanceof IShowEditorInput) { 2726 ((IShowEditorInput) editor).showEditorInput(input); 2727 } 2728 showEditor(activate, editor); 2729 return editor; 2730 } 2731 } 2732 2733 2734 IEditorReference ref = null; 2737 ref = getEditorManager().openEditor(editorID, input, true, editorState); 2738 if (ref != null) { 2739 editor = ref.getEditor(true); 2740 } 2741 2742 if (editor != null) { 2743 setEditorAreaVisible(true); 2744 if (activate) { 2745 if (editor instanceof MultiEditor) { 2746 activate(((MultiEditor) editor).getActiveEditor()); 2747 } else { 2748 activate(editor); 2749 } 2750 } else { 2751 bringToTop(editor); 2752 } 2753 window.firePerspectiveChanged(this, getPerspective(), ref, 2754 CHANGE_EDITOR_OPEN); 2755 window.firePerspectiveChanged(this, getPerspective(), 2756 CHANGE_EDITOR_OPEN); 2757 } 2758 2759 return editor; 2760 } 2761 2762 2766 private IEditorPart busyOpenEditorFromDescriptorBatched(IEditorInput input, 2767 EditorDescriptor editorDescriptor, boolean activate, IMemento editorState) throws PartInitException { 2768 2769 IEditorPart editor = null; 2770 IEditorReference ref = null; 2773 ref = getEditorManager().openEditorFromDescriptor(editorDescriptor, input, editorState); 2774 if (ref != null) { 2775 editor = ref.getEditor(true); 2776 } 2777 2778 if (editor != null) { 2779 setEditorAreaVisible(true); 2780 if (activate) { 2781 if (editor instanceof MultiEditor) { 2782 activate(((MultiEditor) editor).getActiveEditor()); 2783 } else { 2784 activate(editor); 2785 } 2786 } else { 2787 bringToTop(editor); 2788 } 2789 window.firePerspectiveChanged(this, getPerspective(), ref, 2790 CHANGE_EDITOR_OPEN); 2791 window.firePerspectiveChanged(this, getPerspective(), 2792 CHANGE_EDITOR_OPEN); 2793 } 2794 2795 return editor; 2796 } 2797 2798 public void openEmptyTab() { 2799 IEditorPart editor = null; 2800 EditorReference ref = null; 2801 ref = (EditorReference) getEditorManager().openEmptyTab(); 2802 if (ref != null) { 2803 editor = ref.getEmptyEditor((EditorDescriptor) ((EditorRegistry) WorkbenchPlugin 2804 .getDefault().getEditorRegistry()) 2805 .findEditor(EditorRegistry.EMPTY_EDITOR_ID)); 2806 } 2807 2808 if (editor != null) { 2809 setEditorAreaVisible(true); 2810 activate(editor); 2811 window.firePerspectiveChanged(this, getPerspective(), ref, 2812 CHANGE_EDITOR_OPEN); 2813 window.firePerspectiveChanged(this, getPerspective(), 2814 CHANGE_EDITOR_OPEN); 2815 } 2816 } 2817 2818 private void showEditor(boolean activate, IEditorPart editor) { 2819 setEditorAreaVisible(true); 2820 if (activate) { 2821 zoomOutIfNecessary(editor); 2822 activate(editor); 2823 } else { 2824 bringToTop(editor); 2825 } 2826 } 2827 2828 2831 public boolean isEditorPinned(IEditorPart editor) { 2832 WorkbenchPartReference ref = (WorkbenchPartReference)getReference(editor); 2833 return ref != null && ref.isPinned(); 2834 } 2835 2836 2842 private boolean partChangeAffectsZoom(IWorkbenchPartReference ref) { 2843 PartPane pane = ((WorkbenchPartReference) ref).getPane(); 2844 if (pane instanceof MultiEditorInnerPane) { 2845 pane = ((MultiEditorInnerPane) pane).getParentPane(); 2846 } 2847 return getActivePerspective().getPresentation().partChangeAffectsZoom( 2848 pane); 2849 } 2850 2851 2854 public void removeFastView(IViewReference ref) { 2855 Perspective persp = getActivePerspective(); 2856 if (persp == null) { 2857 return; 2858 } 2859 2860 persp.removeFastView(ref); 2862 2863 window.firePerspectiveChanged(this, getPerspective(), ref, 2865 CHANGE_FAST_VIEW_REMOVE); 2866 window.firePerspectiveChanged(this, getPerspective(), 2867 CHANGE_FAST_VIEW_REMOVE); 2868 } 2869 2870 2873 public void removePartListener(IPartListener l) { 2874 partList.getPartService().removePartListener(l); 2875 } 2876 2877 2880 public void removePartListener(IPartListener2 l) { 2881 partList.getPartService().removePartListener(l); 2882 } 2883 2884 2894 public void removePropertyChangeListener(IPropertyChangeListener listener) { 2895 propertyChangeListeners.remove(listener); 2896 } 2897 2898 2901 public void removeSelectionListener(ISelectionListener listener) { 2902 selectionService.removeSelectionListener(listener); 2903 } 2904 2905 2908 public void removeSelectionListener(String partId, 2909 ISelectionListener listener) { 2910 selectionService.removeSelectionListener(partId, listener); 2911 } 2912 2913 2916 public void removePostSelectionListener(ISelectionListener listener) { 2917 selectionService.removePostSelectionListener(listener); 2918 } 2919 2920 2923 public void removePostSelectionListener(String partId, 2924 ISelectionListener listener) { 2925 selectionService.removePostSelectionListener(partId, listener); 2926 } 2927 2928 2935 public void requestActivation(IWorkbenchPart part) { 2936 if (!certifyPart(part)) { 2938 return; 2939 } 2940 2941 if (part instanceof MultiEditor) { 2942 part = ((MultiEditor) part).getActiveEditor(); 2943 } 2944 2945 setActivePart(part); 2947 } 2948 2949 2953 public void resetPerspective() { 2954 ICoolBarManager2 mgr = (ICoolBarManager2) window.getCoolBarManager2(); 2958 try { 2959 mgr.getControl2().setRedraw(false); 2960 BusyIndicator.showWhile(null, new Runnable () { 2961 public void run() { 2962 busyResetPerspective(); 2963 } 2964 }); 2965 } finally { 2966 mgr.getControl2().setRedraw(true); 2967 } 2968 } 2969 2970 2976 public IStatus restoreState(IMemento memento, 2977 final IPerspectiveDescriptor activeDescriptor) { 2978 StartupThreading.runWithoutExceptions(new StartupRunnable() { 2979 2980 public void runWithException() throws Throwable { 2981 deferUpdates(true); 2982 }}); 2983 2984 try { 2985 String pageName = memento.getString(IWorkbenchConstants.TAG_LABEL); 2987 2988 String label = null; if (UIStats.isDebugging(UIStats.RESTORE_WORKBENCH)) { 2990 label = pageName == null ? "" : "::" + pageName; } 2992 2993 try { 2994 UIStats.start(UIStats.RESTORE_WORKBENCH, "WorkbenchPage" + label); if (pageName == null) { 2996 pageName = ""; } 2998 final MultiStatus result = new MultiStatus( 2999 PlatformUI.PLUGIN_ID, 3000 IStatus.OK, 3001 NLS.bind(WorkbenchMessages.WorkbenchPage_unableToRestorePerspective, pageName ), 3002 null); 3003 3004 String workingSetName = memento 3005 .getString(IWorkbenchConstants.TAG_WORKING_SET); 3006 if (workingSetName != null) { 3007 AbstractWorkingSetManager workingSetManager = (AbstractWorkingSetManager) getWorkbenchWindow() 3008 .getWorkbench().getWorkingSetManager(); 3009 setWorkingSet(workingSetManager.getWorkingSet(workingSetName)); 3010 } 3011 3012 IMemento workingSetMem = memento 3013 .getChild(IWorkbenchConstants.TAG_WORKING_SETS); 3014 if (workingSetMem != null) { 3015 IMemento[] workingSetChildren = workingSetMem 3016 .getChildren(IWorkbenchConstants.TAG_WORKING_SET); 3017 List workingSetList = new ArrayList ( 3018 workingSetChildren.length); 3019 for (int i = 0; i < workingSetChildren.length; i++) { 3020 IWorkingSet set = getWorkbenchWindow().getWorkbench() 3021 .getWorkingSetManager().getWorkingSet( 3022 workingSetChildren[i].getID()); 3023 if (set != null) { 3024 workingSetList.add(set); 3025 } 3026 } 3027 3028 workingSets = (IWorkingSet[]) workingSetList 3029 .toArray(new IWorkingSet[workingSetList.size()]); 3030 } 3031 3032 aggregateWorkingSetId = memento.getString(ATT_AGGREGATE_WORKING_SET_ID); 3033 3034 IWorkingSet setWithId = window.getWorkbench().getWorkingSetManager().getWorkingSet(aggregateWorkingSetId); 3035 3036 if (setWithId instanceof AggregateWorkingSet) { 3038 aggregateWorkingSet = (AggregateWorkingSet) setWithId; 3039 } 3040 IMemento childMem = memento 3042 .getChild(IWorkbenchConstants.TAG_EDITORS); 3043 result.merge(getEditorManager().restoreState(childMem)); 3044 3045 childMem = memento.getChild(IWorkbenchConstants.TAG_VIEWS); 3046 if (childMem != null) { 3047 result.merge(getViewFactory().restoreState(childMem)); 3048 } 3049 3050 childMem = memento.getChild(IWorkbenchConstants.TAG_PERSPECTIVES); 3052 String activePartID = childMem 3053 .getString(IWorkbenchConstants.TAG_ACTIVE_PART); 3054 String activePartSecondaryID = null; 3055 if (activePartID != null) { 3056 activePartSecondaryID = ViewFactory 3057 .extractSecondaryId(activePartID); 3058 if (activePartSecondaryID != null) { 3059 activePartID = ViewFactory.extractPrimaryId(activePartID); 3060 } 3061 } 3062 final String activePerspectiveID = childMem 3063 .getString(IWorkbenchConstants.TAG_ACTIVE_PERSPECTIVE); 3064 3065 final IMemento perspMems[] = childMem 3067 .getChildren(IWorkbenchConstants.TAG_PERSPECTIVE); 3068 final Perspective activePerspectiveArray [] = new Perspective[1]; 3069 3070 for (int i = 0; i < perspMems.length; i++) { 3071 3072 final IMemento current = perspMems[i]; 3073 StartupThreading 3074 .runWithoutExceptions(new StartupRunnable() { 3075 3076 public void runWithException() throws Throwable { 3077 Perspective persp = new Perspective(null, 3078 WorkbenchPage.this); 3079 result.merge(persp.restoreState(current)); 3080 final IPerspectiveDescriptor desc = persp 3081 .getDesc(); 3082 if (desc.equals(activeDescriptor)) { 3083 activePerspectiveArray[0] = persp; 3084 } else if ((activePerspectiveArray[0] == null) 3085 && desc.getId().equals( 3086 activePerspectiveID)) { 3087 activePerspectiveArray[0] = persp; 3088 } 3089 perspList.add(persp); 3090 window.firePerspectiveOpened( 3091 WorkbenchPage.this, desc); 3092 } 3093 }); 3094 } 3095 Perspective activePerspective = activePerspectiveArray[0]; 3096 boolean restoreActivePerspective = false; 3097 if (activeDescriptor == null) { 3098 restoreActivePerspective = true; 3099 3100 } else if (activePerspective != null 3101 && activePerspective.getDesc().equals(activeDescriptor)) { 3102 restoreActivePerspective = true; 3103 } else { 3104 restoreActivePerspective = false; 3105 activePerspective = createPerspective((PerspectiveDescriptor) activeDescriptor, true); 3106 if (activePerspective == null) { 3107 result 3108 .merge(new Status( 3109 IStatus.ERROR, 3110 PlatformUI.PLUGIN_ID, 3111 0, 3112 NLS.bind(WorkbenchMessages.Workbench_showPerspectiveError, activeDescriptor.getId() ), 3113 null)); 3114 } 3115 } 3116 3117 perspList.setActive(activePerspective); 3118 3119 activePerspective = perspList.getActive(); 3122 if (activePerspective == null) { 3123 activePerspective = perspList.getNextActive(); 3124 perspList.setActive(activePerspective); 3125 } 3126 if (activePerspective != null && restoreActivePerspective) { 3127 result.merge(activePerspective.restoreState()); 3128 } 3129 3130 if (activePerspective != null) { 3131 final Perspective myPerspective = activePerspective; 3132 final String myActivePartId = activePartID, mySecondaryId = activePartSecondaryID; 3133 StartupThreading.runWithoutExceptions(new StartupRunnable() { 3134 3135 public void runWithException() throws Throwable { 3136 window.firePerspectiveActivated(WorkbenchPage.this, myPerspective 3137 .getDesc()); 3138 3139 if (myActivePartId != null) { 3141 IViewReference ref = myPerspective.findView( 3142 myActivePartId, mySecondaryId); 3143 3144 if (ref != null) { 3145 activationList.setActive(ref); 3146 } 3147 } 3148 }}); 3149 3150 } 3151 3152 childMem = memento 3153 .getChild(IWorkbenchConstants.TAG_NAVIGATION_HISTORY); 3154 if (childMem != null) { 3155 navigationHistory.restoreState(childMem); 3156 } else if (getActiveEditor() != null) { 3157 navigationHistory.markEditor(getActiveEditor()); 3158 } 3159 3160 stickyViewMan.restore(memento); 3162 3163 return result; 3164 } finally { 3165 String blame = activeDescriptor == null ? pageName : activeDescriptor.getId(); 3166 UIStats.end(UIStats.RESTORE_WORKBENCH, blame, "WorkbenchPage" + label); } 3168 } finally { 3169 StartupThreading.runWithoutExceptions(new StartupRunnable() { 3170 3171 public void runWithException() throws Throwable { 3172 deferUpdates(false); 3173 } 3174 }); 3175 } 3176 } 3177 3178 3181 public boolean saveAllEditors(boolean confirm) { 3182 return saveAllEditors(confirm, false); 3183 } 3184 3185 3191 public boolean saveAllEditors(boolean confirm, boolean addNonPartSources) { 3192 return getEditorManager().saveAll(confirm, false, addNonPartSources); 3193 } 3194 3195 3198 protected boolean savePart(ISaveablePart saveable, IWorkbenchPart part, 3199 boolean confirm) { 3200 return getEditorManager().savePart(saveable, part, confirm); 3203 } 3204 3205 3214 public boolean saveEditor(IEditorPart editor, boolean confirm) { 3215 return savePart(editor, editor, confirm); 3216 } 3217 3218 3221 public void savePerspective() { 3222 Perspective persp = getActivePerspective(); 3223 if (persp == null) { 3224 return; 3225 } 3226 3227 if (isZoomed()) { 3229 zoomOut(); 3230 } 3231 3232 persp.saveDesc(); 3233 } 3234 3235 3238 public void savePerspectiveAs(IPerspectiveDescriptor newDesc) { 3239 Perspective persp = getActivePerspective(); 3240 if (persp == null) { 3241 return; 3242 } 3243 IPerspectiveDescriptor oldDesc = persp.getDesc(); 3244 3245 if (isZoomed()) { 3247 zoomOut(); 3248 } 3249 3250 persp.saveDescAs(newDesc); 3251 window.firePerspectiveSavedAs(this, oldDesc, newDesc); 3252 } 3253 3254 3257 public IStatus saveState(IMemento memento) { 3258 if (isZoomed()) { 3260 zoomOut(); 3261 } 3262 3263 MultiStatus result = new MultiStatus( 3264 PlatformUI.PLUGIN_ID, 3265 IStatus.OK, 3266 NLS.bind(WorkbenchMessages.WorkbenchPage_unableToSavePerspective, getLabel()), 3267 null); 3268 3269 IMemento childMem = memento 3271 .createChild(IWorkbenchConstants.TAG_EDITORS); 3272 result.merge(editorMgr.saveState(childMem)); 3273 3274 childMem = memento.createChild(IWorkbenchConstants.TAG_VIEWS); 3275 result.merge(getViewFactory().saveState(childMem)); 3276 3277 childMem = memento.createChild(IWorkbenchConstants.TAG_PERSPECTIVES); 3279 if (getPerspective() != null) { 3280 childMem.putString(IWorkbenchConstants.TAG_ACTIVE_PERSPECTIVE, 3281 getPerspective().getId()); 3282 } 3283 if (getActivePart() != null) { 3284 if (getActivePart() instanceof IViewPart) { 3285 IViewReference ref = (IViewReference) getReference(getActivePart()); 3286 if (ref != null) { 3287 childMem.putString(IWorkbenchConstants.TAG_ACTIVE_PART, 3288 ViewFactory.getKey(ref)); 3289 } 3290 } else { 3291 childMem.putString(IWorkbenchConstants.TAG_ACTIVE_PART, 3292 getActivePart().getSite().getId()); 3293 } 3294 } 3295 3296 Iterator itr = perspList.iterator(); 3298 while (itr.hasNext()) { 3299 Perspective persp = (Perspective) itr.next(); 3300 IMemento gChildMem = childMem 3301 .createChild(IWorkbenchConstants.TAG_PERSPECTIVE); 3302 result.merge(persp.saveState(gChildMem)); 3303 } 3304 if (workingSet != null) { 3306 memento.putString(IWorkbenchConstants.TAG_WORKING_SET, workingSet 3307 .getName()); 3308 } 3309 3310 IMemento workingSetMem = memento 3311 .createChild(IWorkbenchConstants.TAG_WORKING_SETS); 3312 for (int i = 0; i < workingSets.length; i++) { 3313 workingSetMem.createChild(IWorkbenchConstants.TAG_WORKING_SET, 3314 workingSets[i].getName()); 3315 } 3316 3317 if (aggregateWorkingSetId != null) { 3318 memento.putString(ATT_AGGREGATE_WORKING_SET_ID, aggregateWorkingSetId); 3319 } 3320 3321 navigationHistory.saveState(memento 3322 .createChild(IWorkbenchConstants.TAG_NAVIGATION_HISTORY)); 3323 3324 3325 stickyViewMan.save(memento); 3327 3328 return result; 3329 } 3330 3331 private String getId(IWorkbenchPart part) { 3332 return getId(getReference(part)); 3333 } 3334 3335 private String getId(IWorkbenchPartReference ref) { 3336 if (ref == null) { 3337 return "null"; } return ref.getId(); 3339 } 3340 3341 3344 private void setActivePart(IWorkbenchPart newPart) { 3345 if (getActivePart() == newPart) { 3347 return; 3348 } 3349 3350 if (partBeingActivated != null) { 3351 if (partBeingActivated.getPart(false) != newPart) { 3352 WorkbenchPlugin.log(new RuntimeException (NLS.bind( 3353 "WARNING: Prevented recursive attempt to activate part {0} while still in the middle of activating part {1}", getId(newPart), getId(partBeingActivated)))); 3355 } 3356 return; 3357 } 3358 3359 String label = null; if (UIStats.isDebugging(UIStats.ACTIVATE_PART)) { 3363 label = newPart != null ? newPart.getTitle() : "none"; } 3365 try { 3366 IWorkbenchPartReference partref = getReference(newPart); 3367 IWorkbenchPartReference realPartRef = null; 3368 if (newPart != null) { 3369 IWorkbenchPartSite site = newPart.getSite(); 3370 if (site instanceof PartSite) { 3371 realPartRef = ((PartSite) site).getPane() 3372 .getPartReference(); 3373 } 3374 } 3375 3376 partBeingActivated = realPartRef; 3377 3378 UIStats.start(UIStats.ACTIVATE_PART, label); 3379 Perspective persp = getActivePerspective(); 3381 if (persp != null) { 3382 persp.partActivated(newPart); 3383 } 3384 3385 IWorkbenchPart oldPart = getActivePart(); 3387 if (oldPart != null) { 3388 deactivatePart(oldPart); 3389 } 3390 3391 if (newPart != null) { 3393 activationList.setActive(newPart); 3394 if (newPart instanceof IEditorPart) { 3395 makeActiveEditor((IEditorReference)realPartRef); 3396 } 3397 } 3398 activatePart(newPart); 3399 3400 actionSwitcher.updateActivePart(newPart); 3401 3402 partList.setActivePart(partref); 3403 } finally { 3404 partBeingActivated = null; 3405 Object blame = newPart == null ? (Object )this : newPart; 3406 UIStats.end(UIStats.ACTIVATE_PART, blame, label); 3407 } 3408 } 3409 3410 3413 public void setEditorAreaVisible(boolean showEditorArea) { 3414 Perspective persp = getActivePerspective(); 3415 if (persp == null) { 3416 return; 3417 } 3418 if (showEditorArea == persp.isEditorAreaVisible()) { 3419 return; 3420 } 3421 if (isZoomed()) { 3423 zoomOut(); 3424 } 3425 if (showEditorArea) { 3427 persp.showEditorArea(); 3428 window.firePerspectiveChanged(this, getPerspective(), 3429 CHANGE_EDITOR_AREA_SHOW); 3430 } else { 3431 persp.hideEditorArea(); 3432 updateActivePart(); 3433 window.firePerspectiveChanged(this, getPerspective(), 3434 CHANGE_EDITOR_AREA_HIDE); 3435 } 3436 } 3437 3438 3443 private void setPerspective(Perspective newPersp) { 3444 Perspective oldPersp = getActivePerspective(); 3446 if (oldPersp == newPersp) { 3447 return; 3448 } 3449 3450 window.largeUpdateStart(); 3451 try { 3452 if (oldPersp != null) { 3453 window.firePerspectivePreDeactivate(this, oldPersp.getDesc()); 3455 } 3456 3457 if (newPersp != null) { 3458 IStatus status = newPersp.restoreState(); 3459 if (status.getSeverity() != IStatus.OK) { 3460 String title = WorkbenchMessages.WorkbenchPage_problemRestoringTitle; 3461 String msg = WorkbenchMessages.WorkbenchPage_errorReadingState; 3462 ErrorDialog.openError(getWorkbenchWindow().getShell(), title, 3463 msg, status); 3464 } 3465 } 3466 3467 3468 if (oldPersp != null) { 3470 oldPersp.onDeactivate(); 3471 3472 window.firePerspectiveDeactivated(this, oldPersp.getDesc()); 3474 } 3475 3476 perspList.setActive(newPersp); 3478 if (newPersp != null) { 3479 newPersp.onActivate(); 3480 3481 window.firePerspectiveActivated(this, newPersp.getDesc()); 3483 } 3484 3485 updateVisibility(oldPersp, newPersp); 3486 3487 window.updateActionSets(); 3489 3490 stickyViewMan.update(oldPersp, newPersp); 3492 3493 } finally { 3494 window.largeUpdateEnd(); 3495 if (newPersp == null) { 3496 return; 3497 } 3498 IPerspectiveDescriptor desc = newPersp.getDesc(); 3499 if (desc == null) { 3500 return; 3501 } 3502 if (dirtyPerspectives.remove(desc.getId())) { 3503 suggestReset(); 3504 } 3505 } 3506 } 3507 3508 void perspectiveActionSetChanged(Perspective perspective, IActionSetDescriptor descriptor, int changeType) { 3509 if (perspective == getActivePerspective()) { 3510 actionSets.change(descriptor, changeType); 3511 } 3512 } 3513 3514 3517 private void updateVisibility(Perspective oldPersp, Perspective newPersp) { 3518 3519 IWorkbenchPartReference[] oldRefs = new IWorkbenchPartReference[0]; 3521 if (oldPersp != null) { 3522 oldRefs = oldPersp.getViewReferences(); 3523 for (int i = 0; i < oldRefs.length; i++) { 3524 PartPane pane = ((WorkbenchPartReference) oldRefs[i]).getPane(); 3525 pane.setInLayout(false); 3526 } 3527 } 3528 3529 PerspectiveHelper pres = null; 3530 if (newPersp != null) { 3532 pres = newPersp.getPresentation(); 3533 IWorkbenchPartReference[] newRefs = newPersp.getViewReferences(); 3534 for (int i = 0; i < newRefs.length; i++) { 3535 WorkbenchPartReference ref = (WorkbenchPartReference)newRefs[i]; 3536 PartPane pane = ref.getPane(); 3537 if (pres.isPartVisible(ref)) { 3538 activationList.bringToTop(ref); 3539 } 3540 3541 pane.setInLayout(true); 3542 } 3543 } 3544 3545 updateActivePart(); 3546 3547 for (int i = 0; i < oldRefs.length; i++) { 3549 WorkbenchPartReference ref = (WorkbenchPartReference)oldRefs[i]; 3550 3551 PartPane pane = ref.getPane(); 3552 if (pres == null || !pres.isPartVisible(ref)) { 3553 pane.setVisible(false); 3554 } 3555 } 3556 } 3557 3558 3564 public void setPerspective(final IPerspectiveDescriptor desc) { 3565 if (Util.equals(getPerspective(), desc)) { 3566 return; 3567 } 3568 ICoolBarManager2 mgr = (ICoolBarManager2) window.getCoolBarManager2(); 3572 try { 3573 mgr.getControl2().setRedraw(false); 3574 getClientComposite().setRedraw(false); 3575 BusyIndicator.showWhile(null, new Runnable () { 3577 public void run() { 3578 busySetPerspective(desc); 3579 } 3580 }); 3581 } finally { 3582 getClientComposite().setRedraw(true); 3583 mgr.getControl2().setRedraw(true); 3584 IWorkbenchPart part = getActivePart(); 3585 if (part != null) { 3586 part.setFocus(); 3587 } 3588 } 3589 } 3590 3591 3596 public PartService getPartService() { 3597 return (PartService)partList.getPartService(); 3598 } 3599 3600 3603 protected void resetToolBarLayout() { 3604 ICoolBarManager2 mgr = (ICoolBarManager2) window.getCoolBarManager2(); 3605 mgr.resetItemOrder(); 3606 } 3607 3608 3617 public void setWorkingSet(IWorkingSet newWorkingSet) { 3618 IWorkingSet oldWorkingSet = workingSet; 3619 3620 workingSet = newWorkingSet; 3621 if (oldWorkingSet != newWorkingSet) { 3622 firePropertyChange(CHANGE_WORKING_SET_REPLACE, oldWorkingSet, 3623 newWorkingSet); 3624 } 3625 if (newWorkingSet != null) { 3626 WorkbenchPlugin.getDefault().getWorkingSetManager() 3627 .addPropertyChangeListener(workingSetPropertyChangeListener); 3628 } else { 3629 WorkbenchPlugin.getDefault().getWorkingSetManager() 3630 .removePropertyChangeListener(workingSetPropertyChangeListener); 3631 } 3632 } 3633 3634 3637 public void showActionSet(String actionSetID) { 3638 Perspective persp = getActivePerspective(); 3639 if (persp != null) { 3640 ActionSetRegistry reg = WorkbenchPlugin.getDefault() 3641 .getActionSetRegistry(); 3642 3643 IActionSetDescriptor desc = reg.findActionSet(actionSetID); 3644 if (desc != null) { 3645 persp.addActionSet(desc); 3646 window.updateActionSets(); 3647 window.firePerspectiveChanged(this, getPerspective(), 3648 CHANGE_ACTION_SET_SHOW); 3649 } 3650 } 3651 } 3652 3653 3656 public IViewPart showView(String viewID) throws PartInitException { 3657 return showView(viewID, null, VIEW_ACTIVATE); 3658 } 3659 3660 3666 public IViewPart showView(final String viewID, final String secondaryID, 3667 final int mode) throws PartInitException { 3668 3669 if (secondaryID != null) { 3670 if (secondaryID.length() == 0 3671 || secondaryID.indexOf(ViewFactory.ID_SEP) != -1) { 3672 throw new IllegalArgumentException (WorkbenchMessages.WorkbenchPage_IllegalSecondaryId); 3673 } 3674 } 3675 if (!certifyMode(mode)) { 3676 throw new IllegalArgumentException (WorkbenchMessages.WorkbenchPage_IllegalViewMode); 3677 } 3678 3679 final Object [] result = new Object [1]; 3681 BusyIndicator.showWhile(null, new Runnable () { 3682 public void run() { 3683 try { 3684 result[0] = busyShowView(viewID, secondaryID, mode); 3685 } catch (PartInitException e) { 3686 result[0] = e; 3687 } 3688 } 3689 }); 3690 if (result[0] instanceof IViewPart) { 3691 return (IViewPart) result[0]; 3692 } else if (result[0] instanceof PartInitException) { 3693 throw (PartInitException) result[0]; 3694 } else { 3695 throw new PartInitException(WorkbenchMessages.WorkbenchPage_AbnormalWorkbenchCondition); 3696 } 3697 } 3698 3699 3704 private boolean certifyMode(int mode) { 3705 switch (mode) { 3706 case VIEW_ACTIVATE: 3707 case VIEW_VISIBLE: 3708 case VIEW_CREATE: 3709 return true; 3710 default: 3711 return false; 3712 } 3713 } 3714 3715 3718 public void hideFastView() { 3719 Perspective persp = getActivePerspective(); 3720 if (persp != null) { 3721 IViewReference ref = persp.getActiveFastView(); 3722 if (ref != null) { 3723 toggleFastView(ref); 3724 } 3725 } 3726 } 3727 3728 3732 public void toggleFastView(IViewReference ref) { 3733 Perspective persp = getActivePerspective(); 3734 if (persp != null) { 3735 persp.toggleFastView(ref); 3736 if (ref != persp.getActiveFastView()) { 3738 IWorkbenchPart previouslyActive = activationList 3739 .getPreviouslyActive(); 3740 IEditorPart activeEditor = getActiveEditor(); 3741 if (activeEditor != null 3742 && previouslyActive instanceof IEditorPart) { 3743 setActivePart(activeEditor); 3744 } else { 3745 setActivePart(previouslyActive); 3746 } 3747 } 3748 } 3749 } 3750 3751 3757 public void setState(IWorkbenchPartReference ref, int newState) { 3758 Perspective persp = getActivePerspective(); 3759 if (persp == null) { 3760 return; 3761 } 3762 3763 PartPane pane = ((WorkbenchPartReference) ref).getPane(); 3764 3765 if (!pane.isDocked()) { 3770 pane.setZoomed(newState == IStackPresentationSite.STATE_MAXIMIZED); 3771 return; 3772 } 3773 3774 if (ref instanceof IViewReference 3775 && persp.isFastView((IViewReference) ref)) { 3776 persp.setFastViewState(newState); 3777 return; 3778 } 3779 3780 if (Perspective.useNewMinMax(persp)) { 3781 PartStack parent = ((PartStack)pane.getContainer()); 3783 parent.setState(newState); 3784 return; 3785 } 3786 3787 boolean wasZoomed = isZoomed(); 3788 boolean isZoomed = newState == IStackPresentationSite.STATE_MAXIMIZED; 3789 3790 if (wasZoomed && !isZoomed) { 3792 zoomOut(); 3793 } else if (!wasZoomed && isZoomed) { 3794 persp.getPresentation().zoomIn(ref); 3795 activate(ref.getPart(true)); 3796 } 3797 3798 PartStack parent = ((PartStack)pane.getContainer()); 3799 3800 if (parent != null) { 3801 parent.setMinimized(newState == IStackPresentationSite.STATE_MINIMIZED); 3802 } 3803} 3804 3805 3808 public void setPartState(IWorkbenchPartReference ref, int state) { 3809 setState(ref, state); 3810 } 3811 3812 3818 int getState(IWorkbenchPartReference ref) { 3819 Perspective persp = getActivePerspective(); 3820 if (persp == null) { 3821 return IStackPresentationSite.STATE_RESTORED; 3822 } 3823 3824 PartPane pane = ((WorkbenchPartReference) ref).getPane(); 3825 3826 if (ref instanceof IViewReference 3827 && persp.isFastView((IViewReference) ref)) { 3828 return persp.getFastViewState(); 3829 } 3830 3831 PartStack parent = ((PartStack)pane.getContainer()); 3832 3833 if (parent != null) { 3834 return parent.getState(); 3835 } 3836 3837 return IStackPresentationSite.STATE_RESTORED; 3838 } 3839 3840 3843 public int getPartState(IWorkbenchPartReference ref) { 3844 return getState(ref); 3845 } 3846 3847 3850 public void toggleZoom(IWorkbenchPartReference ref) { 3851 int oldState = getState(ref); 3852 boolean shouldZoom = oldState != IStackPresentationSite.STATE_MAXIMIZED; 3853 int newState = shouldZoom ? IStackPresentationSite.STATE_MAXIMIZED : IStackPresentationSite.STATE_RESTORED; 3854 3855 setState(ref, newState); 3856 } 3857 3858 3861 public void updateActionBars() { 3862 window.updateActionBars(); 3863 } 3864 3865 3869 private void updateTabList(IWorkbenchPart part) { 3870 PartSite site = (PartSite) part.getSite(); 3871 PartPane pane = site.getPane(); 3872 if (pane instanceof ViewPane) { 3873 ViewPane viewPane = (ViewPane) pane; 3874 Control[] tabList = viewPane.getTabList(); 3875 if (!pane.isDocked()) { 3876 viewPane.getControl().getShell().setTabList(tabList); 3877 } else { 3878 getClientComposite().setTabList(tabList); 3879 } 3880 } else if (pane instanceof EditorPane) { 3881 EditorSashContainer ea = ((EditorPane) pane).getWorkbook() 3882 .getEditorArea(); 3883 ea.updateTabList(); 3884 getClientComposite().setTabList(new Control[] { ea.getParent() }); 3885 } 3886 } 3887 3888 3889 3892 public void zoomOut() { 3893 Perspective persp = getActivePerspective(); 3894 if (persp != null) { 3895 persp.getPresentation().zoomOut(); 3896 } 3897 } 3898 3899 3906 private void zoomOutIfNecessary(IWorkbenchPart part) { 3907 if (isZoomed() && partChangeAffectsZoom(((PartSite)part.getSite()).getPartReference())) { 3908 zoomOut(); 3909 } 3910 } 3911 3912 3915 public int getEditorReuseThreshold() { 3916 return ((TabBehaviour)Tweaklets.get(TabBehaviour.KEY)).getEditorReuseThreshold(); 3917 } 3918 3919 3922 public void setEditorReuseThreshold(int openEditors) { 3923 } 3924 3925 3928 public IEditorReference[] getSortedEditors() { 3929 return activationList.getEditors(); 3930 } 3931 3932 3935 public IPerspectiveDescriptor[] getOpenPerspectives() { 3936 Perspective opened[] = perspList.getOpenedPerspectives(); 3937 IPerspectiveDescriptor[] result = new IPerspectiveDescriptor[opened.length]; 3938 for (int i = 0; i < result.length; i++) { 3939 result[i] = opened[i].getDesc(); 3940 } 3941 return result; 3942 } 3943 3944 3950 Perspective [] getOpenInternalPerspectives() { 3951 return perspList.getOpenedPerspectives(); 3952 } 3953 3954 3963 Perspective getFirstPerspectiveWithView(IViewPart part) { 3964 Perspective [] perspectives = perspList.getSortedPerspectives(); 3965 for (int i=perspectives.length - 1; i >= 0; i--) { 3966 if (perspectives[i].containsView(part)) { 3967 return perspectives[i]; 3968 } 3969 } 3970 return null; 3972 } 3973 3974 3977 public IPerspectiveDescriptor[] getSortedPerspectives() { 3978 Perspective sortedArray[] = perspList.getSortedPerspectives(); 3979 IPerspectiveDescriptor[] result = new IPerspectiveDescriptor[sortedArray.length]; 3980 for (int i = 0; i < result.length; i++) { 3981 result[i] = sortedArray[i].getDesc(); 3982 } 3983 return result; 3984 } 3985 3986 3989 public IWorkbenchPartReference[] getSortedParts() { 3990 return activationList.getParts(); 3991 } 3992 3993 4001 public IWorkbenchPartReference getReference(IWorkbenchPart part) { 4002 if (part == null) { 4003 return null; 4004 } 4005 IWorkbenchPartSite site = part.getSite(); 4006 if (!(site instanceof PartSite)) { 4007 return null; 4008 } 4009 PartSite partSite = ((PartSite) site); 4010 PartPane pane = partSite.getPane(); 4011 if (pane instanceof MultiEditorInnerPane) { 4012 MultiEditorInnerPane innerPane = (MultiEditorInnerPane) pane; 4013 return innerPane.getParentPane().getPartReference(); 4014 } 4015 return partSite.getPartReference(); 4016 } 4017 4018 private class ActivationList { 4019 List parts = new ArrayList (); 4021 4022 4025 void setActive(IWorkbenchPart part) { 4026 if (parts.size() <= 0) { 4027 return; 4028 } 4029 IWorkbenchPartReference ref = getReference(part); 4030 if (ref != null) { 4031 if (ref == parts.get(parts.size() - 1)) { 4032 return; 4033 } 4034 parts.remove(ref); 4035 parts.add(ref); 4036 } 4037 } 4038 4039 4043 void bringToTop(IWorkbenchPartReference ref) { 4044 ILayoutContainer targetContainer = getContainer(ref); 4045 4046 int newIndex = lastIndexOfContainer(targetContainer); 4047 4048 if (newIndex >= 0 && ref == parts.get(newIndex)) 4050 return; 4051 4052 parts.remove(ref); 4053 if(newIndex >= 0) 4054 parts.add(newIndex, ref); 4055 else 4056 parts.add(ref); 4057 } 4058 4059 4063 int lastIndexOfContainer(ILayoutContainer container) { 4064 for (int i = parts.size() - 1; i >= 0; i--) { 4065 IWorkbenchPartReference ref = (IWorkbenchPartReference)parts.get(i); 4066 4067 ILayoutContainer cnt = getContainer(ref); 4068 if (cnt == container) { 4069 return i; 4070 } 4071 } 4072 4073 return -1; 4074 } 4075 4076 4079 void setActive(IWorkbenchPartReference ref) { 4080 setActive(ref.getPart(true)); 4081 } 4082 4083 4086 void add(IWorkbenchPartReference ref) { 4087 if (parts.indexOf(ref) >= 0) { 4088 return; 4089 } 4090 4091 IWorkbenchPart part = ref.getPart(false); 4092 if (part != null) { 4093 PartPane pane = ((PartSite) part.getSite()).getPane(); 4094 if (pane instanceof MultiEditorInnerPane) { 4095 MultiEditorInnerPane innerPane = (MultiEditorInnerPane) pane; 4096 add(innerPane.getParentPane().getPartReference()); 4097 return; 4098 } 4099 } 4100 parts.add(0, ref); 4101 } 4102 4103 4106 IWorkbenchPart getActive() { 4107 if (parts.isEmpty()) { 4108 return null; 4109 } 4110 return getActive(parts.size() - 1); 4111 } 4112 4113 4116 IWorkbenchPart getPreviouslyActive() { 4117 if (parts.size() < 2) { 4118 return null; 4119 } 4120 return getActive(parts.size() - 2); 4121 } 4122 4123 private IWorkbenchPart getActive(int start) { 4124 IWorkbenchPartReference ref = getActiveReference(start, false); 4125 4126 if (ref == null) { 4127 return null; 4128 } 4129 4130 return ref.getPart(true); 4131 } 4132 4133 public IWorkbenchPartReference getActiveReference(boolean editorsOnly) { 4134 return getActiveReference(parts.size() - 1, editorsOnly); 4135 } 4136 4137 private IWorkbenchPartReference getActiveReference(int start, boolean editorsOnly) { 4138 IWorkbenchPartReference nonObscured = getActiveReference(start, editorsOnly, true); 4140 4141 if (nonObscured != null) { 4142 return nonObscured; 4143 } 4144 4145 return getActiveReference(start, editorsOnly, false); 4147 } 4148 4149 4153 private IWorkbenchPartReference getActiveReference(int start, boolean editorsOnly, boolean skipPartsObscuredByZoom) { 4154 IWorkbenchPartReference[] views = getViewReferences(); 4155 for (int i = start; i >= 0; i--) { 4156 WorkbenchPartReference ref = (WorkbenchPartReference) parts 4157 .get(i); 4158 4159 if (editorsOnly && !(ref instanceof IEditorReference)) { 4160 continue; 4161 } 4162 4163 PartPane pane = ref.getPane(); 4165 4166 if (pane != null) { 4167 if (!pane.allowsAutoFocus()) { 4168 continue; 4169 } 4170 4171 if (skipPartsObscuredByZoom) { 4172 if (pane.isObscuredByZoom()) { 4173 continue; 4174 } 4175 } 4176 } 4177 4178 if (ref instanceof IViewReference) { 4180 if (includeActiveFastViews || !((IViewReference) ref).isFastView()) { 4181 for (int j = 0; j < views.length; j++) { 4182 if (views[j] == ref) { 4183 return ref; 4184 } 4185 } 4186 } 4187 } else { 4188 return ref; 4189 } 4190 } 4191 return null; 4192 } 4193 4194 4198 int indexOf(IWorkbenchPart part) { 4199 IWorkbenchPartReference ref = getReference(part); 4200 if (ref == null) { 4201 return -1; 4202 } 4203 return parts.indexOf(ref); 4204 } 4205 4206 4210 int indexOf(IWorkbenchPartReference ref) { 4211 return parts.indexOf(ref); 4212 } 4213 4214 4217 boolean remove(IWorkbenchPartReference ref) { 4218 return parts.remove(ref); 4219 } 4220 4221 4224 private IEditorReference[] getEditors() { 4225 ArrayList editors = new ArrayList (parts.size()); 4226 for (Iterator i = parts.iterator(); i.hasNext();) { 4227 IWorkbenchPartReference part = (IWorkbenchPartReference) i 4228 .next(); 4229 if (part instanceof IEditorReference) { 4230 editors.add(part); 4231 } 4232 } 4233 return (IEditorReference[]) editors 4234 .toArray(new IEditorReference[editors.size()]); 4235 } 4236 4237 4240 private IWorkbenchPartReference[] getParts() { 4241 IWorkbenchPartReference[] views = getViewReferences(); 4242 ArrayList resultList = new ArrayList (parts.size()); 4243 for (Iterator iterator = parts.iterator(); iterator.hasNext();) { 4244 IWorkbenchPartReference ref = (IWorkbenchPartReference) iterator 4245 .next(); 4246 if (ref instanceof IViewReference) { 4247 for (int i = 0; i < views.length; i++) { 4249 if (views[i] == ref) { 4250 resultList.add(ref); 4251 break; 4252 } 4253 } 4254 } else { 4255 resultList.add(ref); 4256 } 4257 } 4258 IWorkbenchPartReference[] result = new IWorkbenchPartReference[resultList 4259 .size()]; 4260 return (IWorkbenchPartReference[]) resultList.toArray(result); 4261 } 4262 4263 4266 IEditorPart getTopEditor() { 4267 IEditorReference editor = (IEditorReference)getActiveReference(parts.size() - 1, true); 4268 4269 if (editor == null) { 4270 return null; 4271 } 4272 4273 return editor.getEditor(true); 4274 } 4275 } 4276 4277 4281 private class PerspectiveList { 4282 4285 private List openedList; 4286 4287 4292 private List usedList; 4293 4294 4297 private Perspective active; 4298 4299 4302 public PerspectiveList() { 4303 openedList = new ArrayList (); 4304 usedList = new ArrayList (); 4305 } 4306 4307 4313 public void reorder(IPerspectiveDescriptor perspective, int newLoc) { 4314 int oldLocation = 0; 4315 Perspective movedPerspective = null; 4316 for (Iterator iterator = openedList.iterator(); iterator.hasNext();) { 4317 Perspective openPerspective = (Perspective) iterator.next(); 4318 if (openPerspective.getDesc().equals(perspective)) { 4319 oldLocation = openedList.indexOf(openPerspective); 4320 movedPerspective = openPerspective; 4321 } 4322 } 4323 4324 if (oldLocation == newLoc) { 4325 return; 4326 } 4327 4328 openedList.remove(oldLocation); 4329 openedList.add(newLoc, movedPerspective); 4330 4331 } 4332 4333 4339 public Perspective[] getSortedPerspectives() { 4340 Perspective[] result = new Perspective[usedList.size()]; 4341 return (Perspective[]) usedList.toArray(result); 4342 } 4343 4344 4350 public boolean add(Perspective perspective) { 4351 openedList.add(perspective); 4352 usedList.add(0, perspective); 4353 return true; 4355 } 4356 4357 4361 public Iterator iterator() { 4362 return openedList.iterator(); 4363 } 4364 4365 4368 public Perspective[] getOpenedPerspectives() { 4369 Perspective[] result = new Perspective[openedList.size()]; 4370 return (Perspective[]) openedList.toArray(result); 4371 } 4372 4373 4376 public boolean remove(Perspective perspective) { 4377 if (active == perspective) { 4378 updateActionSets(active, null); 4379 active = null; 4380 } 4381 usedList.remove(perspective); 4382 return openedList.remove(perspective); 4383 } 4384 4385 4388 public void swap(Perspective oldPerspective, Perspective newPerspective) { 4389 int oldIndex = openedList.indexOf(oldPerspective); 4390 int newIndex = openedList.indexOf(newPerspective); 4391 4392 if (oldIndex < 0 || newIndex < 0) { 4393 return; 4394 } 4395 4396 openedList.set(oldIndex, newPerspective); 4397 openedList.set(newIndex, oldPerspective); 4398 } 4399 4400 4403 public boolean isEmpty() { 4404 return openedList.isEmpty(); 4405 } 4406 4407 4410 public Perspective getActive() { 4411 return active; 4412 } 4413 4414 4417 public Perspective getNextActive() { 4418 if (active == null) { 4419 if (usedList.isEmpty()) { 4420 return null; 4421 } else { 4422 return (Perspective) usedList.get(usedList.size() - 1); 4423 } 4424 } else { 4425 if (usedList.size() < 2) { 4426 return null; 4427 } else { 4428 return (Perspective) usedList.get(usedList.size() - 2); 4429 } 4430 } 4431 } 4432 4433 4436 public int size() { 4437 return openedList.size(); 4438 } 4439 4440 4444 public void setActive(Perspective perspective) { 4445 if (perspective == active) { 4446 return; 4447 } 4448 4449 updateActionSets(active, perspective); 4450 active = perspective; 4451 4452 if (perspective != null) { 4453 usedList.remove(perspective); 4454 usedList.add(perspective); 4455 } 4456 } 4457 4458 private void updateActionSets(Perspective oldPersp, Perspective newPersp) { 4459 4461 IContextService service = (IContextService) window 4462 .getService(IContextService.class); 4463 try { 4464 service.activateContext(ContextAuthority.DEFER_EVENTS); 4465 if (newPersp != null) { 4466 IActionSetDescriptor[] newAlwaysOn = newPersp 4467 .getAlwaysOnActionSets(); 4468 for (int i = 0; i < newAlwaysOn.length; i++) { 4469 IActionSetDescriptor descriptor = newAlwaysOn[i]; 4470 4471 actionSets.showAction(descriptor); 4472 } 4473 4474 IActionSetDescriptor[] newAlwaysOff = newPersp 4475 .getAlwaysOffActionSets(); 4476 for (int i = 0; i < newAlwaysOff.length; i++) { 4477 IActionSetDescriptor descriptor = newAlwaysOff[i]; 4478 4479 actionSets.maskAction(descriptor); 4480 } 4481 } 4482 4483 if (oldPersp != null) { 4484 IActionSetDescriptor[] newAlwaysOn = oldPersp 4485 .getAlwaysOnActionSets(); 4486 for (int i = 0; i < newAlwaysOn.length; i++) { 4487 IActionSetDescriptor descriptor = newAlwaysOn[i]; 4488 4489 actionSets.hideAction(descriptor); 4490 } 4491 4492 IActionSetDescriptor[] newAlwaysOff = oldPersp 4493 .getAlwaysOffActionSets(); 4494 for (int i = 0; i < newAlwaysOff.length; i++) { 4495 IActionSetDescriptor descriptor = newAlwaysOff[i]; 4496 4497 actionSets.unmaskAction(descriptor); 4498 } 4499 } 4500 } finally { 4501 service.activateContext(ContextAuthority.SEND_EVENTS); 4502 } 4503 } 4504 } 4505 4506 protected void addPerspective(Perspective persp) { 4508 perspList.add(persp); 4509 window.firePerspectiveOpened(this, persp.getDesc()); 4510 } 4511 4512 4520 private IViewReference[] getViewReferenceStack(IViewPart part) { 4521 Perspective persp = getActivePerspective(); 4523 if (persp == null || !certifyPart(part)) { 4524 return null; 4525 } 4526 4527 ILayoutContainer container = ((PartSite) part.getSite()).getPane() 4528 .getContainer(); 4529 if (container instanceof ViewStack) { 4530 ViewStack folder = (ViewStack) container; 4531 final ArrayList list = new ArrayList (folder.getChildren().length); 4532 for (int i = 0; i < folder.getChildren().length; i++) { 4533 LayoutPart layoutPart = folder.getChildren()[i]; 4534 if (layoutPart instanceof ViewPane) { 4535 IViewReference view = ((ViewPane) layoutPart) 4536 .getViewReference(); 4537 if (view != null) { 4538 list.add(view); 4539 } 4540 } 4541 } 4542 4543 Collections.sort(list, new Comparator () { 4545 public int compare(Object o1, Object o2) { 4546 int pos1 = (-1) 4547 * activationList 4548 .indexOf((IWorkbenchPartReference) o1); 4549 int pos2 = (-1) 4550 * activationList 4551 .indexOf((IWorkbenchPartReference) o2); 4552 return pos1 - pos2; 4553 } 4554 }); 4555 4556 return (IViewReference[]) list.toArray(new IViewReference[list 4557 .size()]); 4558 } 4559 4560 return new IViewReference[] { (IViewReference) getReference(part) }; 4561 } 4562 4563 4568 public IViewPart[] getViewStack(IViewPart part) { 4569 IViewReference[] refStack = getViewReferenceStack(part); 4570 if (refStack == null) { 4571 return null; 4572 } 4573 4574 List result = new ArrayList (); 4575 4576 for (int i = 0; i < refStack.length; i++) { 4577 IViewPart next = refStack[i].getView(false); 4578 if (next != null) { 4579 result.add(next); 4580 } 4581 } 4582 4583 return (IViewPart[]) result.toArray(new IViewPart[result.size()]); 4584 } 4585 4586 4598 public void resizeView(IViewPart part, int width, int height) { 4599 SashInfo sashInfo = new SashInfo(); 4600 PartPane pane = ((PartSite) part.getSite()).getPane(); 4601 ILayoutContainer container = pane.getContainer(); 4602 LayoutTree tree = getPerspectivePresentation().getLayout().root 4603 .find(((ViewStack) container)); 4604 4605 findSashParts(tree, pane.findSashes(), sashInfo); 4607 4608 float deltaWidth = width - pane.getBounds().width; 4610 if (sashInfo.right != null) { 4611 Rectangle rightBounds = sashInfo.rightNode.getBounds(); 4612 sashInfo.right.setRatio(((deltaWidth + sashInfo.right 4614 .getBounds().x) - rightBounds.x) 4615 / rightBounds.width); 4616 sashInfo.rightNode.setBounds(rightBounds); 4618 } else if (sashInfo.left != null) { 4619 Rectangle leftBounds = sashInfo.leftNode.getBounds(); 4620 sashInfo.left 4622 .setRatio(((sashInfo.left.getBounds().x - deltaWidth) - leftBounds.x) 4623 / leftBounds.width); 4624 sashInfo.leftNode.setBounds(sashInfo.leftNode.getBounds()); 4626 } 4627 4628 float deltaHeight = height - pane.getBounds().height; 4630 if (sashInfo.bottom != null) { 4631 Rectangle bottomBounds = sashInfo.bottomNode.getBounds(); 4632 sashInfo.bottom.setRatio(((deltaHeight + sashInfo.bottom 4634 .getBounds().y) - bottomBounds.y) 4635 / bottomBounds.height); 4636 sashInfo.bottomNode.setBounds(bottomBounds); 4638 } else if (sashInfo.top != null) { 4639 Rectangle topBounds = sashInfo.topNode.getBounds(); 4640 sashInfo.top 4642 .setRatio(((sashInfo.top.getBounds().y - deltaHeight) - topBounds.y) 4643 / topBounds.height); 4644 sashInfo.topNode.setBounds(topBounds); 4646 } 4647 4648 } 4649 4650 private class SashInfo { 4652 private LayoutPartSash right; 4653 4654 private LayoutPartSash left; 4655 4656 private LayoutPartSash top; 4657 4658 private LayoutPartSash bottom; 4659 4660 private LayoutTreeNode rightNode; 4661 4662 private LayoutTreeNode leftNode; 4663 4664 private LayoutTreeNode topNode; 4665 4666 private LayoutTreeNode bottomNode; 4667 } 4668 4669 private void findSashParts(LayoutTree tree, PartPane.Sashes sashes, 4670 SashInfo info) { 4671 LayoutTree parent = tree.getParent(); 4672 if (parent == null) { 4673 return; 4674 } 4675 4676 if (parent.part instanceof LayoutPartSash) { 4677 LayoutPartSash sash = (LayoutPartSash) parent.part; 4679 Control control = sash.getControl(); 4681 if (control != null) { 4682 if (sash.isVertical()) { 4684 if (sashes.left == control) { 4685 info.left = sash; 4686 info.leftNode = parent.findSash(sash); 4687 } else if (sashes.right == control) { 4688 info.right = sash; 4689 info.rightNode = parent.findSash(sash); 4690 } 4691 } 4692 else { 4694 if (sashes.top == control) { 4695 info.top = sash; 4696 info.topNode = parent.findSash(sash); 4697 } else if (sashes.bottom == control) { 4698 info.bottom = sash; 4699 info.bottomNode = parent.findSash(sash); 4700 } 4701 } 4702 } 4703 } 4704 findSashParts(parent, sashes, info); 4706 } 4707 4708 4713 IWorkbenchPartReference[] getAllParts() { 4714 IViewReference[] views = viewFactory.getViews(); 4715 IEditorReference[] editors = getEditorReferences(); 4716 4717 IWorkbenchPartReference[] result = new IWorkbenchPartReference[views.length + editors.length]; 4718 int resultIdx = 0; 4719 4720 for (int i = 0; i < views.length; i++) { 4721 result[resultIdx++] = views[i]; 4722 } 4723 4724 for (int i = 0; i < editors.length; i++) { 4725 result[resultIdx++] = editors[i]; 4726 } 4727 4728 return result; 4729 } 4730 4731 4736 IWorkbenchPartReference[] getOpenParts() { 4737 IWorkbenchPartReference[] refs = getAllParts(); 4738 List result = new ArrayList (); 4739 4740 for (int i = 0; i < refs.length; i++) { 4741 IWorkbenchPartReference reference = refs[i]; 4742 4743 IWorkbenchPart part = reference.getPart(false); 4744 if (part != null) { 4745 result.add(reference); 4746 } 4747 } 4748 4749 return (IWorkbenchPartReference[]) result.toArray(new IWorkbenchPartReference[result.size()]); 4750 } 4751 4752 4757 public void testInvariants() { 4758 Perspective persp = getActivePerspective(); 4759 4760 if (persp != null) { 4761 4762 persp.testInvariants(); 4763 4764 if (!SwtUtil.isDisposed(getClientComposite()) && editorPresentation.getLayoutPart().isVisible()) { 4767 Assert.isTrue(persp.isEditorAreaVisible()); 4768 } 4769 } 4770 4771 } 4772 4773 4776 public IExtensionTracker getExtensionTracker() { 4777 if (tracker == null) { 4778 tracker = new UIExtensionTracker(getWorkbenchWindow().getWorkbench().getDisplay()); 4779 } 4780 return tracker; 4781 } 4782 4783 4788 public String [] getNewWizardShortcuts() { 4789 Perspective persp = getActivePerspective(); 4790 if (persp == null) { 4791 return new String [0]; 4792 } 4793 return persp.getNewWizardShortcuts(); 4794 } 4795 4796 4801 public String [] getPerspectiveShortcuts() { 4802 Perspective persp = getActivePerspective(); 4803 if (persp == null) { 4804 return new String [0]; 4805 } 4806 return persp.getPerspectiveShortcuts(); 4807 } 4808 4809 4814 public String [] getShowViewShortcuts() { 4815 Perspective persp = getActivePerspective(); 4816 if (persp == null) { 4817 return new String [0]; 4818 } 4819 return persp.getShowViewShortcuts(); 4820 } 4821 4822 4825 private void suggestReset() { 4826 final IWorkbench workbench = getWorkbenchWindow().getWorkbench(); 4827 workbench.getDisplay().asyncExec(new Runnable () { 4828 public void run() { 4829 Shell parentShell = null; 4830 4831 IWorkbenchWindow window = workbench.getActiveWorkbenchWindow(); 4832 if (window == null) { 4833 if (workbench.getWorkbenchWindowCount() == 0) { 4834 return; 4835 } 4836 window = workbench.getWorkbenchWindows()[0]; 4837 } 4838 4839 parentShell = window.getShell(); 4840 4841 if (MessageDialog 4842 .openQuestion( 4843 parentShell, 4844 WorkbenchMessages.Dynamic_resetPerspectiveTitle, 4845 WorkbenchMessages.Dynamic_resetPerspectiveMessage)) { 4846 IWorkbenchPage page = window.getActivePage(); 4847 if (page == null) { 4848 return; 4849 } 4850 page.resetPerspective(); 4851 } 4852 } 4853 }); 4854 4855 4856 } 4857 4858 public boolean isPartVisible(IWorkbenchPartReference reference) { 4859 IWorkbenchPart part = reference.getPart(false); 4860 if (part == null) { 4862 return false; 4863 } 4864 4865 return isPartVisible(part); 4866 } 4867 4868 public IWorkingSet[] getWorkingSets() { 4869 return workingSets; 4870 } 4871 4872 public void setWorkingSets(IWorkingSet[] newWorkingSets) { 4873 if (newWorkingSets == null) { 4874 newWorkingSets = new IWorkingSet[0]; 4875 } 4876 4877 IWorkingSet[] oldWorkingSets = workingSets; 4878 4879 if (newWorkingSets.length > 1) { 4881 Set setOfSets = new HashSet (); 4882 for (int i = 0; i < newWorkingSets.length; i++) { 4883 if (newWorkingSets[i] == null) { 4884 throw new IllegalArgumentException (); 4885 } 4886 setOfSets.add(newWorkingSets[i]); 4887 } 4888 newWorkingSets = (IWorkingSet[]) setOfSets 4889 .toArray(new IWorkingSet[setOfSets.size()]); 4890 } 4891 4892 workingSets = newWorkingSets; 4893 if (!Arrays.equals(oldWorkingSets, newWorkingSets)) { 4894 firePropertyChange(CHANGE_WORKING_SETS_REPLACE, oldWorkingSets, 4895 newWorkingSets); 4896 if (aggregateWorkingSet != null) { 4897 aggregateWorkingSet.setComponents(workingSets); 4898 } 4899 } 4900 if (newWorkingSets != null) { 4901 WorkbenchPlugin 4902 .getDefault() 4903 .getWorkingSetManager() 4904 .addPropertyChangeListener(workingSetPropertyChangeListener); 4905 } else { 4906 WorkbenchPlugin.getDefault().getWorkingSetManager() 4907 .removePropertyChangeListener( 4908 workingSetPropertyChangeListener); 4909 } 4910 } 4911 4912 public IWorkingSet getAggregateWorkingSet() { 4913 if (aggregateWorkingSet == null) { 4914 IWorkingSetManager workingSetManager = PlatformUI.getWorkbench() 4915 .getWorkingSetManager(); 4916 aggregateWorkingSet = (AggregateWorkingSet) workingSetManager.getWorkingSet( 4917 getAggregateWorkingSetId()); 4918 if (aggregateWorkingSet == null) { 4919 aggregateWorkingSet = (AggregateWorkingSet) workingSetManager 4920 .createAggregateWorkingSet( 4921 getAggregateWorkingSetId(), 4922 WorkbenchMessages.WorkbenchPage_workingSet_default_label, 4923 getWorkingSets()); 4924 workingSetManager.addWorkingSet(aggregateWorkingSet); 4925 } 4926 } 4927 return aggregateWorkingSet; 4928 } 4929 4930 private String getAggregateWorkingSetId() { 4931 if (aggregateWorkingSetId == null) { 4932 aggregateWorkingSetId = "Aggregate for window " + System.currentTimeMillis(); } 4934 return aggregateWorkingSetId; 4935 } 4936} 4937 | Popular Tags |