]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.views.swt.client/src/org/simantics/views/swt/client/impl/SWTBrowser.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.views.swt.client / src / org / simantics / views / swt / client / impl / SWTBrowser.java
1 package org.simantics.views.swt.client.impl;
2
3 import org.eclipse.jface.layout.GridDataFactory;
4 import org.eclipse.jface.layout.GridLayoutFactory;
5 import org.eclipse.swt.browser.Browser;
6 import org.eclipse.swt.browser.LocationEvent;
7 import org.eclipse.swt.browser.LocationListener;
8 import org.eclipse.swt.widgets.Composite;
9 import org.simantics.db.layer0.variable.Variable;
10 import org.simantics.scl.runtime.function.Function1;
11 import org.simantics.utils.datastructures.map.Tuple;
12 import org.simantics.views.swt.client.base.SingleSWTViewNode;
13
14 public class SWTBrowser extends SingleSWTViewNode<Browser> {
15         
16         private static final long serialVersionUID = -2704760050046054447L;
17         
18         public String                     document;
19         public Variable                   variable;
20         public Function1<Object, Boolean> locationChanging;
21
22         private Tuple                     lastAppliedParametrization;
23
24         @Override
25         public void reset() {
26                 super.reset();
27                 lastAppliedParametrization = null;
28         }
29         
30         @Override
31         public void createControls(Composite parent) {
32
33                 GridDataFactory.fillDefaults().grab(true, true).applyTo(parent);
34                 GridLayoutFactory.fillDefaults().applyTo(parent);
35
36                 control = new Browser(parent, style);
37                 GridDataFactory.fillDefaults().grab(true, true).applyTo(control);
38
39                 control.addLocationListener(new LocationListener() {
40                         @Override
41                         public void changing(LocationEvent event) {
42                                 Function1<Object, Boolean> lc = locationChanging;
43                                 if (lc != null)
44                                         lc.apply(event);
45                         }
46                         @Override
47                         public void changed(LocationEvent event) {
48                         }
49                 });
50
51                 setProperties();
52
53         }
54
55         public void synchronizeVariable(Variable variable) {
56                 
57         }
58
59         public void synchronizeDocument(final String document) {
60                 
61                 if(document != null) {
62                         
63                         final Variable variable = SWTBrowser.this.variable;
64                         if (variable == null) {
65                                 return;
66                         }
67
68                         Tuple checkParam = new Tuple(document, variable);
69                         if (checkParam.equals(lastAppliedParametrization))
70                                 return;
71                         
72                         lastAppliedParametrization = checkParam;
73                                 
74                         final Browser control = this.control;
75                         if (control == null)
76                                 return;
77                         control.setText(document);
78                         
79                 }
80         }
81
82 }