... | ... | @@ -14,4 +14,50 @@ The final result should look like this: |
|
|
|
|
|
<img src="/uploads/fe1a1897b773194d50daad49cb3eedf2/corefViewOpened.PNG" alt="MVC of the editor and the views" style="width: 640px;" style="height: 480px;" align="middle"/>
|
|
|
|
|
|
But of course we want to use Web technologies instead of SWT widgets. During this tutorial i am making use of the famous Bootstrap framework for styling your UI Elements. |
|
|
\ No newline at end of file |
|
|
But of course we want to use Web technologies instead of SWT widgets. During this tutorial i am making use of the famous Bootstrap framework for styling your UI Elements.
|
|
|
|
|
|
## How can you establish a communication between Java and HTML using SWT
|
|
|
|
|
|
Probably the most interesting question if you want to start writing your view in ```HTML```.
|
|
|
|
|
|
The communication works in both directions, let us look at it using an example. We create a subclass of ```Composite``` and create our HTML view inside. This results in the following class
|
|
|
|
|
|
```java
|
|
|
public class CorefViewHTMLComposite extends Composite {
|
|
|
|
|
|
private Browser browser;
|
|
|
|
|
|
private CorefView controller;
|
|
|
|
|
|
public CorefViewHTMLComposite(Composite parent, int style) {
|
|
|
super(parent, style);
|
|
|
}
|
|
|
|
|
|
```
|
|
|
|
|
|
Aside from the regular constructor you might notice the ```Browser``` widget. This SWT widget allows us to "simply" invoke javascript functions and vice versa.
|
|
|
|
|
|
As in most my other tutorials about writing a view you should create a ```setInput()``` method as shown here:
|
|
|
|
|
|
```java
|
|
|
public void setInput(CorefView controller) {
|
|
|
this.controller = controller;
|
|
|
|
|
|
initLayout();
|
|
|
|
|
|
initEventHandler();
|
|
|
|
|
|
}
|
|
|
```
|
|
|
|
|
|
This saves a reference to our controller, creates the initial HTML layout and registers any listener. Well you might ask this is stil all plain java, where are the Web-technologies. They start to be important if we look into ```initLayout()```
|
|
|
|
|
|
```java
|
|
|
this.setLayout(new FillLayout());
|
|
|
browser = new Browser(this, SWT.NONE);
|
|
|
|
|
|
String page = createHTMLContent();
|
|
|
|
|
|
|
|
|
browser.setText(page);
|
|
|
``` |
|
|
\ No newline at end of file |