1 /******************************************************************************* 2 * Copyright (c) 2000, 2018 IBM Corporation and others. 3 * 4 * This program and the accompanying materials 5 * are made available under the terms of the Eclipse Public License 2.0 6 * which accompanies this distribution, and is available at 7 * https://www.eclipse.org/legal/epl-2.0/ 8 * 9 * SPDX-License-Identifier: EPL-2.0 10 * 11 * Contributors: 12 * IBM Corporation - initial API and implementation 13 *******************************************************************************/ 14 package org.eclipse.ui; 15 16 import org.eclipse.core.runtime.IAdaptable; 17 import org.eclipse.core.runtime.dynamichelpers.IExtensionTracker; 18 import org.eclipse.jface.util.IPropertyChangeListener; 19 20 /** 21 * A workbench page consists of an arrangement of views and editors intended to 22 * be presented together to the user in a single workbench window. 23 * <p> 24 * A page can contain 0 or more views and 0 or more editors. These views and 25 * editors are contained wholly within the page and are not shared with other 26 * pages. The layout and visible action set for the page is defined by a 27 * perspective. 28 * <p> 29 * The number of views and editors within a page is restricted to simplify part 30 * management for the user. In particular: 31 * </p> 32 * <ul> 33 * <li>Unless a view explicitly allows for multiple instances in its plug-in 34 * declaration there will be only one instance in a given workbench page.</li> 35 * <li>Only one editor can exist for each editor input within a page.</li> 36 * </ul> 37 * <p> 38 * This interface is not intended to be implemented by clients. 39 * </p> 40 * 41 * @see IPerspectiveDescriptor 42 * @see IEditorPart 43 * @see IViewPart 44 * @noimplement This interface is not intended to be implemented by clients. 45 */ 46 public interface IWorkbenchPage extends IPartService, ISelectionService { 47 /** 48 * An optional attribute within a workspace marker (<code>IMarker</code>) which 49 * identifies the preferred editor type to be opened when 50 * <code>openEditor</code> is called. 51 * 52 * @see #openEditor(IEditorInput, String) 53 * @see #openEditor(IEditorInput, String, boolean) 54 * @deprecated in 3.0 since the notion of markers this is not generally 55 * applicable. Use the IDE-specific constant 56 * <code>IDE.EDITOR_ID_ATTR</code>. 57 */ 58 @Deprecated 59 String EDITOR_ID_ATTR = "org.eclipse.ui.editorID"; //$NON-NLS-1$ 60 61 /** 62 * Change event id when the perspective is reset to its original state. 63 * 64 * @see IPerspectiveListener 65 */ 66 String CHANGE_RESET = "reset"; //$NON-NLS-1$ 67 68 /** 69 * Change event id when the perspective has completed a reset to its original 70 * state. 71 * 72 * @since 3.0 73 * @see IPerspectiveListener 74 */ 75 String CHANGE_RESET_COMPLETE = "resetComplete"; //$NON-NLS-1$ 76 77 /** 78 * Change event id when one or more views are shown in a perspective. 79 * 80 * @see IPerspectiveListener 81 */ 82 String CHANGE_VIEW_SHOW = "viewShow"; //$NON-NLS-1$ 83 84 /** 85 * Change event id when one or more views are hidden in a perspective. 86 * 87 * @see IPerspectiveListener 88 */ 89 String CHANGE_VIEW_HIDE = "viewHide"; //$NON-NLS-1$ 90 91 /** 92 * Change event id when one or more editors are opened in a perspective. 93 * 94 * @see IPerspectiveListener 95 */ 96 String CHANGE_EDITOR_OPEN = "editorOpen"; //$NON-NLS-1$ 97 98 /** 99 * Change event id when one or more editors are closed in a perspective. 100 * 101 * @see IPerspectiveListener 102 */ 103 String CHANGE_EDITOR_CLOSE = "editorClose"; //$NON-NLS-1$ 104 105 /** 106 * Change event id when the editor area is shown in a perspective. 107 * 108 * @see IPerspectiveListener 109 */ 110 String CHANGE_EDITOR_AREA_SHOW = "editorAreaShow"; //$NON-NLS-1$ 111 112 /** 113 * Change event id when the editor area is hidden in a perspective. 114 * 115 * @see IPerspectiveListener 116 */ 117 String CHANGE_EDITOR_AREA_HIDE = "editorAreaHide"; //$NON-NLS-1$ 118 119 /** 120 * Change event id when an action set is shown in a perspective. 121 * 122 * @see IPerspectiveListener 123 */ 124 String CHANGE_ACTION_SET_SHOW = "actionSetShow"; //$NON-NLS-1$ 125 126 /** 127 * Change event id when an action set is hidden in a perspective. 128 * 129 * @see IPerspectiveListener 130 */ 131 String CHANGE_ACTION_SET_HIDE = "actionSetHide"; //$NON-NLS-1$ 132 133 /** 134 * Change event id when a fast view is added in a perspective. 135 * 136 * @see IPerspectiveListener 137 */ 138 String CHANGE_FAST_VIEW_ADD = "fastViewAdd"; //$NON-NLS-1$ 139 140 /** 141 * Change event id when a fast view is removed in a perspective. 142 * 143 * @see IPerspectiveListener 144 */ 145 String CHANGE_FAST_VIEW_REMOVE = "fastViewRemove"; //$NON-NLS-1$ 146 147 /** 148 * Change event id when the page working set was replaced 149 * 150 * @see IPropertyChangeListener 151 */ 152 String CHANGE_WORKING_SET_REPLACE = "workingSetReplace"; //$NON-NLS-1$ 153 154 /** 155 * Change event id when the page working set list was replaced 156 * 157 * @see IPropertyChangeListener 158 * @since 3.2 159 */ 160 String CHANGE_WORKING_SETS_REPLACE = "workingSetsReplace"; //$NON-NLS-1$ 161 162 /** 163 * Show view mode that indicates the view should be made visible and activated. 164 * Use of this mode has the same effect as calling {@link #showView(String)}. 165 * 166 * @since 3.0 167 */ 168 int VIEW_ACTIVATE = 1; 169 170 /** 171 * Show view mode that indicates the view should be made visible. If the view is 172 * opened in the container that contains the active view then this has the same 173 * effect as <code>VIEW_CREATE</code>. 174 * 175 * @since 3.0 176 */ 177 int VIEW_VISIBLE = 2; 178 179 /** 180 * Show view mode that indicates the view should be made created but not 181 * necessarily be made visible. It will only be made visible in the event that 182 * it is opened in its own container. In other words, only if it is not stacked 183 * with another view. 184 * 185 * @since 3.0 186 */ 187 int VIEW_CREATE = 3; 188 189 /** 190 * Editor opening match mode specifying that no matching against existing 191 * editors should be done. 192 * 193 * @since 3.2 194 */ 195 int MATCH_NONE = 0; 196 197 /** 198 * Editor opening match mode specifying that the editor input should be 199 * considered when matching against existing editors. 200 * 201 * @since 3.2 202 */ 203 int MATCH_INPUT = 1; 204 205 /** 206 * Editor opening match mode specifying that the editor id should be considered 207 * when matching against existing editors. 208 * 209 * @since 3.2 210 */ 211 int MATCH_ID = 2; 212 213 /** 214 * State of a view in a given page when the view stack is minimized. 215 * 216 * @since 3.2 217 */ 218 int STATE_MINIMIZED = 0; 219 220 /** 221 * State of a view in a given page when the page is zoomed in on the view stack. 222 * 223 * @since 3.2 224 */ 225 int STATE_MAXIMIZED = 1; 226 227 /** 228 * State of a view in a given page when the view stack is in it's normal state. 229 * 230 * @since 3.2 231 */ 232 int STATE_RESTORED = 2; 233 234 /** 235 * Activates the given part. The part will be brought to the front and given 236 * focus. The part must belong to this page. 237 * 238 * @param part the part to activate 239 */ activate(IWorkbenchPart part)240 void activate(IWorkbenchPart part); 241 242 /** 243 * Adds a property change listener. 244 * 245 * @param listener the property change listener to add 246 * @since 2.0 247 * @deprecated client should register listeners on the instance of 248 * {@link org.eclipse.ui.IWorkingSetManager} returned by 249 * {@link org.eclipse.ui.IWorkbench#getWorkingSetManager()} instead. 250 */ 251 @Deprecated addPropertyChangeListener(IPropertyChangeListener listener)252 void addPropertyChangeListener(IPropertyChangeListener listener); 253 254 /** 255 * Moves the given part forward in the Z order of this page so as to make it 256 * visible, without changing which part has focus. The part must belong to this 257 * page. 258 * 259 * @param part the part to bring forward 260 */ bringToTop(IWorkbenchPart part)261 void bringToTop(IWorkbenchPart part); 262 263 /** 264 * Closes this workbench page. If this page is the active one, this honor is 265 * passed along to one of the window's other pages if possible. 266 * <p> 267 * If the page has an open editor with unsaved content, the user will be given 268 * the opportunity to save it. 269 * </p> 270 * 271 * @return <code>true</code> if the page was successfully closed, and 272 * <code>false</code> if it is still open 273 */ close()274 boolean close(); 275 276 /** 277 * Closes all of the editors belonging to this workbench page. 278 * <p> 279 * If the page has open editors with unsaved content and <code>save</code> is 280 * <code>true</code>, the user will be given the opportunity to save them. 281 * </p> 282 * 283 * @param save <code>true</code> to save the editor contents if required 284 * (recommended), and <code>false</code> to discard any unsaved 285 * changes 286 * 287 * @return <code>true</code> if all editors were successfully closed, and 288 * <code>false</code> if at least one is still open 289 */ closeAllEditors(boolean save)290 boolean closeAllEditors(boolean save); 291 292 /** 293 * Closes the given <code>Array</code> of editor references. The editors must 294 * belong to this workbench page. 295 * <p> 296 * If any of the editors have unsaved content and <code>save</code> is 297 * <code>true</code>, the user will be given the opportunity to save them. 298 * </p> 299 * 300 * @param editorRefs the editors to close 301 * @param save <code>true</code> to save the editor contents if required 302 * (recommended), and <code>false</code> to discard any 303 * unsaved changes 304 * @return <code>true</code> if the editors were successfully closed, and 305 * <code>false</code> if the editors are still open 306 * @since 3.0 307 */ closeEditors(IEditorReference[] editorRefs, boolean save)308 boolean closeEditors(IEditorReference[] editorRefs, boolean save); 309 310 /** 311 * Closes the given editor. The editor must belong to this workbench page. 312 * <p> 313 * If the editor has unsaved content and <code>save</code> is <code>true</code>, 314 * the user will be given the opportunity to save it. 315 * </p> 316 * 317 * @param editor the editor to close 318 * @param save <code>true</code> to save the editor contents if required 319 * (recommended), and <code>false</code> to discard any unsaved 320 * changes 321 * @return <code>true</code> if the editor was successfully closed, and 322 * <code>false</code> if the editor is still open 323 */ closeEditor(IEditorPart editor, boolean save)324 boolean closeEditor(IEditorPart editor, boolean save); 325 326 /** 327 * Returns the view in this page with the specified id. There is at most one 328 * view in the page with the specified id. 329 * 330 * @param viewId the id of the view extension to use 331 * @return the view, or <code>null</code> if none is found 332 */ findView(String viewId)333 IViewPart findView(String viewId); 334 335 /** 336 * Returns the view reference with the specified id. 337 * 338 * @param viewId the id of the view extension to use 339 * @return the view reference, or <code>null</code> if none is found 340 * @since 3.0 341 */ findViewReference(String viewId)342 IViewReference findViewReference(String viewId); 343 344 /** 345 * Returns the view reference with the specified id and secondary id. 346 * 347 * @param viewId the id of the view extension to use 348 * @param secondaryId the secondary id to use, or <code>null</code> for no 349 * secondary id 350 * @return the view reference, or <code>null</code> if none is found 351 * @since 3.0 352 */ findViewReference(String viewId, String secondaryId)353 IViewReference findViewReference(String viewId, String secondaryId); 354 355 /** 356 * Returns the active editor open in this page. 357 * <p> 358 * This is the visible editor on the page, or, if there is more than one visible 359 * editor, this is the one most recently brought to top. 360 * </p> 361 * 362 * @return the active editor, or <code>null</code> if no editor is active 363 */ getActiveEditor()364 IEditorPart getActiveEditor(); 365 366 /** 367 * Returns the editor with the specified input. Returns null if there is no 368 * opened editor with that input. 369 * 370 * @param input the editor input 371 * @return an editor with input equals to <code>input</code> 372 */ findEditor(IEditorInput input)373 IEditorPart findEditor(IEditorInput input); 374 375 /** 376 * Returns an array of editor references that match the given input and/or 377 * editor id, as specified by the given match flags. Returns an empty array if 378 * there are no matching editors, or if matchFlags is MATCH_NONE. 379 * 380 * @param input the editor input, or <code>null</code> if MATCH_INPUT is 381 * not specified in matchFlags 382 * @param editorId the editor id, or <code>null</code> if MATCH_ID is not 383 * specified in matchFlags 384 * @param matchFlags a bit mask consisting of zero or more of the MATCH_* 385 * constants OR-ed together 386 * @return the references for the matching editors 387 * 388 * @see #MATCH_NONE 389 * @see #MATCH_INPUT 390 * @see #MATCH_ID 391 * @since 3.2 392 */ findEditors(IEditorInput input, String editorId, int matchFlags)393 IEditorReference[] findEditors(IEditorInput input, String editorId, int matchFlags); 394 395 /** 396 * Returns a list of the editors open in this page. 397 * <p> 398 * Note that each page has its own editors; editors are never shared between 399 * pages. 400 * </p> 401 * 402 * @return a list of open editors 403 * 404 * @deprecated Clients are encouraged to use {@link #getEditorReferences()} 405 * instead. Calling this method has the side effect of restoring all 406 * the editors in the page which can cause plug-in activation. 407 */ 408 @Deprecated getEditors()409 IEditorPart[] getEditors(); 410 411 /** 412 * Returns an array of references to open editors in this page. 413 * <p> 414 * Note that each page has its own editors; editors are never shared between 415 * pages. 416 * </p> 417 * 418 * @return a list of open editors 419 */ getEditorReferences()420 IEditorReference[] getEditorReferences(); 421 422 /** 423 * Returns a list of dirty editors in this page. 424 * 425 * @return a list of dirty editors 426 */ getDirtyEditors()427 IEditorPart[] getDirtyEditors(); 428 429 /** 430 * Returns the input for this page. 431 * 432 * @return the input for this page, or <code>null</code> if none 433 */ getInput()434 IAdaptable getInput(); 435 436 /** 437 * Returns the page label. This will be a unique identifier within the 438 * containing workbench window. 439 * 440 * @return the page label 441 */ getLabel()442 String getLabel(); 443 444 /** 445 * Returns the current perspective descriptor for this page, or 446 * <code>null</code> if there is no current perspective. 447 * 448 * @return the current perspective descriptor or <code>null</code> 449 * @see #setPerspective 450 * @see #savePerspective 451 */ getPerspective()452 IPerspectiveDescriptor getPerspective(); 453 454 /** 455 * Returns a list of the reference to views visible on this page. 456 * <p> 457 * Note that each page has its own views; views are never shared between pages. 458 * </p> 459 * 460 * @return a list of references to visible views 461 */ getViewReferences()462 IViewReference[] getViewReferences(); 463 464 /** 465 * Returns a list of the views visible on this page. 466 * <p> 467 * Note that each page has its own views; views are never shared between pages. 468 * </p> 469 * 470 * @return a list of visible views 471 * 472 * @deprecated Clients are encouraged to use {@link #getViewReferences()} 473 * instead. Calling this method has the side effect of restoring all 474 * the views in the page which can cause plug-in activation. 475 */ 476 @Deprecated getViews()477 IViewPart[] getViews(); 478 479 /** 480 * Returns the workbench window of this page. 481 * 482 * @return the workbench window 483 */ getWorkbenchWindow()484 IWorkbenchWindow getWorkbenchWindow(); 485 486 /** 487 * Returns the working set of this page. 488 * 489 * @return the working set of this page. 490 * @since 2.0 491 * @deprecated individual views should store a working set if needed 492 */ 493 @Deprecated getWorkingSet()494 IWorkingSet getWorkingSet(); 495 496 /** 497 * Hides an action set in this page. 498 * <p> 499 * In most cases where this method is used the caller is tightly coupled to a 500 * particular action set. They define it in the registry and may make it visible 501 * in certain scenarios by calling <code>showActionSet</code>. A static variable 502 * is often used to identify the action set id in caller code. 503 * </p> 504 * 505 * @param actionSetID the action set to hide 506 */ hideActionSet(String actionSetID)507 void hideActionSet(String actionSetID); 508 509 /** 510 * Hides the given view. The view must belong to this page. 511 * 512 * @param view the view to hide 513 */ hideView(IViewPart view)514 void hideView(IViewPart view); 515 516 /** 517 * Hides the given view that belongs to the reference, if any. 518 * 519 * @param view the references whos view is to be hidden 520 * @since 3.0 521 */ hideView(IViewReference view)522 void hideView(IViewReference view); 523 524 /** 525 * Returns whether the specified part is visible. 526 * 527 * @param part the part to test 528 * @return boolean <code>true</code> if part is visible 529 */ isPartVisible(IWorkbenchPart part)530 boolean isPartVisible(IWorkbenchPart part); 531 532 /** 533 * Returns whether the page's current perspective is showing the editor area. 534 * 535 * @return <code>true</code> when editor area visible, <code>false</code> 536 * otherwise 537 */ isEditorAreaVisible()538 boolean isEditorAreaVisible(); 539 540 /** 541 * Reuses the specified editor by setting its new input. 542 * 543 * @param editor the editor to be reused 544 * @param input the new input for the reusable editor 545 */ reuseEditor(IReusableEditor editor, IEditorInput input)546 void reuseEditor(IReusableEditor editor, IEditorInput input); 547 548 /** 549 * Opens an editor on the given input. 550 * <p> 551 * If this page already has an editor open on the target input that editor is 552 * activated; otherwise, a new editor is opened. Two editor inputs, input1 and 553 * input2, are considered the same if 554 * </p> 555 * 556 * <pre> 557 * input1.equals(input2) == true 558 * </pre> 559 * <p> 560 * The editor type is determined by mapping <code>editorId</code> to an editor 561 * extension registered with the workbench. An editor id is passed rather than 562 * an editor object to prevent the accidental creation of more than one editor 563 * for the same input. It also guarantees a consistent lifecycle for editors, 564 * regardless of whether they are created by the user or restored from saved 565 * data. 566 * </p> 567 * 568 * @param input the editor input 569 * @param editorId the id of the editor extension to use 570 * @return an open and active editor, or <code>null</code> if an external editor 571 * was opened 572 * @exception PartInitException if the editor could not be created or 573 * initialized 574 */ openEditor(IEditorInput input, String editorId)575 IEditorPart openEditor(IEditorInput input, String editorId) throws PartInitException; 576 577 /** 578 * Opens an editor on the given input. 579 * <p> 580 * If this page already has an editor open on the target input that editor is 581 * brought to the front; otherwise, a new editor is opened. Two editor inputs 582 * are considered the same if they equal. See <code>Object.equals(Object)</code> 583 * and <code>IEditorInput</code>. If <code>activate == true</code> the editor 584 * will be activated. 585 * </p> 586 * <p> 587 * The editor type is determined by mapping <code>editorId</code> to an editor 588 * extension registered with the workbench. An editor id is passed rather than 589 * an editor object to prevent the accidental creation of more than one editor 590 * for the same input. It also guarantees a consistent lifecycle for editors, 591 * regardless of whether they are created by the user or restored from saved 592 * data. 593 * </p> 594 * 595 * @param input the editor input 596 * @param editorId the id of the editor extension to use 597 * @param activate if <code>true</code> the editor will be activated 598 * @return an open editor, or <code>null</code> if an external editor was opened 599 * @exception PartInitException if the editor could not be created or 600 * initialized 601 */ openEditor(IEditorInput input, String editorId, boolean activate)602 IEditorPart openEditor(IEditorInput input, String editorId, boolean activate) throws PartInitException; 603 604 /** 605 * Opens an editor on the given input. 606 * <p> 607 * If this page already has an editor open that matches the given input and/or 608 * editor id (as specified by the matchFlags argument), that editor is brought 609 * to the front; otherwise, a new editor is opened. Two editor inputs are 610 * considered the same if they equal. See <code>Object.equals(Object)</code> and 611 * <code>IEditorInput</code>. If <code>activate == true</code> the editor will 612 * be activated. 613 * </p> 614 * <p> 615 * The editor type is determined by mapping <code>editorId</code> to an editor 616 * extension registered with the workbench. An editor id is passed rather than 617 * an editor object to prevent the accidental creation of more than one editor 618 * for the same input. It also guarantees a consistent lifecycle for editors, 619 * regardless of whether they are created by the user or restored from saved 620 * data. 621 * </p> 622 * 623 * @param input the editor input 624 * @param editorId the id of the editor extension to use 625 * @param activate if <code>true</code> the editor will be activated 626 * @param matchFlags a bit mask consisting of zero or more of the MATCH_* 627 * constants OR-ed together 628 * @return an open editor, or <code>null</code> if an external editor was opened 629 * @exception PartInitException if the editor could not be created or 630 * initialized 631 * 632 * @see #MATCH_NONE 633 * @see #MATCH_INPUT 634 * @see #MATCH_ID 635 * @since 3.2 636 */ openEditor(final IEditorInput input, final String editorId, final boolean activate, final int matchFlags)637 IEditorPart openEditor(final IEditorInput input, final String editorId, final boolean activate, 638 final int matchFlags) throws PartInitException; 639 640 /** 641 * Removes the property change listener. 642 * 643 * @param listener the property change listener to remove 644 * @since 2.0 645 */ removePropertyChangeListener(IPropertyChangeListener listener)646 void removePropertyChangeListener(IPropertyChangeListener listener); 647 648 /** 649 * Changes the visible views, their layout, and the visible action sets within 650 * the page to match the current perspective descriptor. This is a rearrangement 651 * of components and not a replacement. The contents of the current perspective 652 * descriptor are unaffected. 653 * <p> 654 * For more information on perspective change see <code>setPerspective()</code>. 655 * </p> 656 */ resetPerspective()657 void resetPerspective(); 658 659 /** 660 * Saves the contents of all dirty editors belonging to this workbench page. If 661 * there are no dirty editors this method returns without effect. 662 * <p> 663 * If <code>confirm</code> is <code>true</code> the user is prompted to confirm 664 * the command. 665 * </p> 666 * <p> 667 * Note that as of 3.2, this method also saves views that implement 668 * ISaveablePart and are dirty. 669 * </p> 670 * 671 * @param confirm <code>true</code> to ask the user before saving unsaved 672 * changes (recommended), and <code>false</code> to save unsaved 673 * changes without asking 674 * @return <code>true</code> if the command succeeded, and <code>false</code> if 675 * the operation was canceled by the user or an error occurred while 676 * saving 677 */ saveAllEditors(boolean confirm)678 boolean saveAllEditors(boolean confirm); 679 680 /** 681 * Saves the contents of the given editor if dirty. If not, this method returns 682 * without effect. 683 * <p> 684 * If <code>confirm</code> is <code>true</code> the user is prompted to confirm 685 * the command. Otherwise, the save happens without prompt. 686 * </p> 687 * <p> 688 * The editor must belong to this workbench page. 689 * </p> 690 * 691 * @param editor the editor to close 692 * @param confirm <code>true</code> to ask the user before saving unsaved 693 * changes (recommended), and <code>false</code> to save unsaved 694 * changes without asking 695 * @return <code>true</code> if the command succeeded, and <code>false</code> if 696 * the editor was not saved 697 */ saveEditor(IEditorPart editor, boolean confirm)698 boolean saveEditor(IEditorPart editor, boolean confirm); 699 700 /** 701 * Saves the visible views, their layout, and the visible action sets for this 702 * page to the current perspective descriptor. The contents of the current 703 * perspective descriptor are overwritten. 704 */ savePerspective()705 void savePerspective(); 706 707 /** 708 * Saves the visible views, their layout, and the visible action sets for this 709 * page to the given perspective descriptor. The contents of the given 710 * perspective descriptor are overwritten and it is made the current one for 711 * this page. 712 * 713 * @param perspective the perspective descriptor to save to 714 */ savePerspectiveAs(IPerspectiveDescriptor perspective)715 void savePerspectiveAs(IPerspectiveDescriptor perspective); 716 717 /** 718 * Show or hide the editor area for the page's active perspective. 719 * 720 * @param showEditorArea <code>true</code> to show the editor area, 721 * <code>false</code> to hide the editor area 722 */ setEditorAreaVisible(boolean showEditorArea)723 void setEditorAreaVisible(boolean showEditorArea); 724 725 /** 726 * Changes the visible views, their layout, and the visible action sets within 727 * the page to match the given perspective descriptor. This is a rearrangement 728 * of components and not a replacement. The contents of the old perspective 729 * descriptor are unaffected. 730 * <p> 731 * When a perspective change occurs the old perspective is deactivated (hidden) 732 * and cached for future reference. Then the new perspective is activated 733 * (shown). The views within the page are shared by all existing perspectives to 734 * make it easy for the user to switch between one perspective and another 735 * quickly without loss of context. 736 * </p> 737 * <p> 738 * During activation the action sets are modified. If an action set is specified 739 * in the new perspective which is not visible in the old one it will be 740 * created. If an old action set is not specified in the new perspective it will 741 * be disposed. 742 * </p> 743 * <p> 744 * The visible views and their layout within the page also change. If a view is 745 * specified in the new perspective which is not visible in the old one a new 746 * instance of the view will be created. If an old view is not specified in the 747 * new perspective it will be hidden. This view may reappear if the user selects 748 * it from the View menu or if they switch to a perspective (which may be the 749 * old one) where the view is visible. 750 * </p> 751 * <p> 752 * The open editors are not modified by this method. 753 * </p> 754 * 755 * @param perspective the perspective descriptor 756 */ setPerspective(IPerspectiveDescriptor perspective)757 void setPerspective(IPerspectiveDescriptor perspective); 758 759 /** 760 * Shows an action set in this page. 761 * <p> 762 * In most cases where this method is used the caller is tightly coupled to a 763 * particular action set. They define it in the registry and may make it visible 764 * in certain scenarios by calling <code>showActionSet</code>. A static variable 765 * is often used to identify the action set id in caller code. 766 * </p> 767 * 768 * @param actionSetID the action set to show 769 */ showActionSet(String actionSetID)770 void showActionSet(String actionSetID); 771 772 /** 773 * Shows the view identified by the given view id in this page and gives it 774 * focus. If there is a view identified by the given view id (and with no 775 * secondary id) already open in this page, it is given focus. 776 * 777 * @param viewId the id of the view extension to use 778 * @return the shown view 779 * @exception PartInitException if the view could not be initialized 780 */ showView(String viewId)781 IViewPart showView(String viewId) throws PartInitException; 782 783 /** 784 * Shows a view in this page with the given id and secondary id. The behaviour 785 * of this method varies based on the supplied mode. If 786 * <code>VIEW_ACTIVATE</code> is supplied, the view is given focus. If 787 * <code>VIEW_VISIBLE</code> is supplied, then it is made visible but not given 788 * focus. Finally, if <code>VIEW_CREATE</code> is supplied the view is created 789 * and will only be made visible if it is not created in a folder that already 790 * contains visible views. 791 * <p> 792 * This allows multiple instances of a particular view to be created. They are 793 * disambiguated using the secondary id. If a secondary id is given, the view 794 * must allow multiple instances by having specified allowMultiple="true" in its 795 * extension. 796 * </p> 797 * 798 * @param viewId the id of the view extension to use 799 * @param secondaryId the secondary id to use, or <code>null</code> for no 800 * secondary id 801 * @param mode the activation mode. Must be {@link #VIEW_ACTIVATE}, 802 * {@link #VIEW_VISIBLE} or {@link #VIEW_CREATE} 803 * @return a view 804 * @exception PartInitException if the view could not be initialized 805 * @exception IllegalArgumentException if the supplied mode is not valid 806 * @since 3.0 807 */ showView(String viewId, String secondaryId, int mode)808 IViewPart showView(String viewId, String secondaryId, int mode) throws PartInitException; 809 810 /** 811 * Returns <code>true</code> if the editor is pinned and should not be reused. 812 * 813 * @param editor the editor to test 814 * @return boolean whether the editor is pinned 815 */ isEditorPinned(IEditorPart editor)816 boolean isEditorPinned(IEditorPart editor); 817 818 /** 819 * Returns the number of open editors before reusing editors. 820 * 821 * @return a int 822 * 823 * @deprecated 824 */ 825 @Deprecated getEditorReuseThreshold()826 int getEditorReuseThreshold(); 827 828 /** 829 * Set the number of open editors before reusing editors. If < 0 the user 830 * preference settings will be used. 831 * 832 * @param openEditors the threshold 833 * @deprecated use IPageLayout.setEditorReuseThreshold(int openEditors) instead. 834 */ 835 @Deprecated setEditorReuseThreshold(int openEditors)836 void setEditorReuseThreshold(int openEditors); 837 838 /** 839 * Returns the navigation history which manages a list of entries keeping the 840 * history of places (positions, selection and editors) the user visited making 841 * it easier to the user to move back and forward without losing context. 842 * 843 * @return the navigation history 844 * @since 2.1 845 */ getNavigationHistory()846 INavigationHistory getNavigationHistory(); 847 848 /** 849 * Returns an array of IViewParts that are stacked with the given part in the 850 * currently active perspective. 851 * 852 * @param part the part to test 853 * @return the parts that are stacked with this part, including the part in 854 * question. <code>null</code> is returned if the part does not belong 855 * to this page or the part is not contained in the active perspective. 856 * The parts are in LRU order. 857 * @since 3.0 858 */ getViewStack(IViewPart part)859 IViewPart[] getViewStack(IViewPart part); 860 861 /** 862 * Returns the new wizard shortcuts associated with the current perspective. 863 * Returns an empty array if there is no current perspective. 864 * 865 * @see IPageLayout#addNewWizardShortcut(String) 866 * @return an array of wizard identifiers 867 * @since 3.1 868 */ getNewWizardShortcuts()869 String[] getNewWizardShortcuts(); 870 871 /** 872 * Returns the perspective shortcuts associated with the current perspective. 873 * Returns an empty array if there is no current perspective. 874 * 875 * @see IPageLayout#addPerspectiveShortcut(String) 876 * @return an array of perspective identifiers 877 * @since 3.1 878 */ getPerspectiveShortcuts()879 String[] getPerspectiveShortcuts(); 880 881 /** 882 * Returns the show view shortcuts associated with the current perspective. 883 * Returns an empty array if there is no current perspective. 884 * 885 * @see IPageLayout#addShowViewShortcut(String) 886 * @return an array of view identifiers 887 * @since 3.1 888 */ getShowViewShortcuts()889 String[] getShowViewShortcuts(); 890 891 /** 892 * Returns the descriptors for the perspectives that are open in this page, in 893 * the order in which they were opened. 894 * 895 * @return the open perspective descriptors, in order of opening 896 * @since 3.1 897 */ getOpenPerspectives()898 IPerspectiveDescriptor[] getOpenPerspectives(); 899 900 /** 901 * Returns the descriptors for the perspectives that are open in this page, in 902 * the order in which they were activated (oldest first). 903 * 904 * @return the open perspective descriptors, in order of activation 905 * @since 3.1 906 */ getSortedPerspectives()907 IPerspectiveDescriptor[] getSortedPerspectives(); 908 909 /** 910 * Closes the specified perspective in this page. If the last perspective in 911 * this page is closed, then all editors are closed. Views that are not shown in 912 * other perspectives are closed as well. If <code>saveParts</code> is 913 * <code>true</code>, the user will be prompted to save any unsaved changes for 914 * parts that are being closed. The page itself is closed if 915 * <code>closePage</code> is <code>true</code>. 916 * 917 * @param desc the descriptor of the perspective to be closed 918 * @param saveParts whether the page's parts should be saved if closed 919 * @param closePage whether the page itself should be closed if last perspective 920 * @since 3.1 921 */ closePerspective(IPerspectiveDescriptor desc, boolean saveParts, boolean closePage)922 void closePerspective(IPerspectiveDescriptor desc, boolean saveParts, boolean closePage); 923 924 /** 925 * Closes all perspectives in this page. All editors are closed, prompting to 926 * save any unsaved changes if <code>saveEditors</code> is <code>true</code>. 927 * The page itself is closed if <code>closePage</code> is <code>true</code>. 928 * 929 * @param saveEditors whether the page's editors should be saved 930 * @param closePage whether the page itself should be closed 931 * @since 3.1 932 */ closeAllPerspectives(boolean saveEditors, boolean closePage)933 void closeAllPerspectives(boolean saveEditors, boolean closePage); 934 935 /** 936 * <p> 937 * Return the extension tracker for the workbench. This tracker may be used by 938 * plug-ins to ensure responsiveness to changes to the plug-in registry. 939 * </p> 940 * <p> 941 * The tracker at this level of the workbench is typically used to track 942 * elements that only exist over the lifespan of a page. For example, 943 * <code>ViewPart</code> objects fall into this category. 944 * </p> 945 * 946 * @return the extension tracker 947 * @see IWorkbench#getExtensionTracker() 948 * @see IWorkbenchWindow#getExtensionTracker() 949 * @since 3.1 950 */ getExtensionTracker()951 IExtensionTracker getExtensionTracker(); 952 953 /** 954 * Return the visible working sets for this page. Please note that this array is 955 * not filtered by activities. Clients should attempt to ensure that any use of 956 * this method is consistant with the currently enabled activity set. 957 * 958 * @return the visible working sets for this page 959 * @see IWorkbench#getActivitySupport() 960 * @since 3.2 961 */ getWorkingSets()962 IWorkingSet[] getWorkingSets(); 963 964 /** 965 * Set the working sets for this page. Any duplicate entries will be removed 966 * from the array by this method. 967 * 968 * @param sets the new working sets for this page. The array may be empty, but 969 * no element in the array may be <code>null</code>. 970 * @since 3.2 971 */ setWorkingSets(IWorkingSet[] sets)972 void setWorkingSets(IWorkingSet[] sets); 973 974 /** 975 * Return a working set that contains all of the elements contained in the array 976 * of working sets provided by {@link #getWorkingSets()}. Should this array or 977 * the underlying elements in any of the working sets change this set will be 978 * updated. 979 * 980 * <p> 981 * This working set is never <code>null</code>, even if there are no working 982 * sets assigned to this page via {@link #setWorkingSets(IWorkingSet[])}. It is 983 * recommended that any client that uses this API be aware of this and act 984 * accordingly. Specifically, it is recommended that any client utilizing this 985 * or any other IWorkingSet whose {@link IWorkingSet#isAggregateWorkingSet()} 986 * returns <code>true</code> act as if they are not using any working set if the 987 * set is empty. These clients should also maintain an awareness of the contents 988 * of aggregate working sets and toggle this behavior should the contents of the 989 * aggregate either become empty or non-empty. 990 * </p> 991 * <p> 992 * Example pseudocode showing how some workingset utilizing component could 993 * react to changes in aggregate working sets: 994 * </p> 995 * 996 * <pre> 997 * <code> 998 * private IWorkingSet myWorkingSet; 999 * 1000 * IPropertyChangeListener workingSetListener = new IPropertyChangeListener() { 1001 * void propertyChange(PropertyChangeEvent event) { 1002 * if (isMyCurrentWorkingSet(event)) { 1003 * if (isEmptyAggregate(myWorkingSet)) { 1004 * showNoSet(); 1005 * } 1006 * else { 1007 * showSet(); 1008 * } 1009 * } 1010 * } 1011 * }; 1012 * 1013 * void setWorkingSet(IWorkingSet newSet) { 1014 * myWorkingSet = newSet; 1015 * if (myWorkingSet == null || isEmptyAggregate(myWorkingSet)){ 1016 * showNoSet(); 1017 * } 1018 * else { 1019 * showSet(); 1020 * } 1021 * } 1022 * </code> 1023 * </pre> 1024 * 1025 * @return the aggregate working set for this page, this implements 1026 * {@link IAggregateWorkingSet} 1027 * @see IAggregateWorkingSet 1028 * @since 3.2 1029 */ getAggregateWorkingSet()1030 IWorkingSet getAggregateWorkingSet(); 1031 1032 /** 1033 * Returns the page "zoomed" state. 1034 * 1035 * @return <code>true</code> if the page is zoomed in the workbench window, 1036 * <code>false</code> otherwise. 1037 * @since 3.2 1038 */ isPageZoomed()1039 boolean isPageZoomed(); 1040 1041 /** 1042 * Zooms out the zoomed-in part. If the page does not have a zoomed part, it 1043 * does nothing. 1044 * 1045 * @since 3.2 1046 */ zoomOut()1047 void zoomOut(); 1048 1049 /** 1050 * Zoom the page in on a part. If the part is already in zoom then zoom out. 1051 * 1052 * @param ref the workbench part to zoom in on. Must not be <code>null</code>. 1053 * @since 3.2 1054 */ toggleZoom(IWorkbenchPartReference ref)1055 void toggleZoom(IWorkbenchPartReference ref); 1056 1057 /** 1058 * Returns the maximized/minimized/restored state of the given part reference. 1059 * 1060 * @param ref the workbench part to query. Must not be <code>null</code>. 1061 * @return one of the STATE_* contants. 1062 * @since 3.2 1063 */ getPartState(IWorkbenchPartReference ref)1064 int getPartState(IWorkbenchPartReference ref); 1065 1066 /** 1067 * Set the state of the given part reference. Setting the state of one part can 1068 * effect the state of other parts. 1069 * 1070 * @param ref the workbench part reference. Must not be <code>null</code>. 1071 * @param state one of the STATE_* constants. 1072 * @since 3.2 1073 */ setPartState(IWorkbenchPartReference ref, int state)1074 void setPartState(IWorkbenchPartReference ref, int state); 1075 1076 /** 1077 * Find the part reference for the given part. A convenience method to quickly 1078 * go from part to part reference. 1079 * 1080 * @param part The part to search for. It can be <code>null</code>. 1081 * @return The reference for the given part, or <code>null</code> if no 1082 * reference can be found. 1083 * @since 3.2 1084 */ getReference(IWorkbenchPart part)1085 IWorkbenchPartReference getReference(IWorkbenchPart part); 1086 1087 /** 1088 * Add back an open but non-participating editor 1089 * 1090 * @param ref the editor to re-add. Must be an editor removed using 1091 * #hideEditor(IEditorReference), must not have been closed, and must 1092 * not be <code>null</code>. 1093 * @since 3.5 1094 * @see #hideEditor(IEditorReference) 1095 */ showEditor(IEditorReference ref)1096 void showEditor(IEditorReference ref); 1097 1098 /** 1099 * Remove an open editor, turn it into a non-participating editor. 1100 * <p> 1101 * A non-participating editor will not be returned in the list of open editors 1102 * ({@link #getEditorReferences()}) and will not be visible in the editor area. 1103 * However, it will continue to participate in the save lifecycle and may still 1104 * be closed by some workbench close events. 1105 * </p> 1106 * <p> 1107 * Behaviour for hiding and showing editors from multiple stacks is not defined 1108 * (and unsupported) at this time. 1109 * </p> 1110 * 1111 * @param ref the editor reference to remove. It must be a current open editor 1112 * belonging to this page, and must not be <code>null</code>. 1113 * @since 3.5 1114 * @see #showEditor(IEditorReference) 1115 */ hideEditor(IEditorReference ref)1116 void hideEditor(IEditorReference ref); 1117 1118 /** 1119 * Opens editors for the given inputs. Only the editor constructed for the first 1120 * input gets activated. 1121 * <p> 1122 * The editor type is determined by mapping <code>editorIDs</code> to an editor 1123 * extension registered with the workbench. An editor id is passed rather than 1124 * an editor object to prevent the accidental creation of more than one editor 1125 * for the same input. It also guarantees a consistent lifecycle for editors, 1126 * regardless of whether they are created by the user or restored from saved 1127 * data. 1128 * </p> 1129 * <p> 1130 * The length of the input array and editor ID arrays must be the same. The 1131 * editors are opened using pairs of { input[i], editorIDs[i] }. 1132 * </p> 1133 * 1134 * @param inputs the editor inputs 1135 * @param editorIDs the IDs of the editor extensions to use, in the order of 1136 * inputs 1137 * @param matchFlags a bit mask consisting of zero or more of the MATCH_* 1138 * constants OR-ed together 1139 * @return references to the editors constructed for the inputs. The editors 1140 * corresponding to those reference might not be materialized. 1141 * @exception MultiPartInitException if at least one editor could not be created 1142 * or initialized 1143 * @see #MATCH_NONE 1144 * @see #MATCH_INPUT 1145 * @see #MATCH_ID 1146 * @since 3.5 1147 */ openEditors(final IEditorInput[] inputs, final String[] editorIDs, final int matchFlags)1148 IEditorReference[] openEditors(final IEditorInput[] inputs, final String[] editorIDs, final int matchFlags) 1149 throws MultiPartInitException; 1150 1151 /** 1152 * Opens editors for the given inputs. Only the editor constructed for the given 1153 * index will be activated. 1154 * <p> 1155 * There are effectively two different ways to use this method based on what 1156 * information the supplied mementos contain @see org.eclipse.ui.IWorkbenchPage 1157 * #getEditorState(org.eclipse.ui.IEditorReference []): 1158 * </p> 1159 * <ol> 1160 * <li>If the mementos contain the 'input' information then only the memento 1161 * itself is required since it can be used to re-create the editor input and its 1162 * editorID. If all the mementos are of this type then the inputs and editorIDs 1163 * arrays may be null.</li> 1164 * <li>If the supplied memento only contains the editor state then both the 1165 * input and editorID must be non-null.</li> 1166 * </ol> 1167 * <p> 1168 * The editor type is determined by mapping <code>editorIDs</code> to an editor 1169 * extension registered with the workbench. An editor id is passed rather than 1170 * an editor object to prevent the accidental creation of more than one editor 1171 * for the same input. It also guarantees a consistent lifecycle for editors, 1172 * regardless of whether they are created by the user or restored from saved 1173 * data. 1174 * </p> 1175 * <p> 1176 * The length of the input array and editor ID arrays must be the same. The 1177 * editors are opened using pairs of { input[i], editorIDs[i] }. 1178 * </p> 1179 * <p> 1180 * The mementos array mat be null but if not must match the input array in 1181 * length. Entries in the mementos array may also be null if no state is desired 1182 * for that particular editor. 1183 * </p> 1184 * 1185 * @param inputs the editor inputs 1186 * @param editorIDs the IDs of the editor extensions to use, in the order of 1187 * inputs 1188 * @param mementos the mementos representing the state to open the editor 1189 * with. If the supplied memento contains the input's state 1190 * as well as the editor's state then the corresponding 1191 * entries in the 'inputs' and 'ids' arrays may be 1192 * <code>null</code> (they will be created from the 1193 * supplied memento). 1194 * 1195 * @param matchFlags a bit mask consisting of zero or more of the MATCH_* 1196 * constants OR-ed together 1197 * @param activateIndex the index of the editor to make active or -1 if no 1198 * activation is desired. 1199 * @return references to the editors constructed for the inputs. The editors 1200 * corresponding to those reference might not be materialized. 1201 * @exception MultiPartInitException if at least one editor could not be created 1202 * or initialized 1203 * @see #MATCH_NONE 1204 * @see #MATCH_INPUT 1205 * @see #MATCH_ID 1206 * @since 3.8.2 1207 */ openEditors(final IEditorInput[] inputs, final String[] editorIDs, final IMemento[] mementos, final int matchFlags, final int activateIndex)1208 IEditorReference[] openEditors(final IEditorInput[] inputs, final String[] editorIDs, final IMemento[] mementos, 1209 final int matchFlags, final int activateIndex) throws MultiPartInitException; 1210 1211 /** 1212 * Return an IMemento containing the current state of the editor for each of the 1213 * given references. These mementos may be used to determine the initial state 1214 * of an editor on a subsequent open. 1215 * 1216 * @param editorRefs The array of editor references to get the state for 1217 * @param includeInputState If <code>true</code> then the resulting memento will 1218 * be contain the editor input's state as well as the 1219 * editor's state. 1220 * @return The array of mementos. The length of the array will match that of the 1221 * refs array. 1222 * @since 3.8.2 1223 */ getEditorState(IEditorReference[] editorRefs, boolean includeInputState)1224 IMemento[] getEditorState(IEditorReference[] editorRefs, boolean includeInputState); 1225 } 1226