/** * The workbench part creates this instance of the TabbedPropertySheetPage and implements * ITabbedPropertySheetPageContributor which is unique contributor id. This unique contributor id * is used to load a registry with the extension point This id matches the registry. * * <p>It is possible for elements in a selection to implement ITabbedPropertySheetPageContributor * to provide a different contributor id and thus a differenent registry. * * @param selection the current selection in the active workbench part. */ protected void validateRegistry(final ISelection selection) { if (selection == null) { return; } if (!(selection instanceof IStructuredSelection)) { return; } final IStructuredSelection structuredSelection = (IStructuredSelection) selection; if (structuredSelection.size() == 0) { return; } ITabbedPropertySheetPageContributor newContributor = getTabbedPropertySheetPageContributor(structuredSelection.getFirstElement()); if (newContributor == null) { /** selection does not implement or adapt ITabbedPropertySheetPageContributor. */ newContributor = contributor; } final String selectionContributorId = newContributor.getContributorId(); if (selectionContributorId.equals(currentContributorId)) { /** selection has the same contributor id as current, so leave existing registry. */ return; } /** * Selection implements ITabbedPropertySheetPageContributor different than current contributor * id, so make sure all elements implement the new id. If all contributor id do not match, then * fall back to default contributor from the workbench part. */ final Iterator i = structuredSelection.iterator(); i.next(); while (i.hasNext()) { newContributor = getTabbedPropertySheetPageContributor(i.next()); if (newContributor == null || !newContributor.getContributorId().equals(selectionContributorId)) { /** fall back to use the default contributor id from the workbench part. */ if (selectionContributor != null) { disposeContributor(); currentContributorId = contributor.getContributorId(); initContributor(currentContributorId); } return; } } /** All the elements in the selection implement a new contributor id, so use that id. */ disposeContributor(); currentContributorId = selectionContributorId; initContributor(currentContributorId); overrideActionBars(); }
/** * create a new tabbed property sheet page. * * @param tabbedPropertySheetPageContributor the tabbed property sheet page contributor. * @param showTitleBar boolean indicating if the title bar should be shown; default value is * <code>true</code> * @since 3.5 */ public TabbedPropertySheetPage( final ITabbedPropertySheetPageContributor tabbedPropertySheetPageContributor, final boolean showTitleBar) { hasTitleBar = showTitleBar; contributor = tabbedPropertySheetPageContributor; tabToComposite = new HashMap(); selectionQueue = new ArrayList(10); tabSelectionListeners = new ArrayList(); initContributor(contributor.getContributorId()); }
/** * Handle the part activated event. * * @param part the new activated part. */ protected void handlePartActivated(final IWorkbenchPart part) { /* * The properties view has been activated and the current page is this * instance of TabbedPropertySheetPage */ final boolean thisActivated = part instanceof PropertySheet && ((PropertySheet) part).getCurrentPage() == this; /* * When the active part changes and the part does not provide a * selection that affects this property sheet page, the PropertySheet * does not send us a selectionChanged() event. We need to be informed * of these events since we want to send aboutToBeHidden() and * aboutToBeShown() when the property sheet is hidden or shown. */ if (!thisActivated && !part.equals(contributor) && !part.getSite().getId().equals(contributor.getContributorId())) { /* * Is the part is a IContributedContentsView for the contributor, * for example, outline view. */ final IContributedContentsView view = (IContributedContentsView) part.getAdapter(IContributedContentsView.class); if (view == null || view.getContributingPart() != null && !view.getContributingPart().equals(contributor)) { if (activePropertySheet) { if (currentTab != null) { currentTab.aboutToBeHidden(); } activePropertySheet = false; } return; } } if (!activePropertySheet && currentTab != null) { currentTab.aboutToBeShown(); currentTab.refresh(); } activePropertySheet = true; }
/** * Initialize the contributor with the provided contributor id. * * @param contributorId the contributor id. */ private void initContributor(final String contributorId) { descriptorToTab = new HashMap(); if (contributor.getContributorId().equals(contributorId)) { /** default contributor from the workbench part. */ registry = TabbedPropertyRegistryFactory.getInstance().createRegistry(contributor); } else { /** selection contributor. */ selectionContributor = new TabbedPropertySheetPageContributorFromSelection(contributorId); registry = TabbedPropertyRegistryFactory.getInstance().createRegistry(selectionContributor); } currentContributorId = contributorId; tabListContentProvider = getTabListContentProvider(); hasTitleBar = hasTitleBar && registry.getLabelProvider() != null; if (tabbedPropertyViewer != null) { tabbedPropertyViewer.setContentProvider(tabListContentProvider); } /** Add a label provider change listener. */ if (hasTitleBar) { registry.getLabelProvider().addListener(this); } }