1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.browsing.ui.swt;
15 /*******************************************************************************
16 * Copyright (c) 2000, 2008 IBM Corporation and others.
17 * All rights reserved. This program and the accompanying materials
18 * are made available under the terms of the Eclipse Public License v1.0
19 * which accompanies this distribution, and is available at
20 * http://www.eclipse.org/legal/epl-v10.html
23 * IBM Corporation - initial API and implementation
24 *******************************************************************************/
26 import java.util.ArrayList;
27 import java.util.List;
29 import org.eclipse.core.commands.util.Tracing;
30 import org.eclipse.core.runtime.Assert;
31 import org.eclipse.core.runtime.ISafeRunnable;
32 import org.eclipse.core.runtime.SafeRunner;
33 import org.eclipse.jface.resource.ImageDescriptor;
34 import org.eclipse.jface.viewers.ISelectionProvider;
35 import org.eclipse.jface.viewers.SelectionChangedEvent;
36 import org.eclipse.swt.SWT;
37 import org.eclipse.swt.custom.CTabFolder;
38 import org.eclipse.swt.custom.CTabItem;
39 import org.eclipse.swt.events.SelectionAdapter;
40 import org.eclipse.swt.events.SelectionEvent;
41 import org.eclipse.swt.graphics.Image;
42 import org.eclipse.swt.layout.FillLayout;
43 import org.eclipse.swt.widgets.Composite;
44 import org.eclipse.swt.widgets.Control;
45 import org.eclipse.swt.widgets.Display;
46 import org.eclipse.swt.widgets.Item;
47 import org.eclipse.ui.IEditorInput;
48 import org.eclipse.ui.IEditorPart;
49 import org.eclipse.ui.IKeyBindingService;
50 import org.eclipse.ui.IMemento;
51 import org.eclipse.ui.INestableKeyBindingService;
52 import org.eclipse.ui.IPartService;
53 import org.eclipse.ui.IViewPart;
54 import org.eclipse.ui.IViewSite;
55 import org.eclipse.ui.IWorkbenchPart;
56 import org.eclipse.ui.IWorkbenchPartSite;
57 import org.eclipse.ui.PartInitException;
58 import org.eclipse.ui.internal.WorkbenchPlugin;
59 import org.eclipse.ui.internal.misc.Policy;
60 import org.eclipse.ui.internal.services.INestable;
61 import org.eclipse.ui.internal.services.IServiceLocatorCreator;
62 import org.eclipse.ui.internal.util.Util;
63 import org.eclipse.ui.part.MultiPageEditorPart;
64 import org.eclipse.ui.part.MultiPageEditorSite;
65 import org.eclipse.ui.part.MultiPageSelectionProvider;
66 import org.eclipse.ui.part.PageSwitcher;
67 import org.eclipse.ui.part.ViewPart;
68 import org.eclipse.ui.services.IDisposable;
69 import org.eclipse.ui.services.IServiceLocator;
72 * A multi-page editor is an editor with multiple pages, each of which may
73 * contain an editor or an arbitrary SWT control.
75 * Subclasses must implement the following methods:
77 * <li><code>createPages</code> - to create the required pages by calling one
78 * of the <code>addPage</code> methods</li>
79 * <li><code>IEditorPart.doSave</code> - to save contents of editor</li>
80 * <li><code>IEditorPart.doSaveAs</code> - to save contents of editor</li>
81 * <li><code>IEditorPart.isSaveAsAllowed</code> - to enable Save As</li>
82 * <li><code>IEditorPart.gotoMarker</code> - to scroll to a marker</li>
86 * Multi-page editors have a single action bar contributor, which manages
87 * contributions for all the pages. The contributor must be a subclass of
88 * <code>AbstractMultiPageEditorActionBarContributor</code>. Note that since
89 * any nested editors are created directly in code by callers of
90 * <code>addPage(IEditorPart,IEditorInput)</code>, nested editors do not have
91 * their own contributors.
94 * @see org.eclipse.ui.part.MultiPageEditorActionBarContributor
96 * NOTE: this class was originally copied from MultiPageEditorPart and adapter to work as a ViewPart.
98 @SuppressWarnings({"restriction","deprecation","unchecked","rawtypes"})
99 public abstract class TabbedPropertyPage extends ViewPart {
102 * Subclasses that override {@link #createPageContainer(Composite)} can use
103 * this constant to get a site for the container that can be active while
104 * the current page is deactivated.
107 * @see #activateSite()
108 * @see #deactivateSite(boolean, boolean)
109 * @see #getPageSite(int)
111 protected static final int PAGE_CONTAINER_SITE = 65535;
114 * Private tracing output.
116 private static final String TRACING_COMPONENT = "MPE"; //$NON-NLS-1$
119 * The active service locator. This value may be <code>null</code> if
120 * there is no selected page, or if the selected page is a control with
123 private INestable activeServiceLocator;
126 * The container widget.
128 private CTabFolder container;
129 private Composite pageContainer;
132 * List of nested editors. Element type: IEditorPart. Need to hang onto them
133 * here, in addition to using get/setData on the items, because dispose()
134 * needs to access them, but widgetry has already been disposed at that
137 private final ArrayList nestedEditors = new ArrayList(3);
139 private final List pageSites = new ArrayList(3);
141 private IServiceLocator pageContainerSite;
144 * Creates and adds a new page containing the given control to this
145 * multi-page editor. The control may be <code>null</code>, allowing it
146 * to be created and set later using <code>setControl</code>.
149 * the control, or <code>null</code>
150 * @return the index of the new page
152 * @see MultiPageEditorPart#setControl(int, Control)
154 public int addPage(Control control) {
155 int index = getPageCount();
156 addPage(index, control);
161 * @param control the control to add as a page
162 * @param text the page title text
163 * @param image the page title image
166 public int addPage(Control control, String text, Image image) {
167 int result = addPage(control);
168 setPageText(result, text);
169 setPageImage(result, image);
174 * Creates and adds a new page containing the given control to this
175 * multi-page editor. The page is added at the given index. The control may
176 * be <code>null</code>, allowing it to be created and set later using
177 * <code>setControl</code>.
180 * the index at which to add the page (0-based)
182 * the control, or <code>null</code>
184 * @see MultiPageEditorPart#setControl(int, Control)
186 public void addPage(int index, Control control) {
187 createItem(index, control);
191 * Creates an empty container. Creates a CTabFolder with no style bits set,
192 * and hooks a selection listener which calls <code>pageChange()</code>
193 * whenever the selected tab changes.
196 * The composite in which the container tab folder should be
197 * created; must not be <code>null</code>.
198 * @return a new container
200 private CTabFolder createContainer(Composite parent) {
201 // use SWT.FLAT style so that an extra 1 pixel border is not reserved
203 parent.setLayout(new FillLayout());
204 final CTabFolder newContainer = new CTabFolder(parent, getContainerStyle());
205 newContainer.addSelectionListener(new SelectionAdapter() {
207 public void widgetSelected(SelectionEvent e) {
208 int newPageIndex = newContainer.indexOf((CTabItem) e.item);
209 pageChange(newPageIndex);
216 * Override this to customize the style given to the container
217 * {@link CTabFolder} instance created by
218 * {@link #createContainer(Composite)}. Default value is {@value SWT#BOTTOM}
219 * | {@value SWT#FLAT}.
221 * @return swt style mask for {@link CTabFolder}
223 protected int getContainerStyle() {
224 return SWT.BOTTOM | SWT.FLAT;
228 * Creates a tab item at the given index and places the given control in the
229 * new item. The item is a CTabItem with no style bits set.
232 * the index at which to add the control
234 * is the control to be placed in an item
237 private CTabItem createItem(int index, Control control) {
238 CTabItem item = new CTabItem(getTabFolder(), SWT.NONE, index);
239 item.setControl(control);
244 * Creates the pages of this multi-page editor.
246 * Subclasses must implement this method.
249 protected abstract void createPages();
252 * The <code>MultiPageEditor</code> implementation of this
253 * <code>IWorkbenchPart</code> method creates the control for the
254 * multi-page editor by calling <code>createContainer</code>, then
255 * <code>createPages</code>. Subclasses should implement
256 * <code>createPages</code> rather than overriding this method.
259 * The parent in which the editor should be created; must not be
263 public final void createPartControl(Composite parent) {
264 this.pageContainer = createPageContainer(parent);
265 this.container = createContainer(pageContainer);
267 // set the active page (page 0 by default), unless it has already been
269 if (getActivePage() == -1) {
271 IViewSite site = getViewSite();
273 final IServiceLocator serviceLocator = site;
274 if (serviceLocator instanceof INestable) {
275 activeServiceLocator = (INestable) serviceLocator;
276 activeServiceLocator.activate();
280 initializePageSwitching();
284 * Initialize the MultiPageEditorPart to use the page switching command.
285 * Clients can override this method with an empty body if they wish to
290 protected void initializePageSwitching() {
291 new PageSwitcher(getSite().getPart()) {
293 public Object[] getPages() {
294 int pageCount = getPageCount();
295 Object[] result = new Object[pageCount];
296 for (int i = 0; i < pageCount; i++) {
297 result[i] = new Integer(i);
303 public String getName(Object page) {
304 return getPageText(((Integer) page).intValue());
308 public ImageDescriptor getImageDescriptor(Object page) {
309 Image image = getPageImage(((Integer) page).intValue());
313 return ImageDescriptor.createFromImage(image);
317 public void activatePage(Object page) {
318 setActivePage(((Integer) page).intValue());
322 public int getCurrentPageIndex() {
323 return getActivePage();
329 * Creates the parent control for the container returned by
330 * {@link #getContainer() }.
333 * Subclasses may extend and must call super implementation first.
337 * the parent for all of the editors contents.
338 * @return the parent for this editor's container. Must not be
343 protected Composite createPageContainer(Composite parent) {
347 public Composite getPageContainer() {
348 return pageContainer;
352 * Creates the site for the given nested editor. The
353 * <code>MultiPageEditorPart</code> implementation of this method creates
354 * an instance of <code>MultiPageEditorSite</code>. Subclasses may
355 * reimplement to create more specialized sites.
359 * @return the editor site
361 protected IViewSite createSite(IViewPart editor) {
362 return new TabbedPropertyPageViewSite(this, editor);
366 * The <code>MultiPageEditorPart</code> implementation of this
367 * <code>IWorkbenchPart</code> method disposes all nested editors.
368 * Subclasses may extend.
371 public void dispose() {
372 for (int i = 0; i < nestedEditors.size(); ++i) {
373 IEditorPart editor = (IEditorPart) nestedEditors.get(i);
376 nestedEditors.clear();
377 if (pageContainerSite instanceof IDisposable) {
378 ((IDisposable) pageContainerSite).dispose();
379 pageContainerSite = null;
381 for (int i = 0; i < pageSites.size(); i++) {
382 IServiceLocator sl = (IServiceLocator) pageSites.get(i);
383 if (sl instanceof IDisposable) {
384 ((IDisposable) sl).dispose();
391 * Returns the active nested editor if there is one.
393 * Subclasses should not override this method
396 * @return the active nested editor, or <code>null</code> if none
398 protected IEditorPart getActiveEditor() {
399 int index = getActivePage();
401 return getEditor(index);
407 * Returns the index of the currently active page, or -1 if there is no
410 * Subclasses should not override this method
413 * @return the index of the active page, or -1 if there is no active page
415 protected int getActivePage() {
416 CTabFolder tabFolder = getTabFolder();
417 if (tabFolder != null && !tabFolder.isDisposed()) {
418 return tabFolder.getSelectionIndex();
424 * Returns the composite control containing this multi-page editor's pages.
425 * This should be used as the parent when creating controls for the
426 * individual pages. That is, when calling <code>addPage(Control)</code>,
427 * the passed control should be a child of this container.
429 * Warning: Clients should not assume that the container is any particular
430 * subclass of Composite. The actual class used may change in order to
431 * improve the look and feel of multi-page editors. Any code making
432 * assumptions on the particular subclass would thus be broken.
435 * Subclasses should not override this method
438 * @return the composite, or <code>null</code> if
439 * <code>createPartControl</code> has not been called yet
441 protected Composite getContainer() {
446 * Returns the control for the given page index, or <code>null</code> if
447 * no control has been set for the page. The page index must be valid.
449 * Subclasses should not override this method
453 * the index of the page
454 * @return the control for the specified page, or <code>null</code> if
457 protected Control getControl(int pageIndex) {
458 return getItem(pageIndex).getControl();
462 * Returns the editor for the given page index. The page index must be
466 * the index of the page
467 * @return the editor for the specified page, or <code>null</code> if the
468 * specified page was not created with
469 * <code>addPage(IEditorPart,IEditorInput)</code>
471 protected IEditorPart getEditor(int pageIndex) {
472 Item item = getItem(pageIndex);
474 Object data = item.getData();
475 if (data instanceof IEditorPart) {
476 return (IEditorPart) data;
483 * Returns the service locator for the given page index. This method can be
484 * used to create service locators for pages that are just controls. The
485 * page index must be valid.
487 * This will return the editor site service locator for an editor, and
488 * create one for a page that is just a control.
492 * the index of the page
493 * @return the editor for the specified page, or <code>null</code> if the
494 * specified page was not created with
495 * <code>addPage(IEditorPart,IEditorInput)</code>
498 protected final IServiceLocator getPageSite(int pageIndex) {
499 if (pageIndex == PAGE_CONTAINER_SITE) {
500 return getPageContainerSite();
503 Item item = getItem(pageIndex);
505 Object data = item.getData();
506 if (data instanceof IEditorPart) {
507 return ((IEditorPart) data).getSite();
508 } else if (data instanceof IServiceLocator) {
509 return (IServiceLocator) data;
510 } else if (data == null) {
511 IServiceLocatorCreator slc = (IServiceLocatorCreator) getSite()
512 .getService(IServiceLocatorCreator.class);
513 IServiceLocator sl = slc.createServiceLocator(getSite(), null, new IDisposable() {
515 public void dispose() {
516 // TODO Auto-generated method stub
528 * @return A site that can be used with a header.
530 * @see #createPageContainer(Composite)
531 * @see #PAGE_CONTAINER_SITE
532 * @see #getPageSite(int)
534 private IServiceLocator getPageContainerSite() {
535 if (pageContainerSite == null) {
536 IServiceLocatorCreator slc = (IServiceLocatorCreator) getSite()
537 .getService(IServiceLocatorCreator.class);
538 pageContainerSite = slc.createServiceLocator(getSite(), null, new IDisposable() {
540 public void dispose() {
541 // TODO Auto-generated method stub
545 return pageContainerSite;
549 * Returns the tab item for the given page index (page index is 0-based).
550 * The page index must be valid.
553 * the index of the page
554 * @return the tab item for the given page index
556 private CTabItem getItem(int pageIndex) {
557 return getTabFolder().getItem(pageIndex);
561 * Returns the number of pages in this multi-page editor.
563 * @return the number of pages
565 protected int getPageCount() {
566 CTabFolder folder = getTabFolder();
567 // May not have been created yet, or may have been disposed.
568 if (folder != null && !folder.isDisposed()) {
569 return folder.getItemCount();
575 * Returns the image for the page with the given index, or <code>null</code>
576 * if no image has been set for the page. The page index must be valid.
579 * the index of the page
580 * @return the image, or <code>null</code> if none
582 protected Image getPageImage(int pageIndex) {
583 return getItem(pageIndex).getImage();
587 * Returns the text label for the page with the given index. Returns the
588 * empty string if no text label has been set for the page. The page index
592 * the index of the page
593 * @return the text label for the page
595 protected String getPageText(int pageIndex) {
596 return getItem(pageIndex).getText();
600 * Returns the tab folder containing this multi-page editor's pages.
602 * @return the tab folder, or <code>null</code> if
603 * <code>createPartControl</code> has not been called yet
605 protected CTabFolder getTabFolder() {
610 * Handles a property change notification from a nested editor. The default
611 * implementation simply forwards the change to listeners on this multi-page
612 * editor by calling <code>firePropertyChange</code> with the same
613 * property id. For example, if the dirty state of a nested editor changes
614 * (property id <code>IEditorPart.PROP_DIRTY</code>), this method handles
615 * it by firing a property change event for
616 * <code>IEditorPart.PROP_DIRTY</code> to property listeners on this
619 * Subclasses may extend or reimplement this method.
623 * the id of the property that changed
625 protected void handlePropertyChange(int propertyId) {
626 firePropertyChange(propertyId);
630 * The <code>MultiPageEditorPart</code> implementation of this
631 * <code>IEditorPart</code> method sets its site to the given site, its
632 * input to the given input, and the site's selection provider to a
633 * <code>MultiPageSelectionProvider</code>. Subclasses may extend this
637 * The site for which this part is being created; must not be
640 * The input on which this editor should be created; must not be
642 * @throws PartInitException
643 * If the initialization of the part fails -- currently never.
646 public void init(IViewSite site, IMemento memento)
647 throws PartInitException {
649 site.setSelectionProvider(new TabbedPageSelectionProvider(this));
653 * Notifies this multi-page editor that the page with the given id has been
654 * activated. This method is called when the user selects a different tab.
656 * The <code>MultiPageEditorPart</code> implementation of this method sets
657 * focus to the new page, and notifies the action bar contributor (if there
658 * is one). This checks whether the action bar contributor is an instance of
659 * <code>MultiPageEditorActionBarContributor</code>, and, if so, calls
660 * <code>setActivePage</code> with the active nested editor. This also
661 * fires a selection change event if required.
664 * Subclasses may extend this method.
667 * @param newPageIndex
668 * the index of the activated page
670 protected void pageChange(int newPageIndex) {
671 deactivateSite(false, false);
673 IPartService partService = (IPartService) getSite().getService(
675 if (partService != null && partService.getActivePart() == this) {
676 setFocus(newPageIndex);
679 IEditorPart activeEditor = getEditor(newPageIndex);
681 // IEditorActionBarContributor contributor = getViewSite()
682 // .getActionBarContributor();
683 // if (contributor != null
684 // && contributor instanceof MultiPageEditorActionBarContributor) {
685 // ((MultiPageEditorActionBarContributor) contributor)
686 // .setActivePage(activeEditor);
689 if (activeEditor != null) {
690 ISelectionProvider selectionProvider = activeEditor.getSite()
691 .getSelectionProvider();
692 if (selectionProvider != null) {
693 ISelectionProvider outerProvider = getSite()
694 .getSelectionProvider();
695 if (outerProvider instanceof MultiPageSelectionProvider) {
696 SelectionChangedEvent event = new SelectionChangedEvent(
697 selectionProvider, selectionProvider.getSelection());
699 MultiPageSelectionProvider provider = (MultiPageSelectionProvider) outerProvider;
700 provider.fireSelectionChanged(event);
701 provider.firePostSelectionChanged(event);
703 if (Policy.DEBUG_MPE) {
704 Tracing.printTrace(TRACING_COMPONENT,
705 "MultiPageEditorPart " + getTitle() //$NON-NLS-1$
706 + " did not propogate selection for " //$NON-NLS-1$
707 + activeEditor.getTitle());
717 * This method can be used by implementors of
718 * {@link MultiPageEditorPart#createPageContainer(Composite)} to deactivate
719 * the active inner editor services while their header has focus. A
720 * deactivateSite() must have a matching call to activateSite() when
723 * An new inner editor will have its site activated on a
724 * {@link MultiPageEditorPart#pageChange(int)}.
727 * <b>Note:</b> This API is evolving in 3.4 and this might not be its final
732 * immediately deactivate the legacy keybinding service
733 * @param containerSiteActive
734 * Leave the page container site active.
736 * @see #activateSite()
737 * @see #createPageContainer(Composite)
738 * @see #getPageSite(int)
739 * @see #PAGE_CONTAINER_SITE
741 protected final void deactivateSite(boolean immediate,
742 boolean containerSiteActive) {
743 // Deactivate the nested services from the last active service locator.
744 if (activeServiceLocator != null) {
745 activeServiceLocator.deactivate();
746 activeServiceLocator = null;
749 final int pageIndex = getActivePage();
750 final IKeyBindingService service = getSite().getKeyBindingService();
751 if (pageIndex < 0 || pageIndex >= getPageCount() || immediate) {
752 // There is no selected page, so deactivate the active service.
753 if (service instanceof INestableKeyBindingService) {
754 final INestableKeyBindingService nestableService = (INestableKeyBindingService) service;
755 nestableService.activateKeyBindingService(null);
758 .log("MultiPageEditorPart.setFocus() Parent key binding service was not an instance of INestableKeyBindingService. It was an instance of " + service.getClass().getName() + " instead."); //$NON-NLS-1$ //$NON-NLS-2$
762 if (containerSiteActive) {
763 IServiceLocator containerSite = getPageContainerSite();
764 if (containerSite instanceof INestable) {
765 activeServiceLocator = (INestable) containerSite;
766 activeServiceLocator.activate();
772 * This method can be used by implementors of
773 * {@link #createPageContainer(Composite)} to activate the active inner
774 * editor services when their header loses focus.
776 * An new inner editor will have its site activated on a
777 * {@link #pageChange(int)}.
780 * <b>Note:</b> This API is evolving in 3.4 and this might not be its final
785 * @see #deactivateSite(boolean,boolean)
786 * @see #createPageContainer(Composite)
787 * @see #getPageSite(int)
789 protected final void activateSite() {
790 if (activeServiceLocator != null) {
791 activeServiceLocator.deactivate();
792 activeServiceLocator = null;
795 final IKeyBindingService service = getSite().getKeyBindingService();
796 final int pageIndex = getActivePage();
797 final IEditorPart editor = getEditor(pageIndex);
799 if (editor != null) {
800 // active the service for this inner editor
801 if (service instanceof INestableKeyBindingService) {
802 final INestableKeyBindingService nestableService = (INestableKeyBindingService) service;
803 nestableService.activateKeyBindingService(editor
808 .log("MultiPageEditorPart.setFocus() Parent key binding service was not an instance of INestableKeyBindingService. It was an instance of " + service.getClass().getName() + " instead."); //$NON-NLS-1$ //$NON-NLS-2$
810 // Activate the services for the new service locator.
811 final IServiceLocator serviceLocator = editor.getEditorSite();
812 if (serviceLocator instanceof INestable) {
813 activeServiceLocator = (INestable) serviceLocator;
814 activeServiceLocator.activate();
818 Item item = getItem(pageIndex);
820 // There is no selected editor, so deactivate the active service.
821 if (service instanceof INestableKeyBindingService) {
822 final INestableKeyBindingService nestableService = (INestableKeyBindingService) service;
823 nestableService.activateKeyBindingService(null);
826 .log("MultiPageEditorPart.setFocus() Parent key binding service was not an instance of INestableKeyBindingService. It was an instance of " + service.getClass().getName() + " instead."); //$NON-NLS-1$ //$NON-NLS-2$
829 if (item.getData() instanceof INestable) {
830 activeServiceLocator = (INestable) item.getData();
831 activeServiceLocator.activate();
837 * Disposes the given part and its site.
840 * The part to dispose; must not be <code>null</code>.
842 private void disposePart(final IWorkbenchPart part) {
843 SafeRunner.run(new ISafeRunnable() {
845 IWorkbenchPartSite partSite = part.getSite();
847 if (partSite instanceof MultiPageEditorSite) {
848 ((MultiPageEditorSite) partSite).dispose();
852 public void handleException(Throwable e) {
853 // Exception has already being logged by Core. Do nothing.
859 * Removes the page with the given index from this multi-page editor. The
860 * controls for the page are disposed of; if the page has an editor, it is
861 * disposed of too. The page index must be valid.
864 * the index of the page
865 * @see MultiPageEditorPart#addPage(Control)
866 * @see MultiPageEditorPart#addPage(IEditorPart, IEditorInput)
868 public void removePage(int pageIndex) {
869 Assert.isTrue(pageIndex >= 0 && pageIndex < getPageCount());
870 // get editor (if any) before disposing item
871 IEditorPart editor = getEditor(pageIndex);
873 // get control for the item if it's not an editor
874 CTabItem item = getItem(pageIndex);
875 IServiceLocator pageLocator = null;
876 if (item.getData() instanceof IServiceLocator) {
877 pageLocator = (IServiceLocator) item.getData();
879 Control pageControl = item.getControl();
881 // dispose item before disposing editor, in case there's an exception
882 // in editor's dispose
885 if (pageControl != null) {
886 pageControl.dispose();
889 // dispose editor (if any)
890 if (editor != null) {
891 nestedEditors.remove(editor);
894 if (pageLocator != null) {
895 pageSites.remove(pageLocator);
896 if (pageLocator instanceof IDisposable) {
897 ((IDisposable) pageLocator).dispose();
903 * Sets the currently active page.
906 * the index of the page to be activated; the index must be valid
908 protected void setActivePage(int pageIndex) {
909 Assert.isTrue(pageIndex >= 0 && pageIndex < getPageCount());
910 getTabFolder().setSelection(pageIndex);
911 pageChange(pageIndex);
915 * Sets the control for the given page index. The page index must be valid.
918 * the index of the page
920 * the control for the specified page, or <code>null</code> to
923 protected void setControl(int pageIndex, Control control) {
924 getItem(pageIndex).setControl(control);
928 * The <code>MultiPageEditor</code> implementation of this
929 * <code>IWorkbenchPart</code> method sets focus on the active nested
930 * editor, if there is one.
932 * Subclasses may extend or reimplement.
936 public void setFocus() {
937 setFocus(getActivePage());
941 * Sets focus to the control for the given page. If the page has an editor,
942 * this calls its <code>setFocus()</code> method. Otherwise, this calls
943 * <code>setFocus</code> on the control for the page.
946 * the index of the page
948 private void setFocus(int pageIndex) {
949 final IEditorPart editor = getEditor(pageIndex);
950 if (editor != null) {
954 // Give the page's control focus.
955 final Control control = getControl(pageIndex);
956 if (control != null) {
963 * Sets the image for the page with the given index, or <code>null</code>
964 * to clear the image for the page. The page index must be valid.
967 * the index of the page
969 * the image, or <code>null</code>
971 protected void setPageImage(int pageIndex, Image image) {
972 getItem(pageIndex).setImage(image);
976 * Sets the text label for the page with the given index. The page index
977 * must be valid. The text label must not be null.
980 * the index of the page
984 protected void setPageText(int pageIndex, String text) {
985 getItem(pageIndex).setText(text);
989 * If there is an adapter registered against the subclass of
990 * MultiPageEditorPart return that. Otherwise, delegate to the internal
993 * @see org.eclipse.ui.part.WorkbenchPart#getAdapter(java.lang.Class)
996 public Object getAdapter(Class adapter) {
997 Object result = super.getAdapter(adapter);
998 // restrict delegating to the UI thread for bug 144851
999 if (result == null && Display.getCurrent()!=null) {
1000 IEditorPart innerEditor = getActiveEditor();
1001 // see bug 138823 - prevent some subclasses from causing
1003 if (innerEditor != null && innerEditor != this) {
1004 result = Util.getAdapter(innerEditor, adapter);
1011 // * Find the editors contained in this multi-page editor
1012 // * whose editor input match the provided input.
1013 // * @param input the editor input
1014 // * @return the editors contained in this multi-page editor
1015 // * whose editor input match the provided input
1018 // public final IEditorPart[] findEditors(IEditorInput input) {
1019 // List result = new ArrayList();
1020 // int count = getPageCount();
1021 // for (int i = 0; i < count; i++) {
1022 // IEditorPart editor = getEditor(i);
1023 // if (editor != null
1024 // && editor.getEditorInput() != null
1025 // && editor.getEditorInput().equals(input)) {
1026 // result.add(editor);
1029 // return (IEditorPart[]) result.toArray(new IEditorPart[result.size()]);
1033 // * Set the active page of this multi-page editor to the
1034 // * page that contains the given editor part. This method has
1035 // * no effect of the given editor part is not contained in this
1036 // * multi-page editor.
1037 // * @param editorPart the editor part
1040 // public final void setActiveEditor(IEditorPart editorPart) {
1041 // int count = getPageCount();
1042 // for (int i = 0; i < count; i++) {
1043 // IEditorPart editor = getEditor(i);
1044 // if (editor == editorPart) {
1045 // setActivePage(i);
1051 // private IViewPart part;
1053 // public IViewSite getSite() {
1054 // return part.getViewSite();
1057 // public IViewPart getPart() {
1063 public IViewSite getViewSite() {
1064 if(part instanceof IViewPart) return ((IViewPart) part).getViewSite();
1069 public IWorkbenchPartSite getSite() {
1070 return part.getSite();
1073 IWorkbenchPart part;
1075 public TabbedPropertyPage(IWorkbenchPart part) {
1077 // Given part may be null
1078 // assert(part != null);
1079 // setSite(part.getSite());