org.simantics.g2d;bundle-version="[1.0.0,2.0.0)",
org.eclipse.ui.forms;bundle-version="3.4.1",
com.lowagie.text;bundle-version="2.1.5",
- org.simantics.scl.ui.editor;bundle-version="0.1.3";visibility:=reexport,
- org.simantics.scl.compiler.dummy;bundle-version="0.1.3",
org.eclipse.e4.core.contexts;bundle-version="1.4.0",
org.slf4j.api;bundle-version="1.7.20"
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
+++ /dev/null
-/*******************************************************************************
- * 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.browsing.ui.swt.widgets.impl.ReadFactory;
-import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;
-import org.simantics.db.management.ISessionContext;
-import org.simantics.db.procedure.Listener;
-import org.simantics.scl.compiler.StandardSCLCompilerConfiguration;
-import org.simantics.scl.ui.editor.SCLTextEditor;
-import org.simantics.utils.ui.SWTUtils;
-
-public class SCLEditor extends WidgetImpl {
-
- private ReadFactory<?, String> textFactory;
-
- final private SCLTextEditor editor;
-
- public SCLEditor(Composite parent, WidgetSupport support, int style) {
- super(support);
- editor = new SCLTextEditor(parent, style, StandardSCLCompilerConfiguration.INSTANCE);
- support.register(this);
- }
-
- public void setTextFactory(ReadFactory<?, String> textFactory) {
- this.textFactory = textFactory;
- }
-
- public SCLTextEditor getWidget() {
- return editor;
- }
-
- @Override
- public Control getControl() {
- return editor;
- }
-
- @Override
- public void setInput(ISessionContext context, Object input) {
-
- if(textFactory != null) {
- textFactory.listen(context, input, new Listener<String>() {
-
- public void exception(final Throwable t) {
- SWTUtils.asyncExec(editor, new Runnable() {
-
- @Override
- public void run() {
- if(isDisposed()) return;
-// System.out.println("Button received new text: " + text);
- editor.setContent(t.toString());
- }
-
- });
- }
-
- @Override
- public void execute(final String s) {
- SWTUtils.asyncExec(editor, new Runnable() {
-
- @Override
- public void run() {
- if(isDisposed()) return;
- editor.setContent(s);
- }
-
- });
- }
-
- @Override
- public boolean isDisposed() {
- return editor.isDisposed();
- }
-
- });
-
- }
-
- }
-
- public void setContent(String s) {
- editor.setContent(s);
- }
-
- public String getContent() {
- return editor.getContent();
- }
-
-}
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IWorkbenchSite;
import org.simantics.browsing.ui.swt.widgets.Button;
-import org.simantics.browsing.ui.swt.widgets.SCLEditor;
import org.simantics.browsing.ui.swt.widgets.StringPropertyFactory;
+import org.simantics.browsing.ui.swt.widgets.Text;
import org.simantics.browsing.ui.swt.widgets.impl.SelectionListenerImpl;
import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;
import org.simantics.db.Resource;
public class SCLEditorComposite extends ConfigurationComposite {
- private SCLEditor editor;
+ private Text editor;
public void create(Composite body, IWorkbenchSite site, ISessionContext context, final WidgetSupport support) {
@Override
public void beforeApply() {
- content = editor.getContent();
- editor.getWidget().storeSelectedRange();
+ content = editor.getWidget().getText();
+ //editor.getWidget().storeSelectedRange();
editor.getControl().setFocus();
- editor.getWidget().restoreSelectedRange();
+ //editor.getWidget().restoreSelectedRange();
}
@Override
});
- editor = new SCLEditor(body, support, SWT.BORDER | SWT.FLAT);
+ editor = new Text(body, support, SWT.BORDER | SWT.FLAT);
editor.setTextFactory(new StringPropertyFactory(Layer0X.URIs.HasExpression));
//editor.addModifyListener(new StringPropertyModifier(context, Layer0.URIs.HasExpression));
GridDataFactory.fillDefaults().grab(true, true).span(2, 1).applyTo(editor.getControl());
org.bouncycastle.bcprov-jdk14;bundle-version="1.38.0",
org.simantics.image2.ontology;bundle-version="1.1.0",
org.simantics.scl.compiler;bundle-version="0.4.0",
- org.simantics.scl.compiler.dummy;bundle-version="1.0.0",
org.simantics.scl.osgi;bundle-version="1.0.4",
org.eclipse.jface.text;bundle-version="3.7.1",
org.simantics.graphviz,
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<classpath>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
- <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
- <classpathentry kind="src" path="src"/>
- <classpathentry kind="output" path="bin"/>
-</classpath>
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<projectDescription>
- <name>org.simantics.scl.compiler.dummy</name>
- <comment></comment>
- <projects>
- </projects>
- <buildSpec>
- <buildCommand>
- <name>org.eclipse.jdt.core.javabuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>org.eclipse.pde.ManifestBuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>org.eclipse.pde.SchemaBuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- </buildSpec>
- <natures>
- <nature>org.eclipse.pde.PluginNature</nature>
- <nature>org.eclipse.jdt.core.javanature</nature>
- </natures>
-</projectDescription>
+++ /dev/null
-eclipse.preferences.version=1
-org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
-org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
-org.eclipse.jdt.core.compiler.compliance=1.8
-org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
-org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
-org.eclipse.jdt.core.compiler.source=1.8
+++ /dev/null
-Manifest-Version: 1.0
-Bundle-ManifestVersion: 2
-Bundle-Name: Dummy SCL compiler
-Bundle-SymbolicName: org.simantics.scl.compiler.dummy
-Bundle-Version: 1.0.0.qualifier
-Bundle-RequiredExecutionEnvironment: JavaSE-1.8
-Export-Package: org.simantics.scl.compiler
-Require-Bundle: org.simantics.scl.runtime;bundle-version="0.2.0"
+++ /dev/null
-source.. = src/
-output.. = bin/
-bin.includes = META-INF/,\
- .
+++ /dev/null
-package org.simantics.scl.compiler;
-
-public class ErrorMessage {
- int line;
- int start;
- int stop;
- String message;
-
- public ErrorMessage(int line, int start, int stop, String message) {
- this.line = line;
- this.start = start;
- this.stop = stop;
- this.message = message;
- }
-
- public int getLine() {
- return line;
- }
-
- public int getStart() {
- return start;
- }
-
- public int getStop() {
- return stop;
- }
-
- public String getMessage() {
- return message;
- }
-
- @Override
- public String toString() {
- return "at " + line + ":" + start + "-" + stop + " " + message;
- }
-}
+++ /dev/null
-package org.simantics.scl.compiler;
-
-import java.util.Collection;
-
-public class InvalidInputException extends Exception {
-
- private static final long serialVersionUID = 2923907879583127677L;
-
- Collection<ErrorMessage> errors;
-
- public InvalidInputException(Collection<ErrorMessage> errors) {
- this.errors = errors;
- }
-
- public Collection<ErrorMessage> getErrors() {
- return errors;
- }
-
-}
+++ /dev/null
-package org.simantics.scl.compiler;
-
-import java.io.InputStream;
-import java.util.Collections;
-
-import org.simantics.scl.runtime.Computation;
-
-public class SCLCompiler {
-
- public SCLCompiler(SCLCompilerConfiguration configuration) {
- }
-
- public static Computation compileExpression(SCLCompilerConfiguration configuration, InputStream code) throws InvalidInputException {
- throw new InvalidInputException(Collections.singleton(new ErrorMessage(0, 0, 0, "No SCL compiler")));
- }
-
- public static Computation compileExpression(SCLCompilerConfiguration configuration, String code) throws InvalidInputException {
- throw new InvalidInputException(Collections.singleton(new ErrorMessage(0, 0, 0, "No SCL compiler")));
- }
-
-}
+++ /dev/null
-package org.simantics.scl.compiler;
-
-
-public interface SCLCompilerConfiguration {
-}
+++ /dev/null
-package org.simantics.scl.compiler;
-
-
-public class StandardSCLCompilerConfiguration implements SCLCompilerConfiguration {
-
- public static final SCLCompilerConfiguration INSTANCE = new StandardSCLCompilerConfiguration();
-
-}
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<classpath>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
- <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
- <classpathentry kind="src" path="src"/>
- <classpathentry kind="output" path="bin"/>
-</classpath>
+++ /dev/null
-bin
\ No newline at end of file
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<projectDescription>
- <name>org.simantics.scl.ui.editor</name>
- <comment></comment>
- <projects>
- </projects>
- <buildSpec>
- <buildCommand>
- <name>org.eclipse.jdt.core.javabuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>org.eclipse.pde.ManifestBuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>org.eclipse.pde.SchemaBuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- </buildSpec>
- <natures>
- <nature>org.eclipse.pde.PluginNature</nature>
- <nature>org.eclipse.jdt.core.javanature</nature>
- </natures>
-</projectDescription>
+++ /dev/null
-eclipse.preferences.version=1
-org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
-org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
-org.eclipse.jdt.core.compiler.compliance=1.8
-org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
-org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
-org.eclipse.jdt.core.compiler.source=1.8
+++ /dev/null
-Manifest-Version: 1.0
-Bundle-ManifestVersion: 2
-Bundle-Name: SCL Workbench Editor
-Bundle-SymbolicName: org.simantics.scl.ui.editor
-Bundle-Version: 0.1.3
-Bundle-RequiredExecutionEnvironment: JavaSE-1.8
-Require-Bundle: org.eclipse.swt;bundle-version="3.104.0",
- gnu.trove3;bundle-version="3.0.3",
- org.simantics.scl.compiler.dummy;bundle-version="0.0.9",
- org.simantics.scl.runtime;bundle-version="0.0.9",
- org.eclipse.jface;bundle-version="3.11.0",
- org.eclipse.jface.text;bundle-version="3.6.0",
- org.eclipse.core.runtime;bundle-version="3.11.0",
- org.eclipse.ui.workbench.texteditor;bundle-version="3.6.0",
- org.eclipse.ui.editors;bundle-version="3.6.0"
-Export-Package: org.simantics.scl.ui.editor
-Bundle-Vendor: VTT Technical Research Centre of Finland
+++ /dev/null
-source.. = src/
-output.. = bin/
-bin.includes = META-INF/,\
- .
+++ /dev/null
-package org.simantics.scl.ui.editor;
-
-import org.eclipse.jface.resource.ImageDescriptor;
-import org.eclipse.jface.resource.ImageRegistry;
-import org.eclipse.jface.text.source.Annotation;
-import org.eclipse.jface.text.source.IAnnotationAccess;
-import org.eclipse.jface.text.source.IAnnotationAccessExtension;
-import org.eclipse.jface.text.source.ImageUtilities;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.graphics.GC;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.graphics.Rectangle;
-import org.eclipse.swt.widgets.Canvas;
-
-final class SCLAnnotationAccess implements IAnnotationAccess, IAnnotationAccessExtension {
-
- ImageRegistry registry;
-
- public SCLAnnotationAccess(ImageRegistry registry) {
- this.registry = registry;
- }
-
- @Override
- public Object getType(Annotation annotation) {
- return annotation.getType();
- }
-
- @Override
- public boolean isMultiLine(Annotation annotation) {
- return true;
- }
-
- @Override
- public boolean isTemporary(Annotation annotation) {
- return !annotation.isPersistent();
- }
-
- @Override
- public String getTypeLabel(Annotation annotation) {
- return annotation.getType();
- }
-
- @Override
- public int getLayer(Annotation annotation) {
- return 0;
- }
-
- @Override
- public void paint(Annotation annotation, GC gc, Canvas canvas, Rectangle bounds) {
- Image image = registry.get("error");
- if(image == null) {
- registry.put("error", ImageDescriptor.createFromFile(getClass(), "error_tsk.gif"));
- image = registry.get("error");
- }
- ImageUtilities.drawImage(image, gc, canvas, bounds, SWT.CENTER, SWT.TOP);
- }
-
- @Override
- public boolean isPaintable(Annotation annotation) {
- return true;
- }
-
- @Override
- public boolean isSubtype(Object annotationType, Object potentialSupertype) {
- return annotationType.equals(potentialSupertype);
- }
-
- @Override
- public Object[] getSupertypes(Object annotationType) {
- return new Object[0];
- }
-}
\ No newline at end of file
+++ /dev/null
-package org.simantics.scl.ui.editor;
-
-import org.eclipse.jface.text.DefaultTextHover;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.ITextHover;
-import org.eclipse.jface.text.TextAttribute;
-import org.eclipse.jface.text.presentation.IPresentationReconciler;
-import org.eclipse.jface.text.presentation.PresentationReconciler;
-import org.eclipse.jface.text.rules.DefaultDamagerRepairer;
-import org.eclipse.jface.text.rules.IRule;
-import org.eclipse.jface.text.rules.ITokenScanner;
-import org.eclipse.jface.text.rules.IWordDetector;
-import org.eclipse.jface.text.rules.MultiLineRule;
-import org.eclipse.jface.text.rules.PatternRule;
-import org.eclipse.jface.text.rules.RuleBasedScanner;
-import org.eclipse.jface.text.rules.Token;
-import org.eclipse.jface.text.rules.WordRule;
-import org.eclipse.jface.text.source.DefaultAnnotationHover;
-import org.eclipse.jface.text.source.IAnnotationHover;
-import org.eclipse.jface.text.source.ISharedTextColors;
-import org.eclipse.jface.text.source.ISourceViewer;
-import org.eclipse.jface.text.source.SourceViewerConfiguration;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.graphics.Device;
-import org.eclipse.swt.graphics.Font;
-import org.eclipse.swt.graphics.RGB;
-
-public class SCLSourceViewerConfiguration extends SourceViewerConfiguration {
-
- public static final char[] CONTENT_ASSIST_AUTO_CHARS = new char[] { '.' };
- Device device;
-
- ISharedTextColors sharedTextColors;
-
- public SCLSourceViewerConfiguration(Device device,
- ISharedTextColors sharedTextColors) {
- this.device = device;
- this.sharedTextColors = sharedTextColors;
- }
-
- public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) {
- return new String[] {
- IDocument.DEFAULT_CONTENT_TYPE
- };
- }
-
- public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) {
- PresentationReconciler reconciler = new PresentationReconciler();
-
- DefaultDamagerRepairer dr = new DefaultDamagerRepairer(getSclTokenScanner());
-
- reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
- reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
-
- return reconciler;
- }
-
- ITokenScanner getSclTokenScanner() {
- RuleBasedScanner scanner = new RuleBasedScanner();
-
- Font font = new Font(device, "Courier New", 10, SWT.NORMAL);
- Font boldFont = new Font(device, "Courier New", 10, SWT.BOLD);
-
- Token defaultToken = new Token(
- new TextAttribute(
- sharedTextColors.getColor(new RGB(0, 0, 0)),
- null,
- 0,
- font
- ));
- Token string = new Token(new TextAttribute(
- sharedTextColors.getColor(new RGB(42, 0, 255)),
- null,
- 0,
- font
- ));
- Token reserved = new Token(
- new TextAttribute(
- sharedTextColors.getColor(new RGB(127, 0, 85)),
- null,
- SWT.BOLD,
- boldFont
- ));
- Token comment = new Token(new TextAttribute(
- sharedTextColors.getColor(new RGB(63, 127, 95)),
- null,
- 0,
- font
- ));
-
- WordRule reservedWord = new WordRule(new IWordDetector() {
- @Override
- public boolean isWordStart(char c) {
- return Character.isJavaIdentifierStart(c);
- }
-
- @Override
- public boolean isWordPart(char c) {
- return Character.isJavaIdentifierPart(c) || c=='.';
- }
- });
-
- reservedWord.addWord("if", reserved);
- reservedWord.addWord("then", reserved);
- reservedWord.addWord("else", reserved);
- reservedWord.addWord("match", reserved);
- reservedWord.addWord("with", reserved);
- reservedWord.addWord("data", reserved);
- reservedWord.addWord("type", reserved);
- reservedWord.addWord("class", reserved);
-
- IRule[] rules = new IRule[] {
- //new MultiLineRule("\"\"\"", "\"\"\"", string),
- new PatternRule("\"", "\"", string, '\\', true),
- new MultiLineRule("/*", "*/", comment),
- new PatternRule("//", null, comment, '\0', true),
- reservedWord
- };
- scanner.setRules(rules);
- scanner.setDefaultReturnToken(defaultToken);
-
- return scanner;
- }
-
- @Override
- public ITextHover getTextHover(ISourceViewer sourceViewer, String contentType) {
- return new DefaultTextHover(sourceViewer);
- }
-
- @Override
- public IAnnotationHover getAnnotationHover(ISourceViewer sourceViewer) {
- return new DefaultAnnotationHover();
- }
-}
+++ /dev/null
-package org.simantics.scl.ui.editor;
-
-
-import java.util.Collection;
-import java.util.Iterator;
-
-import org.eclipse.jface.resource.ImageRegistry;
-import org.eclipse.jface.text.Document;
-import org.eclipse.jface.text.ITextListener;
-import org.eclipse.jface.text.Position;
-import org.eclipse.jface.text.TextEvent;
-import org.eclipse.jface.text.source.Annotation;
-import org.eclipse.jface.text.source.AnnotationModel;
-import org.eclipse.jface.text.source.AnnotationPainter;
-import org.eclipse.jface.text.source.IAnnotationModel;
-import org.eclipse.jface.text.source.ISharedTextColors;
-import org.eclipse.jface.text.source.OverviewRuler;
-import org.eclipse.jface.text.source.SourceViewer;
-import org.eclipse.jface.text.source.VerticalRuler;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.KeyAdapter;
-import org.eclipse.swt.events.KeyEvent;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.graphics.RGB;
-import org.eclipse.swt.layout.FillLayout;
-import org.eclipse.swt.widgets.Composite;
-import org.simantics.scl.compiler.ErrorMessage;
-import org.simantics.scl.compiler.InvalidInputException;
-import org.simantics.scl.compiler.SCLCompiler;
-import org.simantics.scl.compiler.SCLCompilerConfiguration;
-
-public class SCLTextEditor extends Composite {
-
- private static final int DELAY_BEFORE_COMPILATION = 500 /*ms*/;
-
- SCLCompilerConfiguration configuration;
-
- SourceViewer viewer;
- ImageRegistry imageRegistry;
- SCLAnnotationAccess annotationAccess;
- ISharedTextColors sharedTextColors;
- IAnnotationModel annotationModel;
-
- public SCLTextEditor(Composite parent, int style, SCLCompilerConfiguration configuration) {
- super(parent, style);
- setLayout(new FillLayout());
-
- this.configuration = configuration;
-
- imageRegistry = new ImageRegistry(parent.getDisplay());
- annotationAccess = new SCLAnnotationAccess(imageRegistry);
- sharedTextColors = new SharedTextColors(getDisplay());
- annotationModel = new AnnotationModel();
-
- VerticalRuler leftRuler = new VerticalRuler(12, annotationAccess);
- leftRuler.setModel(annotationModel);
-
- OverviewRuler rightRuler =
- new OverviewRuler(annotationAccess, 12, sharedTextColors);
- rightRuler.setModel(annotationModel);
- rightRuler.addAnnotationType("error");
- rightRuler.setAnnotationTypeLayer("error", 0);
- rightRuler.setAnnotationTypeColor("error", sharedTextColors.getColor(new RGB(255,0,128)));
-
- viewer = new SourceViewer(this,
- leftRuler, rightRuler,
- true,
- SWT.H_SCROLL | SWT.V_SCROLL);
- Document document = new Document();
- viewer.setDocument(document, annotationModel);
- viewer.setEditable(true);
- viewer.configure(new SCLSourceViewerConfiguration(
- getDisplay(), sharedTextColors));
-
- // Annotations to text area
- AnnotationPainter annotationPainter =
- new AnnotationPainter(viewer, annotationAccess);
- annotationPainter.addAnnotationType("error");
- annotationPainter.setAnnotationTypeColor("error", sharedTextColors.getColor(new RGB(255,0,128)));
- viewer.addPainter(annotationPainter);
- annotationModel.addAnnotationModelListener(annotationPainter);
-
- // Undo support (maybe not needed in workbench?)
- viewer.getTextWidget().addKeyListener(new KeyAdapter() {
- @Override
- public void keyReleased(KeyEvent e) {
- }
- @Override
- public void keyPressed(KeyEvent e) {
- if(e.keyCode=='z'&& e.stateMask == SWT.CTRL) {
- viewer.getUndoManager().undo();
- }
- else if(e.keyCode=='y'&& e.stateMask == SWT.CTRL) {
- viewer.getUndoManager().redo();
- }
- }
- });
-
- // Automatic compilation when text changes
- viewer.addTextListener(new ITextListener() {
- @Override
- public void textChanged(TextEvent event) {
- scheduleCompilation();
- }
- });
- }
-
- @Override
- public void dispose() {
- super.dispose();
- sharedTextColors.dispose();
- }
-
- @SuppressWarnings("unchecked")
- private void removeAnnotations() {
- Iterator<Annotation> it = annotationModel.getAnnotationIterator();
- while(it.hasNext()) {
- Annotation annotation = it.next();
- annotationModel.removeAnnotation(annotation);
- }
- }
-
- private void setAnnotations(Collection<ErrorMessage> messages) {
- removeAnnotations();
- for(ErrorMessage message : messages) {
- annotationModel.addAnnotation(
- new Annotation("error", true, message.getMessage()),
- new Position(message.getStart(), message.getStop()-message.getStart()+1));
- }
- }
-
- /**
- * Tries to compile current
- */
- private void compileSync(String code) {
- try {
- SCLCompiler.compileExpression(configuration, code);
- getDisplay().asyncExec(new Runnable() {
- @Override
- public void run() {
- removeAnnotations();
- }
- });
- } catch (final InvalidInputException e) {
- getDisplay().asyncExec(new Runnable() {
- @Override
- public void run() {
- setAnnotations(e.getErrors());
- }
- });
- } catch(Exception e) {
- e.printStackTrace();
- }
- }
-
- Object compilationLock = new Object();
- String codeToBeCompiled;
-
- private synchronized void scheduleCompilation() {
- synchronized(compilationLock) {
- if(codeToBeCompiled == null) {
- new Thread("SCLTextEditor compilation") {
- public void run() {
- while(true) {
- String code;
- // Waits until code has remained unmodified for
- // time specified by DELAY_BEFORE_COMPILATION.
- synchronized(compilationLock) {
- do {
- code = codeToBeCompiled;
- try {
- compilationLock.wait(DELAY_BEFORE_COMPILATION);
- } catch (InterruptedException e) {
- }
- } while(!code.equals(codeToBeCompiled));
- }
-
- // Does the actual compilation and updates
- // annotations.
- compileSync(code);
-
- // If code was not modified during compilation,
- // exits the compilation thread and sets
- // codeToBeCompiled null to signal inactivity.
- synchronized(compilationLock) {
- if(code.equals(codeToBeCompiled)) {
- codeToBeCompiled = null;
- return;
- }
- }
- }
- }
- }.start();
- }
- codeToBeCompiled = viewer.getDocument().get();
- compilationLock.notify();
- }
- }
-
- public String getContent() {
- final String[] result = new String[1];
- getDisplay().syncExec(new Runnable() {
- @Override
- public void run() {
- result[0] = viewer.getDocument().get();
- }
- });
- return result[0];
- }
-
- public void setContent(final String content) {
- getDisplay().asyncExec(new Runnable() {
- @Override
- public void run() {
- if (viewer.getTextWidget().isDisposed()) return;
- viewer.getDocument().set(content);
- }
- });
- }
-
- private Point storedSelectedRange;
-
- public void storeSelectedRange() {
- storedSelectedRange = viewer.getSelectedRange();
- }
-
- public void restoreSelectedRange() {
- if (storedSelectedRange != null) {
- viewer.setSelectedRange(storedSelectedRange.x, storedSelectedRange.y);
- storedSelectedRange = null;
- }
- }
-
-}
+++ /dev/null
-package org.simantics.scl.ui.editor;
-
-import gnu.trove.map.hash.THashMap;
-
-import org.eclipse.jface.text.source.ISharedTextColors;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.graphics.RGB;
-import org.eclipse.swt.widgets.Display;
-
-final class SharedTextColors implements ISharedTextColors {
-
- Display display;
- THashMap<RGB,Color> map = new THashMap<RGB,Color>();
-
- public SharedTextColors(Display display) {
- this.display = display;
- }
-
- @Override
- public Color getColor(RGB rgb) {
- Color color = map.get(rgb);
- if(color == null) {
- color = new Color(display, rgb);
- map.put(rgb, color);
- }
- return color;
- }
-
- @Override
- public void dispose() {
- for(Color color : map.values())
- color.dispose();
- map.clear();
- }
-}
\ No newline at end of file
+++ /dev/null
-package org.simantics.scl.ui.editor;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.custom.SashForm;
-import org.eclipse.swt.events.KeyAdapter;
-import org.eclipse.swt.events.KeyEvent;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.graphics.Font;
-import org.eclipse.swt.layout.FillLayout;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Event;
-import org.eclipse.swt.widgets.Listener;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.swt.widgets.Text;
-import org.simantics.scl.compiler.SCLCompiler;
-import org.simantics.scl.compiler.StandardSCLCompilerConfiguration;
-
-public class TestTextEditor {
-
- public static void main(String[] args) {
- Display display = new Display();
- final Shell shell = new Shell(display);
- shell.setText("SCL text widget example");
- shell.setLayout(new FillLayout());
-
- SashForm sashForm = new SashForm(shell, SWT.VERTICAL);
-
- final SCLTextEditor editor = new SCLTextEditor(sashForm, 0, StandardSCLCompilerConfiguration.INSTANCE);
- editor.setContent(
- "// Difficulty: 0\n" +
- "// Expected: [2.0, 3.0, 5.0, 7.0, 11.0, 13.0, 17.0, 19.0]\n\n" +
- "// and : [Boolean] -> Boolean\n" +
- "and = fold (&&) True\n\n" +
- "// isPrime : Integer -> Boolean\n" +
- "isPrime p = and (\n" +
- " d <- [2 .. sqrt p]\n" +
- " [p % d > 0]\n" +
- ")\n\n" +
- "x <- [2 .. 20]\n" +
- "isPrime x\n" +
- "[x]"
- );
-
- final Text resultArea = new Text(sashForm, SWT.MULTI | SWT.WRAP | SWT.V_SCROLL);
- resultArea.setText("Ctrl-S executes the code.");
- resultArea.setEditable(false);
- resultArea.setBackground(new Color(shell.getDisplay(), 255, 255, 255));
- resultArea.setFont(new Font(shell.getDisplay(), "Courier New", 10, SWT.NORMAL));
-
- sashForm.setWeights(new int[] {5, 1});
-
- display.addFilter(SWT.KeyDown, new Listener() {
- @Override
- public void handleEvent(Event event) {
- if(event.keyCode == 's' && event.stateMask == SWT.CTRL) {
- final String code = editor.getContent();
- new Thread() {
- public void run() {
- try {
- final String result = SCLCompiler.compileExpression(StandardSCLCompilerConfiguration.INSTANCE, code).execute().toString();
- shell.getDisplay().asyncExec(new Runnable() {
- public void run() {
- resultArea.setText(result);
- }
- });
- } catch (Exception e) {
- }
- }
- }.start();
- event.doit = false;
- }
- }
- });
- shell.addKeyListener(new KeyAdapter() {
- @Override
- public void keyPressed(KeyEvent e) {
- System.out.println(e);
- }
- });
-
- shell.open();
- while (!shell.isDisposed ()) {
- if (!display.readAndDispatch ()) display.sleep ();
- }
- display.dispose ();
- }
-
-}
org.simantics.diagram.ontology;bundle-version="1.0.0",
org.simantics.structural.ontology;bundle-version="1.0.0",
org.simantics.basicexpression;bundle-version="1.0.0",
- org.simantics.scl.compiler.dummy;bundle-version="0.1.2",
org.simantics.db.layer0;bundle-version="1.1.0",
org.simantics.scl.db;bundle-version="0.1.2",
org.simantics.scl.runtime;bundle-version="0.1.2",
<module>org.simantics.scenegraph.ui</module>
<module>org.simantics.scl.commands</module>
<module>org.simantics.scl.compiler</module>
- <module>org.simantics.scl.compiler.dummy</module>
<module>org.simantics.scl.data</module>
<module>org.simantics.scl.db</module>
<module>org.simantics.scl.expressions</module>
<module>org.simantics.scl.reflection</module>
<module>org.simantics.scl.runtime</module>
<module>org.simantics.scl.ui</module>
- <module>org.simantics.scl.ui.editor</module>
<module>org.simantics.selectionview</module>
<module>org.simantics.selectionview.ontology</module>
<module>org.simantics.selectionview.ui.ontology</module>
version="0.0.0"
unpack="false"/>
- <plugin
- id="org.simantics.scl.ui.editor"
- download-size="0"
- install-size="0"
- version="0.0.0"
- unpack="false"/>
-
</feature>
version="0.0.0"
unpack="false"/>
- <plugin
- id="org.simantics.scl.compiler.dummy"
- download-size="0"
- install-size="0"
- version="0.0.0"
- unpack="false"/>
-
- <plugin
- id="org.simantics.scl.ui.editor"
- download-size="0"
- install-size="0"
- version="0.0.0"
- unpack="false"/>
-
<plugin
id="org.simantics.scl.db"
download-size="0"