1 /*******************************************************************************
2 * Copyright (c) 2000, 2010 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
12 package org.simantics.browsing.ui.platform;
14 import java.util.HashMap;
15 import java.util.Iterator;
19 import org.eclipse.core.commands.common.EventManager;
20 import org.eclipse.core.runtime.Platform;
21 import org.eclipse.jface.action.IAction;
22 import org.eclipse.jface.util.IPropertyChangeListener;
23 import org.eclipse.jface.util.PropertyChangeEvent;
24 import org.eclipse.jface.util.SafeRunnable;
25 import org.eclipse.jface.viewers.IPostSelectionProvider;
26 import org.eclipse.jface.viewers.ISelection;
27 import org.eclipse.jface.viewers.ISelectionChangedListener;
28 import org.eclipse.jface.viewers.ISelectionProvider;
29 import org.eclipse.jface.viewers.SelectionChangedEvent;
30 import org.eclipse.jface.viewers.StructuredSelection;
31 import org.eclipse.swt.SWT;
32 import org.eclipse.swt.widgets.Composite;
33 import org.eclipse.swt.widgets.Control;
34 import org.eclipse.ui.IActionBars;
35 import org.eclipse.ui.IPartListener;
36 import org.eclipse.ui.IPartListener2;
37 import org.eclipse.ui.IViewPart;
38 import org.eclipse.ui.IViewSite;
39 import org.eclipse.ui.IWorkbenchPage;
40 import org.eclipse.ui.IWorkbenchPart;
41 import org.eclipse.ui.IWorkbenchPartReference;
42 import org.eclipse.ui.PartInitException;
43 import org.eclipse.ui.SubActionBars;
44 import org.eclipse.ui.internal.WorkbenchPlugin;
45 import org.eclipse.ui.internal.util.Util;
46 import org.eclipse.ui.part.IPage;
47 import org.eclipse.ui.part.IPageBookViewPage;
48 import org.eclipse.ui.part.IPageSite;
49 import org.eclipse.ui.part.PageBook;
50 import org.eclipse.ui.part.ViewPart;
51 import org.simantics.browsing.ui.common.IPageBookViewPagePartInit;
54 * Abstract superclass of all multi-page workbench views.
56 * Within the workbench there are many views which track the active part. If a
57 * part is activated these views display some properties for the active part. A
58 * simple example is the <code>Outline View</code>, which displays the outline
59 * for the active editor. To avoid loss of context when part activation changes,
60 * these views may implement a multi-page approach. A separate page is
61 * maintained within the view for each source view. If a part is activated the
62 * associated page for the part is brought to top. If a part is closed the
63 * associated page is disposed. <code>PageBookView</code> is a base
64 * implementation for multi page views.
67 * <code>PageBookView</code>s provide an <code>IPageSite</code> for each of
68 * their pages. This site is supplied during the page's initialization. The page
69 * may supply a selection provider for this site. <code>PageBookView</code>s
70 * deal with these selection providers in a similar way to a workbench page's
71 * <code>SelectionService</code>. When a page is made visible, if its site has a
72 * selection provider, then changes in the selection are listened for and the
73 * current selection is obtained and fired as a selection change event.
74 * Selection changes are no longer listened for when a page is made invisible.
77 * This class should be subclassed by clients wishing to define new multi-page
81 * When a <code>PageBookView</code> is created the following methods are
82 * invoked. Subclasses must implement these.
84 * <li><code>createDefaultPage</code> - called to create a default page for the
85 * view. This page is displayed when the active part in the workbench does not
87 * <li><code>getBootstrapPart</code> - called to determine the active part in
88 * the workbench. A page will be created for this part</li>
92 * When a part is activated the base implementation does not know if a page
93 * should be created for the part. Therefore, it delegates creation to the
96 * <li><code>isImportant</code> - called when a workbench part is activated.
97 * Subclasses return whether a page should be created for the new part.</li>
98 * <li><code>doCreatePage</code> - called to create a page for a particular part
99 * in the workbench. This is only invoked when <code>isImportant</code> returns
100 * </code>true</code>.</li>
104 * When a part is closed the base implementation will destroy the page
105 * associated with the particular part. The page was created by a subclass, so
106 * the subclass must also destroy it. Subclasses must implement these.
108 * <li><code>doDestroyPage</code> - called to destroy a page for a particular
109 * part in the workbench.</li>
113 * Otherwise a carbon copy of {@link org.eclipse.ui.part.PageBookView} but
114 * {@link #partActivated(IWorkbenchPart)} has been slightly customized to not
115 * always show the default page if an activated page does not provide a property
118 * @author Tuukka Lehtonen
120 @SuppressWarnings({"rawtypes", "unchecked", "deprecation", "restriction"})
121 public abstract class PageBookView extends ViewPart implements IPartListener {
123 * The pagebook control, or <code>null</code> if not initialized.
125 private PageBook book;
128 * The page record for the default page.
130 private PageRec defaultPageRec;
133 * Map from parts to part records (key type: <code>IWorkbenchPart</code>;
134 * value type: <code>PartRec</code>).
136 private final Map mapPartToRec = new HashMap();
139 * Map from pages to view sites Note that view sites were not added to page
140 * recs to avoid breaking binary compatibility with previous builds
142 private final Map mapPageToSite = new HashMap();
145 * Map from pages to the number of pageRecs actively associated with a page.
147 private final Map mapPageToNumRecs = new HashMap();
150 * The page rec which provided the current page or <code>null</code>
152 private PageRec activeRec;
155 * If the part is hidden (usually an editor) then store it so we can
156 * continue to track it when it becomes visible.
158 private IWorkbenchPart hiddenPart = null;
161 * The action bar property listener.
163 private final IPropertyChangeListener actionBarPropListener = new IPropertyChangeListener() {
165 public void propertyChange(PropertyChangeEvent event) {
166 if (event.getProperty().equals(SubActionBars.P_ACTION_HANDLERS)
168 && event.getSource() == activeRec.subActionBars) {
169 refreshGlobalActionHandlers();
175 * Selection change listener to listen for page selection changes
177 private final ISelectionChangedListener selectionChangedListener = new ISelectionChangedListener() {
179 public void selectionChanged(SelectionChangedEvent event) {
180 pageSelectionChanged(event);
185 * Selection change listener to listen for page selection changes
187 private final ISelectionChangedListener postSelectionListener = new ISelectionChangedListener() {
189 public void selectionChanged(SelectionChangedEvent event) {
190 postSelectionChanged(event);
195 * Selection provider for this view's site
197 private final SelectionProvider selectionProvider = new SelectionProvider();
200 * A data structure used to store the information about a single page within
203 protected static class PageRec {
208 public IWorkbenchPart part;
216 * The page's action bars
218 public SubActionBars subActionBars;
221 * Creates a new page record initialized to the given part and page.
226 public PageRec(IWorkbenchPart part, IPage page) {
232 * Disposes of this page record by <code>null</code>ing its fields.
234 public void dispose() {
240 private static class SelectionManager extends EventManager {
246 public void addSelectionChangedListener(
247 ISelectionChangedListener listener) {
248 addListenerObject(listener);
256 public void removeSelectionChangedListener(
257 ISelectionChangedListener listener) {
258 removeListenerObject(listener);
266 public void selectionChanged(final SelectionChangedEvent event) {
267 // pass on the notification to listeners
268 Object[] listeners = getListeners();
269 for (int i = 0; i < listeners.length; ++i) {
270 final ISelectionChangedListener l = (ISelectionChangedListener) listeners[i];
271 Platform.run(new SafeRunnable() {
274 l.selectionChanged(event);
283 * A selection provider/listener for this view. It is a selection provider
284 * for this view's site.
286 protected class SelectionProvider implements IPostSelectionProvider {
288 private final SelectionManager fSelectionListener = new SelectionManager();
290 private final SelectionManager fPostSelectionListeners = new SelectionManager();
293 * (non-Javadoc) Method declared on ISelectionProvider.
296 public void addSelectionChangedListener(
297 ISelectionChangedListener listener) {
298 fSelectionListener.addSelectionChangedListener(listener);
302 * (non-Javadoc) Method declared on ISelectionProvider.
305 public ISelection getSelection() {
306 // get the selection provider from the current page
307 IPage currentPage = getCurrentPage();
308 // during workbench startup we may be in a state when
309 // there is no current page
310 if (currentPage == null) {
311 return StructuredSelection.EMPTY;
313 IPageSite site = getPageSite(currentPage);
315 return StructuredSelection.EMPTY;
317 ISelectionProvider selProvider = site.getSelectionProvider();
318 if (selProvider != null) {
319 return selProvider.getSelection();
321 return StructuredSelection.EMPTY;
325 * (non-Javadoc) Method declared on ISelectionProvider.
328 public void removeSelectionChangedListener(
329 ISelectionChangedListener listener) {
330 fSelectionListener.removeSelectionChangedListener(listener);
334 * The selection has changed. Process the event, notifying selection
335 * listeners and post selection listeners.
340 public void selectionChanged(final SelectionChangedEvent event) {
341 fSelectionListener.selectionChanged(event);
345 * The selection has changed, so notify any post-selection listeners.
350 public void postSelectionChanged(final SelectionChangedEvent event) {
351 fPostSelectionListeners.selectionChanged(event);
355 * (non-Javadoc) Method declared on ISelectionProvider.
358 public void setSelection(ISelection selection) {
359 // get the selection provider from the current page
360 IPage currentPage = getCurrentPage();
361 // during workbench startup we may be in a state when
362 // there is no current page
363 if (currentPage == null) {
366 IPageSite site = getPageSite(currentPage);
370 ISelectionProvider selProvider = site.getSelectionProvider();
371 // and set its selection
372 if (selProvider != null) {
373 selProvider.setSelection(selection);
380 * @see org.eclipse.jface.viewers.IPostSelectionProvider#addPostSelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener)
383 public void addPostSelectionChangedListener(
384 ISelectionChangedListener listener) {
385 fPostSelectionListeners.addSelectionChangedListener(listener);
391 * @see org.eclipse.jface.viewers.IPostSelectionProvider#removePostSelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener)
394 public void removePostSelectionChangedListener(
395 ISelectionChangedListener listener) {
396 fPostSelectionListeners.removeSelectionChangedListener(listener);
401 * Creates a new pagebook view.
403 protected PageBookView() {
408 * Creates and returns the default page for this view.
410 * Subclasses must implement this method.
413 * Subclasses must call initPage with the new page (if it is an
414 * <code>IPageBookViewPage</code>) before calling createControl on the
419 * the pagebook control
420 * @return the default page
422 protected abstract IPage createDefaultPage(PageBook book);
425 * Creates a page for a given part. Adds it to the pagebook but does not
429 * The part we are making a page for.
430 * @return IWorkbenchPart
432 private PageRec createPage(IWorkbenchPart part) {
433 PageRec rec = doCreatePage(part);
435 mapPartToRec.put(part, rec);
442 * Prepares the page in the given page rec for use in this view.
446 private void preparePage(PageRec rec) {
447 IPageSite site = null;
450 if (!doesPageExist(rec.page)) {
451 if (rec.page instanceof IPageBookViewPage) {
452 site = ((IPageBookViewPage) rec.page).getSite();
455 // We will create a site for our use
456 site = new PageSite(getViewSite());
458 mapPageToSite.put(rec.page, site);
460 rec.subActionBars = (SubActionBars) site.getActionBars();
461 rec.subActionBars.addPropertyChangeListener(actionBarPropListener);
462 // for backward compability with IPage
463 rec.page.setActionBars(rec.subActionBars);
465 count = new Integer(0);
467 site = (IPageSite) mapPageToSite.get(rec.page);
468 rec.subActionBars = (SubActionBars) site.getActionBars();
469 count = ((Integer) mapPageToNumRecs.get(rec.page));
472 mapPageToNumRecs.put(rec.page, new Integer(count.intValue() + 1));
476 * Initializes the given page with a page site.
478 * Subclasses should call this method after the page is created but before
479 * creating its controls.
482 * Subclasses may override
486 * The page to initialize
488 protected void initPage(IPageBookViewPage page) {
491 page.init(new PageSite(getViewSite()));
492 } catch (PartInitException e) {
493 WorkbenchPlugin.log(getClass(), "initPage", e); //$NON-NLS-1$
496 if(page instanceof IPageBookViewPagePartInit) {
497 ((IPageBookViewPagePartInit)page).initPart(this);
503 * The <code>PageBookView</code> implementation of this
504 * <code>IWorkbenchPart</code> method creates a <code>PageBook</code>
505 * control with its default page showing. Subclasses may extend.
508 public void createPartControl(Composite parent) {
510 // Create the page book.
511 book = new PageBook(parent, SWT.NONE);
513 // Create the default page rec.
514 IPage defaultPage = createDefaultPage(book);
515 defaultPageRec = new PageRec(null, defaultPage);
516 preparePage(defaultPageRec);
518 // Show the default page
519 showPageRec(defaultPageRec);
521 // Listen to part activation events.
522 getSite().getPage().addPartListener(partListener);
527 * The <code>PageBookView</code> implementation of this
528 * <code>IWorkbenchPart</code> method cleans up all the pages. Subclasses
532 public void dispose() {
533 // stop listening to part activation
534 getSite().getPage().removePartListener(partListener);
536 // Deref all of the pages.
538 if (defaultPageRec != null) {
539 // check for null since the default page may not have
540 // been created (ex. perspective never visible)
541 defaultPageRec.page.dispose();
542 defaultPageRec = null;
544 Map clone = (Map) ((HashMap) mapPartToRec).clone();
545 Iterator itr = clone.values().iterator();
546 while (itr.hasNext()) {
547 PageRec rec = (PageRec) itr.next();
556 * Creates a new page in the pagebook for a particular part. This page will
557 * be made visible whenever the part is active, and will be destroyed with a
558 * call to <code>doDestroyPage</code>.
560 * Subclasses must implement this method.
563 * Subclasses must call initPage with the new page (if it is an
564 * <code>IPageBookViewPage</code>) before calling createControl on the
570 * @return the record describing a new page for this view
571 * @see #doDestroyPage
573 protected abstract PageRec doCreatePage(IWorkbenchPart part);
576 * Destroys a page in the pagebook for a particular part. This page was
577 * returned as a result from <code>doCreatePage</code>.
579 * Subclasses must implement this method.
585 * a page record for the part
588 protected abstract void doDestroyPage(IWorkbenchPart part,
592 * Returns true if the page has already been created.
596 * @return true if this page has already been created.
598 protected boolean doesPageExist(IPage page) {
599 return mapPageToNumRecs.containsKey(page);
603 * The <code>PageBookView</code> implementation of this
604 * <code>IAdaptable</code> method delegates to the current page, if it
605 * implements <code>IAdaptable</code>.
608 public Object getAdapter(Class key) {
609 // delegate to the current page, if supported
610 IPage page = getCurrentPage();
611 Object adapter = Util.getAdapter(page, key);
612 if (adapter != null) {
615 // if the page did not find the adapter, look for one provided by
616 // this view before delegating to super.
617 adapter = getViewAdapter(key);
618 if (adapter != null) {
622 return super.getAdapter(key);
626 * Returns an adapter of the specified type, as provided by this view (not
627 * the current page), or <code>null</code> if this view does not provide
628 * an adapter of the specified adapter.
630 * The default implementation returns <code>null</code>. Subclasses may
635 * the adapter class to look up
636 * @return a object castable to the given class, or <code>null</code> if
637 * this object does not have an adapter for the given class
640 protected Object getViewAdapter(Class adapter) {
645 * Returns the active, important workbench part for this view.
647 * When the page book view is created it has no idea which part within the
648 * workbook should be used to generate the first page. Therefore, it
649 * delegates the choice to subclasses of <code>PageBookView</code>.
652 * Implementors of this method should return an active, important part in
653 * the workbench or <code>null</code> if none found.
656 * Subclasses must implement this method.
659 * @return the active important part, or <code>null</code> if none
661 protected abstract IWorkbenchPart getBootstrapPart();
664 * Returns the part which contributed the current page to this view.
666 * @return the part which contributed the current page or <code>null</code>
667 * if no part contributed the current page
669 protected IWorkbenchPart getCurrentContributingPart() {
670 if (activeRec == null) {
673 return activeRec.part;
677 * Returns the currently visible page for this view or <code>null</code>
678 * if no page is currently visible.
680 * @return the currently visible page
682 public IPage getCurrentPage() {
683 if (activeRec == null) {
686 return activeRec.page;
690 * Returns the view site for the given page of this view.
694 * @return the corresponding site, or <code>null</code> if not found
696 protected PageSite getPageSite(IPage page) {
697 return (PageSite) mapPageToSite.get(page);
701 * Returns the default page for this view.
703 * @return the default page
705 public IPage getDefaultPage() {
706 return defaultPageRec.page;
710 * Returns the pagebook control for this view.
712 * @return the pagebook control, or <code>null</code> if not initialized
714 protected PageBook getPageBook() {
719 * Returns the page record for the given part.
723 * @return the corresponding page record, or <code>null</code> if not
726 protected PageRec getPageRec(IWorkbenchPart part) {
727 return (PageRec) mapPartToRec.get(part);
731 * Returns the page record for the given page of this view.
735 * @return the corresponding page record, or <code>null</code> if not
738 protected PageRec getPageRec(IPage page) {
739 Iterator itr = mapPartToRec.values().iterator();
740 while (itr.hasNext()) {
741 PageRec rec = (PageRec) itr.next();
742 if (rec.page == page) {
750 * Returns whether the given part should be added to this view.
752 * Subclasses must implement this method.
757 * @return <code>true</code> if the part is relevant, and
758 * <code>false</code> otherwise
760 protected abstract boolean isImportant(IWorkbenchPart part);
763 * (non-Javadoc) Method declared on IViewPart.
766 public void init(IViewSite site) throws PartInitException {
767 site.setSelectionProvider(selectionProvider);
772 * The <code>PageBookView</code> implementation of this
773 * <code>IPartListener</code> method shows the page when the given part is
774 * activated. Subclasses may extend.
777 public void partActivated(IWorkbenchPart part) {
778 // Is this an important part? If not just return.
779 if (!isImportant(part)) {
784 // Create a page for the part.
785 PageRec rec = getPageRec(part);
787 rec = createPage(part);
794 Control[] children = book.getChildren();
795 //System.out.println("CHILDREN: " + Arrays.toString(children));
796 if (children.length < 2) {
797 //System.out.println("showing default page");
798 showPageRec(defaultPageRec);
804 * The <code>PageBookView</code> implementation of this
805 * <code>IPartListener</code> method does nothing. Subclasses may extend.
808 public void partBroughtToTop(IWorkbenchPart part) {
809 // Do nothing by default
813 * The <code>PageBookView</code> implementation of this
814 * <code>IPartListener</code> method deal with the closing of the active
815 * part. Subclasses may extend.
818 public void partClosed(IWorkbenchPart part) {
819 // Update the active part.
820 if (activeRec != null && activeRec.part == part) {
821 showPageRec(defaultPageRec);
824 // Find and remove the part page.
825 PageRec rec = getPageRec(part);
829 if (part == hiddenPart) {
835 * The <code>PageBookView</code> implementation of this
836 * <code>IPartListener</code> method does nothing. Subclasses may extend.
839 public void partDeactivated(IWorkbenchPart part) {
846 * @see org.eclipse.ui.IPartListener#partOpened(org.eclipse.ui.IWorkbenchPart)
849 public void partOpened(IWorkbenchPart part) {
850 // Do nothing by default.
854 * Refreshes the global actions for the active page.
856 private void refreshGlobalActionHandlers() {
857 // Clear old actions.
858 IActionBars bars = getViewSite().getActionBars();
859 bars.clearGlobalActionHandlers();
862 Map newActionHandlers = activeRec.subActionBars
863 .getGlobalActionHandlers();
864 if (newActionHandlers != null) {
865 Set keys = newActionHandlers.entrySet();
866 Iterator iter = keys.iterator();
867 while (iter.hasNext()) {
868 Map.Entry entry = (Map.Entry) iter.next();
869 bars.setGlobalActionHandler((String) entry.getKey(),
870 (IAction) entry.getValue());
876 * Removes a page record. If it is the last reference to the page dispose of
877 * it - otherwise just decrement the reference count.
881 private void removePage(PageRec rec) {
882 mapPartToRec.remove(rec.part);
884 int newCount = ((Integer) mapPageToNumRecs.get(rec.page)).intValue() - 1;
887 Object site = mapPageToSite.remove(rec.page);
888 mapPageToNumRecs.remove(rec.page);
890 Control control = rec.page.getControl();
891 if (control != null && !control.isDisposed()) {
892 // Dispose the page's control so pages don't have to do this in
895 // The page's control is a child of this view's control so if
897 // is closed, the page's control will already be disposed.
902 doDestroyPage(rec.part, rec);
904 if (rec.subActionBars != null) {
905 rec.subActionBars.dispose();
908 if (site instanceof PageSite) {
909 ((PageSite) site).dispose();
912 mapPageToNumRecs.put(rec.page, new Integer(newCount));
917 * (non-Javadoc) Method declared on IWorkbenchPart.
920 public void setFocus() {
921 // first set focus on the page book, in case the page
922 // doesn't properly handle setFocus
926 // then set focus on the page, if any
927 if (activeRec != null) {
928 activeRec.page.setFocus();
933 * Handle page selection changes.
937 private void pageSelectionChanged(SelectionChangedEvent event) {
938 // forward this change from a page to our site's selection provider
939 SelectionProvider provider = (SelectionProvider) getSite()
940 .getSelectionProvider();
941 if (provider != null) {
942 provider.selectionChanged(event);
947 * Handle page selection changes.
951 private void postSelectionChanged(SelectionChangedEvent event) {
952 // forward this change from a page to our site's selection provider
953 SelectionProvider provider = (SelectionProvider) getSite()
954 .getSelectionProvider();
955 if (provider != null) {
956 provider.postSelectionChanged(event);
961 * Shows a page for the active workbench part.
963 private void showBootstrapPart() {
964 IWorkbenchPart part = getBootstrapPart();
971 * Shows page contained in the given page record in this view. The page
972 * record must be one from this pagebook view.
974 * The <code>PageBookView</code> implementation of this method asks the
975 * pagebook control to show the given page's control, and records that the
976 * given page is now current. Subclasses may extend.
980 * the page record containing the page to show
982 protected void showPageRec(PageRec pageRec) {
983 // If already showing do nothing
984 if (activeRec == pageRec) {
987 // If the page is the same, just set activeRec to pageRec
988 if (activeRec != null && pageRec != null
989 && activeRec.page == pageRec.page) {
995 if (activeRec != null) {
996 PageSite pageSite = (PageSite) mapPageToSite.get(activeRec.page);
998 activeRec.subActionBars.deactivate();
1000 // deactivate the nested services
1001 pageSite.deactivate();
1003 // remove our selection listener
1004 ISelectionProvider provider = pageSite.getSelectionProvider();
1005 if (provider != null) {
1007 .removeSelectionChangedListener(selectionChangedListener);
1008 if (provider instanceof IPostSelectionProvider) {
1009 ((IPostSelectionProvider) provider)
1010 .removePostSelectionChangedListener(postSelectionListener);
1016 activeRec = pageRec;
1017 Control pageControl = activeRec.page.getControl();
1018 if (pageControl != null && !pageControl.isDisposed()) {
1019 PageSite pageSite = (PageSite) mapPageToSite.get(activeRec.page);
1021 // Verify that the page control is not disposed
1022 // If we are closing, it may have already been disposed
1023 book.showPage(pageControl);
1024 activeRec.subActionBars.activate();
1025 refreshGlobalActionHandlers();
1027 // activate the nested services
1028 pageSite.activate();
1030 // add our selection listener
1031 ISelectionProvider provider = pageSite.getSelectionProvider();
1032 if (provider != null) {
1033 provider.addSelectionChangedListener(selectionChangedListener);
1034 if (provider instanceof IPostSelectionProvider) {
1035 ((IPostSelectionProvider) provider)
1036 .addPostSelectionChangedListener(postSelectionListener);
1039 // Update action bars.
1040 getViewSite().getActionBars().updateActionBars();
1045 * Returns the selectionProvider for this page book view.
1047 * @return a SelectionProvider
1049 protected SelectionProvider getSelectionProvider() {
1050 return selectionProvider;
1053 private final IPartListener2 partListener = new IPartListener2() {
1055 public void partActivated(IWorkbenchPartReference partRef) {
1056 IWorkbenchPart part = partRef.getPart(false);
1057 PageBookView.this.partActivated(part);
1061 public void partBroughtToTop(IWorkbenchPartReference partRef) {
1062 PageBookView.this.partBroughtToTop(partRef.getPart(false));
1066 public void partClosed(IWorkbenchPartReference partRef) {
1067 PageBookView.this.partClosed(partRef.getPart(false));
1071 public void partDeactivated(IWorkbenchPartReference partRef) {
1072 PageBookView.this.partDeactivated(partRef.getPart(false));
1076 public void partHidden(IWorkbenchPartReference partRef) {
1077 PageBookView.this.partHidden(partRef.getPart(false));
1081 public void partInputChanged(IWorkbenchPartReference partRef) {
1085 public void partOpened(IWorkbenchPartReference partRef) {
1086 PageBookView.this.partOpened(partRef.getPart(false));
1090 public void partVisible(IWorkbenchPartReference partRef) {
1091 PageBookView.this.partVisible(partRef.getPart(false));
1096 * Make sure that the part is not considered if it is hidden.
1100 protected void partHidden(IWorkbenchPart part) {
1101 if (part == null || part != getCurrentContributingPart()) {
1104 // if we've minimized the editor stack, that's no reason to
1106 if (getSite().getPage().getPartState(
1107 getSite().getPage().getReference(part)) == IWorkbenchPage.STATE_MINIMIZED) {
1110 // if we're switching from a part source in our own stack,
1111 // we also don't want to clear our content.
1112 if (part instanceof IViewPart) {
1113 final IViewPart[] viewStack = getSite().getPage()
1114 .getViewStack(this);
1115 if (containsPart(viewStack, part)) {
1120 showPageRec(defaultPageRec);
1126 * @return <code>true</code> if the part is in the viewStack
1128 private boolean containsPart(IViewPart[] viewStack, IWorkbenchPart part) {
1129 if (viewStack == null) {
1132 for (int i = 0; i < viewStack.length; i++) {
1133 if (viewStack[i] == part) {
1141 * Make sure that the part is not considered if it is hidden.
1146 protected void partVisible(IWorkbenchPart part) {
1147 if (part == null || part != hiddenPart) {
1150 partActivated(part);