1 /*******************************************************************************
2 * Copyright (c) 2012 Association for Decentralized Information Management in
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.browsing.ui.swt.widgets;
14 import org.eclipse.swt.graphics.Color;
15 import org.eclipse.swt.graphics.Font;
16 import org.eclipse.swt.widgets.Control;
17 import org.simantics.Simantics;
18 import org.simantics.browsing.ui.swt.widgets.impl.Widget;
19 import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;
20 import org.simantics.db.procedure.Listener;
21 import org.simantics.db.request.ReadInterface;
22 import org.simantics.ui.colors.Colors;
24 abstract public class WidgetImpl implements Widget {
26 protected final WidgetSupport support;
28 public WidgetImpl(WidgetSupport support) {
29 this.support = support;
32 public abstract Control getControl();
34 public void setFont(Font font) {
35 getControl().setFont(font);
38 public void setBackground(Color color) {
39 getControl().setBackground(color);
42 public <T> void setBackground(final ReadInterface<org.simantics.datatypes.adt.Color> read) {
44 Simantics.getSession().async(read, new Listener<org.simantics.datatypes.adt.Color>() {
47 public void exception(Throwable t) {
52 public void execute(final org.simantics.datatypes.adt.Color color) {
54 if(isDisposed()) return;
56 getControl().getDisplay().asyncExec(new Runnable() {
60 getControl().setBackground(Colors.swt(getControl().getDisplay(), color));
67 public boolean isDisposed() {
68 return getControl().isDisposed();
75 public void setForeground(Color color) {
76 getControl().setForeground(color);
79 public void setLayoutData(Object layoutData) {
80 getControl().setLayoutData(layoutData);