java - Modify Listener on Text Field -
I've added the modified listener to the text field, when I try to open the dialog, then the revised listener event is active
UserNameDialog dialog = New UserNameDialog (PlatformUI.getWorkbench (). GetActiveWorkbenchWindow (). GetShell (), True) ; Dialog.init ("", userSession.hasAdminRights (), false, true, false, ""); Dialog.open (); If (dialog.getReturnCode () == Window CANCEL) {return; }
Dialog class
Public class UserNameDialog TitleAreaDialog {Private text txtUsername; @ Override Protected Control Bundiologue (composite parent) {setMessage ("enter user information and press OK"); SetTitle ("user information"); Composite region = (holistic) super.Credidiologia (guardian); Composite Container = New Composite (Area, SWT.NONE); Container.Settleout (new grid layout (2, wrong)); Container.SettleHand Data (new grid data (SWT.FILL, SWT.FILL, true, true, 1, 1)); Label lblUserName = new label (container, SWT.NONE); LblUserName.setText ("username"); TxtUsername = new text (container, SWT.BORDER); TxtUsername.setLayoutData (new grid data (SWT.FILL, SWT.CENTER, true, incorrect, 1, 1)); TxtUsername.addListener (SWT.Modify, new listener) {@Override Public void handheldEvent {event} {getButton (IDialogConstants.OK_ID) .Set non-static (isValidUsername ()); // As I try to open the dialogue, the handler comes here and throws an exception to getButton (IDialogConstants.OK_ID)}}); If (newUuser || current user admin) txtUsername.setEditable (true); Else txtUsername.setEditable (false); TxtUsername.setText (name); New label (container, SWT.NONE); New label (container, SWT.NONE); Return area; } / ** * Create content of the button bar. * @On Ultimate Parents * / @ Override Protected ZeroButtonsForButtonBar (Composite Parents) {okButton = createButton (Parents, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true); Create Button (Parents, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, Incorrect); OkButton.setEnabled (wrong); } Private boolean isValidUsername () {string user name = txtUsername.getText (); Return username = null & amp; Amp; Username.trim () Length ()> 0; }}
It is inside a dialog but it is called before the dialog is created which I think because okButton is zero
OK, here's an example of a dialog, which will enable OK button if the user name is at least one letter:
private lessons; Protected UserMediaLog (shell parent shell) {super (parent shell); } @ Override protected zero configured shell (shell new shell) {super.configure shell (new shell); NewShell.setText ("dialog"); } @ Override Protected Control RadiationOogerea (Composite Parent) {Composite Container = (Composite) Super. Cratediologia (Guardian); Text = new text (container, SWT.BORDER); Text.setLayoutData (New Grid Data (SWT.BEGINNING, SWT.CENTER, Incorrect, Incorrect)); Text.addListener (SWT.Modify, new listener) {@Override public void handleEvent (event event) {getButton (IDialogConstants.OK_ID) .setEnabled (isValidUsername ());}}); Return container; } Private boolean isValidUsername () {string user name = text.getText (); Return username = null & amp; Amp; Username.trim () Length ()> 0; } @ Override protected void () (if (isValidUsername ()) super.okPressed (); Else System.out.println ( "Invalid user name");} @ Override protected void Bnanebrtnsforbtnbar (Composite parent) {createButton (Guardian , IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true); button to (parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false); GetButton (IDialogConstantskOK_ID) KsetEnabled (false);} public static void main (string [] args) {New User Name Below (New Shell ()). Open ();}
Comments
Post a Comment