]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/widgets/SCLEditor.java
Merge "Workaround fix for acorn mutex printing for now"
[simantics/platform.git] / bundles / org.simantics.browsing.ui.swt / src / org / simantics / browsing / ui / swt / widgets / SCLEditor.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2012 Association for Decentralized Information Management
3  * in Industry THTH ry.
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
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.browsing.ui.swt.widgets;
13
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;
23
24 public class SCLEditor extends WidgetImpl {
25
26         private ReadFactory<?, String> textFactory;
27         
28         final private SCLTextEditor editor;
29         
30         public SCLEditor(Composite parent, WidgetSupport support, int style) {
31                 super(support);
32                 editor = new SCLTextEditor(parent, style, StandardSCLCompilerConfiguration.INSTANCE);
33                 support.register(this);
34         }
35         
36         public void setTextFactory(ReadFactory<?, String> textFactory) {
37                 this.textFactory = textFactory;
38         }
39         
40         public SCLTextEditor getWidget() {
41                 return editor;
42         }
43         
44         @Override
45         public Control getControl() {
46                 return editor;
47         }
48
49         @Override
50         public void setInput(ISessionContext context, Object input) {
51
52                 if(textFactory != null) {
53                         textFactory.listen(context, input, new Listener<String>() {
54
55                                 public void exception(final Throwable t) {
56                                         SWTUtils.asyncExec(editor, new Runnable() {
57
58                                                 @Override
59                                                 public void run() {
60                                                         if(isDisposed()) return;
61 //                                                      System.out.println("Button received new text: " + text);
62                                                         editor.setContent(t.toString());
63                                                 }
64
65                                         });
66                                 }
67
68                                 @Override
69                                 public void execute(final String s) {
70                                         SWTUtils.asyncExec(editor, new Runnable() {
71
72                                                 @Override
73                                                 public void run() {
74                                                         if(isDisposed()) return;
75                                                         editor.setContent(s);
76                                                 }
77
78                                         });
79                                 }
80
81                                 @Override
82                                 public boolean isDisposed() {
83                                         return editor.isDisposed();
84                                 }
85
86                         });
87                 
88                 }
89                 
90         }
91         
92         public void setContent(String s) {
93                 editor.setContent(s);
94         }
95         
96         public String getContent() {
97                 return editor.getContent();
98         }
99
100 }