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

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

Introduction

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

Prototype

public void setHTML(SafeHtml html) 

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();//w ww .j a  v a 2 s  .  c om
    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:com.qualogy.qafe.gwt.client.vo.functions.execute.SetValueExecute.java

License:Apache License

public static void processValue(UIObject uiObject, Object valueToSet, SetValueGVO setValue,
        DataContainerGVO valueDTC) {//from  w ww.j  a  v a 2 s. co m
    if (uiObject != null) {
        if (uiObject instanceof HasText) {
            if (uiObject instanceof QRadioButton) {
                QRadioButton qRadioButton = (QRadioButton) uiObject;
                qRadioButton.reset();
                if (valueToSet != null) {
                    qRadioButton.setValue(valueToSet.toString());
                }

            } else if (uiObject instanceof CheckBox) {
                CheckBox checkBox = (CheckBox) uiObject;
                String checkedValue = DOM.getElementAttribute(checkBox.getElement(),
                        CheckBoxGVO.CHECKED_VALUE_ATTRIBUTE_TAG);
                String unCheckedValue = DOM.getElementAttribute(checkBox.getElement(),
                        CheckBoxGVO.UNCHECKED_VALUE_ATTRIBUTE_TAG);
                String checkedValueDomain = DOM.getElementAttribute(checkBox.getElement(),
                        CheckBoxGVO.CHECKED_VALUE_DOMAIN_ATTRIBUTE_TAG);
                String unCheckedValueDomain = DOM.getElementAttribute(checkBox.getElement(),
                        CheckBoxGVO.UNCHECKED_VALUE_DOMAIN_ATTRIBUTE_TAG);

                if (valueToSet != null) {
                    if (checkedValue != null && checkedValue.equals(valueToSet)) {
                        checkBox.setChecked(true);
                    } else if (unCheckedValue != null && unCheckedValue.equals(valueToSet)) {
                        checkBox.setChecked(false);
                    } else if (isInDomain(valueToSet.toString(), checkedValueDomain)) {
                        checkBox.setChecked(true);
                    } else if (isInDomain(valueToSet.toString(), unCheckedValueDomain)) {
                        checkBox.setChecked(false);
                    }
                } else {
                    checkBox.setChecked(false);
                }
            } else if (uiObject instanceof HTML) {
                HTML html = (HTML) uiObject;
                if (valueToSet != null) {
                    html.setHTML(valueToSet.toString());
                } else {
                    html.setHTML("");
                }
            } else if (uiObject instanceof PushButton) {
                ((PushButton) uiObject).getUpFace().setText(valueToSet.toString());
                ((PushButton) uiObject).getDownFace().setText(valueToSet.toString());
            } else if (uiObject instanceof RichTextArea) {
                RichTextArea richTextArea = (RichTextArea) uiObject;
                richTextArea.setHTML(valueToSet.toString());
            } else {
                HasText hasText = (HasText) uiObject;
                if (valueDTC != null) {
                    if (valueDTC.getKind() == DataContainerGVO.KIND_STRING) {
                        if (valueDTC.getStringDataType() == DataContainerGVO.TYPE_DATE) {
                            if (uiObject instanceof QDatePicker) {
                                ((QDatePicker) uiObject).setValue(valueDTC.getDateData());
                            }
                        } else {
                            hasText.setText(valueToSet.toString());
                            uiObject.setStyleName(uiObject.getStyleName().replaceAll("qafe_invalid_field",
                                    "qafe_valid_field"));
                        }
                    } else {
                        hasText.setText(valueToSet.toString());
                    }
                } else if (valueToSet != null) {
                    hasText.setText(valueToSet.toString());
                } else {
                    hasText.setText("");
                }
            }
        } else if (uiObject instanceof Frame) {
            Frame frame = (Frame) uiObject;
            if (valueToSet != null) {
                frame.setUrl(valueToSet.toString());
            } else {
                frame.setUrl("");
            }
        }

        if (uiObject instanceof ListBox) {
            ListBox listBox = (ListBox) uiObject;
            // If it is needed to populate data and select a data from dropdown it should be seperate calls.
            if (valueDTC != null && valueDTC.getListofDC() != null) {
                processListBox(setValue, uiObject, valueDTC);
            } else {
                processValue4ListBox(listBox, valueToSet, setValue.getAction());
            }

        }

        if (uiObject instanceof Image) {
            Image image = (Image) uiObject;
            if (valueToSet != null) {
                image.setUrl(valueToSet.toString());
            }

        }

        if (uiObject instanceof QDatePicker) {
            QDatePicker qDatePicker = (QDatePicker) uiObject;
            if (valueDTC != null) {
                qDatePicker.setValue(valueDTC.getDateData(), true);
            }
        }

        if (uiObject instanceof QSliderBar) {
            QSliderBar slider = (QSliderBar) uiObject;
            slider.setValue(valueToSet);
        }

        if (uiObject instanceof HasDataGridMethods) {
            HasDataGridMethods dataGrid = (HasDataGridMethods) uiObject;
            List<DataContainerGVO> listOfDataMap = new ArrayList<DataContainerGVO>();
            if (valueDTC.getKind() == DataContainerGVO.KIND_MAP) {
                listOfDataMap.add(new DataContainerGVO(valueDTC.getDataMap()));
                dataGrid.insertData(listOfDataMap, false, setValue.getSenderId(), setValue.getListenerType());
            } else if (valueDTC.getKind() == DataContainerGVO.KIND_COLLECTION) {
                listOfDataMap = valueDTC.getListofDC();
                dataGrid.insertData(listOfDataMap, false, setValue.getSenderId(), setValue.getListenerType());
            } else if (valueDTC.getKind() == DataContainerGVO.KIND_STRING) {
                String cellOnRowToSet = setValue.getComponentId();
                listOfDataMap.add(new DataContainerGVO(valueDTC.getDataString()));
                dataGrid.setDataToCell(new DataContainerGVO(valueDTC.getDataString()), false,
                        setValue.getSenderId(), cellOnRowToSet);
            }
            dataGrid.redraw();
        }
    }
}

From source file:com.qualogy.qafe.gwt.client.vo.handlers.SetValueHandler.java

License:Apache License

private void processValue(UIObject uiObject, Object value, SetValueGVO setValueGVO,
        DataContainerGVO dataContainerGVO) {
    if (uiObject != null) {
        if (uiObject instanceof HasText) {
            if (uiObject instanceof QRadioButton) {
                QRadioButton qRadioButton = (QRadioButton) uiObject;
                qRadioButton.reset();/*  ww  w. j  a v a 2  s.c om*/
                if (value != null) {
                    qRadioButton.setValue(value.toString());
                }

            } else if (uiObject instanceof CheckBox) {
                CheckBox checkBox = (CheckBox) uiObject;
                String checkedValue = DOM.getElementAttribute(checkBox.getElement(),
                        CheckBoxGVO.CHECKED_VALUE_ATTRIBUTE_TAG);
                String unCheckedValue = DOM.getElementAttribute(checkBox.getElement(),
                        CheckBoxGVO.UNCHECKED_VALUE_ATTRIBUTE_TAG);
                String checkedValueDomain = DOM.getElementAttribute(checkBox.getElement(),
                        CheckBoxGVO.CHECKED_VALUE_DOMAIN_ATTRIBUTE_TAG);
                String unCheckedValueDomain = DOM.getElementAttribute(checkBox.getElement(),
                        CheckBoxGVO.UNCHECKED_VALUE_DOMAIN_ATTRIBUTE_TAG);

                if (value != null) {
                    if (checkedValue != null && checkedValue.equals(value)) {
                        checkBox.setChecked(true);
                    } else if (unCheckedValue != null && unCheckedValue.equals(value)) {
                        checkBox.setChecked(false);
                    } else if (isInDomain(value.toString(), checkedValueDomain)) {
                        checkBox.setChecked(true);
                    } else if (isInDomain(value.toString(), unCheckedValueDomain)) {
                        checkBox.setChecked(false);
                    }
                } else {
                    checkBox.setChecked(false);
                }
            } else if (uiObject instanceof HTML) {
                HTML html = (HTML) uiObject;
                if (value != null) {
                    html.setHTML(value.toString());
                } else {
                    html.setHTML("");
                }
            } else if (uiObject instanceof PushButton) {
                ((PushButton) uiObject).getUpFace().setText(value.toString());
                ((PushButton) uiObject).getDownFace().setText(value.toString());
            } else if (uiObject instanceof RichTextArea) {
                RichTextArea richTextArea = (RichTextArea) uiObject;
                richTextArea.setHTML(value.toString());
            } else {
                HasText hasText = (HasText) uiObject;
                if (dataContainerGVO != null) {
                    if (dataContainerGVO.getKind() == DataContainerGVO.KIND_STRING) {
                        if (dataContainerGVO.getStringDataType() == DataContainerGVO.TYPE_DATE) {
                            if (uiObject instanceof QDatePicker) {
                                ((QDatePicker) uiObject).setValue(dataContainerGVO.getDateData());
                            }
                        } else {
                            hasText.setText(value.toString());
                            uiObject.setStyleName(uiObject.getStyleName().replaceAll("qafe_invalid_field",
                                    "qafe_valid_field"));
                        }
                    } else {
                        hasText.setText(value.toString());
                    }
                } else if (value != null) {
                    hasText.setText(value.toString());
                } else {
                    hasText.setText("");
                }
            }
        } else if (uiObject instanceof Frame) {
            Frame frame = (Frame) uiObject;
            if (value != null) {
                frame.setUrl(value.toString());
            } else {
                frame.setUrl("");
            }
        }

        if (uiObject instanceof ListBox) {
            ListBox listBox = (ListBox) uiObject;
            // If it is needed to populate data and select a data from dropdown it should be seperate calls.
            if (dataContainerGVO != null && dataContainerGVO.getListofDC() != null) {
                processListBox(uiObject, setValueGVO, dataContainerGVO);
            } else {
                processValue4ListBox(listBox, value, setValueGVO.getAction());
            }

        }

        if (uiObject instanceof Image) {
            Image image = (Image) uiObject;
            if (value != null) {
                image.setUrl(value.toString());
            }

        }

        if (uiObject instanceof QDatePicker) {
            QDatePicker qDatePicker = (QDatePicker) uiObject;
            if (dataContainerGVO != null) {
                qDatePicker.setValue(dataContainerGVO.getDateData(), true);
            }
        }

        if (uiObject instanceof QSliderBar) {
            QSliderBar slider = (QSliderBar) uiObject;
            slider.setValue(value);
        }

        if (uiObject instanceof HasDataGridMethods) {
            HasDataGridMethods dataGrid = (HasDataGridMethods) uiObject;
            List<DataContainerGVO> listOfDataMap = new ArrayList<DataContainerGVO>();
            if (dataContainerGVO.getKind() == DataContainerGVO.KIND_MAP) {
                listOfDataMap.add(new DataContainerGVO(dataContainerGVO.getDataMap()));
                dataGrid.insertData(listOfDataMap, false, setValueGVO.getSenderId(),
                        setValueGVO.getListenerType());
            } else if (dataContainerGVO.getKind() == DataContainerGVO.KIND_COLLECTION) {
                listOfDataMap = dataContainerGVO.getListofDC();
                dataGrid.insertData(listOfDataMap, false, setValueGVO.getSenderId(),
                        setValueGVO.getListenerType());
            } else if (dataContainerGVO.getKind() == DataContainerGVO.KIND_STRING) {
                String cellOnRowToSet = setValueGVO.getComponentId();
                listOfDataMap.add(new DataContainerGVO(dataContainerGVO.getDataString()));
                dataGrid.setDataToCell(new DataContainerGVO(dataContainerGVO.getDataString()), false,
                        setValueGVO.getSenderId(), cellOnRowToSet);
            }
            dataGrid.redraw();
        }
    }
}

From source file:gwtquery.plugins.enhance.client.gwt.RichTextWidgetFactory.java

License:Apache License

private RichTextArea create(String v) {
    RichTextArea b = new RichTextArea();
    b.setHTML(v);
    return b;
}

From source file:org.kuali.continuity.admin.main.client.FlexibleForm.java

License:Educational Community License

public void clear(RichTextArea c) {

    c.setHTML("");
    c.setText("");
}

From source file:org.pentaho.pat.client.ui.panels.windows.ConnectMondrianPanel.java

License:Open Source License

/**
 * Run on panel initialize.//from   w ww. ja  v  a2 s .c o m
 */
private void init() {

    final FormPanel formPanel = new FormPanel();
    formPanel.setAction(FORM_ACTION);
    formPanel.setMethod(FORM_METHOD);
    formPanel.setEncoding(FORM_ENCODING);
    formPanel.addSubmitCompleteHandler(new SubmitCompleteHandler() {

        public void onSubmitComplete(final SubmitCompleteEvent arg0) {
            if (arg0 != null && arg0.getResults() != null && arg0.getResults().length() > 0) {
                if (arg0.getResults().contains(VALIDATION_START)) {
                    final String tmp = arg0.getResults().substring(
                            arg0.getResults().indexOf(VALIDATION_START) + VALIDATION_START.length(),
                            arg0.getResults().indexOf(VALIDATION_END));
                    if (tmp != null && tmp.length() > 0) {
                        if (schemaValCheckbox.getValue()) {
                            MessageBox.info(Pat.CONSTANTS.warning(),
                                    MessageFactory.getInstance().schemaFileInvalid() + "<br>" + tmp); //$NON-NLS-1$
                        }
                    }
                }
                if (arg0.getResults().contains(SCHEMA_START)) {
                    final String tmp = arg0.getResults().substring(
                            arg0.getResults().indexOf(SCHEMA_START) + SCHEMA_START.length(),
                            arg0.getResults().indexOf(SCHEMA_END));
                    schemaData = decode(tmp);
                    saveButton.setEnabled(true);
                    viewSchemaButton.setEnabled(true);
                    viewSchemaButton.setText(Pat.CONSTANTS.viewSchema());
                    // TODO remove this later

                    Application.INSTANCE.showInfoPanel(Pat.CONSTANTS.fileUpload(), Pat.CONSTANTS.success());
                } else {
                    MessageBox.error(Pat.CONSTANTS.error(), Pat.CONSTANTS.fileUploadFailed());
                }
            } else {
                MessageBox.error(Pat.CONSTANTS.error(), Pat.CONSTANTS.checkErrorLog());
            }
        }
    });
    final FormLayout layout = new FormLayout("right:[40dlu,pref], 3dlu, 70dlu, 7dlu, " //$NON-NLS-1$
            + "right:[40dlu,pref], 3dlu, 70dlu", //$NON-NLS-1$
            "p, 3dlu, p, 3dlu,p, 3dlu,p, 3dlu,p, 3dlu,p, 3dlu,p, 3dlu,p, 3dlu,p, 3dlu,p"); //$NON-NLS-1$
    final PanelBuilder builder = new PanelBuilder(layout);
    builder.addLabel(Pat.CONSTANTS.name() + LABEL_SUFFIX, CellConstraints.xy(1, 1));
    builder.add(nameTextBox, CellConstraints.xyw(3, 1, 5));
    builder.addLabel(Pat.CONSTANTS.jdbcDriver() + LABEL_SUFFIX, CellConstraints.xy(1, 3));
    builder.add(driverListBox, CellConstraints.xyw(3, 3, 5));
    builder.addLabel(Pat.CONSTANTS.jdbcUrl() + LABEL_SUFFIX, CellConstraints.xy(1, 5));
    builder.add(urlTextBox, CellConstraints.xyw(3, 5, 5));
    builder.addLabel(Pat.CONSTANTS.username() + LABEL_SUFFIX, CellConstraints.xy(1, 7));
    builder.add(userTextBox, CellConstraints.xy(3, 7));
    builder.addLabel(Pat.CONSTANTS.password() + LABEL_SUFFIX, CellConstraints.xy(5, 7));
    builder.add(passwordTextBox, CellConstraints.xy(7, 7));
    builder.addLabel(Pat.CONSTANTS.schemaFile() + LABEL_SUFFIX, CellConstraints.xy(1, 9));
    fileUpload.setName(FORM_NAME_FILE);
    builder.add(fileUpload, CellConstraints.xyw(3, 9, 5));
    builder.add(schemaValCheckbox, CellConstraints.xyw(3, 11, 5));
    uploadButton.addClickHandler(new ClickHandler() {
        public void onClick(final ClickEvent event) {
            final String filename = fileUpload.getFilename();
            if (filename == null || filename.length() == 0) {
                MessageBox.error(Pat.CONSTANTS.error(), Pat.CONSTANTS.fileUploadNoFile());
            } else {
                formPanel.submit();
            }
        }
    });

    builder.add(uploadButton, CellConstraints.xy(3, 13));

    viewSchemaButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent arg0) {

            final WindowPanel winPanel = new WindowPanel(Pat.CONSTANTS.schemaFile());
            final LayoutPanel wpLayoutPanel = new LayoutPanel(new BoxLayout(Orientation.VERTICAL));
            wpLayoutPanel.setSize("450px", "200px"); //$NON-NLS-1$ //$NON-NLS-2$
            final RichTextArea schemaArea = new RichTextArea();
            String newStr = schemaData + "";
            newStr = newStr.replaceAll("\\<", "&lt;").replaceAll("\\>", "&gt;").replaceAll(" ", "&nbsp;");
            newStr = newStr.replaceAll("\t", "&nbsp;&nbsp;&nbsp;");
            newStr = newStr.replaceAll("(\r\n)", "<br>"); //$NON-NLS-1$ //$NON-NLS-2$
            //                newStr = newStr.replaceAll("[\r\n\t\f]", "<br>"); //$NON-NLS-1$ //$NON-NLS-2$
            schemaArea.setHTML(newStr + "");

            wpLayoutPanel.add(schemaArea, new BoxLayoutData(1, 0.9));
            final ToolButton saveBtn = new ToolButton(Pat.CONSTANTS.save());
            saveBtn.addClickHandler(new ClickHandler() {
                public void onClick(final ClickEvent arg0) {
                    String newStr = schemaArea.getHTML();
                    newStr = newStr.replaceAll("&lt;", "\\<").replaceAll("&gt;", "\\>").replaceAll("&nbsp;",
                            " ");
                    newStr = newStr.replaceAll("&nbsp;&nbsp;&nbsp;", "\t");
                    newStr = newStr.replaceAll("<br>", "\r\n"); //$NON-NLS-1$ //$NON-NLS-2$
                    schemaData = newStr;
                    winPanel.hide();
                    ConnectionManagerWindow.display(false);
                }

            });

            final ToolButton closeBtn = new ToolButton(Pat.CONSTANTS.close());
            closeBtn.addClickHandler(new ClickHandler() {
                public void onClick(final ClickEvent arg0) {
                    winPanel.hide();
                    ConnectionManagerWindow.display(false);
                }

            });
            final LayoutPanel wpButtonPanel = new LayoutPanel(new BoxLayout(Orientation.HORIZONTAL));

            wpButtonPanel.add(saveBtn);
            wpButtonPanel.add(closeBtn);
            wpLayoutPanel.add(wpButtonPanel);
            wpLayoutPanel.layout();
            winPanel.add(wpLayoutPanel);
            winPanel.layout();
            winPanel.pack();
            winPanel.setSize("700px", "520px"); //$NON-NLS-1$ //$NON-NLS-2$

            ConnectionManagerWindow.close();
            winPanel.center();

        }
    });
    viewSchemaButton.setEnabled(false);
    viewSchemaButton.setText(Pat.CONSTANTS.noSchema());
    builder.add(viewSchemaButton, CellConstraints.xy(7, 13));

    builder.addLabel(Pat.CONSTANTS.role() + LABEL_SUFFIX, CellConstraints.xy(1, 15));
    builder.add(roleTextBox, CellConstraints.xyw(3, 15, 5));

    builder.add(startupCheckbox, CellConstraints.xy(3, 17));

    saveButton.addClickHandler(new ClickHandler() {
        public void onClick(final ClickEvent event) {
            final CubeConnection cc = getCubeConnection();
            if (validateConnection(cc)) {

                saveButton.setEnabled(false);
                ServiceFactory.getSessionInstance().saveConnection(Pat.getSessionID(), cc,
                        new AsyncCallback<String>() {
                            public void onFailure(final Throwable arg0) {
                                MessageBox.error(Pat.CONSTANTS.error(), MessageFactory.getInstance()
                                        .failedLoadConnection(arg0.getLocalizedMessage()));
                                saveButton.setEnabled(true);
                            }

                            public void onSuccess(final String id) {
                                if (cc.isConnectOnStartup()) {
                                    ConnectionManagerPanel.connectEvent(id, cc.isConnected(), true);
                                }
                                ConnectionManagerWindow.closeTabs();
                            }
                        });

            }
        }
    });

    saveButton.setEnabled(false);

    builder.add(saveButton, CellConstraints.xy(3, 19));

    cancelButton.addClickHandler(new ClickHandler() {
        public void onClick(final ClickEvent event) {
            ConnectionManagerWindow.closeTabs();
        }
    });
    builder.add(cancelButton, CellConstraints.xy(7, 19));
    final LayoutPanel layoutPanel = builder.getPanel();
    layoutPanel.setPadding(15);
    formPanel.add(layoutPanel);
    this.getLayoutPanel().add(formPanel);
}

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  va 2 s  .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++;//from w  ww  .  ja  v a  2  s.co 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.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 www.ja v  a  2 s  .  co  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 w  w w . java 2  s .  c  o  m
 */
@Override
public HasHTML addTextArea(final RichTextElementDTO richTextElement, final FoldPanel sectionPanel,
        final boolean draftMode) {

    if (draftMode) {

        final RichTextArea textArea = new RichTextArea();

        textArea.setHTML(richTextElement.getText());
        textArea.addFocusHandler(new FocusHandler() {

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

        sectionPanel.add(textArea);
        return textArea;

    } else {

        final HTML html = new HTML();
        final String value = richTextElement.getText();

        if (ClientUtils.isBlank(value)) {
            html.setText(I18N.CONSTANTS.reportEmptySection());
            html.addStyleName(STYLE_PROJECT_REPORT_FIELD_EMPTY);

        } else {
            html.setHTML(value);
            html.addStyleName(STYLE_PROJECT_REPORT_FIELD);
        }

        sectionPanel.add(html);
        return null;
    }
}