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.selectionview;
14 import org.eclipse.jface.viewers.ISelection;
15 import org.eclipse.ui.IPartListener;
16 import org.eclipse.ui.IWorkbenchPage;
17 import org.eclipse.ui.IWorkbenchPart;
18 import org.eclipse.ui.IWorkbenchPartSite;
19 import org.eclipse.ui.part.Page;
20 import org.simantics.ui.workbench.IPropertyPage;
24 * Subclasses must implement the following methods:
26 * <li><code>createControl</code> - to create the page's control</li>
27 * <li><code>getControl</code> - to retrieve the page's control</li>
28 * <li><code>getSelection</code> - to retrieve the page's current selection</li>
29 * <li><code>setFocus</code> - implement to accept focus</li>
30 * <li><code>sourceSelectionChanged</code> - puts the incoming ISelection into use in this page</li>
31 * <li><code>sourcePartClosed</code> - cleans up the page controls after a current selection source part has been closed</li>
35 * Subclasses may extend or reimplement the following methods as required:
37 * <li><code>dispose</code> - extend to provide additional cleanup</li>
38 * <li><code>setActionBars</code> - reimplement to make contributions</li>
39 * <li><code>makeContributions</code> - this method exists to support previous versions</li>
40 * <li><code>setActionBars</code> - this method exists to support previous versions</li>
41 * <li><code>init</code> - extend to provide additional setup</li>
45 * @author Tuukka Lehtonen
47 public abstract class AbstractPropertyPage extends Page implements IPropertyPage {
50 * Part listener which cleans up this page when the source part is closed.
51 * This is hooked only when there is a source part.
53 private class PartListener implements IPartListener {
54 public void partActivated(IWorkbenchPart part) {
57 public void partBroughtToTop(IWorkbenchPart part) {
60 public void partClosed(IWorkbenchPart part) {
61 if (sourcePart == part) {
63 sourcePartClosed(part);
67 public void partDeactivated(IWorkbenchPart part) {
70 public void partOpened(IWorkbenchPart part) {
74 private final PartListener partListener = new PartListener();
76 protected IWorkbenchPartSite sourceSite;
78 protected IWorkbenchPart sourcePart;
81 * @param sourceSite the workbench part site that produces this page or
82 * <code>null</code> if there is no site, i.e. the page is within a
83 * dialog or a plain shell.
85 public AbstractPropertyPage(IWorkbenchPartSite sourceSite) {
87 this.sourceSite = sourceSite;
91 public void dispose() {
94 if (sourcePart != null) {
95 sourcePart.getSite().getPage().removePartListener(partListener);
104 public void selectionChanged(IWorkbenchPart part, ISelection selection) {
105 if (getControl() == null) {
109 if (sourcePart != null) {
110 sourcePart.getSite().getPage().removePartListener(partListener);
114 // change the viewer input since the workbench selection has changed.
116 sourceSelectionChanged(selection);
118 if (sourcePart != null) {
119 IWorkbenchPartSite site = sourcePart.getSite();
121 new Exception("null site").printStackTrace();
124 IWorkbenchPage page = site.getPage();
126 new Exception("null page").printStackTrace();
129 page.addPartListener(partListener);
136 protected abstract void sourceSelectionChanged(ISelection selection);
141 protected abstract void sourcePartClosed(IWorkbenchPart part);