X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.selectionview%2Fsrc%2Forg%2Fsimantics%2Fselectionview%2FAbstractPropertyPage.java;h=430f59fa38afc2bd1b03e05a62ed0700584584bb;hp=7d7c015986c4a683417444fb4ff3a76712b7c8ad;hb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;hpb=24e2b34260f219f0d1644ca7a138894980e25b14 diff --git a/bundles/org.simantics.selectionview/src/org/simantics/selectionview/AbstractPropertyPage.java b/bundles/org.simantics.selectionview/src/org/simantics/selectionview/AbstractPropertyPage.java index 7d7c01598..430f59fa3 100644 --- a/bundles/org.simantics.selectionview/src/org/simantics/selectionview/AbstractPropertyPage.java +++ b/bundles/org.simantics.selectionview/src/org/simantics/selectionview/AbstractPropertyPage.java @@ -1,143 +1,143 @@ -/******************************************************************************* - * 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: - *

- *

- *

- * Subclasses may extend or reimplement the following methods as required: - *

- *

- * - * @author Tuukka Lehtonen - */ -public abstract class AbstractPropertyPage extends Page implements IPropertyPage { - - /** - * Part listener which cleans up this page when the source part is closed. - * This is hooked only when there is a source part. - */ - private class PartListener implements IPartListener { - public void partActivated(IWorkbenchPart part) { - } - - public void partBroughtToTop(IWorkbenchPart part) { - } - - public void partClosed(IWorkbenchPart part) { - if (sourcePart == part) { - sourcePart = null; - sourcePartClosed(part); - } - } - - public void partDeactivated(IWorkbenchPart part) { - } - - public void partOpened(IWorkbenchPart part) { - } - } - - private final PartListener partListener = new PartListener(); - - protected IWorkbenchPartSite sourceSite; - - protected IWorkbenchPart sourcePart; - - /** - * @param sourceSite the workbench part site that produces this page or - * null 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); - -} +/******************************************************************************* + * 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: + *

+ *

+ *

+ * Subclasses may extend or reimplement the following methods as required: + *

+ *

+ * + * @author Tuukka Lehtonen + */ +public abstract class AbstractPropertyPage extends Page implements IPropertyPage { + + /** + * Part listener which cleans up this page when the source part is closed. + * This is hooked only when there is a source part. + */ + private class PartListener implements IPartListener { + public void partActivated(IWorkbenchPart part) { + } + + public void partBroughtToTop(IWorkbenchPart part) { + } + + public void partClosed(IWorkbenchPart part) { + if (sourcePart == part) { + sourcePart = null; + sourcePartClosed(part); + } + } + + public void partDeactivated(IWorkbenchPart part) { + } + + public void partOpened(IWorkbenchPart part) { + } + } + + private final PartListener partListener = new PartListener(); + + protected IWorkbenchPartSite sourceSite; + + protected IWorkbenchPart sourcePart; + + /** + * @param sourceSite the workbench part site that produces this page or + * null 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); + +}