Example usage for com.google.gwt.user.client.ui RichTextArea getText

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

Introduction

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

Prototype

public String getText() 

Source Link

Usage

From source file:com.phideltcmu.recruiter.client.ui.popup.NotesAdder.java

License:Creative Commons License

public NotesAdder(final Person p, final StringCallback callback) {
    super();//  www  .  j  a va 2s . c o  m
    title.setText("Notes For " + p.getFullName());
    title.setStyleName("oldenburg150");
    final RichTextArea area = new RichTextArea();
    area.setSize("100%", "14em");
    String notes = p.getNotes();
    area.setHTML(notes == null ? "" : notes);

    // Add the components to a panel
    Grid grid = new Grid(4, 1);
    grid.setWidget(0, 0, title);
    grid.setWidget(1, 0, area);
    grid.setWidget(2, 0, saveButton);

    saveButton.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent clickEvent) {
            DynamicRecruiter.RECRUIT_SERVICE.saveNotes(p.getAndrewID(), area.getHTML(),
                    DynamicRecruiter.authUser.getAuthToken(), new AsyncCallback<Void>() {
                        @Override
                        public void onFailure(Throwable throwable) {
                            throwable.printStackTrace();
                        }

                        @Override
                        public void onSuccess(Void aVoid) {
                            notesAdder.hide();
                            Window.alert("Notes Saved!");
                            if (area.getText().length() == 0) {
                                callback.onStringReturned(null);
                            } else {
                                callback.onStringReturned(area.getHTML());
                            }
                        }
                    });
        }
    });
    this.bindWidget(grid);
}

From source file:org.sigmah.client.page.orgunit.reports.KeyQuestionDialog.java

License:Open Source License

public static Dialog getDialog(final KeyQuestionDTO keyQuestion, final RichTextArea textArea,
        final FoldPanel panel, final int toolButtonIndex, final KeyQuestionState keyQuestionState,
        boolean enabled) {
    final Dialog dialog = getDialog();
    dialog.setHeading(I18N.MESSAGES.reportKeyQuestionDialogTitle(Integer.toString(keyQuestion.getNumber())));

    // Question label
    final Label question = (Label) dialog.getWidget(0);
    question.setText(keyQuestion.getLabel());

    // Rich text editor
    final RichTextArea dialogTextArea = (RichTextArea) dialog.getWidget(1);
    dialogTextArea.setHTML(textArea.getHTML());

    final boolean wasValid = !"".equals(textArea.getText());

    // OK Button/*from  w  w  w .j a v a2s .  c o  m*/
    final Button okButton = dialog.getButtonById(Dialog.OK);

    okButton.removeAllListeners();

    if (enabled) {

        dialog.getTopComponent().enable();
        dialogTextArea.setEnabled(true);

        okButton.setVisible(true);
        okButton.addSelectionListener(new SelectionListener<ButtonEvent>() {
            @Override
            public void componentSelected(ButtonEvent ce) {
                dialog.hide();
                textArea.setHTML(dialogTextArea.getHTML());

                final boolean isValid = !"".equals(dialogTextArea.getText());

                final ToolbarImages images = GWT.create(ToolbarImages.class);
                if (isValid) {
                    panel.setToolButtonImage(toolButtonIndex, images.compasGreen());

                    if (!wasValid)
                        keyQuestionState.increaseValids();

                } else {
                    panel.setToolButtonImage(toolButtonIndex, images.compasRed());

                    if (wasValid)
                        keyQuestionState.decreaseValids();
                }
            }
        });

    } else {

        okButton.setVisible(false);

        dialog.getTopComponent().disable();
        dialogTextArea.setEnabled(false);
    }

    return dialog;
}

From source file:org.sigmah.client.page.orgunit.reports.OrgUnitReportsView.java

License:Open Source License

private void displaySection(final ProjectReportSectionDTO section, final FoldPanel parent,
        final StringBuilder prefix, int level, final boolean draftMode) {

    final FoldPanel sectionPanel = new FoldPanel();
    sectionPanel.setHeading(prefix.toString() + ' ' + section.getName());
    sectionPanel.addStyleName("project-report-level-" + level);

    int index = 1;
    int prefixLength = prefix.length();
    for (final ProjectReportContent object : section.getChildren()) {
        if (object.getClass() == ProjectReportSectionDTO.class) {
            prefix.append(index).append('.');

            displaySection((ProjectReportSectionDTO) object, sectionPanel, prefix, level + 1, draftMode);
            index++;//  w w w. j  av a  2s.  c  o  m

            prefix.setLength(prefixLength);

        } else if (object.getClass() == RichTextElementDTO.class) {

            if (draftMode) {
                final RichTextArea textArea = new RichTextArea();
                textArea.setHTML(((RichTextElementDTO) object).getText());

                textArea.addFocusHandler(new FocusHandler() {

                    @Override
                    public void onFocus(FocusEvent event) {
                        globalFormatterArray[0] = textArea.getFormatter();
                    }
                });

                sectionPanel.add(textArea);
                textAreas.put(((RichTextElementDTO) object).getId(), textArea);
                oldContents.put(((RichTextElementDTO) object).getId(), textArea.getText());

            } else {
                final HTML html = new HTML();

                final String value = ((RichTextElementDTO) object).getText();
                if (value == null || "".equals(value)) {
                    html.setText(I18N.CONSTANTS.reportEmptySection());
                    html.addStyleName("project-report-field-empty");

                } else {
                    html.setHTML(value);
                    html.addStyleName("project-report-field");
                }

                sectionPanel.add(html);
            }

        } else if (object.getClass() == KeyQuestionDTO.class) {
            final KeyQuestionDTO keyQuestion = (KeyQuestionDTO) object;
            keyQuestionState.increaseCount();

            keyQuestion.setNumber(keyQuestionState.getCount());

            // Rich text field
            final RichTextArea textArea = new RichTextArea();
            final RichTextElementDTO richTextElementDTO = keyQuestion.getRichTextElementDTO();
            if (richTextElementDTO != null) {
                textArea.setHTML(richTextElementDTO.getText());
                textAreas.put(richTextElementDTO.getId(), textArea);
                oldContents.put(richTextElementDTO.getId(), textArea.getText());

            } else {
                Log.error("No text area is attached to the key question #" + keyQuestion.getId());
            }

            // Compas icon
            final ToolbarImages images = GWT.create(ToolbarImages.class);

            final ImageResource icon;
            if ("".equals(textArea.getText()))
                icon = images.compasRed();
            else {
                icon = images.compasGreen();
                keyQuestionState.increaseValids();
            }

            final int toolButtonIndex = sectionPanel.getToolButtonCount();

            sectionPanel.addToolButton(icon, new ClickHandler() {

                @Override
                public void onClick(ClickEvent event) {
                    KeyQuestionDialog.getDialog(keyQuestion, textArea, sectionPanel, toolButtonIndex,
                            keyQuestionState, draftMode).show();
                }
            });

        } else {
            Log.warn("Report : object type unknown (" + object.getClass() + ")");
        }
    }

    parent.add(sectionPanel);
}

From source file:org.sigmah.client.page.orgunit.reports.OrgUnitReportsView.java

License:Open Source License

public boolean isTextAreaChanged() {
    boolean changed = false;
    if (textAreas != null) {
        for (Map.Entry<Integer, String> entry : oldContents.entrySet()) {
            RichTextArea textArea = textAreas.get(entry.getKey());
            if (!textArea.getText().equals(entry.getValue()))
                changed = true;//ww  w.jav  a  2 s.  com
        }
    }
    return changed;
}

From source file:org.sigmah.client.page.orgunit.reports.OrgUnitReportsView.java

License:Open Source License

public void updateChanges() {
    if (textAreas != null) {
        for (Map.Entry<Integer, String> entry : oldContents.entrySet()) {
            RichTextArea textArea = textAreas.get(entry.getKey());
            oldContents.put(entry.getKey(), textArea.getText());
        }/*from  w w  w  .j  a v a  2 s .c om*/
    }
}

From source file:org.sigmah.client.ui.view.reports.KeyQuestionDialog.java

License:Open Source License

public static Dialog getDialog(final KeyQuestionDTO keyQuestion, final RichTextArea textArea,
        final FoldPanel panel, final int toolButtonIndex, final KeyQuestionState keyQuestionState,
        boolean enabled) {
    final Dialog dialog = getDialog();
    dialog.setHeadingHtml(/*from  w w  w  .  j a  v a2s  .  c  o m*/
            I18N.MESSAGES.reportKeyQuestionDialogTitle(Integer.toString(keyQuestion.getNumber())));

    // Question label
    final Label question = (Label) dialog.getWidget(0);
    question.setTitle(keyQuestion.getLabel());

    // Rich text editor
    final RichTextArea dialogTextArea = (RichTextArea) dialog.getWidget(1);
    dialogTextArea.setHTML(textArea.getHTML());

    final boolean wasValid = !"".equals(textArea.getText());

    // OK Button
    final Button okButton = dialog.getButtonById(Dialog.OK);

    okButton.removeAllListeners();

    if (enabled) {

        dialog.getTopComponent().enable();
        dialogTextArea.setEnabled(true);

        okButton.setVisible(true);
        okButton.addSelectionListener(new SelectionListener<ButtonEvent>() {

            @Override
            public void componentSelected(ButtonEvent ce) {
                dialog.hide();
                textArea.setHTML(dialogTextArea.getHTML());

                final boolean isValid = !"".equals(dialogTextArea.getText());

                final ToolbarImages images = GWT.create(ToolbarImages.class);
                if (isValid) {
                    panel.setToolButtonImage(toolButtonIndex, images.compasGreen());

                    if (!wasValid)
                        keyQuestionState.increaseValids();

                } else {
                    panel.setToolButtonImage(toolButtonIndex, images.compasRed());

                    if (wasValid)
                        keyQuestionState.decreaseValids();
                }
            }
        });

    } else {

        okButton.setVisible(false);

        dialog.getTopComponent().disable();
        dialogTextArea.setEnabled(false);
    }

    return dialog;
}

From source file:org.sigmah.client.ui.view.reports.ReportsView.java

License:Open Source License

/**
 * {@inheritDoc}//from  ww  w.ja  va2 s.  c o  m
 */
@Override
public HasHTML addKeyQuestion(final KeyQuestionDTO keyQuestion, final FoldPanel sectionPanel,
        final boolean draftMode) {

    keyQuestionState.increaseCount();

    keyQuestion.setNumber(keyQuestionState.getCount());

    // Rich text field.
    final RichTextArea textArea = new RichTextArea();
    final RichTextElementDTO richTextElementDTO = keyQuestion.getRichTextElementDTO();

    if (richTextElementDTO != null) {
        textArea.setHTML(richTextElementDTO.getText());
    }

    // Compas icon.
    final ImageResource icon;
    if (ClientUtils.isBlank(textArea.getText())) {
        icon = ToolbarImages.IMAGES.compasRed();

    } else {
        icon = ToolbarImages.IMAGES.compasGreen();
        keyQuestionState.increaseValids();
    }

    sectionPanel.addToolButton(icon, new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            KeyQuestionDialog.getDialog(keyQuestion, textArea, sectionPanel, sectionPanel.getToolButtonCount(),
                    keyQuestionState, draftMode).show();
        }
    });

    return textArea;
}