1 package org.simantics.views.swt.client.impl;
3 import org.eclipse.jface.layout.GridDataFactory;
4 import org.eclipse.jface.layout.GridLayoutFactory;
5 import org.eclipse.mylyn.wikitext.parser.MarkupParser;
6 import org.eclipse.swt.browser.Browser;
7 import org.eclipse.swt.widgets.Composite;
8 import org.simantics.Simantics;
9 import org.simantics.browsing.ui.common.ErrorLogger;
10 import org.simantics.db.ReadGraph;
11 import org.simantics.db.exception.DatabaseException;
12 import org.simantics.db.layer0.variable.Variable;
13 import org.simantics.db.request.Read;
14 import org.simantics.scl.runtime.function.Function1;
15 import org.simantics.utils.datastructures.map.Tuple;
16 import org.simantics.views.swt.client.base.SingleSWTViewNode;
17 import org.simantics.wiki.ui.SimanticsDialect;
18 import org.simantics.wiki.ui.language.MediaWikiLanguage;
20 public class SWTWikiBrowser extends SingleSWTViewNode<Browser> {
22 private static final long serialVersionUID = 5826022972081217837L;
24 public String document;
25 public Variable variable;
26 public Function1<String, Boolean> navigate;
27 public Variable edited;
29 private Tuple lastAppliedParametrization;
34 lastAppliedParametrization = null;
38 public void createControls(Composite parent) {
40 GridDataFactory.fillDefaults().grab(true, true).applyTo(parent);
41 GridLayoutFactory.fillDefaults().applyTo(parent);
43 control = new Browser(parent, style);
44 GridDataFactory.fillDefaults().grab(true, true).applyTo(control);
50 public void synchronizeVariable(Variable variable) {
54 public void synchronizeEdited(Variable edited) {
55 propertyCallback.apply("edited", edited);
58 public void synchronizeDocument(final String document) {
60 if(document != null) {
62 final Variable variable = SWTWikiBrowser.this.variable;
63 if (variable == null) {
67 Tuple checkParam = new Tuple(document, variable);
68 if (checkParam.equals(lastAppliedParametrization))
71 lastAppliedParametrization = checkParam;
75 String markup = Simantics.getSession().syncRequest(new Read<String>() {
77 public String perform(ReadGraph graph) throws DatabaseException {
78 return SimanticsDialect.INSTANCE.apply(graph, variable, document);
82 MarkupParser markupParser = new MarkupParser();
83 MediaWikiLanguage language = new MediaWikiLanguage();
84 markupParser.setMarkupLanguage(language);
85 String htmlContent = markupParser.parseToHtml(markup);
86 if (htmlContent == null)
89 final Browser control = this.control;
92 control.setText(htmlContent);
94 } catch (DatabaseException e) {
95 ErrorLogger.defaultLogError(e);