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:net.sf.mmm.client.ui.gwt.widgets.richtext.RichTextToolbar.java

License:Apache License

/**
 * @param feature is the {@link RichTextFeature} to invoke (e.g. if according button has been clicked).
 *///w  ww.j  ava  2 s . co m
protected void invokeFeature(RichTextFeature feature) {

    switch (feature) {
    case BOLD:
        RichTextToolbar.this.formatter.toggleBold();
        break;
    case ITALIC:
        RichTextToolbar.this.formatter.toggleItalic();
        break;
    case UNDERLINE:
        RichTextToolbar.this.formatter.toggleUnderline();
        break;
    case SUBSCRIPT:
        RichTextToolbar.this.formatter.toggleSubscript();
        break;
    case SUPERSCRIPT:
        RichTextToolbar.this.formatter.toggleSuperscript();
        break;
    case STRIKETHROUGH:
        RichTextToolbar.this.formatter.toggleStrikethrough();
        break;
    case ALIGN_LEFT:
        RichTextToolbar.this.formatter.setJustification(Justification.LEFT);
        break;
    case ALIGN_CENTER:
        RichTextToolbar.this.formatter.setJustification(Justification.CENTER);
        break;
    case ALIGN_RIGHT:
        RichTextToolbar.this.formatter.setJustification(Justification.RIGHT);
        break;
    case UNORDERED_LIST:
        RichTextToolbar.this.formatter.insertUnorderedList();
        break;
    case ORDERED_LIST:
        RichTextToolbar.this.formatter.insertOrderedList();
        break;
    case HORIZONTAL_LINE:
        RichTextToolbar.this.formatter.insertHorizontalRule();
        break;
    case INSERT_IMAGE:
        String url = Window.prompt(this.bundle.labelEnterImageUrl().getLocalizedMessage(), "http://");
        if (url != null) {
            RichTextToolbar.this.formatter.insertImage(url);
        }
        break;
    case INSERT_LINK:
        url = Window.prompt(this.bundle.labelEnterLinkUrl().getLocalizedMessage(), "http://");
        if (url != null) {
            RichTextToolbar.this.formatter.createLink(url);
            // this.linkMode = true;
        }
        break;
    case REMOVE_FORMAT:
        this.formatter.removeFormat();
        this.formatter.removeLink();
        break;
    case FONT_FAMILY:
        final DialogBox popup = new DialogBox();
        popup.setStylePrimaryName("Popup");
        popup.setText("Please choose font");
        Grid content = new Grid(3, 2);
        content.setWidget(0, 0, new Label("Font-Family"));
        final ListBox dropdownFontFamily = new ListBox(false);
        for (String font : JavaScriptUtil.getInstance().getAvailableFonts()) {
            dropdownFontFamily.addItem(font);
        }
        content.setWidget(0, 1, dropdownFontFamily);
        content.setWidget(1, 0, new Label("Font-Size"));
        final ListBox dropdownFontSize = new ListBox(false);
        for (FontSize size : FONT_SIZES) {
            dropdownFontSize.addItem(Integer.toString(size.getNumber()));
        }
        content.setWidget(1, 1, dropdownFontSize);
        Button widget = new Button("OK");
        ClickHandler handler = new ClickHandler() {

            @Override
            public void onClick(ClickEvent event) {

                popup.hide();
                String fontFamily = dropdownFontFamily.getValue(dropdownFontFamily.getSelectedIndex());
                RichTextToolbar.this.formatter.setFontName(fontFamily);
                String fontSize = dropdownFontSize.getValue(dropdownFontSize.getSelectedIndex());
                for (FontSize size : FONT_SIZES) {
                    if (Integer.toString(size.getNumber()).equals(fontSize)) {
                        RichTextToolbar.this.formatter.setFontSize(size);
                    }
                }
            }
        };
        widget.addClickHandler(handler);
        content.setWidget(2, 0, widget);
        popup.setGlassEnabled(true);
        popup.setWidget(content);
        popup.center();
        popup.show();
        break;
    case FONT_SIZE:
        JsSelection selection = JavaScriptUtil.getInstance()
                .getSelection(RichTextToolbar.this.richTextArea.getElement());
        Window.alert(selection.getText() + "\n" + selection.getHtml());
        // RichTextToolbar.this.formatter.setFontSize(fontSize);
        break;
    case INDENT:
        RichTextToolbar.this.formatter.rightIndent();
        break;
    case OUTDENT:
        RichTextToolbar.this.formatter.leftIndent();
        break;
    case UNDO:
        RichTextToolbar.this.formatter.undo();
        break;
    case REDO:
        RichTextToolbar.this.formatter.redo();
        break;
    default:
        break;
    }
}

From source file:net.urlgrey.mythpodcaster.client.AddSubscriptionHandler.java

License:Open Source License

@Override
public void onClick(ClickEvent arg0) {
    // Create a dialog box and set the caption text
    final DialogBox dialogBox = new DialogBox();
    dialogBox.ensureDebugId("cwDialogBox");
    dialogBox.setText("Add Transcoding Profile Subscription");

    // Create a table to layout the content
    VerticalPanel dialogContents = new VerticalPanel();
    dialogContents.setSpacing(4);/*  w  ww  .  j  a va  2  s  .  co  m*/
    dialogBox.setWidget(dialogContents);

    // Transcoding Profile Selection
    final ListBox profileListBox;
    if (transcodingProfile == null) {
        HorizontalPanel listBoxPanel = new HorizontalPanel();
        listBoxPanel.add(new HTML("Transcoding Profile: "));
        profileListBox = new ListBox();
        listBoxPanel.add(profileListBox);
        dialogContents.add(listBoxPanel);
    } else {
        profileListBox = null;
    }

    final HorizontalPanel mostRecentPanel = new HorizontalPanel();
    mostRecentPanel.add(new HTML("Number of most recent to transcode: "));
    final ListBox mostRecentListBox = new ListBox();
    mostRecentListBox.addItem("1");
    mostRecentListBox.addItem("2");
    mostRecentListBox.addItem("3");
    mostRecentListBox.addItem("4");
    mostRecentListBox.addItem("5");
    mostRecentListBox.addItem("6");
    mostRecentListBox.addItem("7");
    mostRecentListBox.addItem("8");
    mostRecentListBox.addItem("9");
    mostRecentListBox.addItem("10");
    mostRecentPanel.add(mostRecentListBox);
    mostRecentPanel.setVisible(false);

    final HorizontalPanel specificRecordingsPanel = new HorizontalPanel();
    specificRecordingsPanel.add(new HTML("Specific Recordings: "));
    final ListBox recordingsListBox = new ListBox(true);
    recordingsListBox.setVisibleItemCount(5);
    specificRecordingsPanel.add(recordingsListBox);
    specificRecordingsPanel.setVisible(false);

    HorizontalPanel scopePanel = new HorizontalPanel();
    scopePanel.add(new HTML("Scope: "));
    final ListBox scopeListBox = new ListBox();
    scopeListBox.addItem("All recordings", SCOPE_ALL);
    scopeListBox.addItem("Number of Most Recent Recordings", SCOPE_MOST_RECENT);
    scopeListBox.addItem("Specific Recordings", SCOPE_SPECIFIC_RECORDINGS);
    scopePanel.add(scopeListBox);

    scopeListBox.addChangeHandler(new ChangeHandler() {

        @Override
        public void onChange(ChangeEvent arg0) {
            switch (scopeListBox.getSelectedIndex()) {
            case SCOPE_INDEX_ALL:
                mostRecentPanel.setVisible(false);
                specificRecordingsPanel.setVisible(false);
                dialogBox.center();
                break;
            case SCOPE_INDEX_MOST_RECENT:
                mostRecentPanel.setVisible(true);
                specificRecordingsPanel.setVisible(false);
                dialogBox.center();
                break;
            case SCOPE_INDEX_SPECIFIC_RECORDINGS:
                mostRecentPanel.setVisible(false);
                UIControllerServiceAsync service = (UIControllerServiceAsync) GWT
                        .create(UIControllerService.class);

                try {
                    service.listRecordingsForSeries(seriesId, new AsyncCallback<List<String[]>>() {

                        @Override
                        public void onFailure(Throwable arg0) {
                        }

                        @Override
                        public void onSuccess(List<String[]> recordings) {
                            recordingsListBox.clear();
                            final DateTimeFormat format = DateTimeFormat
                                    .getFormat(DateTimeFormat.PredefinedFormat.DATE_MEDIUM);
                            for (String[] recording : recordings) {
                                Date d = new Date(Long.valueOf(recording[2]));
                                final String recordingTitle = (recording[1] != null
                                        && recording[1].trim().length() > 0) ? recording[1] : seriesTitle;
                                final String label = "[" + format.format(d) + "] " + recordingTitle;
                                recordingsListBox.addItem(label, recording[0]);
                            }
                            specificRecordingsPanel.setVisible(true);
                            dialogBox.center();
                        }
                    });
                } catch (Exception e) {
                    e.printStackTrace();
                }

                break;
            }
        }
    });

    dialogContents.add(scopePanel);
    dialogContents.add(mostRecentPanel);
    dialogContents.add(specificRecordingsPanel);

    // Add a cancel button at the bottom of the dialog
    final Button cancelButton = new Button("Cancel", new ClickHandler() {
        public void onClick(ClickEvent event) {
            dialogBox.hide();
        }
    });

    // Add a cancel button at the bottom of the dialog
    final Button okButton = new Button("OK", new ClickHandler() {

        public void onClick(ClickEvent event) {
            UIControllerServiceAsync service = (UIControllerServiceAsync) GWT.create(UIControllerService.class);
            try {
                final FeedSubscriptionItemDTO item = new FeedSubscriptionItemDTO();
                item.setDateAdded(new Date());
                item.setSeriesId(seriesId);
                item.setTitle(seriesTitle);
                if (profileListBox != null) {
                    item.setTranscodeProfile(profileListBox.getValue(profileListBox.getSelectedIndex()));
                } else {
                    item.setTranscodeProfile(transcodingProfile);
                }

                switch (scopeListBox.getSelectedIndex()) {
                case SCOPE_INDEX_MOST_RECENT:
                    item.setScope(SCOPE_MOST_RECENT);
                    item.setNumberOfMostRecentToKeep(
                            Integer.parseInt(mostRecentListBox.getValue(mostRecentListBox.getSelectedIndex())));
                    break;
                case SCOPE_INDEX_SPECIFIC_RECORDINGS:
                    final Set<String> selectedRecordings = new HashSet<String>();
                    final int recordingCount = recordingsListBox.getItemCount();
                    for (int i = 0; i < recordingCount; i++) {
                        if (recordingsListBox.isItemSelected(i)) {
                            selectedRecordings.add(recordingsListBox.getValue(i));
                        }
                    }

                    final String[] result = selectedRecordings.toArray(new String[0]);
                    item.setScope(SCOPE_SPECIFIC_RECORDINGS);
                    item.setRecordedProgramKeys(result);
                    break;
                default:
                    item.setScope(SCOPE_ALL);
                    break;
                }

                // add subscription on the backend
                service.addSubscription(item, new AsyncCallback<Boolean>() {

                    @Override
                    public void onFailure(Throwable arg0) {
                        parent.refreshData();
                    }

                    @Override
                    public void onSuccess(Boolean arg0) {
                        parent.refreshData();
                    }
                });
            } catch (Exception e) {
                e.printStackTrace();
            }

            dialogBox.hide();
        }
    });

    final SimplePanel buttonTopSpacer = new SimplePanel();
    buttonTopSpacer.setHeight("20px");

    final SimplePanel buttonSpacer = new SimplePanel();
    buttonSpacer.setWidth("30px");

    HorizontalPanel buttonRow = new HorizontalPanel();
    buttonRow.add(cancelButton);
    buttonRow.add(buttonSpacer);
    buttonRow.add(okButton);
    dialogContents.add(buttonTopSpacer);
    dialogContents.add(buttonRow);
    dialogContents.setCellHorizontalAlignment(buttonRow, HasHorizontalAlignment.ALIGN_CENTER);
    if (LocaleInfo.getCurrentLocale().isRTL()) {
        dialogContents.setCellHorizontalAlignment(cancelButton, HasHorizontalAlignment.ALIGN_LEFT);

    } else {
        dialogContents.setCellHorizontalAlignment(cancelButton, HasHorizontalAlignment.ALIGN_RIGHT);
    }

    if (profileListBox == null) {
        // populate the dialog with the current settings in the backend

        UIControllerServiceAsync service = (UIControllerServiceAsync) GWT.create(UIControllerService.class);
        try {
            service.retrieveSubscriptionDetails(seriesId, transcodingProfile,
                    new AsyncCallback<FeedSubscriptionItemDTO>() {

                        @Override
                        public void onFailure(Throwable arg0) {

                        }

                        @Override
                        public void onSuccess(final FeedSubscriptionItemDTO item) {
                            if (SCOPE_MOST_RECENT.equals(item.getScope())) {
                                scopeListBox.setSelectedIndex(SCOPE_INDEX_MOST_RECENT);
                                mostRecentListBox.setSelectedIndex(item.getNumberOfMostRecentToKeep() - 1);
                                mostRecentPanel.setVisible(true);
                                specificRecordingsPanel.setVisible(false);
                                dialogBox.center();
                            } else if (SCOPE_SPECIFIC_RECORDINGS.equals(item.getScope())) {
                                scopeListBox.setSelectedIndex(SCOPE_INDEX_SPECIFIC_RECORDINGS);
                                UIControllerServiceAsync service = (UIControllerServiceAsync) GWT
                                        .create(UIControllerService.class);

                                try {
                                    service.listRecordingsForSeries(seriesId,
                                            new AsyncCallback<List<String[]>>() {

                                                @Override
                                                public void onFailure(Throwable arg0) {
                                                }

                                                @Override
                                                public void onSuccess(List<String[]> recordings) {
                                                    recordingsListBox.clear();
                                                    final DateTimeFormat format = DateTimeFormat.getFormat(
                                                            DateTimeFormat.PredefinedFormat.DATE_MEDIUM);
                                                    int i = 0;
                                                    for (String[] recording : recordings) {
                                                        Date d = new Date(Long.valueOf(recording[2]));
                                                        final String recordingTitle = (recording[1] != null
                                                                && recording[1].trim().length() > 0)
                                                                        ? recording[1]
                                                                        : seriesTitle;
                                                        final String label = "[" + format.format(d) + "] "
                                                                + recordingTitle;
                                                        recordingsListBox.addItem(label, recording[0]);
                                                        for (String id : item.getRecordedProgramKeys()) {
                                                            if (id.equals(recording[0])) {
                                                                recordingsListBox.setItemSelected(i, true);
                                                                break;
                                                            }
                                                        }
                                                        i++;
                                                    }

                                                    dialogBox.center();
                                                }
                                            });
                                } catch (Exception e) {
                                    e.printStackTrace();
                                }

                                mostRecentPanel.setVisible(false);
                                specificRecordingsPanel.setVisible(true);
                            } else {
                                scopeListBox.setSelectedIndex(SCOPE_INDEX_ALL);
                                mostRecentPanel.setVisible(false);
                                specificRecordingsPanel.setVisible(false);
                                dialogBox.center();
                            }
                        }
                    });
        } catch (Exception e) {
        }
    } else {
        // configure the dialog to show the transcoding profiles that are not already in use with this
        // program

        UIControllerServiceAsync service = (UIControllerServiceAsync) GWT.create(UIControllerService.class);
        try {
            service.findAvailableTranscodingProfilesForSeries(seriesId, new AsyncCallback<List<String[]>>() {

                @Override
                public void onFailure(Throwable arg0) {

                }

                @Override
                public void onSuccess(List<String[]> profiles) {
                    for (String[] profile : profiles) {
                        profileListBox.addItem(profile[1], profile[0]);
                    }

                    dialogBox.center();
                }
            });
        } catch (Exception e) {
        }
    }
}

From source file:net.urlgrey.mythpodcaster.client.UnsubscribeHandler.java

License:Open Source License

@Override
public void onClick(ClickEvent event) {
    // Create a dialog box and set the caption text
    final DialogBox dialogBox = new DialogBox();
    dialogBox.ensureDebugId("cwDialogBox");
    dialogBox.setText("Unsubscribe?");

    // Create a table to layout the content
    VerticalPanel dialogContents = new VerticalPanel();
    dialogContents.setSpacing(4);//from   w  w  w .  j ava 2  s .co m
    dialogBox.setWidget(dialogContents);

    // Add some text to the top of the dialog
    HTML details = new HTML("Are you sure you want to unsubscribe?");
    dialogContents.add(details);
    dialogContents.setCellHorizontalAlignment(details, HasHorizontalAlignment.ALIGN_CENTER);

    // Add a cancel button at the bottom of the dialog
    final Button cancelButton = new Button("Cancel", new ClickHandler() {
        public void onClick(ClickEvent event) {
            dialogBox.hide();
        }
    });

    // Add a cancel button at the bottom of the dialog
    final Button okButton = new Button("OK", new ClickHandler() {
        public void onClick(ClickEvent event) {
            UIControllerServiceAsync service = (UIControllerServiceAsync) GWT.create(UIControllerService.class);
            try {
                service.removeSubscription(seriesId, transcodingProfile, new AsyncCallback<Boolean>() {

                    @Override
                    public void onFailure(Throwable arg0) {
                        parent.refreshData();
                    }

                    @Override
                    public void onSuccess(Boolean arg0) {
                        parent.refreshData();
                    }
                });
            } catch (Exception e) {
                e.printStackTrace();
            }

            dialogBox.hide();
        }
    });

    final SimplePanel buttonTopSpacer = new SimplePanel();
    buttonTopSpacer.setHeight("20px");

    final SimplePanel buttonSpacer = new SimplePanel();
    buttonSpacer.setWidth("30px");

    HorizontalPanel buttonRow = new HorizontalPanel();
    buttonRow.add(cancelButton);
    buttonRow.add(buttonSpacer);
    buttonRow.add(okButton);
    dialogContents.add(buttonTopSpacer);
    dialogContents.add(buttonRow);
    dialogContents.setCellHorizontalAlignment(buttonRow, HasHorizontalAlignment.ALIGN_CENTER);
    if (LocaleInfo.getCurrentLocale().isRTL()) {
        dialogContents.setCellHorizontalAlignment(cancelButton, HasHorizontalAlignment.ALIGN_LEFT);

    } else {
        dialogContents.setCellHorizontalAlignment(cancelButton, HasHorizontalAlignment.ALIGN_RIGHT);
    }

    dialogBox.center();
    dialogBox.show();
}

From source file:nl.sense_os.commonsense.login.client.forgotpassword.ForgotPasswordActivity.java

License:Open Source License

private void onForgotPasswordFailure(int code, Throwable error) {
    errorDialog = new DialogBox();
    errorDialog.setHTML(SafeHtmlUtils.fromSafeConstant("<b>Request failed</b>"));

    AlertDialogContent content = new AlertDialogContent();
    content.setMessage(/*from w w w . j  av a 2  s .  c o  m*/
            "The request to reset your password failed! Error: " + code + " (" + error.getMessage() + ")");
    content.setPresenter(this);

    errorDialog.setWidget(content);
    errorDialog.center();
}

From source file:nl.sense_os.commonsense.login.client.forgotpassword.ForgotPasswordActivity.java

License:Open Source License

private void onForgotRequestSuccess() {
    successDialog = new DialogBox();
    successDialog.setHTML(SafeHtmlUtils.fromSafeConstant("<b>Requested password reset</b>"));

    AlertDialogContent content = new AlertDialogContent();
    content.setMessage("You will receive an email with a link to reset your password.");
    content.setPresenter(this);

    successDialog.setWidget(content);/*from   w  ww.  j ava2s  .c o m*/
    successDialog.center();
}

From source file:nl.sense_os.commonsense.login.client.forgotpassword.ForgotPasswordActivity.java

License:Open Source License

private void onUserNotFound() {
    errorDialog = new DialogBox();
    errorDialog.setHTML(SafeHtmlUtils.fromSafeConstant("<b>User not found</b>"));

    AlertDialogContent content = new AlertDialogContent();
    content.setMessage("We could not find a user in CommonSense with that username or email address.");
    content.setPresenter(this);

    errorDialog.setWidget(content);/*from   www .  j  a  v  a2s  .c  o  m*/
    errorDialog.center();
}

From source file:nl.sense_os.commonsense.login.client.login.LoginActivity.java

License:Open Source License

private void onAuthenticationFailure() {

    // enable view
    view.setBusy(false);/*from  ww  w.ja v a 2 s  . c  o  m*/

    // show alert
    alertDialog = new DialogBox();
    alertDialog.setHTML(SafeHtmlUtils.fromSafeConstant("<b>Login failed</b>"));

    AlertDialogContent content = new AlertDialogContent();
    content.setMessage("Login failed! Invalid username or password.");
    content.setPresenter(this);

    alertDialog.setWidget(content);
    alertDialog.center();
    content.setFocus(true);
}

From source file:nl.sense_os.commonsense.login.client.login.LoginActivity.java

License:Open Source License

private void onLoginFailure(int code, Throwable error) {

    // enable view
    view.setBusy(false);//from ww w.j  a va  2  s . co m

    // show alert
    alertDialog = new DialogBox();
    alertDialog.setHTML(SafeHtmlUtils.fromSafeConstant("<b>Login failed</b>"));

    AlertDialogContent content = new AlertDialogContent();
    content.setMessage("Login failed! Error: " + code + " (" + error.getMessage() + ")");
    content.setPresenter(this);

    alertDialog.setWidget(content);
    alertDialog.center();
}

From source file:nl.sense_os.commonsense.login.client.newpassword.NewPasswordActivity.java

License:Open Source License

private void onPasswordResetFailure(int code, Throwable error) {

    alertDialog = new DialogBox();
    alertDialog.setHTML(SafeHtmlUtils.fromSafeConstant("<b>Request failed</b>"));

    AlertDialogContent content = new AlertDialogContent();
    content.setMessage("Your password was not changed. Error: " + code + " (" + error.getMessage()
            + "). Please try to reset your password again.");
    content.setPresenter(this);

    alertDialog.setWidget(content);/*from  ww w  . j  a va 2s. co  m*/
    alertDialog.center();
}

From source file:nl.sense_os.commonsense.login.client.newpassword.NewPasswordActivity.java

License:Open Source License

private void onPasswordResetSuccess(String text) {

    alertDialog = new DialogBox();
    alertDialog.setHTML(SafeHtmlUtils.fromSafeConstant("<b>Password changed</b>"));

    AlertDialogContent content = new AlertDialogContent();
    content.setMessage("Your password was succesfully changed. You can now log in.");
    content.setPresenter(this);

    alertDialog.setWidget(content);/*from ww  w . j av a  2s  .  c  om*/
    alertDialog.center();
}