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.google.api.services.samples.calendar.appengine.client.CalendarButtons.java

License:Apache License

@UiHandler("updateButton")
void handleUpdate(ClickEvent e) {
    DialogBox dialogBox = new DialogBox();
    dialogBox.setAnimationEnabled(true);
    dialogBox.setText("Update Calendar Title:");
    UpdateDialogContent content = new UpdateDialogContent(main, dialogBox, calendar, calendarIndex);
    dialogBox.add(content);/*from  w  w w .  j a  va 2 s  .  c  om*/
    dialogBox.show();
}

From source file:com.google.appinventor.client.editor.blocks.BlocklyPanel.java

License:Open Source License

/**
 * Create a Dialog Box. We call this from Javascript (blockly) to
 * display a dialog box.  We do this here because we can get calls
 * from the blocklyframe when it is not visible.  Because we are in
 * the parent window, we can display dialogs that will be visible
 * even when the blocklyframe is not visible.
 *
 * @param title      Title for the Dialog Box
 * @param mess       The message to display
 * @param buttonName The string to display in the "OK" button.
 * @param size       0 or 1. 0 makes a smaller box 1 makes a larger box.
 * @param callback   an opague JavaScriptObject that contains the
 *                   callback function provided by the Javascript code.
 * @return The created dialog box.//from ww w  .  j av  a  2  s.  com
 */

public static DialogBox createDialog(String title, String mess, final String buttonName,
        final String cancelButtonName, int size, final JavaScriptObject callback) {
    final DialogBox dialogBox = new DialogBox();
    dialogBox.setStylePrimaryName("ode-DialogBox");
    dialogBox.setText(title);
    if (size == 0) {
        dialogBox.setHeight("150px");
    } else {
        dialogBox.setHeight("400px");
    }
    dialogBox.setWidth("400px");
    dialogBox.setGlassEnabled(true);
    dialogBox.setAnimationEnabled(true);
    dialogBox.center();
    VerticalPanel DialogBoxContents = new VerticalPanel();
    HTML message = new HTML(mess);
    HorizontalPanel holder = new HorizontalPanel();
    if (buttonName != null) { // If buttonName and cancelButtonName are null
        Button ok = new Button(buttonName); // We won't have any buttons and other
        ok.addClickHandler(new ClickHandler() { // code is needed to dismiss us
            @Override
            public void onClick(ClickEvent event) {
                doCallBack(callback, buttonName);
            }
        });
        holder.add(ok);
    }
    if (cancelButtonName != null) {
        Button cancel = new Button(cancelButtonName);
        cancel.addClickHandler(new ClickHandler() {
            @Override
            public void onClick(ClickEvent event) {
                doCallBack(callback, cancelButtonName);
            }
        });
        holder.add(cancel);
    }
    DialogBoxContents.add(message);
    DialogBoxContents.add(holder);
    dialogBox.setWidget(DialogBoxContents);
    terminateDrag(); // cancel a drag before showing the modal dialog
    dialogBox.show();
    return dialogBox;
}

From source file:com.google.appinventor.client.editor.youngandroid.BlocklyPanel.java

License:Open Source License

/**
 * Create a Dialog Box. We call this from Javascript (blockly) to
 * display a dialog box.  We do this here because we can get calls
 * from the blocklyframe when it is not visible.  Because we are in
 * the parent window, we can display dialogs that will be visible
 * even when the blocklyframe is not visible.
 *
 * @param title      Title for the Dialog Box
 * @param mess       The message to display
 * @param buttonName The string to display in the "OK" button.
 * @param size       0 or 1. 0 makes a smaller box 1 makes a larger box.
 * @param callback   an opague JavaScriptObject that contains the
 *                   callback function provided by the Javascript code.
 * @return The created dialog box./*from w ww . j av a 2 s .c  o  m*/
 */

public static DialogBox createDialog(String title, String mess, final String buttonName,
        final String cancelButtonName, int size, final JavaScriptObject callback) {
    final DialogBox dialogBox = new DialogBox();
    dialogBox.setStylePrimaryName("ode-DialogBox");
    dialogBox.setText(title);
    if (size == 0) {
        dialogBox.setHeight("150px");
    } else {
        dialogBox.setHeight("400px");
    }
    dialogBox.setWidth("400px");
    dialogBox.setGlassEnabled(true);
    dialogBox.setAnimationEnabled(true);
    dialogBox.center();
    VerticalPanel DialogBoxContents = new VerticalPanel();
    HTML message = new HTML(mess);
    message.setStyleName("DialogBox-message");
    HorizontalPanel holder = new HorizontalPanel();
    if (buttonName != null) { // If buttonName and cancelButtonName are null
        Button ok = new Button(buttonName); // We won't have any buttons and other
        ok.addClickListener(new ClickListener() { // code is needed to dismiss us
            public void onClick(Widget sender) {
                doCallBack(callback, buttonName);
            }
        });
        holder.add(ok);
    }
    if (cancelButtonName != null) {
        Button cancel = new Button(cancelButtonName);
        cancel.addClickListener(new ClickListener() {
            public void onClick(Widget sender) {
                doCallBack(callback, cancelButtonName);
            }
        });
        holder.add(cancel);
    }
    DialogBoxContents.add(message);
    DialogBoxContents.add(holder);
    dialogBox.setWidget(DialogBoxContents);
    dialogBox.show();
    return dialogBox;
}

From source file:com.google.code.gwt.appcache.sample.helloappcache.client.HelloApplicationCache.java

License:Apache License

/**
 * This is the entry point method./*from   w  w  w  . j  a  v  a  2 s. com*/
 */
public void onModuleLoad() {
    Image img = new Image("http://code.google.com/webtoolkit/logo-185x175.png");
    Button button = new Button("Click me");

    VerticalPanel vPanel = new VerticalPanel();
    // We can add style names.
    vPanel.addStyleName("widePanel");
    vPanel.setHorizontalAlignment(VerticalPanel.ALIGN_CENTER);
    vPanel.add(img);
    vPanel.add(button);

    // Add image and button to the RootPanel
    RootPanel.get().add(vPanel);

    // Create the dialog box
    final DialogBox dialogBox = new DialogBox();
    dialogBox.setText("Welcome to GWT ApplicationCache Demo!");
    dialogBox.setAnimationEnabled(true);
    Button closeButton = new Button("close");
    VerticalPanel dialogVPanel = new VerticalPanel();
    dialogVPanel.setWidth("100%");
    dialogVPanel.setHorizontalAlignment(VerticalPanel.ALIGN_CENTER);
    dialogVPanel.add(closeButton);

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

    // Set the contents of the Widget
    dialogBox.setWidget(dialogVPanel);

    button.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            // Invoke service:
            HelloServiceAsync service = GWT.create(HelloService.class);
            service.sayHello("Bart", new AsyncCallback<String>() {
                public void onFailure(Throwable caught) {
                    dialogBox.setText("Could not invoke 'sayHello' service: " + caught);
                    dialogBox.center();
                    dialogBox.show();
                }

                public void onSuccess(String result) {
                    dialogBox.setText(result + "! Welcome to GWT ApplicationCache Demo!");
                    dialogBox.center();
                    dialogBox.show();
                }
            });
        }
    });
}

From source file:com.google.code.gwt.database.sample.hellodatabase.client.HelloDatabase.java

License:Apache License

/**
 * This is the entry point method./*www  .  ja va 2  s .c o m*/
 */
public void onModuleLoad() {
    if (!Database.isSupported()) {
        Window.alert("HTML 5 Database is NOT supported in this browser!");
        return;
    }

    // Create the dialog box
    final DialogBox dialogBox = new DialogBox();
    dialogBox.setText("Welcome to GWT Database Demo!");
    dialogBox.setAnimationEnabled(true);
    Button closeButton = new Button("close", new ClickHandler() {
        public void onClick(ClickEvent event) {
            dialogBox.hide();
        }
    });
    VerticalPanel dialogVPanel = new VerticalPanel();
    dialogVPanel.setWidth("100%");
    dialogVPanel.setHorizontalAlignment(VerticalPanel.ALIGN_CENTER);
    final VerticalPanel clickedData = new VerticalPanel();
    dialogVPanel.add(clickedData);
    dialogVPanel.add(closeButton);

    dialogBox.setWidget(dialogVPanel);

    Image img = new Image("http://code.google.com/webtoolkit/logo-185x175.png");
    Button addClickButton = new Button("Add Click", new ClickHandler() {
        public void onClick(ClickEvent event) {
            dbService.insertClick(new Date(), new RowIdListCallback() {
                public void onFailure(DataServiceException error) {
                    Window.alert("Failed to add click! " + error);
                }

                public void onSuccess(final List<Integer> rowIds) {
                    dbService.getClicks(new ListCallback<ClickRow>() {
                        public void onFailure(DataServiceException error) {
                            Window.alert("Failed to query clicks! " + error);
                        }

                        public void onSuccess(List<ClickRow> result) {
                            clickedData.clear();
                            clickedData.add(new Label("Last click insert ID: " + rowIds.get(0)));
                            for (ClickRow row : result) {
                                clickedData.add(new Label("Clicked on " + row.getClicked()));
                            }
                            dialogBox.center();
                            dialogBox.show();
                        }
                    });
                }
            });
        }
    });
    Button getCountButton = new Button("Get Counts", new ClickHandler() {
        public void onClick(ClickEvent event) {
            getCount();
        }
    });

    vPanel = new VerticalPanel();
    // We can add style names.
    vPanel.addStyleName("widePanel");
    vPanel.setHorizontalAlignment(VerticalPanel.ALIGN_CENTER);
    vPanel.add(img);
    vPanel.add(addClickButton);
    vPanel.add(getCountButton);

    // Add image and button to the RootPanel
    RootPanel.get().add(vPanel);

    // Create table 'clickcount' if it doesn't exist already:
    dbService.initTable(new VoidCallback() {
        public void onFailure(DataServiceException error) {
            Window.alert("Failed to initialize table! " + error);
        }

        public void onSuccess() {
            Window.alert("Database initialized successfully.");
            getCount();
        }
    });

    getVersion();
}

From source file:com.google.code.gwt.iui.sample.helloiui.client.HelloiUI.java

License:Apache License

/**
 * This is the entry point method.// ww w .  ja v a  2  s. co  m
 */
public void onModuleLoad() {
    Image img = new Image("http://code.google.com/webtoolkit/logo-185x175.png");
    Button button = new Button("Click me");

    VerticalPanel vPanel = new VerticalPanel();
    // We can add style names.
    vPanel.addStyleName("widePanel");
    vPanel.setHorizontalAlignment(VerticalPanel.ALIGN_CENTER);
    vPanel.add(img);
    vPanel.add(button);

    // Add image and button to the RootPanel
    RootPanel.get().add(vPanel);

    // Create the dialog box
    final DialogBox dialogBox = new DialogBox();
    dialogBox.setText("Welcome to GWT iUI Demo!");
    dialogBox.setAnimationEnabled(true);
    Button closeButton = new Button("close");
    VerticalPanel dialogVPanel = new VerticalPanel();
    dialogVPanel.setWidth("100%");
    dialogVPanel.setHorizontalAlignment(VerticalPanel.ALIGN_CENTER);
    dialogVPanel.add(closeButton);

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

    // Set the contents of the Widget
    dialogBox.setWidget(dialogVPanel);

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

From source file:com.google.code.gwt.template.sample.hellotemplate.client.HelloTemplate.java

License:Apache License

/**
 * This is the entry point method./*from  w  w w.j  a v  a2s  .  c o  m*/
 */
public void onModuleLoad() {
    Image img = new Image("http://code.google.com/webtoolkit/logo-185x175.png");
    Button button = new Button("Click me");

    VerticalPanel vPanel = new VerticalPanel();
    // We can add style names.
    vPanel.addStyleName("widePanel");
    vPanel.setHorizontalAlignment(VerticalPanel.ALIGN_CENTER);
    vPanel.add(img);
    vPanel.add(button);

    // Add image and button to the RootPanel
    RootPanel.get().add(vPanel);

    // Create the dialog box
    final DialogBox dialogBox = new DialogBox();
    dialogBox.setText("Welcome to GWT Template Demo!");
    dialogBox.setAnimationEnabled(true);
    Button closeButton = new Button("close");
    VerticalPanel dialogVPanel = new VerticalPanel();
    dialogVPanel.setWidth("100%");
    dialogVPanel.setHorizontalAlignment(VerticalPanel.ALIGN_CENTER);
    dialogVPanel.add(closeButton);

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

    // Set the contents of the Widget
    dialogBox.setWidget(dialogVPanel);

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

From source file:com.google.code.p.gwtchismes.client.GWTCProgress.java

License:Apache License

public void initialize(int options, int elements) {
    // Read the options and set variables
    if ((options & SHOW_TIME_REMAINING) == SHOW_TIME_REMAINING)
        showRemaining = true;/*  w  w w .  j a  va  2s. co m*/
    if ((options & SHOW_TEXT) == SHOW_TEXT)
        showText = true;
    if ((options & SHOW_NUMBERS) == SHOW_NUMBERS)
        showNumbers = true;
    if ((options & SHOW_AS_DIALOG) == SHOW_AS_DIALOG)
        showAsDialog = true;
    if ((options & SHOW_LEFT_TEXT) == SHOW_LEFT_TEXT)
        showText = showLeftText = true;

    // Set element count
    this.elements = elements;

    // Styling
    contentTable.setStyleName(StyleCProgress);
    numberLabel.setStyleName(StyleCPrgNumbers);
    remainLabel.setStyleName(StyleCPrgTime);
    textLabel.setStyleName(StyleCPrgText);

    // Create the out container
    Grid containerElementGrid = new Grid(1, 1);
    containerElementGrid.setStyleName(StyleCBarOuter);
    containerElementGrid.setCellPadding(0);
    containerElementGrid.setCellSpacing(0);
    // Create container for elements
    elementGrid = new Grid(1, elements);
    elementGrid.setStyleName(StyleCBarInner);
    elementGrid.setCellPadding(0);
    elementGrid.setCellSpacing(0);
    containerElementGrid.setWidget(0, 0, elementGrid);
    // Create elements
    for (int loop = 0; loop < elements; loop++) {
        Grid elm = new Grid(1, 1);
        elm.setHTML(0, 0, "");
        elm.setStyleName(StyleCBarDone);
        elm.addStyleName(StyleCBarElement);
        elementGrid.setWidget(0, loop, elm);
    }

    // Set up the surrounding flex table based on the options
    int row = 0;
    int col = 0;
    if (showLeftText)
        contentTable.setWidget(row, col++, textLabel);
    else if (showText)
        contentTable.setWidget(row++, col, textLabel);
    if (showNumbers)
        contentTable.setWidget(row, col + 1, numberLabel);
    contentTable.setWidget(row++, col, containerElementGrid);
    contentTable.setWidget(row++, col, remainLabel);

    // Initialize progress bar
    setProgress(0);
    if (showAsDialog) {
        // Create the background
        background = new GWTCGlassPanel();
        // put the container into a dialog
        progressDlg = new DialogBox();
        progressDlg.setWidget(contentTable);
        progressDlg.setStyleName(StyleCProgress);
        progressDlg.addStyleDependentName(StyleCProgressDlg);
        progressDlg.center();
        hide();
        // Initialize this composite with an empty element
        initWidget(new SimplePanel());
    } else {
        initWidget(contentTable);
    }
}

From source file:com.google.developers.gdgfirenze.gwt.client.GwtDemoApp.java

License:Apache License

/**
 * This is the entry point method./* w ww  . ja  va  2  s . c  om*/
 */
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);
        }
    });

    /**
     * The Class MyHandler.
     * 
     * 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.google.gwt.gadgets.sample.hellogadgets.client.HelloGadgets.java

License:Apache License

@Override
protected void init(final HelloPreferences prefs) {
    Image img = new Image("http://code.google.com/webtoolkit/logo-185x175.png");
    Button button = new Button("Click me");

    VerticalPanel vPanel = new VerticalPanel();
    vPanel.setWidth("100%");
    vPanel.setHorizontalAlignment(VerticalPanel.ALIGN_CENTER);
    vPanel.add(img);//w w w .ja  v  a 2 s .c om
    vPanel.add(button);

    RootPanel.get().add(vPanel);

    // Create the dialog box
    final DialogBox dialogBox = new DialogBox();

    // The content of the dialog comes from a User specified Preference
    dialogBox.setText(prefs.promptSomethingElse().getValue());
    dialogBox.setAnimationEnabled(true);
    Button closeButton = new Button("Close");
    VerticalPanel dialogVPanel = new VerticalPanel();
    dialogVPanel.setWidth("100%");
    dialogVPanel.setHorizontalAlignment(VerticalPanel.ALIGN_CENTER);
    dialogVPanel.add(closeButton);

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

    // Set the contents of the Widget
    dialogBox.setWidget(dialogVPanel);

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