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

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

Introduction

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

Prototype

@Override
    public void show() 

Source Link

Usage

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

License:Open Source License

/**
 * Creates, visually centers, and optionally displays the dialog box
 * that informs the user how to start learning about using App Inventor
 * or create a new project.// w w w . j  a v a  2s  . c  o m
 * @param showDialog Convenience variable to show the created DialogBox.
 * @return The created and optionally displayed Dialog box.
 */
public DialogBox createNoProjectsDialog(boolean showDialog) {
    // Create the UI elements of the DialogBox
    final DialogBox dialogBox = new DialogBox(true, false); //DialogBox(autohide, modal)
    dialogBox.setStylePrimaryName("ode-DialogBox");
    dialogBox.setText(MESSAGES.createNoProjectsDialogText());

    Grid mainGrid = new Grid(2, 2);
    mainGrid.getCellFormatter().setAlignment(0, 0, HasHorizontalAlignment.ALIGN_CENTER,
            HasVerticalAlignment.ALIGN_MIDDLE);
    mainGrid.getCellFormatter().setAlignment(0, 1, HasHorizontalAlignment.ALIGN_CENTER,
            HasVerticalAlignment.ALIGN_MIDDLE);
    mainGrid.getCellFormatter().setAlignment(1, 1, HasHorizontalAlignment.ALIGN_RIGHT,
            HasVerticalAlignment.ALIGN_MIDDLE);

    Image dialogImage = new Image(Ode.getImageBundle().androidGreenSmall());

    Grid messageGrid = new Grid(2, 1);
    messageGrid.getCellFormatter().setAlignment(0, 0, HasHorizontalAlignment.ALIGN_JUSTIFY,
            HasVerticalAlignment.ALIGN_MIDDLE);
    messageGrid.getCellFormatter().setAlignment(1, 0, HasHorizontalAlignment.ALIGN_LEFT,
            HasVerticalAlignment.ALIGN_MIDDLE);

    Label messageChunk1 = new HTML(MESSAGES.createNoProjectsDialogMessage1());

    messageChunk1.setWidth("23em");
    Label messageChunk2 = new Label(MESSAGES.createNoprojectsDialogMessage2());

    // Add the elements to the grids and DialogBox.
    messageGrid.setWidget(0, 0, messageChunk1);
    messageGrid.setWidget(1, 0, messageChunk2);
    mainGrid.setWidget(0, 0, dialogImage);
    mainGrid.setWidget(0, 1, messageGrid);

    dialogBox.setWidget(mainGrid);
    dialogBox.center();

    if (showDialog) {
        dialogBox.show();
    }

    return dialogBox;
}

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

License:Open Source License

/**
 * Possibly display the MIT App Inventor "Splash Screen"
 *
 * @param force Bypass the check to see if they have dimissed this version
 *//* ww  w . j av a  2 s. co m*/
private void createWelcomeDialog(boolean force) {
    if (!shouldShowWelcomeDialog() && !force) {
        openProjectsTab();
        return;
    }
    // Create the UI elements of the DialogBox
    final DialogBox dialogBox = new DialogBox(false, true); // DialogBox(autohide, modal)
    dialogBox.setStylePrimaryName("ode-DialogBox");
    dialogBox.setText(MESSAGES.createWelcomeDialogText());
    dialogBox.setHeight(splashConfig.height + "px");
    dialogBox.setWidth(splashConfig.width + "px");
    dialogBox.setGlassEnabled(true);
    dialogBox.setAnimationEnabled(true);
    dialogBox.center();
    VerticalPanel DialogBoxContents = new VerticalPanel();
    HTML message = new HTML(splashConfig.content);
    message.setStyleName("DialogBox-message");
    FlowPanel holder = new FlowPanel();
    Button ok = new Button(MESSAGES.createWelcomeDialogButton());
    final CheckBox noshow = new CheckBox(MESSAGES.doNotShow());
    ok.addClickListener(new ClickListener() {
        public void onClick(Widget sender) {
            dialogBox.hide();
            if (noshow.getValue()) { // User checked the box
                userSettings.getSettings(SettingsConstants.SPLASH_SETTINGS).changePropertyValue(
                        SettingsConstants.SPLASH_SETTINGS_VERSION, "" + splashConfig.version);
                userSettings.saveSettings(null);
            }
            openProjectsTab();
        }
    });
    holder.add(ok);
    holder.add(noshow);
    DialogBoxContents.add(message);
    DialogBoxContents.add(holder);
    dialogBox.setWidget(DialogBoxContents);
    dialogBox.show();
}

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

License:Open Source License

/**
 * Show a Survey Splash Screen to the user if they have not previously
 * acknowledged it.//w w  w .ja  v  a 2s .  c om
 */
private void showSurveySplash() {
    // Create the UI elements of the DialogBox
    if (isReadOnly) { // Bypass the survey if we are read-only
        maybeShowSplash();
        return;
    }
    final DialogBox dialogBox = new DialogBox(false, true); // DialogBox(autohide, modal)
    dialogBox.setStylePrimaryName("ode-DialogBox");
    dialogBox.setText(MESSAGES.createWelcomeDialogText());
    dialogBox.setHeight("200px");
    dialogBox.setWidth("600px");
    dialogBox.setGlassEnabled(true);
    dialogBox.setAnimationEnabled(true);
    dialogBox.center();
    VerticalPanel DialogBoxContents = new VerticalPanel();
    HTML message = new HTML(MESSAGES.showSurveySplashMessage());
    message.setStyleName("DialogBox-message");
    FlowPanel holder = new FlowPanel();
    Button takesurvey = new Button(MESSAGES.showSurveySplashButtonNow());
    takesurvey.addClickListener(new ClickListener() {
        public void onClick(Widget sender) {
            dialogBox.hide();
            // Update Splash Settings here
            userSettings.getSettings(SettingsConstants.SPLASH_SETTINGS).changePropertyValue(
                    SettingsConstants.SPLASH_SETTINGS_SHOWSURVEY, "" + YaVersion.SPLASH_SURVEY);
            userSettings.saveSettings(null);
            takeSurvey(); // Open survey in a new window
            maybeShowSplash();
        }
    });
    holder.add(takesurvey);
    Button latersurvey = new Button(MESSAGES.showSurveySplashButtonLater());
    latersurvey.addClickListener(new ClickListener() {
        public void onClick(Widget sender) {
            dialogBox.hide();
            maybeShowSplash();
        }
    });
    holder.add(latersurvey);
    Button neversurvey = new Button(MESSAGES.showSurveySplashButtonNever());
    neversurvey.addClickListener(new ClickListener() {
        public void onClick(Widget sender) {
            dialogBox.hide();
            // Update Splash Settings here
            Settings settings = userSettings.getSettings(SettingsConstants.SPLASH_SETTINGS);
            settings.changePropertyValue(SettingsConstants.SPLASH_SETTINGS_SHOWSURVEY,
                    "" + YaVersion.SPLASH_SURVEY);
            String declined = settings.getPropertyValue(SettingsConstants.SPLASH_SETTINGS_DECLINED);
            if (declined == null)
                declined = ""; // Shouldn't happen
            if (declined != "")
                declined += ",";
            declined += "" + YaVersion.SPLASH_SURVEY; // Record that we declined this survey
            settings.changePropertyValue(SettingsConstants.SPLASH_SETTINGS_DECLINED, declined);
            userSettings.saveSettings(null);
            maybeShowSplash();
        }
    });
    holder.add(neversurvey);
    DialogBoxContents.add(message);
    DialogBoxContents.add(holder);
    dialogBox.setWidget(DialogBoxContents);
    dialogBox.show();
}

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

License:Open Source License

/**
 * Show a Dialog Box when we receive an SC_PRECONDITION_FAILED
 * response code to any Async RPC call. This is a signal that
 * either our session has expired, or our login cookie has otherwise
 * become invalid. This is a fatal error and the user should not
 * be permitted to continue (many ignore the red error bar and keep
 * working, in vain). So now when this happens, we put up this
 * modal dialog box which cannot be dismissed. Instead it presents
 * just one option, a "Reload" button which reloads the browser.
 * This should trigger a re-authentication (or in the case of an
 * App Inventor upgrade trigging the problem, the loading of newer
 * code)./*from  w w w .  j av  a2 s.  com*/
 */

public void sessionDead() {
    // 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.setWidth("400px");
    dialogBox.setGlassEnabled(true);
    dialogBox.setAnimationEnabled(true);
    dialogBox.center();
    VerticalPanel DialogBoxContents = new VerticalPanel();
    HTML message = new HTML(MESSAGES.sessionDead());
    message.setStyleName("DialogBox-message");
    FlowPanel holder = new FlowPanel();
    Button reloadSession = new Button(MESSAGES.reloadWindow());
    reloadSession.addClickListener(new ClickListener() {
        public void onClick(Widget sender) {
            dialogBox.hide();
            reloadWindow(true);
        }
    });
    holder.add(reloadSession);
    DialogBoxContents.add(message);
    DialogBoxContents.add(holder);
    dialogBox.setWidget(DialogBoxContents);
    dialogBox.show();
}

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./* www .j  av a  2  s  . co  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 av a 2 s. co  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

/**
 * The "Final" Dialog box. When a user chooses to end their session
 * due to a conflicting login, we should show this dialog which is modal
 * and has no exit! My preference would have been to close the window
 * altogether, but the browsers won't let javascript code close windows
 * that it didn't open itself (like the main window). I also tried to
 * use document.write() to write replacement HTML but that caused errors
 * in Firefox and strange behavior in Chrome. So we do this...
 *
 * We are called from invalidSessionDialog() (above).
 *///  www . ja  va 2 s  .  c  om
private void finalDialog() {
    // Create the UI elements of the DialogBox
    final DialogBox dialogBox = new DialogBox(false, true); // DialogBox(autohide, modal)
    dialogBox.setStylePrimaryName("ode-DialogBox");
    dialogBox.setText(MESSAGES.finalDialogText());
    dialogBox.setHeight("100px");
    dialogBox.setWidth("400px");
    dialogBox.setGlassEnabled(true);
    dialogBox.setAnimationEnabled(true);
    dialogBox.center();
    VerticalPanel DialogBoxContents = new VerticalPanel();
    HTML message = new HTML(MESSAGES.finalDialogMessage());
    message.setStyleName("DialogBox-message");
    DialogBoxContents.add(message);
    dialogBox.setWidget(DialogBoxContents);
    dialogBox.show();
}

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

License:Open Source License

/**
 * corruptionDialog -- Put up a dialog box explaining that we detected corruption
 * while reading in a project file. There is no continuing once this happens.
 *
 *///from   w  w w. j  a v  a2  s  .  com
void corruptionDialog() {
    // Create the UI elements of the DialogBox
    final DialogBox dialogBox = new DialogBox(false, true); // DialogBox(autohide, modal)
    dialogBox.setStylePrimaryName("ode-DialogBox");
    dialogBox.setText(MESSAGES.corruptionDialogText());
    dialogBox.setHeight("100px");
    dialogBox.setWidth("400px");
    dialogBox.setGlassEnabled(true);
    dialogBox.setAnimationEnabled(true);
    dialogBox.center();
    VerticalPanel DialogBoxContents = new VerticalPanel();
    HTML message = new HTML(MESSAGES.corruptionDialogMessage());
    message.setStyleName("DialogBox-message");
    DialogBoxContents.add(message);
    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  ww .j av a  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.//  w w  w  . j a 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();
}