Archi Forum

Archi Plug-ins => jArchi => Topic started by: rchevallier on April 07, 2020, 17:00:55 PM

Title: swt dialog box example in jarchi
Post by: rchevallier on April 07, 2020, 17:00:55 PM
Hi all,

Based on the work of Hervé, but using SWT/Jface instead of Swing to have the same look and feel as Archi, I've developed a configuration dialog box script which can serve as example if you need something similar. Caveat: you need to understand swt widgets and layout.

You can find the code here: https://gist.github.com/rchevallier/d155527dcc3e956848a90e51bf21d7e1 (https://gist.github.com/rchevallier/d155527dcc3e956848a90e51bf21d7e1)

NB: Using VsCode for coding in Javascript, I added some type annotation for type checking functionality of this IDE

Title: Re: swt dialog box example in jarchi
Post by: Jean-Baptiste Sarrodie on April 07, 2020, 19:06:45 PM
Hi,

Great! Thank you!

I was missing such example.

Regards,

JB
Title: Re: swt dialog box example in jarchi
Post by: Phil Beauvoir on April 07, 2020, 19:58:55 PM
Yes, thank-you very much for sharing. That's what this forum is all about, users helping each other and sharing. Nice. :-)

Phil
Title: Re: swt dialog box example in jarchi
Post by: rchevallier on April 10, 2020, 14:48:04 PM
And if anyone has remarks for improvement, please don't hesitate (my 1st code in js, I'm more of a java, scala, python guy) :)
Title: Re: swt dialog box example in jarchi
Post by: Manj75 on June 14, 2021, 09:09:17 AM
I came across this post and the script looked interesting, but on trying it out I get an exception. Is this meant to work straight out of the zip file or am I missing a step?

Script Error: javax.script.ScriptException: SyntaxError: file:/C:/Users/Manjit/AppData/Roaming/Archi4/scripts/JFaceConfigDialog.ajs:22:23 Expected an operand but found const
/** @type JavaClass */ const SWT = Java.type('org.eclipse.swt.SWT')
                       ^ in <eval> at line number 1


Appreciate any help to get this working as it would be great to use for same look and feel of Archi.
Title: Re: swt dialog box example in jarchi
Post by: Phil Beauvoir on June 14, 2021, 09:35:28 AM
Some of the code in the script is not supported by JS ES5.

In Archi Preferences, Scripting, choose "Nashorn ES6" or "GraalVM".
Title: Re: swt dialog box example in jarchi
Post by: Manj75 on June 14, 2021, 09:44:36 AM
Thanks Phil - Nashorn ES6 sorted it
Title: Re: swt dialog box example in jarchi
Post by: rchevallier on June 14, 2021, 10:55:37 AM
Thanks Phil
It was not clear indeed it requires ES6 or above
Added a comment in the gist
Title: Re: swt dialog box example in jarchi
Post by: fanievh on September 03, 2023, 13:55:36 PM
Apologies for replying to such an old thread. I've been searching to find an example of adding a SWT.Selection listener to buttons using rchevallier's script as the base. I have made changes to the script and it is working for my use case but now need to add a selection listener to a specific button to update something on the dialog.  All the examples available are Java examples but I can't seem to find a Javascript / Graalvm / JArchi example.  The Java examples are typically as follows:

    button.addListener( SWT.Selection, new Listener() {
      public void handleEvent( Event e ) {
        // do something
      }
    } );

How would I do it if I added a listener to rchevaillier's script?

A similar question was asked in this thread but I don't know what the eventual resolution was: https://forum.archimatetool.com/index.php?topic=1088.msg5809#msg5809

Thanks in advance for any possible assistance
Title: Re: swt dialog box example in jarchi
Post by: Phil Beauvoir on September 03, 2023, 14:35:23 PM
Try this:

button.addListener(SWT.Selection, event => {
    console.log(event);
});

Title: Re: swt dialog box example in jarchi
Post by: fanievh on September 03, 2023, 16:44:10 PM
Thank you so much, that works!!
Title: Re: swt dialog box example in jarchi
Post by: rchevallier on September 04, 2023, 14:17:30 PM
@fanievh Since then, I've developped more extensive use of SWT by jArchi.
In case this can be helpful, you'll find the code there: https://github.com/rchevallier/jarchi-lib/blob/main/doc/Colormap%20wizard.md (and https://github.com/rchevallier/jarchi-lib/blob/main/scripts/lib/colormap/UI.js)
Title: Re: swt dialog box example in jarchi
Post by: fanievh on October 18, 2023, 14:46:51 PM
Thank you @rchevallier, I just had a brief look at your example and it looks very good!