import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.ui.Widget;
-import com.vaadin.terminal.gwt.client.ApplicationConnection;
-import com.vaadin.terminal.gwt.client.UIDL;
import com.vaadin.terminal.gwt.client.ui.Connect;
import com.vaadin.terminal.gwt.client.ui.textfield.TextFieldConnector;
import com.vaadin.ui.PasswordField;
@Connect(PasswordField.class)
public class PasswordFieldConnector extends TextFieldConnector {
- @Override
- public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
- super.updateFromUIDL(uidl, client);
- }
-
@Override
protected Widget createWidget() {
return GWT.create(VPasswordField.class);
package com.vaadin.terminal.gwt.client.ui.textarea;
import com.google.gwt.core.client.GWT;
-import com.google.gwt.user.client.Event;
import com.google.gwt.user.client.ui.Widget;
-import com.vaadin.terminal.gwt.client.ApplicationConnection;
-import com.vaadin.terminal.gwt.client.UIDL;
+import com.vaadin.terminal.gwt.client.communication.StateChangeEvent;
import com.vaadin.terminal.gwt.client.ui.Connect;
import com.vaadin.terminal.gwt.client.ui.textfield.TextFieldConnector;
import com.vaadin.ui.TextArea;
public class TextAreaConnector extends TextFieldConnector {
@Override
- public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
- // Call parent renderer explicitly
- super.updateFromUIDL(uidl, client);
+ public TextAreaState getState() {
+ return (TextAreaState) super.getState();
+ }
- if (uidl.hasAttribute("rows")) {
- getWidget().setRows(uidl.getIntAttribute("rows"));
- }
+ @Override
+ public void onStateChanged(StateChangeEvent stateChangeEvent) {
+ super.onStateChanged(stateChangeEvent);
- if (getWidget().getMaxLength() >= 0) {
- getWidget().sinkEvents(Event.ONKEYUP);
- }
+ getWidget().setRows(getState().getRows());
+ getWidget().setWordwrap(getState().isWordwrap());
}
@Override
--- /dev/null
+package com.vaadin.terminal.gwt.client.ui.textarea;
+
+import com.vaadin.terminal.gwt.client.ui.textfield.AbstractTextFieldState;
+
+public class TextAreaState extends AbstractTextFieldState {
+
+ /**
+ * Number of visible rows in the text area. The default is 5.
+ */
+ private int rows = 5;
+
+ /**
+ * Tells if word-wrapping should be used in the text area.
+ */
+ private boolean wordwrap = true;
+
+ public int getRows() {
+ return rows;
+ }
+
+ public void setRows(int rows) {
+ this.rows = rows;
+ }
+
+ public boolean isWordwrap() {
+ return wordwrap;
+ }
+
+ public void setWordwrap(boolean wordwrap) {
+ this.wordwrap = wordwrap;
+ }
+
+}
package com.vaadin.terminal.gwt.client.ui.textarea;
import com.google.gwt.core.client.Scheduler;
+import com.google.gwt.dom.client.Style.Overflow;
+import com.google.gwt.dom.client.TextAreaElement;
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.vaadin.terminal.gwt.client.BrowserInfo;
+import com.vaadin.terminal.gwt.client.Util;
import com.vaadin.terminal.gwt.client.ui.textfield.VTextField;
/**
*/
public class VTextArea extends VTextField {
public static final String CLASSNAME = "v-textarea";
+ private boolean wordwrap = true;
public VTextArea() {
super(DOM.createTextArea());
setStyleName(CLASSNAME);
}
+ public TextAreaElement getTextAreaElement() {
+ return super.getElement().cast();
+ }
+
public void setRows(int rows) {
- setRows(getElement(), rows);
+ getTextAreaElement().setRows(rows);
}
- private native void setRows(Element e, int r)
- /*-{
- try {
- if(e.tagName.toLowerCase() == "textarea")
- e.rows = r;
- } catch (e) {}
- }-*/;
+ @Override
+ protected void setMaxLength(int newMaxLength) {
+ super.setMaxLength(newMaxLength);
+
+ boolean hasMaxLength = (newMaxLength >= 0);
+
+ if (hasMaxLength) {
+ sinkEvents(Event.ONKEYUP);
+ } else {
+ unsinkEvents(Event.ONKEYUP);
+ }
+ }
@Override
public void onBrowserEvent(Event event) {
// detected in a different way.
return getImpl().getTextAreaCursorPos(getElement());
}
+
+ @Override
+ protected void setMaxLengthToElement(int newMaxLength) {
+ // There is no maxlength property for textarea. The maximum length is
+ // enforced by the KEYUP handler
+
+ }
+
+ public void setWordwrap(boolean wordwrap) {
+ if (wordwrap == this.wordwrap) {
+ return; // No change
+ }
+
+ if (wordwrap) {
+ getElement().removeAttribute("wrap");
+ getElement().getStyle().clearOverflow();
+ } else {
+ getElement().setAttribute("wrap", "off");
+ getElement().getStyle().setOverflow(Overflow.AUTO);
+ }
+ if (BrowserInfo.get().isOpera()) {
+ // Opera fails to dynamically update the wrap attribute so we detach
+ // and reattach the whole TextArea.
+ Util.detachAttach(getElement());
+ }
+ this.wordwrap = wordwrap;
+ }
}
--- /dev/null
+package com.vaadin.terminal.gwt.client.ui.textfield;
+
+import com.vaadin.terminal.gwt.client.AbstractFieldState;
+
+public class AbstractTextFieldState extends AbstractFieldState {
+ /**
+ * Maximum character count in text field.
+ */
+ private int maxLength = -1;
+
+ /**
+ * Number of visible columns in the TextField.
+ */
+ private int columns = 0;
+
+ /**
+ * The prompt to display in an empty field. Null when disabled.
+ */
+ private String inputPrompt = null;
+
+ /**
+ * The text in the field
+ */
+ private String text = null;
+
+ public int getMaxLength() {
+ return maxLength;
+ }
+
+ public void setMaxLength(int maxLength) {
+ this.maxLength = maxLength;
+ }
+
+ public int getColumns() {
+ return columns;
+ }
+
+ public void setColumns(int columns) {
+ this.columns = columns;
+ }
+
+ public String getInputPrompt() {
+ return inputPrompt;
+ }
+
+ public void setInputPrompt(String inputPrompt) {
+ this.inputPrompt = inputPrompt;
+ }
+
+ public String getText() {
+ return text;
+ }
+
+ public void setText(String text) {
+ this.text = text;
+ }
+
+}
public class TextFieldConnector extends AbstractFieldConnector implements
Paintable, BeforeShortcutActionListener {
+ @Override
+ public AbstractTextFieldState getState() {
+ return (AbstractTextFieldState) super.getState();
+ }
+
public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
// Save details
getWidget().client = client;
getWidget().setReadOnly(isReadOnly());
- getWidget().inputPrompt = uidl
- .getStringAttribute(VTextField.ATTR_INPUTPROMPT);
-
- getWidget().setMaxLength(
- uidl.hasAttribute("maxLength") ? uidl
- .getIntAttribute("maxLength") : -1);
-
- getWidget().immediate = getState().isImmediate();
+ getWidget().setInputPrompt(getState().getInputPrompt());
+ getWidget().setMaxLength(getState().getMaxLength());
+ getWidget().setImmediate(getState().isImmediate());
getWidget().listenTextChangeEvents = hasEventListener("ie");
if (getWidget().listenTextChangeEvents) {
getWidget().sinkEvents(VTextField.TEXTCHANGE_EVENTS);
getWidget().attachCutEventListener(getWidget().getElement());
}
+ getWidget().setColumns(getState().getColumns());
- if (uidl.hasAttribute("cols")) {
- getWidget().setColumns(
- new Integer(uidl.getStringAttribute("cols")).intValue());
- }
-
- final String text = uidl.getStringVariable("text");
+ final String text = getState().getText();
/*
* We skip the text content update if field has been repainted, but text
}
});
}
-
- // Here for backward compatibility; to be moved to TextArea.
- // Optimization: server does not send attribute for the default 'true'
- // state.
- if (uidl.hasAttribute("wordwrap")
- && uidl.getBooleanAttribute("wordwrap") == false) {
- getWidget().setWordwrap(false);
- } else {
- getWidget().setWordwrap(true);
- }
}
@Override
package com.vaadin.terminal.gwt.client.ui.textfield;
-import com.google.gwt.dom.client.Style.Overflow;
import com.google.gwt.event.dom.client.BlurEvent;
import com.google.gwt.event.dom.client.BlurHandler;
import com.google.gwt.event.dom.client.ChangeEvent;
*/
private boolean valueBeforeEditIsSynced = true;
- protected boolean immediate = false;
+ private boolean immediate = false;
private int maxLength = -1;
private static final String CLASSNAME_PROMPT = "prompt";
- protected static final String ATTR_INPUTPROMPT = "prompt";
public static final String ATTR_TEXTCHANGE_TIMEOUT = "iet";
public static final String VAR_CURSOR = "c";
public static final String ATTR_TEXTCHANGE_EVENTMODE = "iem";
protected static final String TEXTCHANGE_MODE_EAGER = "EAGER";
private static final String TEXTCHANGE_MODE_TIMEOUT = "TIMEOUT";
- protected String inputPrompt = null;
+ private String inputPrompt = null;
private boolean prompting = false;
private int lastCursorPos = -1;
- private boolean wordwrap = true;
public VTextField() {
this(DOM.createInputText());
protected void setMaxLength(int newMaxLength) {
if (newMaxLength >= 0) {
maxLength = newMaxLength;
- if (getElement().getTagName().toLowerCase().equals("textarea")) {
- // NOP no maxlength property for textarea
- } else {
- getElement().setPropertyInt("maxLength", maxLength);
- }
- } else if (maxLength != -1) {
- if (getElement().getTagName().toLowerCase().equals("textarea")) {
- // NOP no maxlength property for textarea
- } else {
- getElement().removeAttribute("maxLength");
- }
+ } else {
maxLength = -1;
}
+ setMaxLengthToElement(newMaxLength);
+ }
+ protected void setMaxLengthToElement(int newMaxLength) {
+ if (newMaxLength >= 0) {
+ getElement().setPropertyInt("maxLength", newMaxLength);
+ } else {
+ getElement().removeAttribute("maxLength");
+ }
}
public int getMaxLength() {
}
public void setColumns(int columns) {
- setColumns(getElement(), columns);
- }
-
- private native void setColumns(Element e, int c)
- /*-{
- try {
- switch(e.tagName.toLowerCase()) {
- case "input":
- //e.size = c;
- e.style.width = c+"em";
- break;
- case "textarea":
- //e.cols = c;
- e.style.width = c+"em";
- break;
- default:;
- }
- } catch (e) {}
- }-*/;
-
- // Here for backward compatibility; to be moved to TextArea
- public void setWordwrap(boolean enabled) {
- if (enabled == wordwrap) {
- return; // No change
+ if (columns <= 0) {
+ return;
}
- if (enabled) {
- getElement().removeAttribute("wrap");
- getElement().getStyle().clearOverflow();
- } else {
- getElement().setAttribute("wrap", "off");
- getElement().getStyle().setOverflow(Overflow.AUTO);
- }
- if (BrowserInfo.get().isSafari4()) {
- // Force redraw as Safari 4 does not properly update the screen
- Util.forceWebkitRedraw(getElement());
- } else if (BrowserInfo.get().isOpera()) {
- // Opera fails to dynamically update the wrap attribute so we detach
- // and reattach the whole TextArea.
- Util.detachAttach(getElement());
- }
- wordwrap = enabled;
+ setWidth(columns + "em");
}
public void onKeyDown(KeyDownEvent event) {
valueChange(false);
}
}
+
+ public void setImmediate(boolean immediate) {
+ this.immediate = immediate;
+ }
+
+ public void setInputPrompt(String inputPrompt) {
+ this.inputPrompt = inputPrompt;
+ }
+
}
package com.vaadin.ui;
-import java.text.Format;
import java.util.Map;
import com.vaadin.event.FieldEvents.BlurEvent;
import com.vaadin.terminal.PaintException;
import com.vaadin.terminal.PaintTarget;
import com.vaadin.terminal.Vaadin6Component;
+import com.vaadin.terminal.gwt.client.ui.textfield.AbstractTextFieldState;
import com.vaadin.terminal.gwt.client.ui.textfield.VTextField;
public abstract class AbstractTextField extends AbstractField<String> implements
BlurNotifier, FocusNotifier, TextChangeNotifier, Vaadin6Component {
- /**
- * Value formatter used to format the string contents.
- */
- @Deprecated
- private Format format;
-
/**
* Null representation.
*/
* representation .
*/
private boolean nullSettingAllowed = false;
- /**
- * Maximum character count in text field.
- */
- private int maxLength = -1;
-
- /**
- * Number of visible columns in the TextField.
- */
- private int columns = 0;
-
- /**
- * The prompt to display in an empty field. Null when disabled.
- */
- private String inputPrompt = null;
-
/**
* The text content when the last messages to the server was sent. Cleared
* when value is changed.
super();
}
- public void paintContent(PaintTarget target) throws PaintException {
-
- if (getMaxLength() >= 0) {
- target.addAttribute("maxLength", getMaxLength());
- }
-
- // Adds the number of column and rows
- final int columns = getColumns();
- if (columns != 0) {
- target.addAttribute("cols", String.valueOf(columns));
- }
+ @Override
+ public AbstractTextFieldState getState() {
+ return (AbstractTextFieldState) super.getState();
+ }
- if (getInputPrompt() != null) {
- target.addAttribute("prompt", getInputPrompt());
- }
+ @Override
+ public void updateState() {
+ super.updateState();
- // Adds the content as variable
- String value = getFormattedValue();
+ String value = getValue();
if (value == null) {
value = getNullRepresentation();
}
- if (value == null) {
- throw new IllegalStateException(
- "Null values are not allowed if the null-representation is null");
- }
- target.addVariable(this, "text", value);
+ getState().setText(value);
+ }
+
+ public void paintContent(PaintTarget target) throws PaintException {
if (selectionPosition != -1) {
target.addAttribute("selpos", selectionPosition);
}
- /**
- * Gets the formatted string value. Sets the field value by using the
- * assigned Format.
- *
- * @return the Formatted value.
- * @see #setFormat(Format)
- * @see Format
- * @deprecated
- */
- @Deprecated
- protected String getFormattedValue() {
- Object v = getValue();
- if (v == null) {
- return null;
- }
- return v.toString();
- }
-
- @Override
- public String getValue() {
- String v = super.getValue();
- if (format == null || v == null) {
- return v;
- }
- try {
- return format.format(v);
- } catch (final IllegalArgumentException e) {
- return v;
- }
- }
-
public void changeVariables(Object source, Map<String, Object> variables) {
changingVariables = true;
if (getMaxLength() != -1 && newValue.length() > getMaxLength()) {
newValue = newValue.substring(0, getMaxLength());
}
- final String oldValue = getFormattedValue();
+ final String oldValue = getValue();
if (newValue != null
&& (oldValue == null || isNullSettingAllowed())
&& newValue.equals(getNullRepresentation())) {
// If the modified status changes, or if we have a
// formatter, repaint is needed after all.
- if (format != null || wasModified != isModified()) {
+ if (wasModified != isModified()) {
requestRepaint();
}
}
requestRepaint();
}
- /**
- * Gets the value formatter of TextField.
- *
- * @return the Format used to format the value.
- * @deprecated replaced by {@link com.vaadin.data.util.PropertyFormatter}
- */
- @Deprecated
- public Format getFormat() {
- return format;
- }
-
- /**
- * Gets the value formatter of TextField.
- *
- * @param format
- * the Format used to format the value. Null disables the
- * formatting.
- * @deprecated replaced by {@link com.vaadin.data.util.PropertyFormatter}
- */
- @Deprecated
- public void setFormat(Format format) {
- this.format = format;
- requestRepaint();
- }
-
@Override
protected boolean isEmpty() {
return super.isEmpty() || getValue().length() == 0;
* @return the maxLength
*/
public int getMaxLength() {
- return maxLength;
+ return getState().getMaxLength();
}
/**
* the maxLength to set
*/
public void setMaxLength(int maxLength) {
- this.maxLength = maxLength;
+ getState().setMaxLength(maxLength);
requestRepaint();
}
* @return the number of columns in the editor.
*/
public int getColumns() {
- return columns;
+ return getState().getColumns();
}
/**
if (columns < 0) {
columns = 0;
}
- this.columns = columns;
+ getState().setColumns(columns);
requestRepaint();
}
* @return the current input prompt, or null if not enabled
*/
public String getInputPrompt() {
- return inputPrompt;
+ return getState().getInputPrompt();
}
/**
* @param inputPrompt
*/
public void setInputPrompt(String inputPrompt) {
- this.inputPrompt = inputPrompt;
+ getState().setInputPrompt(inputPrompt);
requestRepaint();
}
package com.vaadin.ui;
import com.vaadin.data.Property;
-import com.vaadin.terminal.PaintException;
-import com.vaadin.terminal.PaintTarget;
+import com.vaadin.terminal.gwt.client.ui.textarea.TextAreaState;
/**
* A text field that supports multi line editing.
*/
public class TextArea extends AbstractTextField {
- private static final int DEFAULT_ROWS = 5;
-
- /**
- * Number of visible rows in the text area.
- */
- private int rows = DEFAULT_ROWS;
-
- /**
- * Tells if word-wrapping should be used in the text area.
- */
- private boolean wordwrap = true;
-
/**
* Constructs an empty TextArea.
*/
}
+ @Override
+ public TextAreaState getState() {
+ return (TextAreaState) super.getState();
+ }
+
/**
* Sets the number of rows in the text area.
*
if (rows < 0) {
rows = 0;
}
- if (this.rows != rows) {
- this.rows = rows;
- requestRepaint();
- }
+ getState().setRows(rows);
+ requestRepaint();
}
/**
* @return number of explicitly set rows.
*/
public int getRows() {
- return rows;
+ return getState().getRows();
}
/**
* word-wrap mode.
*/
public void setWordwrap(boolean wordwrap) {
- if (this.wordwrap != wordwrap) {
- this.wordwrap = wordwrap;
- requestRepaint();
- }
+ getState().setWordwrap(wordwrap);
+ requestRepaint();
}
/**
* <code>false</code> if not.
*/
public boolean isWordwrap() {
- return wordwrap;
+ return getState().isWordwrap();
}
- @Override
- public void paintContent(PaintTarget target) throws PaintException {
- super.paintContent(target);
-
- target.addAttribute("rows", getRows());
-
- if (!isWordwrap()) {
- // Wordwrap is only painted if turned off to minimize communications
- target.addAttribute("wordwrap", false);
- }
-
- }
}