/*******************************************************************************
* 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.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Set;
import java.util.TreeSet;
import java.util.function.Consumer;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.IWorkbenchPartSite;
import org.simantics.utils.ObjectUtils;
/**
*
* See PropertyPage for more information on what can be extended or
* reimplemented from the superclasses. In addition to those, subclasses may
* extend or reimplement the following methods:
*
*
getContexts - reimplement to define what browse contexts
* this property page should be initialized with. The same result can also be
* achieved by using the
* {@link StandardPropertyPage#StandardPropertyPage(IWorkbenchPartSite, Set)}
* constructor.
*
*
*
* @author Tuukka Lehtonen
*
* @see StandardProperties
*/
public class StandardPropertyPage extends PropertyPage {
private final Set contexts;
private StandardProperties tabs;
/**
* For updating the view title when the active tab changes.
*/
//private transient ISelection lastSelection;
private transient Consumer lastTitleCallback;
/**
* Initializes a new standard property page for the specified workbench part
* without loading the page configuration from any extensible contexts.
*
* @param site the workbench part site that contains this page or
* null if there is no site, i.e. the page is within a
* dialog or a plain shell.
*/
public StandardPropertyPage(IWorkbenchPartSite site) {
this(site, new TreeSet());
}
/**
* Initializes a new standard property page for the specified workbench part
* and specifies which contexts should be searched for
* {@link SelectionProcessor} and {@link PropertyTabContributor} bindings to
* initialize the page.
*
* @param site the workbench part site that contains this page or
* null if there is no site, i.e. the page is within a
* dialog or a plain shell.
* @param contexts the contexts to search bindings for to initialize the
* property page
*/
public StandardPropertyPage(IWorkbenchPartSite site, Set contexts) {
super(site);
this.contexts = contexts;
}
protected SelectionProcessor, ?> getSelectionProcessor() {
return new StandardSelectionProcessor();
}
protected Set getContexts() {
return contexts;
}
@SuppressWarnings("unchecked")
@Override
protected void createPageControls(Composite parent) {
SelectionProcessor, ?> sp = getSelectionProcessor();
@SuppressWarnings("rawtypes")
Collection sps = null;
if (sp != null)
sps = Collections.singleton(sp);
tabs = new StandardProperties(sourceSite, getSite(), parent, SWT.NONE, getContexts(), sps) {
@Override
protected void activeTabChanged(TabChangeEvent event) {
StandardPropertyPage.this.activeTabChanged(event);
}
@Override
protected ComparableTabContributor selectInitialTab(Collection