1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
\r
3 * in Industry THTH ry.
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.selectionview;
\r
14 import org.eclipse.jface.viewers.ISelection;
\r
15 import org.eclipse.ui.IPartListener;
\r
16 import org.eclipse.ui.IWorkbenchPage;
\r
17 import org.eclipse.ui.IWorkbenchPart;
\r
18 import org.eclipse.ui.IWorkbenchPartSite;
\r
19 import org.eclipse.ui.part.Page;
\r
20 import org.simantics.ui.workbench.IPropertyPage;
\r
24 * Subclasses must implement the following methods:
\r
26 * <li><code>createControl</code> - to create the page's control</li>
\r
27 * <li><code>getControl</code> - to retrieve the page's control</li>
\r
28 * <li><code>getSelection</code> - to retrieve the page's current selection</li>
\r
29 * <li><code>setFocus</code> - implement to accept focus</li>
\r
30 * <li><code>sourceSelectionChanged</code> - puts the incoming ISelection into use in this page</li>
\r
31 * <li><code>sourcePartClosed</code> - cleans up the page controls after a current selection source part has been closed</li>
\r
35 * Subclasses may extend or reimplement the following methods as required:
\r
37 * <li><code>dispose</code> - extend to provide additional cleanup</li>
\r
38 * <li><code>setActionBars</code> - reimplement to make contributions</li>
\r
39 * <li><code>makeContributions</code> - this method exists to support previous versions</li>
\r
40 * <li><code>setActionBars</code> - this method exists to support previous versions</li>
\r
41 * <li><code>init</code> - extend to provide additional setup</li>
\r
45 * @author Tuukka Lehtonen
\r
47 public abstract class AbstractPropertyPage extends Page implements IPropertyPage {
\r
50 * Part listener which cleans up this page when the source part is closed.
\r
51 * This is hooked only when there is a source part.
\r
53 private class PartListener implements IPartListener {
\r
54 public void partActivated(IWorkbenchPart part) {
\r
57 public void partBroughtToTop(IWorkbenchPart part) {
\r
60 public void partClosed(IWorkbenchPart part) {
\r
61 if (sourcePart == part) {
\r
63 sourcePartClosed(part);
\r
67 public void partDeactivated(IWorkbenchPart part) {
\r
70 public void partOpened(IWorkbenchPart part) {
\r
74 private final PartListener partListener = new PartListener();
\r
76 protected IWorkbenchPartSite sourceSite;
\r
78 protected IWorkbenchPart sourcePart;
\r
81 * @param sourceSite the workbench part site that produces this page or
\r
82 * <code>null</code> if there is no site, i.e. the page is within a
\r
83 * dialog or a plain shell.
\r
85 public AbstractPropertyPage(IWorkbenchPartSite sourceSite) {
\r
87 this.sourceSite = sourceSite;
\r
91 public void dispose() {
\r
94 if (sourcePart != null) {
\r
95 sourcePart.getSite().getPage().removePartListener(partListener);
\r
104 public void selectionChanged(IWorkbenchPart part, ISelection selection) {
\r
105 if (getControl() == null) {
\r
109 if (sourcePart != null) {
\r
110 sourcePart.getSite().getPage().removePartListener(partListener);
\r
114 // change the viewer input since the workbench selection has changed.
\r
116 sourceSelectionChanged(selection);
\r
118 if (sourcePart != null) {
\r
119 IWorkbenchPartSite site = sourcePart.getSite();
\r
121 new Exception("null site").printStackTrace();
\r
124 IWorkbenchPage page = site.getPage();
\r
126 new Exception("null page").printStackTrace();
\r
129 page.addPartListener(partListener);
\r
136 protected abstract void sourceSelectionChanged(ISelection selection);
\r
141 protected abstract void sourcePartClosed(IWorkbenchPart part);
\r