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

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

Introduction

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

Prototype

public DialogBox() 

Source Link

Document

Creates an empty dialog box.

Usage

From source file:com.googlecode.konamigwt.hadoken.client.Hadoken.java

License:BEER-WARE LICENSE

/**
 * This is the entry point method./*from   w ww  .j  a  va2 s  .com*/
 */
public void onModuleLoad() {

    final Button sendButton = new Button("Send");
    final TextBox nameField = new TextBox();
    nameField.setText("GWT User");
    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);
        }
    });

    // Quick and Dirty implementation
    new Konami(new KonamiHandler() {
        @Override
        public void onKonamiCodePerformed() {
            final Image image = new Image("media/ryu.gif");
            DOM.appendChild(RootPanel.get().getElement(), image.getElement());

            final Audio audio = Audio.createIfSupported();
            if (audio != null) {
                audio.setSrc("media/hadoken.ogg");
                DOM.appendChild(RootPanel.get().getElement(), audio.getElement());
                audio.play();
            }
            Timer timer = new Timer() {

                @Override
                public void run() {
                    DOM.removeChild(RootPanel.get().getElement(), image.getElement());
                    if (audio != null) {
                        DOM.removeChild(RootPanel.get().getElement(), audio.getElement());
                    }
                }

            };
            timer.schedule(1100);

        }
    }).start();

    // 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("");
            serverResponseLabel.removeStyleName("serverResponseLabelError");
            serverResponseLabel.setHTML("Hello " + textToServer);
            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.gwt.conn.client.Authenticate.java

/** This is essentially the main method for the editor 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);
    startupBox.setText("Connoisseur");
    final VerticalPanel startupPanel = new VerticalPanel(); // can contain other widgets
    startupPanel.addStyleName("marginPanel"); // interacts with Connfrontend.css
    startupPanel.setHorizontalAlignment(VerticalPanel.ALIGN_CENTER);

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

        // load dashboard if license key has been submitted before
        if (storage.getLength() > 0) {
            boolean internet = Communicate.hasInternet();
            StorageContainer.initStorage(); // prepares storage for interaction
            Dashboard.loadMenu(Communicate.deserialize(storage.getItem("menu")), "", internet);
            //Dashboard.loadDashboard();
        }/*from ww  w .j  ava  2s.c o m*/

        // otherwise load authentication UI in order to receive license key input
        else {
            final Button submitButton = new Button("Submit"); // "Submit" appears on button
            submitButton.addStyleName("myButton"); // interacts with Connfrontend.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 Connfrontend.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);
            final HTML commError = new HTML();
            commError.addStyleName("errorLabel");
            buttonPanel.add(commError);
            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 the submitButton and submitLicense
            class MyHandler implements ClickHandler, KeyUpHandler {
                /** Fired when the user clicks submit. */
                public void onClick(ClickEvent event) {
                    submit();
                }

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

                /** Checks the submitted license key for validity. Loads the dashboard if valid. */
                private void submit() {
                    // check submit fields
                    String license = submitLicense.getText();
                    String restID = submitRestID.getText();
                    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(result);
                        returnFlag = 1;
                    }

                    // validate restID
                    result = FieldVerifier.isValidRestaurantID(restID);
                    if (!result.equals("")) { // error
                        restErrorLabel.setText(result);
                        returnFlag = 1;
                    }

                    // don't do anything until the errors are resolved
                    if (returnFlag == 1)
                        return;
                    storage.setItem("menu", "");

                    // attempt to authenticate
                    Communicate.authenticate(restID, license, commError, startupBox, submitButton,
                            submitLicense, submitRestID);

                } // end submit
            } // 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.gwt.conn.client.Communicate.java

public static void showDialog(String text) {
    final DialogBox errorBox = new DialogBox();
    errorBox.setAnimationEnabled(true);/*from w w w .  j av a  2s. c o m*/
    final VerticalPanel errorVPanel = new VerticalPanel();
    errorVPanel.addStyleName("marginPanel"); // interacts with Connfrontend.css
    errorVPanel.setHorizontalAlignment(VerticalPanel.ALIGN_CENTER);
    final Button errorButton = new Button("Continue");
    errorButton.addStyleName("myButton");
    final HorizontalPanel errorHPanel = new HorizontalPanel();
    errorVPanel.add(new HTML(text));
    errorHPanel.add(errorButton);
    errorVPanel.add(errorHPanel);
    errorBox.setWidget(errorVPanel);
    errorBox.center();
    errorButton.setFocus(true);

    class ErrorHandler implements ClickHandler, KeyUpHandler {
        public void onClick(ClickEvent event) { // button clicked
            cont();
        }

        public void onKeyUp(KeyUpEvent event) { // ENTER key
            if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER)
                cont();
        }

        private void cont() {
            errorButton.setEnabled(false);
            errorBox.hide();
        }
    }
    final ErrorHandler errorHandler = new ErrorHandler();
    errorButton.addClickHandler(errorHandler);
}

From source file:com.gwt.conn.client.Communicate.java

public static void authenticate(final String restID, final String license, final HTML commError,
        final DialogBox startupBox, final Button submitButton, final TextBox submitLicense,
        final TextBox submitRestID) {
    // attempt to sync with server
    storage.setItem("authenticated?", "null");
    String result = sync("menu", restID, true); // true because authenticating
    if (!result.equals("")) {
        commError.setText("<br>No internet connection detected.");
        return;/*from  w w  w.j  a  va2  s  .c o m*/
    }

    // hide authentication submission form and replace with an "Authenticating..." message
    submitButton.setEnabled(false);
    submitLicense.setEnabled(false);
    submitRestID.setEnabled(false);
    startupBox.hide();
    final DialogBox authBox = new DialogBox();
    authBox.setAnimationEnabled(true);
    final VerticalPanel authPanel = new VerticalPanel();
    authPanel.addStyleName("marginPanel"); // interacts with Connfrontend.css
    authPanel.setHorizontalAlignment(VerticalPanel.ALIGN_CENTER);
    authPanel.add(new HTML("Authenticating..."));
    authBox.setWidget(authPanel);
    authBox.center();

    // repeat a timer until the value of "authenticated?" changes
    final Timer timer = new Timer() {
        public void run() {
            // authentication unsuccessful
            if (storage.getItem("authenticated?").equals("no")) {
                // report error and show authentication form again
                authBox.hide();
                commError.setText("<br>Something went wrong. Please try again.");
                submitButton.setEnabled(true);
                submitLicense.setEnabled(true);
                submitRestID.setEnabled(true);
                startupBox.center();
                this.cancel();
            }

            // authentication successful
            else if (storage.getItem("authenticated?").equals("yes")) {
                // save license and restaurant id and setup storage
                authBox.hide();
                storage.setItem("license", license); // secret key for security
                storage.setItem("restID", restID); // used for almost every call to the backend
                storage.setItem("numMenus", Integer.toString(0));
                StorageContainer.initStorage();

                // go to dashboard (true meaning there is internet since we were able to authenticate)
                // "firstTime" causes a popup box to appear explaining how to use Connoisseur
                this.cancel();
                Dashboard.loadMenu(deserialize(storage.getItem("menu")), "firstTime", true);

            }
        }
    };

    // repeat once every half second
    timer.scheduleRepeating(500); // 500 milliseconds
}

From source file:com.gwt.conn.client.Dashboard.java

/** Called when no internet connection is detected in order to inform the user. */
public static void showNoInternetError() {
    // put everything in a popup dialog box
    final DialogBox errorBox = new DialogBox();
    errorBox.setAnimationEnabled(true);//from   ww  w.  jav a 2  s . c o m
    final VerticalPanel errorVPanel = new VerticalPanel();
    errorVPanel.addStyleName("marginPanel"); // interacts with
    // Connfrontend.css
    errorVPanel.setHorizontalAlignment(VerticalPanel.ALIGN_CENTER);
    final Button errorButton = new Button("Continue");
    errorButton.addStyleName("myButton");
    final HorizontalPanel errorHPanel = new HorizontalPanel();
    errorVPanel.add(new HTML(SERVER_ERROR));
    errorHPanel.add(errorButton);
    errorVPanel.add(errorHPanel);
    errorBox.setWidget(errorVPanel);
    errorBox.center();
    errorButton.setFocus(true);

    // handler for errorButton
    class ErrorHandler implements ClickHandler, KeyUpHandler {
        public void onClick(ClickEvent event) { // button clicked
            cont();
        }

        public void onKeyUp(KeyUpEvent event) { // ENTER key
            if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER)
                cont();
        }

        private void cont() {
            errorButton.setEnabled(false);
            errorBox.hide();
        }
    }
    final ErrorHandler errorHandler = new ErrorHandler();
    errorButton.addClickHandler(errorHandler);
    errorButton.addKeyUpHandler(errorHandler);
}

From source file:com.gwt.conn.client.Dashboard.java

/**
 * Called by Authenticate.java when successfully authenticated. (multiple
 * menus version)//from  w ww.j  a  v  a2  s.c o  m
 */
public void loadDashboard() {
    final HTML statusLabel = new HTML(); // dynamic HTML
    final DialogBox dashboardBox = new DialogBox();
    dashboardBox.setAnimationEnabled(true);

    // send the license to the server
    greetingService.greetServer(storage.getItem("license"), new AsyncCallback<String>() {
        public void onFailure(Throwable caught) {
            // show the RPC error message to the user
            dashboardBox.setText("Dashboard - Offline Mode");
            // statusLabel.setHTML(???);

            final DialogBox errorBox = new DialogBox();
            errorBox.setAnimationEnabled(true);

            final VerticalPanel errorVPanel = new VerticalPanel();
            errorVPanel.addStyleName("marginPanel"); // interacts
            // with
            // Connfrontend.css
            errorVPanel.setHorizontalAlignment(VerticalPanel.ALIGN_CENTER);

            final Button errorButton = new Button("Continue");
            errorButton.addStyleName("myButton");

            final HorizontalPanel errorHPanel = new HorizontalPanel();

            errorVPanel.add(new HTML(SERVER_ERROR));
            errorHPanel.add(errorButton);
            errorVPanel.add(errorHPanel);
            errorBox.setWidget(errorVPanel);
            errorBox.center();
            errorButton.setFocus(true);

            // handler for errorButton
            class ErrorHandler implements ClickHandler, KeyUpHandler {
                // Fired when the user clicks Continue.
                public void onClick(ClickEvent event) {
                    cont();
                }

                // Fired when the user presses Enter.
                public void onKeyUp(KeyUpEvent event) {
                    if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER)
                        cont();
                }

                private void cont() {
                    errorButton.setEnabled(false);
                    errorBox.hide();
                    finishLoad(dashboardBox, statusLabel); // void
                    // method
                    // below
                }
            }

            // attach the handler
            final ErrorHandler errorHandler = new ErrorHandler();
            errorButton.addClickHandler(errorHandler);
        } // end onFailure

        public void onSuccess(String result) {
            // StorageContainer.synchronizeWithBackend(); //
            // implemented in StorageContainer.java
            dashboardBox.setText("Dashboard");
            statusLabel.setHTML(result);
            finishLoad(dashboardBox, statusLabel); // void method
            // below
        }
    }); // end greetServer
}

From source file:com.gwt.conn.client.Dashboard.java

/** Called when the user wants to create a new menu. */
private void newMenu(final DialogBox dashboardBox) {
    // declarations
    final DialogBox submitBox = new DialogBox();
    submitBox.setAnimationEnabled(true);

    final VerticalPanel submitVPanel = new VerticalPanel();
    submitVPanel.addStyleName("marginPanel");
    submitVPanel.setHorizontalAlignment(VerticalPanel.ALIGN_CENTER);

    final Label errorLabel = new Label();
    errorLabel.addStyleName("errorLabel");

    final Button sendButton = new Button("Submit");
    sendButton.addStyleName("myButton");

    final Button cancelButton = new Button("Cancel");
    sendButton.addStyleName("myButton");

    final TextBox submitField = new TextBox(); // user can input text using
    // this//  w w  w.  ja v  a  2  s  .  c  o m
    submitField.setText("menu name..."); // default text to be seen on load

    final HorizontalPanel submitHPanel = new HorizontalPanel();

    // organize UI
    submitVPanel.add(new HTML("Please enter a name for your new menu:"));
    submitHPanel.add(submitField);
    submitHPanel.add(sendButton);
    submitHPanel.add(cancelButton);
    submitVPanel.add(submitHPanel);
    submitVPanel.add(errorLabel);
    submitBox.setWidget(submitVPanel);
    submitBox.center();
    submitField.setFocus(true);
    submitField.selectAll();

    // handler for the sendButton and submitField
    class SubmitHandler implements ClickHandler, KeyUpHandler {
        /** Fired when the user clicks submit. */
        public void onClick(ClickEvent event) {
            submit();
        }

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

        /**
         * Checks the submitted menu name for validity. If valid, loads a
         * new menu object and starts the visual editor.
         */
        private void submit() {
            // validate menu name
            String menuName = submitField.getText();
            String test = FieldVerifier.isValidMenuName(menuName);
            if (!test.equals("")) {
                errorLabel.setText(test);
                submitField.selectAll();
                return;
            }

            String json = "";// createDefaultJSON(); // get default JSON
                             // object
            StorageContainer.addMenu(menuName, json); // to storage
            sendButton.setEnabled(false);
            submitBox.hide();
            // visualEditor.loadVisualEditor(dashboardBox, json); // start
            // editing
        }
    }

    // handler for the cancel button
    class CancelHandler implements ClickHandler {
        /** Fired when the user clicks cancel. */
        public void onClick(ClickEvent event) {
            submitBox.hide();
            dashboardBox.center();
        }
    }

    // attach the handlers
    final SubmitHandler submitHandler = new SubmitHandler();
    final CancelHandler cancelHandler = new CancelHandler();
    sendButton.addClickHandler(submitHandler);
    submitField.addKeyUpHandler(submitHandler);
    cancelButton.addClickHandler(cancelHandler);
}

From source file:com.gwt.conn.client.Dashboard.java

/** Called when the user wants to edit an existing menu. */
private void getMenus(final DialogBox dashboardBox) {
    // declarations
    final DialogBox editBox = new DialogBox();
    editBox.setAnimationEnabled(true);/*from   w ww  . ja v a2s.c  o m*/

    final VerticalPanel editVPanel = new VerticalPanel();
    editVPanel.addStyleName("marginPanel");
    editVPanel.setHorizontalAlignment(VerticalPanel.ALIGN_CENTER);

    final Button cancelButton = new Button("Cancel");
    cancelButton.addStyleName("myButton");

    // from StorageContainer.java
    int numMenus = StorageContainer.getNumMenus();
    final String[] menus = StorageContainer.getMenus();

    // organize UI
    for (int i = 0; i < numMenus; ++i) {
        final String menuName = menus[i];
        final Button button = new Button(menuName);
        button.addStyleName("myButton");
        editVPanel.add(button);

        // handler for the buttons
        class ButtonHandler implements ClickHandler {
            /** Fired when the user clicks cancel. */
            public void onClick(ClickEvent event) {
                editBox.hide();
                // String json = StorageContainer.getMenu(menuName);
                // visualEditor.loadVisualEditor(dashboardBox, json); //
                // start editing
            }
        }

        // attach handler
        final ButtonHandler buttonHandler = new ButtonHandler();
        button.addClickHandler(buttonHandler);
    }

    editVPanel.add(cancelButton);
    editBox.setWidget(editVPanel);
    editBox.center();

    // handler for the cancel button
    class CancelHandler implements ClickHandler {
        /** Fired when the user clicks cancel. */
        public void onClick(ClickEvent event) {
            editBox.hide();
            dashboardBox.center();
        }
    }

    // attach cancel handler
    final CancelHandler cancelHandler = new CancelHandler();
    cancelButton.addClickHandler(cancelHandler);
}

From source file:com.gwttest.client.Demo.java

License:Open Source License

private void createPopupDialog() {
    popupDb = new DialogBox();
    popupDb.setText("Chart in Dialog");

    VerticalPanel dbContents = new VerticalPanel();
    dbContents.setSpacing(4);/*w  w w.j av  a  2s . com*/
    popupDb.setWidget(dbContents);

    ChartWidget chart = new ChartWidget();
    chart.setChartData(getStackChartData());
    chart.setSize("300", "300");
    dbContents.add(chart);
    Button closeButton = new Button("Close", new ClickHandler() {
        public void onClick(ClickEvent event) {
            popupDb.hide();
        }
    });
    dbContents.add(closeButton);
    dbContents.setCellHorizontalAlignment(closeButton, HasHorizontalAlignment.ALIGN_RIGHT);

}

From source file:com.gwttest.client.Demo.java

License:Open Source License

private void createImageDialog(String imgurl) {
    final DialogBox imageDb = new DialogBox();
    imageDb.setText("Image Capture of Chart");

    VerticalPanel dbContents = new VerticalPanel();
    dbContents.setSpacing(4);/*  w w  w.ja  v  a  2s  .co m*/
    imageDb.setWidget(dbContents);

    Image chartImg = new Image(imgurl);

    chartImg.setSize("250", "200");
    dbContents.add(chartImg);

    Button closeButton = new Button("Close", new ClickHandler() {
        public void onClick(ClickEvent event) {
            imageDb.hide();
        }
    });
    dbContents.add(closeButton);
    dbContents.setCellHorizontalAlignment(closeButton, HasHorizontalAlignment.ALIGN_RIGHT);

    imageDb.center();
    imageDb.show();
}