import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Element;
-import com.google.gwt.user.client.Event;
import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlowPanel;
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.VPaintableWidget;
-import com.vaadin.terminal.gwt.client.UIDL;
import com.vaadin.terminal.gwt.client.Util;
+import com.vaadin.terminal.gwt.client.VPaintableMap;
import com.vaadin.terminal.gwt.client.ui.Field;
import com.vaadin.terminal.gwt.client.ui.ShortcutActionHandler;
-import com.vaadin.terminal.gwt.client.ui.ShortcutActionHandler.BeforeShortcutActionListener;
import com.vaadin.terminal.gwt.client.ui.ShortcutActionHandler.ShortcutActionHandlerOwner;
/**
* @author Vaadin Ltd.
*
*/
-public class VRichTextArea extends Composite implements VPaintableWidget, Field,
- ChangeHandler, BlurHandler, KeyPressHandler, KeyDownHandler,
- BeforeShortcutActionListener, Focusable {
+public class VRichTextArea extends Composite implements Field, ChangeHandler,
+ BlurHandler, KeyPressHandler, KeyDownHandler, Focusable {
/**
* The input node CSS classname.
protected ApplicationConnection client;
- private boolean immediate = false;
+ boolean immediate = false;
- private RichTextArea rta;
+ RichTextArea rta;
private VRichTextToolbar formatter;
- private HTML html = new HTML();
+ HTML html = new HTML();
private final FlowPanel fp = new FlowPanel();
private int extraHorizontalPixels = -1;
private int extraVerticalPixels = -1;
- private int maxLength = -1;
+ int maxLength = -1;
private int toolbarNaturalWidth = 500;
- private HandlerRegistration keyPressHandler;
+ HandlerRegistration keyPressHandler;
private ShortcutActionHandlerOwner hasShortcutActionHandler;
- private String currentValue = "";
+ String currentValue = "";
private boolean readOnly = false;
}
}
- public void updateFromUIDL(final UIDL uidl, ApplicationConnection client) {
- this.client = client;
- id = uidl.getId();
-
- if (uidl.hasVariable("text")) {
- currentValue = uidl.getStringVariable("text");
- if (rta.isAttached()) {
- rta.setHTML(currentValue);
- } else {
- html.setHTML(currentValue);
- }
- }
- if (!uidl.hasAttribute("cached")) {
- 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;
- if (newMaxLength >= 0) {
- if (maxLength == -1) {
- keyPressHandler = rta.addKeyPressHandler(this);
- }
- maxLength = newMaxLength;
- } else if (maxLength != -1) {
- getElement().setAttribute("maxlength", "");
- maxLength = -1;
- keyPressHandler.removeHandler();
- }
-
- if (uidl.hasAttribute("selectAll")) {
- selectAll();
- }
-
- }
-
- private void selectAll() {
+ void selectAll() {
/*
* There is a timing issue if trying to select all immediately on first
* render. Simple deferred command is not enough. Using Timer with
}.schedule(320);
}
- private void setReadOnly(boolean b) {
+ void setReadOnly(boolean b) {
if (isReadOnly() != b) {
swapEditableArea();
readOnly = b;
if (shortcutHandler != null) {
shortcutHandler
.handleKeyboardEvent(com.google.gwt.user.client.Event
- .as(event.getNativeEvent()), this);
+ .as(event.getNativeEvent()),
+ VPaintableMap.get(client).getPaintable(this));
}
}
return hasShortcutActionHandler;
}
- public void onBeforeShortcutAction(Event e) {
- synchronizeContentToServer();
- }
-
public int getTabIndex() {
return rta.getTabIndex();
}
--- /dev/null
+package com.vaadin.terminal.gwt.client.ui.richtextarea;\r
+\r
+import com.google.gwt.core.client.GWT;\r
+import com.google.gwt.user.client.Event;\r
+import com.google.gwt.user.client.ui.Widget;\r
+import com.vaadin.terminal.gwt.client.ApplicationConnection;\r
+import com.vaadin.terminal.gwt.client.UIDL;\r
+import com.vaadin.terminal.gwt.client.ui.ShortcutActionHandler.BeforeShortcutActionListener;\r
+import com.vaadin.terminal.gwt.client.ui.VAbstractPaintableWidget;\r
+\r
+public class VRichTextAreaPaintable extends VAbstractPaintableWidget implements\r
+ BeforeShortcutActionListener {\r
+\r
+ public void updateFromUIDL(final UIDL uidl, ApplicationConnection client) {\r
+ getWidgetForPaintable().client = client;\r
+ getWidgetForPaintable().id = uidl.getId();\r
+\r
+ if (uidl.hasVariable("text")) {\r
+ getWidgetForPaintable().currentValue = uidl\r
+ .getStringVariable("text");\r
+ if (getWidgetForPaintable().rta.isAttached()) {\r
+ getWidgetForPaintable().rta\r
+ .setHTML(getWidgetForPaintable().currentValue);\r
+ } else {\r
+ getWidgetForPaintable().html\r
+ .setHTML(getWidgetForPaintable().currentValue);\r
+ }\r
+ }\r
+ if (!uidl.hasAttribute("cached")) {\r
+ getWidgetForPaintable().setEnabled(\r
+ !uidl.getBooleanAttribute("disabled"));\r
+ }\r
+\r
+ if (client.updateComponent(this, uidl, true)) {\r
+ return;\r
+ }\r
+\r
+ getWidgetForPaintable().setReadOnly(\r
+ uidl.getBooleanAttribute("readonly"));\r
+ getWidgetForPaintable().immediate = uidl\r
+ .getBooleanAttribute("immediate");\r
+ int newMaxLength = uidl.hasAttribute("maxLength") ? uidl\r
+ .getIntAttribute("maxLength") : -1;\r
+ if (newMaxLength >= 0) {\r
+ if (getWidgetForPaintable().maxLength == -1) {\r
+ getWidgetForPaintable().keyPressHandler = getWidgetForPaintable().rta\r
+ .addKeyPressHandler(getWidgetForPaintable());\r
+ }\r
+ getWidgetForPaintable().maxLength = newMaxLength;\r
+ } else if (getWidgetForPaintable().maxLength != -1) {\r
+ getWidgetForPaintable().getElement().setAttribute("maxlength", "");\r
+ getWidgetForPaintable().maxLength = -1;\r
+ getWidgetForPaintable().keyPressHandler.removeHandler();\r
+ }\r
+\r
+ if (uidl.hasAttribute("selectAll")) {\r
+ getWidgetForPaintable().selectAll();\r
+ }\r
+\r
+ }\r
+\r
+ public void onBeforeShortcutAction(Event e) {\r
+ getWidgetForPaintable().synchronizeContentToServer();\r
+ }\r
+\r
+ @Override\r
+ public VRichTextArea getWidgetForPaintable() {\r
+ return (VRichTextArea) super.getWidgetForPaintable();\r
+ };\r
+\r
+ @Override\r
+ protected Widget createWidget() {\r
+ return GWT.create(VRichTextArea.class);\r
+ }\r
+\r
+}\r