1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.selectionview;
14 import java.util.concurrent.atomic.AtomicBoolean;
16 import org.eclipse.jface.viewers.ISelectionProvider;
17 import org.eclipse.swt.events.DisposeEvent;
18 import org.eclipse.swt.events.DisposeListener;
19 import org.eclipse.swt.widgets.Composite;
20 import org.eclipse.swt.widgets.Control;
21 import org.eclipse.ui.IWorkbenchSite;
22 import org.simantics.browsing.ui.common.ErrorLogger;
23 import org.simantics.db.common.procedure.adapter.ListenerSupport;
24 import org.simantics.db.management.ISessionContext;
27 * Override {@link #createControls(Composite, ISessionContext)} to create
28 * controls for your own tab.
31 * This class implements {@link ListenerSupport} to help in dealing with graph
35 * This adapter has the following default implementations for IPropertyTab:
37 * <li>{@link #getSelectionProvider()} - returns null, i.e. does not provide any
38 * selection to other UI/Workbench parts.</li>
39 * <li>{@link #requestFocus()} - calls {@link Control#setFocus()} for
40 * {@link #getControl()} if a control exists</li>
41 * <li>{@link #isDisposed()} - returns <code>false</code> by default and
42 * <code>true</code> if {@link #setDisposed()} has been called</li>
45 * @author Tuukka Lehtonen
47 * @see PropertyTabContributorImpl
49 public abstract class PropertyTabAdapter implements IPropertyTab2, ListenerSupport {
51 protected IWorkbenchSite site;
53 private final AtomicBoolean disposed = new AtomicBoolean();
55 public PropertyTabAdapter(IWorkbenchSite site) {
61 * Override this implementation and call super.createControl(parent) as the
62 * last thing in your property table.
64 * @see org.simantics.selectionview.IPropertyTab#createControl(org.eclipse.swt.widgets.Composite)
67 public final void createControl(Composite parent, ISessionContext context) {
68 createControls(parent, context);
69 Control control = getControl();
71 if (control == null || control.isDisposed())
74 control.addDisposeListener(new DisposeListener() {
76 public void widgetDisposed(DisposeEvent e) {
83 * Override this implementation to create the tab's controls.
85 * @see #createControl(Composite, ISessionContext)
87 public void createControls(Composite parent, ISessionContext context) {
88 Control control = getControl();
89 if (control == null || control.isDisposed())
92 control.addDisposeListener(new DisposeListener() {
94 public void widgetDisposed(DisposeEvent e) {
101 public void dispose() {
105 * @return <code>true</code> if tab was marked disposed, <code>false</code>
106 * if it was already marked disposed
108 protected boolean setDisposed() {
109 return disposed.compareAndSet(false, true);
113 public boolean isDisposed() {
114 return disposed.get();
118 public ISelectionProvider getSelectionProvider() {
123 public void requestFocus() {
124 Control control = getControl();
125 if (control == null || control.isDisposed())
132 public void exception(Throwable t) {
133 ErrorLogger.defaultLogError("PropertyTabAdapter received unexpected exception.", t);