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