Load ace.js. Check, you have loaded it from CDN. The @NpmPackage annotation serves no purpose if you load Ace from a CDN. You can remove that or you can change the @JsModule annotation to load the file from the npm package, something like @JsModule("ace-builds/src-noconflict/ace.js").
Define a <div> with an id attribute, the one to be used for the editor. This you get by changing @Tag("ace") to @Tag("div") (not strictly necessary) and doing e.g. setId("editor") in the constructor.
Tell Ace about the div that should be made into an editor:
var editor = ace.edit("editor");
editor.setTheme("ace/theme/monokai");
editor.session.setMode("ace/mode/javascript");
This you can do as getElement().executeJs("var editor = ace.edit('editor'); editor.setTheme('ace/theme/monokai');editor.session.setMode('ace/mode/javascript');");
If you do this.getElement().setProperty("theme", "ace/theme/twilight");, then you are setting the property on the DOM element but you should be setting it on the editor object returned by ace.edit it seems.
Finally, the easiest way to allow sizing the component is to implement HasSize which will add setWidth and setHeight and some other variants for you.
Thank you very much Artur. Everything works as you have suggested. The theme and mode works if set at the executeJs but if i set it at the method level its not working.
public void setFontSize(int size)
{
getElement().setProperty("editor.setFontSize",size);
}
public void setTheme() {
getElement().setProperty("editor.setTheme", "ace/theme/tomorrow");
}
If you want to access to editor object later on you need to store it. I presume it will work if you add something like this.editor = editor to your execJS code. Then the editor object will be stored as a property of the DOM element, which is what you set using getElement().setProperty
Artur Signell:
If you want to access to editor object later on you need to store it. I presume it will work if you add something like this.editor = editor to your execJS code. Then the editor object will be stored as a property of the DOM element, which is what you set using getElement().setProperty