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