A simple promptSelection function

Started by Thomas Rohde, November 16, 2022, 03:56:31 AM

Previous topic - Next topic

Thomas Rohde

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?

Thomas Rohde

Change the return statement to return a proper Javascript string:

return new String(dialog.getResult());

Jean-Baptiste Sarrodie

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.

Regards,

JB
If you value and use Archi, please consider making a donation!
Ask your ArchiMate related questions to the ArchiMate Community's Discussion Board.