diff options
author | Marc Englund <marc.englund@itmill.com> | 2008-01-18 08:57:52 +0000 |
---|---|---|
committer | Marc Englund <marc.englund@itmill.com> | 2008-01-18 08:57:52 +0000 |
commit | 41706606b271c9f4c9bd27c4a6ef172d808f25c3 (patch) | |
tree | 0cde83ed3e16b72f3f9637e419f6a8ef3755c4be /src/com/itmill/toolkit/demo/featurebrowser/JavaScriptAPIExample.java | |
parent | 291a1690a707185f8bfe3f6dbc7895a05c87dd0d (diff) | |
download | vaadin-framework-41706606b271c9f4c9bd27c4a6ef172d808f25c3.tar.gz vaadin-framework-41706606b271c9f4c9bd27c4a6ef172d808f25c3.zip |
ApplicationConnection publishes javascript function itmill.forceSync().
FeatureBrowser contains example.
svn changeset:3577/svn branch:trunk
Diffstat (limited to 'src/com/itmill/toolkit/demo/featurebrowser/JavaScriptAPIExample.java')
-rw-r--r-- | src/com/itmill/toolkit/demo/featurebrowser/JavaScriptAPIExample.java | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/src/com/itmill/toolkit/demo/featurebrowser/JavaScriptAPIExample.java b/src/com/itmill/toolkit/demo/featurebrowser/JavaScriptAPIExample.java new file mode 100644 index 0000000000..032d9aaf4c --- /dev/null +++ b/src/com/itmill/toolkit/demo/featurebrowser/JavaScriptAPIExample.java @@ -0,0 +1,94 @@ +/*
+@ITMillApache2LicenseForJavaFiles@
+ */
+
+package com.itmill.toolkit.demo.featurebrowser;
+
+import java.util.Date;
+
+import com.itmill.toolkit.terminal.PaintException;
+import com.itmill.toolkit.terminal.PaintTarget;
+import com.itmill.toolkit.ui.Button;
+import com.itmill.toolkit.ui.CustomComponent;
+import com.itmill.toolkit.ui.Label;
+import com.itmill.toolkit.ui.OrderedLayout;
+import com.itmill.toolkit.ui.RichTextArea;
+import com.itmill.toolkit.ui.Button.ClickEvent;
+
+/**
+ * An example using a RichTextArea to edit a Label in XHTML-mode.
+ *
+ */
+public class JavaScriptAPIExample extends CustomComponent {
+
+ public static final String txt = "<A href=\"javascript:itmill.forceSync();\">javascript:itmill.forceSync();</A>";
+
+ private final OrderedLayout main;
+ private final Label l;
+ private final RichTextArea editor = new RichTextArea();
+
+ public JavaScriptAPIExample() {
+ // main layout
+ main = new OrderedLayout();
+ main.setMargin(true);
+ setCompositionRoot(main);
+ // Add the label
+ l = new Label(txt);
+ l.setContentMode(Label.CONTENT_XHTML);
+ main.addComponent(l);
+ // Edit button with inline click-listener
+ Button 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);
+ event.getButton().setCaption("Save");
+ } else {
+ l.setValue(editor.getValue());
+ main.replaceComponent(editor, l);
+ event.getButton().setCaption("Edit");
+ }
+ }
+ });
+ main.addComponent(b);
+ main.setComponentAlignment(b, OrderedLayout.ALIGNMENT_RIGHT,
+ OrderedLayout.ALIGNMENT_VERTICAL_CENTER);
+
+ //
+ Label l = new Label(
+ "This label will update it's value AFTER it's rendered to the client. "
+ + "The client will be synchronized on reload, when you click a button, "
+ + "or when itmill.forceSync() is called.") {
+
+ public void paintContent(PaintTarget target) throws PaintException {
+
+ super.paintContent(target);
+ Delay d = new Delay(this);
+ d.start();
+ }
+
+ };
+ main.addComponent(l);
+
+ }
+
+ private class Delay extends Thread {
+ Label label;
+
+ public Delay(Label l) {
+ label = l;
+ }
+
+ public void run() {
+ try {
+ Thread.sleep(500);
+ label.setValue(new Date().toString());
+ join();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ }
+}
|