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

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

Introduction

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

Prototype

@Override
    public Widget getWidget() 

Source Link

Usage

From source file:ch.unifr.pai.twice.layout.client.eclipseLayout.MiceSplitLayoutPanel.java

License:Apache License

/**
 * Close the dialog and adds the widget to the previous panel
 * /*from w ww. j a  va  2  s.c om*/
 * @param dialog
 */
private void closeDialog(DialogBox dialog) {
    ResizableDecoratorPanel panel = dialogs.remove(dialog);
    if (getWidgetDirection(panel) == Direction.CENTER) {
        if (originsOfCenterReplacements.size() > 0) {
            ResizableDecoratorPanel lastReplacement = null;
            Iterator<ResizableDecoratorPanel> i = originsOfCenterReplacements.keySet().iterator();
            while (i.hasNext())
                lastReplacement = i.next();
            if (lastReplacement != null) {
                setWidgetToSlot(lastReplacement, slots.get(getCenter()));
                setWidgetSize(lastReplacement, originsOfCenterReplacements.get(lastReplacement));
            }
        }
    }
    setWidgetToSlot(panel, dialog.getWidget());
    if (getWidgetDirection(panel) != Direction.CENTER) {
        setWidgetSize(panel, widthOfDialogsOriginalSlots.remove(panel));
    }
    dialog.hide();
    onResize();
}

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

License:Open Source License

public static void SetDialogContent(DialogBox dialog, String mess) {
    HTML html = (HTML) ((VerticalPanel) dialog.getWidget()).getWidget(0);
    html.setHTML(mess);/*from ww w. java  2 s .c  o m*/
}

From source file:com.google.appinventor.client.Ode.java

License:Open Source License

public void blocksTruncatedDialog(final long projectId, final String fileId, final String content,
        final OdeAsyncCallback callback) {
    final DialogBox dialogBox = new DialogBox(false, true); // DialogBox(autohide, modal)
    dialogBox.setStylePrimaryName("ode-DialogBox");
    dialogBox.setText(MESSAGES.blocksTruncatedDialogText());
    dialogBox.setHeight("150px");
    dialogBox.setWidth("600px");
    dialogBox.setGlassEnabled(true);/*from  w  ww. jav a  2 s  .co m*/
    dialogBox.setAnimationEnabled(true);
    dialogBox.center();
    String[] fileParts = fileId.split("/");
    String screenNameParts = fileParts[fileParts.length - 1];
    final String screenName = screenNameParts.split("\\.")[0]; // Get rid of the .bky part
    final String userEmail = user.getUserEmail();
    VerticalPanel DialogBoxContents = new VerticalPanel();
    HTML message = new HTML(MESSAGES.blocksTruncatedDialogMessage().replace("%1", screenName));
    message.setStyleName("DialogBox-message");
    FlowPanel holder = new FlowPanel();
    final Button continueSession = new Button(MESSAGES.blocksTruncatedDialogButtonSave());
    continueSession.addClickListener(new ClickListener() {
        public void onClick(Widget sender) {
            dialogBox.hide();
            // call save2 again, this time with force = true so the empty workspace will be written
            getProjectService().save2(getSessionId(), projectId, fileId, true, content, callback);
        }
    });
    holder.add(continueSession);
    final Button cancelSession = new Button(MESSAGES.blocksTruncatedDialogButtonNoSave());
    final OdeAsyncCallback<Void> logReturn = new OdeAsyncCallback<Void>() {
        @Override
        public void onSuccess(Void result) {
            reloadWindow(false);
        }
    };
    cancelSession.addClickListener(new ClickListener() {
        public void onClick(Widget sender) {
            // Note: We do *not* remove the dialog, this locks the UI up (our intent)
            // Wait for a few seconds for other I/O to complete
            cancelSession.setEnabled(false); // Disable button to prevent further clicking
            continueSession.setEnabled(false); // This one as well
            Timer t = new Timer() {
                int count = 5;

                @Override
                public void run() {
                    if (count > 0) {
                        HTML html = (HTML) ((VerticalPanel) dialogBox.getWidget()).getWidget(0);
                        html.setHTML(MESSAGES.blocksTruncatedDialogButtonHTML().replace("%1", "" + count));
                        count -= 1;
                    } else {
                        this.cancel();
                        getProjectService().log("Disappearing Blocks: ProjectId = " + projectId + " fileId = "
                                + fileId + " User = " + userEmail, logReturn);
                    }
                }
            };
            t.scheduleRepeating(1000); // Run every second
        }
    });
    holder.add(cancelSession);
    DialogBoxContents.add(message);
    DialogBoxContents.add(holder);
    dialogBox.setWidget(DialogBoxContents);
    dialogBox.show();
}

From source file:org.opendatakit.dwc.client.DemoWebClient.java

License:Apache License

private void defineDialogIneractions(final TextBox nameField, final Button sendButton, final Label errorLabel,
        final BUTTON_FIELD_ACTION api) {

    // 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.setWidth(Integer.toString(Window.getClientWidth() - 10) + "px");
    dialogVPanel.setHorizontalAlignment(VerticalPanel.ALIGN_RIGHT);
    dialogVPanel.add(closeButton);// ww  w  .j a  v  a  2s  .  c  om
    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("");
            AsyncCallback<String> callback = 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("<verbatim>" + SafeHtmlUtils.htmlEscape(SERVER_ERROR) + "</verbatim>");
                    dialogBox.getWidget().setWidth("90%");
                    dialogBox.center();
                    closeButton.setFocus(true);
                }

                public void onSuccess(String result) {
                    dialogBox.setText("Remote Procedure Call");
                    serverResponseLabel.removeStyleName("serverResponseLabelError");
                    serverResponseLabel
                            .setHTML("<verbatim>" + SafeHtmlUtils.htmlEscape(result) + "</verbatim>");
                    dialogBox.getWidget().setWidth("90%");
                    dialogBox.center();
                    closeButton.setFocus(true);
                }
            };

            if (api == BUTTON_FIELD_ACTION.OAUTH2_FETCH) {
                greetingService.obtainOauth2Data(textToServer, callback);
            } else if (api == BUTTON_FIELD_ACTION.OAUTH1_FETCH) {
                greetingService.obtainOauth1Data(textToServer, callback);
            } else {
                greetingService.greetServer(textToServer, callback);
            }
        }
    }

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