1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2012 Association for Decentralized Information Management
\r
3 * in Industry THTH ry.
\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.widgets.Composite;
\r
15 import org.eclipse.swt.widgets.Control;
\r
16 import org.simantics.browsing.ui.swt.widgets.impl.ReadFactory;
\r
17 import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;
\r
18 import org.simantics.db.management.ISessionContext;
\r
19 import org.simantics.db.procedure.Listener;
\r
20 import org.simantics.scl.compiler.StandardSCLCompilerConfiguration;
\r
21 import org.simantics.scl.ui.editor.SCLTextEditor;
\r
22 import org.simantics.utils.ui.SWTUtils;
\r
24 public class SCLEditor extends WidgetImpl {
\r
26 private ReadFactory<?, String> textFactory;
\r
28 final private SCLTextEditor editor;
\r
30 public SCLEditor(Composite parent, WidgetSupport support, int style) {
\r
32 editor = new SCLTextEditor(parent, style, StandardSCLCompilerConfiguration.INSTANCE);
\r
33 support.register(this);
\r
36 public void setTextFactory(ReadFactory<?, String> textFactory) {
\r
37 this.textFactory = textFactory;
\r
40 public SCLTextEditor getWidget() {
\r
45 public Control getControl() {
\r
50 public void setInput(ISessionContext context, Object input) {
\r
52 if(textFactory != null) {
\r
53 textFactory.listen(context, input, new Listener<String>() {
\r
55 public void exception(final Throwable t) {
\r
56 SWTUtils.asyncExec(editor, new Runnable() {
\r
60 if(isDisposed()) return;
\r
61 // System.out.println("Button received new text: " + text);
\r
62 editor.setContent(t.toString());
\r
69 public void execute(final String s) {
\r
70 SWTUtils.asyncExec(editor, new Runnable() {
\r
74 if(isDisposed()) return;
\r
75 editor.setContent(s);
\r
82 public boolean isDisposed() {
\r
83 return editor.isDisposed();
\r
92 public void setContent(String s) {
\r
93 editor.setContent(s);
\r
96 public String getContent() {
\r
97 return editor.getContent();
\r