- Changes input prompt to be based on the placeholder attribute. - Unifies TextChangeEvents with ValueChangeEvents. - add*Listener methods now return Registration objects, remove*Listener methods removed. Change-Id: Ie92506ae9db205bb0010ae9126c608c62ad023fftags/8.0.0.alpha1
@@ -0,0 +1,55 @@ | |||
/* | |||
* Copyright 2000-2014 Vaadin Ltd. | |||
* | |||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | |||
* use this file except in compliance with the License. You may obtain a copy of | |||
* the License at | |||
* | |||
* http://www.apache.org/licenses/LICENSE-2.0 | |||
* | |||
* Unless required by applicable law or agreed to in writing, software | |||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | |||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | |||
* License for the specific language governing permissions and limitations under | |||
* the License. | |||
*/ | |||
package com.vaadin.client.event; | |||
import com.google.gwt.event.dom.client.DomEvent; | |||
/** | |||
* Represents a native InputEvent. | |||
* | |||
* @since 8.0 | |||
*/ | |||
public class InputEvent extends DomEvent<InputHandler> { | |||
/** | |||
* Event type for InputEvent. Represents the meta-data associated with this | |||
* event. | |||
*/ | |||
private static final Type<InputHandler> TYPE = new Type<InputHandler>( | |||
"input", new InputEvent()); | |||
protected InputEvent() { | |||
} | |||
/** | |||
* Gets the event type associated with InputEvent. | |||
* | |||
* @return the handler type | |||
*/ | |||
public static Type<InputHandler> getType() { | |||
return TYPE; | |||
} | |||
@Override | |||
public Type<InputHandler> getAssociatedType() { | |||
return TYPE; | |||
} | |||
@Override | |||
protected void dispatch(InputHandler handler) { | |||
handler.onInput(this); | |||
} | |||
} |
@@ -0,0 +1,34 @@ | |||
/* | |||
* Copyright 2000-2014 Vaadin Ltd. | |||
* | |||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | |||
* use this file except in compliance with the License. You may obtain a copy of | |||
* the License at | |||
* | |||
* http://www.apache.org/licenses/LICENSE-2.0 | |||
* | |||
* Unless required by applicable law or agreed to in writing, software | |||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | |||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | |||
* License for the specific language governing permissions and limitations under | |||
* the License. | |||
*/ | |||
package com.vaadin.client.event; | |||
import com.google.gwt.event.shared.EventHandler; | |||
/** | |||
* Handler interface for {@link InputEvent}s. | |||
* | |||
* @since 8.0 | |||
*/ | |||
public interface InputHandler extends EventHandler { | |||
/** | |||
* Called when an {@link InputEvent} is fired. | |||
* | |||
* @param event | |||
* the {@link InputEvent} that was fired. | |||
*/ | |||
void onInput(InputEvent event); | |||
} |
@@ -0,0 +1,533 @@ | |||
/* | |||
* Copyright 2000-2014 Vaadin Ltd. | |||
* | |||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | |||
* use this file except in compliance with the License. You may obtain a copy of | |||
* the License at | |||
* | |||
* http://www.apache.org/licenses/LICENSE-2.0 | |||
* | |||
* Unless required by applicable law or agreed to in writing, software | |||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | |||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | |||
* License for the specific language governing permissions and limitations under | |||
* the License. | |||
*/ | |||
package com.vaadin.client.legacy.ui; | |||
import com.google.gwt.core.client.Scheduler; | |||
import com.google.gwt.core.client.Scheduler.ScheduledCommand; | |||
import com.google.gwt.dom.client.Element; | |||
import com.google.gwt.event.dom.client.BlurEvent; | |||
import com.google.gwt.event.dom.client.BlurHandler; | |||
import com.google.gwt.event.dom.client.ChangeEvent; | |||
import com.google.gwt.event.dom.client.ChangeHandler; | |||
import com.google.gwt.event.dom.client.FocusEvent; | |||
import com.google.gwt.event.dom.client.FocusHandler; | |||
import com.google.gwt.event.dom.client.KeyCodes; | |||
import com.google.gwt.event.dom.client.KeyDownEvent; | |||
import com.google.gwt.event.dom.client.KeyDownHandler; | |||
import com.google.gwt.user.client.DOM; | |||
import com.google.gwt.user.client.Event; | |||
import com.google.gwt.user.client.Timer; | |||
import com.google.gwt.user.client.ui.TextBoxBase; | |||
import com.vaadin.client.ApplicationConnection; | |||
import com.vaadin.client.BrowserInfo; | |||
import com.vaadin.client.WidgetUtil; | |||
import com.vaadin.client.ui.Field; | |||
import com.vaadin.shared.EventId; | |||
import com.vaadin.shared.legacy.ui.textfield.LegacyTextFieldConstants; | |||
/** | |||
* This class represents a basic text input field with one row. | |||
* | |||
* @author Vaadin Ltd. | |||
* | |||
*/ | |||
@Deprecated | |||
public class VLegacyTextField extends TextBoxBase implements Field, ChangeHandler, | |||
FocusHandler, BlurHandler, KeyDownHandler { | |||
/** | |||
* The input node CSS classname. | |||
*/ | |||
public static final String CLASSNAME = "v-textfield"; | |||
/** | |||
* This CSS classname is added to the input node on hover. | |||
*/ | |||
public static final String CLASSNAME_FOCUS = "focus"; | |||
/** For internal use only. May be removed or replaced in the future. */ | |||
public String paintableId; | |||
/** For internal use only. May be removed or replaced in the future. */ | |||
public ApplicationConnection client; | |||
/** For internal use only. May be removed or replaced in the future. */ | |||
public String valueBeforeEdit = null; | |||
/** | |||
* Set to false if a text change event has been sent since the last value | |||
* change event. This means that {@link #valueBeforeEdit} should not be | |||
* trusted when determining whether a text change even should be sent. | |||
*/ | |||
private boolean valueBeforeEditIsSynced = true; | |||
private boolean immediate = false; | |||
private int maxLength = -1; | |||
private static final String CLASSNAME_PROMPT = "prompt"; | |||
private static final String TEXTCHANGE_MODE_TIMEOUT = "TIMEOUT"; | |||
private String inputPrompt = null; | |||
private boolean prompting = false; | |||
private int lastCursorPos = -1; | |||
// used while checking if FF has set input prompt as value | |||
private boolean possibleInputError = false; | |||
public VLegacyTextField() { | |||
this(DOM.createInputText()); | |||
} | |||
protected VLegacyTextField(Element node) { | |||
super(node); | |||
setStyleName(CLASSNAME); | |||
addChangeHandler(this); | |||
if (BrowserInfo.get().isIE() || BrowserInfo.get().isFirefox()) { | |||
addKeyDownHandler(this); | |||
} | |||
addFocusHandler(this); | |||
addBlurHandler(this); | |||
} | |||
/** | |||
* For internal use only. May be removed or replaced in the future. | |||
* <p> | |||
* TODO When GWT adds ONCUT, add it there and remove workaround. See | |||
* http://code.google.com/p/google-web-toolkit/issues/detail?id=4030 | |||
* <p> | |||
* Also note that the cut/paste are not totally crossbrowsers compatible. | |||
* E.g. in Opera mac works via context menu, but on via File->Paste/Cut. | |||
* Opera might need the polling method for 100% working textchanceevents. | |||
* Eager polling for a change is bit dum and heavy operation, so I guess we | |||
* should first try to survive without. | |||
*/ | |||
public static final int TEXTCHANGE_EVENTS = Event.ONPASTE | Event.KEYEVENTS | |||
| Event.ONMOUSEUP; | |||
@Override | |||
public void onBrowserEvent(Event event) { | |||
super.onBrowserEvent(event); | |||
if (listenTextChangeEvents | |||
&& (event.getTypeInt() & TEXTCHANGE_EVENTS) == event | |||
.getTypeInt()) { | |||
deferTextChangeEvent(); | |||
} | |||
} | |||
/* | |||
* TODO optimize this so that only changes are sent + make the value change | |||
* event just a flag that moves the current text to value | |||
*/ | |||
private String lastTextChangeString = null; | |||
private String getLastCommunicatedString() { | |||
return lastTextChangeString; | |||
} | |||
private void communicateTextValueToServer() { | |||
String text = getText(); | |||
if (prompting) { | |||
// Input prompt visible, text is actually "" | |||
text = ""; | |||
} | |||
if (!text.equals(getLastCommunicatedString())) { | |||
if (valueBeforeEditIsSynced && text.equals(valueBeforeEdit)) { | |||
/* | |||
* Value change for the current text has been enqueued since the | |||
* last text change event was sent, but we can't know that it | |||
* has been sent to the server. Ensure that all pending changes | |||
* are sent now. Sending a value change without a text change | |||
* will simulate a TextChangeEvent on the server. | |||
*/ | |||
client.sendPendingVariableChanges(); | |||
} else { | |||
// Default case - just send an immediate text change message | |||
client.updateVariable(paintableId, | |||
LegacyTextFieldConstants.VAR_CUR_TEXT, text, true); | |||
// Shouldn't investigate valueBeforeEdit to avoid duplicate text | |||
// change events as the states are not in sync any more | |||
valueBeforeEditIsSynced = false; | |||
} | |||
lastTextChangeString = text; | |||
} | |||
} | |||
private Timer textChangeEventTrigger = new Timer() { | |||
@Override | |||
public void run() { | |||
if (isAttached()) { | |||
updateCursorPosition(); | |||
communicateTextValueToServer(); | |||
scheduled = false; | |||
} | |||
} | |||
}; | |||
private boolean scheduled = false; | |||
/** For internal use only. May be removed or replaced in the future. */ | |||
public boolean listenTextChangeEvents; | |||
/** For internal use only. May be removed or replaced in the future. */ | |||
public String textChangeEventMode; | |||
public int textChangeEventTimeout; | |||
private void deferTextChangeEvent() { | |||
if (textChangeEventMode.equals(TEXTCHANGE_MODE_TIMEOUT) && scheduled) { | |||
return; | |||
} else { | |||
textChangeEventTrigger.cancel(); | |||
} | |||
textChangeEventTrigger.schedule(getTextChangeEventTimeout()); | |||
scheduled = true; | |||
} | |||
private int getTextChangeEventTimeout() { | |||
return textChangeEventTimeout; | |||
} | |||
@Override | |||
public void setReadOnly(boolean readOnly) { | |||
boolean wasReadOnly = isReadOnly(); | |||
if (readOnly) { | |||
setTabIndex(-1); | |||
} else if (wasReadOnly && !readOnly && getTabIndex() == -1) { | |||
/* | |||
* Need to manually set tab index to 0 since server will not send | |||
* the tab index if it is 0. | |||
*/ | |||
setTabIndex(0); | |||
} | |||
super.setReadOnly(readOnly); | |||
} | |||
/** For internal use only. May be removed or replaced in the future. */ | |||
public void updateFieldContent(final String text) { | |||
setPrompting(inputPrompt != null && focusedTextField != this | |||
&& (text.equals(""))); | |||
String fieldValue; | |||
if (prompting) { | |||
fieldValue = isReadOnly() ? "" : inputPrompt; | |||
addStyleDependentName(CLASSNAME_PROMPT); | |||
} else { | |||
fieldValue = text; | |||
removeStyleDependentName(CLASSNAME_PROMPT); | |||
} | |||
setText(fieldValue); | |||
lastTextChangeString = valueBeforeEdit = text; | |||
valueBeforeEditIsSynced = true; | |||
} | |||
protected void onCut() { | |||
if (listenTextChangeEvents) { | |||
deferTextChangeEvent(); | |||
} | |||
} | |||
/** For internal use only. May be removed or replaced in the future. */ | |||
public native void attachCutEventListener(Element el) | |||
/*-{ | |||
var me = this; | |||
el.oncut = $entry(function() { | |||
me.@com.vaadin.client.legacy.ui.VLegacyTextField::onCut()(); | |||
}); | |||
}-*/; | |||
protected native void detachCutEventListener(Element el) | |||
/*-{ | |||
el.oncut = null; | |||
}-*/; | |||
private void onDrop() { | |||
if (focusedTextField == this) { | |||
return; | |||
} | |||
updateText(false); | |||
} | |||
private void updateText(boolean blurred) { | |||
String text = getText(); | |||
setPrompting(inputPrompt != null && (text == null || text.isEmpty())); | |||
if (prompting) { | |||
setText(isReadOnly() ? "" : inputPrompt); | |||
if (blurred) { | |||
addStyleDependentName(CLASSNAME_PROMPT); | |||
} | |||
} | |||
valueChange(blurred); | |||
} | |||
private void scheduleOnDropEvent() { | |||
Scheduler.get().scheduleDeferred(new ScheduledCommand() { | |||
@Override | |||
public void execute() { | |||
onDrop(); | |||
} | |||
}); | |||
} | |||
private native void attachDropEventListener(Element el) | |||
/*-{ | |||
var me = this; | |||
el.ondrop = $entry(function() { | |||
me.@com.vaadin.client.legacy.ui.VLegacyTextField::scheduleOnDropEvent()(); | |||
}); | |||
}-*/; | |||
private native void detachDropEventListener(Element el) | |||
/*-{ | |||
el.ondrop = null; | |||
}-*/; | |||
@Override | |||
protected void onDetach() { | |||
super.onDetach(); | |||
detachCutEventListener(getElement()); | |||
if (focusedTextField == this) { | |||
focusedTextField = null; | |||
} | |||
if (BrowserInfo.get().isFirefox()) { | |||
removeOnInputListener(getElement()); | |||
detachDropEventListener(getElement()); | |||
} | |||
} | |||
@Override | |||
protected void onAttach() { | |||
super.onAttach(); | |||
if (listenTextChangeEvents) { | |||
detachCutEventListener(getElement()); | |||
} | |||
if (BrowserInfo.get().isFirefox()) { | |||
// Workaround for FF setting input prompt as the value if esc is | |||
// pressed while the field is focused and empty (#8051). | |||
addOnInputListener(getElement()); | |||
// Workaround for FF updating component's internal value after | |||
// having drag-and-dropped text from another element (#14056) | |||
attachDropEventListener(getElement()); | |||
} | |||
} | |||
/** For internal use only. May be removed or replaced in the future. */ | |||
public void setMaxLength(int newMaxLength) { | |||
if (newMaxLength == maxLength) { | |||
return; | |||
} | |||
maxLength = newMaxLength; | |||
updateMaxLength(maxLength); | |||
} | |||
/** | |||
* This method is responsible for updating the DOM or otherwise ensuring | |||
* that the given max length is enforced. Called when the max length for the | |||
* field has changed. | |||
* | |||
* @param maxLength | |||
* The new max length | |||
*/ | |||
protected void updateMaxLength(int maxLength) { | |||
if (maxLength >= 0) { | |||
getElement().setPropertyInt("maxLength", maxLength); | |||
} else { | |||
getElement().removeAttribute("maxLength"); | |||
} | |||
setMaxLengthToElement(maxLength); | |||
} | |||
protected void setMaxLengthToElement(int newMaxLength) { | |||
if (newMaxLength >= 0) { | |||
getElement().setPropertyInt("maxLength", newMaxLength); | |||
} else { | |||
getElement().removeAttribute("maxLength"); | |||
} | |||
} | |||
public int getMaxLength() { | |||
return maxLength; | |||
} | |||
@Override | |||
public void onChange(ChangeEvent event) { | |||
valueChange(false); | |||
} | |||
/** | |||
* Called when the field value might have changed and/or the field was | |||
* blurred. These are combined so the blur event is sent in the same batch | |||
* as a possible value change event (these are often connected). | |||
* | |||
* @param blurred | |||
* true if the field was blurred | |||
*/ | |||
public void valueChange(boolean blurred) { | |||
if (client != null && paintableId != null) { | |||
boolean sendBlurEvent = false; | |||
boolean sendValueChange = false; | |||
if (blurred && client.hasEventListeners(this, EventId.BLUR)) { | |||
sendBlurEvent = true; | |||
client.updateVariable(paintableId, EventId.BLUR, "", false); | |||
} | |||
String newText = prompting ? "" : getText(); | |||
if (newText != null && !newText.equals(valueBeforeEdit)) { | |||
sendValueChange = immediate; | |||
client.updateVariable(paintableId, "text", newText, false); | |||
valueBeforeEdit = newText; | |||
valueBeforeEditIsSynced = true; | |||
} | |||
/* | |||
* also send cursor position, no public api yet but for easier | |||
* extension | |||
*/ | |||
updateCursorPosition(); | |||
if (sendBlurEvent || sendValueChange) { | |||
/* | |||
* Avoid sending text change event as we will simulate it on the | |||
* server side before value change events. | |||
*/ | |||
textChangeEventTrigger.cancel(); | |||
scheduled = false; | |||
client.sendPendingVariableChanges(); | |||
} | |||
} | |||
} | |||
/** | |||
* Updates the cursor position variable if it has changed since the last | |||
* update. | |||
* | |||
* @return true iff the value was updated | |||
*/ | |||
protected boolean updateCursorPosition() { | |||
if (WidgetUtil.isAttachedAndDisplayed(this)) { | |||
int cursorPos = prompting ? 0 : getCursorPos(); | |||
if (lastCursorPos != cursorPos) { | |||
client.updateVariable(paintableId, | |||
LegacyTextFieldConstants.VAR_CURSOR, cursorPos, false); | |||
lastCursorPos = cursorPos; | |||
return true; | |||
} | |||
} | |||
return false; | |||
} | |||
private static VLegacyTextField focusedTextField; | |||
public static void flushChangesFromFocusedTextField() { | |||
if (focusedTextField != null) { | |||
focusedTextField.onChange(null); | |||
} | |||
} | |||
@Override | |||
public void onFocus(FocusEvent event) { | |||
addStyleDependentName(CLASSNAME_FOCUS); | |||
if (prompting) { | |||
setText(""); | |||
removeStyleDependentName(CLASSNAME_PROMPT); | |||
setPrompting(false); | |||
} | |||
focusedTextField = this; | |||
if (client != null && client.hasEventListeners(this, EventId.FOCUS)) { | |||
client.updateVariable(paintableId, EventId.FOCUS, "", true); | |||
} | |||
} | |||
@Override | |||
public void onBlur(BlurEvent event) { | |||
// this is called twice on Chrome when e.g. changing tab while prompting | |||
// field focused - do not change settings on the second time | |||
if (focusedTextField != this) { | |||
return; | |||
} | |||
removeStyleDependentName(CLASSNAME_FOCUS); | |||
focusedTextField = null; | |||
updateText(true); | |||
} | |||
private void setPrompting(boolean prompting) { | |||
this.prompting = prompting; | |||
} | |||
public void setColumns(int columns) { | |||
if (columns <= 0) { | |||
return; | |||
} | |||
setWidth(columns + "em"); | |||
} | |||
@Override | |||
public void onKeyDown(KeyDownEvent event) { | |||
if (BrowserInfo.get().isIE() | |||
&& event.getNativeKeyCode() == KeyCodes.KEY_ENTER) { | |||
// IE does not send change events when pressing enter in a text | |||
// input so we handle it using a key listener instead | |||
valueChange(false); | |||
} else if (BrowserInfo.get().isFirefox() | |||
&& event.getNativeKeyCode() == KeyCodes.KEY_ESCAPE | |||
&& getText().equals("")) { | |||
// check after onInput event if inputPrompt has appeared as the | |||
// value of the field | |||
possibleInputError = true; | |||
} | |||
} | |||
public void setImmediate(boolean immediate) { | |||
this.immediate = immediate; | |||
} | |||
public void setInputPrompt(String inputPrompt) { | |||
this.inputPrompt = inputPrompt; | |||
} | |||
protected boolean isWordwrap() { | |||
String wrap = getElement().getAttribute("wrap"); | |||
return !"off".equals(wrap); | |||
} | |||
private native void addOnInputListener(Element el) | |||
/*-{ | |||
var self = this; | |||
el.oninput = $entry(function() { | |||
self.@com.vaadin.client.legacy.ui.VLegacyTextField::checkForInputError()(); | |||
}); | |||
}-*/; | |||
private native void removeOnInputListener(Element el) | |||
/*-{ | |||
el.oninput = null; | |||
}-*/; | |||
private void checkForInputError() { | |||
if (possibleInputError && getText().equals(inputPrompt)) { | |||
setText(""); | |||
} | |||
possibleInputError = false; | |||
} | |||
} |
@@ -0,0 +1,130 @@ | |||
/* | |||
* Copyright 2000-2014 Vaadin Ltd. | |||
* | |||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | |||
* use this file except in compliance with the License. You may obtain a copy of | |||
* the License at | |||
* | |||
* http://www.apache.org/licenses/LICENSE-2.0 | |||
* | |||
* Unless required by applicable law or agreed to in writing, software | |||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | |||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | |||
* License for the specific language governing permissions and limitations under | |||
* the License. | |||
*/ | |||
package com.vaadin.client.legacy.ui.textfield; | |||
import com.google.gwt.core.client.Scheduler; | |||
import com.google.gwt.user.client.Command; | |||
import com.google.gwt.user.client.Event; | |||
import com.vaadin.client.ApplicationConnection; | |||
import com.vaadin.client.Paintable; | |||
import com.vaadin.client.UIDL; | |||
import com.vaadin.client.Util; | |||
import com.vaadin.client.legacy.ui.VLegacyTextField; | |||
import com.vaadin.client.ui.AbstractFieldConnector; | |||
import com.vaadin.client.ui.ShortcutActionHandler.BeforeShortcutActionListener; | |||
import com.vaadin.legacy.ui.LegacyTextField; | |||
import com.vaadin.shared.legacy.ui.textfield.LegacyAbstractTextFieldState; | |||
import com.vaadin.shared.legacy.ui.textfield.LegacyTextFieldConstants; | |||
import com.vaadin.shared.ui.Connect; | |||
import com.vaadin.shared.ui.Connect.LoadStyle; | |||
@Deprecated | |||
@Connect(value = LegacyTextField.class, loadStyle = LoadStyle.EAGER) | |||
public class LegacyTextFieldConnector extends AbstractFieldConnector implements | |||
Paintable, BeforeShortcutActionListener { | |||
@Override | |||
public LegacyAbstractTextFieldState getState() { | |||
return (LegacyAbstractTextFieldState) super.getState(); | |||
} | |||
@Override | |||
public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { | |||
// Save details | |||
getWidget().client = client; | |||
getWidget().paintableId = uidl.getId(); | |||
if (!isRealUpdate(uidl)) { | |||
return; | |||
} | |||
getWidget().setReadOnly(isReadOnly()); | |||
getWidget().setInputPrompt(getState().inputPrompt); | |||
getWidget().setMaxLength(getState().maxLength); | |||
getWidget().setImmediate(getState().immediate); | |||
getWidget().listenTextChangeEvents = hasEventListener("ie"); | |||
if (getWidget().listenTextChangeEvents) { | |||
getWidget().textChangeEventMode = uidl | |||
.getStringAttribute(LegacyTextFieldConstants.ATTR_TEXTCHANGE_EVENTMODE); | |||
if (getWidget().textChangeEventMode | |||
.equals(LegacyTextFieldConstants.TEXTCHANGE_MODE_EAGER)) { | |||
getWidget().textChangeEventTimeout = 1; | |||
} else { | |||
getWidget().textChangeEventTimeout = uidl | |||
.getIntAttribute(LegacyTextFieldConstants.ATTR_TEXTCHANGE_TIMEOUT); | |||
if (getWidget().textChangeEventTimeout < 1) { | |||
// Sanitize and allow lazy/timeout with timeout set to 0 to | |||
// work as eager | |||
getWidget().textChangeEventTimeout = 1; | |||
} | |||
} | |||
getWidget().sinkEvents(VLegacyTextField.TEXTCHANGE_EVENTS); | |||
getWidget().attachCutEventListener(getWidget().getElement()); | |||
} | |||
getWidget().setColumns(getState().columns); | |||
String text = getState().text; | |||
if (text == null) { | |||
text = ""; | |||
} | |||
/* | |||
* We skip the text content update if field has been repainted, but text | |||
* has not been changed (#6588). Additional sanity check verifies there | |||
* is no change in the queue (in which case we count more on the server | |||
* side value). <input> is updated only when it looses focus, so we | |||
* force updating if not focused. Lost focus issue appeared in (#15144) | |||
*/ | |||
if (!(Util.getFocusedElement() == getWidget().getElement()) | |||
|| !uidl.getBooleanAttribute(LegacyTextFieldConstants.ATTR_NO_VALUE_CHANGE_BETWEEN_PAINTS) | |||
|| getWidget().valueBeforeEdit == null | |||
|| !text.equals(getWidget().valueBeforeEdit)) { | |||
getWidget().updateFieldContent(text); | |||
} | |||
if (uidl.hasAttribute("selpos")) { | |||
final int pos = uidl.getIntAttribute("selpos"); | |||
final int length = uidl.getIntAttribute("sellen"); | |||
/* | |||
* Gecko defers setting the text so we need to defer the selection. | |||
*/ | |||
Scheduler.get().scheduleDeferred(new Command() { | |||
@Override | |||
public void execute() { | |||
getWidget().setSelectionRange(pos, length); | |||
} | |||
}); | |||
} | |||
} | |||
@Override | |||
public VLegacyTextField getWidget() { | |||
return (VLegacyTextField) super.getWidget(); | |||
} | |||
@Override | |||
public void onBeforeShortcutAction(Event e) { | |||
flush(); | |||
} | |||
@Override | |||
public void flush() { | |||
getWidget().valueChange(false); | |||
} | |||
} |
@@ -33,6 +33,7 @@ import com.google.gwt.user.client.ui.Widget; | |||
import com.vaadin.client.ApplicationConnection; | |||
import com.vaadin.client.Focusable; | |||
import com.vaadin.client.UIDL; | |||
import com.vaadin.client.legacy.ui.VLegacyTextField; | |||
public abstract class VOptionGroupBase extends Composite implements Field, | |||
ClickHandler, ChangeHandler, KeyPressHandler, Focusable, HasEnabled { | |||
@@ -83,7 +84,7 @@ public abstract class VOptionGroupBase extends Composite implements Field, | |||
public final Panel container; | |||
/** For internal use only. May be removed or replaced in the future. */ | |||
public VTextField newItemField; | |||
public VLegacyTextField newItemField; | |||
/** For internal use only. May be removed or replaced in the future. */ | |||
public VNativeButton newItemButton; |
@@ -17,6 +17,7 @@ | |||
package com.vaadin.client.ui; | |||
import com.google.gwt.user.client.DOM; | |||
import com.vaadin.client.legacy.ui.VLegacyTextField; | |||
/** | |||
* This class represents a password field. | |||
@@ -24,7 +25,7 @@ import com.google.gwt.user.client.DOM; | |||
* @author Vaadin Ltd. | |||
* | |||
*/ | |||
public class VPasswordField extends VTextField { | |||
public class VPasswordField extends VLegacyTextField { | |||
public VPasswordField() { | |||
super(DOM.createInputPassword()); |
@@ -85,6 +85,7 @@ import com.vaadin.client.ConnectorMap; | |||
import com.vaadin.client.DeferredWorker; | |||
import com.vaadin.client.Focusable; | |||
import com.vaadin.client.HasChildMeasurementHintConnector.ChildMeasurementHint; | |||
import com.vaadin.client.legacy.ui.VLegacyTextField; | |||
import com.vaadin.client.MouseEventDetailsBuilder; | |||
import com.vaadin.client.StyleConstants; | |||
import com.vaadin.client.TooltipInfo; | |||
@@ -6472,7 +6473,7 @@ public class VScrollTable extends FlowPanel implements HasWidgets, | |||
if (!(widget instanceof VLabel) | |||
&& !(widget instanceof VEmbedded) | |||
&& !(widget instanceof VTextField && ((VTextField) widget) | |||
&& !(widget instanceof VLegacyTextField && ((VLegacyTextField) widget) | |||
.isReadOnly())) { | |||
return null; | |||
} |
@@ -33,6 +33,7 @@ import com.google.gwt.user.client.DOM; | |||
import com.google.gwt.user.client.Event; | |||
import com.vaadin.client.BrowserInfo; | |||
import com.vaadin.client.WidgetUtil; | |||
import com.vaadin.client.legacy.ui.VLegacyTextField; | |||
import com.vaadin.client.ui.dd.DragImageModifier; | |||
/** | |||
@@ -44,7 +45,7 @@ import com.vaadin.client.ui.dd.DragImageModifier; | |||
* @author Vaadin Ltd. | |||
* | |||
*/ | |||
public class VTextArea extends VTextField implements DragImageModifier { | |||
public class VTextArea extends VLegacyTextField implements DragImageModifier { | |||
public static final String CLASSNAME = "v-textarea"; | |||
private boolean wordwrap = true; |
@@ -1,12 +1,12 @@ | |||
/* | |||
* Copyright 2000-2014 Vaadin Ltd. | |||
* | |||
* | |||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | |||
* use this file except in compliance with the License. You may obtain a copy of | |||
* the License at | |||
* | |||
* | |||
* http://www.apache.org/licenses/LICENSE-2.0 | |||
* | |||
* | |||
* Unless required by applicable law or agreed to in writing, software | |||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | |||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | |||
@@ -16,27 +16,9 @@ | |||
package com.vaadin.client.ui; | |||
import com.google.gwt.core.client.Scheduler; | |||
import com.google.gwt.core.client.Scheduler.ScheduledCommand; | |||
import com.google.gwt.dom.client.Element; | |||
import com.google.gwt.event.dom.client.BlurEvent; | |||
import com.google.gwt.event.dom.client.BlurHandler; | |||
import com.google.gwt.event.dom.client.ChangeEvent; | |||
import com.google.gwt.event.dom.client.ChangeHandler; | |||
import com.google.gwt.event.dom.client.FocusEvent; | |||
import com.google.gwt.event.dom.client.FocusHandler; | |||
import com.google.gwt.event.dom.client.KeyCodes; | |||
import com.google.gwt.event.dom.client.KeyDownEvent; | |||
import com.google.gwt.event.dom.client.KeyDownHandler; | |||
import com.google.gwt.user.client.DOM; | |||
import com.google.gwt.user.client.Event; | |||
import com.google.gwt.user.client.Timer; | |||
import com.google.gwt.user.client.ui.TextBoxBase; | |||
import com.vaadin.client.ApplicationConnection; | |||
import com.vaadin.client.BrowserInfo; | |||
import com.vaadin.client.WidgetUtil; | |||
import com.vaadin.shared.EventId; | |||
import com.vaadin.shared.ui.textfield.TextFieldConstants; | |||
/** | |||
* This class represents a basic text input field with one row. | |||
@@ -44,488 +26,33 @@ import com.vaadin.shared.ui.textfield.TextFieldConstants; | |||
* @author Vaadin Ltd. | |||
* | |||
*/ | |||
public class VTextField extends TextBoxBase implements Field, ChangeHandler, | |||
FocusHandler, BlurHandler, KeyDownHandler { | |||
public class VTextField extends TextBoxBase implements Field { | |||
/** | |||
* The input node CSS classname. | |||
*/ | |||
public static final String CLASSNAME = "v-textfield"; | |||
/** | |||
* This CSS classname is added to the input node on hover. | |||
*/ | |||
public static final String CLASSNAME_FOCUS = "focus"; | |||
/** For internal use only. May be removed or replaced in the future. */ | |||
public String paintableId; | |||
/** For internal use only. May be removed or replaced in the future. */ | |||
public ApplicationConnection client; | |||
/** For internal use only. May be removed or replaced in the future. */ | |||
public String valueBeforeEdit = null; | |||
/** | |||
* Set to false if a text change event has been sent since the last value | |||
* change event. This means that {@link #valueBeforeEdit} should not be | |||
* trusted when determining whether a text change even should be sent. | |||
*/ | |||
private boolean valueBeforeEditIsSynced = true; | |||
private boolean immediate = false; | |||
private int maxLength = -1; | |||
private static final String CLASSNAME_PROMPT = "prompt"; | |||
private static final String TEXTCHANGE_MODE_TIMEOUT = "TIMEOUT"; | |||
private String inputPrompt = null; | |||
private boolean prompting = false; | |||
private int lastCursorPos = -1; | |||
// used while checking if FF has set input prompt as value | |||
private boolean possibleInputError = false; | |||
public VTextField() { | |||
this(DOM.createInputText()); | |||
setStyleName(CLASSNAME); | |||
} | |||
protected VTextField(Element node) { | |||
super(node); | |||
setStyleName(CLASSNAME); | |||
addChangeHandler(this); | |||
if (BrowserInfo.get().isIE() || BrowserInfo.get().isFirefox()) { | |||
addKeyDownHandler(this); | |||
} | |||
addFocusHandler(this); | |||
addBlurHandler(this); | |||
} | |||
/** | |||
* For internal use only. May be removed or replaced in the future. | |||
* <p> | |||
* TODO When GWT adds ONCUT, add it there and remove workaround. See | |||
* http://code.google.com/p/google-web-toolkit/issues/detail?id=4030 | |||
* <p> | |||
* Also note that the cut/paste are not totally crossbrowsers compatible. | |||
* E.g. in Opera mac works via context menu, but on via File->Paste/Cut. | |||
* Opera might need the polling method for 100% working textchanceevents. | |||
* Eager polling for a change is bit dum and heavy operation, so I guess we | |||
* should first try to survive without. | |||
*/ | |||
public static final int TEXTCHANGE_EVENTS = Event.ONPASTE | Event.KEYEVENTS | |||
| Event.ONMOUSEUP; | |||
@Override | |||
public void onBrowserEvent(Event event) { | |||
super.onBrowserEvent(event); | |||
if (listenTextChangeEvents | |||
&& (event.getTypeInt() & TEXTCHANGE_EVENTS) == event | |||
.getTypeInt()) { | |||
deferTextChangeEvent(); | |||
} | |||
} | |||
/* | |||
* TODO optimize this so that only changes are sent + make the value change | |||
* event just a flag that moves the current text to value | |||
*/ | |||
private String lastTextChangeString = null; | |||
private String getLastCommunicatedString() { | |||
return lastTextChangeString; | |||
} | |||
private void communicateTextValueToServer() { | |||
String text = getText(); | |||
if (prompting) { | |||
// Input prompt visible, text is actually "" | |||
text = ""; | |||
} | |||
if (!text.equals(getLastCommunicatedString())) { | |||
if (valueBeforeEditIsSynced && text.equals(valueBeforeEdit)) { | |||
/* | |||
* Value change for the current text has been enqueued since the | |||
* last text change event was sent, but we can't know that it | |||
* has been sent to the server. Ensure that all pending changes | |||
* are sent now. Sending a value change without a text change | |||
* will simulate a TextChangeEvent on the server. | |||
*/ | |||
client.sendPendingVariableChanges(); | |||
} else { | |||
// Default case - just send an immediate text change message | |||
client.updateVariable(paintableId, | |||
TextFieldConstants.VAR_CUR_TEXT, text, true); | |||
// Shouldn't investigate valueBeforeEdit to avoid duplicate text | |||
// change events as the states are not in sync any more | |||
valueBeforeEditIsSynced = false; | |||
} | |||
lastTextChangeString = text; | |||
} | |||
} | |||
private Timer textChangeEventTrigger = new Timer() { | |||
@Override | |||
public void run() { | |||
if (isAttached()) { | |||
updateCursorPosition(); | |||
communicateTextValueToServer(); | |||
scheduled = false; | |||
} | |||
} | |||
}; | |||
private boolean scheduled = false; | |||
/** For internal use only. May be removed or replaced in the future. */ | |||
public boolean listenTextChangeEvents; | |||
/** For internal use only. May be removed or replaced in the future. */ | |||
public String textChangeEventMode; | |||
public int textChangeEventTimeout; | |||
private void deferTextChangeEvent() { | |||
if (textChangeEventMode.equals(TEXTCHANGE_MODE_TIMEOUT) && scheduled) { | |||
return; | |||
} else { | |||
textChangeEventTrigger.cancel(); | |||
} | |||
textChangeEventTrigger.schedule(getTextChangeEventTimeout()); | |||
scheduled = true; | |||
} | |||
private int getTextChangeEventTimeout() { | |||
return textChangeEventTimeout; | |||
} | |||
@Override | |||
public void setReadOnly(boolean readOnly) { | |||
boolean wasReadOnly = isReadOnly(); | |||
if (readOnly) { | |||
setTabIndex(-1); | |||
} else if (wasReadOnly && !readOnly && getTabIndex() == -1) { | |||
/* | |||
* Need to manually set tab index to 0 since server will not send | |||
* the tab index if it is 0. | |||
*/ | |||
setTabIndex(0); | |||
} | |||
super.setReadOnly(readOnly); | |||
} | |||
/** For internal use only. May be removed or replaced in the future. */ | |||
public void updateFieldContent(final String text) { | |||
setPrompting(inputPrompt != null && focusedTextField != this | |||
&& (text.equals(""))); | |||
String fieldValue; | |||
if (prompting) { | |||
fieldValue = isReadOnly() ? "" : inputPrompt; | |||
addStyleDependentName(CLASSNAME_PROMPT); | |||
} else { | |||
fieldValue = text; | |||
removeStyleDependentName(CLASSNAME_PROMPT); | |||
} | |||
setText(fieldValue); | |||
lastTextChangeString = valueBeforeEdit = text; | |||
valueBeforeEditIsSynced = true; | |||
} | |||
protected void onCut() { | |||
if (listenTextChangeEvents) { | |||
deferTextChangeEvent(); | |||
} | |||
} | |||
/** For internal use only. May be removed or replaced in the future. */ | |||
public native void attachCutEventListener(Element el) | |||
/*-{ | |||
var me = this; | |||
el.oncut = $entry(function() { | |||
me.@com.vaadin.client.ui.VTextField::onCut()(); | |||
}); | |||
}-*/; | |||
protected native void detachCutEventListener(Element el) | |||
/*-{ | |||
el.oncut = null; | |||
}-*/; | |||
private void onDrop() { | |||
if (focusedTextField == this) { | |||
return; | |||
} | |||
updateText(false); | |||
} | |||
private void updateText(boolean blurred) { | |||
String text = getText(); | |||
setPrompting(inputPrompt != null && (text == null || text.isEmpty())); | |||
if (prompting) { | |||
setText(isReadOnly() ? "" : inputPrompt); | |||
if (blurred) { | |||
addStyleDependentName(CLASSNAME_PROMPT); | |||
} | |||
} | |||
valueChange(blurred); | |||
} | |||
private void scheduleOnDropEvent() { | |||
Scheduler.get().scheduleDeferred(new ScheduledCommand() { | |||
@Override | |||
public void execute() { | |||
onDrop(); | |||
} | |||
}); | |||
} | |||
private native void attachDropEventListener(Element el) | |||
/*-{ | |||
var me = this; | |||
el.ondrop = $entry(function() { | |||
me.@com.vaadin.client.ui.VTextField::scheduleOnDropEvent()(); | |||
}); | |||
}-*/; | |||
private native void detachDropEventListener(Element el) | |||
/*-{ | |||
el.ondrop = null; | |||
}-*/; | |||
@Override | |||
protected void onDetach() { | |||
super.onDetach(); | |||
detachCutEventListener(getElement()); | |||
if (focusedTextField == this) { | |||
focusedTextField = null; | |||
} | |||
if (BrowserInfo.get().isFirefox()) { | |||
removeOnInputListener(getElement()); | |||
detachDropEventListener(getElement()); | |||
} | |||
} | |||
@Override | |||
protected void onAttach() { | |||
super.onAttach(); | |||
if (listenTextChangeEvents) { | |||
detachCutEventListener(getElement()); | |||
} | |||
if (BrowserInfo.get().isFirefox()) { | |||
// Workaround for FF setting input prompt as the value if esc is | |||
// pressed while the field is focused and empty (#8051). | |||
addOnInputListener(getElement()); | |||
// Workaround for FF updating component's internal value after | |||
// having drag-and-dropped text from another element (#14056) | |||
attachDropEventListener(getElement()); | |||
} | |||
} | |||
/** For internal use only. May be removed or replaced in the future. */ | |||
public void setMaxLength(int newMaxLength) { | |||
if (newMaxLength == maxLength) { | |||
return; | |||
} | |||
maxLength = newMaxLength; | |||
updateMaxLength(maxLength); | |||
} | |||
/** | |||
* This method is responsible for updating the DOM or otherwise ensuring | |||
* that the given max length is enforced. Called when the max length for the | |||
* field has changed. | |||
* | |||
* @param maxLength | |||
* The new max length | |||
*/ | |||
protected void updateMaxLength(int maxLength) { | |||
public void setMaxLength(int maxLength) { | |||
if (maxLength >= 0) { | |||
getElement().setPropertyInt("maxLength", maxLength); | |||
} else { | |||
getElement().removeAttribute("maxLength"); | |||
} | |||
setMaxLengthToElement(maxLength); | |||
} | |||
protected void setMaxLengthToElement(int newMaxLength) { | |||
if (newMaxLength >= 0) { | |||
getElement().setPropertyInt("maxLength", newMaxLength); | |||
public void setPlaceholder(String placeholder) { | |||
if (placeholder != null) { | |||
getElement().setAttribute("placeholder", placeholder); | |||
} else { | |||
getElement().removeAttribute("maxLength"); | |||
} | |||
} | |||
public int getMaxLength() { | |||
return maxLength; | |||
} | |||
@Override | |||
public void onChange(ChangeEvent event) { | |||
valueChange(false); | |||
} | |||
/** | |||
* Called when the field value might have changed and/or the field was | |||
* blurred. These are combined so the blur event is sent in the same batch | |||
* as a possible value change event (these are often connected). | |||
* | |||
* @param blurred | |||
* true if the field was blurred | |||
*/ | |||
public void valueChange(boolean blurred) { | |||
if (client != null && paintableId != null) { | |||
boolean sendBlurEvent = false; | |||
boolean sendValueChange = false; | |||
if (blurred && client.hasEventListeners(this, EventId.BLUR)) { | |||
sendBlurEvent = true; | |||
client.updateVariable(paintableId, EventId.BLUR, "", false); | |||
} | |||
String newText = prompting ? "" : getText(); | |||
if (newText != null && !newText.equals(valueBeforeEdit)) { | |||
sendValueChange = immediate; | |||
client.updateVariable(paintableId, "text", newText, false); | |||
valueBeforeEdit = newText; | |||
valueBeforeEditIsSynced = true; | |||
} | |||
/* | |||
* also send cursor position, no public api yet but for easier | |||
* extension | |||
*/ | |||
updateCursorPosition(); | |||
if (sendBlurEvent || sendValueChange) { | |||
/* | |||
* Avoid sending text change event as we will simulate it on the | |||
* server side before value change events. | |||
*/ | |||
textChangeEventTrigger.cancel(); | |||
scheduled = false; | |||
client.sendPendingVariableChanges(); | |||
} | |||
} | |||
} | |||
/** | |||
* Updates the cursor position variable if it has changed since the last | |||
* update. | |||
* | |||
* @return true iff the value was updated | |||
*/ | |||
protected boolean updateCursorPosition() { | |||
if (WidgetUtil.isAttachedAndDisplayed(this)) { | |||
int cursorPos = prompting ? 0 : getCursorPos(); | |||
if (lastCursorPos != cursorPos) { | |||
client.updateVariable(paintableId, | |||
TextFieldConstants.VAR_CURSOR, cursorPos, false); | |||
lastCursorPos = cursorPos; | |||
return true; | |||
} | |||
} | |||
return false; | |||
} | |||
private static VTextField focusedTextField; | |||
public static void flushChangesFromFocusedTextField() { | |||
if (focusedTextField != null) { | |||
focusedTextField.onChange(null); | |||
} | |||
} | |||
@Override | |||
public void onFocus(FocusEvent event) { | |||
addStyleDependentName(CLASSNAME_FOCUS); | |||
if (prompting) { | |||
setText(""); | |||
removeStyleDependentName(CLASSNAME_PROMPT); | |||
setPrompting(false); | |||
} | |||
focusedTextField = this; | |||
if (client != null && client.hasEventListeners(this, EventId.FOCUS)) { | |||
client.updateVariable(paintableId, EventId.FOCUS, "", true); | |||
} | |||
} | |||
@Override | |||
public void onBlur(BlurEvent event) { | |||
// this is called twice on Chrome when e.g. changing tab while prompting | |||
// field focused - do not change settings on the second time | |||
if (focusedTextField != this) { | |||
return; | |||
} | |||
removeStyleDependentName(CLASSNAME_FOCUS); | |||
focusedTextField = null; | |||
updateText(true); | |||
} | |||
private void setPrompting(boolean prompting) { | |||
this.prompting = prompting; | |||
} | |||
public void setColumns(int columns) { | |||
if (columns <= 0) { | |||
return; | |||
} | |||
setWidth(columns + "em"); | |||
} | |||
@Override | |||
public void onKeyDown(KeyDownEvent event) { | |||
if (BrowserInfo.get().isIE() | |||
&& event.getNativeKeyCode() == KeyCodes.KEY_ENTER) { | |||
// IE does not send change events when pressing enter in a text | |||
// input so we handle it using a key listener instead | |||
valueChange(false); | |||
} else if (BrowserInfo.get().isFirefox() | |||
&& event.getNativeKeyCode() == KeyCodes.KEY_ESCAPE | |||
&& getText().equals("")) { | |||
// check after onInput event if inputPrompt has appeared as the | |||
// value of the field | |||
possibleInputError = true; | |||
} | |||
} | |||
public void setImmediate(boolean immediate) { | |||
this.immediate = immediate; | |||
} | |||
public void setInputPrompt(String inputPrompt) { | |||
this.inputPrompt = inputPrompt; | |||
} | |||
protected boolean isWordwrap() { | |||
String wrap = getElement().getAttribute("wrap"); | |||
return !"off".equals(wrap); | |||
} | |||
private native void addOnInputListener(Element el) | |||
/*-{ | |||
var self = this; | |||
el.oninput = $entry(function() { | |||
self.@com.vaadin.client.ui.VTextField::checkForInputError()(); | |||
}); | |||
}-*/; | |||
private native void removeOnInputListener(Element el) | |||
/*-{ | |||
el.oninput = null; | |||
}-*/; | |||
private void checkForInputError() { | |||
if (possibleInputError && getText().equals(inputPrompt)) { | |||
setText(""); | |||
getElement().removeAttribute("placeholder"); | |||
} | |||
possibleInputError = false; | |||
} | |||
} |
@@ -34,6 +34,7 @@ import com.vaadin.client.Focusable; | |||
import com.vaadin.client.LocaleNotLoadedException; | |||
import com.vaadin.client.LocaleService; | |||
import com.vaadin.client.VConsole; | |||
import com.vaadin.client.legacy.ui.VLegacyTextField; | |||
import com.vaadin.client.ui.aria.AriaHelper; | |||
import com.vaadin.client.ui.aria.HandlesAriaCaption; | |||
import com.vaadin.client.ui.aria.HandlesAriaInvalid; | |||
@@ -73,8 +74,8 @@ public class VTextualDate extends VDateField implements Field, ChangeHandler, | |||
text.addFocusHandler(new FocusHandler() { | |||
@Override | |||
public void onFocus(FocusEvent event) { | |||
text.addStyleName(VTextField.CLASSNAME + "-" | |||
+ VTextField.CLASSNAME_FOCUS); | |||
text.addStyleName(VLegacyTextField.CLASSNAME + "-" | |||
+ VLegacyTextField.CLASSNAME_FOCUS); | |||
if (prompting) { | |||
text.setText(""); | |||
setPrompting(false); | |||
@@ -93,8 +94,8 @@ public class VTextualDate extends VDateField implements Field, ChangeHandler, | |||
text.addBlurHandler(new BlurHandler() { | |||
@Override | |||
public void onBlur(BlurEvent event) { | |||
text.removeStyleName(VTextField.CLASSNAME + "-" | |||
+ VTextField.CLASSNAME_FOCUS); | |||
text.removeStyleName(VLegacyTextField.CLASSNAME + "-" | |||
+ VLegacyTextField.CLASSNAME_FOCUS); | |||
String value = getText(); | |||
setPrompting(inputPrompt != null | |||
&& (value == null || "".equals(value))); | |||
@@ -119,7 +120,7 @@ public class VTextualDate extends VDateField implements Field, ChangeHandler, | |||
protected void updateStyleNames() { | |||
if (text != null) { | |||
text.setStyleName(VTextField.CLASSNAME); | |||
text.setStyleName(VLegacyTextField.CLASSNAME); | |||
text.addStyleName(getStylePrimaryName() + "-textfield"); | |||
} | |||
} | |||
@@ -367,8 +368,8 @@ public class VTextualDate extends VDateField implements Field, ChangeHandler, | |||
&& (text == null || "".equals(text)) | |||
&& !this.text.getStyleName() | |||
.contains( | |||
VTextField.CLASSNAME + "-" | |||
+ VTextField.CLASSNAME_FOCUS)) { | |||
VLegacyTextField.CLASSNAME + "-" | |||
+ VLegacyTextField.CLASSNAME_FOCUS)) { | |||
text = readonly ? "" : inputPrompt; | |||
setPrompting(true); | |||
} else { |
@@ -43,6 +43,7 @@ import com.vaadin.client.LayoutManager; | |||
import com.vaadin.client.Profiler; | |||
import com.vaadin.client.VConsole; | |||
import com.vaadin.client.WidgetUtil; | |||
import com.vaadin.client.legacy.ui.VLegacyTextField; | |||
import com.vaadin.client.ui.ShortcutActionHandler.ShortcutActionHandlerOwner; | |||
import com.vaadin.client.ui.TouchScrollDelegate.TouchScrollHandler; | |||
import com.vaadin.client.ui.ui.UIConnector; | |||
@@ -415,7 +416,7 @@ public class VUI extends SimplePanel implements ResizeHandler, | |||
// cause some odd issues. Should be replaced with a decent solution, see | |||
// also related BeforeShortcutActionListener interface. Same interface | |||
// might be usable here. | |||
VTextField.flushChangesFromFocusedTextField(); | |||
VLegacyTextField.flushChangesFromFocusedTextField(); | |||
} | |||
private native static void loadAppIdListFromDOM(ArrayList<String> list) |
@@ -28,11 +28,11 @@ import com.google.gwt.user.client.ui.FormPanel; | |||
import com.vaadin.client.ComponentConnector; | |||
import com.vaadin.client.ConnectorHierarchyChangeEvent; | |||
import com.vaadin.client.communication.StateChangeEvent; | |||
import com.vaadin.client.legacy.ui.VLegacyTextField; | |||
import com.vaadin.client.legacy.ui.textfield.LegacyTextFieldConnector; | |||
import com.vaadin.client.ui.AbstractSingleComponentContainerConnector; | |||
import com.vaadin.client.ui.VTextField; | |||
import com.vaadin.client.ui.button.ButtonConnector; | |||
import com.vaadin.client.ui.nativebutton.NativeButtonConnector; | |||
import com.vaadin.client.ui.textfield.TextFieldConnector; | |||
import com.vaadin.shared.Connector; | |||
import com.vaadin.shared.ui.Connect; | |||
import com.vaadin.shared.ui.loginform.LoginFormConstants; | |||
@@ -44,8 +44,8 @@ import com.google.gwt.core.client.Scheduler; | |||
public class LoginFormConnector extends | |||
AbstractSingleComponentContainerConnector { | |||
private VTextField passwordField; | |||
private VTextField userField; | |||
private VLegacyTextField passwordField; | |||
private VLegacyTextField userField; | |||
private LoginFormRpc loginFormRpc; | |||
@Override | |||
@@ -98,9 +98,9 @@ public class LoginFormConnector extends | |||
getResourceUrl(LoginFormConstants.LOGIN_RESOURCE_NAME)); | |||
} | |||
private VTextField configureTextField(Connector connector, String id) { | |||
private VLegacyTextField configureTextField(Connector connector, String id) { | |||
if (connector != null) { | |||
VTextField textField = ((TextFieldConnector) connector).getWidget(); | |||
VLegacyTextField textField = ((LegacyTextFieldConnector) connector).getWidget(); | |||
textField.addKeyDownHandler(new SubmitKeyHandler()); | |||
@@ -20,10 +20,10 @@ import com.vaadin.client.ApplicationConnection; | |||
import com.vaadin.client.Paintable; | |||
import com.vaadin.client.StyleConstants; | |||
import com.vaadin.client.UIDL; | |||
import com.vaadin.client.legacy.ui.VLegacyTextField; | |||
import com.vaadin.client.ui.AbstractFieldConnector; | |||
import com.vaadin.client.ui.VNativeButton; | |||
import com.vaadin.client.ui.VOptionGroupBase; | |||
import com.vaadin.client.ui.VTextField; | |||
import com.vaadin.shared.ui.select.AbstractSelectState; | |||
public abstract class OptionGroupBaseConnector extends AbstractFieldConnector | |||
@@ -65,7 +65,7 @@ public abstract class OptionGroupBaseConnector extends AbstractFieldConnector | |||
getWidget().newItemButton.addClickHandler(getWidget()); | |||
getWidget().newItemButton | |||
.addStyleName(StyleConstants.UI_WIDGET); | |||
getWidget().newItemField = new VTextField(); | |||
getWidget().newItemField = new VLegacyTextField(); | |||
getWidget().newItemField.client = getConnection(); | |||
getWidget().newItemField.paintableId = getConnectorId(); | |||
getWidget().newItemField.addKeyPressHandler(getWidget()); |
@@ -16,13 +16,13 @@ | |||
package com.vaadin.client.ui.passwordfield; | |||
import com.vaadin.client.legacy.ui.textfield.LegacyTextFieldConnector; | |||
import com.vaadin.client.ui.VPasswordField; | |||
import com.vaadin.client.ui.textfield.TextFieldConnector; | |||
import com.vaadin.shared.ui.Connect; | |||
import com.vaadin.ui.PasswordField; | |||
@Connect(PasswordField.class) | |||
public class PasswordFieldConnector extends TextFieldConnector { | |||
public class PasswordFieldConnector extends LegacyTextFieldConnector { | |||
@Override | |||
public VPasswordField getWidget() { |
@@ -20,14 +20,14 @@ import com.google.gwt.dom.client.Element; | |||
import com.google.gwt.event.dom.client.MouseUpEvent; | |||
import com.google.gwt.event.dom.client.MouseUpHandler; | |||
import com.vaadin.client.WidgetUtil.CssSize; | |||
import com.vaadin.client.legacy.ui.textfield.LegacyTextFieldConnector; | |||
import com.vaadin.client.ui.VTextArea; | |||
import com.vaadin.client.ui.textfield.TextFieldConnector; | |||
import com.vaadin.shared.ui.Connect; | |||
import com.vaadin.shared.ui.textarea.TextAreaState; | |||
import com.vaadin.ui.TextArea; | |||
@Connect(TextArea.class) | |||
public class TextAreaConnector extends TextFieldConnector { | |||
public class TextAreaConnector extends LegacyTextFieldConnector { | |||
@Override | |||
public TextAreaState getState() { |
@@ -17,98 +17,90 @@ | |||
package com.vaadin.client.ui.textfield; | |||
import com.google.gwt.core.client.Scheduler; | |||
import com.google.gwt.event.dom.client.ChangeEvent; | |||
import com.google.gwt.event.dom.client.ChangeHandler; | |||
import com.google.gwt.user.client.Command; | |||
import com.google.gwt.user.client.Event; | |||
import com.vaadin.client.ApplicationConnection; | |||
import com.vaadin.client.Paintable; | |||
import com.vaadin.client.UIDL; | |||
import com.vaadin.client.Util; | |||
import com.vaadin.client.ui.AbstractFieldConnector; | |||
import com.vaadin.client.ui.ShortcutActionHandler.BeforeShortcutActionListener; | |||
import com.google.gwt.user.client.Timer; | |||
import com.vaadin.client.annotations.OnStateChange; | |||
import com.vaadin.client.event.InputEvent; | |||
import com.vaadin.client.event.InputHandler; | |||
import com.vaadin.client.ui.AbstractComponentConnector; | |||
import com.vaadin.client.ui.ConnectorFocusAndBlurHandler; | |||
import com.vaadin.client.ui.VTextField; | |||
import com.vaadin.shared.ui.Connect; | |||
import com.vaadin.shared.ui.Connect.LoadStyle; | |||
import com.vaadin.shared.ui.textfield.AbstractTextFieldState; | |||
import com.vaadin.shared.ui.textfield.TextFieldConstants; | |||
import com.vaadin.shared.ui.textfield.TextFieldServerRpc; | |||
import com.vaadin.shared.ui.textfield.TextFieldState; | |||
import com.vaadin.shared.ui.textfield.ValueChangeMode; | |||
import com.vaadin.ui.TextField; | |||
@Connect(value = TextField.class, loadStyle = LoadStyle.EAGER) | |||
public class TextFieldConnector extends AbstractFieldConnector implements | |||
Paintable, BeforeShortcutActionListener { | |||
public class TextFieldConnector extends AbstractComponentConnector { | |||
@Override | |||
public AbstractTextFieldState getState() { | |||
return (AbstractTextFieldState) super.getState(); | |||
} | |||
@Override | |||
public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { | |||
// Save details | |||
getWidget().client = client; | |||
getWidget().paintableId = uidl.getId(); | |||
protected void init() { | |||
ConnectorFocusAndBlurHandler.addHandlers(this); | |||
getWidget().addChangeHandler(new ChangeHandler() { | |||
if (!isRealUpdate(uidl)) { | |||
return; | |||
} | |||
@Override | |||
public void onChange(ChangeEvent event) { | |||
sendValueChange(); | |||
} | |||
}); | |||
getWidget().addDomHandler(new InputHandler() { | |||
getWidget().setReadOnly(isReadOnly()); | |||
getWidget().setInputPrompt(getState().inputPrompt); | |||
getWidget().setMaxLength(getState().maxLength); | |||
getWidget().setImmediate(getState().immediate); | |||
getWidget().listenTextChangeEvents = hasEventListener("ie"); | |||
if (getWidget().listenTextChangeEvents) { | |||
getWidget().textChangeEventMode = uidl | |||
.getStringAttribute(TextFieldConstants.ATTR_TEXTCHANGE_EVENTMODE); | |||
if (getWidget().textChangeEventMode | |||
.equals(TextFieldConstants.TEXTCHANGE_MODE_EAGER)) { | |||
getWidget().textChangeEventTimeout = 1; | |||
} else { | |||
getWidget().textChangeEventTimeout = uidl | |||
.getIntAttribute(TextFieldConstants.ATTR_TEXTCHANGE_TIMEOUT); | |||
if (getWidget().textChangeEventTimeout < 1) { | |||
// Sanitize and allow lazy/timeout with timeout set to 0 to | |||
// work as eager | |||
getWidget().textChangeEventTimeout = 1; | |||
@Override | |||
public void onInput(InputEvent event) { | |||
if (getState().valueChangeMode != ValueChangeMode.BLUR) { | |||
scheduleValueChange(); | |||
} | |||
} | |||
getWidget().sinkEvents(VTextField.TEXTCHANGE_EVENTS); | |||
getWidget().attachCutEventListener(getWidget().getElement()); | |||
} | |||
getWidget().setColumns(getState().columns); | |||
String text = getState().text; | |||
if (text == null) { | |||
text = ""; | |||
} | |||
/* | |||
* We skip the text content update if field has been repainted, but text | |||
* has not been changed (#6588). Additional sanity check verifies there | |||
* is no change in the queue (in which case we count more on the server | |||
* side value). <input> is updated only when it looses focus, so we | |||
* force updating if not focused. Lost focus issue appeared in (#15144) | |||
*/ | |||
if (!(Util.getFocusedElement() == getWidget().getElement()) | |||
|| !uidl.getBooleanAttribute(TextFieldConstants.ATTR_NO_VALUE_CHANGE_BETWEEN_PAINTS) | |||
|| getWidget().valueBeforeEdit == null | |||
|| !text.equals(getWidget().valueBeforeEdit)) { | |||
getWidget().updateFieldContent(text); | |||
} | |||
}, InputEvent.getType()); | |||
} | |||
if (uidl.hasAttribute("selpos")) { | |||
final int pos = uidl.getIntAttribute("selpos"); | |||
final int length = uidl.getIntAttribute("sellen"); | |||
/* | |||
* Gecko defers setting the text so we need to defer the selection. | |||
*/ | |||
private Timer valueChangeTrigger = new Timer() { | |||
@Override | |||
public void run() { | |||
Scheduler.get().scheduleDeferred(new Command() { | |||
@Override | |||
public void execute() { | |||
getWidget().setSelectionRange(pos, length); | |||
sendValueChange(); | |||
} | |||
}); | |||
} | |||
}; | |||
private void scheduleValueChange() { | |||
switch (getState().valueChangeMode) { | |||
case LAZY: | |||
lazyTextChange(); | |||
break; | |||
case TIMEOUT: | |||
timeoutTextChange(); | |||
break; | |||
case EAGER: | |||
eagerTextChange(); | |||
break; | |||
} | |||
} | |||
private void lazyTextChange() { | |||
valueChangeTrigger.schedule(getState().valueChangeTimeout); | |||
} | |||
private void timeoutTextChange() { | |||
if (valueChangeTrigger.isRunning()) | |||
return; | |||
valueChangeTrigger.schedule(getState().valueChangeTimeout); | |||
} | |||
private void eagerTextChange() { | |||
valueChangeTrigger.run(); | |||
} | |||
@Override | |||
public TextFieldState getState() { | |||
return (TextFieldState) super.getState(); | |||
} | |||
@Override | |||
@@ -116,14 +108,46 @@ public class TextFieldConnector extends AbstractFieldConnector implements | |||
return (VTextField) super.getWidget(); | |||
} | |||
@Override | |||
public void onBeforeShortcutAction(Event e) { | |||
flush(); | |||
@OnStateChange("readOnly") | |||
private void updateReadOnly() { | |||
getWidget().setReadOnly(getState().readOnly); | |||
} | |||
@Override | |||
public void flush() { | |||
getWidget().valueChange(false); | |||
@OnStateChange({ "selectionStart", "selectionLength" }) | |||
private void updateSelection() { | |||
if (getState().selectionStart != -1) { | |||
Scheduler.get().scheduleDeferred(new Command() { | |||
@Override | |||
public void execute() { | |||
getWidget().setSelectionRange(getState().selectionStart, | |||
getState().selectionLength); | |||
} | |||
}); | |||
} | |||
} | |||
@OnStateChange("cursorPosition") | |||
private void updateCursorPosition() { | |||
Scheduler.get().scheduleDeferred(new Command() { | |||
@Override | |||
public void execute() { | |||
getWidget().setCursorPos(getState().cursorPosition); | |||
} | |||
}); | |||
} | |||
private boolean hasStateChanged() { | |||
boolean textChanged = !getWidget().getValue().equals(getState().text); | |||
boolean cursorPosChanged = getWidget() | |||
.getCursorPos() != getState().cursorPosition; | |||
return textChanged || cursorPosChanged; | |||
} | |||
private void sendValueChange() { | |||
if (!hasStateChanged()) { | |||
return; | |||
} | |||
getRpcProxy(TextFieldServerRpc.class).setText(getWidget().getValue(), | |||
getWidget().getCursorPos()); | |||
} | |||
} |
@@ -21,20 +21,20 @@ import java.util.EnumSet; | |||
import com.vaadin.data.Item; | |||
import com.vaadin.data.fieldgroup.FieldGroup.BindException; | |||
import com.vaadin.legacy.ui.LegacyAbstractField; | |||
import com.vaadin.legacy.ui.LegacyAbstractTextField; | |||
import com.vaadin.legacy.ui.LegacyCheckBox; | |||
import com.vaadin.legacy.ui.LegacyDateField; | |||
import com.vaadin.legacy.ui.LegacyField; | |||
import com.vaadin.legacy.ui.LegacyInlineDateField; | |||
import com.vaadin.legacy.ui.LegacyPopupDateField; | |||
import com.vaadin.legacy.ui.LegacyTextField; | |||
import com.vaadin.ui.AbstractSelect; | |||
import com.vaadin.ui.AbstractTextField; | |||
import com.vaadin.ui.ComboBox; | |||
import com.vaadin.ui.ListSelect; | |||
import com.vaadin.ui.NativeSelect; | |||
import com.vaadin.ui.OptionGroup; | |||
import com.vaadin.ui.RichTextArea; | |||
import com.vaadin.ui.Table; | |||
import com.vaadin.ui.TextField; | |||
/** | |||
* This class contains a basic implementation for {@link FieldGroupFieldFactory} | |||
@@ -74,9 +74,9 @@ public class DefaultFieldGroupFieldFactory implements FieldGroupFieldFactory { | |||
|| boolean.class.isAssignableFrom(type)) { | |||
return createBooleanField(fieldType); | |||
} | |||
if (AbstractTextField.class.isAssignableFrom(fieldType)) { | |||
if (LegacyAbstractTextField.class.isAssignableFrom(fieldType)) { | |||
return fieldType.cast(createAbstractTextField( | |||
fieldType.asSubclass(AbstractTextField.class))); | |||
fieldType.asSubclass(LegacyAbstractTextField.class))); | |||
} else if (fieldType == RichTextArea.class) { | |||
return fieldType.cast(createRichTextArea()); | |||
} | |||
@@ -104,9 +104,9 @@ public class DefaultFieldGroupFieldFactory implements FieldGroupFieldFactory { | |||
AbstractSelect s = createCompatibleSelect(selectClass); | |||
populateWithEnumData(s, (Class<? extends Enum>) type); | |||
return (T) s; | |||
} else if (AbstractTextField.class.isAssignableFrom(fieldType)) { | |||
} else if (LegacyAbstractTextField.class.isAssignableFrom(fieldType)) { | |||
return (T) createAbstractTextField( | |||
(Class<? extends AbstractTextField>) fieldType); | |||
(Class<? extends LegacyAbstractTextField>) fieldType); | |||
} | |||
return null; | |||
@@ -121,9 +121,9 @@ public class DefaultFieldGroupFieldFactory implements FieldGroupFieldFactory { | |||
} else if (anyField(fieldType) | |||
|| LegacyDateField.class.isAssignableFrom(fieldType)) { | |||
field = new LegacyPopupDateField(); | |||
} else if (AbstractTextField.class.isAssignableFrom(fieldType)) { | |||
} else if (LegacyAbstractTextField.class.isAssignableFrom(fieldType)) { | |||
field = createAbstractTextField( | |||
(Class<? extends AbstractTextField>) fieldType); | |||
(Class<? extends LegacyAbstractTextField>) fieldType); | |||
} else { | |||
return null; | |||
} | |||
@@ -182,18 +182,18 @@ public class DefaultFieldGroupFieldFactory implements FieldGroupFieldFactory { | |||
LegacyCheckBox cb = new LegacyCheckBox(null); | |||
cb.setImmediate(true); | |||
return (T) cb; | |||
} else if (AbstractTextField.class.isAssignableFrom(fieldType)) { | |||
} else if (LegacyAbstractTextField.class.isAssignableFrom(fieldType)) { | |||
return (T) createAbstractTextField( | |||
(Class<? extends AbstractTextField>) fieldType); | |||
(Class<? extends LegacyAbstractTextField>) fieldType); | |||
} | |||
return null; | |||
} | |||
protected <T extends AbstractTextField> T createAbstractTextField( | |||
protected <T extends LegacyAbstractTextField> T createAbstractTextField( | |||
Class<T> fieldType) { | |||
if (fieldType == AbstractTextField.class) { | |||
fieldType = (Class<T>) TextField.class; | |||
if (fieldType == LegacyAbstractTextField.class) { | |||
fieldType = (Class<T>) LegacyTextField.class; | |||
} | |||
try { | |||
T field = fieldType.newInstance(); | |||
@@ -220,8 +220,9 @@ public class DefaultFieldGroupFieldFactory implements FieldGroupFieldFactory { | |||
*/ | |||
protected <T extends LegacyField> T createDefaultField(Class<?> type, | |||
Class<T> fieldType) { | |||
if (fieldType.isAssignableFrom(TextField.class)) { | |||
return fieldType.cast(createAbstractTextField(TextField.class)); | |||
if (fieldType.isAssignableFrom(LegacyTextField.class)) { | |||
return fieldType | |||
.cast(createAbstractTextField(LegacyTextField.class)); | |||
} | |||
return null; | |||
} |
@@ -20,12 +20,12 @@ import java.io.Serializable; | |||
import java.lang.reflect.Method; | |||
import com.vaadin.legacy.ui.LegacyField; | |||
import com.vaadin.legacy.ui.LegacyTextField; | |||
import com.vaadin.legacy.ui.LegacyField.ValueChangeEvent; | |||
import com.vaadin.shared.EventId; | |||
import com.vaadin.shared.communication.FieldRpc.FocusAndBlurServerRpc; | |||
import com.vaadin.ui.Component; | |||
import com.vaadin.ui.Component.Event; | |||
import com.vaadin.ui.TextField; | |||
import com.vaadin.util.ReflectTools; | |||
/** | |||
@@ -192,12 +192,12 @@ public interface FieldEvents { | |||
* The {@link TextChangeNotifier}s implementation may decide when exactly | |||
* TextChangeEvents are fired. TextChangeEvents are not necessary fire for | |||
* example on each key press, but buffered with a small delay. The | |||
* {@link TextField} component supports different modes for triggering | |||
* {@link LegacyTextField} component supports different modes for triggering | |||
* TextChangeEvents. | |||
* | |||
* @see TextChangeListener | |||
* @see TextChangeNotifier | |||
* @see TextField#setTextChangeEventMode(com.vaadin.ui.TextField.TextChangeEventMode) | |||
* @see LegacyTextField#setTextChangeEventMode(com.vaadin.ui.LegacyTextField.TextChangeEventMode) | |||
* @since 6.5 | |||
*/ | |||
public static abstract class TextChangeEvent extends Component.Event { | |||
@@ -240,7 +240,7 @@ public interface FieldEvents { | |||
/** | |||
* An interface implemented by a {@link LegacyField} supporting | |||
* {@link TextChangeEvent}s. An example a {@link TextField} supports | |||
* {@link TextChangeEvent}s. An example a {@link LegacyTextField} supports | |||
* {@link TextChangeListener}s. | |||
*/ | |||
public interface TextChangeNotifier extends Serializable { |
@@ -0,0 +1,814 @@ | |||
/* | |||
* Copyright 2000-2014 Vaadin Ltd. | |||
* | |||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | |||
* use this file except in compliance with the License. You may obtain a copy of | |||
* the License at | |||
* | |||
* http://www.apache.org/licenses/LICENSE-2.0 | |||
* | |||
* Unless required by applicable law or agreed to in writing, software | |||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | |||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | |||
* License for the specific language governing permissions and limitations under | |||
* the License. | |||
*/ | |||
package com.vaadin.legacy.ui; | |||
import java.util.Collection; | |||
import java.util.Map; | |||
import org.jsoup.nodes.Attributes; | |||
import org.jsoup.nodes.Element; | |||
import com.vaadin.event.FieldEvents.BlurEvent; | |||
import com.vaadin.event.FieldEvents.BlurListener; | |||
import com.vaadin.event.FieldEvents.BlurNotifier; | |||
import com.vaadin.event.FieldEvents.FocusEvent; | |||
import com.vaadin.event.FieldEvents.FocusListener; | |||
import com.vaadin.event.FieldEvents.FocusNotifier; | |||
import com.vaadin.event.FieldEvents.TextChangeEvent; | |||
import com.vaadin.event.FieldEvents.TextChangeListener; | |||
import com.vaadin.event.FieldEvents.TextChangeNotifier; | |||
import com.vaadin.server.PaintException; | |||
import com.vaadin.server.PaintTarget; | |||
import com.vaadin.shared.legacy.ui.textfield.LegacyAbstractTextFieldState; | |||
import com.vaadin.shared.legacy.ui.textfield.LegacyTextFieldConstants; | |||
import com.vaadin.ui.LegacyComponent; | |||
import com.vaadin.ui.declarative.DesignAttributeHandler; | |||
import com.vaadin.ui.declarative.DesignContext; | |||
@Deprecated | |||
public abstract class LegacyAbstractTextField | |||
extends LegacyAbstractField<String> implements BlurNotifier, | |||
FocusNotifier, TextChangeNotifier, LegacyComponent { | |||
/** | |||
* Null representation. | |||
*/ | |||
private String nullRepresentation = "null"; | |||
/** | |||
* Is setting to null from non-null value allowed by setting with null | |||
* representation . | |||
*/ | |||
private boolean nullSettingAllowed = false; | |||
/** | |||
* The text content when the last messages to the server was sent. Cleared | |||
* when value is changed. | |||
*/ | |||
private String lastKnownTextContent; | |||
/** | |||
* The position of the cursor when the last message to the server was sent. | |||
*/ | |||
private int lastKnownCursorPosition; | |||
/** | |||
* Flag indicating that a text change event is pending to be triggered. | |||
* Cleared by {@link #setInternalValue(Object)} and when the event is fired. | |||
*/ | |||
private boolean textChangeEventPending; | |||
private boolean isFiringTextChangeEvent = false; | |||
private TextChangeEventMode textChangeEventMode = TextChangeEventMode.LAZY; | |||
private final int DEFAULT_TEXTCHANGE_TIMEOUT = 400; | |||
private int textChangeEventTimeout = DEFAULT_TEXTCHANGE_TIMEOUT; | |||
/** | |||
* Temporarily holds the new selection position. Cleared on paint. | |||
*/ | |||
private int selectionPosition = -1; | |||
/** | |||
* Temporarily holds the new selection length. | |||
*/ | |||
private int selectionLength; | |||
/** | |||
* Flag used to determine whether we are currently handling a state change | |||
* triggered by a user. Used to properly fire text change event before value | |||
* change event triggered by the client side. | |||
*/ | |||
private boolean changingVariables; | |||
protected LegacyAbstractTextField() { | |||
super(); | |||
} | |||
@Override | |||
protected LegacyAbstractTextFieldState getState() { | |||
return (LegacyAbstractTextFieldState) super.getState(); | |||
} | |||
@Override | |||
protected LegacyAbstractTextFieldState getState(boolean markAsDirty) { | |||
return (LegacyAbstractTextFieldState) super.getState(markAsDirty); | |||
} | |||
@Override | |||
public void beforeClientResponse(boolean initial) { | |||
super.beforeClientResponse(initial); | |||
String value = getValue(); | |||
if (value == null) { | |||
value = getNullRepresentation(); | |||
} | |||
getState().text = value; | |||
} | |||
@Override | |||
public void paintContent(PaintTarget target) throws PaintException { | |||
if (selectionPosition != -1) { | |||
target.addAttribute("selpos", selectionPosition); | |||
target.addAttribute("sellen", selectionLength); | |||
selectionPosition = -1; | |||
} | |||
if (hasListeners(TextChangeEvent.class)) { | |||
target.addAttribute( | |||
LegacyTextFieldConstants.ATTR_TEXTCHANGE_EVENTMODE, | |||
getTextChangeEventMode().toString()); | |||
target.addAttribute( | |||
LegacyTextFieldConstants.ATTR_TEXTCHANGE_TIMEOUT, | |||
getTextChangeTimeout()); | |||
if (lastKnownTextContent != null) { | |||
/* | |||
* The field has be repainted for some reason (e.g. caption, | |||
* size, stylename), but the value has not been changed since | |||
* the last text change event. Let the client side know about | |||
* the value the server side knows. Client side may then ignore | |||
* the actual value, depending on its state. | |||
*/ | |||
target.addAttribute( | |||
LegacyTextFieldConstants.ATTR_NO_VALUE_CHANGE_BETWEEN_PAINTS, | |||
true); | |||
} | |||
} | |||
} | |||
@Override | |||
public void changeVariables(Object source, Map<String, Object> variables) { | |||
changingVariables = true; | |||
try { | |||
// Sets the height set by the user when resize the <textarea>. | |||
String newHeight = (String) variables.get("height"); | |||
if (newHeight != null) { | |||
setHeight(newHeight); | |||
} | |||
// Sets the width set by the user when resize the <textarea>. | |||
String newWidth = (String) variables.get("width"); | |||
if (newWidth != null) { | |||
setWidth(newWidth); | |||
} | |||
if (variables.containsKey(LegacyTextFieldConstants.VAR_CURSOR)) { | |||
Integer object = (Integer) variables | |||
.get(LegacyTextFieldConstants.VAR_CURSOR); | |||
lastKnownCursorPosition = object.intValue(); | |||
} | |||
if (variables.containsKey(LegacyTextFieldConstants.VAR_CUR_TEXT)) { | |||
/* | |||
* NOTE, we might want to develop this further so that on a | |||
* value change event the whole text content don't need to be | |||
* sent from the client to server. Just "commit" the value from | |||
* currentText to the value. | |||
*/ | |||
handleInputEventTextChange(variables); | |||
} | |||
// Sets the text | |||
if (variables.containsKey("text") && !isReadOnly()) { | |||
// Only do the setting if the string representation of the value | |||
// has been updated | |||
String newValue = (String) variables.get("text"); | |||
// server side check for max length | |||
if (getMaxLength() != -1 | |||
&& newValue.length() > getMaxLength()) { | |||
newValue = newValue.substring(0, getMaxLength()); | |||
} | |||
final String oldValue = getValue(); | |||
if (newValue != null | |||
&& (oldValue == null || isNullSettingAllowed()) | |||
&& newValue.equals(getNullRepresentation())) { | |||
newValue = null; | |||
} | |||
if (newValue != oldValue | |||
&& (newValue == null || !newValue.equals(oldValue))) { | |||
boolean wasModified = isModified(); | |||
setValue(newValue, true); | |||
// If the modified status changes, or if we have a | |||
// formatter, repaint is needed after all. | |||
if (wasModified != isModified()) { | |||
markAsDirty(); | |||
} | |||
} | |||
} | |||
firePendingTextChangeEvent(); | |||
if (variables.containsKey(FocusEvent.EVENT_ID)) { | |||
fireEvent(new FocusEvent(this)); | |||
} | |||
if (variables.containsKey(BlurEvent.EVENT_ID)) { | |||
fireEvent(new BlurEvent(this)); | |||
} | |||
} finally { | |||
changingVariables = false; | |||
} | |||
} | |||
@Override | |||
public Class<String> getType() { | |||
return String.class; | |||
} | |||
/** | |||
* Gets the null-string representation. | |||
* | |||
* <p> | |||
* The null-valued strings are represented on the user interface by | |||
* replacing the null value with this string. If the null representation is | |||
* set null (not 'null' string), painting null value throws exception. | |||
* </p> | |||
* | |||
* <p> | |||
* The default value is string 'null'. | |||
* </p> | |||
* | |||
* @return the String Textual representation for null strings. | |||
* @see LegacyTextField#isNullSettingAllowed() | |||
*/ | |||
public String getNullRepresentation() { | |||
return nullRepresentation; | |||
} | |||
/** | |||
* Is setting nulls with null-string representation allowed. | |||
* | |||
* <p> | |||
* If this property is true, writing null-representation string to text | |||
* field always sets the field value to real null. If this property is | |||
* false, null setting is not made, but the null values are maintained. | |||
* Maintenance of null-values is made by only converting the textfield | |||
* contents to real null, if the text field matches the null-string | |||
* representation and the current value of the field is null. | |||
* </p> | |||
* | |||
* <p> | |||
* By default this setting is false | |||
* </p> | |||
* | |||
* @return boolean Should the null-string represenation be always converted | |||
* to null-values. | |||
* @see LegacyTextField#getNullRepresentation() | |||
*/ | |||
public boolean isNullSettingAllowed() { | |||
return nullSettingAllowed; | |||
} | |||
/** | |||
* Sets the null-string representation. | |||
* | |||
* <p> | |||
* The null-valued strings are represented on the user interface by | |||
* replacing the null value with this string. If the null representation is | |||
* set null (not 'null' string), painting null value throws exception. | |||
* </p> | |||
* | |||
* <p> | |||
* The default value is string 'null' | |||
* </p> | |||
* | |||
* @param nullRepresentation | |||
* Textual representation for null strings. | |||
* @see LegacyTextField#setNullSettingAllowed(boolean) | |||
*/ | |||
public void setNullRepresentation(String nullRepresentation) { | |||
this.nullRepresentation = nullRepresentation; | |||
markAsDirty(); | |||
} | |||
/** | |||
* Sets the null conversion mode. | |||
* | |||
* <p> | |||
* If this property is true, writing null-representation string to text | |||
* field always sets the field value to real null. If this property is | |||
* false, null setting is not made, but the null values are maintained. | |||
* Maintenance of null-values is made by only converting the textfield | |||
* contents to real null, if the text field matches the null-string | |||
* representation and the current value of the field is null. | |||
* </p> | |||
* | |||
* <p> | |||
* By default this setting is false. | |||
* </p> | |||
* | |||
* @param nullSettingAllowed | |||
* Should the null-string representation always be converted to | |||
* null-values. | |||
* @see LegacyTextField#getNullRepresentation() | |||
*/ | |||
public void setNullSettingAllowed(boolean nullSettingAllowed) { | |||
this.nullSettingAllowed = nullSettingAllowed; | |||
markAsDirty(); | |||
} | |||
@Override | |||
public boolean isEmpty() { | |||
return super.isEmpty() || getValue().length() == 0; | |||
} | |||
/** | |||
* Returns the maximum number of characters in the field. Value -1 is | |||
* considered unlimited. Terminal may however have some technical limits. | |||
* | |||
* @return the maxLength | |||
*/ | |||
public int getMaxLength() { | |||
return getState(false).maxLength; | |||
} | |||
/** | |||
* Sets the maximum number of characters in the field. Value -1 is | |||
* considered unlimited. Terminal may however have some technical limits. | |||
* | |||
* @param maxLength | |||
* the maxLength to set | |||
*/ | |||
public void setMaxLength(int maxLength) { | |||
getState().maxLength = maxLength; | |||
} | |||
/** | |||
* Gets the number of columns in the editor. If the number of columns is set | |||
* 0, the actual number of displayed columns is determined implicitly by the | |||
* adapter. | |||
* | |||
* @return the number of columns in the editor. | |||
*/ | |||
public int getColumns() { | |||
return getState(false).columns; | |||
} | |||
/** | |||
* Sets the number of columns in the editor. If the number of columns is set | |||
* 0, the actual number of displayed columns is determined implicitly by the | |||
* adapter. | |||
* | |||
* @param columns | |||
* the number of columns to set. | |||
*/ | |||
public void setColumns(int columns) { | |||
if (columns < 0) { | |||
columns = 0; | |||
} | |||
getState().columns = columns; | |||
} | |||
/** | |||
* Gets the current input prompt. | |||
* | |||
* @see #setInputPrompt(String) | |||
* @return the current input prompt, or null if not enabled | |||
*/ | |||
public String getInputPrompt() { | |||
return getState(false).inputPrompt; | |||
} | |||
/** | |||
* Sets the input prompt - a textual prompt that is displayed when the field | |||
* would otherwise be empty, to prompt the user for input. | |||
* | |||
* @param inputPrompt | |||
*/ | |||
public void setInputPrompt(String inputPrompt) { | |||
getState().inputPrompt = inputPrompt; | |||
} | |||
/* ** Text Change Events ** */ | |||
private void firePendingTextChangeEvent() { | |||
if (textChangeEventPending && !isFiringTextChangeEvent) { | |||
isFiringTextChangeEvent = true; | |||
textChangeEventPending = false; | |||
try { | |||
fireEvent(new TextChangeEventImpl(this)); | |||
} finally { | |||
isFiringTextChangeEvent = false; | |||
} | |||
} | |||
} | |||
@Override | |||
protected void setInternalValue(String newValue) { | |||
if (changingVariables && !textChangeEventPending) { | |||
/* | |||
* TODO check for possible (minor?) issue (not tested) | |||
* | |||
* -field with e.g. PropertyFormatter. | |||
* | |||
* -TextChangeListener and it changes value. | |||
* | |||
* -if formatter again changes the value, do we get an extra | |||
* simulated text change event ? | |||
*/ | |||
/* | |||
* Fire a "simulated" text change event before value change event if | |||
* change is coming from the client side. | |||
* | |||
* Iff there is both value change and textChangeEvent in same | |||
* variable burst, it is a text field in non immediate mode and the | |||
* text change event "flushed" queued value change event. In this | |||
* case textChangeEventPending flag is already on and text change | |||
* event will be fired after the value change event. | |||
*/ | |||
if (newValue == null && lastKnownTextContent != null | |||
&& !lastKnownTextContent.equals(getNullRepresentation())) { | |||
// Value was changed from something to null representation | |||
lastKnownTextContent = getNullRepresentation(); | |||
textChangeEventPending = true; | |||
} else if (newValue != null | |||
&& !newValue.toString().equals(lastKnownTextContent)) { | |||
// Value was changed to something else than null representation | |||
lastKnownTextContent = newValue.toString(); | |||
textChangeEventPending = true; | |||
} | |||
firePendingTextChangeEvent(); | |||
} | |||
super.setInternalValue(newValue); | |||
} | |||
@Override | |||
public void setValue(String newValue) throws ReadOnlyException { | |||
super.setValue(newValue); | |||
/* | |||
* Make sure w reset lastKnownTextContent field on value change. The | |||
* clearing must happen here as well because TextChangeListener can | |||
* revert the original value. Client must respect the value in this | |||
* case. LegacyAbstractField optimizes value change if the existing | |||
* value is reset. Also we need to force repaint if the flag is on. | |||
*/ | |||
if (lastKnownTextContent != null) { | |||
lastKnownTextContent = null; | |||
markAsDirty(); | |||
} | |||
} | |||
private void handleInputEventTextChange(Map<String, Object> variables) { | |||
/* | |||
* TODO we could vastly optimize the communication of values by using | |||
* some sort of diffs instead of always sending the whole text content. | |||
* Also on value change events we could use the mechanism. | |||
*/ | |||
String object = (String) variables | |||
.get(LegacyTextFieldConstants.VAR_CUR_TEXT); | |||
lastKnownTextContent = object; | |||
textChangeEventPending = true; | |||
} | |||
/** | |||
* Sets the mode how the TextField triggers {@link TextChangeEvent}s. | |||
* | |||
* @param inputEventMode | |||
* the new mode | |||
* | |||
* @see TextChangeEventMode | |||
*/ | |||
public void setTextChangeEventMode(TextChangeEventMode inputEventMode) { | |||
textChangeEventMode = inputEventMode; | |||
markAsDirty(); | |||
} | |||
/** | |||
* @return the mode used to trigger {@link TextChangeEvent}s. | |||
*/ | |||
public TextChangeEventMode getTextChangeEventMode() { | |||
return textChangeEventMode; | |||
} | |||
/** | |||
* Different modes how the TextField can trigger {@link TextChangeEvent}s. | |||
*/ | |||
public enum TextChangeEventMode { | |||
/** | |||
* An event is triggered on each text content change, most commonly key | |||
* press events. | |||
*/ | |||
EAGER, | |||
/** | |||
* Each text change event in the UI causes the event to be communicated | |||
* to the application after a timeout. The length of the timeout can be | |||
* controlled with {@link TextField#setTextChangeTimeout(int)}. Only the | |||
* last input event is reported to the server side if several text | |||
* change events happen during the timeout. | |||
* <p> | |||
* In case of a {@link ValueChangeEvent} the schedule is not kept | |||
* strictly. Before a {@link ValueChangeEvent} a {@link TextChangeEvent} | |||
* is triggered if the text content has changed since the previous | |||
* TextChangeEvent regardless of the schedule. | |||
*/ | |||
TIMEOUT, | |||
/** | |||
* An event is triggered when there is a pause of text modifications. | |||
* The length of the pause can be modified with | |||
* {@link TextField#setTextChangeTimeout(int)}. Like with the | |||
* {@link #TIMEOUT} mode, an event is forced before | |||
* {@link ValueChangeEvent}s, even if the user did not keep a pause | |||
* while entering the text. | |||
* <p> | |||
* This is the default mode. | |||
*/ | |||
LAZY | |||
} | |||
@Override | |||
public void addTextChangeListener(TextChangeListener listener) { | |||
addListener(TextChangeListener.EVENT_ID, TextChangeEvent.class, | |||
listener, TextChangeListener.EVENT_METHOD); | |||
} | |||
/** | |||
* @deprecated As of 7.0, replaced by | |||
* {@link #addTextChangeListener(TextChangeListener)} | |||
**/ | |||
@Deprecated | |||
public void addListener(TextChangeListener listener) { | |||
addTextChangeListener(listener); | |||
} | |||
@Override | |||
public void removeTextChangeListener(TextChangeListener listener) { | |||
removeListener(TextChangeListener.EVENT_ID, TextChangeEvent.class, | |||
listener); | |||
} | |||
/** | |||
* @deprecated As of 7.0, replaced by | |||
* {@link #removeTextChangeListener(TextChangeListener)} | |||
**/ | |||
@Deprecated | |||
public void removeListener(TextChangeListener listener) { | |||
removeTextChangeListener(listener); | |||
} | |||
/** | |||
* The text change timeout modifies how often text change events are | |||
* communicated to the application when {@link #getTextChangeEventMode()} is | |||
* {@link TextChangeEventMode#LAZY} or {@link TextChangeEventMode#TIMEOUT}. | |||
* | |||
* | |||
* @see #getTextChangeEventMode() | |||
* | |||
* @param timeout | |||
* the timeout in milliseconds | |||
*/ | |||
public void setTextChangeTimeout(int timeout) { | |||
textChangeEventTimeout = timeout; | |||
markAsDirty(); | |||
} | |||
/** | |||
* Gets the timeout used to fire {@link TextChangeEvent}s when the | |||
* {@link #getTextChangeEventMode()} is {@link TextChangeEventMode#LAZY} or | |||
* {@link TextChangeEventMode#TIMEOUT}. | |||
* | |||
* @return the timeout value in milliseconds | |||
*/ | |||
public int getTextChangeTimeout() { | |||
return textChangeEventTimeout; | |||
} | |||
public static class TextChangeEventImpl extends TextChangeEvent { | |||
private String curText; | |||
private int cursorPosition; | |||
private TextChangeEventImpl(final LegacyAbstractTextField tf) { | |||
super(tf); | |||
curText = tf.getCurrentTextContent(); | |||
cursorPosition = tf.getCursorPosition(); | |||
} | |||
@Override | |||
public LegacyAbstractTextField getComponent() { | |||
return (LegacyAbstractTextField) super.getComponent(); | |||
} | |||
@Override | |||
public String getText() { | |||
return curText; | |||
} | |||
@Override | |||
public int getCursorPosition() { | |||
return cursorPosition; | |||
} | |||
} | |||
/** | |||
* Gets the current (or the last known) text content in the field. | |||
* <p> | |||
* Note the text returned by this method is not necessary the same that is | |||
* returned by the {@link #getValue()} method. The value is updated when the | |||
* terminal fires a value change event via e.g. blurring the field or by | |||
* pressing enter. The value returned by this method is updated also on | |||
* {@link TextChangeEvent}s. Due to this high dependency to the terminal | |||
* implementation this method is (at least at this point) not published. | |||
* | |||
* @return the text which is currently displayed in the field. | |||
*/ | |||
private String getCurrentTextContent() { | |||
if (lastKnownTextContent != null) { | |||
return lastKnownTextContent; | |||
} else { | |||
Object text = getValue(); | |||
if (text == null) { | |||
return getNullRepresentation(); | |||
} | |||
return text.toString(); | |||
} | |||
} | |||
/** | |||
* Selects all text in the field. | |||
* | |||
* @since 6.4 | |||
*/ | |||
public void selectAll() { | |||
String text = getValue() == null ? "" : getValue().toString(); | |||
setSelectionRange(0, text.length()); | |||
} | |||
/** | |||
* Sets the range of text to be selected. | |||
* | |||
* As a side effect the field will become focused. | |||
* | |||
* @since 6.4 | |||
* | |||
* @param pos | |||
* the position of the first character to be selected | |||
* @param length | |||
* the number of characters to be selected | |||
*/ | |||
public void setSelectionRange(int pos, int length) { | |||
selectionPosition = pos; | |||
selectionLength = length; | |||
focus(); | |||
markAsDirty(); | |||
} | |||
/** | |||
* Sets the cursor position in the field. As a side effect the field will | |||
* become focused. | |||
* | |||
* @since 6.4 | |||
* | |||
* @param pos | |||
* the position for the cursor | |||
*/ | |||
public void setCursorPosition(int pos) { | |||
setSelectionRange(pos, 0); | |||
lastKnownCursorPosition = pos; | |||
} | |||
/** | |||
* Returns the last known cursor position of the field. | |||
* | |||
* <p> | |||
* Note that due to the client server nature or the GWT terminal, Vaadin | |||
* cannot provide the exact value of the cursor position in most situations. | |||
* The value is updated only when the client side terminal communicates to | |||
* TextField, like on {@link ValueChangeEvent}s and {@link TextChangeEvent} | |||
* s. This may change later if a deep push integration is built to Vaadin. | |||
* | |||
* @return the cursor position | |||
*/ | |||
public int getCursorPosition() { | |||
return lastKnownCursorPosition; | |||
} | |||
@Override | |||
public void addFocusListener(FocusListener listener) { | |||
addListener(FocusEvent.EVENT_ID, FocusEvent.class, listener, | |||
FocusListener.focusMethod); | |||
} | |||
/** | |||
* @deprecated As of 7.0, replaced by | |||
* {@link #addFocusListener(FocusListener)} | |||
**/ | |||
@Deprecated | |||
public void addListener(FocusListener listener) { | |||
addFocusListener(listener); | |||
} | |||
@Override | |||
public void removeFocusListener(FocusListener listener) { | |||
removeListener(FocusEvent.EVENT_ID, FocusEvent.class, listener); | |||
} | |||
/** | |||
* @deprecated As of 7.0, replaced by | |||
* {@link #removeFocusListener(FocusListener)} | |||
**/ | |||
@Deprecated | |||
public void removeListener(FocusListener listener) { | |||
removeFocusListener(listener); | |||
} | |||
@Override | |||
public void addBlurListener(BlurListener listener) { | |||
addListener(BlurEvent.EVENT_ID, BlurEvent.class, listener, | |||
BlurListener.blurMethod); | |||
} | |||
/** | |||
* @deprecated As of 7.0, replaced by {@link #addBlurListener(BlurListener)} | |||
**/ | |||
@Deprecated | |||
public void addListener(BlurListener listener) { | |||
addBlurListener(listener); | |||
} | |||
@Override | |||
public void removeBlurListener(BlurListener listener) { | |||
removeListener(BlurEvent.EVENT_ID, BlurEvent.class, listener); | |||
} | |||
/** | |||
* @deprecated As of 7.0, replaced by | |||
* {@link #removeBlurListener(BlurListener)} | |||
**/ | |||
@Deprecated | |||
public void removeListener(BlurListener listener) { | |||
removeBlurListener(listener); | |||
} | |||
/* | |||
* (non-Javadoc) | |||
* | |||
* @see com.vaadin.ui.AbstractField#readDesign(org.jsoup.nodes.Element , | |||
* com.vaadin.ui.declarative.DesignContext) | |||
*/ | |||
@Override | |||
public void readDesign(Element design, DesignContext designContext) { | |||
super.readDesign(design, designContext); | |||
Attributes attr = design.attributes(); | |||
if (attr.hasKey("maxlength")) { | |||
setMaxLength(DesignAttributeHandler.readAttribute("maxlength", attr, | |||
Integer.class)); | |||
} | |||
} | |||
/* | |||
* (non-Javadoc) | |||
* | |||
* @see com.vaadin.ui.AbstractField#getCustomAttributes() | |||
*/ | |||
@Override | |||
protected Collection<String> getCustomAttributes() { | |||
Collection<String> customAttributes = super.getCustomAttributes(); | |||
customAttributes.add("maxlength"); | |||
customAttributes.add("max-length"); // to prevent this appearing in | |||
// output | |||
customAttributes.add("cursor-position"); | |||
return customAttributes; | |||
} | |||
/* | |||
* (non-Javadoc) | |||
* | |||
* @see com.vaadin.ui.AbstractField#writeDesign(org.jsoup.nodes.Element, | |||
* com.vaadin.ui.declarative.DesignContext) | |||
*/ | |||
@Override | |||
public void writeDesign(Element design, DesignContext designContext) { | |||
super.writeDesign(design, designContext); | |||
LegacyAbstractTextField def = (LegacyAbstractTextField) designContext | |||
.getDefaultInstance(this); | |||
Attributes attr = design.attributes(); | |||
DesignAttributeHandler.writeAttribute("maxlength", attr, getMaxLength(), | |||
def.getMaxLength(), Integer.class); | |||
} | |||
} |
@@ -0,0 +1,151 @@ | |||
/* | |||
* Copyright 2000-2014 Vaadin Ltd. | |||
* | |||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | |||
* use this file except in compliance with the License. You may obtain a copy of | |||
* the License at | |||
* | |||
* http://www.apache.org/licenses/LICENSE-2.0 | |||
* | |||
* Unless required by applicable law or agreed to in writing, software | |||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | |||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | |||
* License for the specific language governing permissions and limitations under | |||
* the License. | |||
*/ | |||
package com.vaadin.legacy.ui; | |||
import org.jsoup.nodes.Attributes; | |||
import org.jsoup.nodes.Element; | |||
import com.vaadin.data.Property; | |||
import com.vaadin.ui.declarative.DesignAttributeHandler; | |||
import com.vaadin.ui.declarative.DesignContext; | |||
/** | |||
* <p> | |||
* A text editor component that can be bound to any bindable Property. The text | |||
* editor supports both multiline and single line modes, default is one-line | |||
* mode. | |||
* </p> | |||
* | |||
* <p> | |||
* Since <code>TextField</code> extends <code>LegacyAbstractField</code> it | |||
* implements the {@link com.vaadin.data.Buffered} interface. A | |||
* <code>TextField</code> is in write-through mode by default, so | |||
* {@link com.vaadin.legacy.ui.LegacyAbstractField#setWriteThrough(boolean)} | |||
* must be called to enable buffering. | |||
* </p> | |||
* | |||
* @author Vaadin Ltd. | |||
* @since 3.0 | |||
*/ | |||
@SuppressWarnings("serial") | |||
@Deprecated | |||
public class LegacyTextField extends LegacyAbstractTextField { | |||
/** | |||
* Constructs an empty <code>TextField</code> with no caption. | |||
*/ | |||
public LegacyTextField() { | |||
clear(); | |||
} | |||
/** | |||
* Constructs an empty <code>TextField</code> with given caption. | |||
* | |||
* @param caption | |||
* the caption <code>String</code> for the editor. | |||
*/ | |||
public LegacyTextField(String caption) { | |||
this(); | |||
setCaption(caption); | |||
} | |||
/** | |||
* Constructs a new <code>TextField</code> that's bound to the specified | |||
* <code>Property</code> and has no caption. | |||
* | |||
* @param dataSource | |||
* the Property to be edited with this editor. | |||
*/ | |||
public LegacyTextField(Property dataSource) { | |||
setPropertyDataSource(dataSource); | |||
} | |||
/** | |||
* Constructs a new <code>TextField</code> that's bound to the specified | |||
* <code>Property</code> and has the given caption <code>String</code>. | |||
* | |||
* @param caption | |||
* the caption <code>String</code> for the editor. | |||
* @param dataSource | |||
* the Property to be edited with this editor. | |||
*/ | |||
public LegacyTextField(String caption, Property dataSource) { | |||
this(dataSource); | |||
setCaption(caption); | |||
} | |||
/** | |||
* Constructs a new <code>TextField</code> with the given caption and | |||
* initial text contents. The editor constructed this way will not be bound | |||
* to a Property unless | |||
* {@link com.vaadin.data.Property.Viewer#setPropertyDataSource(Property)} | |||
* is called to bind it. | |||
* | |||
* @param caption | |||
* the caption <code>String</code> for the editor. | |||
* @param value | |||
* the initial text content of the editor. | |||
*/ | |||
public LegacyTextField(String caption, String value) { | |||
setValue(value); | |||
setCaption(caption); | |||
} | |||
/* | |||
* (non-Javadoc) | |||
* | |||
* @see com.vaadin.ui.AbstractTextField#readDesign(org.jsoup.nodes.Element, | |||
* com.vaadin.ui.declarative.DesignContext) | |||
*/ | |||
@Override | |||
public void readDesign(Element design, DesignContext designContext) { | |||
super.readDesign(design, designContext); | |||
Attributes attr = design.attributes(); | |||
if (attr.hasKey("value")) { | |||
String newFieldValue = DesignAttributeHandler.readAttribute("value", | |||
attr, String.class); | |||
setValue(newFieldValue, false, true); | |||
} | |||
} | |||
/* | |||
* (non-Javadoc) | |||
* | |||
* @see com.vaadin.ui.AbstractTextField#writeDesign(org.jsoup.nodes.Element | |||
* , com.vaadin.ui.declarative.DesignContext) | |||
*/ | |||
@Override | |||
public void writeDesign(Element design, DesignContext designContext) { | |||
super.writeDesign(design, designContext); | |||
LegacyAbstractTextField def = (LegacyAbstractTextField) designContext | |||
.getDefaultInstance(this); | |||
Attributes attr = design.attributes(); | |||
DesignAttributeHandler.writeAttribute("value", attr, getValue(), | |||
def.getValue(), String.class); | |||
} | |||
/* | |||
* (non-Javadoc) | |||
* | |||
* @see com.vaadin.ui.AbstractField#clear() | |||
*/ | |||
@Override | |||
public void clear() { | |||
setValue(""); | |||
} | |||
} |
@@ -1,12 +1,12 @@ | |||
/* | |||
* Copyright 2000-2014 Vaadin Ltd. | |||
* | |||
* | |||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | |||
* use this file except in compliance with the License. You may obtain a copy of | |||
* the License at | |||
* | |||
* | |||
* http://www.apache.org/licenses/LICENSE-2.0 | |||
* | |||
* | |||
* Unless required by applicable law or agreed to in writing, software | |||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | |||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | |||
@@ -17,323 +17,68 @@ | |||
package com.vaadin.ui; | |||
import java.util.Collection; | |||
import java.util.Map; | |||
import org.jsoup.nodes.Attributes; | |||
import org.jsoup.nodes.Element; | |||
import com.vaadin.event.FieldEvents.BlurEvent; | |||
import com.vaadin.event.FieldEvents.BlurListener; | |||
import com.vaadin.event.FieldEvents.BlurNotifier; | |||
import com.vaadin.event.FieldEvents.FocusEvent; | |||
import com.vaadin.event.FieldEvents.FocusListener; | |||
import com.vaadin.event.FieldEvents.FocusNotifier; | |||
import com.vaadin.event.FieldEvents.TextChangeEvent; | |||
import com.vaadin.event.FieldEvents.TextChangeListener; | |||
import com.vaadin.event.FieldEvents.TextChangeNotifier; | |||
import com.vaadin.legacy.ui.LegacyAbstractField; | |||
import com.vaadin.server.PaintException; | |||
import com.vaadin.server.PaintTarget; | |||
import com.vaadin.shared.ui.textfield.AbstractTextFieldState; | |||
import com.vaadin.shared.ui.textfield.TextFieldConstants; | |||
import com.vaadin.event.Registration; | |||
import com.vaadin.shared.ui.textfield.TextFieldServerRpc; | |||
import com.vaadin.shared.ui.textfield.TextFieldState; | |||
import com.vaadin.shared.ui.textfield.ValueChangeMode; | |||
import com.vaadin.ui.declarative.DesignAttributeHandler; | |||
import com.vaadin.ui.declarative.DesignContext; | |||
public abstract class AbstractTextField extends LegacyAbstractField<String> | |||
implements BlurNotifier, FocusNotifier, TextChangeNotifier, | |||
LegacyComponent { | |||
/** | |||
* Null representation. | |||
*/ | |||
private String nullRepresentation = "null"; | |||
/** | |||
* Is setting to null from non-null value allowed by setting with null | |||
* representation . | |||
*/ | |||
private boolean nullSettingAllowed = false; | |||
/** | |||
* The text content when the last messages to the server was sent. Cleared | |||
* when value is changed. | |||
*/ | |||
private String lastKnownTextContent; | |||
/** | |||
* The position of the cursor when the last message to the server was sent. | |||
*/ | |||
private int lastKnownCursorPosition; | |||
/** | |||
* Flag indicating that a text change event is pending to be triggered. | |||
* Cleared by {@link #setInternalValue(Object)} and when the event is fired. | |||
*/ | |||
private boolean textChangeEventPending; | |||
private boolean isFiringTextChangeEvent = false; | |||
private TextChangeEventMode textChangeEventMode = TextChangeEventMode.LAZY; | |||
private final int DEFAULT_TEXTCHANGE_TIMEOUT = 400; | |||
private int textChangeEventTimeout = DEFAULT_TEXTCHANGE_TIMEOUT; | |||
/** | |||
* Temporarily holds the new selection position. Cleared on paint. | |||
*/ | |||
private int selectionPosition = -1; | |||
/** | |||
* Temporarily holds the new selection length. | |||
*/ | |||
private int selectionLength; | |||
/** | |||
* Flag used to determine whether we are currently handling a state change | |||
* triggered by a user. Used to properly fire text change event before value | |||
* change event triggered by the client side. | |||
*/ | |||
private boolean changingVariables; | |||
/** | |||
* Abstract base class for text input components. | |||
* | |||
* @author Vaadin Ltd. | |||
* @since 8.0 | |||
*/ | |||
public abstract class AbstractTextField extends AbstractField<String> { | |||
protected AbstractTextField() { | |||
super(); | |||
} | |||
@Override | |||
protected AbstractTextFieldState getState() { | |||
return (AbstractTextFieldState) super.getState(); | |||
} | |||
registerRpc(new TextFieldServerRpc() { | |||
@Override | |||
protected AbstractTextFieldState getState(boolean markAsDirty) { | |||
return (AbstractTextFieldState) super.getState(markAsDirty); | |||
} | |||
@Override | |||
public void beforeClientResponse(boolean initial) { | |||
super.beforeClientResponse(initial); | |||
String value = getValue(); | |||
if (value == null) { | |||
value = getNullRepresentation(); | |||
} | |||
getState().text = value; | |||
} | |||
@Override | |||
public void paintContent(PaintTarget target) throws PaintException { | |||
if (selectionPosition != -1) { | |||
target.addAttribute("selpos", selectionPosition); | |||
target.addAttribute("sellen", selectionLength); | |||
selectionPosition = -1; | |||
} | |||
if (hasListeners(TextChangeEvent.class)) { | |||
target.addAttribute(TextFieldConstants.ATTR_TEXTCHANGE_EVENTMODE, | |||
getTextChangeEventMode().toString()); | |||
target.addAttribute(TextFieldConstants.ATTR_TEXTCHANGE_TIMEOUT, | |||
getTextChangeTimeout()); | |||
if (lastKnownTextContent != null) { | |||
/* | |||
* The field has be repainted for some reason (e.g. caption, | |||
* size, stylename), but the value has not been changed since | |||
* the last text change event. Let the client side know about | |||
* the value the server side knows. Client side may then ignore | |||
* the actual value, depending on its state. | |||
*/ | |||
target.addAttribute( | |||
TextFieldConstants.ATTR_NO_VALUE_CHANGE_BETWEEN_PAINTS, | |||
true); | |||
} | |||
} | |||
} | |||
@Override | |||
public void changeVariables(Object source, Map<String, Object> variables) { | |||
changingVariables = true; | |||
try { | |||
// Sets the height set by the user when resize the <textarea>. | |||
String newHeight = (String) variables.get("height"); | |||
if (newHeight != null) { | |||
setHeight(newHeight); | |||
} | |||
// Sets the width set by the user when resize the <textarea>. | |||
String newWidth = (String) variables.get("width"); | |||
if (newWidth != null) { | |||
setWidth(newWidth); | |||
} | |||
if (variables.containsKey(TextFieldConstants.VAR_CURSOR)) { | |||
Integer object = (Integer) variables | |||
.get(TextFieldConstants.VAR_CURSOR); | |||
lastKnownCursorPosition = object.intValue(); | |||
@Override | |||
public void blur() { | |||
fireEvent(new BlurEvent(AbstractTextField.this)); | |||
} | |||
if (variables.containsKey(TextFieldConstants.VAR_CUR_TEXT)) { | |||
/* | |||
* NOTE, we might want to develop this further so that on a | |||
* value change event the whole text content don't need to be | |||
* sent from the client to server. Just "commit" the value from | |||
* currentText to the value. | |||
*/ | |||
handleInputEventTextChange(variables); | |||
@Override | |||
public void focus() { | |||
fireEvent(new FocusEvent(AbstractTextField.this)); | |||
} | |||
// Sets the text | |||
if (variables.containsKey("text") && !isReadOnly()) { | |||
// Only do the setting if the string representation of the value | |||
// has been updated | |||
String newValue = (String) variables.get("text"); | |||
// server side check for max length | |||
if (getMaxLength() != -1 | |||
&& newValue.length() > getMaxLength()) { | |||
newValue = newValue.substring(0, getMaxLength()); | |||
} | |||
final String oldValue = getValue(); | |||
if (newValue != null | |||
&& (oldValue == null || isNullSettingAllowed()) | |||
&& newValue.equals(getNullRepresentation())) { | |||
newValue = null; | |||
} | |||
if (newValue != oldValue | |||
&& (newValue == null || !newValue.equals(oldValue))) { | |||
boolean wasModified = isModified(); | |||
setValue(newValue, true); | |||
// If the modified status changes, or if we have a | |||
// formatter, repaint is needed after all. | |||
if (wasModified != isModified()) { | |||
markAsDirty(); | |||
} | |||
} | |||
@Override | |||
public void setText(String text, int cursorPosition) { | |||
getUI().getConnectorTracker() | |||
.getDiffState(AbstractTextField.this).put("text", text); | |||
getUI().getConnectorTracker() | |||
.getDiffState(AbstractTextField.this) | |||
.put("cursorPosition", cursorPosition); | |||
getState(false).cursorPosition = cursorPosition; | |||
setValue(text, true); | |||
} | |||
firePendingTextChangeEvent(); | |||
if (variables.containsKey(FocusEvent.EVENT_ID)) { | |||
fireEvent(new FocusEvent(this)); | |||
} | |||
if (variables.containsKey(BlurEvent.EVENT_ID)) { | |||
fireEvent(new BlurEvent(this)); | |||
} | |||
} finally { | |||
changingVariables = false; | |||
} | |||
}); | |||
} | |||
@Override | |||
public Class<String> getType() { | |||
return String.class; | |||
} | |||
/** | |||
* Gets the null-string representation. | |||
* | |||
* <p> | |||
* The null-valued strings are represented on the user interface by | |||
* replacing the null value with this string. If the null representation is | |||
* set null (not 'null' string), painting null value throws exception. | |||
* </p> | |||
* | |||
* <p> | |||
* The default value is string 'null'. | |||
* </p> | |||
* | |||
* @return the String Textual representation for null strings. | |||
* @see TextField#isNullSettingAllowed() | |||
*/ | |||
public String getNullRepresentation() { | |||
return nullRepresentation; | |||
} | |||
/** | |||
* Is setting nulls with null-string representation allowed. | |||
* | |||
* <p> | |||
* If this property is true, writing null-representation string to text | |||
* field always sets the field value to real null. If this property is | |||
* false, null setting is not made, but the null values are maintained. | |||
* Maintenance of null-values is made by only converting the textfield | |||
* contents to real null, if the text field matches the null-string | |||
* representation and the current value of the field is null. | |||
* </p> | |||
* | |||
* <p> | |||
* By default this setting is false | |||
* </p> | |||
* | |||
* @return boolean Should the null-string represenation be always converted | |||
* to null-values. | |||
* @see TextField#getNullRepresentation() | |||
*/ | |||
public boolean isNullSettingAllowed() { | |||
return nullSettingAllowed; | |||
} | |||
/** | |||
* Sets the null-string representation. | |||
* | |||
* <p> | |||
* The null-valued strings are represented on the user interface by | |||
* replacing the null value with this string. If the null representation is | |||
* set null (not 'null' string), painting null value throws exception. | |||
* </p> | |||
* | |||
* <p> | |||
* The default value is string 'null' | |||
* </p> | |||
* | |||
* @param nullRepresentation | |||
* Textual representation for null strings. | |||
* @see TextField#setNullSettingAllowed(boolean) | |||
*/ | |||
public void setNullRepresentation(String nullRepresentation) { | |||
this.nullRepresentation = nullRepresentation; | |||
markAsDirty(); | |||
} | |||
/** | |||
* Sets the null conversion mode. | |||
* | |||
* <p> | |||
* If this property is true, writing null-representation string to text | |||
* field always sets the field value to real null. If this property is | |||
* false, null setting is not made, but the null values are maintained. | |||
* Maintenance of null-values is made by only converting the textfield | |||
* contents to real null, if the text field matches the null-string | |||
* representation and the current value of the field is null. | |||
* </p> | |||
* | |||
* <p> | |||
* By default this setting is false. | |||
* </p> | |||
* | |||
* @param nullSettingAllowed | |||
* Should the null-string representation always be converted to | |||
* null-values. | |||
* @see TextField#getNullRepresentation() | |||
*/ | |||
public void setNullSettingAllowed(boolean nullSettingAllowed) { | |||
this.nullSettingAllowed = nullSettingAllowed; | |||
markAsDirty(); | |||
} | |||
@Override | |||
public boolean isEmpty() { | |||
return super.isEmpty() || getValue().length() == 0; | |||
public void setValue(String value) { | |||
if (value == null) { | |||
setValue("", false); | |||
} else { | |||
setValue(value, false); | |||
} | |||
} | |||
/** | |||
* Returns the maximum number of characters in the field. Value -1 is | |||
* considered unlimited. Terminal may however have some technical limits. | |||
* | |||
* | |||
* @return the maxLength | |||
*/ | |||
public int getMaxLength() { | |||
@@ -343,7 +88,7 @@ public abstract class AbstractTextField extends LegacyAbstractField<String> | |||
/** | |||
* Sets the maximum number of characters in the field. Value -1 is | |||
* considered unlimited. Terminal may however have some technical limits. | |||
* | |||
* | |||
* @param maxLength | |||
* the maxLength to set | |||
*/ | |||
@@ -352,398 +97,230 @@ public abstract class AbstractTextField extends LegacyAbstractField<String> | |||
} | |||
/** | |||
* Gets the number of columns in the editor. If the number of columns is set | |||
* 0, the actual number of displayed columns is determined implicitly by the | |||
* adapter. | |||
* | |||
* @return the number of columns in the editor. | |||
* Returns the current placeholder text. | |||
* | |||
* @see #setPlaceholder(String) | |||
* @return the placeholder text | |||
*/ | |||
public int getColumns() { | |||
return getState(false).columns; | |||
public String getPlaceholder() { | |||
return getState(false).placeholder; | |||
} | |||
/** | |||
* Sets the number of columns in the editor. If the number of columns is set | |||
* 0, the actual number of displayed columns is determined implicitly by the | |||
* adapter. | |||
* | |||
* @param columns | |||
* the number of columns to set. | |||
* Sets the placeholder text. The placeholder is text that is displayed when | |||
* the field would otherwise be empty, to prompt the user for input. | |||
* | |||
* @param placeholder | |||
* the placeholder text to set | |||
*/ | |||
public void setColumns(int columns) { | |||
if (columns < 0) { | |||
columns = 0; | |||
} | |||
getState().columns = columns; | |||
public void setPlaceholder(String placeholder) { | |||
getState().placeholder = placeholder; | |||
} | |||
/** | |||
* Gets the current input prompt. | |||
* | |||
* @see #setInputPrompt(String) | |||
* @return the current input prompt, or null if not enabled | |||
*/ | |||
public String getInputPrompt() { | |||
return getState(false).inputPrompt; | |||
@Override | |||
public String getValue() { | |||
return getState(false).text; | |||
} | |||
/** | |||
* Sets the input prompt - a textual prompt that is displayed when the field | |||
* would otherwise be empty, to prompt the user for input. | |||
* | |||
* @param inputPrompt | |||
* Selects all text in the field. | |||
*/ | |||
public void setInputPrompt(String inputPrompt) { | |||
getState().inputPrompt = inputPrompt; | |||
} | |||
/* ** Text Change Events ** */ | |||
private void firePendingTextChangeEvent() { | |||
if (textChangeEventPending && !isFiringTextChangeEvent) { | |||
isFiringTextChangeEvent = true; | |||
textChangeEventPending = false; | |||
try { | |||
fireEvent(new TextChangeEventImpl(this)); | |||
} finally { | |||
isFiringTextChangeEvent = false; | |||
} | |||
} | |||
} | |||
@Override | |||
protected void setInternalValue(String newValue) { | |||
if (changingVariables && !textChangeEventPending) { | |||
/* | |||
* TODO check for possible (minor?) issue (not tested) | |||
* | |||
* -field with e.g. PropertyFormatter. | |||
* | |||
* -TextChangeListener and it changes value. | |||
* | |||
* -if formatter again changes the value, do we get an extra | |||
* simulated text change event ? | |||
*/ | |||
/* | |||
* Fire a "simulated" text change event before value change event if | |||
* change is coming from the client side. | |||
* | |||
* Iff there is both value change and textChangeEvent in same | |||
* variable burst, it is a text field in non immediate mode and the | |||
* text change event "flushed" queued value change event. In this | |||
* case textChangeEventPending flag is already on and text change | |||
* event will be fired after the value change event. | |||
*/ | |||
if (newValue == null && lastKnownTextContent != null | |||
&& !lastKnownTextContent.equals(getNullRepresentation())) { | |||
// Value was changed from something to null representation | |||
lastKnownTextContent = getNullRepresentation(); | |||
textChangeEventPending = true; | |||
} else if (newValue != null | |||
&& !newValue.toString().equals(lastKnownTextContent)) { | |||
// Value was changed to something else than null representation | |||
lastKnownTextContent = newValue.toString(); | |||
textChangeEventPending = true; | |||
} | |||
firePendingTextChangeEvent(); | |||
} | |||
super.setInternalValue(newValue); | |||
} | |||
@Override | |||
public void setValue(String newValue) throws ReadOnlyException { | |||
super.setValue(newValue); | |||
/* | |||
* Make sure w reset lastKnownTextContent field on value change. The | |||
* clearing must happen here as well because TextChangeListener can | |||
* revert the original value. Client must respect the value in this | |||
* case. LegacyAbstractField optimizes value change if the existing | |||
* value is reset. Also we need to force repaint if the flag is on. | |||
*/ | |||
if (lastKnownTextContent != null) { | |||
lastKnownTextContent = null; | |||
markAsDirty(); | |||
} | |||
} | |||
private void handleInputEventTextChange(Map<String, Object> variables) { | |||
/* | |||
* TODO we could vastly optimize the communication of values by using | |||
* some sort of diffs instead of always sending the whole text content. | |||
* Also on value change events we could use the mechanism. | |||
*/ | |||
String object = (String) variables.get(TextFieldConstants.VAR_CUR_TEXT); | |||
lastKnownTextContent = object; | |||
textChangeEventPending = true; | |||
public void selectAll() { | |||
setSelection(0, getValue().length()); | |||
} | |||
/** | |||
* Sets the mode how the TextField triggers {@link TextChangeEvent}s. | |||
* | |||
* @param inputEventMode | |||
* the new mode | |||
* | |||
* @see TextChangeEventMode | |||
* Sets the range of text to be selected. | |||
* | |||
* As a side effect the field will become focused. | |||
* | |||
* @param pos | |||
* the position of the first character to be selected | |||
* @param length | |||
* the number of characters to be selected | |||
*/ | |||
public void setTextChangeEventMode(TextChangeEventMode inputEventMode) { | |||
textChangeEventMode = inputEventMode; | |||
markAsDirty(); | |||
public void setSelection(int start, int length) { | |||
getState().selectionStart = start; | |||
getState().selectionLength = length; | |||
focus(); | |||
} | |||
/** | |||
* @return the mode used to trigger {@link TextChangeEvent}s. | |||
* Sets the cursor position in the field. As a side effect the field will | |||
* become focused. | |||
* | |||
* @param pos | |||
* the position for the cursor | |||
*/ | |||
public TextChangeEventMode getTextChangeEventMode() { | |||
return textChangeEventMode; | |||
public void setCursorPosition(int pos) { | |||
getState().cursorPosition = pos; | |||
focus(); | |||
} | |||
/** | |||
* Different modes how the TextField can trigger {@link TextChangeEvent}s. | |||
* Returns the last known cursor position of the field. | |||
* | |||
*/ | |||
public enum TextChangeEventMode { | |||
/** | |||
* An event is triggered on each text content change, most commonly key | |||
* press events. | |||
*/ | |||
EAGER, | |||
/** | |||
* Each text change event in the UI causes the event to be communicated | |||
* to the application after a timeout. The length of the timeout can be | |||
* controlled with {@link TextField#setTextChangeTimeout(int)}. Only the | |||
* last input event is reported to the server side if several text | |||
* change events happen during the timeout. | |||
* <p> | |||
* In case of a {@link ValueChangeEvent} the schedule is not kept | |||
* strictly. Before a {@link ValueChangeEvent} a {@link TextChangeEvent} | |||
* is triggered if the text content has changed since the previous | |||
* TextChangeEvent regardless of the schedule. | |||
*/ | |||
TIMEOUT, | |||
/** | |||
* An event is triggered when there is a pause of text modifications. | |||
* The length of the pause can be modified with | |||
* {@link TextField#setTextChangeTimeout(int)}. Like with the | |||
* {@link #TIMEOUT} mode, an event is forced before | |||
* {@link ValueChangeEvent}s, even if the user did not keep a pause | |||
* while entering the text. | |||
* <p> | |||
* This is the default mode. | |||
*/ | |||
LAZY | |||
} | |||
@Override | |||
public void addTextChangeListener(TextChangeListener listener) { | |||
addListener(TextChangeListener.EVENT_ID, TextChangeEvent.class, | |||
listener, TextChangeListener.EVENT_METHOD); | |||
public int getCursorPosition() { | |||
return getState(false).cursorPosition; | |||
} | |||
@Override | |||
public void removeTextChangeListener(TextChangeListener listener) { | |||
removeListener(TextChangeListener.EVENT_ID, TextChangeEvent.class, | |||
/** | |||
* Adds a {@link FocusListener} to this component, which gets fired when | |||
* this component receives keyboard focus. | |||
* | |||
* @param listener | |||
* the focus listener | |||
* @return a registration for the listener | |||
* | |||
* @see Registration | |||
*/ | |||
public Registration addFocusListener(FocusListener listener) { | |||
addListener(FocusEvent.EVENT_ID, FocusEvent.class, listener, | |||
FocusListener.focusMethod); | |||
return () -> removeListener(FocusEvent.EVENT_ID, FocusEvent.class, | |||
listener); | |||
} | |||
/** | |||
* The text change timeout modifies how often text change events are | |||
* communicated to the application when {@link #getTextChangeEventMode()} is | |||
* {@link TextChangeEventMode#LAZY} or {@link TextChangeEventMode#TIMEOUT}. | |||
* | |||
* | |||
* @see #getTextChangeEventMode() | |||
* | |||
* @param timeout | |||
* the timeout in milliseconds | |||
* Adds a {@link BlurListener} to this component, which gets fired when this | |||
* component loses keyboard focus. | |||
* | |||
* @param listener | |||
* the blur listener | |||
* @return a registration for the listener | |||
* | |||
* @see Registration | |||
*/ | |||
public void setTextChangeTimeout(int timeout) { | |||
textChangeEventTimeout = timeout; | |||
markAsDirty(); | |||
public Registration addBlurListener(BlurListener listener) { | |||
addListener(BlurEvent.EVENT_ID, BlurEvent.class, listener, | |||
BlurListener.blurMethod); | |||
return () -> removeListener(BlurEvent.EVENT_ID, BlurEvent.class, | |||
listener); | |||
} | |||
/** | |||
* Gets the timeout used to fire {@link TextChangeEvent}s when the | |||
* {@link #getTextChangeEventMode()} is {@link TextChangeEventMode#LAZY} or | |||
* {@link TextChangeEventMode#TIMEOUT}. | |||
* | |||
* @return the timeout value in milliseconds | |||
* Gets the number of columns in the editor. If the number of columns is set | |||
* 0, the actual number of displayed columns is determined implicitly by the | |||
* adapter. | |||
* | |||
* @return the number of columns in the editor. | |||
*/ | |||
public int getTextChangeTimeout() { | |||
return textChangeEventTimeout; | |||
} | |||
public static class TextChangeEventImpl extends TextChangeEvent { | |||
private String curText; | |||
private int cursorPosition; | |||
private TextChangeEventImpl(final AbstractTextField tf) { | |||
super(tf); | |||
curText = tf.getCurrentTextContent(); | |||
cursorPosition = tf.getCursorPosition(); | |||
} | |||
@Override | |||
public AbstractTextField getComponent() { | |||
return (AbstractTextField) super.getComponent(); | |||
} | |||
@Override | |||
public String getText() { | |||
return curText; | |||
} | |||
@Override | |||
public int getCursorPosition() { | |||
return cursorPosition; | |||
} | |||
public int getColumns() { | |||
return getState(false).columns; | |||
} | |||
/** | |||
* Gets the current (or the last known) text content in the field. | |||
* <p> | |||
* Note the text returned by this method is not necessary the same that is | |||
* returned by the {@link #getValue()} method. The value is updated when the | |||
* terminal fires a value change event via e.g. blurring the field or by | |||
* pressing enter. The value returned by this method is updated also on | |||
* {@link TextChangeEvent}s. Due to this high dependency to the terminal | |||
* implementation this method is (at least at this point) not published. | |||
* | |||
* @return the text which is currently displayed in the field. | |||
* Sets the number of columns in the editor. If the number of columns is set | |||
* 0, the actual number of displayed columns is determined implicitly by the | |||
* adapter. | |||
* | |||
* @param columns | |||
* the number of columns to set. | |||
*/ | |||
private String getCurrentTextContent() { | |||
if (lastKnownTextContent != null) { | |||
return lastKnownTextContent; | |||
} else { | |||
Object text = getValue(); | |||
if (text == null) { | |||
return getNullRepresentation(); | |||
} | |||
return text.toString(); | |||
public void setColumns(int columns) { | |||
if (columns < 0) { | |||
columns = 0; | |||
} | |||
getState().columns = columns; | |||
} | |||
/** | |||
* Selects all text in the field. | |||
* Sets the mode how the TextField triggers {@link ValueChange}s. | |||
* | |||
* @param mode | |||
* the new mode | |||
* | |||
* @since 6.4 | |||
* @see ValueChangeMode | |||
*/ | |||
public void selectAll() { | |||
String text = getValue() == null ? "" : getValue().toString(); | |||
setSelectionRange(0, text.length()); | |||
public void setValueChangeMode(ValueChangeMode mode) { | |||
getState().valueChangeMode = mode; | |||
} | |||
/** | |||
* Sets the range of text to be selected. | |||
* | |||
* As a side effect the field will become focused. | |||
* | |||
* @since 6.4 | |||
* | |||
* @param pos | |||
* the position of the first character to be selected | |||
* @param length | |||
* the number of characters to be selected | |||
* Returns the currently set {@link ValueChangeMode}. | |||
* | |||
* @return the mode used to trigger {@link ValueChange}s. | |||
* | |||
* @see ValueChangeMode | |||
*/ | |||
public void setSelectionRange(int pos, int length) { | |||
selectionPosition = pos; | |||
selectionLength = length; | |||
focus(); | |||
markAsDirty(); | |||
public ValueChangeMode getValueChangeMode() { | |||
return getState(false).valueChangeMode; | |||
} | |||
/** | |||
* Sets the cursor position in the field. As a side effect the field will | |||
* become focused. | |||
* Sets how often {@link ValueChange}s are triggered when the | |||
* {@link ValueChangeMode} is set to either {@link ValueChangeMode#LAZY} or | |||
* {@link ValueChangeMode#TIMEOUT}. | |||
* | |||
* @since 6.4 | |||
* @param timeout | |||
* timeout in milliseconds, must be greater or equal to 0 | |||
* @throws IllegalArgumentException | |||
* if given timeout is smaller than 0 | |||
* | |||
* @param pos | |||
* the position for the cursor | |||
* @see ValueChangeMode | |||
*/ | |||
public void setCursorPosition(int pos) { | |||
setSelectionRange(pos, 0); | |||
lastKnownCursorPosition = pos; | |||
public void setValueChangeTimeout(int timeout) { | |||
if (timeout < 0) | |||
throw new IllegalArgumentException( | |||
"Timeout must be greater than 0"); | |||
getState().valueChangeTimeout = timeout; | |||
} | |||
/** | |||
* Returns the last known cursor position of the field. | |||
* | |||
* <p> | |||
* Note that due to the client server nature or the GWT terminal, Vaadin | |||
* cannot provide the exact value of the cursor position in most situations. | |||
* The value is updated only when the client side terminal communicates to | |||
* TextField, like on {@link ValueChangeEvent}s and {@link TextChangeEvent} | |||
* s. This may change later if a deep push integration is built to Vaadin. | |||
* | |||
* @return the cursor position | |||
* Returns the currently set timeout, in milliseconds, for how often | |||
* {@link ValueChange}s are triggered if the current {@link ValueChangeMode} | |||
* is set to either {@link ValueChangeMode#LAZY} or | |||
* {@link ValueChangeMode#TIMEOUT}. | |||
* | |||
* @return the timeout in milliseconds of how often {@link ValueChange}s are | |||
* triggered. | |||
*/ | |||
public int getCursorPosition() { | |||
return lastKnownCursorPosition; | |||
public int getValueChangeTimeout() { | |||
return getState(false).valueChangeTimeout; | |||
} | |||
@Override | |||
public void addFocusListener(FocusListener listener) { | |||
addListener(FocusEvent.EVENT_ID, FocusEvent.class, listener, | |||
FocusListener.focusMethod); | |||
public void readDesign(Element design, DesignContext designContext) { | |||
super.readDesign(design, designContext); | |||
Attributes attr = design.attributes(); | |||
if (attr.hasKey("maxlength")) { | |||
setMaxLength(DesignAttributeHandler.readAttribute("maxlength", attr, | |||
Integer.class)); | |||
} | |||
} | |||
@Override | |||
public void removeFocusListener(FocusListener listener) { | |||
removeListener(FocusEvent.EVENT_ID, FocusEvent.class, listener); | |||
protected TextFieldState getState() { | |||
return (TextFieldState) super.getState(); | |||
} | |||
@Override | |||
public void addBlurListener(BlurListener listener) { | |||
addListener(BlurEvent.EVENT_ID, BlurEvent.class, listener, | |||
BlurListener.blurMethod); | |||
protected TextFieldState getState(boolean markAsDirty) { | |||
return (TextFieldState) super.getState(markAsDirty); | |||
} | |||
@Override | |||
public void removeBlurListener(BlurListener listener) { | |||
removeListener(BlurEvent.EVENT_ID, BlurEvent.class, listener); | |||
protected void doSetValue(String value) { | |||
getState().text = value; | |||
} | |||
/* | |||
* (non-Javadoc) | |||
* | |||
* @see com.vaadin.ui.AbstractField#readDesign(org.jsoup.nodes.Element , | |||
* com.vaadin.ui.declarative.DesignContext) | |||
/** | |||
* Clears the value of this field. | |||
*/ | |||
@Override | |||
public void readDesign(Element design, DesignContext designContext) { | |||
super.readDesign(design, designContext); | |||
Attributes attr = design.attributes(); | |||
if (attr.hasKey("maxlength")) { | |||
setMaxLength(DesignAttributeHandler.readAttribute("maxlength", attr, | |||
Integer.class)); | |||
} | |||
public void clear() { | |||
setValue(""); | |||
} | |||
/* | |||
* (non-Javadoc) | |||
* | |||
* @see com.vaadin.ui.AbstractField#getCustomAttributes() | |||
/** | |||
* Checks if the field is empty. | |||
* | |||
* @return true if the field value is an empty string, false otherwise | |||
*/ | |||
@Override | |||
protected Collection<String> getCustomAttributes() { | |||
Collection<String> customAttributes = super.getCustomAttributes(); | |||
customAttributes.add("maxlength"); | |||
customAttributes.add("max-length"); // to prevent this appearing in | |||
// output | |||
customAttributes.add("cursor-position"); | |||
return customAttributes; | |||
public boolean isEmpty() { | |||
return "".equals(getValue()); | |||
} | |||
/* | |||
* (non-Javadoc) | |||
* | |||
* @see com.vaadin.ui.AbstractField#writeDesign(org.jsoup.nodes.Element, | |||
* com.vaadin.ui.declarative.DesignContext) | |||
*/ | |||
@Override | |||
public void writeDesign(Element design, DesignContext designContext) { | |||
super.writeDesign(design, designContext); | |||
@@ -754,4 +331,13 @@ public abstract class AbstractTextField extends LegacyAbstractField<String> | |||
def.getMaxLength(), Integer.class); | |||
} | |||
@Override | |||
protected Collection<String> getCustomAttributes() { | |||
Collection<String> customAttributes = super.getCustomAttributes(); | |||
customAttributes.add("maxlength"); | |||
customAttributes.add("max-length"); // to prevent this appearing in | |||
// output | |||
customAttributes.add("cursor-position"); | |||
return customAttributes; | |||
} | |||
} |
@@ -23,6 +23,7 @@ import com.vaadin.data.Property; | |||
import com.vaadin.legacy.ui.LegacyCheckBox; | |||
import com.vaadin.legacy.ui.LegacyDateField; | |||
import com.vaadin.legacy.ui.LegacyField; | |||
import com.vaadin.legacy.ui.LegacyTextField; | |||
import com.vaadin.shared.util.SharedUtil; | |||
/** | |||
@@ -86,13 +87,13 @@ public class DefaultFieldFactory | |||
/** | |||
* Creates fields based on the property type. | |||
* <p> | |||
* The default field type is {@link TextField}. Other field types generated | |||
* The default field type is {@link LegacyTextField}. Other field types generated | |||
* by this method: | |||
* <p> | |||
* <b>Boolean</b>: {@link CheckBox}.<br/> | |||
* <b>Date</b>: {@link LegacyDateField}(resolution: day).<br/> | |||
* <b>Item</b>: {@link Form}. <br/> | |||
* <b>default field type</b>: {@link TextField}. | |||
* <b>default field type</b>: {@link LegacyTextField}. | |||
* <p> | |||
* | |||
* @param type | |||
@@ -122,7 +123,7 @@ public class DefaultFieldFactory | |||
return new LegacyCheckBox(); | |||
} | |||
return new TextField(); | |||
return new LegacyTextField(); | |||
} | |||
} |
@@ -24,6 +24,7 @@ import java.lang.reflect.Method; | |||
import java.util.HashMap; | |||
import java.util.Map; | |||
import com.vaadin.legacy.ui.LegacyTextField; | |||
import com.vaadin.server.StreamResource; | |||
import com.vaadin.shared.ui.loginform.LoginFormConstants; | |||
import com.vaadin.shared.ui.loginform.LoginFormRpc; | |||
@@ -32,7 +33,7 @@ import com.vaadin.shared.ui.loginform.LoginFormState; | |||
/** | |||
* Login form with auto-completion and auto-fill for all major browsers. You can | |||
* derive from this class and implement the | |||
* {@link #createContent(com.vaadin.ui.TextField, com.vaadin.ui.PasswordField, com.vaadin.ui.Button)} | |||
* {@link #createContent(com.vaadin.legacy.ui.LegacyTextField, com.vaadin.ui.PasswordField, com.vaadin.ui.Button)} | |||
* method to build the layout using the text fields and login button that are | |||
* passed to that method. The supplied components are specially treated so that | |||
* they work with password managers. | |||
@@ -40,7 +41,7 @@ import com.vaadin.shared.ui.loginform.LoginFormState; | |||
* If you need to change the URL as part of the login procedure, call | |||
* {@link #setLoginMode(LoginMode)} with the argument {@link LoginMode#DEFERRED} | |||
* in your implementation of | |||
* {@link #createContent(com.vaadin.ui.TextField, com.vaadin.ui.PasswordField, com.vaadin.ui.Button) | |||
* {@link #createContent(com.vaadin.legacy.ui.LegacyTextField, com.vaadin.ui.PasswordField, com.vaadin.ui.Button) | |||
* createContent}. | |||
* <p> | |||
* To customize the fields or to replace them with your own implementations, you | |||
@@ -140,9 +141,9 @@ public class LoginForm extends AbstractSingleComponentContainer { | |||
* @return the user name field | |||
* @since 7.7 | |||
*/ | |||
protected TextField createUsernameField() { | |||
protected LegacyTextField createUsernameField() { | |||
checkInitialized(); | |||
TextField field = new TextField(getUsernameCaption()); | |||
LegacyTextField field = new LegacyTextField(getUsernameCaption()); | |||
field.focus(); | |||
return field; | |||
} | |||
@@ -284,7 +285,7 @@ public class LoginForm extends AbstractSingleComponentContainer { | |||
* @return content component | |||
* @since 7.7 | |||
*/ | |||
protected Component createContent(TextField userNameField, | |||
protected Component createContent(LegacyTextField userNameField, | |||
PasswordField passwordField, Button loginButton) { | |||
VerticalLayout layout = new VerticalLayout(); | |||
layout.setSpacing(true); | |||
@@ -324,8 +325,8 @@ public class LoginForm extends AbstractSingleComponentContainer { | |||
getLoginButton())); | |||
} | |||
private TextField getUsernameField() { | |||
return (TextField) getState().userNameFieldConnector; | |||
private LegacyTextField getUsernameField() { | |||
return (LegacyTextField) getState().userNameFieldConnector; | |||
} | |||
private PasswordField getPasswordField() { |
@@ -19,6 +19,7 @@ import org.jsoup.nodes.Attributes; | |||
import org.jsoup.nodes.Element; | |||
import com.vaadin.data.Property; | |||
import com.vaadin.legacy.ui.LegacyAbstractTextField; | |||
import com.vaadin.ui.declarative.DesignAttributeHandler; | |||
import com.vaadin.ui.declarative.DesignContext; | |||
@@ -26,7 +27,7 @@ import com.vaadin.ui.declarative.DesignContext; | |||
* A field that is used to enter secret text information like passwords. The | |||
* entered text is not displayed on the screen. | |||
*/ | |||
public class PasswordField extends AbstractTextField { | |||
public class PasswordField extends LegacyAbstractTextField { | |||
/** | |||
* Constructs an empty PasswordField. | |||
@@ -107,7 +108,7 @@ public class PasswordField extends AbstractTextField { | |||
@Override | |||
public void writeDesign(Element design, DesignContext designContext) { | |||
super.writeDesign(design, designContext); | |||
AbstractTextField def = (AbstractTextField) designContext | |||
LegacyAbstractTextField def = (LegacyAbstractTextField) designContext | |||
.getDefaultInstance(this); | |||
Attributes attr = design.attributes(); | |||
DesignAttributeHandler.writeAttribute("value", attr, getValue(), |
@@ -22,6 +22,7 @@ import org.jsoup.nodes.Element; | |||
import com.vaadin.data.Property; | |||
import com.vaadin.legacy.ui.LegacyAbstractField; | |||
import com.vaadin.legacy.ui.LegacyTextField; | |||
import com.vaadin.server.PaintException; | |||
import com.vaadin.server.PaintTarget; | |||
import com.vaadin.shared.ui.textarea.RichTextAreaState; | |||
@@ -30,7 +31,7 @@ import com.vaadin.ui.declarative.DesignContext; | |||
/** | |||
* A simple RichTextArea to edit HTML format text. | |||
* | |||
* Note, that using {@link TextField#setMaxLength(int)} method in | |||
* Note, that using {@link LegacyTextField#setMaxLength(int)} method in | |||
* {@link RichTextArea} may produce unexpected results as formatting is counted | |||
* into length of field. | |||
*/ | |||
@@ -213,7 +214,7 @@ public class RichTextArea extends LegacyAbstractField<String> implements | |||
* </p> | |||
* | |||
* @return the String Textual representation for null strings. | |||
* @see TextField#isNullSettingAllowed() | |||
* @see LegacyTextField#isNullSettingAllowed() | |||
*/ | |||
public String getNullRepresentation() { | |||
return nullRepresentation; | |||
@@ -237,7 +238,7 @@ public class RichTextArea extends LegacyAbstractField<String> implements | |||
* | |||
* @return boolean Should the null-string represenation be always converted | |||
* to null-values. | |||
* @see TextField#getNullRepresentation() | |||
* @see LegacyTextField#getNullRepresentation() | |||
*/ | |||
public boolean isNullSettingAllowed() { | |||
return nullSettingAllowed; | |||
@@ -258,7 +259,7 @@ public class RichTextArea extends LegacyAbstractField<String> implements | |||
* | |||
* @param nullRepresentation | |||
* Textual representation for null strings. | |||
* @see TextField#setNullSettingAllowed(boolean) | |||
* @see LegacyTextField#setNullSettingAllowed(boolean) | |||
*/ | |||
public void setNullRepresentation(String nullRepresentation) { | |||
this.nullRepresentation = nullRepresentation; | |||
@@ -283,7 +284,7 @@ public class RichTextArea extends LegacyAbstractField<String> implements | |||
* @param nullSettingAllowed | |||
* Should the null-string represenation be always converted to | |||
* null-values. | |||
* @see TextField#getNullRepresentation() | |||
* @see LegacyTextField#getNullRepresentation() | |||
*/ | |||
public void setNullSettingAllowed(boolean nullSettingAllowed) { | |||
this.nullSettingAllowed = nullSettingAllowed; |
@@ -19,6 +19,7 @@ package com.vaadin.ui; | |||
import org.jsoup.nodes.Element; | |||
import com.vaadin.data.Property; | |||
import com.vaadin.legacy.ui.LegacyAbstractTextField; | |||
import com.vaadin.shared.ui.textarea.TextAreaState; | |||
import com.vaadin.ui.declarative.DesignContext; | |||
import com.vaadin.ui.declarative.DesignFormatter; | |||
@@ -26,7 +27,7 @@ import com.vaadin.ui.declarative.DesignFormatter; | |||
/** | |||
* A text field that supports multi line editing. | |||
*/ | |||
public class TextArea extends AbstractTextField { | |||
public class TextArea extends LegacyAbstractTextField { | |||
/** | |||
* Constructs an empty TextArea. |
@@ -24,22 +24,10 @@ import com.vaadin.ui.declarative.DesignAttributeHandler; | |||
import com.vaadin.ui.declarative.DesignContext; | |||
/** | |||
* <p> | |||
* A text editor component that can be bound to any bindable Property. The text | |||
* editor supports both multiline and single line modes, default is one-line | |||
* mode. | |||
* </p> | |||
* | |||
* <p> | |||
* Since <code>TextField</code> extends <code>LegacyAbstractField</code> it implements | |||
* the {@link com.vaadin.data.Buffered} interface. A <code>TextField</code> is | |||
* in write-through mode by default, so | |||
* {@link com.vaadin.legacy.ui.LegacyAbstractField#setWriteThrough(boolean)} must be called | |||
* to enable buffering. | |||
* </p> | |||
* A component for editing textual data that fits on a single line. For a | |||
* multi-line textarea, see the {@link TextArea} component. | |||
* | |||
* @author Vaadin Ltd. | |||
* @since 3.0 | |||
*/ | |||
@SuppressWarnings("serial") | |||
public class TextField extends AbstractTextField { | |||
@@ -62,31 +50,6 @@ public class TextField extends AbstractTextField { | |||
setCaption(caption); | |||
} | |||
/** | |||
* Constructs a new <code>TextField</code> that's bound to the specified | |||
* <code>Property</code> and has no caption. | |||
* | |||
* @param dataSource | |||
* the Property to be edited with this editor. | |||
*/ | |||
public TextField(Property dataSource) { | |||
setPropertyDataSource(dataSource); | |||
} | |||
/** | |||
* Constructs a new <code>TextField</code> that's bound to the specified | |||
* <code>Property</code> and has the given caption <code>String</code>. | |||
* | |||
* @param caption | |||
* the caption <code>String</code> for the editor. | |||
* @param dataSource | |||
* the Property to be edited with this editor. | |||
*/ | |||
public TextField(String caption, Property dataSource) { | |||
this(dataSource); | |||
setCaption(caption); | |||
} | |||
/** | |||
* Constructs a new <code>TextField</code> with the given caption and | |||
* initial text contents. The editor constructed this way will not be bound | |||
@@ -104,29 +67,17 @@ public class TextField extends AbstractTextField { | |||
setCaption(caption); | |||
} | |||
/* | |||
* (non-Javadoc) | |||
* | |||
* @see com.vaadin.ui.AbstractTextField#readDesign(org.jsoup.nodes.Element, | |||
* com.vaadin.ui.declarative.DesignContext) | |||
*/ | |||
@Override | |||
public void readDesign(Element design, DesignContext designContext) { | |||
super.readDesign(design, designContext); | |||
Attributes attr = design.attributes(); | |||
if (attr.hasKey("value")) { | |||
String newFieldValue = DesignAttributeHandler.readAttribute( | |||
"value", attr, String.class); | |||
setValue(newFieldValue, false, true); | |||
String text = DesignAttributeHandler.readAttribute("value", attr, | |||
String.class); | |||
doSetValue(text); | |||
} | |||
} | |||
/* | |||
* (non-Javadoc) | |||
* | |||
* @see com.vaadin.ui.AbstractTextField#writeDesign(org.jsoup.nodes.Element | |||
* , com.vaadin.ui.declarative.DesignContext) | |||
*/ | |||
@Override | |||
public void writeDesign(Element design, DesignContext designContext) { | |||
super.writeDesign(design, designContext); | |||
@@ -136,15 +87,4 @@ public class TextField extends AbstractTextField { | |||
DesignAttributeHandler.writeAttribute("value", attr, getValue(), | |||
def.getValue(), String.class); | |||
} | |||
/* | |||
* (non-Javadoc) | |||
* | |||
* @see com.vaadin.ui.AbstractField#clear() | |||
*/ | |||
@Override | |||
public void clear() { | |||
setValue(""); | |||
} | |||
} |
@@ -19,10 +19,10 @@ import java.lang.reflect.Method; | |||
import com.vaadin.data.Property.ValueChangeEvent; | |||
import com.vaadin.data.Property.ValueChangeListener; | |||
import com.vaadin.legacy.ui.LegacyTextField; | |||
import com.vaadin.shared.ui.colorpicker.Color; | |||
import com.vaadin.ui.Component; | |||
import com.vaadin.ui.CssLayout; | |||
import com.vaadin.ui.TextField; | |||
/** | |||
* A component that represents color selection preview within a color picker. | |||
@@ -51,7 +51,7 @@ public class ColorPickerPreview extends CssLayout implements ColorSelector, | |||
private Color color; | |||
/** The field. */ | |||
private final TextField field; | |||
private final LegacyTextField field; | |||
/** The old value. */ | |||
private String oldValue; | |||
@@ -59,7 +59,7 @@ public class ColorPickerPreview extends CssLayout implements ColorSelector, | |||
private ColorPickerPreview() { | |||
setStyleName("v-colorpicker-preview"); | |||
setImmediate(true); | |||
field = new TextField(); | |||
field = new LegacyTextField(); | |||
field.setImmediate(true); | |||
field.setSizeFull(); | |||
field.setStyleName("v-colorpicker-preview-textfield"); |
@@ -18,25 +18,10 @@ import com.vaadin.server.AbstractErrorMessage; | |||
import com.vaadin.server.ErrorMessage; | |||
import com.vaadin.server.UserError; | |||
import com.vaadin.tests.data.bean.Person; | |||
import com.vaadin.ui.AbstractField; | |||
import com.vaadin.ui.TextField; | |||
public class BinderTest { | |||
class TextField extends AbstractField<String> { | |||
String value = ""; | |||
@Override | |||
public String getValue() { | |||
return value; | |||
} | |||
@Override | |||
protected void doSetValue(String value) { | |||
this.value = value; | |||
} | |||
} | |||
private static class StatusBean { | |||
private String status; | |||
@@ -24,13 +24,13 @@ import org.junit.Test; | |||
import com.vaadin.data.fieldgroup.DefaultFieldGroupFieldFactory; | |||
import com.vaadin.legacy.ui.LegacyDateField; | |||
import com.vaadin.legacy.ui.LegacyInlineDateField; | |||
import com.vaadin.legacy.ui.LegacyField; | |||
import com.vaadin.legacy.ui.LegacyInlineDateField; | |||
import com.vaadin.legacy.ui.LegacyPopupDateField; | |||
import com.vaadin.legacy.ui.LegacyTextField; | |||
import com.vaadin.ui.AbstractSelect; | |||
import com.vaadin.ui.ComboBox; | |||
import com.vaadin.ui.ListSelect; | |||
import com.vaadin.ui.TextField; | |||
public class DefaultFieldGroupFieldFactoryTest { | |||
@@ -46,8 +46,8 @@ public class DefaultFieldGroupFieldFactoryTest { | |||
Class<DefaultFieldGroupFieldFactory> clazz = DefaultFieldGroupFieldFactory.class; | |||
Constructor<?>[] constructors = clazz.getConstructors(); | |||
Assert.assertEquals( | |||
"DefaultFieldGroupFieldFactory contains public constructors", | |||
0, constructors.length); | |||
"DefaultFieldGroupFieldFactory contains public constructors", 0, | |||
constructors.length); | |||
} | |||
@Test | |||
@@ -66,23 +66,26 @@ public class DefaultFieldGroupFieldFactoryTest { | |||
@Test | |||
public void testDateGenerationForPopupDateField() { | |||
LegacyField f = fieldFactory.createField(Date.class, LegacyDateField.class); | |||
LegacyField f = fieldFactory.createField(Date.class, | |||
LegacyDateField.class); | |||
Assert.assertNotNull(f); | |||
Assert.assertEquals(LegacyPopupDateField.class, f.getClass()); | |||
} | |||
@Test | |||
public void testDateGenerationForInlineDateField() { | |||
LegacyField f = fieldFactory.createField(Date.class, LegacyInlineDateField.class); | |||
LegacyField f = fieldFactory.createField(Date.class, | |||
LegacyInlineDateField.class); | |||
Assert.assertNotNull(f); | |||
Assert.assertEquals(LegacyInlineDateField.class, f.getClass()); | |||
} | |||
@Test | |||
public void testDateGenerationForTextField() { | |||
LegacyField f = fieldFactory.createField(Date.class, TextField.class); | |||
LegacyField f = fieldFactory.createField(Date.class, | |||
LegacyTextField.class); | |||
Assert.assertNotNull(f); | |||
Assert.assertEquals(TextField.class, f.getClass()); | |||
Assert.assertEquals(LegacyTextField.class, f.getClass()); | |||
} | |||
@Test | |||
@@ -98,22 +101,24 @@ public class DefaultFieldGroupFieldFactoryTest { | |||
@Test | |||
public void testEnumComboBox() { | |||
LegacyField f = fieldFactory.createField(SomeEnum.class, ComboBox.class); | |||
LegacyField f = fieldFactory.createField(SomeEnum.class, | |||
ComboBox.class); | |||
Assert.assertNotNull(f); | |||
Assert.assertEquals(ComboBox.class, f.getClass()); | |||
} | |||
@Test | |||
public void testEnumAnySelect() { | |||
LegacyField f = fieldFactory | |||
.createField(SomeEnum.class, AbstractSelect.class); | |||
LegacyField f = fieldFactory.createField(SomeEnum.class, | |||
AbstractSelect.class); | |||
Assert.assertNotNull(f); | |||
Assert.assertEquals(ListSelect.class, f.getClass()); | |||
} | |||
@Test | |||
public void testEnumAnyField() { | |||
LegacyField f = fieldFactory.createField(SomeEnum.class, LegacyField.class); | |||
LegacyField f = fieldFactory.createField(SomeEnum.class, | |||
LegacyField.class); | |||
Assert.assertNotNull(f); | |||
Assert.assertEquals(ListSelect.class, f.getClass()); | |||
} |
@@ -14,7 +14,7 @@ import com.vaadin.data.Property.Transactional; | |||
import com.vaadin.data.util.BeanItem; | |||
import com.vaadin.data.util.TransactionalPropertyWrapper; | |||
import com.vaadin.legacy.ui.LegacyField; | |||
import com.vaadin.ui.TextField; | |||
import com.vaadin.legacy.ui.LegacyTextField; | |||
public class FieldGroupTest { | |||
@@ -63,7 +63,7 @@ public class FieldGroupTest { | |||
} | |||
}; | |||
group.setItemDataSource(new BeanItem<Bean>(bean)); | |||
TextField field = new TextField(); | |||
LegacyTextField field = new LegacyTextField(); | |||
group.bind(field, "name"); | |||
Property propertyDataSource = field.getPropertyDataSource(); |
@@ -6,7 +6,7 @@ import org.junit.Test; | |||
import com.vaadin.data.fieldgroup.FieldGroup; | |||
import com.vaadin.data.fieldgroup.PropertyId; | |||
import com.vaadin.ui.TextField; | |||
import com.vaadin.legacy.ui.LegacyTextField; | |||
public class ReflectToolsGetSuperFieldTest { | |||
@@ -14,7 +14,7 @@ public class ReflectToolsGetSuperFieldTest { | |||
public void getFieldFromSuperClass() { | |||
class MyClass { | |||
@PropertyId("testProperty") | |||
TextField test = new TextField("This is a test"); | |||
LegacyTextField test = new LegacyTextField("This is a test"); | |||
} | |||
class MySubClass extends MyClass { | |||
// no fields here |
@@ -23,7 +23,7 @@ import java.util.List; | |||
import org.junit.Test; | |||
import com.vaadin.data.fieldgroup.FieldGroup; | |||
import com.vaadin.ui.TextField; | |||
import com.vaadin.legacy.ui.LegacyTextField; | |||
/** | |||
* Test verifying that TransactionalPropertyWrapper removes it's listener from | |||
@@ -63,9 +63,9 @@ public class TransactionalPropertyWrapperTest { | |||
} | |||
} | |||
private final TextField nameField = new TextField("Name"); | |||
private final TextField ageField = new TextField("Age"); | |||
private final TextField unboundField = new TextField("No FieldGroup"); | |||
private final LegacyTextField nameField = new LegacyTextField("Name"); | |||
private final LegacyTextField ageField = new LegacyTextField("Age"); | |||
private final LegacyTextField unboundField = new LegacyTextField("No FieldGroup"); | |||
private final TestingProperty<String> unboundProp = new TestingProperty<String>( | |||
"Hello World"); | |||
private final PropertysetItem item = new PropertysetItem(); |
@@ -25,13 +25,14 @@ import org.junit.Test; | |||
import com.vaadin.data.util.ObjectProperty; | |||
import com.vaadin.legacy.data.util.converter.LegacyConverter; | |||
import com.vaadin.legacy.data.util.converter.LegacyReverseConverter; | |||
import com.vaadin.legacy.ui.LegacyTextField; | |||
import com.vaadin.tests.data.bean.AnotherTestEnum; | |||
import com.vaadin.tests.data.bean.TestEnum; | |||
import com.vaadin.ui.TextField; | |||
public class AnyEnumToStringConverterTest { | |||
public class AnyEnumToStringConverter implements LegacyConverter<Enum, String> { | |||
public class AnyEnumToStringConverter | |||
implements LegacyConverter<Enum, String> { | |||
public AnyEnumToStringConverter() { | |||
} | |||
@@ -99,29 +100,30 @@ public class AnyEnumToStringConverterTest { | |||
public void stringToEnumConversion() { | |||
Assert.assertEquals(TestEnum.TWO, converter.convertToPresentation( | |||
TestEnum.TWO.toString(), TestEnum.class, null)); | |||
Assert.assertEquals(AnotherTestEnum.TWO, converter | |||
.convertToPresentation(AnotherTestEnum.TWO.toString(), | |||
Assert.assertEquals(AnotherTestEnum.TWO, | |||
converter.convertToPresentation(AnotherTestEnum.TWO.toString(), | |||
AnotherTestEnum.class, null)); | |||
} | |||
@Test | |||
public void stringToEnumWithField() { | |||
TextField tf = new TextField(); | |||
LegacyTextField tf = new LegacyTextField(); | |||
tf.setConverter(new LegacyReverseConverter(converter)); | |||
tf.setPropertyDataSource(new ObjectProperty(AnotherTestEnum.TWO)); | |||
Assert.assertEquals(AnotherTestEnum.TWO.toString(), tf.getValue()); | |||
tf.setValue(AnotherTestEnum.ONE.toString()); | |||
Assert.assertEquals(AnotherTestEnum.ONE.toString(), tf.getValue()); | |||
Assert.assertEquals(AnotherTestEnum.ONE, tf.getConvertedValue()); | |||
Assert.assertEquals(AnotherTestEnum.ONE, tf.getPropertyDataSource() | |||
.getValue()); | |||
Assert.assertEquals(AnotherTestEnum.ONE, | |||
tf.getPropertyDataSource().getValue()); | |||
tf.setPropertyDataSource(new ObjectProperty(TestEnum.TWO)); | |||
Assert.assertEquals(TestEnum.TWO.toString(), tf.getValue()); | |||
tf.setValue(TestEnum.ONE.toString()); | |||
Assert.assertEquals(TestEnum.ONE.toString(), tf.getValue()); | |||
Assert.assertEquals(TestEnum.ONE, tf.getConvertedValue()); | |||
Assert.assertEquals(TestEnum.ONE, tf.getPropertyDataSource().getValue()); | |||
Assert.assertEquals(TestEnum.ONE, | |||
tf.getPropertyDataSource().getValue()); | |||
} | |||
} |
@@ -22,13 +22,14 @@ import org.junit.Test; | |||
import com.vaadin.legacy.data.util.converter.LegacyConverter; | |||
import com.vaadin.legacy.data.util.converter.LegacyDefaultConverterFactory; | |||
import com.vaadin.legacy.ui.LegacyTextField; | |||
import com.vaadin.server.VaadinSession; | |||
import com.vaadin.tests.util.AlwaysLockedVaadinSession; | |||
import com.vaadin.ui.TextField; | |||
public class ConverterFactoryTest { | |||
public static class ConvertTo42 implements LegacyConverter<String, Integer> { | |||
public static class ConvertTo42 | |||
implements LegacyConverter<String, Integer> { | |||
@Override | |||
public Integer convertToModel(String value, | |||
@@ -56,7 +57,8 @@ public class ConverterFactoryTest { | |||
} | |||
public static class ConverterFactory42 extends LegacyDefaultConverterFactory { | |||
public static class ConverterFactory42 | |||
extends LegacyDefaultConverterFactory { | |||
@Override | |||
public <PRESENTATION, MODEL> LegacyConverter<PRESENTATION, MODEL> createConverter( | |||
Class<PRESENTATION> presentationType, Class<MODEL> modelType) { | |||
@@ -76,7 +78,7 @@ public class ConverterFactoryTest { | |||
appWithCustomIntegerConverter | |||
.setConverterFactory(new ConverterFactory42()); | |||
TextField tf = new TextField("", "123") { | |||
LegacyTextField tf = new LegacyTextField("", "123") { | |||
@Override | |||
public VaadinSession getSession() { | |||
return appWithCustomIntegerConverter; | |||
@@ -96,7 +98,7 @@ public class ConverterFactoryTest { | |||
.setConverterFactory(new ConverterFactory42()); | |||
VaadinSession.setCurrent(appWithCustomIntegerConverter); | |||
TextField tf = new TextField("", "123"); | |||
LegacyTextField tf = new LegacyTextField("", "123"); | |||
tf.setConverter(Integer.class); | |||
// The application converter always returns 42. Current application is | |||
// null | |||
@@ -111,7 +113,7 @@ public class ConverterFactoryTest { | |||
.setConverterFactory(new ConverterFactory42()); | |||
VaadinSession.setCurrent(new AlwaysLockedVaadinSession(null)); | |||
TextField tf = new TextField("", "123") { | |||
LegacyTextField tf = new LegacyTextField("", "123") { | |||
@Override | |||
public VaadinSession getSession() { | |||
return fieldAppWithCustomIntegerConverter; |
@@ -25,14 +25,14 @@ import org.junit.Test; | |||
import com.vaadin.data.util.ObjectProperty; | |||
import com.vaadin.legacy.data.util.converter.LegacyConverter; | |||
import com.vaadin.legacy.data.util.converter.LegacyReverseConverter; | |||
import com.vaadin.legacy.ui.LegacyTextField; | |||
import com.vaadin.tests.data.bean.AnotherTestEnum; | |||
import com.vaadin.tests.data.bean.TestEnum; | |||
import com.vaadin.ui.TextField; | |||
public class SpecificEnumToStringConverterTest { | |||
public class SpecificEnumToStringConverter implements | |||
LegacyConverter<Enum, String> { | |||
public class SpecificEnumToStringConverter | |||
implements LegacyConverter<Enum, String> { | |||
private Class<? extends Enum> enumClass; | |||
@@ -104,22 +104,22 @@ public class SpecificEnumToStringConverterTest { | |||
@Test | |||
public void stringToEnumConversion() { | |||
Assert.assertEquals(TestEnum.TWO, testEnumConverter | |||
.convertToPresentation(TestEnum.TWO.toString(), TestEnum.class, | |||
null)); | |||
Assert.assertEquals(TestEnum.TWO, | |||
testEnumConverter.convertToPresentation(TestEnum.TWO.toString(), | |||
TestEnum.class, null)); | |||
} | |||
@Test | |||
public void stringToEnumWithField() { | |||
TextField tf = new TextField(); | |||
LegacyTextField tf = new LegacyTextField(); | |||
tf.setConverter(new LegacyReverseConverter(anotherTestEnumConverter)); | |||
tf.setPropertyDataSource(new ObjectProperty(AnotherTestEnum.TWO)); | |||
Assert.assertEquals(AnotherTestEnum.TWO.toString(), tf.getValue()); | |||
tf.setValue(AnotherTestEnum.ONE.toString()); | |||
Assert.assertEquals(AnotherTestEnum.ONE.toString(), tf.getValue()); | |||
Assert.assertEquals(AnotherTestEnum.ONE, tf.getConvertedValue()); | |||
Assert.assertEquals(AnotherTestEnum.ONE, tf.getPropertyDataSource() | |||
.getValue()); | |||
Assert.assertEquals(AnotherTestEnum.ONE, | |||
tf.getPropertyDataSource().getValue()); | |||
} | |||
} |
@@ -19,8 +19,9 @@ import java.io.ByteArrayInputStream; | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
import com.vaadin.legacy.ui.LegacyTextField; | |||
import com.vaadin.ui.AbstractComponent; | |||
import com.vaadin.ui.TextField; | |||
import org.junit.After; | |||
import org.junit.Assert; | |||
import org.junit.Test; |
@@ -15,9 +15,9 @@ | |||
*/ | |||
package com.vaadin.tests.design; | |||
import com.vaadin.legacy.ui.LegacyTextField; | |||
import com.vaadin.ui.Button; | |||
import com.vaadin.ui.NativeButton; | |||
import com.vaadin.ui.TextField; | |||
import com.vaadin.ui.VerticalLayout; | |||
/** | |||
@@ -30,7 +30,7 @@ public class InvalidLayoutTemplate extends VerticalLayout { | |||
private NativeButton secondButton; | |||
private NativeButton yetanotherbutton; // generated based on caption | |||
private Button clickme; // generated based on caption | |||
private TextField shouldNotBeMapped; | |||
private LegacyTextField shouldNotBeMapped; | |||
public NativeButton getFirstButton() { | |||
return firstButton; | |||
@@ -48,7 +48,7 @@ public class InvalidLayoutTemplate extends VerticalLayout { | |||
return clickme; | |||
} | |||
public TextField getShouldNotBeMapped() { | |||
public LegacyTextField getShouldNotBeMapped() { | |||
return shouldNotBeMapped; | |||
} | |||
@@ -15,10 +15,10 @@ | |||
*/ | |||
package com.vaadin.tests.design.designroot; | |||
import com.vaadin.ui.TextField; | |||
import com.vaadin.legacy.ui.LegacyTextField; | |||
public class ExtendedDesignWithAnnotation extends DesignWithAnnotation { | |||
private TextField customField = new TextField(); | |||
private LegacyTextField customField = new LegacyTextField(); | |||
public ExtendedDesignWithAnnotation() { | |||
customField.setInputPrompt("Something"); |
@@ -17,13 +17,13 @@ package com.vaadin.tests.design.designroot; | |||
import com.vaadin.ui.Button.ClickEvent; | |||
import com.vaadin.ui.Button.ClickListener; | |||
import com.vaadin.legacy.ui.LegacyTextField; | |||
import com.vaadin.ui.Notification; | |||
import com.vaadin.ui.TextField; | |||
public class ExtendedDesignWithEmptyAnnotation extends | |||
DesignWithEmptyAnnotation { | |||
private TextField customField = new TextField(); | |||
private LegacyTextField customField = new LegacyTextField(); | |||
public ExtendedDesignWithEmptyAnnotation() { | |||
super(); |
@@ -4,7 +4,7 @@ import org.junit.Test; | |||
import com.vaadin.data.Property.ValueChangeEvent; | |||
import com.vaadin.data.Property.ValueChangeListener; | |||
import com.vaadin.ui.TextField; | |||
import com.vaadin.legacy.ui.LegacyTextField; | |||
public class EventRouterTest { | |||
@@ -12,7 +12,7 @@ public class EventRouterTest { | |||
@Test | |||
public void testAddInEventListener() { | |||
final TextField tf = new TextField(); | |||
final LegacyTextField tf = new LegacyTextField(); | |||
final ValueChangeListener outer = new ValueChangeListener() { | |||
@@ -17,10 +17,10 @@ package com.vaadin.tests.server; | |||
import org.junit.Test; | |||
import com.vaadin.legacy.ui.LegacyTextField; | |||
import com.vaadin.server.AbstractClientConnector; | |||
import com.vaadin.server.AbstractExtension; | |||
import com.vaadin.ui.Label; | |||
import com.vaadin.ui.TextField; | |||
public class ExtensionTest { | |||
@@ -33,7 +33,7 @@ public class ExtensionTest { | |||
@Test(expected = IllegalArgumentException.class) | |||
public void testRemoveExtensionFromWrongConnector() { | |||
Label l = new Label(); | |||
TextField t = new TextField(); | |||
LegacyTextField t = new LegacyTextField(); | |||
t.removeExtension(new DummyExtension(l)); | |||
} | |||
@@ -7,23 +7,23 @@ import org.junit.Test; | |||
import com.vaadin.data.util.MethodProperty; | |||
import com.vaadin.legacy.data.Validator.InvalidValueException; | |||
import com.vaadin.legacy.data.util.converter.LegacyStringToIntegerConverter; | |||
import com.vaadin.legacy.data.util.converter.LegacyConverter.ConversionException; | |||
import com.vaadin.legacy.data.util.converter.LegacyStringToIntegerConverter; | |||
import com.vaadin.legacy.ui.LegacyTextField; | |||
import com.vaadin.tests.data.bean.Address; | |||
import com.vaadin.tests.data.bean.Country; | |||
import com.vaadin.tests.data.bean.Person; | |||
import com.vaadin.tests.data.bean.Sex; | |||
import com.vaadin.ui.TextField; | |||
public class AbsFieldValueConversionErrorTest { | |||
Person paulaBean = new Person("Paula", "Brilliant", "paula@brilliant.com", | |||
34, Sex.FEMALE, new Address("Paula street 1", 12345, "P-town", | |||
Country.FINLAND)); | |||
34, Sex.FEMALE, | |||
new Address("Paula street 1", 12345, "P-town", Country.FINLAND)); | |||
@Test | |||
public void testValidateConversionErrorParameters() { | |||
TextField tf = new TextField(); | |||
LegacyTextField tf = new LegacyTextField(); | |||
tf.setConverter(new LegacyStringToIntegerConverter()); | |||
tf.setPropertyDataSource(new MethodProperty<String>(paulaBean, "age")); | |||
tf.setConversionError("(Type: {0}) Converter exception message: {1}"); | |||
@@ -41,7 +41,7 @@ public class AbsFieldValueConversionErrorTest { | |||
@Test | |||
public void testConvertToModelConversionErrorParameters() { | |||
TextField tf = new TextField(); | |||
LegacyTextField tf = new LegacyTextField(); | |||
tf.setConverter(new LegacyStringToIntegerConverter()); | |||
tf.setPropertyDataSource(new MethodProperty<String>(paulaBean, "age")); | |||
tf.setConversionError("(Type: {0}) Converter exception message: {1}"); | |||
@@ -59,7 +59,7 @@ public class AbsFieldValueConversionErrorTest { | |||
@Test | |||
public void testNullConversionMessages() { | |||
TextField tf = new TextField(); | |||
LegacyTextField tf = new LegacyTextField(); | |||
tf.setConverter(new LegacyStringToIntegerConverter()); | |||
tf.setPropertyDataSource(new MethodProperty<String>(paulaBean, "age")); | |||
tf.setConversionError(null); | |||
@@ -75,7 +75,7 @@ public class AbsFieldValueConversionErrorTest { | |||
@Test | |||
public void testDefaultConversionErrorMessage() { | |||
TextField tf = new TextField(); | |||
LegacyTextField tf = new LegacyTextField(); | |||
tf.setConverter(new LegacyStringToIntegerConverter()); | |||
tf.setPropertyDataSource(new MethodProperty<String>(paulaBean, "age")); | |||
tf.setValue("abc"); |
@@ -13,19 +13,19 @@ import com.vaadin.data.util.ObjectProperty; | |||
import com.vaadin.legacy.data.util.converter.LegacyConverter; | |||
import com.vaadin.legacy.data.util.converter.LegacyConverter.ConversionException; | |||
import com.vaadin.legacy.data.util.converter.LegacyStringToIntegerConverter; | |||
import com.vaadin.legacy.ui.LegacyTextField; | |||
import com.vaadin.server.VaadinSession; | |||
import com.vaadin.tests.data.bean.Address; | |||
import com.vaadin.tests.data.bean.Country; | |||
import com.vaadin.tests.data.bean.Person; | |||
import com.vaadin.tests.data.bean.Sex; | |||
import com.vaadin.tests.util.AlwaysLockedVaadinSession; | |||
import com.vaadin.ui.TextField; | |||
public class AbsFieldValueConversionsTest { | |||
Person paulaBean = new Person("Paula", "Brilliant", "paula@brilliant.com", | |||
34, Sex.FEMALE, new Address("Paula street 1", 12345, "P-town", | |||
Country.FINLAND)); | |||
34, Sex.FEMALE, | |||
new Address("Paula street 1", 12345, "P-town", Country.FINLAND)); | |||
/** | |||
* Java uses a non-breaking space (ascii 160) instead of space when | |||
@@ -35,9 +35,9 @@ public class AbsFieldValueConversionsTest { | |||
@Test | |||
public void testWithoutConversion() { | |||
TextField tf = new TextField(); | |||
tf.setPropertyDataSource(new MethodProperty<String>(paulaBean, | |||
"firstName")); | |||
LegacyTextField tf = new LegacyTextField(); | |||
tf.setPropertyDataSource( | |||
new MethodProperty<String>(paulaBean, "firstName")); | |||
assertEquals("Paula", tf.getValue()); | |||
assertEquals("Paula", tf.getPropertyDataSource().getValue()); | |||
tf.setValue("abc"); | |||
@@ -49,7 +49,7 @@ public class AbsFieldValueConversionsTest { | |||
@Test | |||
public void testNonmodifiedBufferedFieldConversion() { | |||
VaadinSession.setCurrent(new AlwaysLockedVaadinSession(null)); | |||
TextField tf = new TextField("salary"); | |||
LegacyTextField tf = new LegacyTextField("salary"); | |||
tf.setBuffered(true); | |||
tf.setLocale(new Locale("en", "US")); | |||
ObjectProperty<Integer> ds = new ObjectProperty<Integer>(123456789); | |||
@@ -66,7 +66,7 @@ public class AbsFieldValueConversionsTest { | |||
@Test | |||
public void testModifiedBufferedFieldConversion() { | |||
VaadinSession.setCurrent(new AlwaysLockedVaadinSession(null)); | |||
TextField tf = new TextField("salary"); | |||
LegacyTextField tf = new LegacyTextField("salary"); | |||
tf.setBuffered(true); | |||
tf.setLocale(new Locale("en", "US")); | |||
ObjectProperty<Integer> ds = new ObjectProperty<Integer>(123456789); | |||
@@ -85,7 +85,7 @@ public class AbsFieldValueConversionsTest { | |||
@Test | |||
public void testStringIdentityConversion() { | |||
TextField tf = new TextField(); | |||
LegacyTextField tf = new LegacyTextField(); | |||
tf.setConverter(new LegacyConverter<String, String>() { | |||
@Override | |||
@@ -110,8 +110,8 @@ public class AbsFieldValueConversionsTest { | |||
return String.class; | |||
} | |||
}); | |||
tf.setPropertyDataSource(new MethodProperty<String>(paulaBean, | |||
"firstName")); | |||
tf.setPropertyDataSource( | |||
new MethodProperty<String>(paulaBean, "firstName")); | |||
assertEquals("Paula", tf.getValue()); | |||
assertEquals("Paula", tf.getPropertyDataSource().getValue()); | |||
tf.setValue("abc"); | |||
@@ -122,7 +122,7 @@ public class AbsFieldValueConversionsTest { | |||
@Test | |||
public void testIntegerStringConversion() { | |||
TextField tf = new TextField(); | |||
LegacyTextField tf = new LegacyTextField(); | |||
tf.setConverter(new LegacyStringToIntegerConverter()); | |||
tf.setPropertyDataSource(new MethodProperty<Integer>(paulaBean, "age")); | |||
@@ -140,7 +140,7 @@ public class AbsFieldValueConversionsTest { | |||
public void testChangeReadOnlyFieldLocale() { | |||
VaadinSession.setCurrent(new AlwaysLockedVaadinSession(null)); | |||
TextField tf = new TextField("salary"); | |||
LegacyTextField tf = new LegacyTextField("salary"); | |||
tf.setLocale(new Locale("en", "US")); | |||
ObjectProperty<Integer> ds = new ObjectProperty<Integer>(123456789); | |||
ds.setReadOnly(true); | |||
@@ -171,7 +171,7 @@ public class AbsFieldValueConversionsTest { | |||
public void testNumberDoubleConverterChange() { | |||
final VaadinSession a = new AlwaysLockedVaadinSession(null); | |||
VaadinSession.setCurrent(a); | |||
TextField tf = new TextField() { | |||
LegacyTextField tf = new LegacyTextField() { | |||
@Override | |||
public VaadinSession getSession() { | |||
return a; | |||
@@ -198,14 +198,15 @@ public class AbsFieldValueConversionsTest { | |||
@Test | |||
public void testNullConverter() { | |||
TextField tf = new TextField("foo"); | |||
LegacyTextField tf = new LegacyTextField("foo"); | |||
tf.setConverter(new LegacyStringToIntegerConverter()); | |||
tf.setPropertyDataSource(new ObjectProperty<Integer>(12)); | |||
tf.setConverter((LegacyConverter) null); | |||
try { | |||
Object v = tf.getConvertedValue(); | |||
System.out.println(v); | |||
Assert.fail("Trying to convert String -> Integer should fail when there is no converter"); | |||
Assert.fail( | |||
"Trying to convert String -> Integer should fail when there is no converter"); | |||
} catch (ConversionException e) { | |||
// ok, should happen when there is no converter but conversion is | |||
// needed |
@@ -17,55 +17,49 @@ package com.vaadin.tests.server.component.abstractfield; | |||
import org.junit.Test; | |||
import com.vaadin.data.util.ObjectProperty; | |||
import com.vaadin.legacy.ui.LegacyAbstractField; | |||
import com.vaadin.tests.design.DeclarativeTestBase; | |||
import com.vaadin.ui.AbstractField; | |||
import com.vaadin.ui.TextField; | |||
/** | |||
* Tests declarative support for implementations of {@link LegacyAbstractField}. | |||
* Tests declarative support for implementations of {@link AbstractField}. | |||
* | |||
* @since 7.4 | |||
* @author Vaadin Ltd | |||
*/ | |||
public class AbstractFieldDeclarativeTest extends | |||
DeclarativeTestBase<LegacyAbstractField<?>> { | |||
public class AbstractFieldDeclarativeTest | |||
extends DeclarativeTestBase<AbstractField<?>> { | |||
@Test | |||
public void testPlainText() { | |||
String design = "<vaadin-text-field buffered validation-visible='false' invalid-committed" | |||
+ " invalid-allowed='false' required required-error='This is a required field'" | |||
+ " conversion-error='Input {0} cannot be parsed' tabindex=3 readonly/>"; | |||
LegacyAbstractField tf = new TextField(); | |||
tf.setBuffered(true); | |||
tf.setBuffered(true); | |||
tf.setValidationVisible(false); | |||
tf.setInvalidCommitted(true); | |||
tf.setInvalidAllowed(false); | |||
tf.setRequired(true); | |||
tf.setRequiredError("This is a required field"); | |||
tf.setConversionError("Input {0} cannot be parsed"); | |||
tf.setTabIndex(3); | |||
tf.setReadOnly(true); | |||
testRead(design, tf); | |||
testWrite(design, tf); | |||
// Test with readonly=false | |||
design = design.replace("readonly", ""); | |||
tf.setReadOnly(false); | |||
testRead(design, tf); | |||
testWrite(design, tf); | |||
// FIXME | |||
// String design = "<vaadin-text-field readonly tabindex=3" | |||
// + "required" | |||
// + "/>"; | |||
// AbstractField<String> tf = new TextField(); | |||
// tf.setRequired(true); | |||
// tf.setTabIndex(3); | |||
// tf.setReadOnly(true); | |||
// testRead(design, tf); | |||
// testWrite(design, tf); | |||
// | |||
// // Test with readonly=false | |||
// design = design.replace("readonly", ""); | |||
// tf.setReadOnly(false); | |||
// testRead(design, tf); | |||
// testWrite(design, tf); | |||
} | |||
@Test | |||
public void testModelReadOnly() { | |||
// Test that read only value coming from property data source is not | |||
// written to design. | |||
String design = "<vaadin-text-field value=test></vaadin-text-field>"; | |||
LegacyAbstractField component = new TextField(); | |||
ObjectProperty<String> property = new ObjectProperty<String>("test"); | |||
property.setReadOnly(true); | |||
component.setPropertyDataSource(property); | |||
String design = "<vaadin-text-field readonly value=test></vaadin-text-field>"; | |||
AbstractField<String> component = new TextField(); | |||
component.setReadOnly(true); | |||
component.setValue("test"); | |||
// FIXME (?) current implementation only | |||
// disables client-side modification | |||
testWrite(design, component); | |||
} | |||
} |
@@ -8,12 +8,12 @@ import org.junit.Test; | |||
import com.vaadin.data.Property.ReadOnlyStatusChangeEvent; | |||
import com.vaadin.data.Property.ReadOnlyStatusChangeListener; | |||
import com.vaadin.data.util.MethodProperty; | |||
import com.vaadin.legacy.ui.LegacyTextField; | |||
import com.vaadin.tests.data.bean.Address; | |||
import com.vaadin.tests.data.bean.Country; | |||
import com.vaadin.tests.data.bean.Person; | |||
import com.vaadin.tests.data.bean.Sex; | |||
import com.vaadin.ui.Label; | |||
import com.vaadin.ui.TextField; | |||
public class AbstractFieldReadOnlyTest { | |||
@@ -23,7 +23,7 @@ public class AbstractFieldReadOnlyTest { | |||
@Test | |||
public void testReadOnlyProperty() { | |||
TextField tf = new TextField(); | |||
LegacyTextField tf = new LegacyTextField(); | |||
tf.setPropertyDataSource(new MethodProperty<String>(paulaBean, | |||
"firstName")); | |||
assertFalse(tf.isReadOnly()); | |||
@@ -34,7 +34,7 @@ public class AbstractFieldReadOnlyTest { | |||
@Test | |||
public void testReadOnlyEventFromProperty() { | |||
final Label valueStore = new Label(""); | |||
TextField tf = new TextField(); | |||
LegacyTextField tf = new LegacyTextField(); | |||
tf.addReadOnlyStatusChangeListener(new ReadOnlyStatusChangeListener() { | |||
@Override | |||
public void readOnlyStatusChange(ReadOnlyStatusChangeEvent event) { |
@@ -8,13 +8,13 @@ import java.util.Locale; | |||
import org.junit.Test; | |||
import com.vaadin.data.util.MethodProperty; | |||
import com.vaadin.legacy.ui.LegacyTextField; | |||
import com.vaadin.server.VaadinSession; | |||
import com.vaadin.tests.data.bean.Address; | |||
import com.vaadin.tests.data.bean.Country; | |||
import com.vaadin.tests.data.bean.Person; | |||
import com.vaadin.tests.data.bean.Sex; | |||
import com.vaadin.tests.util.AlwaysLockedVaadinSession; | |||
import com.vaadin.ui.TextField; | |||
public class DefaultConverterFactoryTest { | |||
@@ -87,7 +87,7 @@ public class DefaultConverterFactoryTest { | |||
VaadinSession sess = new AlwaysLockedVaadinSession(null); | |||
VaadinSession.setCurrent(sess); | |||
TextField tf = new TextField(); | |||
LegacyTextField tf = new LegacyTextField(); | |||
tf.setLocale(new Locale("en", "US")); | |||
tf.setPropertyDataSource(new MethodProperty<Integer>(new FloatBean(12f, | |||
23f), "f2")); | |||
@@ -103,7 +103,7 @@ public class DefaultConverterFactoryTest { | |||
VaadinSession sess = new AlwaysLockedVaadinSession(null); | |||
VaadinSession.setCurrent(sess); | |||
TextField tf = new TextField(); | |||
LegacyTextField tf = new LegacyTextField(); | |||
tf.setLocale(new Locale("en", "US")); | |||
tf.setPropertyDataSource(new MethodProperty<Integer>(new LongBean(12, | |||
1982739187238L), "l2")); | |||
@@ -118,7 +118,7 @@ public class DefaultConverterFactoryTest { | |||
public void testDefaultNumberConversion() { | |||
VaadinSession app = new AlwaysLockedVaadinSession(null); | |||
VaadinSession.setCurrent(app); | |||
TextField tf = new TextField(); | |||
LegacyTextField tf = new LegacyTextField(); | |||
tf.setLocale(new Locale("en", "US")); | |||
tf.setPropertyDataSource(new MethodProperty<Integer>(paulaBean, | |||
"salary")); |
@@ -17,9 +17,9 @@ package com.vaadin.tests.server.component.abstracttextfield; | |||
import org.junit.Test; | |||
import com.vaadin.shared.ui.textfield.ValueChangeMode; | |||
import com.vaadin.tests.design.DeclarativeTestBase; | |||
import com.vaadin.ui.AbstractTextField; | |||
import com.vaadin.ui.AbstractTextField.TextChangeEventMode; | |||
import com.vaadin.ui.TextField; | |||
/** | |||
@@ -28,23 +28,26 @@ import com.vaadin.ui.TextField; | |||
* @since | |||
* @author Vaadin Ltd | |||
*/ | |||
public class AbstractTextFieldDeclarativeTest extends | |||
DeclarativeTestBase<AbstractTextField> { | |||
public class AbstractTextFieldDeclarativeTest | |||
extends DeclarativeTestBase<AbstractTextField> { | |||
@Test | |||
public void testAttributes() { | |||
String design = "<vaadin-text-field null-representation=this-is-null " | |||
+ "null-setting-allowed maxlength=5 columns=3 " | |||
+ "input-prompt=input text-change-event-mode=eager " | |||
+ "text-change-timeout=100 />"; | |||
String design = "<vaadin-text-field " | |||
// + "null-representation=this-is-null " | |||
// + "null-setting-allowed " | |||
+ "maxlength=5 columns=3 " | |||
+ "placeholder=input value-change-mode=eager " | |||
+ "value-change-timeout=100 />"; | |||
AbstractTextField tf = new TextField(); | |||
tf.setNullRepresentation("this-is-null"); | |||
tf.setNullSettingAllowed(true); | |||
// FIXME | |||
// tf.setNullRepresentation("this-is-null"); | |||
// tf.setNullSettingAllowed(true); | |||
tf.setMaxLength(5); | |||
tf.setColumns(3); | |||
tf.setInputPrompt("input"); | |||
tf.setTextChangeEventMode(TextChangeEventMode.EAGER); | |||
tf.setTextChangeTimeout(100); | |||
tf.setPlaceholder("input"); | |||
tf.setValueChangeMode(ValueChangeMode.EAGER); | |||
tf.setValueChangeTimeout(100); | |||
testRead(design, tf); | |||
testWrite(design, tf); | |||
} |
@@ -8,27 +8,27 @@ import com.vaadin.event.FieldEvents.FocusEvent; | |||
import com.vaadin.event.FieldEvents.FocusListener; | |||
import com.vaadin.event.FieldEvents.TextChangeEvent; | |||
import com.vaadin.event.FieldEvents.TextChangeListener; | |||
import com.vaadin.legacy.ui.LegacyTextField; | |||
import com.vaadin.tests.server.component.AbstractListenerMethodsTestBase; | |||
import com.vaadin.ui.TextField; | |||
public class AbstractTextFieldListenersTest extends | |||
AbstractListenerMethodsTestBase { | |||
@Test | |||
public void testTextChangeListenerAddGetRemove() throws Exception { | |||
testListenerAddGetRemove(TextField.class, TextChangeEvent.class, | |||
testListenerAddGetRemove(LegacyTextField.class, TextChangeEvent.class, | |||
TextChangeListener.class); | |||
} | |||
@Test | |||
public void testFocusListenerAddGetRemove() throws Exception { | |||
testListenerAddGetRemove(TextField.class, FocusEvent.class, | |||
testListenerAddGetRemove(LegacyTextField.class, FocusEvent.class, | |||
FocusListener.class); | |||
} | |||
@Test | |||
public void testBlurListenerAddGetRemove() throws Exception { | |||
testListenerAddGetRemove(TextField.class, BlurEvent.class, | |||
testListenerAddGetRemove(LegacyTextField.class, BlurEvent.class, | |||
BlurListener.class); | |||
} | |||
} |
@@ -11,8 +11,8 @@ import com.vaadin.data.fieldgroup.FieldGroup.CommitException; | |||
import com.vaadin.data.fieldgroup.PropertyId; | |||
import com.vaadin.data.util.BeanItem; | |||
import com.vaadin.legacy.ui.LegacyField; | |||
import com.vaadin.legacy.ui.LegacyTextField; | |||
import com.vaadin.ui.RichTextArea; | |||
import com.vaadin.ui.TextField; | |||
public class BeanFieldGroupTest { | |||
@@ -72,10 +72,10 @@ public class BeanFieldGroupTest { | |||
public static class ViewStub { | |||
TextField basicField = new TextField(); | |||
LegacyTextField basicField = new LegacyTextField(); | |||
@PropertyId("anotherField") | |||
TextField boundWithAnnotation = new TextField(); | |||
LegacyTextField boundWithAnnotation = new LegacyTextField(); | |||
} | |||
@SuppressWarnings("unchecked") |
@@ -7,8 +7,8 @@ import org.junit.Test; | |||
import com.vaadin.data.fieldgroup.FieldGroup; | |||
import com.vaadin.data.util.ObjectProperty; | |||
import com.vaadin.data.util.PropertysetItem; | |||
import com.vaadin.legacy.ui.LegacyTextField; | |||
import com.vaadin.ui.FormLayout; | |||
import com.vaadin.ui.TextField; | |||
public class CaseInsensitiveBindingTest { | |||
@@ -18,7 +18,7 @@ public class CaseInsensitiveBindingTest { | |||
item.addItemProperty("LastName", new ObjectProperty<String>("Sparrow")); | |||
class MyForm extends FormLayout { | |||
TextField lastName = new TextField("Last name"); | |||
LegacyTextField lastName = new LegacyTextField("Last name"); | |||
public MyForm() { | |||
@@ -41,7 +41,7 @@ public class CaseInsensitiveBindingTest { | |||
item.addItemProperty("first_name", new ObjectProperty<String>("Jack")); | |||
class MyForm extends FormLayout { | |||
TextField firstName = new TextField("First name"); | |||
LegacyTextField firstName = new LegacyTextField("First name"); | |||
public MyForm() { | |||
// Should bind to the first_name property | |||
@@ -65,7 +65,7 @@ public class CaseInsensitiveBindingTest { | |||
item.addItemProperty("firstName", new ObjectProperty<String>("This")); | |||
class MyForm extends FormLayout { | |||
TextField firstName = new TextField("First name"); | |||
LegacyTextField firstName = new LegacyTextField("First name"); | |||
public MyForm() { | |||
// should bind to the firstName property, not first_name |
@@ -32,7 +32,7 @@ import com.vaadin.data.fieldgroup.FieldGroup.CommitException; | |||
import com.vaadin.data.util.AbstractProperty; | |||
import com.vaadin.legacy.data.Validator.InvalidValueException; | |||
import com.vaadin.legacy.ui.LegacyField; | |||
import com.vaadin.ui.TextField; | |||
import com.vaadin.legacy.ui.LegacyTextField; | |||
/** | |||
* | |||
@@ -46,7 +46,7 @@ public class FieldGroupTest { | |||
public void setReadOnly_readOnlyAndNoDataSource_fieldIsReadOnly() { | |||
FieldGroup fieldGroup = new FieldGroup(); | |||
TextField field = new TextField(); | |||
LegacyTextField field = new LegacyTextField(); | |||
fieldGroup.bind(field, "property"); | |||
fieldGroup.setReadOnly(true); | |||
@@ -58,7 +58,7 @@ public class FieldGroupTest { | |||
public void setReadOnly_writableAndNoDataSource_fieldIsWritable() { | |||
FieldGroup fieldGroup = new FieldGroup(); | |||
TextField field = new TextField(); | |||
LegacyTextField field = new LegacyTextField(); | |||
fieldGroup.bind(field, "property"); | |||
fieldGroup.setReadOnly(false); | |||
@@ -73,15 +73,15 @@ public class FieldGroupTest { | |||
fieldGroup.setItemDataSource(new TestItem()); | |||
TextField field1 = new TextField(); | |||
LegacyTextField field1 = new LegacyTextField(); | |||
field1.setRequired(true); | |||
fieldGroup.bind(field1, "prop1"); | |||
TextField field2 = new TextField(); | |||
LegacyTextField field2 = new LegacyTextField(); | |||
field2.setRequired(true); | |||
fieldGroup.bind(field2, "prop2"); | |||
Set<TextField> set = new HashSet<>(Arrays.asList(field1, | |||
Set<LegacyTextField> set = new HashSet<>(Arrays.asList(field1, | |||
field2)); | |||
try { |
@@ -7,13 +7,13 @@ import org.junit.Test; | |||
import com.vaadin.data.fieldgroup.FieldGroup; | |||
import com.vaadin.data.util.BeanItem; | |||
import com.vaadin.legacy.ui.LegacyTextField; | |||
import com.vaadin.tests.data.bean.BeanWithReadOnlyField; | |||
import com.vaadin.ui.TextField; | |||
public class FieldGroupWithReadOnlyPropertiesTest { | |||
private TextField readOnlyField = new TextField(); | |||
private TextField writableField = new TextField(); | |||
private LegacyTextField readOnlyField = new LegacyTextField(); | |||
private LegacyTextField writableField = new LegacyTextField(); | |||
@Test | |||
public void bindReadOnlyPropertyToFieldGroup() { |
@@ -8,8 +8,8 @@ import com.vaadin.data.fieldgroup.FieldGroup; | |||
import com.vaadin.data.fieldgroup.PropertyId; | |||
import com.vaadin.data.util.ObjectProperty; | |||
import com.vaadin.data.util.PropertysetItem; | |||
import com.vaadin.legacy.ui.LegacyTextField; | |||
import com.vaadin.ui.FormLayout; | |||
import com.vaadin.ui.TextField; | |||
public class FieldNamedDescriptionTest { | |||
@@ -24,12 +24,12 @@ public class FieldNamedDescriptionTest { | |||
// Define a form as a class that extends some layout | |||
class MyForm extends FormLayout { | |||
// Member that will bind to the "name" property | |||
TextField name = new TextField("Name"); | |||
LegacyTextField name = new LegacyTextField("Name"); | |||
// This member will not bind to the desctiptionProperty as the name | |||
// description conflicts with something in the binding process | |||
@PropertyId("description") | |||
TextField description = new TextField("Description"); | |||
LegacyTextField description = new LegacyTextField("Description"); | |||
public MyForm() { | |||
@@ -18,8 +18,8 @@ package com.vaadin.tests.server.component.form; | |||
import org.junit.Assert; | |||
import org.junit.Test; | |||
import com.vaadin.legacy.ui.LegacyTextField; | |||
import com.vaadin.ui.Form; | |||
import com.vaadin.ui.TextField; | |||
/** | |||
* Test for {@link Form}. | |||
@@ -32,7 +32,7 @@ public class FormTest { | |||
public void testFocus() { | |||
Form form = new Form(); | |||
final boolean firstFieldIsFocused[] = new boolean[1]; | |||
TextField field1 = new TextField() { | |||
LegacyTextField field1 = new LegacyTextField() { | |||
@Override | |||
public boolean isConnectorEnabled() { | |||
return false; | |||
@@ -45,7 +45,7 @@ public class FormTest { | |||
}; | |||
final boolean secondFieldIsFocused[] = new boolean[1]; | |||
TextField field2 = new TextField() { | |||
LegacyTextField field2 = new LegacyTextField() { | |||
@Override | |||
public boolean isConnectorEnabled() { | |||
return true; |
@@ -40,6 +40,7 @@ import org.junit.Before; | |||
import org.junit.Test; | |||
import com.vaadin.data.util.IndexedContainer; | |||
import com.vaadin.legacy.ui.LegacyTextField; | |||
import com.vaadin.server.KeyMapper; | |||
import com.vaadin.shared.ui.grid.GridColumnState; | |||
import com.vaadin.shared.ui.grid.GridState; | |||
@@ -48,7 +49,6 @@ import com.vaadin.ui.Grid; | |||
import com.vaadin.ui.Grid.Column; | |||
import com.vaadin.ui.Grid.ColumnResizeEvent; | |||
import com.vaadin.ui.Grid.ColumnResizeListener; | |||
import com.vaadin.ui.TextField; | |||
public class GridColumnsTest { | |||
@@ -283,12 +283,12 @@ public class GridColumnsTest { | |||
@Test | |||
public void testPropertyAndColumnEditorFieldsMatch() { | |||
Column column1 = grid.getColumn("column1"); | |||
column1.setEditorField(new TextField()); | |||
column1.setEditorField(new LegacyTextField()); | |||
assertSame(column1.getEditorField(), grid.getColumn("column1") | |||
.getEditorField()); | |||
Column column2 = grid.getColumn("column2"); | |||
column2.setEditorField(new TextField()); | |||
column2.setEditorField(new LegacyTextField()); | |||
assertSame(column2.getEditorField(), column2.getEditorField()); | |||
} | |||
@@ -36,11 +36,11 @@ import com.vaadin.data.fieldgroup.FieldGroup; | |||
import com.vaadin.data.fieldgroup.FieldGroup.CommitException; | |||
import com.vaadin.data.util.IndexedContainer; | |||
import com.vaadin.legacy.ui.LegacyField; | |||
import com.vaadin.legacy.ui.LegacyTextField; | |||
import com.vaadin.server.MockVaadinSession; | |||
import com.vaadin.server.VaadinService; | |||
import com.vaadin.server.VaadinSession; | |||
import com.vaadin.ui.Grid; | |||
import com.vaadin.ui.TextField; | |||
public class GridEditorTest { | |||
@@ -148,7 +148,7 @@ public class GridEditorTest { | |||
@Test | |||
public void testSaveEditor() throws Exception { | |||
startEdit(); | |||
TextField field = (TextField) grid.getColumn(PROPERTY_NAME) | |||
LegacyTextField field = (LegacyTextField) grid.getColumn(PROPERTY_NAME) | |||
.getEditorField(); | |||
field.setValue("New Name"); | |||
@@ -165,7 +165,7 @@ public class GridEditorTest { | |||
public void testSaveEditorCommitFail() throws Exception { | |||
startEdit(); | |||
((TextField) grid.getColumn(PROPERTY_AGE).getEditorField()) | |||
((LegacyTextField) grid.getColumn(PROPERTY_AGE).getEditorField()) | |||
.setValue("Invalid"); | |||
try { | |||
// Manual fail instead of @Test(expected=...) to check it is | |||
@@ -180,7 +180,7 @@ public class GridEditorTest { | |||
@Test | |||
public void testCancelEditor() throws Exception { | |||
startEdit(); | |||
TextField field = (TextField) grid.getColumn(PROPERTY_NAME) | |||
LegacyTextField field = (LegacyTextField) grid.getColumn(PROPERTY_NAME) | |||
.getEditorField(); | |||
field.setValue("New Name"); | |||
@@ -217,7 +217,7 @@ public class GridEditorTest { | |||
@Test | |||
public void testCustomBinding() { | |||
TextField textField = new TextField(); | |||
LegacyTextField textField = new LegacyTextField(); | |||
grid.getColumn(PROPERTY_NAME).setEditorField(textField); | |||
startEdit(); | |||
@@ -261,10 +261,10 @@ public class GridEditorTest { | |||
@Test | |||
public void testSetFieldAgain() { | |||
TextField field = new TextField(); | |||
LegacyTextField field = new LegacyTextField(); | |||
grid.getColumn(PROPERTY_NAME).setEditorField(field); | |||
field = new TextField(); | |||
field = new LegacyTextField(); | |||
grid.getColumn(PROPERTY_NAME).setEditorField(field); | |||
assertSame("new field should be used.", field, |
@@ -4,10 +4,10 @@ import org.junit.Assert; | |||
import org.junit.Before; | |||
import org.junit.Test; | |||
import com.vaadin.legacy.ui.LegacyTextField; | |||
import com.vaadin.ui.Alignment; | |||
import com.vaadin.ui.GridLayout; | |||
import com.vaadin.ui.Label; | |||
import com.vaadin.ui.TextField; | |||
public class DefaultAlignmentTest { | |||
@@ -21,7 +21,7 @@ public class DefaultAlignmentTest { | |||
@Test | |||
public void testDefaultAlignment() { | |||
Label label = new Label("A label"); | |||
TextField tf = new TextField("A TextField"); | |||
LegacyTextField tf = new LegacyTextField("A TextField"); | |||
gridLayout.addComponent(label); | |||
gridLayout.addComponent(tf); | |||
Assert.assertEquals(Alignment.TOP_LEFT, | |||
@@ -33,7 +33,7 @@ public class DefaultAlignmentTest { | |||
@Test | |||
public void testAlteredDefaultAlignment() { | |||
Label label = new Label("A label"); | |||
TextField tf = new TextField("A TextField"); | |||
LegacyTextField tf = new LegacyTextField("A TextField"); | |||
gridLayout.setDefaultComponentAlignment(Alignment.MIDDLE_CENTER); | |||
gridLayout.addComponent(label); | |||
gridLayout.addComponent(tf); |
@@ -4,11 +4,11 @@ import org.junit.Assert; | |||
import org.junit.Before; | |||
import org.junit.Test; | |||
import com.vaadin.legacy.ui.LegacyTextField; | |||
import com.vaadin.ui.AbstractOrderedLayout; | |||
import com.vaadin.ui.Alignment; | |||
import com.vaadin.ui.HorizontalLayout; | |||
import com.vaadin.ui.Label; | |||
import com.vaadin.ui.TextField; | |||
import com.vaadin.ui.VerticalLayout; | |||
public class DefaultAlignmentTest { | |||
@@ -34,7 +34,7 @@ public class DefaultAlignmentTest { | |||
public void testDefaultAlignment(AbstractOrderedLayout layout) { | |||
Label label = new Label("A label"); | |||
TextField tf = new TextField("A TextField"); | |||
LegacyTextField tf = new LegacyTextField("A TextField"); | |||
layout.addComponent(label); | |||
layout.addComponent(tf); | |||
Assert.assertEquals(Alignment.TOP_LEFT, | |||
@@ -55,7 +55,7 @@ public class DefaultAlignmentTest { | |||
public void testAlteredDefaultAlignment(AbstractOrderedLayout layout) { | |||
Label label = new Label("A label"); | |||
TextField tf = new TextField("A TextField"); | |||
LegacyTextField tf = new LegacyTextField("A TextField"); | |||
layout.setDefaultComponentAlignment(Alignment.MIDDLE_CENTER); | |||
layout.addComponent(label); | |||
layout.addComponent(tf); |
@@ -72,8 +72,8 @@ public class TabSheetDeclarativeTest extends DeclarativeTestBase<TabSheet> { | |||
public void tabsNotShown() { | |||
String design = "<vaadin-tab-sheet tabs-visible=\"false\">\n" | |||
+ " <tab caption=\"My Tab\" selected>\n" | |||
+ " <vaadin-label>My Content</vaadin-label>\n" | |||
+ " </tab>\n" + "</vaadin-tab-sheet>\n"; | |||
+ " <vaadin-label>My Content</vaadin-label>\n" + " </tab>\n" | |||
+ "</vaadin-tab-sheet>\n"; | |||
TabSheet ts = new TabSheet(); | |||
ts.setTabsVisible(false); | |||
Label l = new Label("My Content", ContentMode.HTML); |
@@ -5,17 +5,17 @@ import org.junit.Test; | |||
import com.vaadin.data.util.ObjectProperty; | |||
import com.vaadin.legacy.data.validator.LegacyRangeValidator; | |||
import com.vaadin.legacy.ui.LegacyTextField; | |||
import com.vaadin.tests.data.converter.ConverterFactoryTest.ConvertTo42; | |||
import com.vaadin.ui.TextField; | |||
public class TextFieldWithConverterAndValidatorTest { | |||
private TextField field; | |||
private LegacyTextField field; | |||
private ObjectProperty<Integer> property; | |||
@Before | |||
public void setUp() { | |||
field = new TextField(); | |||
field = new LegacyTextField(); | |||
field.setInvalidAllowed(false); | |||
} | |||
@@ -13,7 +13,7 @@ import com.vaadin.data.Property.ValueChangeEvent; | |||
import com.vaadin.data.Property.ValueChangeListener; | |||
import com.vaadin.data.util.ObjectProperty; | |||
import com.vaadin.data.util.PropertyFormatter; | |||
import com.vaadin.ui.TextField; | |||
import com.vaadin.legacy.ui.LegacyTextField; | |||
public class TextFieldWithPropertyFormatterTest { | |||
@@ -21,7 +21,7 @@ public class TextFieldWithPropertyFormatterTest { | |||
private static final String PARSED_VALUE = "BAR"; | |||
private static final String FORMATTED_VALUE = "FOOBAR"; | |||
private static final String ORIGINAL_VALUE = "Original"; | |||
private TextField field; | |||
private LegacyTextField field; | |||
private PropertyFormatter<String> formatter; | |||
private ObjectProperty<String> property; | |||
private ValueChangeListener listener; | |||
@@ -31,7 +31,7 @@ public class TextFieldWithPropertyFormatterTest { | |||
@Before | |||
public void setUp() { | |||
field = new TextField() { | |||
field = new LegacyTextField() { | |||
@Override | |||
public void markAsDirty() { | |||
repainted++; |
@@ -11,17 +11,17 @@ import com.vaadin.legacy.data.Validator.InvalidValueException; | |||
import com.vaadin.legacy.data.validator.LegacyEmailValidator; | |||
import com.vaadin.legacy.data.validator.LegacyRegexpValidator; | |||
import com.vaadin.legacy.data.validator.LegacyStringLengthValidator; | |||
import com.vaadin.ui.TextField; | |||
import com.vaadin.legacy.ui.LegacyTextField; | |||
public class TextFieldWithValidatorTest { | |||
private TextField field; | |||
private LegacyTextField field; | |||
private ObjectProperty<String> property; | |||
@Before | |||
public void setUp() { | |||
field = new TextField(); | |||
field = new LegacyTextField(); | |||
field.setInvalidAllowed(false); | |||
property = new ObjectProperty<String>("original"); | |||
field.setPropertyDataSource(property); |
@@ -11,7 +11,7 @@ import org.junit.Test; | |||
import com.vaadin.data.Property.ValueChangeEvent; | |||
import com.vaadin.data.util.ObjectProperty; | |||
import com.vaadin.legacy.ui.LegacyAbstractField; | |||
import com.vaadin.ui.TextField; | |||
import com.vaadin.legacy.ui.LegacyTextField; | |||
/** | |||
* Check that the value change listener for a text field is triggered exactly | |||
@@ -24,7 +24,7 @@ public class TextFieldValueChangeTest extends | |||
@Before | |||
public void setUp() { | |||
super.setUp(new TextField()); | |||
super.setUp(new LegacyTextField()); | |||
} | |||
/** | |||
@@ -42,7 +42,7 @@ public class TextFieldValueChangeTest extends | |||
protected void setValue(LegacyAbstractField<String> field) { | |||
Map<String, Object> variables = new HashMap<String, Object>(); | |||
variables.put("text", "newValue"); | |||
((TextField) field).changeVariables(field, variables); | |||
((LegacyTextField) field).changeVariables(field, variables); | |||
} | |||
/** |
@@ -3,13 +3,13 @@ package com.vaadin.tests.server.validation; | |||
import org.junit.Test; | |||
import com.vaadin.legacy.data.validator.LegacyIntegerValidator; | |||
import com.vaadin.ui.TextField; | |||
import com.vaadin.legacy.ui.LegacyTextField; | |||
public class ReadOnlyValidationTest { | |||
@Test | |||
public void testIntegerValidation() { | |||
TextField field = new TextField(); | |||
LegacyTextField field = new LegacyTextField(); | |||
field.addValidator(new LegacyIntegerValidator("Enter a Valid Number")); | |||
field.setValue(String.valueOf(10)); | |||
field.validate(); |
@@ -8,6 +8,7 @@ import org.junit.Before; | |||
import org.junit.Test; | |||
import com.vaadin.legacy.data.util.converter.LegacyStringToIntegerConverter; | |||
import com.vaadin.legacy.ui.LegacyTextField; | |||
import com.vaadin.server.VaadinRequest; | |||
import com.vaadin.server.VaadinSession; | |||
import com.vaadin.tests.util.AlwaysLockedVaadinSession; | |||
@@ -34,7 +35,7 @@ public class AbsFieldDataSourceLocaleChangeTest { | |||
@Test | |||
public void localeChangesOnAttach() { | |||
TextField tf = new TextField(); | |||
LegacyTextField tf = new LegacyTextField(); | |||
tf.setConverter(new LegacyStringToIntegerConverter() { | |||
@Override |
@@ -19,18 +19,19 @@ import org.junit.Assert; | |||
import org.junit.Test; | |||
import com.vaadin.data.util.ObjectProperty; | |||
import com.vaadin.legacy.ui.LegacyTextField; | |||
public class TextFieldTest { | |||
@Test | |||
public void initiallyEmpty() { | |||
TextField tf = new TextField(); | |||
LegacyTextField tf = new LegacyTextField(); | |||
Assert.assertTrue(tf.isEmpty()); | |||
} | |||
@Test | |||
public void emptyAfterClearUsingPDS() { | |||
TextField tf = new TextField(new ObjectProperty<String>("foo")); | |||
LegacyTextField tf = new LegacyTextField(new ObjectProperty<String>("foo")); | |||
Assert.assertFalse(tf.isEmpty()); | |||
tf.clear(); | |||
Assert.assertTrue(tf.isEmpty()); | |||
@@ -38,7 +39,7 @@ public class TextFieldTest { | |||
@Test | |||
public void emptyAfterClear() { | |||
TextField tf = new TextField(); | |||
LegacyTextField tf = new LegacyTextField(); | |||
tf.setValue("foobar"); | |||
Assert.assertFalse(tf.isEmpty()); | |||
tf.clear(); |
@@ -13,12 +13,13 @@ | |||
* License for the specific language governing permissions and limitations under | |||
* the License. | |||
*/ | |||
package com.vaadin.shared.ui.textfield; | |||
package com.vaadin.shared.legacy.ui.textfield; | |||
import com.vaadin.shared.AbstractFieldState; | |||
import com.vaadin.shared.annotations.NoLayout; | |||
public class AbstractTextFieldState extends AbstractFieldState { | |||
@Deprecated | |||
public class LegacyAbstractTextFieldState extends AbstractFieldState { | |||
{ | |||
primaryStyleName = "v-textfield"; | |||
} |
@@ -13,11 +13,12 @@ | |||
* License for the specific language governing permissions and limitations under | |||
* the License. | |||
*/ | |||
package com.vaadin.shared.ui.textfield; | |||
package com.vaadin.shared.legacy.ui.textfield; | |||
import java.io.Serializable; | |||
public class TextFieldConstants implements Serializable { | |||
@Deprecated | |||
public class LegacyTextFieldConstants implements Serializable { | |||
public static final String VAR_CUR_TEXT = "curText"; | |||
public static final String ATTR_NO_VALUE_CHANGE_BETWEEN_PAINTS = "nvc"; | |||
public static final String ATTR_TEXTCHANGE_TIMEOUT = "iet"; |
@@ -15,7 +15,7 @@ | |||
*/ | |||
package com.vaadin.shared.ui.textarea; | |||
import com.vaadin.shared.ui.textfield.AbstractTextFieldState; | |||
import com.vaadin.shared.legacy.ui.textfield.LegacyAbstractTextFieldState; | |||
/** | |||
* | |||
@@ -23,7 +23,7 @@ import com.vaadin.shared.ui.textfield.AbstractTextFieldState; | |||
* | |||
* @since 7.6 | |||
*/ | |||
public class RichTextAreaState extends AbstractTextFieldState { | |||
public class RichTextAreaState extends LegacyAbstractTextFieldState { | |||
{ | |||
primaryStyleName = "v-richtextarea"; |
@@ -17,9 +17,9 @@ package com.vaadin.shared.ui.textarea; | |||
import com.vaadin.shared.annotations.DelegateToWidget; | |||
import com.vaadin.shared.annotations.NoLayout; | |||
import com.vaadin.shared.ui.textfield.AbstractTextFieldState; | |||
import com.vaadin.shared.legacy.ui.textfield.LegacyAbstractTextFieldState; | |||
public class TextAreaState extends AbstractTextFieldState { | |||
public class TextAreaState extends LegacyAbstractTextFieldState { | |||
{ | |||
primaryStyleName = "v-textarea"; | |||
} |
@@ -0,0 +1,24 @@ | |||
/* | |||
* Copyright 2000-2014 Vaadin Ltd. | |||
* | |||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | |||
* use this file except in compliance with the License. You may obtain a copy of | |||
* the License at | |||
* | |||
* http://www.apache.org/licenses/LICENSE-2.0 | |||
* | |||
* Unless required by applicable law or agreed to in writing, software | |||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | |||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | |||
* License for the specific language governing permissions and limitations under | |||
* the License. | |||
*/ | |||
package com.vaadin.shared.ui.textfield; | |||
import com.vaadin.shared.communication.FieldRpc.FocusAndBlurServerRpc; | |||
public interface TextFieldServerRpc extends FocusAndBlurServerRpc { | |||
public void setText(String text, int cursorPosition); | |||
} |
@@ -0,0 +1,67 @@ | |||
/* | |||
* Copyright 2000-2014 Vaadin Ltd. | |||
* | |||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | |||
* use this file except in compliance with the License. You may obtain a copy of | |||
* the License at | |||
* | |||
* http://www.apache.org/licenses/LICENSE-2.0 | |||
* | |||
* Unless required by applicable law or agreed to in writing, software | |||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | |||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | |||
* License for the specific language governing permissions and limitations under | |||
* the License. | |||
*/ | |||
package com.vaadin.shared.ui.textfield; | |||
import com.vaadin.shared.AbstractFieldState; | |||
import com.vaadin.shared.annotations.DelegateToWidget; | |||
import com.vaadin.shared.annotations.NoLayout; | |||
public class TextFieldState extends AbstractFieldState { | |||
{ | |||
primaryStyleName = "v-textfield"; | |||
} | |||
/** | |||
* Maximum character count in text field. | |||
*/ | |||
@DelegateToWidget | |||
@NoLayout | |||
public int maxLength = -1; | |||
/** | |||
* Number of visible columns in the TextField. | |||
*/ | |||
public int columns = 0; | |||
/** | |||
* The prompt to display in an empty field. Null when disabled. | |||
*/ | |||
@DelegateToWidget | |||
@NoLayout | |||
public String placeholder = null; | |||
/** | |||
* The text in the field | |||
*/ | |||
@DelegateToWidget | |||
@NoLayout | |||
public String text = ""; | |||
@NoLayout | |||
public int selectionStart = -1; | |||
@NoLayout | |||
public int selectionLength = 0; | |||
@NoLayout | |||
public int cursorPosition = 0; | |||
@NoLayout | |||
public ValueChangeMode valueChangeMode = ValueChangeMode.LAZY; | |||
@NoLayout | |||
public int valueChangeTimeout = 400; | |||
} |
@@ -0,0 +1,51 @@ | |||
/* | |||
* Copyright 2000-2014 Vaadin Ltd. | |||
* | |||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | |||
* use this file except in compliance with the License. You may obtain a copy of | |||
* the License at | |||
* | |||
* http://www.apache.org/licenses/LICENSE-2.0 | |||
* | |||
* Unless required by applicable law or agreed to in writing, software | |||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | |||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | |||
* License for the specific language governing permissions and limitations under | |||
* the License. | |||
*/ | |||
package com.vaadin.shared.ui.textfield; | |||
/** | |||
* Different modes for when and how often field value changes are transmitted | |||
* from the client to the server. | |||
*/ | |||
public enum ValueChangeMode { | |||
/** | |||
* Fires a server-side event when the field loses focus. | |||
*/ | |||
BLUR, | |||
/** | |||
* Fires a server-side event every time the client-side value changes. This | |||
* gives the least latency but may cause unnecessary traffic. | |||
*/ | |||
EAGER, | |||
/** | |||
* Fires a server-side event at defined intervals as long as the value | |||
* changes from one event to the next. For instance, you can use this mode | |||
* to transmit a snapshot of the contents of a text area every second as | |||
* long as the user keeps typing. | |||
*/ | |||
TIMEOUT, | |||
/** | |||
* On every user event, schedule a server-side event after a defined | |||
* interval, cancelling the currently-scheduled event if any. This is a good | |||
* choice if you want to, for instance, wait for a small break in the user's | |||
* typing before sending the event. | |||
*/ | |||
LAZY | |||
} |
@@ -17,6 +17,7 @@ | |||
package com.vaadin.tests; | |||
import com.vaadin.legacy.ui.LegacyField; | |||
import com.vaadin.legacy.ui.LegacyTextField; | |||
import com.vaadin.shared.ui.label.ContentMode; | |||
import com.vaadin.ui.Button; | |||
import com.vaadin.ui.Button.ClickEvent; | |||
@@ -27,7 +28,6 @@ import com.vaadin.ui.Label; | |||
import com.vaadin.ui.LegacyWindow; | |||
import com.vaadin.ui.Panel; | |||
import com.vaadin.ui.PasswordField; | |||
import com.vaadin.ui.TextField; | |||
import com.vaadin.ui.Tree; | |||
import com.vaadin.ui.VerticalLayout; | |||
@@ -51,7 +51,7 @@ public class CustomLayoutDemo extends com.vaadin.server.LegacyApplication | |||
private final Panel bodyPanel = new Panel(); | |||
private final TextField username = new TextField("Username"); | |||
private final LegacyTextField username = new LegacyTextField("Username"); | |||
private final PasswordField loginPwd = new PasswordField("Password"); | |||
@@ -1,5 +1,6 @@ | |||
package com.vaadin.tests; | |||
import com.vaadin.legacy.ui.LegacyTextField; | |||
import com.vaadin.ui.AbstractSelect; | |||
import com.vaadin.ui.Button; | |||
import com.vaadin.ui.Button.ClickEvent; | |||
@@ -10,7 +11,6 @@ import com.vaadin.ui.GridLayout; | |||
import com.vaadin.ui.ListSelect; | |||
import com.vaadin.ui.NativeSelect; | |||
import com.vaadin.ui.OptionGroup; | |||
import com.vaadin.ui.TextField; | |||
/** | |||
* Simple test helper to test Focusable.focus() method. | |||
@@ -30,7 +30,7 @@ public class FocusingComponents extends CustomComponent { | |||
addFocusableTest(f); | |||
addFocusableTest(new ComboBox()); | |||
addFocusableTest(new TextField()); | |||
addFocusableTest(new LegacyTextField()); | |||
addFocusableTest(new DateField()); | |||
addFocusableTest(new NativeSelect()); | |||
addFocusableTest(new ListSelect()); |
@@ -16,12 +16,12 @@ | |||
package com.vaadin.tests; | |||
import com.vaadin.legacy.ui.LegacyTextField; | |||
import com.vaadin.ui.Button; | |||
import com.vaadin.ui.Button.ClickEvent; | |||
import com.vaadin.ui.Button.ClickListener; | |||
import com.vaadin.ui.Label; | |||
import com.vaadin.ui.LegacyWindow; | |||
import com.vaadin.ui.TextField; | |||
import com.vaadin.ui.VerticalLayout; | |||
import com.vaadin.ui.Window; | |||
@@ -50,7 +50,7 @@ public class ModalWindow extends com.vaadin.server.LegacyApplication implements | |||
main.addComponent(new Label("ModalWindow demo")); | |||
// Main window textfield | |||
final TextField f = new TextField(); | |||
final LegacyTextField f = new LegacyTextField(); | |||
f.setTabIndex(1); | |||
main.addComponent(f); | |||
@@ -87,7 +87,7 @@ public class ModalWindow extends com.vaadin.server.LegacyApplication implements | |||
"You have to close this window before accessing others.")); | |||
// Textfield for modal window | |||
final TextField f = new TextField(); | |||
final LegacyTextField f = new LegacyTextField(); | |||
f.setTabIndex(4); | |||
layout.addComponent(f); | |||
f.focus(); |
@@ -19,6 +19,7 @@ package com.vaadin.tests; | |||
import java.util.Date; | |||
import java.util.Map; | |||
import com.vaadin.legacy.ui.LegacyTextField; | |||
import com.vaadin.server.UserError; | |||
import com.vaadin.shared.ui.label.ContentMode; | |||
import com.vaadin.ui.Button; | |||
@@ -28,7 +29,6 @@ import com.vaadin.ui.DateField; | |||
import com.vaadin.ui.Label; | |||
import com.vaadin.ui.TabSheet; | |||
import com.vaadin.ui.Table; | |||
import com.vaadin.ui.TextField; | |||
import com.vaadin.ui.VerticalLayout; | |||
public class PerformanceTestBasicComponentRendering extends CustomComponent { | |||
@@ -80,7 +80,7 @@ public class PerformanceTestBasicComponentRendering extends CustomComponent { | |||
} | |||
testContainer.addComponent(cb); | |||
TextField tf = new TextField("TextField " + i); | |||
LegacyTextField tf = new LegacyTextField("TextField " + i); | |||
tf.setDescription("DESC SDKJSDF"); | |||
tf.setComponentError(new UserError("dsfjklsdf")); | |||
testContainer.addComponent(tf); |
@@ -18,6 +18,7 @@ package com.vaadin.tests; | |||
import java.util.Random; | |||
import com.vaadin.legacy.ui.LegacyTextField; | |||
import com.vaadin.server.ExternalResource; | |||
import com.vaadin.ui.AbstractComponent; | |||
import com.vaadin.ui.Button; | |||
@@ -32,7 +33,6 @@ import com.vaadin.ui.Link; | |||
import com.vaadin.ui.Panel; | |||
import com.vaadin.ui.Select; | |||
import com.vaadin.ui.TabSheet; | |||
import com.vaadin.ui.TextField; | |||
import com.vaadin.ui.VerticalLayout; | |||
/** | |||
@@ -149,7 +149,7 @@ public class RandomLayoutStress extends com.vaadin.server.LegacyApplication { | |||
break; | |||
case 2: | |||
// TextField | |||
result = new TextField(); | |||
result = new LegacyTextField(); | |||
result.setCaption("TextField component " + caption); | |||
break; | |||
case 3: |
@@ -16,6 +16,7 @@ | |||
package com.vaadin.tests; | |||
import com.vaadin.legacy.ui.LegacyTextField; | |||
import com.vaadin.server.ClassResource; | |||
import com.vaadin.server.ErrorMessage; | |||
import com.vaadin.server.ExternalResource; | |||
@@ -41,7 +42,6 @@ import com.vaadin.ui.Select; | |||
import com.vaadin.ui.Slider; | |||
import com.vaadin.ui.TabSheet; | |||
import com.vaadin.ui.Table; | |||
import com.vaadin.ui.TextField; | |||
import com.vaadin.ui.Tree; | |||
import com.vaadin.ui.TwinColSelect; | |||
import com.vaadin.ui.Upload; | |||
@@ -163,7 +163,7 @@ public class TestCaptionWrapper extends CustomComponent implements Listener { | |||
final Table table = new Table("Table " + count++); | |||
test(layout, table); | |||
final TextField tf = new TextField("Textfield " + count++); | |||
final LegacyTextField tf = new LegacyTextField("Textfield " + count++); | |||
test(layout, tf); | |||
final Tree tree = new Tree("Tree " + count++); |
@@ -16,12 +16,12 @@ | |||
package com.vaadin.tests; | |||
import com.vaadin.legacy.ui.LegacyTextField; | |||
import com.vaadin.ui.Alignment; | |||
import com.vaadin.ui.Button; | |||
import com.vaadin.ui.CustomComponent; | |||
import com.vaadin.ui.DateField; | |||
import com.vaadin.ui.HorizontalLayout; | |||
import com.vaadin.ui.TextField; | |||
import com.vaadin.ui.VerticalLayout; | |||
public class TestForAlignments extends CustomComponent { | |||
@@ -34,8 +34,8 @@ public class TestForAlignments extends CustomComponent { | |||
final Button b2 = new Button("Left"); | |||
final Button b3 = new Button("Bottom"); | |||
final Button b4 = new Button("Top"); | |||
final TextField t1 = new TextField("Right aligned"); | |||
final TextField t2 = new TextField("Bottom aligned"); | |||
final LegacyTextField t1 = new LegacyTextField("Right aligned"); | |||
final LegacyTextField t2 = new LegacyTextField("Bottom aligned"); | |||
final DateField d1 = new DateField("Center aligned"); | |||
final DateField d2 = new DateField("Center aligned"); | |||
@@ -17,6 +17,7 @@ | |||
package com.vaadin.tests; | |||
import com.vaadin.data.util.IndexedContainer; | |||
import com.vaadin.legacy.ui.LegacyTextField; | |||
import com.vaadin.ui.Button; | |||
import com.vaadin.ui.Button.ClickEvent; | |||
import com.vaadin.ui.CustomComponent; | |||
@@ -24,7 +25,6 @@ import com.vaadin.ui.HorizontalLayout; | |||
import com.vaadin.ui.Label; | |||
import com.vaadin.ui.Panel; | |||
import com.vaadin.ui.Table; | |||
import com.vaadin.ui.TextField; | |||
import com.vaadin.ui.VerticalLayout; | |||
public class TestForContainerFilterable extends CustomComponent { | |||
@@ -34,8 +34,8 @@ public class TestForContainerFilterable extends CustomComponent { | |||
Table t = new Table(); | |||
private static String parts[] = { "Neo", "Sa", "rem", "the", "adi", "za", | |||
"tre", "day", "Ca", "re", "cen", "ter", "mi", "nal" }; | |||
TextField fooFilter = new TextField("foo-filter"); | |||
TextField barFilter = new TextField("bar-filter"); | |||
LegacyTextField fooFilter = new LegacyTextField("foo-filter"); | |||
LegacyTextField barFilter = new LegacyTextField("bar-filter"); | |||
Button filterButton = new Button("Filter"); | |||
Label count = new Label(); | |||
@@ -30,6 +30,7 @@ import java.lang.management.MemoryMXBean; | |||
import com.vaadin.data.Property.ValueChangeEvent; | |||
import com.vaadin.legacy.ui.LegacyAbstractField; | |||
import com.vaadin.legacy.ui.LegacyTextField; | |||
import com.vaadin.server.StreamResource; | |||
import com.vaadin.shared.ui.label.ContentMode; | |||
import com.vaadin.ui.Button; | |||
@@ -43,7 +44,6 @@ import com.vaadin.ui.Link; | |||
import com.vaadin.ui.Panel; | |||
import com.vaadin.ui.ProgressIndicator; | |||
import com.vaadin.ui.Select; | |||
import com.vaadin.ui.TextField; | |||
import com.vaadin.ui.Upload; | |||
import com.vaadin.ui.Upload.FinishedEvent; | |||
import com.vaadin.ui.Upload.StartedEvent; | |||
@@ -73,7 +73,7 @@ public class TestForUpload extends CustomComponent implements | |||
private final Select uploadBufferSelector; | |||
private TextField textField; | |||
private LegacyTextField textField; | |||
private Label textFieldValue; | |||
@@ -99,7 +99,7 @@ public class TestForUpload extends CustomComponent implements | |||
main.addComponent(new Label( | |||
"Clicking on button b updates information about upload components status or same with garbage collector.")); | |||
textField = new TextField("Test field"); | |||
textField = new LegacyTextField("Test field"); | |||
textFieldValue = new Label(); | |||
main.addComponent(textField); | |||
main.addComponent(textFieldValue); |
@@ -1,16 +1,16 @@ | |||
package com.vaadin.tests.actions; | |||
import com.vaadin.event.Action; | |||
import com.vaadin.legacy.ui.LegacyTextField; | |||
import com.vaadin.server.VaadinRequest; | |||
import com.vaadin.tests.components.AbstractTestUIWithLog; | |||
import com.vaadin.ui.TextField; | |||
@SuppressWarnings("serial") | |||
public class ActionsWithoutKeyCode extends AbstractTestUIWithLog { | |||
@Override | |||
protected void setup(VaadinRequest request) { | |||
TextField tf = new TextField(); | |||
LegacyTextField tf = new LegacyTextField(); | |||
tf.setWidth("100%"); | |||
tf.setInputPrompt("Enter text with å,ä or ä or press windows key while textfield is focused"); | |||
addComponent(tf); |
@@ -3,6 +3,7 @@ package com.vaadin.tests.appengine; | |||
import com.google.apphosting.api.DeadlineExceededException; | |||
import com.vaadin.data.Property; | |||
import com.vaadin.data.Property.ValueChangeEvent; | |||
import com.vaadin.legacy.ui.LegacyTextField; | |||
import com.vaadin.server.ClassResource; | |||
import com.vaadin.server.DownloadStream; | |||
import com.vaadin.server.LegacyApplication; | |||
@@ -13,7 +14,6 @@ import com.vaadin.ui.GridLayout; | |||
import com.vaadin.ui.Label; | |||
import com.vaadin.ui.LegacyWindow; | |||
import com.vaadin.ui.Notification; | |||
import com.vaadin.ui.TextField; | |||
public class GAESyncTest extends LegacyApplication { | |||
@@ -48,7 +48,7 @@ public class GAESyncTest extends LegacyApplication { | |||
private class IntrWindow extends LegacyWindow { | |||
private int n = 0; | |||
private static final long serialVersionUID = -6521351715072191625l; | |||
TextField tf; | |||
LegacyTextField tf; | |||
Label l; | |||
LegacyApplication app; | |||
GridLayout gl; | |||
@@ -56,7 +56,7 @@ public class GAESyncTest extends LegacyApplication { | |||
private IntrWindow(LegacyApplication app) { | |||
this.app = app; | |||
tf = new TextField("Echo thingie"); | |||
tf = new LegacyTextField("Echo thingie"); | |||
tf.setImmediate(true); | |||
tf.addListener(new Property.ValueChangeListener() { | |||
@Override |
@@ -18,6 +18,7 @@ package com.vaadin.tests.application; | |||
import com.vaadin.annotations.Theme; | |||
import com.vaadin.data.Property.ValueChangeEvent; | |||
import com.vaadin.data.Property.ValueChangeListener; | |||
import com.vaadin.legacy.ui.LegacyTextField; | |||
import com.vaadin.server.VaadinRequest; | |||
import com.vaadin.server.VaadinServlet; | |||
import com.vaadin.tests.components.AbstractTestUIWithLog; | |||
@@ -30,7 +31,6 @@ import com.vaadin.ui.Component; | |||
import com.vaadin.ui.HorizontalLayout; | |||
import com.vaadin.ui.Label; | |||
import com.vaadin.ui.Panel; | |||
import com.vaadin.ui.TextField; | |||
import com.vaadin.ui.VerticalLayout; | |||
/** | |||
@@ -129,7 +129,7 @@ public class CommErrorEmulatorUI extends AbstractTestUIWithLog { | |||
private Component createConfigPanel() { | |||
Panel p = new Panel("Reconnect dialog configuration"); | |||
p.setSizeUndefined(); | |||
final TextField reconnectDialogMessage = new TextField( | |||
final LegacyTextField reconnectDialogMessage = new LegacyTextField( | |||
"Reconnect message"); | |||
reconnectDialogMessage.setWidth("50em"); | |||
reconnectDialogMessage.setValue(getReconnectDialogConfiguration() | |||
@@ -143,7 +143,7 @@ public class CommErrorEmulatorUI extends AbstractTestUIWithLog { | |||
} | |||
}); | |||
final TextField reconnectDialogGaveUpMessage = new TextField( | |||
final LegacyTextField reconnectDialogGaveUpMessage = new LegacyTextField( | |||
"Reconnect gave up message"); | |||
reconnectDialogGaveUpMessage.setWidth("50em"); | |||
@@ -157,7 +157,7 @@ public class CommErrorEmulatorUI extends AbstractTestUIWithLog { | |||
reconnectDialogGaveUpMessage.getValue()); | |||
} | |||
}); | |||
final TextField reconnectDialogReconnectAttempts = new TextField( | |||
final LegacyTextField reconnectDialogReconnectAttempts = new LegacyTextField( | |||
"Reconnect attempts"); | |||
reconnectDialogReconnectAttempts.setConverter(Integer.class); | |||
reconnectDialogReconnectAttempts | |||
@@ -172,7 +172,7 @@ public class CommErrorEmulatorUI extends AbstractTestUIWithLog { | |||
.getConvertedValue()); | |||
} | |||
}); | |||
final TextField reconnectDialogReconnectInterval = new TextField( | |||
final LegacyTextField reconnectDialogReconnectInterval = new LegacyTextField( | |||
"Reconnect interval (ms)"); | |||
reconnectDialogReconnectInterval.setConverter(Integer.class); | |||
reconnectDialogReconnectInterval | |||
@@ -188,7 +188,7 @@ public class CommErrorEmulatorUI extends AbstractTestUIWithLog { | |||
} | |||
}); | |||
final TextField reconnectDialogGracePeriod = new TextField( | |||
final LegacyTextField reconnectDialogGracePeriod = new LegacyTextField( | |||
"Reconnect dialog grace period (ms)"); | |||
reconnectDialogGracePeriod.setConverter(Integer.class); | |||
reconnectDialogGracePeriod | |||
@@ -230,11 +230,11 @@ public class CommErrorEmulatorUI extends AbstractTestUIWithLog { | |||
hl.setSpacing(true); | |||
hl.setDefaultComponentAlignment(Alignment.MIDDLE_LEFT); | |||
Label l1 = new Label("Respond to " + type + " requests with code"); | |||
final TextField responseCode = new TextField(null, "" + response.code); | |||
final LegacyTextField responseCode = new LegacyTextField(null, "" + response.code); | |||
responseCode.setConverter(Integer.class); | |||
responseCode.setWidth("5em"); | |||
Label l2 = new Label("for the following"); | |||
final TextField timeField = new TextField(null, "" + response.time); | |||
final LegacyTextField timeField = new LegacyTextField(null, "" + response.time); | |||
timeField.setConverter(Integer.class); | |||
timeField.setWidth("5em"); | |||
Label l3 = new Label("seconds"); |
@@ -16,6 +16,7 @@ | |||
package com.vaadin.tests.application.calculator; | |||
import com.vaadin.legacy.ui.LegacyTextField; | |||
import com.vaadin.server.VaadinRequest; | |||
import com.vaadin.tests.components.AbstractTestUI; | |||
import com.vaadin.ui.Alignment; | |||
@@ -27,7 +28,6 @@ import com.vaadin.ui.HorizontalLayout; | |||
import com.vaadin.ui.Label; | |||
import com.vaadin.ui.Table; | |||
import com.vaadin.ui.Table.ColumnHeaderMode; | |||
import com.vaadin.ui.TextField; | |||
import com.vaadin.ui.VerticalLayout; | |||
import com.vaadin.ui.Window; | |||
@@ -65,7 +65,7 @@ public class Calc extends AbstractTestUI { | |||
VerticalLayout vl = new VerticalLayout(); | |||
vl.setMargin(true); | |||
final TextField tf = new TextField(); | |||
final LegacyTextField tf = new LegacyTextField(); | |||
tf.setSizeFull(); | |||
vl.addComponent(tf); | |||
@@ -128,7 +128,7 @@ public class Calc extends AbstractTestUI { | |||
private VerticalLayout topLayout = new VerticalLayout(); | |||
// User interface components | |||
private final TextField display = new TextField(); | |||
private final LegacyTextField display = new LegacyTextField(); | |||
private final Log log = new Log(); | |||
@@ -4,6 +4,7 @@ import java.util.HashSet; | |||
import java.util.Iterator; | |||
import java.util.LinkedHashMap; | |||
import com.vaadin.legacy.ui.LegacyTextField; | |||
import com.vaadin.ui.AbstractComponentContainer; | |||
import com.vaadin.ui.Button; | |||
import com.vaadin.ui.Component; | |||
@@ -19,7 +20,6 @@ import com.vaadin.ui.RichTextArea; | |||
import com.vaadin.ui.TabSheet; | |||
import com.vaadin.ui.Table; | |||
import com.vaadin.ui.TextArea; | |||
import com.vaadin.ui.TextField; | |||
import com.vaadin.ui.VerticalSplitPanel; | |||
public abstract class AbstractComponentContainerTest<T extends AbstractComponentContainer> | |||
@@ -68,7 +68,7 @@ public abstract class AbstractComponentContainerTest<T extends AbstractComponent | |||
private Command<T, ComponentSize> addTextFieldCommand = new Command<T, ComponentSize>() { | |||
@Override | |||
public void execute(T c, ComponentSize size, Object data) { | |||
TextField tf = new TextField(); | |||
LegacyTextField tf = new LegacyTextField(); | |||
c.addComponent(tf); | |||
size.apply(tf); | |||
} |
@@ -15,10 +15,10 @@ | |||
*/ | |||
package com.vaadin.tests.components; | |||
import com.vaadin.legacy.ui.LegacyTextField; | |||
import com.vaadin.server.VaadinRequest; | |||
import com.vaadin.ui.Label; | |||
import com.vaadin.ui.Panel; | |||
import com.vaadin.ui.TextField; | |||
import com.vaadin.ui.VerticalLayout; | |||
/** | |||
@@ -34,7 +34,7 @@ public class AbstractOrderedLayoutWithCaptions extends AbstractTestUI { | |||
VerticalLayout layout = new VerticalLayout(); | |||
layout.setSizeFull(); | |||
TextField textField = new TextField("Input Text:"); | |||
LegacyTextField textField = new LegacyTextField("Input Text:"); | |||
Label label1 = new Label("LABEL 1"); | |||
Label label2 = new Label("LABEL 2"); | |||
@@ -2,6 +2,7 @@ package com.vaadin.tests.components; | |||
import java.util.Iterator; | |||
import com.vaadin.legacy.ui.LegacyTextField; | |||
import com.vaadin.ui.Button; | |||
import com.vaadin.ui.Button.ClickEvent; | |||
import com.vaadin.ui.Button.ClickListener; | |||
@@ -10,7 +11,6 @@ import com.vaadin.ui.NativeButton; | |||
import com.vaadin.ui.Panel; | |||
import com.vaadin.ui.TabSheet; | |||
import com.vaadin.ui.TextArea; | |||
import com.vaadin.ui.TextField; | |||
import com.vaadin.ui.VerticalLayout; | |||
public class DisableEnableCascadeStyles extends TestBase { | |||
@@ -19,7 +19,7 @@ public class DisableEnableCascadeStyles extends TestBase { | |||
private TabSheet innerTabsheet; | |||
private Button button; | |||
private TextArea textArea; | |||
private TextField textField; | |||
private LegacyTextField textField; | |||
private VerticalLayout layout; | |||
private NativeButton nativeButton; | |||
private Button enableDisablePanelButton; | |||
@@ -36,7 +36,7 @@ public class DisableEnableCascadeStyles extends TestBase { | |||
button = new Button("Button, enabled"); | |||
nativeButton = new NativeButton("NativeButton, enabled"); | |||
textField = new TextField("TextField with caption and value, enabled"); | |||
textField = new LegacyTextField("TextField with caption and value, enabled"); | |||
textField.setValue("Text"); | |||
textArea = new TextArea("TextArea with caption and value, enabled"); | |||
textArea.setValue("Text"); |
@@ -3,11 +3,11 @@ package com.vaadin.tests.components; | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
import com.vaadin.legacy.ui.LegacyTextField; | |||
import com.vaadin.server.CompositeErrorMessage; | |||
import com.vaadin.server.UserError; | |||
import com.vaadin.ui.Button; | |||
import com.vaadin.ui.ComboBox; | |||
import com.vaadin.ui.TextField; | |||
public class ErrorMessages extends TestBase { | |||
@@ -20,7 +20,7 @@ public class ErrorMessages extends TestBase { | |||
bb.setComponentError(new CompositeErrorMessage(errors)); | |||
addComponent(bb); | |||
TextField tf = new TextField("", "Textfield with UserError"); | |||
LegacyTextField tf = new LegacyTextField("", "Textfield with UserError"); | |||
tf.setComponentError(new UserError("This is a failure")); | |||
addComponent(tf); | |||
@@ -6,6 +6,7 @@ import com.vaadin.event.FieldEvents.BlurEvent; | |||
import com.vaadin.event.FieldEvents.BlurListener; | |||
import com.vaadin.event.FieldEvents.FocusEvent; | |||
import com.vaadin.event.FieldEvents.FocusListener; | |||
import com.vaadin.legacy.ui.LegacyTextField; | |||
import com.vaadin.ui.Button; | |||
import com.vaadin.ui.Button.ClickEvent; | |||
import com.vaadin.ui.Button.ClickListener; | |||
@@ -16,7 +17,6 @@ import com.vaadin.ui.Label; | |||
import com.vaadin.ui.Layout; | |||
import com.vaadin.ui.NativeButton; | |||
import com.vaadin.ui.OptionGroup; | |||
import com.vaadin.ui.TextField; | |||
import com.vaadin.ui.VerticalLayout; | |||
public class FocusAndBlurListeners extends TestBase { | |||
@@ -46,7 +46,7 @@ public class FocusAndBlurListeners extends TestBase { | |||
protected void setup() { | |||
Layout l = getLayout(); | |||
TextField tf = new TextField("TextField"); | |||
LegacyTextField tf = new LegacyTextField("TextField"); | |||
l.addComponent(tf); | |||
DateField df = new DateField("DateField"); |
@@ -4,10 +4,10 @@ import java.util.Arrays; | |||
import com.vaadin.event.ShortcutAction.KeyCode; | |||
import com.vaadin.event.ShortcutAction.ModifierKey; | |||
import com.vaadin.legacy.ui.LegacyTextField; | |||
import com.vaadin.ui.Button; | |||
import com.vaadin.ui.Button.ClickEvent; | |||
import com.vaadin.ui.Select; | |||
import com.vaadin.ui.TextField; | |||
public class FocusFromShortcutAction extends TestBase { | |||
@@ -15,7 +15,7 @@ public class FocusFromShortcutAction extends TestBase { | |||
protected void setup() { | |||
final Select select = new Select("Select", Arrays.asList("Option 1", | |||
"Option 2")); | |||
final TextField text = new TextField("Text"); | |||
final LegacyTextField text = new LegacyTextField("Text"); | |||
addComponent(select); | |||
addComponent(text); |
@@ -1,7 +1,7 @@ | |||
package com.vaadin.tests.components; | |||
import com.vaadin.legacy.ui.LegacyTextField; | |||
import com.vaadin.ui.Button; | |||
import com.vaadin.ui.TextField; | |||
public class MultipleDebugIds extends TestBase { | |||
@@ -17,8 +17,8 @@ public class MultipleDebugIds extends TestBase { | |||
@Override | |||
protected void setup() { | |||
TextField textField = new TextField(); | |||
TextField textField2 = new TextField(); | |||
LegacyTextField textField = new LegacyTextField(); | |||
LegacyTextField textField2 = new LegacyTextField(); | |||
Button button = new Button(); | |||
Button button2 = new Button(); | |||
textField.setId("textfield"); |
@@ -6,9 +6,9 @@ import javax.validation.constraints.NotNull; | |||
import com.vaadin.annotations.Viewport; | |||
import com.vaadin.legacy.data.util.converter.LegacyStringToIntegerConverter; | |||
import com.vaadin.legacy.data.validator.LegacyIntegerRangeValidator; | |||
import com.vaadin.legacy.ui.LegacyTextField; | |||
import com.vaadin.server.VaadinRequest; | |||
import com.vaadin.ui.Label; | |||
import com.vaadin.ui.TextField; | |||
@Viewport(value = "width=device-width,height=device-height") | |||
public class TouchDevicesTooltip extends AbstractTestUI { | |||
@@ -24,7 +24,7 @@ public class TouchDevicesTooltip extends AbstractTestUI { | |||
} | |||
private void createTextField(int n) { | |||
TextField textField = new TextField("Value" + n); | |||
LegacyTextField textField = new LegacyTextField("Value" + n); | |||
textField.setConverter(new LegacyStringToIntegerConverter()); | |||
textField.addValidator( | |||
new LegacyIntegerRangeValidator(getErrorMessage(n), 0, 100)); |
@@ -15,6 +15,7 @@ | |||
*/ | |||
package com.vaadin.tests.components.absolutelayout; | |||
import com.vaadin.legacy.ui.LegacyTextField; | |||
import com.vaadin.server.ThemeResource; | |||
import com.vaadin.server.VaadinRequest; | |||
import com.vaadin.tests.components.AbstractTestUI; | |||
@@ -27,7 +28,6 @@ import com.vaadin.ui.GridLayout; | |||
import com.vaadin.ui.HorizontalLayout; | |||
import com.vaadin.ui.Label; | |||
import com.vaadin.ui.PasswordField; | |||
import com.vaadin.ui.TextField; | |||
import com.vaadin.ui.VerticalLayout; | |||
public class AbsoluteLayoutHideComponent extends AbstractTestUI { | |||
@@ -35,7 +35,7 @@ public class AbsoluteLayoutHideComponent extends AbstractTestUI { | |||
private AbsoluteLayout mainLayout; | |||
private VerticalLayout topBar = new VerticalLayout(); | |||
private GridLayout menu; | |||
private TextField editEmail = new TextField(); | |||
private LegacyTextField editEmail = new LegacyTextField(); | |||
private PasswordField editPassword = new PasswordField(); | |||
@Override |
@@ -15,12 +15,12 @@ | |||
*/ | |||
package com.vaadin.tests.components.abstractcomponent; | |||
import com.vaadin.legacy.ui.LegacyTextField; | |||
import com.vaadin.server.VaadinRequest; | |||
import com.vaadin.tests.components.AbstractTestUI; | |||
import com.vaadin.ui.Button; | |||
import com.vaadin.ui.Button.ClickEvent; | |||
import com.vaadin.ui.Label; | |||
import com.vaadin.ui.TextField; | |||
public class PrimaryStyle extends AbstractTestUI { | |||
@@ -37,7 +37,7 @@ public class PrimaryStyle extends AbstractTestUI { | |||
button.setStyleName("state"); | |||
addComponent(button); | |||
final TextField tf = new TextField("Test TextField"); | |||
final LegacyTextField tf = new LegacyTextField("Test TextField"); | |||
tf.setPrimaryStyleName("initial"); | |||
tf.setStyleName("state"); | |||
addComponent(tf); |
@@ -2,16 +2,16 @@ package com.vaadin.tests.components.abstractfield; | |||
import com.vaadin.data.util.ObjectProperty; | |||
import com.vaadin.legacy.data.validator.LegacyStringLengthValidator; | |||
import com.vaadin.legacy.ui.LegacyTextField; | |||
import com.vaadin.tests.components.TestBase; | |||
import com.vaadin.ui.Button; | |||
import com.vaadin.ui.Button.ClickEvent; | |||
import com.vaadin.ui.Button.ClickListener; | |||
import com.vaadin.ui.Notification; | |||
import com.vaadin.ui.TextField; | |||
public class AbstractFieldCommitWithInvalidValues extends TestBase { | |||
private TextField tf; | |||
private LegacyTextField tf; | |||
@Override | |||
protected String getDescription() { | |||
@@ -25,7 +25,7 @@ public class AbstractFieldCommitWithInvalidValues extends TestBase { | |||
@Override | |||
protected void setup() { | |||
tf = new TextField("A field, must contain 1-2 chars", | |||
tf = new LegacyTextField("A field, must contain 1-2 chars", | |||
new ObjectProperty<String>("a")); | |||
tf.addValidator( | |||
new LegacyStringLengthValidator("Invalid length", 1, 2, false)); |
@@ -1,11 +1,11 @@ | |||
package com.vaadin.tests.components.abstractfield; | |||
import com.vaadin.data.util.ObjectProperty; | |||
import com.vaadin.legacy.ui.LegacyTextField; | |||
import com.vaadin.tests.components.TestBase; | |||
import com.vaadin.ui.Button; | |||
import com.vaadin.ui.Component.Event; | |||
import com.vaadin.ui.Component.Listener; | |||
import com.vaadin.ui.TextField; | |||
public class AbstractFieldDataSourceReadOnly extends TestBase { | |||
@@ -41,7 +41,7 @@ public class AbstractFieldDataSourceReadOnly extends TestBase { | |||
}); | |||
// Input field | |||
TextField input = new TextField("Field"); | |||
LegacyTextField input = new LegacyTextField("Field"); | |||
input.setPropertyDataSource(stateHolder.getTextField()); | |||
addComponent(button); |