| /******************************************************************************* |
| * Copyright (c) 2016 ALL4TEC & CEA LIST. |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License 2.0 |
| * which accompanies this distribution, and is available at |
| * https://www.eclipse.org/legal/epl-2.0/ |
| * |
| * SPDX-License-Identifier: EPL-2.0 |
| * |
| * Contributors: |
| * ALL4TEC & CEA LIST - initial API and implementation |
| ******************************************************************************/ |
| package org.polarsys.esf.core.common.ui.view; |
| |
| import org.eclipse.emf.common.ui.viewer.IViewerProvider; |
| import org.eclipse.emf.edit.domain.EditingDomain; |
| import org.eclipse.emf.edit.domain.IEditingDomainProvider; |
| import org.eclipse.jface.viewers.Viewer; |
| import org.eclipse.ui.IEditorPart; |
| import org.eclipse.ui.IWorkbenchPage; |
| import org.eclipse.ui.IWorkbenchPart; |
| import org.eclipse.ui.part.IPage; |
| import org.eclipse.ui.part.MessagePage; |
| import org.eclipse.ui.part.PageBook; |
| import org.eclipse.ui.part.PageBookView; |
| import org.polarsys.esf.core.common.ui.CommonUIActivator; |
| import org.polarsys.esf.core.common.ui.filter.IFilterPartListener; |
| |
| /** |
| * Abstract base for the views which are looking at the content of an ESF Model |
| * opened in any type of editor (Graphical, EMF tree table, etc.). |
| * |
| * These views are also listening to the changes on the filter to adapt the content |
| * of their pages. |
| * |
| * Moreover, they must implements the interface IEditingDomainProvider to return the editing |
| * domain used by the current page. This is mandatory to enable the actions activation with |
| * the action bars contributor. |
| * To enable the refresh contextual action, the view must provide a viewer, and implements |
| * the IViewerProvider interface. The viewer search is delegated to the current page. |
| * |
| * @author $Author: jdumont $ |
| * @version $Revision: 83 $ |
| */ |
| public abstract class AbstractModelPageBookView |
| extends PageBookView |
| implements IFilterPartListener, IEditingDomainProvider, IViewerProvider { |
| |
| /** Message to show on the default page. */ |
| private static final String DEFAULT_TEXT = CommonUIActivator.getMessages() |
| .getString("AbstractSAModelPageBookView.defaultPage.label"); //$NON-NLS-1$ |
| |
| /** |
| * Default constructor. |
| */ |
| public AbstractModelPageBookView() { |
| super(); |
| } |
| |
| /** |
| * {@inheritDoc} |
| * |
| * The default page displays only a message to warn the user that |
| * he must open an editor to link a new page to its content. |
| */ |
| @Override |
| protected IPage createDefaultPage(final PageBook pBook) { |
| |
| // Create the default page, which will contains only an information message |
| MessagePage vPage = new MessagePage(); |
| |
| // Initialise the page and create its controls |
| initPage(vPage); |
| vPage.createControl(pBook); |
| |
| // Set the default message to the page |
| vPage.setMessage(DEFAULT_TEXT); |
| |
| return vPage; |
| } |
| |
| /** |
| * {@inheritDoc} |
| * |
| * Track only the editors to synchronise the view pages. |
| */ |
| @Override |
| protected boolean isImportant(final IWorkbenchPart pPart) { |
| // Only cares about editors |
| return pPart instanceof IEditorPart; |
| } |
| |
| /** |
| * {@inheritDoc} |
| */ |
| @Override |
| protected void doDestroyPage(final IWorkbenchPart pPart, final PageRec pPageRec) { |
| // Get the page from the page record |
| IPage vPage = pPageRec.page; |
| |
| // Dispose the page, and the record |
| vPage.dispose(); |
| pPageRec.dispose(); |
| } |
| |
| /** |
| * {@inheritDoc} |
| * |
| * Return the active editor for the current page. |
| */ |
| @Override |
| protected IWorkbenchPart getBootstrapPart() { |
| IWorkbenchPart vBootStrapPart = null; |
| |
| // Get the current page shown |
| IWorkbenchPage vPage = getSite().getPage(); |
| if (vPage != null) { |
| // Get the active editor linked to this page |
| vBootStrapPart = vPage.getActiveEditor(); |
| } |
| |
| return vBootStrapPart; |
| } |
| |
| /** |
| * {@inheritDoc} |
| * |
| * Treat this event as a part activation. |
| * Otherwise, nothing is done by default. |
| */ |
| @Override |
| public void partBroughtToTop(final IWorkbenchPart pPart) { |
| partActivated(pPart); |
| } |
| |
| /** |
| * {@inheritDoc} |
| * |
| * This method is overridden to register this current page book view as selection provider |
| * in the page action bar contributor, to enable the contextual actions. |
| * |
| * This must be done on each activation, and not only once when the page is initialised, |
| * as in this case, the {@link #getEditingDomain()} method will be called only once, and |
| * the actions won't be linked to the right editing domain. |
| */ |
| @Override |
| public void partActivated(final IWorkbenchPart pPart) { |
| // Call the parent method |
| super.partActivated(pPart); |
| |
| // If the current page in a instance of model page, update its action bar contributor |
| // to use this view as selection listener |
| if (getCurrentPage() instanceof AbstractModelPage) { |
| ((AbstractModelPage) getCurrentPage()).updateActionBarContributorActivePart(this); |
| } |
| } |
| |
| /** |
| * {@inheritDoc} |
| * |
| * For a page book view, the event treatment is delegated to the current page. |
| */ |
| @Override |
| public void filterTextChanged(final String pNewFilterText) { |
| IPage vCurrentPage = getCurrentPage(); |
| |
| if (vCurrentPage instanceof AbstractModelPage) { |
| ((AbstractModelPage) vCurrentPage).filterTextChanged(pNewFilterText); |
| } |
| } |
| |
| /** |
| * {@inheritDoc} |
| * |
| * Return the editing domain of the current page displayed. |
| */ |
| @Override |
| public EditingDomain getEditingDomain() { |
| |
| EditingDomain vEditingDomain = null; |
| |
| // Delegate the editing domain providing to the current page |
| if (getCurrentPage() instanceof IEditingDomainProvider) { |
| vEditingDomain = ((IEditingDomainProvider) getCurrentPage()).getEditingDomain(); |
| } |
| |
| return vEditingDomain; |
| } |
| |
| /** |
| * {@inheritDoc} |
| * |
| * Return the viewer current page displayed if possible, null otherwise. |
| */ |
| @Override |
| public Viewer getViewer() { |
| |
| Viewer vViewer = null; |
| |
| // Delegate the viewer providing to the current page |
| if (getCurrentPage() instanceof IViewerProvider) { |
| vViewer = ((IViewerProvider) getCurrentPage()).getViewer(); |
| } |
| |
| return vViewer; |
| } |
| } |