--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2012 Association for Decentralized Information Management in\r
+ * Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.browsing.ui.swt.widgets;\r
+\r
+import org.eclipse.swt.graphics.Color;\r
+import org.eclipse.swt.graphics.Font;\r
+import org.eclipse.swt.widgets.Control;\r
+import org.simantics.Simantics;\r
+import org.simantics.browsing.ui.swt.widgets.impl.Widget;\r
+import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;\r
+import org.simantics.db.procedure.Listener;\r
+import org.simantics.db.request.ReadInterface;\r
+import org.simantics.ui.colors.Colors;\r
+\r
+abstract public class WidgetImpl implements Widget {\r
+\r
+ protected final WidgetSupport support;\r
+ \r
+ public WidgetImpl(WidgetSupport support) {\r
+ this.support = support;\r
+ }\r
+ \r
+ public abstract Control getControl();\r
+ \r
+ public void setFont(Font font) {\r
+ getControl().setFont(font);\r
+ }\r
+ \r
+ public void setBackground(Color color) {\r
+ getControl().setBackground(color);\r
+ }\r
+ \r
+ public <T> void setBackground(final ReadInterface<org.simantics.datatypes.adt.Color> read) {\r
+ \r
+ Simantics.getSession().async(read, new Listener<org.simantics.datatypes.adt.Color>() {\r
+\r
+ @Override\r
+ public void exception(Throwable t) {\r
+ t.printStackTrace();\r
+ }\r
+\r
+ @Override\r
+ public void execute(final org.simantics.datatypes.adt.Color color) {\r
+\r
+ if(isDisposed()) return;\r
+\r
+ getControl().getDisplay().asyncExec(new Runnable() {\r
+\r
+ @Override\r
+ public void run() {\r
+ getControl().setBackground(Colors.swt(getControl().getDisplay(), color));\r
+ }\r
+\r
+ });\r
+ }\r
+\r
+ @Override\r
+ public boolean isDisposed() {\r
+ return getControl().isDisposed();\r
+ }\r
+\r
+ });\r
+\r
+ }\r
+ \r
+ public void setForeground(Color color) {\r
+ getControl().setForeground(color);\r
+ }\r
+ \r
+ public void setLayoutData(Object layoutData) {\r
+ getControl().setLayoutData(layoutData);\r
+ }\r
+\r
+}\r