]> source.dussan.org Git - vaadin-framework.git/commitdiff
#8324 Split RichTextArea into widget + paintable
authorArtur Signell <artur@vaadin.com>
Tue, 31 Jan 2012 12:10:05 +0000 (14:10 +0200)
committerArtur Signell <artur@vaadin.com>
Tue, 31 Jan 2012 13:09:29 +0000 (15:09 +0200)
src/com/vaadin/terminal/gwt/client/ui/richtextarea/VRichTextArea.java
src/com/vaadin/terminal/gwt/client/ui/richtextarea/VRichTextAreaPaintable.java [new file with mode: 0644]
src/com/vaadin/ui/RichTextArea.java

index 35d3247f9b14a9de768778be2a280c607a9af669..a586929d13dd54f0c0a446ecb811a7d4a6a15d60 100644 (file)
@@ -17,7 +17,6 @@ import com.google.gwt.event.shared.HandlerRegistration;
 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;
@@ -27,12 +26,10 @@ 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.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;
 
 /**
@@ -41,9 +38,8 @@ import com.vaadin.terminal.gwt.client.ui.ShortcutActionHandler.ShortcutActionHan
  * @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.
@@ -54,13 +50,13 @@ public class VRichTextArea extends Composite implements VPaintableWidget, Field,
 
     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();
 
@@ -69,15 +65,15 @@ public class VRichTextArea extends Composite implements VPaintableWidget, Field,
     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;
 
@@ -127,48 +123,7 @@ public class VRichTextArea extends Composite implements VPaintableWidget, Field,
         }
     }
 
-    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
@@ -190,7 +145,7 @@ public class VRichTextArea extends Composite implements VPaintableWidget, Field,
         }.schedule(320);
     }
 
-    private void setReadOnly(boolean b) {
+    void setReadOnly(boolean b) {
         if (isReadOnly() != b) {
             swapEditableArea();
             readOnly = b;
@@ -346,7 +301,8 @@ public class VRichTextArea extends Composite implements VPaintableWidget, Field,
         if (shortcutHandler != null) {
             shortcutHandler
                     .handleKeyboardEvent(com.google.gwt.user.client.Event
-                            .as(event.getNativeEvent()), this);
+                            .as(event.getNativeEvent()),
+                            VPaintableMap.get(client).getPaintable(this));
         }
     }
 
@@ -364,10 +320,6 @@ public class VRichTextArea extends Composite implements VPaintableWidget, Field,
         return hasShortcutActionHandler;
     }
 
-    public void onBeforeShortcutAction(Event e) {
-        synchronizeContentToServer();
-    }
-
     public int getTabIndex() {
         return rta.getTabIndex();
     }
diff --git a/src/com/vaadin/terminal/gwt/client/ui/richtextarea/VRichTextAreaPaintable.java b/src/com/vaadin/terminal/gwt/client/ui/richtextarea/VRichTextAreaPaintable.java
new file mode 100644 (file)
index 0000000..477cd13
--- /dev/null
@@ -0,0 +1,76 @@
+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
index ea22a6b54b602b27e55f4df52b1df3d5f5896b74..240063caf3dc707e3b0adb3b63990cb6fcc753c5 100644 (file)
@@ -10,7 +10,7 @@ import java.util.Map;
 import com.vaadin.data.Property;
 import com.vaadin.terminal.PaintException;
 import com.vaadin.terminal.PaintTarget;
-import com.vaadin.terminal.gwt.client.ui.richtextarea.VRichTextArea;
+import com.vaadin.terminal.gwt.client.ui.richtextarea.VRichTextAreaPaintable;
 import com.vaadin.ui.ClientWidget.LoadStyle;
 
 /**
@@ -20,7 +20,7 @@ import com.vaadin.ui.ClientWidget.LoadStyle;
  * {@link RichTextArea} may produce unexpected results as formatting is counted
  * into length of field.
  */
-@ClientWidget(value = VRichTextArea.class, loadStyle = LoadStyle.LAZY)
+@ClientWidget(value = VRichTextAreaPaintable.class, loadStyle = LoadStyle.LAZY)
 public class RichTextArea extends AbstractField<String> {
 
     /**