X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.browsing.ui.swt%2Fsrc%2Forg%2Fsimantics%2Fbrowsing%2Fui%2Fswt%2Fwidgets%2FWidgetImpl.java;fp=bundles%2Forg.simantics.browsing.ui.swt%2Fsrc%2Forg%2Fsimantics%2Fbrowsing%2Fui%2Fswt%2Fwidgets%2FWidgetImpl.java;h=5fe27380f8970ffcac5e302224f539ad13e10eb1;hp=0000000000000000000000000000000000000000;hb=969bd23cab98a79ca9101af33334000879fb60c5;hpb=866dba5cd5a3929bbeae85991796acb212338a08 diff --git a/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/widgets/WidgetImpl.java b/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/widgets/WidgetImpl.java new file mode 100644 index 000000000..5fe27380f --- /dev/null +++ b/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/widgets/WidgetImpl.java @@ -0,0 +1,83 @@ +/******************************************************************************* + * Copyright (c) 2012 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.browsing.ui.swt.widgets; + +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.Font; +import org.eclipse.swt.widgets.Control; +import org.simantics.Simantics; +import org.simantics.browsing.ui.swt.widgets.impl.Widget; +import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; +import org.simantics.db.procedure.Listener; +import org.simantics.db.request.ReadInterface; +import org.simantics.ui.colors.Colors; + +abstract public class WidgetImpl implements Widget { + + protected final WidgetSupport support; + + public WidgetImpl(WidgetSupport support) { + this.support = support; + } + + public abstract Control getControl(); + + public void setFont(Font font) { + getControl().setFont(font); + } + + public void setBackground(Color color) { + getControl().setBackground(color); + } + + public void setBackground(final ReadInterface read) { + + Simantics.getSession().async(read, new Listener() { + + @Override + public void exception(Throwable t) { + t.printStackTrace(); + } + + @Override + public void execute(final org.simantics.datatypes.adt.Color color) { + + if(isDisposed()) return; + + getControl().getDisplay().asyncExec(new Runnable() { + + @Override + public void run() { + getControl().setBackground(Colors.swt(getControl().getDisplay(), color)); + } + + }); + } + + @Override + public boolean isDisposed() { + return getControl().isDisposed(); + } + + }); + + } + + public void setForeground(Color color) { + getControl().setForeground(color); + } + + public void setLayoutData(Object layoutData) { + getControl().setLayoutData(layoutData); + } + +}