X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.selectionview%2Fsrc%2Forg%2Fsimantics%2Fselectionview%2FAbstractPropertyPage.java;fp=bundles%2Forg.simantics.selectionview%2Fsrc%2Forg%2Fsimantics%2Fselectionview%2FAbstractPropertyPage.java;h=7d7c015986c4a683417444fb4ff3a76712b7c8ad;hb=969bd23cab98a79ca9101af33334000879fb60c5;hp=0000000000000000000000000000000000000000;hpb=866dba5cd5a3929bbeae85991796acb212338a08;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.selectionview/src/org/simantics/selectionview/AbstractPropertyPage.java b/bundles/org.simantics.selectionview/src/org/simantics/selectionview/AbstractPropertyPage.java new file mode 100644 index 000000000..7d7c01598 --- /dev/null +++ b/bundles/org.simantics.selectionview/src/org/simantics/selectionview/AbstractPropertyPage.java @@ -0,0 +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: + *
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);
+
+}