Archi Forum

Archi Plug-ins => jArchi => Topic started by: Thomas Rohde on November 16, 2022, 03:56:31 AM

Title: A simple promptSelection function
Post by: Thomas Rohde on November 16, 2022, 03:56:31 AM
I sometimes need a prompt to select from a list. As it turns out this is simple:

window.promptSelection = function (title, choices) {
    var ElementListSelectionDialog = Java.type('org.eclipse.ui.dialogs.ElementListSelectionDialog');
    var LabelProvider = Java.type('org.eclipse.jface.viewers.LabelProvider');
    var dialog = new ElementListSelectionDialog(shell, new LabelProvider());

    dialog.setElements(choices);
    dialog.setTitle(title);
    dialog.open();
    return dialog.getResult();
}

// Test it
let answer = window.promptSelection("Is everything OK?", ["Yes", "Maybe", "No"]);
console.log(answer);

Maybe this could be added to init.js?
Title: Re: A simple promptSelection function
Post by: Thomas Rohde on November 16, 2022, 05:15:40 AM
Change the return statement to return a proper Javascript string:

return new String(dialog.getResult());
Title: Re: A simple promptSelection function
Post by: Jean-Baptiste Sarrodie on November 16, 2022, 13:46:52 PM
Hi,

Quote from: Thomas Rohde on November 16, 2022, 03:56:31 AMMaybe this could be added to init.js?

Yes, makes sense.

Could you share the code as a Gist and open an issue on GitHub (https://github.com/archimatetool/archi-scripting-plugin/issues).

Regards,

JB