Example usage for com.google.gwt.user.client.ui DialogBox setWidget

List of usage examples for com.google.gwt.user.client.ui DialogBox setWidget

Introduction

In this page you can find the example usage for com.google.gwt.user.client.ui DialogBox setWidget.

Prototype

@Override
    public void setWidget(Widget w) 

Source Link

Usage

From source file:com.appspot.socialinquirer.client.util.UiUtils.java

License:Apache License

/**
 * Show classification dialog./*from ww  w  . j a v  a2  s . co  m*/
 *
 * @param result the result
 * @param constants the constants
 */
public static void showClassificationDialog(List<Classification> result, EverScribeConstants constants) {
    final DialogBox dialogBox = new DialogBox();
    dialogBox.setText("Classification");
    dialogBox.setAnimationEnabled(true);
    VerticalPanel dialogVPanel = new VerticalPanel();
    dialogVPanel.setHorizontalAlignment(HasAlignment.ALIGN_CENTER);
    StringBuilder builder = new StringBuilder();
    builder.append("<table style='text-align: left; width: 100%;' border='1' cellpadding='2' cellspacing='2'>");
    builder.append("<tbody>");
    builder.append("<tr><th nowrap='nowrap'>Class</th><th nowrap='nowrap'>Probability</th></tr>");
    for (Classification classification : result) {
        builder.append("<tr><td nowrap='nowrap'>" + classification.getCategory() + "</td><td nowrap='nowrap'>"
                + classification.getProbability() + "</td></tr>");
    }
    builder.append("</tbody>");
    builder.append("</table>");
    dialogVPanel.add(new HTML(builder.toString()));
    final Button closeButton = new Button(constants.closeButton());
    closeButton.getElement().setId("closeButton");
    dialogVPanel.add(closeButton);
    dialogBox.setWidget(dialogVPanel);

    closeButton.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            dialogBox.hide();
        }
    });
    dialogBox.center();
}

From source file:com.appspot.socialinquirer.client.util.UiUtils.java

License:Apache License

/**
 * Show translation dialog./*from ww w.  j  a v a 2 s  .c  om*/
 *
 * @param result the result
 * @param constants the constants
 */
public static void showTranslationDialog(String result, EverScribeConstants constants) {
    final DialogBox dialogBox = new DialogBox();
    dialogBox.setText("Translation");
    dialogBox.setAnimationEnabled(true);
    dialogBox.setWidth("400px");
    dialogBox.setHeight("200px");
    VerticalPanel dialogVPanel = new VerticalPanel();
    dialogVPanel.add(new HTML(result));
    final Button closeButton = new Button(constants.closeButton());
    // We can set the id of a widget by accessing its
    // Element
    closeButton.getElement().setId("closeButton");
    dialogVPanel.add(closeButton);
    dialogBox.setWidget(dialogVPanel);

    closeButton.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            dialogBox.hide();
        }
    });
    dialogBox.center();
}

From source file:com.codenvy.example.gwt.client.GWTEntryPoint.java

License:Open Source License

/**
 * This is the entry point method.//www.j a  v a 2  s  .  c  o  m
 */
public void onModuleLoad() {
    final Button sendButton = new Button(messages.sendButton());
    final TextBox nameField = new TextBox();
    nameField.setText(messages.nameField());
    final Label errorLabel = new Label();

    // We can add style names to widgets
    sendButton.addStyleName("sendButton");

    // Add the nameField and sendButton to the RootPanel
    // Use RootPanel.get() to get the entire body element
    RootPanel.get("nameFieldContainer").add(nameField);
    RootPanel.get("sendButtonContainer").add(sendButton);
    RootPanel.get("errorLabelContainer").add(errorLabel);

    // Focus the cursor on the name field when the app loads
    nameField.setFocus(true);
    nameField.selectAll();

    // Create the popup dialog box
    final DialogBox dialogBox = new DialogBox();
    dialogBox.setText("Remote Procedure Call");
    dialogBox.setAnimationEnabled(true);
    final Button closeButton = new Button("Close");
    // We can set the id of a widget by accessing its Element
    closeButton.getElement().setId("closeButton");
    final Label textToServerLabel = new Label();
    final HTML serverResponseLabel = new HTML();
    VerticalPanel dialogVPanel = new VerticalPanel();
    dialogVPanel.addStyleName("dialogVPanel");
    dialogVPanel.add(new HTML("<b>Sending name to the server:</b>"));
    dialogVPanel.add(textToServerLabel);
    dialogVPanel.add(new HTML("<br><b>Server replies:</b>"));
    dialogVPanel.add(serverResponseLabel);
    dialogVPanel.setHorizontalAlignment(VerticalPanel.ALIGN_RIGHT);
    dialogVPanel.add(closeButton);
    dialogBox.setWidget(dialogVPanel);

    // Add a handler to close the DialogBox
    closeButton.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            dialogBox.hide();
            sendButton.setEnabled(true);
            sendButton.setFocus(true);
        }
    });

    // Create a handler for the sendButton and nameField
    class MyHandler implements ClickHandler, KeyUpHandler {
        /**
         * Fired when the user clicks on the sendButton.
         */
        public void onClick(ClickEvent event) {
            sendNameToServer();
        }

        /**
         * Fired when the user types in the nameField.
         */
        public void onKeyUp(KeyUpEvent event) {
            if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) {
                sendNameToServer();
            }
        }

        /**
         * Send the name from the nameField to the server and wait for a response.
         */
        private void sendNameToServer() {
            // First, we validate the input.
            errorLabel.setText("");
            String textToServer = nameField.getText();
            if (!FieldVerifier.isValidName(textToServer)) {
                errorLabel.setText("Please enter at least four characters");
                return;
            }

            // Then, we send the input to the server.
            sendButton.setEnabled(false);
            textToServerLabel.setText(textToServer);
            serverResponseLabel.setText("");
            greetingService.greetServer(textToServer, new AsyncCallback<String>() {
                public void onFailure(Throwable caught) {
                    // Show the RPC error message to the user
                    dialogBox.setText("Remote Procedure Call - Failure");
                    serverResponseLabel.addStyleName("serverResponseLabelError");
                    serverResponseLabel.setHTML(SERVER_ERROR);
                    dialogBox.center();
                    closeButton.setFocus(true);
                }

                public void onSuccess(String result) {
                    dialogBox.setText("Remote Procedure Call");
                    serverResponseLabel.removeStyleName("serverResponseLabelError");
                    serverResponseLabel.setHTML(result);
                    dialogBox.center();
                    closeButton.setFocus(true);
                }
            });
        }
    }

    // Add a handler to send the name to the server
    MyHandler handler = new MyHandler();
    sendButton.addClickHandler(handler);
    nameField.addKeyUpHandler(handler);
}

From source file:com.cognitivemedicine.metricsdashboard.client.widgets.Alerts.java

License:Apache License

public static void notify(Panel parent, String title, String message) {
    final DialogBox d = new DialogBox();
    d.setText(title);/*  w  ww .j  a v  a2 s .  com*/
    d.setModal(false);
    // d.center();
    Button closeButton = new Button("Close", new ClickHandler() {
        public void onClick(ClickEvent event) {
            d.hide();
        }
    });
    // d.add(closeButton);
    d.addCloseHandler(new CloseHandler<PopupPanel>() {
        @Override
        public void onClose(CloseEvent<PopupPanel> event) {
            d.hide();
        }
    });

    VerticalPanel v = new VerticalPanel();
    // v.add(new Label(message));

    HTML html = new HTML();
    html.setHTML(message);
    html.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            d.hide();
        }
    });

    v.add(html);
    v.add(closeButton);
    d.setWidget(v);
    // d.setPopupPosition(Window.getClientWidth()-d.getOffsetWidth(),
    // Window.getClientHeight()-d.getOffsetWidth());

    Timer t = new Timer() {
        @Override
        public void run() {
            d.hide();
        }
    };
    t.schedule(3000);

    d.setWidth("300px");
    d.setHeight("200px");
    d.center();
    // d.setPopupPosition(Window.getClientWidth()-d.getOffsetWidth(),
    // Window.getClientHeight()-d.getOffsetWidth());
    // d.show();
}

From source file:com.connoisseur.menuapp.client.Authenticate.java

/** This is essentially the main method for the menu app. */
public static void go() {
    storage.clear(); // uncomment to completely reset app

    final DialogBox startupBox = new DialogBox(); // movable box that contains widgets
    startupBox.setAnimationEnabled(true);
    final VerticalPanel startupPanel = new VerticalPanel(); // can contain other widgets
    startupPanel.addStyleName("marginPanel"); // interacts with Menuapp.css
    startupPanel.setHorizontalAlignment(VerticalPanel.ALIGN_CENTER);

    // check to see if storage is supported
    if (storage != null) {

        // load viewer if license key and restID have been submitted before
        if (storage.getLength() > 0) {
            Viewer.loadViewer();//from  w  w  w . j ava 2 s .  c o m
        }

        // otherwise load authentication UI in order to receive input
        else {
            final Button submitButton = new Button("Submit"); // "Submit" appears on button
            submitButton.addStyleName("myButton"); // interacts with Menuapp.css
            final HorizontalPanel buttonPanel = new HorizontalPanel(); // used to center button
            buttonPanel.addStyleName("marginlessPanel");

            // license widgets
            final Label licenseErrorLabel = new Label(); // dynamic text
            licenseErrorLabel.addStyleName("errorLabel"); // interacts with Menuapp.css
            final TextBox submitLicense = new TextBox(); // user can input text using this
            submitLicense.setText("license key..."); // default text to be seen on load

            // restaurant ID widgets
            final Label restErrorLabel = new Label();
            restErrorLabel.addStyleName("errorLabel");
            final TextBox submitRestID = new TextBox();
            submitRestID.setText("restaurant ID...");

            // organize UI
            startupPanel.add(new HTML("Please enter your license key:"));
            startupPanel.add(submitLicense);
            startupPanel.add(licenseErrorLabel);
            startupPanel.add(new HTML("<br>Please enter your restaurant ID:"));
            startupPanel.add(submitRestID);
            startupPanel.add(restErrorLabel);
            startupPanel.add(new HTML("<br>"));
            buttonPanel.add(submitButton);
            startupPanel.add(buttonPanel);

            // setup startupBox, which is what will be seen by the user
            startupBox.setWidget(startupPanel); // connects the two widgets
            startupBox.center(); // also shows the box

            // focus the cursor on submitLicense when startupBox appears
            submitLicense.setFocus(true);
            submitLicense.selectAll();

            // create a handler for submitButton, submitLicense and submitRestID
            class MyHandler implements ClickHandler, KeyUpHandler {
                /** Fired when the user clicks submit. */
                public void onClick(ClickEvent event) {
                    submit();
                }

                /** Fired when the user presses Enter in a submit field. */
                public void onKeyUp(KeyUpEvent event) {
                    if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER)
                        submit();
                }

                /** Checks the submitted license key and restaurant ID for validity. Loads Viewer if valid. */
                private void submit() {
                    String license = submitLicense.getText(); // unused for now
                    String restID = submitRestID.getText(); // not sure how to validate yet
                    int returnFlag = 0; // so that both tests can be done
                    licenseErrorLabel.setText("");
                    restErrorLabel.setText("");

                    // validate license
                    String result = FieldVerifier.isValidLicenseKey(license); // from FieldVerifier.java
                    if (!result.equals("")) { // error
                        licenseErrorLabel.setText("You submitted an invalid license key.");
                        submitLicense.selectAll();
                        returnFlag = 1;
                    }

                    // validate restID
                    result = FieldVerifier.isValidRestaurantID(restID);
                    if (!result.equals("")) { // error
                        restErrorLabel.setText("You submitted an invalid restaurant ID.");
                        submitRestID.selectAll();
                        returnFlag = 1;
                    }

                    // don't do anything until the errors are resolved
                    if (returnFlag == 1)
                        return;

                    // clean up
                    submitButton.setEnabled(false);
                    submitLicense.setEnabled(false);
                    submitRestID.setEnabled(false);
                    startupBox.hide();

                    // set up storage
                    storage.setItem("license", license); // secret key for security
                    storage.setItem("restID", restID); // used for almost every call to the backend

                    // show menu
                    Viewer.loadViewer();
                }
            } // MyHandler

            // attach the handler
            final MyHandler handler = new MyHandler();
            submitButton.addClickHandler(handler);
            submitLicense.addKeyUpHandler(handler);
            submitRestID.addKeyUpHandler(handler);
        } // else load authentication UI

    } // if storage supported

    // storage is not supported, so report error
    else {
        startupPanel.add(new HTML("<font color=red>The app will not function because local<br>"
                + "storage is not supported on this platform.</font>"));
        startupBox.setWidget(startupPanel);
        startupBox.center();
    }
}

From source file:com.controlj.addon.gwttree.client.Dialog.java

License:Open Source License

private static void showErrorDialog(String title, String html, String text) {
    // Create a dialog box and set the caption text
    final DialogBox dialogBox = new DialogBox(false, true);
    dialogBox.setText(title);/* ww  w .j a v  a2 s. c o m*/

    // Create a table to layout the content
    VerticalPanel dialogContents = new VerticalPanel();
    dialogContents.setSpacing(4);
    dialogBox.setWidget(dialogContents);

    // Add either HTML or Text
    Widget details = html != null ? new HTML(html) : new Label(text);
    dialogContents.add(details);
    dialogContents.setCellHorizontalAlignment(details, HasHorizontalAlignment.ALIGN_CENTER);

    // Add a close button at the bottom of the dialog
    Button closeButton = new Button("Close", new ClickHandler() {
        public void onClick(ClickEvent event) {
            dialogBox.hide();
        }
    });
    dialogContents.add(closeButton);
    dialogContents.setCellHorizontalAlignment(closeButton, HasHorizontalAlignment.ALIGN_CENTER);

    // final configuration and show the dialog box
    dialogBox.setGlassEnabled(true);
    dialogBox.setAnimationEnabled(true);
    dialogBox.center();
    dialogBox.show();
}

From source file:com.controlj.addon.gwttree.client.Dialog.java

License:Open Source License

/**<!====== showInputDialog ===============================================>
   Displays a dialog box allowing input from the user.  The dialog contains
   both "OK" and "Cancel" buttons.  Before it is displayed,
   the {@link Handler#setupButtons} method is called (to allow "hotkeys" to
   be associated with the buttons).  When the dialog is closed by the user
   the {@link Handler#dialogClosed} method is called so that appropriate
   action can be taken.  This method immediately returns to the caller.
   <!      Name       Description>
   @param  titleBar   The dialog title./*from   w  w  w. jav  a2  s.  c  o m*/
   @param  content    The content (can be a panel with lots of controls).
   @param  handler    The handler for when the dialog is closed.
<!=======================================================================>*/
public static void showInputDialog(String titleBar, Widget content, Handler handler) {
    // Create a dialog box and set the caption text
    final DialogBox dialogBox = new DialogBox(false, true);
    dialogBox.setText(titleBar);

    // Create a table to layout the content
    VerticalPanel dialogContents = new VerticalPanel();
    dialogContents.setSpacing(4);
    dialogContents.add(content);

    // Add Ok and Cancel buttons at the bottom of the dialog
    Widget buttonPanel = createButtonPanel(dialogBox, handler);
    dialogContents.add(buttonPanel);
    dialogContents.setCellHorizontalAlignment(buttonPanel, HasHorizontalAlignment.ALIGN_CENTER);

    // final configuration and show the dialog box
    dialogBox.setWidget(dialogContents);
    dialogBox.setGlassEnabled(true);
    dialogBox.setAnimationEnabled(true);
    dialogBox.center();
    dialogBox.show();
}

From source file:com.databasepreservation.visualization.client.common.Dialogs.java

public static void showConfirmDialog(String title, String message, String cancelButtonText,
        String confirmButtonText, final AsyncCallback<Boolean> callback) {
    final DialogBox dialogBox = new DialogBox(false, true);
    dialogBox.setText(title);/* ww w.  j  a  v a  2  s  . c  o  m*/

    FlowPanel layout = new FlowPanel();
    Label messageLabel = new Label(message);
    Button cancelButton = new Button(cancelButtonText);
    Button confirmButton = new Button(confirmButtonText);
    FlowPanel footer = new FlowPanel();

    layout.add(messageLabel);
    layout.add(footer);
    footer.add(cancelButton);
    footer.add(confirmButton);

    dialogBox.setWidget(layout);

    dialogBox.setGlassEnabled(true);
    dialogBox.setAnimationEnabled(false);

    cancelButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            dialogBox.hide();
            callback.onSuccess(false);
        }
    });

    confirmButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            dialogBox.hide();
            callback.onSuccess(true);
        }
    });

    dialogBox.addStyleName("wui-dialog-confirm");
    layout.addStyleName("wui-dialog-layout");
    footer.addStyleName("wui-dialog-layout-footer");
    messageLabel.addStyleName("wui-dialog-message");
    cancelButton.addStyleName("btn btn-link");
    confirmButton.addStyleName("btn btn-play");

    dialogBox.center();
    dialogBox.show();
}

From source file:com.databasepreservation.visualization.client.common.Dialogs.java

public static void showInformationDialog(String title, String message, String continueButtonText,
        final AsyncCallback<Void> callback) {
    final DialogBox dialogBox = new DialogBox(false, true);
    dialogBox.setText(title);//from  w  w w  . j av  a2 s.  com

    FlowPanel layout = new FlowPanel();
    Label messageLabel = new Label(message);
    Button continueButton = new Button(continueButtonText);

    layout.add(messageLabel);
    layout.add(continueButton);

    dialogBox.setWidget(layout);

    dialogBox.setGlassEnabled(true);
    dialogBox.setAnimationEnabled(false);

    continueButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            dialogBox.hide();
            callback.onSuccess(null);
        }
    });

    dialogBox.addStyleName("wui-dialog-information");
    layout.addStyleName("wui-dialog-layout");
    messageLabel.addStyleName("wui-dialog-message");
    continueButton.addStyleName("btn btn-play");

    dialogBox.center();
    dialogBox.show();
}

From source file:com.databasepreservation.visualization.client.common.Dialogs.java

public static void showPromptDialog(String title, String message, String placeHolder, final RegExp validator,
        String cancelButtonText, String confirmButtonText, final AsyncCallback<String> callback) {
    final DialogBox dialogBox = new DialogBox(false, true);
    dialogBox.setText(title);//w  w w  . j  a va2s.  c  o  m

    final FlowPanel layout = new FlowPanel();

    if (message != null) {
        final Label messageLabel = new Label(message);
        layout.add(messageLabel);
        messageLabel.addStyleName("wui-dialog-message");
    }

    final TextBox inputBox = new TextBox();

    if (placeHolder != null) {
        inputBox.getElement().setPropertyString("placeholder", placeHolder);
    }

    final Button cancelButton = new Button(cancelButtonText);
    final Button confirmButton = new Button(confirmButtonText);

    layout.add(inputBox);
    layout.add(cancelButton);
    layout.add(confirmButton);

    dialogBox.setWidget(layout);

    dialogBox.setGlassEnabled(true);
    dialogBox.setAnimationEnabled(false);

    cancelButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            dialogBox.hide();
            callback.onFailure(null);
        }
    });

    confirmButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            dialogBox.hide();
            callback.onSuccess(inputBox.getText());
        }
    });

    inputBox.addValueChangeHandler(new ValueChangeHandler<String>() {

        @Override
        public void onValueChange(ValueChangeEvent<String> event) {
            boolean isValid = validator.test(inputBox.getText());
            if (isValid) {
                inputBox.addStyleName("error");
            } else {
                inputBox.removeStyleName("error");
            }
        }
    });

    inputBox.addKeyPressHandler(new KeyPressHandler() {

        @Override
        public void onKeyPress(KeyPressEvent event) {
            boolean isValid = validator.test(inputBox.getText());
            confirmButton.setEnabled(isValid);
        }
    });

    inputBox.addKeyDownHandler(new KeyDownHandler() {

        @Override
        public void onKeyDown(KeyDownEvent event) {
            if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) {
                boolean isValid = validator.test(inputBox.getText());
                if (isValid) {
                    dialogBox.hide();
                    callback.onSuccess(inputBox.getText());
                }
            }
        }

    });

    confirmButton.setEnabled(validator.test(inputBox.getText()));

    dialogBox.addStyleName("wui-dialog-prompt");
    layout.addStyleName("wui-dialog-layout");
    inputBox.addStyleName("form-textbox wui-dialog-message");
    cancelButton.addStyleName("btn btn-link");
    confirmButton.addStyleName("pull-right btn btn-play");

    dialogBox.center();
    dialogBox.show();
    inputBox.setFocus(true);
}