X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=bundles%2Forg.simantics.selectionview%2Fsrc%2Forg%2Fsimantics%2Fselectionview%2FPropertyPage.java;h=eb4caaebaf0b014e4de0ae124377a8658620172a;hb=48df6974c83f3f42497712b35e8531377a4178c8;hp=a21378eef4aa3bb055409f6bfb2331056742e410;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.selectionview/src/org/simantics/selectionview/PropertyPage.java b/bundles/org.simantics.selectionview/src/org/simantics/selectionview/PropertyPage.java index a21378eef..eb4caaeba 100644 --- a/bundles/org.simantics.selectionview/src/org/simantics/selectionview/PropertyPage.java +++ b/bundles/org.simantics.selectionview/src/org/simantics/selectionview/PropertyPage.java @@ -1,327 +1,327 @@ -/******************************************************************************* - * 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 java.util.function.Consumer; - -import org.eclipse.core.runtime.IAdaptable; -import org.eclipse.jface.action.IMenuManager; -import org.eclipse.jface.action.IToolBarManager; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.ISelectionProvider; -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Event; -import org.eclipse.swt.widgets.Listener; -import org.eclipse.ui.IPartListener2; -import org.eclipse.ui.IWorkbenchPart; -import org.eclipse.ui.IWorkbenchPartReference; -import org.eclipse.ui.IWorkbenchPartSite; -import org.eclipse.ui.part.IPageSite; -import org.simantics.Simantics; -import org.simantics.browsing.ui.common.IPageBookViewPagePartInit; -import org.simantics.browsing.ui.common.views.IFilterAreaProvider; -import org.simantics.browsing.ui.swt.PartNameListener; -import org.simantics.browsing.ui.swt.PropertyPageUtil; -import org.simantics.db.ReadGraph; -import org.simantics.db.Session; -import org.simantics.db.exception.DatabaseException; -import org.simantics.db.management.ISessionContext; -import org.simantics.db.management.ISessionContextChangedListener; -import org.simantics.db.management.ISessionContextProvider; -import org.simantics.db.management.SessionContextChangedEvent; -import org.simantics.db.request.Read; -import org.simantics.ui.workbench.IPropertyPage; - -/** - *
- * Subclasses may extend or reimplement the following methods as required: - *
createPageControls
- to create the page's controlsfillToolBar
- to add actions to the page's toolbarfillDropDownMenu
- to add actions to the page's drop-down menugetControl
- to retrieve the page's controlsetFocus
- 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 closeddispose
- 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 setup for the view before any controls are createdsessionContextChanged
- reimplement to take actions when the source database session changesnull
if there is no site, i.e. the page is within a
- * dialog or a plain shell.
- */
- public PropertyPage(IWorkbenchPartSite site) {
- super(site);
- }
-
- @Override
- public void init(IPageSite pageSite) {
-
- super.init(pageSite);
-
- if(getSite() != null)
- getSite().getPage().addPartListener(this);
-
- }
-
- @Override
- public void initPart(IWorkbenchPart part) {
- propertyPageView = part;
- }
-
- @Override
- public void dispose() {
-
- if(getSite() != null)
- getSite().getPage().removePartListener(this);
-
- // Stop listening for title changes.
- if (currentPartNameListener != null) {
- currentPartNameListener.dispose();
- currentPartNameListener = null;
- }
-
- ISessionContextProvider contextProvider = getSessionContextProvider();
- if (contextProvider != null)
- contextProvider.removeContextChangedListener(contextChangeListener);
-
- //System.out.println("dispose " + this);
- // Must invoke dispose before nullifying table since super will dispose the widget.
- super.dispose();
- tab = null;
- sessionContext = null;
- }
-
- protected ISessionContextProvider getSessionContextProvider() {
- return Simantics.getSessionContextProvider();
- }
-
- protected ISessionContext getSessionContext() {
- return sessionContext;
- }
-
- protected Session getSession() {
- if (sessionContext == null)
- throw new IllegalStateException("null session context");
- return sessionContext.getSession();
- }
-
- @Override
- public final void createControl(Composite parent) {
- createPageControls(parent);
-
- // Attach to current session context provider to keep the UI intact even
- // when the current UI session changes.
- ISessionContextProvider contextProvider = getSessionContextProvider();
- contextProvider.addContextChangedListener(contextChangeListener);
- setSessionContext(contextProvider.getSessionContext());
- }
-
- /**
- * Override to customize the UI component created on this page.
- *
- * @param parent
- */
- protected void createPageControls(Composite parent) {
- PropertyTable pt = new PropertyTable(sourceSite, parent, SWT.NONE);
- tab = pt;
- tab.createControl(pt, getSessionContext());
- tab.getControl().addListener(SWT.Dispose, new Listener() {
- @Override
- public void handleEvent(Event event) {
- PropertyPage.this.dispose();
- }
- });
- ISelectionProvider pv = pt.getSelectionProvider();
- getSite().setSelectionProvider(pv);
-
- fillToolBar(getSite().getActionBars().getToolBarManager());
- fillDropDownMenu(getSite().getActionBars().getMenuManager());
- }
-
- protected void fillToolBar(IToolBarManager manager) {
- }
-
- protected void fillDropDownMenu(IMenuManager manager) {
- }
-
- /**
- * @param newContext
- */
- protected final void setSessionContext(ISessionContext newContext) {
-// ISessionContext oldContext = this.sessionContext;
- this.sessionContext = newContext;
-// System.out.println("PropertyPage.setSessionContext: " + oldContext + " -> " + newContext);
- }
-
- protected ISessionContextChangedListener contextChangeListener = new ISessionContextChangedListener() {
- @Override
- public void sessionContextChanged(SessionContextChangedEvent event) {
- setSessionContext(event.getNewValue());
- }
- };
-
- @Override
- public Control getControl() {
- return (tab != null) ? tab.getControl() : null;
- }
-
- @Override
- public ISelection getSelection() {
- if (tab != null && !tab.isDisposed()) {
- ISelectionProvider provider = tab.getSelectionProvider();
- if (provider != null)
- return provider.getSelection();
- }
- return null;
- }
-
- /**
- * Sets focus to a part in the page.
- * @see org.eclipse.ui.part.Page#setFocus()
- */
- @Override
- public void setFocus() {
- if (tab != null && !tab.isDisposed()) {
- tab.requestFocus();
- }
- }
-
- @Override
- protected void sourcePartClosed(IWorkbenchPart part) {
- if (tab != null && !tab.isDisposed()) {
- tab.setInput(getSessionContext(), StructuredSelection.EMPTY, false);
- }
- }
-
- @Override
- protected void sourceSelectionChanged(ISelection selection) {
- if (tab != null && !tab.isDisposed()) {
- latestSelection = selection;
- if(visible)
- tab.setInput(getSessionContext(), selection, false);
- }
- }
-
- protected void refresh() {
- if (tab != null && !tab.isDisposed()) {
- tab.setInput(getSessionContext(), latestSelection, true);
- }
- }
-
- protected PartNameListener currentPartNameListener = null;
-
- @Override
- public void updatePartName(final ISelection forSelection, Consumer+ * Subclasses may extend or reimplement the following methods as required: + *
createPageControls
- to create the page's controlsfillToolBar
- to add actions to the page's toolbarfillDropDownMenu
- to add actions to the page's drop-down menugetControl
- to retrieve the page's controlsetFocus
- 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 closeddispose
- 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 setup for the view before any controls are createdsessionContextChanged
- reimplement to take actions when the source database session changesnull
if there is no site, i.e. the page is within a
+ * dialog or a plain shell.
+ */
+ public PropertyPage(IWorkbenchPartSite site) {
+ super(site);
+ }
+
+ @Override
+ public void init(IPageSite pageSite) {
+
+ super.init(pageSite);
+
+ if(getSite() != null)
+ getSite().getPage().addPartListener(this);
+
+ }
+
+ @Override
+ public void initPart(IWorkbenchPart part) {
+ propertyPageView = part;
+ }
+
+ @Override
+ public void dispose() {
+
+ if(getSite() != null)
+ getSite().getPage().removePartListener(this);
+
+ // Stop listening for title changes.
+ if (currentPartNameListener != null) {
+ currentPartNameListener.dispose();
+ currentPartNameListener = null;
+ }
+
+ ISessionContextProvider contextProvider = getSessionContextProvider();
+ if (contextProvider != null)
+ contextProvider.removeContextChangedListener(contextChangeListener);
+
+ //System.out.println("dispose " + this);
+ // Must invoke dispose before nullifying table since super will dispose the widget.
+ super.dispose();
+ tab = null;
+ sessionContext = null;
+ }
+
+ protected ISessionContextProvider getSessionContextProvider() {
+ return Simantics.getSessionContextProvider();
+ }
+
+ protected ISessionContext getSessionContext() {
+ return sessionContext;
+ }
+
+ protected Session getSession() {
+ if (sessionContext == null)
+ throw new IllegalStateException("null session context");
+ return sessionContext.getSession();
+ }
+
+ @Override
+ public final void createControl(Composite parent) {
+ createPageControls(parent);
+
+ // Attach to current session context provider to keep the UI intact even
+ // when the current UI session changes.
+ ISessionContextProvider contextProvider = getSessionContextProvider();
+ contextProvider.addContextChangedListener(contextChangeListener);
+ setSessionContext(contextProvider.getSessionContext());
+ }
+
+ /**
+ * Override to customize the UI component created on this page.
+ *
+ * @param parent
+ */
+ protected void createPageControls(Composite parent) {
+ PropertyTable pt = new PropertyTable(sourceSite, parent, SWT.NONE);
+ tab = pt;
+ tab.createControl(pt, getSessionContext());
+ tab.getControl().addListener(SWT.Dispose, new Listener() {
+ @Override
+ public void handleEvent(Event event) {
+ PropertyPage.this.dispose();
+ }
+ });
+ ISelectionProvider pv = pt.getSelectionProvider();
+ getSite().setSelectionProvider(pv);
+
+ fillToolBar(getSite().getActionBars().getToolBarManager());
+ fillDropDownMenu(getSite().getActionBars().getMenuManager());
+ }
+
+ protected void fillToolBar(IToolBarManager manager) {
+ }
+
+ protected void fillDropDownMenu(IMenuManager manager) {
+ }
+
+ /**
+ * @param newContext
+ */
+ protected final void setSessionContext(ISessionContext newContext) {
+// ISessionContext oldContext = this.sessionContext;
+ this.sessionContext = newContext;
+// System.out.println("PropertyPage.setSessionContext: " + oldContext + " -> " + newContext);
+ }
+
+ protected ISessionContextChangedListener contextChangeListener = new ISessionContextChangedListener() {
+ @Override
+ public void sessionContextChanged(SessionContextChangedEvent event) {
+ setSessionContext(event.getNewValue());
+ }
+ };
+
+ @Override
+ public Control getControl() {
+ return (tab != null) ? tab.getControl() : null;
+ }
+
+ @Override
+ public ISelection getSelection() {
+ if (tab != null && !tab.isDisposed()) {
+ ISelectionProvider provider = tab.getSelectionProvider();
+ if (provider != null)
+ return provider.getSelection();
+ }
+ return null;
+ }
+
+ /**
+ * Sets focus to a part in the page.
+ * @see org.eclipse.ui.part.Page#setFocus()
+ */
+ @Override
+ public void setFocus() {
+ if (tab != null && !tab.isDisposed()) {
+ tab.requestFocus();
+ }
+ }
+
+ @Override
+ protected void sourcePartClosed(IWorkbenchPart part) {
+ if (tab != null && !tab.isDisposed()) {
+ tab.setInput(getSessionContext(), StructuredSelection.EMPTY, false);
+ }
+ }
+
+ @Override
+ protected void sourceSelectionChanged(ISelection selection) {
+ if (tab != null && !tab.isDisposed()) {
+ latestSelection = selection;
+ if(visible)
+ tab.setInput(getSessionContext(), selection, false);
+ }
+ }
+
+ protected void refresh() {
+ if (tab != null && !tab.isDisposed()) {
+ tab.setInput(getSessionContext(), latestSelection, true);
+ }
+ }
+
+ protected PartNameListener currentPartNameListener = null;
+
+ @Override
+ public void updatePartName(final ISelection forSelection, Consumer