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

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

Introduction

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

Prototype

protected Button(com.google.gwt.dom.client.Element element) 

Source Link

Document

This constructor may be used by subclasses to explicitly use an existing element.

Usage

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

License:Open Source License

/**
 * Show a Warning Dialog box when another login session has been
 * created. The user is then given two choices. They can either
 * close this session of App Inventor, which will close the current
 * window, or they can click "Take Over" which will reload this
 * window effectively making it the latest login and invalidating
 * all other sessions.//from  w  w  w . j  ava  2s.c  o m
 *
 * We are called from OdeAsyncCallback when we detect that our
 * session has been invalidated.
 */
public void invalidSessionDialog() {
    // Create the UI elements of the DialogBox
    final DialogBox dialogBox = new DialogBox(false, true); // DialogBox(autohide, modal)
    dialogBox.setStylePrimaryName("ode-DialogBox");
    dialogBox.setText(MESSAGES.invalidSessionDialogText());
    dialogBox.setHeight("200px");
    dialogBox.setWidth("800px");
    dialogBox.setGlassEnabled(true);
    dialogBox.setAnimationEnabled(true);
    dialogBox.center();
    VerticalPanel DialogBoxContents = new VerticalPanel();
    HTML message = new HTML(MESSAGES.invalidSessionDialogMessage());
    message.setStyleName("DialogBox-message");
    FlowPanel holder = new FlowPanel();
    Button closeSession = new Button(MESSAGES.invalidSessionDialogButtonEnd());
    closeSession.addClickListener(new ClickListener() {
        public void onClick(Widget sender) {
            dialogBox.hide();
            finalDialog();
        }
    });
    holder.add(closeSession);
    Button reloadSession = new Button(MESSAGES.invalidSessionDialogButtonCurrent());
    reloadSession.addClickListener(new ClickListener() {
        public void onClick(Widget sender) {
            dialogBox.hide();
            reloadWindow(false);
        }
    });
    holder.add(reloadSession);
    Button continueSession = new Button(MESSAGES.invalidSessionDialogButtonContinue());
    continueSession.addClickListener(new ClickListener() {
        public void onClick(Widget sender) {
            dialogBox.hide();
            bashWarningDialog();
        }
    });
    holder.add(continueSession);
    DialogBoxContents.add(message);
    DialogBoxContents.add(holder);
    dialogBox.setWidget(DialogBoxContents);
    dialogBox.show();
}

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

License:Open Source License

/**
 * The user has chosen to continue a session even though
 * others are still active. This risks damaging (bashing) projects.
 * So before we proceed, we provide a stern warning. If they press
 * "Continue" we set their sessionId to "force" which is recognized
 * by the backend as a sessionId that should always match. This is
 * safe because normal sessionIds are UUIDs which are always longer
 * then the word "force." I know this is a bit kludgey, but by doing
 * it this way we don't have to change the RPC interface which makes
 * releasing this code non-disruptive to people using App Inventor
 * during the release.// w ww  .j a  v  a 2  s  .  c  o m
 *
 * If the user selects "Cancel" we take them back to the
 * invalidSessionDialog.
 */

private void bashWarningDialog() {
    // Create the UI elements of the DialogBox
    final DialogBox dialogBox = new DialogBox(false, true); // DialogBox(autohide, modal)
    dialogBox.setStylePrimaryName("ode-DialogBox");
    dialogBox.setText(MESSAGES.bashWarningDialogText());
    dialogBox.setHeight("200px");
    dialogBox.setWidth("800px");
    dialogBox.setGlassEnabled(true);
    dialogBox.setAnimationEnabled(true);
    dialogBox.center();
    VerticalPanel DialogBoxContents = new VerticalPanel();
    HTML message = new HTML(MESSAGES.bashWarningDialogMessage());
    message.setStyleName("DialogBox-message");
    FlowPanel holder = new FlowPanel();
    Button continueSession = new Button(MESSAGES.bashWarningDialogButtonContinue());
    continueSession.addClickListener(new ClickListener() {
        public void onClick(Widget sender) {
            dialogBox.hide();
            sessionId = "force"; // OK, over-ride in place!
            // Because we ultimately got here from a failure in the save function...
            ChainableCommand cmd = new SaveAllEditorsCommand(null);
            cmd.startExecuteChain(Tracking.PROJECT_ACTION_SAVE_YA, getCurrentYoungAndroidProjectRootNode());
            // Will now go back to our regularly scheduled main loop
        }
    });
    holder.add(continueSession);
    Button cancelSession = new Button(MESSAGES.bashWarningDialogButtonNo());
    cancelSession.addClickListener(new ClickListener() {
        public void onClick(Widget sender) {
            dialogBox.hide();
            invalidSessionDialog();
        }
    });
    holder.add(cancelSession);
    DialogBoxContents.add(message);
    DialogBoxContents.add(holder);
    dialogBox.setWidget(DialogBoxContents);
    dialogBox.show();
}

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 w  w  . j ava 2  s  .c  o 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:com.google.appinventor.client.Ode.java

License:Open Source License

/**
 * Display a Dialog box that explains that you cannot connect a
 * device or the emulator to App Inventor until you have a project
 * selected.//from   ww  w. ja v a 2  s .co  m
 */

private void wontConnectDialog() {
    // Create the UI elements of the DialogBox
    final DialogBox dialogBox = new DialogBox(false, true); // DialogBox(autohide, modal)
    dialogBox.setStylePrimaryName("ode-DialogBox");
    dialogBox.setText(MESSAGES.noprojectDialogTitle());
    dialogBox.setHeight("100px");
    dialogBox.setWidth("400px");
    dialogBox.setGlassEnabled(true);
    dialogBox.setAnimationEnabled(true);
    dialogBox.center();
    VerticalPanel DialogBoxContents = new VerticalPanel();
    HTML message = new HTML("<p>" + MESSAGES.noprojectDuringConnect() + "</p>");
    message.setStyleName("DialogBox-message");
    FlowPanel holder = new FlowPanel();
    Button okButton = new Button("OK");
    okButton.addClickListener(new ClickListener() {
        public void onClick(Widget sender) {
            dialogBox.hide();
        }
    });
    holder.add(okButton);
    DialogBoxContents.add(message);
    DialogBoxContents.add(holder);
    dialogBox.setWidget(DialogBoxContents);
    dialogBox.show();
}

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

License:Open Source License

/**
 * Display a generic warning dialog box.
 * This method is public because it is intended to be used from other
 * parts of the client GWT side system.//from www.  j  av  a2 s. c om
 *
 * Note: We expect our caller to internationalize the messages to be
 * displayed.
 *
 * @param title The title for the dialog box
 * @param message The message to display
 * @param buttonString the name of the button, i.e., "OK"
 */

public void warningDialog(String title, String messageString, String buttonString) {
    // Create the UI elements of the DialogBox
    final DialogBox dialogBox = new DialogBox(false, true); // DialogBox(autohide, modal)
    dialogBox.setStylePrimaryName("ode-DialogBox");
    dialogBox.setText(title);
    dialogBox.setHeight("100px");
    dialogBox.setWidth("400px");
    dialogBox.setGlassEnabled(true);
    dialogBox.setAnimationEnabled(true);
    dialogBox.center();
    VerticalPanel DialogBoxContents = new VerticalPanel();
    HTML message = new HTML("<p>" + messageString + "</p>");
    message.setStyleName("DialogBox-message");
    FlowPanel holder = new FlowPanel();
    Button okButton = new Button(buttonString);
    okButton.addClickListener(new ClickListener() {
        public void onClick(Widget sender) {
            dialogBox.hide();
        }
    });
    holder.add(okButton);
    DialogBoxContents.add(message);
    DialogBoxContents.add(holder);
    dialogBox.setWidget(DialogBoxContents);
    dialogBox.show();
}

From source file:com.google.appinventor.client.output.OdeLog.java

License:Open Source License

/**
 * Creates a new output panel for displaying internal messages.
 *//* w w w .  java2  s.c o  m*/
private OdeLog() {
    // Initialize UI
    Button clearButton = new Button(MESSAGES.clearButton());
    clearButton.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            clear();
        }
    });

    text = new HTML();
    text.setWidth("100%");

    VerticalPanel panel = new VerticalPanel();
    panel.add(clearButton);
    panel.add(text);
    panel.setSize("100%", "100%");
    panel.setCellHeight(text, "100%");
    panel.setCellWidth(text, "100%");

    initWidget(panel);
}

From source file:com.google.appinventor.client.utils.MessageDialog.java

License:Open Source License

/**
 * Put up a modal dialog box./*  w  ww. j a  v a  2  s .c om*/
 *
 * @param title Title for the dialog, already internationalized
 * @param message Message box content, already internationalized
 * @param OK String for OK button, already internationalized
 * @param Cancel String for Cancel button, null if non, internationalized
 * @param actions Actions object to call upon completion, can be null
 */
public static void messageDialog(String title, String message, String OK, String Cancel,
        final Actions actions) {
    final DialogBox dialogBox = new DialogBox(false, true); // DialogBox(autohide, modal)
    dialogBox.setStylePrimaryName("ode-DialogBox");
    dialogBox.setText(title);
    dialogBox.setHeight("100px");
    dialogBox.setWidth("400px");
    dialogBox.setGlassEnabled(true);
    dialogBox.setAnimationEnabled(true);
    dialogBox.center();
    VerticalPanel DialogBoxContents = new VerticalPanel();
    HTML messageHtml = new HTML("<p>" + message + "</p>");
    messageHtml.setStyleName("DialogBox-message");
    FlowPanel holder = new FlowPanel();
    Button okButton = new Button(OK);
    okButton.addClickListener(new ClickListener() {
        public void onClick(Widget sender) {
            dialogBox.hide();
            if (actions != null)
                actions.onOK();
        }
    });
    holder.add(okButton);
    if (Cancel != null) {
        Button cancelButton = new Button(Cancel);
        cancelButton.addClickListener(new ClickListener() {
            @Override
            public void onClick(Widget sender) {
                dialogBox.hide();
                if (actions != null)
                    actions.onCancel();
            }
        });
        holder.add(cancelButton);
    }
    DialogBoxContents.add(messageHtml);
    DialogBoxContents.add(holder);
    dialogBox.setWidget(DialogBoxContents);
    dialogBox.show();
}

From source file:com.google.appinventor.client.widgets.properties.AdditionalChoicePropertyEditor.java

License:Open Source License

/**
 * Initializes the additional choice panel.
 *
 * <p>This method must be called from any implementor's constructor.
 *
 * @param panel  panel containing additional choices
 *///ww w.j  a v  a 2s .c o m
protected void initAdditionalChoicePanel(Panel panel) {
    Button cancelButton = new Button(MESSAGES.cancelButton());
    cancelButton.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            closeAdditionalChoiceDialog(false);
        }
    });
    Button okButton = new Button(MESSAGES.okButton());
    okButton.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            closeAdditionalChoiceDialog(true);
        }
    });

    HorizontalPanel buttonPanel = new HorizontalPanel();
    buttonPanel.add(cancelButton);
    buttonPanel.add(okButton);
    buttonPanel.setWidth("100%");
    buttonPanel.setHorizontalAlignment(HorizontalPanel.ALIGN_RIGHT);

    VerticalPanel contentPanel = new VerticalPanel();
    contentPanel.add(panel);
    contentPanel.add(buttonPanel);

    popup = new PopupPanel(false, true);
    popup.setAutoHideEnabled(true);
    popup.setWidget(contentPanel);
    popup.setStylePrimaryName("ode-MultipleChoicePropertyEditor");
}

From source file:com.google.appinventor.client.wizards.FileUploadWizard.java

License:Open Source License

private void createErrorDialog(String title, String body, Error e, final FolderNode folderNode,
        final FileUploadedCallback fileUploadedCallback) {
    final DialogBox dialogBox = new DialogBox(false, true);
    HTML message;/*from   ww  w.j a  v  a  2  s  . co  m*/
    dialogBox.setStylePrimaryName("ode-DialogBox");
    dialogBox.setHeight("150px");
    dialogBox.setWidth("350px");
    dialogBox.setGlassEnabled(true);
    dialogBox.setAnimationEnabled(true);
    dialogBox.center();
    VerticalPanel DialogBoxContents = new VerticalPanel();
    FlowPanel holder = new FlowPanel();
    Button ok = new Button("OK");
    ok.addClickListener(new ClickListener() {
        public void onClick(Widget sender) {
            dialogBox.hide();
            new FileUploadWizard(folderNode, fileUploadedCallback).show();
        }
    });
    holder.add(ok);
    dialogBox.setText(title);
    message = new HTML(body);

    switch (e) {
    case AIAMEDIAASSET:
        Button info = new Button("More Info");
        info.addClickListener(new ClickListener() {
            public void onClick(Widget sender) {
                Window.open(MESSAGES.aiaMediaAssetHelp(), "AIA Help", "");
            }
        });
        holder.add(info);
    case NOFILESELECETED:
    case MALFORMEDFILENAME:
    case FILENAMEBADSIZE:
    default:
        break;
    }

    message.setStyleName("DialogBox-message");
    DialogBoxContents.add(message);
    DialogBoxContents.add(holder);
    dialogBox.setWidget(DialogBoxContents);
    dialogBox.show();
}

From source file:com.google.appinventor.client.wizards.Wizard.java

License:Open Source License

/**
 * Creates a new wizard./*from  w ww .  ja  v  a  2s. com*/
 * <p>
 * Implementations are expected to build the wizard dialog in their
 * constructor. In particular, it is expected that
 * {@link #addPage(Panel)} and {@link #initFinishCommand(Command)}
 * will be called before the constructor terminates.
 *
 * @param title title displayed in wizard dialog box
 * @param modal indicates modality of the wizard
 * @param adaptiveSizing instead of using the minimal size for the
 *                       wizard also considers the size of the browser area
 */
protected Wizard(String title, boolean modal, boolean adaptiveSizing) {
    // Initialize UI
    // TODO(lizlooney) - investigate using built-in modality support. The
    // reasons for not using it initially are no longer valid.
    super(false, false);

    this.modal = modal;
    this.adaptiveSizing = adaptiveSizing;

    setStylePrimaryName("ode-DialogBox");
    setText(title);

    ClickListener buttonListener = new ClickListener() {
        @Override
        public void onClick(Widget sender) {
            if (sender == cancelButton) {
                handleCancelClick();
            } else if (sender == nextButton) {
                showNextPage();
            } else if (sender == backButton) {
                showPreviousPage();
            } else if (sender == okButton) {
                handleOkClick();
            }
        }
    };
    cancelButton = new Button(MESSAGES.cancelButton());
    cancelButton.addClickListener(buttonListener);
    backButton = new Button(MESSAGES.backButton());
    backButton.addClickListener(buttonListener);
    nextButton = new Button(MESSAGES.nextButton());
    nextButton.addClickListener(buttonListener);
    okButton = new Button(MESSAGES.okButton());
    okButton.addClickListener(buttonListener);

    buttonPanel = new HorizontalPanel();
    buttonPanel.add(cancelButton);
    buttonPanel.add(backButton);
    buttonPanel.add(nextButton);
    buttonPanel.add(okButton);
    buttonPanel.setSize("100%", "24px");

    pageDeck = new DeckPanel();
    pageDeck.setSize("100%", "100%");

    pagePanel = new AbsolutePanel();
    pagePanel.add(pageDeck);
    pagePanel.setWidth("100%");

    VerticalPanel contentPanel = new VerticalPanel();
    contentPanel.add(pagePanel);
    contentPanel.add(buttonPanel);
    contentPanel.setSize("100%", "100%");

    add(contentPanel);
}