/******************************************************************************* * Copyright (c) 2007, 2010 Association for Decentralized Information Management * in Industry THTH ry. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * VTT Technical Research Centre of Finland - initial API and implementation *******************************************************************************/ package org.simantics.selectionview; import org.eclipse.jface.viewers.ISelection; import org.eclipse.ui.IPartListener; import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.IWorkbenchPart; import org.eclipse.ui.IWorkbenchPartSite; import org.eclipse.ui.part.Page; import org.simantics.ui.workbench.IPropertyPage; /** *
* Subclasses must implement the following methods: *
createControl
- to create the page's controlgetControl
- to retrieve the page's controlgetSelection
- to retrieve the page's current selectionsetFocus
- implement to accept focussourceSelectionChanged
- puts the incoming ISelection into use in this pagesourcePartClosed
- cleans up the page controls after a current selection source part has been closed* Subclasses may extend or reimplement the following methods as required: *
dispose
- extend to provide additional cleanupsetActionBars
- reimplement to make contributionsmakeContributions
- this method exists to support previous versionssetActionBars
- this method exists to support previous versionsinit
- extend to provide additional setupnull
if there is no site, i.e. the page is within a
* dialog or a plain shell.
*/
public AbstractPropertyPage(IWorkbenchPartSite sourceSite) {
super();
this.sourceSite = sourceSite;
}
@Override
public void dispose() {
super.dispose();
if (sourcePart != null) {
sourcePart.getSite().getPage().removePartListener(partListener);
sourcePart = null;
}
sourceSite = null;
}
@Override
public void selectionChanged(IWorkbenchPart part, ISelection selection) {
if (getControl() == null) {
return;
}
if (sourcePart != null) {
sourcePart.getSite().getPage().removePartListener(partListener);
sourcePart = null;
}
// change the viewer input since the workbench selection has changed.
sourcePart = part;
sourceSelectionChanged(selection);
if (sourcePart != null) {
IWorkbenchPartSite site = sourcePart.getSite();
if(site == null) {
new Exception("null site").printStackTrace();
return;
}
IWorkbenchPage page = site.getPage();
if(page == null) {
new Exception("null page").printStackTrace();
return;
}
page.addPartListener(partListener);
}
}
/**
* @param selection
*/
protected abstract void sourceSelectionChanged(ISelection selection);
/**
* @param part
*/
protected abstract void sourcePartClosed(IWorkbenchPart part);
}