summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMatti Tahvonen <matti.tahvonen@itmill.com>2010-07-21 19:35:03 +0000
committerMatti Tahvonen <matti.tahvonen@itmill.com>2010-07-21 19:35:03 +0000
commitf7ebba2cc68e6301c397c9b34b13096bd7ccb3e9 (patch)
tree461c2dd0bb8fb5338fcbbec34c59ae8fc7962bef /src
parent768d95b50e7e9e7e0363ed863833f537b1f9abeb (diff)
downloadvaadin-framework-f7ebba2cc68e6301c397c9b34b13096bd7ccb3e9.tar.gz
vaadin-framework-f7ebba2cc68e6301c397c9b34b13096bd7ccb3e9.zip
fixes #5089 (read only mode) and #5379 webkit bug
svn changeset:14294/svn branch:6.4
Diffstat (limited to 'src')
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/richtextarea/VRichTextArea.java86
-rw-r--r--src/com/vaadin/ui/RichTextArea.java11
2 files changed, 78 insertions, 19 deletions
diff --git a/src/com/vaadin/terminal/gwt/client/ui/richtextarea/VRichTextArea.java b/src/com/vaadin/terminal/gwt/client/ui/richtextarea/VRichTextArea.java
index b82f96e456..8752d2a78f 100644
--- a/src/com/vaadin/terminal/gwt/client/ui/richtextarea/VRichTextArea.java
+++ b/src/com/vaadin/terminal/gwt/client/ui/richtextarea/VRichTextArea.java
@@ -24,6 +24,7 @@ import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.RichTextArea;
import com.google.gwt.user.client.ui.Widget;
import com.vaadin.terminal.gwt.client.ApplicationConnection;
+import com.vaadin.terminal.gwt.client.BrowserInfo;
import com.vaadin.terminal.gwt.client.Paintable;
import com.vaadin.terminal.gwt.client.UIDL;
import com.vaadin.terminal.gwt.client.Util;
@@ -53,9 +54,9 @@ public class VRichTextArea extends Composite implements Paintable, Field,
private boolean immediate = false;
- private RichTextArea rta = new RichTextArea();
+ private RichTextArea rta;
- private VRichTextToolbar formatter = new VRichTextToolbar(rta);
+ private VRichTextToolbar formatter;
private HTML html = new HTML();
@@ -76,13 +77,11 @@ public class VRichTextArea extends Composite implements Paintable, Field,
private String currentValue = "";
+ private boolean readOnly = false;
+
public VRichTextArea() {
+ createRTAComponents();
fp.add(formatter);
-
- rta.setWidth("100%");
- rta.addBlurHandler(this);
- rta.addKeyDownHandler(this);
-
fp.add(rta);
initWidget(fp);
@@ -90,36 +89,63 @@ public class VRichTextArea extends Composite implements Paintable, Field,
}
+ private void createRTAComponents() {
+ rta = new RichTextArea();
+ rta.setWidth("100%");
+ rta.addBlurHandler(this);
+ rta.addKeyDownHandler(this);
+ formatter = new VRichTextToolbar(rta);
+ }
+
public void setEnabled(boolean enabled) {
if (this.enabled != enabled) {
- rta.setEnabled(enabled);
- if (enabled) {
- fp.remove(html);
- fp.add(rta);
- } else {
- html.setHTML(rta.getHTML());
- fp.remove(rta);
- fp.add(html);
- }
+ // rta.setEnabled(enabled);
+ swapEditableArea();
this.enabled = enabled;
}
}
+ /**
+ * Swaps html to rta and visa versa.
+ */
+ private void swapEditableArea() {
+ if (html.isAttached()) {
+ fp.remove(html);
+ if (BrowserInfo.get().isWebkit()) {
+ fp.remove(formatter);
+ createRTAComponents(); // recreate new RTA to bypass #5379
+ fp.add(formatter);
+ }
+ rta.setHTML(currentValue);
+ fp.add(rta);
+ } else {
+ html.setHTML(currentValue);
+ fp.remove(rta);
+ fp.add(html);
+ }
+ }
+
public void updateFromUIDL(final UIDL uidl, ApplicationConnection client) {
this.client = client;
id = uidl.getId();
if (uidl.hasVariable("text")) {
currentValue = uidl.getStringVariable("text");
- rta.setHTML(currentValue);
-
+ if (rta.isAttached()) {
+ rta.setHTML(currentValue);
+ } else {
+ html.setHTML(currentValue);
+ }
+ }
+ if (!uidl.hasAttribute("cached")) {
+ setEnabled(!uidl.getBooleanAttribute("disabled"));
}
- setEnabled(!uidl.getBooleanAttribute("disabled"));
if (client.updateComponent(this, uidl, true)) {
return;
}
+ setReadOnly(uidl.getBooleanAttribute("readonly"));
immediate = uidl.getBooleanAttribute("immediate");
int newMaxLength = uidl.hasAttribute("maxLength") ? uidl
.getIntAttribute("maxLength") : -1;
@@ -135,6 +161,22 @@ public class VRichTextArea extends Composite implements Paintable, Field,
}
}
+ private void setReadOnly(boolean b) {
+ if (isReadOnly() != b) {
+ swapEditableArea();
+ readOnly = b;
+ if (readOnly) {
+ formatter.setVisible(false);
+ } else {
+ formatter.setVisible(true);
+ }
+ }
+ }
+
+ private boolean isReadOnly() {
+ return readOnly;
+ }
+
// TODO is this really used, or does everything go via onBlur() only?
public void onChange(ChangeEvent event) {
synchronizeContentToServer();
@@ -149,7 +191,13 @@ public class VRichTextArea extends Composite implements Paintable, Field,
if (!html.equals(currentValue)) {
client.updateVariable(id, "text", html, immediate);
currentValue = html;
+ } else {
+ ApplicationConnection.getConsole().log(
+ "RTE: Not updated: " + currentValue + "|" + html);
+
}
+ } else {
+ ApplicationConnection.getConsole().log("RTE: No client or ID!");
}
}
diff --git a/src/com/vaadin/ui/RichTextArea.java b/src/com/vaadin/ui/RichTextArea.java
index f7aceb4dcc..bb7b6e58c1 100644
--- a/src/com/vaadin/ui/RichTextArea.java
+++ b/src/com/vaadin/ui/RichTextArea.java
@@ -91,4 +91,15 @@ public class RichTextArea extends TextField {
"RichTextArea does not support inputPrompt");
}
+ @Override
+ public void setReadOnly(boolean readOnly) {
+ super.setReadOnly(readOnly);
+ // IE6 cannot support multi-classname selectors properly
+ if (readOnly) {
+ addStyleName("v-richtextarea-readonly");
+ } else {
+ removeStyleName("v-richtextarea-readonly");
+ }
+ }
+
}