/*
@ITMillApache2LicenseForJavaFiles@
*/
package com.itmill.toolkit.automatedtests.featurebrowser;
import com.itmill.toolkit.ui.Button;
import com.itmill.toolkit.ui.CustomComponent;
import com.itmill.toolkit.ui.Label;
import com.itmill.toolkit.ui.RichTextArea;
import com.itmill.toolkit.ui.VerticalLayout;
import com.itmill.toolkit.ui.Button.ClickEvent;
/**
* An example using a RichTextArea to edit a Label in XHTML-mode.
*
*/
public class RichTextExample extends CustomComponent {
public static final String txt = "
RichText editor example
"
+ "To edit this text, press the Edit button below."
+ "
"
+ "See the manual "
+ "for more information.";
private final VerticalLayout main;
private final Label l;
private final RichTextArea editor = new RichTextArea();
private final Button b;
public RichTextExample() {
// main layout
main = new VerticalLayout();
main.setMargin(true);
setCompositionRoot(main);
editor.setWidth("100%");
// Add the label
l = new Label(txt);
l.setContentMode(Label.CONTENT_XHTML);
main.addComponent(l);
// Edit button with inline click-listener
b = new Button("Edit", new Button.ClickListener() {
public void buttonClick(ClickEvent event) {
// swap Label <-> RichTextArea
if (main.getComponentIterator().next() == l) {
editor.setValue(l.getValue());
main.replaceComponent(l, editor);
b.setCaption("Save");
} else {
l.setValue(editor.getValue());
main.replaceComponent(editor, l);
b.setCaption("Edit");
}
}
});
main.addComponent(b);
main.setComponentAlignment(b, VerticalLayout.ALIGNMENT_RIGHT,
VerticalLayout.ALIGNMENT_VERTICAL_CENTER);
}
}