List of usage examples for com.google.gwt.user.client.ui RichTextArea addFocusHandler
public HandlerRegistration addFocusHandler(FocusHandler handler)
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 w w .j a v a2s . 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.ui.view.reports.ReportsView.java
License:Open Source License
/** * {@inheritDoc}/* ww w . j av a2 s . c om*/ */ @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; } }