new InputDialog(Shell parentShell, String dialogTitle, String dialogMessage, String initialValue, IInputValidator validator) : InputDialog « org.eclipse.jface.dialogs « Java by API






new InputDialog(Shell parentShell, String dialogTitle, String dialogMessage, String initialValue, IInputValidator validator)

import org.eclipse.jface.dialogs.IInputValidator;
import org.eclipse.jface.dialogs.InputDialog;
import org.eclipse.jface.window.ApplicationWindow;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class MainClass extends ApplicationWindow {
  public MainClass() {
    super(null);
  }

  public void run() {
    setBlockOnOpen(true);
    open();
    Display.getCurrent().dispose();
  }

  protected void configureShell(Shell shell) {
    super.configureShell(shell);
    shell.setText("Send Message");
    shell.setSize(500, 400);

    InputDialog dlg = new InputDialog(Display.getCurrent().getActiveShell(),
        "", "Enter 5-8 characters", "info", new LengthValidator());
    if (dlg.open() == Window.OK) {
      System.out.println(dlg.getValue());
    }
  }

  public static void main(String[] args) {
    new MainClass().run();
  }
}

class LengthValidator implements IInputValidator {
  public String isValid(String newText) {
    int len = newText.length();
    if (len < 5) return "Too short";
    if (len > 8) return "Too long";
    return null;
  }
}
           
       








Related examples in the same category