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.

RichTextExample.java 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. @ITMillApache2LicenseForJavaFiles@
  3. */
  4. package com.vaadin.automatedtests.featurebrowser;
  5. import com.vaadin.ui.Alignment;
  6. import com.vaadin.ui.Button;
  7. import com.vaadin.ui.CustomComponent;
  8. import com.vaadin.ui.Label;
  9. import com.vaadin.ui.RichTextArea;
  10. import com.vaadin.ui.VerticalLayout;
  11. import com.vaadin.ui.Button.ClickEvent;
  12. /**
  13. * An example using a RichTextArea to edit a Label in XHTML-mode.
  14. *
  15. */
  16. public class RichTextExample extends CustomComponent {
  17. public static final String txt = "<h1>RichText editor example</h1>"
  18. + "To edit this text, press the <b>Edit</b> button below."
  19. + "<br/>"
  20. + "See the <A href=\"http://www.itmill.com/documentation/itmill-toolkit-5-reference-manual/\">manual</a> "
  21. + "for more information.";
  22. private final VerticalLayout main;
  23. private final Label l;
  24. private final RichTextArea editor = new RichTextArea();
  25. private final Button b;
  26. public RichTextExample() {
  27. // main layout
  28. main = new VerticalLayout();
  29. main.setMargin(true);
  30. setCompositionRoot(main);
  31. editor.setWidth("100%");
  32. // Add the label
  33. l = new Label(txt);
  34. l.setContentMode(Label.CONTENT_XHTML);
  35. main.addComponent(l);
  36. // Edit button with inline click-listener
  37. b = new Button("Edit", new Button.ClickListener() {
  38. public void buttonClick(ClickEvent event) {
  39. // swap Label <-> RichTextArea
  40. if (main.getComponentIterator().next() == l) {
  41. editor.setValue(l.getValue());
  42. main.replaceComponent(l, editor);
  43. b.setCaption("Save");
  44. } else {
  45. l.setValue(editor.getValue());
  46. main.replaceComponent(editor, l);
  47. b.setCaption("Edit");
  48. }
  49. }
  50. });
  51. main.addComponent(b);
  52. main.setComponentAlignment(b, Alignment.MIDDLE_RIGHT);
  53. }
  54. }