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