@Retention(value=SOURCE) @Target(value=METHOD) public @interface HTMLDialog
<html> <head> <!-- btw. use data-netbeans-css attribute to control the CSS --> <title>Base question</title> <meta charset="UTF-8"> </head> <body> <div>Hello World! How are you?</div> <-- you need to check the checkbox to enabled the OK button --> <input type="checkbox" data-bind="checked: ok">OK?<br> <-- enabled with checkbox is checked --> <button id='ok' hidden data-bind="enable: ok">Good</button> <button id='bad' hidden>Bad</button> </body> </html>Java Source AskQuestion.java
@Model
(className = "AskCtrl", properties = {@Property
(name = "ok", type = boolean.class) }) public final class AskQuestion implements ActionListener {@HTMLDialog
(url = "dialog.html") static void showHelloWorld(boolean checked) { new AskCtrl(checked).applyBindings(); }@Override
public void actionPerformed(ActionEvent
e) { // shows dialog with a question, checkbox is checked by default //Pages
is automatically generated class String ret = Pages.showHelloWorld(true); System.out.println("User selected: " + ret); } }
The method is generated into Pages
class in the same package
(unless one changes the name via className()
) and has the same name,
and parameters as the method annotated by this annotation. When the method
is invoked, it opens a dialog, loads an HTML page into it. When the page is
loaded, it calls back the method annotated by this annotation and passes it
its own arguments. The method is supposed to make the page live, preferrably
by using Model
generated class and calling
applyBindings()
on it.
The HTML page may contain hidden <button>
elements. If it does so,
those buttons are copied to the dialog frame and displayed underneath the page.
Their enabled/disabled state reflects the state of the buttons in the page.
When one of the buttons is selected, the dialog closes and the generated
method returns with 'id' of the selected button (or null
if
the dialog was closed).
By default, if the HTML defines no hidden
<button>
elements, two buttons are added. One representing
the OK choice (with id="OK"
) and one representing
the cancel choice (with null
id). Both buttons are always
enabled. One can check the
return value from the dialog showing method
to be "OK"
to know whether the
user approved the dialog.
public abstract String url
nbresloc
protocol - as such the HTML page can be L10Ned
later by adding classical L10N suffixes. E.g. index_cs.html
will take preceedence over index.html
if the user is
running in Czech Locale
.public abstract String className
public abstract String[] techIds
technology ids
. One can specify the preferred ones
to use in this NetBeans component by using this attribute.Built on June 4 2024. | Copyright © 2017-2024 Apache Software Foundation. All Rights Reserved.