You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

IRichTextArea.java 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. @ITMillApache2LicenseForJavaFiles@
  3. */
  4. package com.itmill.toolkit.terminal.gwt.client.ui.richtextarea;
  5. import com.google.gwt.user.client.ui.ChangeListener;
  6. import com.google.gwt.user.client.ui.Composite;
  7. import com.google.gwt.user.client.ui.FlowPanel;
  8. import com.google.gwt.user.client.ui.FocusListener;
  9. import com.google.gwt.user.client.ui.HTML;
  10. import com.google.gwt.user.client.ui.RichTextArea;
  11. import com.google.gwt.user.client.ui.Widget;
  12. import com.itmill.toolkit.terminal.gwt.client.ApplicationConnection;
  13. import com.itmill.toolkit.terminal.gwt.client.Paintable;
  14. import com.itmill.toolkit.terminal.gwt.client.UIDL;
  15. import com.itmill.toolkit.terminal.gwt.client.ui.Field;
  16. /**
  17. * This class represents a basic text input field with one row.
  18. *
  19. * @author IT Mill Ltd.
  20. *
  21. */
  22. public class IRichTextArea extends Composite implements Paintable, Field,
  23. ChangeListener, FocusListener {
  24. /**
  25. * The input node CSS classname.
  26. */
  27. public static final String CLASSNAME = "i-richtextarea";
  28. protected String id;
  29. protected ApplicationConnection client;
  30. private boolean immediate = false;
  31. private RichTextArea rta = new RichTextArea();
  32. private IRichTextToolbar formatter = new IRichTextToolbar(rta);
  33. private HTML html = new HTML();
  34. private final FlowPanel fp = new FlowPanel();
  35. private boolean enabled = true;
  36. public IRichTextArea() {
  37. fp.add(formatter);
  38. rta.setWidth("100%");
  39. rta.addFocusListener(this);
  40. fp.add(rta);
  41. initWidget(fp);
  42. setStyleName(CLASSNAME);
  43. }
  44. public void setEnabled(boolean enabled) {
  45. if (this.enabled != enabled) {
  46. rta.setEnabled(enabled);
  47. if (enabled) {
  48. fp.remove(html);
  49. fp.add(rta);
  50. } else {
  51. html.setHTML(rta.getHTML());
  52. fp.remove(rta);
  53. fp.add(html);
  54. }
  55. this.enabled = enabled;
  56. }
  57. }
  58. public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
  59. this.client = client;
  60. id = uidl.getId();
  61. if (uidl.hasVariable("text")) {
  62. rta.setHTML(uidl.getStringVariable("text"));
  63. }
  64. setEnabled(!uidl.getBooleanAttribute("disabled"));
  65. if (client.updateComponent(this, uidl, true)) {
  66. return;
  67. }
  68. immediate = uidl.getBooleanAttribute("immediate");
  69. }
  70. public void onChange(Widget sender) {
  71. if (client != null && id != null) {
  72. client.updateVariable(id, "text", rta.getText(), immediate);
  73. }
  74. }
  75. public void onFocus(Widget sender) {
  76. }
  77. public void onLostFocus(Widget sender) {
  78. final String html = rta.getHTML();
  79. client.updateVariable(id, "text", html, immediate);
  80. }
  81. }