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%2FText.java;h=b4af8e22a41c26a7853444e09471ae14307b9ada;hp=932b85a8caa1d4f932fe68ee8a7dcb3af87315a8;hb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;hpb=24e2b34260f219f0d1644ca7a138894980e25b14 diff --git a/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/widgets/Text.java b/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/widgets/Text.java index 932b85a8c..b4af8e22a 100644 --- a/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/widgets/Text.java +++ b/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/widgets/Text.java @@ -1,141 +1,141 @@ -/******************************************************************************* - * Copyright (c) 2007, 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.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.simantics.Simantics; -import org.simantics.browsing.ui.swt.widgets.impl.ReadFactory; -import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; -import org.simantics.db.ReadGraph; -import org.simantics.db.common.request.ParametrizedRead; -import org.simantics.db.common.request.UniqueRead; -import org.simantics.db.exception.DatabaseException; -import org.simantics.db.management.ISessionContext; -import org.simantics.db.procedure.Listener; -import org.simantics.utils.ui.SWTUtils; - -public class Text extends WidgetImpl { - - private ReadFactory textFactory; - - final private org.eclipse.swt.widgets.Text text; - - public Text(Composite parent, WidgetSupport support, int style) { - super(support); - text = new org.eclipse.swt.widgets.Text(parent, style); - support.register(this); - } - - public void setTextFactory(ReadFactory textFactory) { - this.textFactory = textFactory; - } - - public org.eclipse.swt.widgets.Text getWidget() { - return text; - } - - @Override - public Control getControl() { - return text; - } - - @Override - public void setInput(ISessionContext context, Object input) { - - if(textFactory != null) { - textFactory.listen(context, input, new Listener() { - - public void exception(final Throwable t) { - SWTUtils.asyncExec(text, new Runnable() { - - @Override - public void run() { - if(isDisposed()) return; -// System.out.println("Button received new text: " + text); - text.setText(t.toString()); - } - - }); - } - - @Override - public void execute(final String s) { - SWTUtils.asyncExec(text, new Runnable() { - - @Override - public void run() { - if(isDisposed()) return; - text.setText(s); - } - - }); - } - - @Override - public boolean isDisposed() { - return text.isDisposed(); - } - - }); - - } - - } - - public void setText(String s) { - text.setText(s); - } - - public void setText(final ParametrizedRead read) { - - Simantics.getSession().async(new UniqueRead() { - - @Override - public String perform(ReadGraph graph) throws DatabaseException { - T input = support.getInput(graph); - return graph.syncRequest(read.get(input)); - } - - }, new Listener() { - - @Override - public void exception(Throwable t) { - t.printStackTrace(); - } - - @Override - public void execute(final String _text) { - - if(isDisposed()) return; - - text.getDisplay().asyncExec(new Runnable() { - - @Override - public void run() { - if(_text == null) text.setText(""); - else text.setText(_text); - } - - }); - } - - @Override - public boolean isDisposed() { - return text.isDisposed(); - } - - }); - - } - -} +/******************************************************************************* + * Copyright (c) 2007, 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.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.simantics.Simantics; +import org.simantics.browsing.ui.swt.widgets.impl.ReadFactory; +import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; +import org.simantics.db.ReadGraph; +import org.simantics.db.common.request.ParametrizedRead; +import org.simantics.db.common.request.UniqueRead; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.management.ISessionContext; +import org.simantics.db.procedure.Listener; +import org.simantics.utils.ui.SWTUtils; + +public class Text extends WidgetImpl { + + private ReadFactory textFactory; + + final private org.eclipse.swt.widgets.Text text; + + public Text(Composite parent, WidgetSupport support, int style) { + super(support); + text = new org.eclipse.swt.widgets.Text(parent, style); + support.register(this); + } + + public void setTextFactory(ReadFactory textFactory) { + this.textFactory = textFactory; + } + + public org.eclipse.swt.widgets.Text getWidget() { + return text; + } + + @Override + public Control getControl() { + return text; + } + + @Override + public void setInput(ISessionContext context, Object input) { + + if(textFactory != null) { + textFactory.listen(context, input, new Listener() { + + public void exception(final Throwable t) { + SWTUtils.asyncExec(text, new Runnable() { + + @Override + public void run() { + if(isDisposed()) return; +// System.out.println("Button received new text: " + text); + text.setText(t.toString()); + } + + }); + } + + @Override + public void execute(final String s) { + SWTUtils.asyncExec(text, new Runnable() { + + @Override + public void run() { + if(isDisposed()) return; + text.setText(s); + } + + }); + } + + @Override + public boolean isDisposed() { + return text.isDisposed(); + } + + }); + + } + + } + + public void setText(String s) { + text.setText(s); + } + + public void setText(final ParametrizedRead read) { + + Simantics.getSession().async(new UniqueRead() { + + @Override + public String perform(ReadGraph graph) throws DatabaseException { + T input = support.getInput(graph); + return graph.syncRequest(read.get(input)); + } + + }, new Listener() { + + @Override + public void exception(Throwable t) { + t.printStackTrace(); + } + + @Override + public void execute(final String _text) { + + if(isDisposed()) return; + + text.getDisplay().asyncExec(new Runnable() { + + @Override + public void run() { + if(_text == null) text.setText(""); + else text.setText(_text); + } + + }); + } + + @Override + public boolean isDisposed() { + return text.isDisposed(); + } + + }); + + } + +}