]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/widgets/WidgetImpl.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.browsing.ui.swt / src / org / simantics / browsing / ui / swt / widgets / WidgetImpl.java
1 /*******************************************************************************
2  * Copyright (c) 2012 Association for Decentralized Information Management in
3  * Industry THTH ry.
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
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.browsing.ui.swt.widgets;
13
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;
23
24 abstract public class WidgetImpl implements Widget {
25
26         protected final WidgetSupport support;
27         
28         public WidgetImpl(WidgetSupport support) {
29                 this.support = support;
30         }
31         
32         public abstract Control getControl();
33         
34         public void setFont(Font font) {
35                 getControl().setFont(font);
36         }
37         
38         public void setBackground(Color color) {
39                 getControl().setBackground(color);
40         }
41         
42     public <T> void setBackground(final ReadInterface<org.simantics.datatypes.adt.Color> read) {
43         
44         Simantics.getSession().async(read, new Listener<org.simantics.datatypes.adt.Color>() {
45
46                 @Override
47                 public void exception(Throwable t) {
48                         t.printStackTrace();
49                 }
50
51                 @Override
52                 public void execute(final org.simantics.datatypes.adt.Color color) {
53
54                         if(isDisposed()) return;
55
56                         getControl().getDisplay().asyncExec(new Runnable() {
57
58                                 @Override
59                                 public void run() {
60                                         getControl().setBackground(Colors.swt(getControl().getDisplay(), color));
61                                 }
62
63                         });
64                 }
65
66                 @Override
67                 public boolean isDisposed() {
68                         return getControl().isDisposed();
69                 }
70
71         });
72
73     }
74         
75         public void setForeground(Color color) {
76                 getControl().setForeground(color);
77         }
78         
79     public void setLayoutData(Object layoutData) {
80         getControl().setLayoutData(layoutData);
81     }
82
83 }