X

Geertjan's Blog

  • November 27, 2012

Embedded Nashorn in JEditorPane

Geertjan Wielenga
Product Manager

Here's a prototype for some kind of backoffice content management system. Several interesting goodies are included, such as an embedded JavaScript editor, as can be seen in the screenshot:

Key items of interest in the above are as follows:

  • Embedded JavaScript editor (i.e., the latest and greatest Nashorn technology, look it up, if you're not aware of what that is.) The way that's done is to include the relevant JavaScript modules in your NetBeans Platform application. Make very sure to include "Lexer to NetBeans Bridge", which does a bunch of critical stuff under the hood. The JEditorPane is defined as follows, along the lines that I blogged about recently thanks to Steven Yi:

    javaScriptPane.setContentType("text/javascript");
    EditorKit kit = CloneableEditorSupport.getEditorKit("text/javascript");
    javaScriptPane.setEditorKit(kit);
    javaScriptPane.getDocument().putProperty("mimeType", "text/javascript");

    Note that "javaScriptPane" above is simply a JEditorPane.

  • Timon Veenstra's excellent solution for integrating Nodes with MultiViewElements, which is described here by Timon, and nowhere else in the world. The tab you see above is within a pluggable container, so anyone else could create a new module and register their own MultiViewElement such that it will be incorporated into the editor.

  • A small trick to ensure that only one window opens per news item:

    @NbBundle.Messages("OpenNews=Open")
    private class OpenNewsAction extends AbstractAction {
    public OpenNewsAction() {
    super(Bundle.OpenNews());
    }
    @Override
    public void actionPerformed(ActionEvent e) {
    News news = getLookup().lookup(News.class);
    Mode editorMode = WindowManager.getDefault().findMode("editor");
    for (TopComponent tc : WindowManager.getDefault().getOpenedTopComponents(editorMode)) {
    if (tc.getDisplayName().equals(news.getTitle())) {
    tc.requestActive();
    return;
    }
    }
    TopComponent tc = MultiViews.createMultiView("application/x-newsnode", NewsNode.this);
    tc.open();
    tc.requestActive();
    }
    }

The rest of what you see above is all standard NetBeans Platform stuff. The sources of everything you see above is here:

http://java.net/projects/nb-api-samples/sources/api-samples/show/versions/7.3/misc/CMSBackOffice

Be the first to comment

Comments ( 0 )
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.Captcha
Oracle

Integrated Cloud Applications & Platform Services