| /*=============================================================================# |
| # Copyright (c) 2012, 2020 Stephan Wahlbrink and others. |
| # |
| # This program and the accompanying materials are made available under the |
| # terms of the Eclipse Public License 2.0 which is available at |
| # https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 |
| # which is available at https://www.apache.org/licenses/LICENSE-2.0. |
| # |
| # SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 |
| # |
| # Contributors: |
| # Stephan Wahlbrink <sw@wahlbrink.eu> - initial API and implementation |
| #=============================================================================*/ |
| |
| package org.eclipse.statet.base.ui.contentfilter; |
| |
| import org.eclipse.ui.IEditorPart; |
| import org.eclipse.ui.IWorkbenchPage; |
| import org.eclipse.ui.IWorkbenchPart; |
| import org.eclipse.ui.part.IContributedContentsView; |
| import org.eclipse.ui.part.IPage; |
| import org.eclipse.ui.part.MessagePage; |
| import org.eclipse.ui.part.PageBook; |
| import org.eclipse.ui.part.PageBookView; |
| |
| |
| public class FilterView extends PageBookView { |
| |
| |
| public static final String VIEW_ID = "org.eclipse.statet.workbench.views.ContentFilter"; //$NON-NLS-1$ |
| |
| |
| public FilterView() { |
| super(); |
| } |
| |
| |
| @Override |
| protected IPage createDefaultPage(final PageBook book) { |
| final MessagePage page = new MessagePage(); |
| initPage(page); |
| page.createControl(book); |
| page.setMessage("No data source available"); |
| |
| initPage(page); |
| page.createControl(book); |
| |
| return page; |
| } |
| |
| @Override |
| protected PageRec doCreatePage(final IWorkbenchPart part) { |
| final IFilterPage page = part.getAdapter(IFilterPage.class); |
| if (page != null) { |
| initPage(page); |
| page.createControl(getPageBook()); |
| return new PageRec(part, page); |
| } |
| return null; |
| } |
| |
| @Override |
| protected void doDestroyPage(final IWorkbenchPart part, final PageRec rec) { |
| final IFilterPage page = (IFilterPage) rec.page; |
| page.dispose(); |
| rec.dispose(); |
| } |
| |
| @Override |
| @SuppressWarnings("unchecked") |
| public <T> T getAdapter(final Class<T> adapterType) { |
| if (adapterType == IContributedContentsView.class) { |
| return (T) new IContributedContentsView() { |
| @Override |
| public IWorkbenchPart getContributingPart() { |
| return getContributingEditor(); |
| } |
| }; |
| } |
| return super.getAdapter(adapterType); |
| } |
| |
| @Override |
| protected IWorkbenchPart getBootstrapPart() { |
| final IWorkbenchPage page = getSite().getPage(); |
| if (page != null) { |
| return page.getActiveEditor(); |
| } |
| return null; |
| } |
| |
| private IWorkbenchPart getContributingEditor() { |
| return getCurrentContributingPart(); |
| } |
| |
| @Override |
| protected boolean isImportant(final IWorkbenchPart part) { |
| return (part instanceof IEditorPart); |
| } |
| |
| @Override |
| public void partBroughtToTop(final IWorkbenchPart part) { |
| partActivated(part); |
| } |
| |
| } |