Synchronises parts of compatibility package code to match 7.7 Picks suitable patches for 8 code as welltags/8.1.0.alpha1
@@ -17,6 +17,7 @@ package com.vaadin.client.connectors; | |||
import java.util.ArrayList; | |||
import java.util.Collection; | |||
import java.util.logging.Logger; | |||
import com.google.gwt.core.client.JavaScriptObject; | |||
import com.google.gwt.core.client.JsArrayString; | |||
@@ -64,7 +65,7 @@ public class JavaScriptRendererConnector | |||
private static native JavaScriptObject createCellReferenceWrapper() | |||
/*-{ | |||
var reference = {}; | |||
var setProperty = function(name, getter, setter) { | |||
var descriptor = { | |||
get: getter | |||
@@ -74,25 +75,25 @@ public class JavaScriptRendererConnector | |||
} | |||
Object.defineProperty(reference, name, descriptor); | |||
}; | |||
setProperty("element", function() { | |||
return reference.target.@CellReference::getElement()(); | |||
}, null); | |||
setProperty("rowIndex", function() { | |||
return reference.target.@CellReference::getRowIndex()(); | |||
}, null); | |||
setProperty("columnIndex", function() { | |||
return reference.target.@CellReference::getColumnIndex()(); | |||
}, null); | |||
setProperty("colSpan", function() { | |||
return reference.target.@RendererCellReference::getColSpan()(); | |||
}, function(colSpan) { | |||
reference.target.@RendererCellReference::setColSpan(*)(colSpan); | |||
}); | |||
return reference; | |||
}-*/; | |||
@@ -136,8 +137,15 @@ public class JavaScriptRendererConnector | |||
+ " must have a function named 'render'"); | |||
} | |||
if (hasFunction("destory")) { | |||
getLogger().severe("Your JavaScript connector (" | |||
+ helper.getInitFunctionName() | |||
+ ") has a typo. The destory method should be renamed to destroy."); | |||
} | |||
final boolean hasInit = hasFunction("init"); | |||
final boolean hasDestroy = hasFunction("destroy"); | |||
final boolean hasDestroy = hasFunction("destroy") | |||
|| hasFunction("destory"); | |||
final boolean hasOnActivate = hasFunction("onActivate"); | |||
final boolean hasGetConsumedEvents = hasFunction("getConsumedEvents"); | |||
final boolean hasOnBrowserEvent = hasFunction("onBrowserEvent"); | |||
@@ -183,17 +191,23 @@ public class JavaScriptRendererConnector | |||
@Override | |||
public void destroy(RendererCellReference cell) { | |||
getLogger().warning("Destprying: " + cell.getRowIndex() + " " | |||
+ cell.getColumnIndexDOM()); | |||
if (hasDestroy) { | |||
destory(helper.getConnectorWrapper(), getJsCell(cell)); | |||
destroy(helper.getConnectorWrapper(), getJsCell(cell)); | |||
} else { | |||
super.destroy(cell); | |||
} | |||
} | |||
private native void destory(JavaScriptObject wrapper, | |||
private native void destroy(JavaScriptObject wrapper, | |||
JavaScriptObject cell) | |||
/*-{ | |||
wrapper.destory(cell); | |||
if (wrapper.destroy) { | |||
wrapper.destroy(cell); | |||
} else if (wrapper.destory) { | |||
wrapper.destory(cell); | |||
} | |||
}-*/; | |||
@Override | |||
@@ -258,6 +272,10 @@ public class JavaScriptRendererConnector | |||
}; | |||
} | |||
private Logger getLogger() { | |||
return Logger.getLogger(JavaScriptRendererConnector.class.getName()); | |||
} | |||
@Override | |||
public Object decode(JsonValue value) { | |||
// Let the js logic decode the raw json that the server sent |
@@ -29,7 +29,7 @@ import com.vaadin.client.widget.grid.RendererCellReference; | |||
*/ | |||
public class ImageRenderer extends ClickableRenderer<String, Image> { | |||
public static final String TRANSPARENT_GIF_1PX = "data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs="; | |||
public static final String TRANSPARENT_GIF_1PX = "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7"; | |||
@Override | |||
public Image createWidget() { |
@@ -87,7 +87,7 @@ import com.vaadin.shared.util.SharedUtil; | |||
* Client side implementation of the ComboBox component. | |||
* | |||
* TODO needs major refactoring (to be extensible etc) | |||
* | |||
* | |||
* @since 8.0 | |||
*/ | |||
@SuppressWarnings("deprecation") | |||
@@ -243,12 +243,12 @@ public class VComboBox extends Composite implements Field, KeyDownHandler, | |||
return $entry(function(e) { | |||
var deltaX = e.deltaX ? e.deltaX : -0.5*e.wheelDeltaX; | |||
var deltaY = e.deltaY ? e.deltaY : -0.5*e.wheelDeltaY; | |||
// IE8 has only delta y | |||
if (isNaN(deltaY)) { | |||
deltaY = -0.5*e.wheelDelta; | |||
} | |||
@com.vaadin.client.ui.VComboBox.JsniUtil::moveScrollFromEvent(*)(widget, deltaX, deltaY, e, e.deltaMode); | |||
}); | |||
}-*/; |
@@ -305,10 +305,12 @@ public class VCustomLayout extends ComplexPanel { | |||
*/ | |||
public void updateCaption(ComponentConnector childConnector) { | |||
Widget widget = childConnector.getWidget(); | |||
if (widget.getParent() != this) { | |||
if (!widget.isAttached()) { | |||
// Widget has not been added because the location was not found | |||
return; | |||
} | |||
VCaptionWrapper wrapper = childWidgetToCaptionWrapper.get(widget); | |||
if (VCaption.isNeeded(childConnector)) { | |||
if (wrapper == null) { |
@@ -392,6 +392,7 @@ public class VDragAndDropWrapper extends VCustomComponent | |||
public boolean html5DragDrop(VHtml5DragEvent event) { | |||
if (dropHandler == null || !currentlyValid) { | |||
VDragAndDropManager.get().interruptDrag(); | |||
return true; | |||
} | |||
try { | |||
@@ -466,11 +467,11 @@ public class VDragAndDropWrapper extends VCustomComponent | |||
public final native void postFile(VHtml5File file) | |||
/*-{ | |||
this.setRequestHeader('Content-Type', 'multipart/form-data'); | |||
// Seems like IE10 will loose the file if we don't keep a reference to it... | |||
this.fileBeingUploaded = file; | |||
this.send(file); | |||
}-*/; | |||
@@ -626,19 +627,19 @@ public class VDragAndDropWrapper extends VCustomComponent | |||
protected native void hookHtml5Events(com.google.gwt.user.client.Element el) | |||
/*-{ | |||
var me = this; | |||
el.addEventListener("dragenter", $entry(function(ev) { | |||
return me.@com.vaadin.client.ui.VDragAndDropWrapper::html5DragEnter(Lcom/vaadin/client/ui/dd/VHtml5DragEvent;)(ev); | |||
}), false); | |||
el.addEventListener("dragleave", $entry(function(ev) { | |||
return me.@com.vaadin.client.ui.VDragAndDropWrapper::html5DragLeave(Lcom/vaadin/client/ui/dd/VHtml5DragEvent;)(ev); | |||
}), false); | |||
el.addEventListener("dragover", $entry(function(ev) { | |||
return me.@com.vaadin.client.ui.VDragAndDropWrapper::html5DragOver(Lcom/vaadin/client/ui/dd/VHtml5DragEvent;)(ev); | |||
}), false); | |||
el.addEventListener("drop", $entry(function(ev) { | |||
return me.@com.vaadin.client.ui.VDragAndDropWrapper::html5DragDrop(Lcom/vaadin/client/ui/dd/VHtml5DragEvent;)(ev); | |||
}), false); |
@@ -691,6 +691,8 @@ public class VWindow extends VOverlay implements ShortcutActionHandlerOwner, | |||
public void hide() { | |||
if (vaadinModality) { | |||
hideModalityCurtain(); | |||
hideDraggingCurtain(); | |||
hideResizingCurtain(); | |||
} | |||
super.hide(); | |||
@@ -55,9 +55,9 @@ public interface EditorHandler<T> { | |||
public int getRowIndex(); | |||
/** | |||
* Returns the index of the column being focused. | |||
* Returns the DOM index of the column being focused. | |||
* | |||
* @return the column index | |||
* @return the column index (excluding hidden columns) | |||
*/ | |||
public int getColumnIndex(); | |||
@@ -31,4 +31,4 @@ public interface GridEventHandler<T> { | |||
* the event that occurred | |||
*/ | |||
public void onEvent(GridEvent<T> event); | |||
} | |||
} |
@@ -1097,15 +1097,15 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>, | |||
private Grid<T> grid; | |||
private final int rowIndex; | |||
private final int columnIndex; | |||
private final int columnIndexDOM; | |||
private RequestCallback<T> callback; | |||
private boolean completed = false; | |||
public EditorRequestImpl(Grid<T> grid, int rowIndex, int columnIndex, | |||
public EditorRequestImpl(Grid<T> grid, int rowIndex, int columnIndexDOM, | |||
RequestCallback<T> callback) { | |||
this.grid = grid; | |||
this.rowIndex = rowIndex; | |||
this.columnIndex = columnIndex; | |||
this.columnIndexDOM = columnIndexDOM; | |||
this.callback = callback; | |||
} | |||
@@ -1116,7 +1116,7 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>, | |||
@Override | |||
public int getColumnIndex() { | |||
return columnIndex; | |||
return columnIndexDOM; | |||
} | |||
@Override | |||
@@ -1285,13 +1285,13 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>, | |||
} | |||
/** | |||
* Returns the column index the editor was opened at. If the editor is | |||
* not open, returns -1. | |||
* Returns the DOM column index (excluding hidden columns) the editor | |||
* was opened at. If the editor is not open, returns -1. | |||
* | |||
* @return the column index or -1 if editor is not open | |||
*/ | |||
public int getFocusedColumnIndex() { | |||
return getEditor().focusedColumnIndex; | |||
return getEditor().focusedColumnIndexDOM; | |||
} | |||
} | |||
@@ -1362,7 +1362,7 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>, | |||
private boolean enabled = false; | |||
private State state = State.INACTIVE; | |||
private int rowIndex = -1; | |||
private int focusedColumnIndex = -1; | |||
private int focusedColumnIndexDOM = -1; | |||
private String styleName = null; | |||
private HandlerRegistration hScrollHandler; | |||
@@ -1427,10 +1427,10 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>, | |||
bindTimeout.cancel(); | |||
rowIndex = request.getRowIndex(); | |||
focusedColumnIndex = request.getColumnIndex(); | |||
if (focusedColumnIndex >= 0) { | |||
focusedColumnIndexDOM = request.getColumnIndex(); | |||
if (focusedColumnIndexDOM >= 0) { | |||
// Update internal focus of Grid | |||
grid.focusCell(rowIndex, focusedColumnIndex); | |||
grid.focusCell(rowIndex, focusedColumnIndexDOM); | |||
} | |||
showOverlay(); | |||
@@ -1539,9 +1539,10 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>, | |||
* | |||
* @param rowIndex | |||
* the index of the row to be edited | |||
* @param columnIndex | |||
* the column index of the editor widget that should be | |||
* initially focused or -1 to not set focus | |||
* @param columnIndexDOM | |||
* the column index (excluding hidden columns) of the editor | |||
* widget that should be initially focused or -1 to not set | |||
* focus | |||
* | |||
* @throws IllegalStateException | |||
* if this editor is not enabled | |||
@@ -1551,7 +1552,7 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>, | |||
* | |||
* @since 7.5 | |||
*/ | |||
public void editRow(final int rowIndex, final int columnIndex) { | |||
public void editRow(final int rowIndex, final int columnIndexDOM) { | |||
if (!enabled) { | |||
throw new IllegalStateException( | |||
"Cannot edit row: editor is not enabled"); | |||
@@ -1576,35 +1577,35 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>, | |||
return; | |||
} | |||
} | |||
if (columnIndex >= grid.getVisibleColumns().size()) { | |||
if (columnIndexDOM >= grid.getVisibleColumns().size()) { | |||
throw new IllegalArgumentException( | |||
"Edited column index " + columnIndex | |||
"Edited column index " + columnIndexDOM | |||
+ " was bigger than visible column count."); | |||
} | |||
if (this.rowIndex == rowIndex | |||
&& focusedColumnIndex == columnIndex) { | |||
&& focusedColumnIndexDOM == columnIndexDOM) { | |||
// NO-OP | |||
return; | |||
} | |||
if (this.rowIndex == rowIndex) { | |||
if (focusedColumnIndex != columnIndex) { | |||
if (columnIndex >= grid.getFrozenColumnCount()) { | |||
if (focusedColumnIndexDOM != columnIndexDOM) { | |||
if (columnIndexDOM >= grid.getFrozenColumnCount()) { | |||
// Scroll to new focused column. | |||
grid.getEscalator().scrollToColumn(columnIndex, | |||
grid.getEscalator().scrollToColumn(columnIndexDOM, | |||
ScrollDestination.ANY, 0); | |||
} | |||
focusedColumnIndex = columnIndex; | |||
focusedColumnIndexDOM = columnIndexDOM; | |||
} | |||
updateHorizontalScrollPosition(); | |||
// Update Grid internal focus and focus widget if possible | |||
if (focusedColumnIndex >= 0) { | |||
grid.focusCell(rowIndex, focusedColumnIndex); | |||
focusColumn(focusedColumnIndex); | |||
if (focusedColumnIndexDOM >= 0) { | |||
grid.focusCell(rowIndex, focusedColumnIndexDOM); | |||
focusColumn(focusedColumnIndexDOM); | |||
} | |||
// No need to request anything from the editor handler. | |||
@@ -1614,13 +1615,13 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>, | |||
final Escalator escalator = grid.getEscalator(); | |||
if (escalator.getVisibleRowRange().contains(rowIndex)) { | |||
show(rowIndex, columnIndex); | |||
show(rowIndex, columnIndexDOM); | |||
} else { | |||
vScrollHandler = grid.addScrollHandler(new ScrollHandler() { | |||
@Override | |||
public void onScroll(ScrollEvent event) { | |||
if (escalator.getVisibleRowRange().contains(rowIndex)) { | |||
show(rowIndex, columnIndex); | |||
show(rowIndex, columnIndexDOM); | |||
vScrollHandler.removeHandler(); | |||
} | |||
} | |||
@@ -1653,7 +1654,7 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>, | |||
"Cannot cancel edit: editor is not in edit mode"); | |||
} | |||
handler.cancel(new EditorRequestImpl<>(grid, rowIndex, | |||
focusedColumnIndex, null), afterSave); | |||
focusedColumnIndexDOM, null), afterSave); | |||
doCancel(); | |||
} | |||
@@ -1661,7 +1662,7 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>, | |||
hideOverlay(); | |||
state = State.INACTIVE; | |||
rowIndex = -1; | |||
focusedColumnIndex = -1; | |||
focusedColumnIndexDOM = -1; | |||
grid.getEscalator().setScrollLocked(Direction.VERTICAL, false); | |||
updateSelectionCheckboxesAsNeeded(true); | |||
} | |||
@@ -1699,7 +1700,7 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>, | |||
setButtonsEnabled(false); | |||
saveTimeout.schedule(SAVE_TIMEOUT_MS); | |||
EditorRequest<T> request = new EditorRequestImpl<>(grid, rowIndex, | |||
focusedColumnIndex, saveRequestCallback); | |||
focusedColumnIndexDOM, saveRequestCallback); | |||
handler.save(request); | |||
updateSelectionCheckboxesAsNeeded(true); | |||
} | |||
@@ -1871,8 +1872,8 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>, | |||
grid.attachWidget(editor, cell); | |||
} | |||
if (i == focusedColumnIndex) { | |||
focusColumn(focusedColumnIndex); | |||
if (i == focusedColumnIndexDOM) { | |||
focusColumn(focusedColumnIndexDOM); | |||
} | |||
} else { | |||
cell.addClassName(NOT_EDITABLE_CLASS_NAME); | |||
@@ -1972,13 +1973,14 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>, | |||
Unit.PX); | |||
} | |||
private void focusColumn(int colIndex) { | |||
if (colIndex < 0 || colIndex >= grid.getVisibleColumns().size()) { | |||
private void focusColumn(int columnIndexDOM) { | |||
if (columnIndexDOM < 0 | |||
|| columnIndexDOM >= grid.getVisibleColumns().size()) { | |||
// NO-OP | |||
return; | |||
} | |||
Widget editor = getWidget(grid.getVisibleColumn(colIndex)); | |||
Widget editor = getWidget(grid.getVisibleColumn(columnIndexDOM)); | |||
if (editor instanceof Focusable) { | |||
((Focusable) editor).focus(); | |||
} else if (editor instanceof com.google.gwt.user.client.ui.Focusable) { | |||
@@ -2563,9 +2565,7 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>, | |||
++i; | |||
} while (cell != null); | |||
} | |||
int columnIndex = getColumns() | |||
.indexOf(getVisibleColumn(columnIndexDOM)); | |||
if (columnIndex >= escalator.getColumnConfiguration() | |||
if (columnIndexDOM >= escalator.getColumnConfiguration() | |||
.getFrozenColumnCount()) { | |||
escalator.scrollToColumn(columnIndexDOM, ScrollDestination.ANY, | |||
10); | |||
@@ -6278,21 +6278,22 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>, | |||
* | |||
* @param rowIndex | |||
* index of row to focus | |||
* @param columnIndex | |||
* index of cell to focus | |||
* @param columnIndexDOM | |||
* index (excluding hidden columns) of cell to focus | |||
*/ | |||
void focusCell(int rowIndex, int columnIndex) { | |||
void focusCell(int rowIndex, int columnIndexDOM) { | |||
final Range rowRange = Range.between(0, dataSource.size()); | |||
final Range columnRange = Range.between(0, getVisibleColumns().size()); | |||
assert rowRange.contains( | |||
rowIndex) : "Illegal row index. Should be in range " + rowRange; | |||
assert columnRange.contains( | |||
columnIndex) : "Illegal column index. Should be in range " | |||
columnIndexDOM) : "Illegal column index. Should be in range " | |||
+ columnRange; | |||
if (rowRange.contains(rowIndex) && columnRange.contains(columnIndex)) { | |||
cellFocusHandler.setCellFocus(rowIndex, columnIndex, | |||
if (rowRange.contains(rowIndex) | |||
&& columnRange.contains(columnIndexDOM)) { | |||
cellFocusHandler.setCellFocus(rowIndex, columnIndexDOM, | |||
escalator.getBody()); | |||
WidgetUtil.focus(getElement()); | |||
} | |||
@@ -7447,10 +7448,11 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>, | |||
} | |||
Widget widget; | |||
if (editor.focusedColumnIndex < 0) { | |||
if (editor.focusedColumnIndexDOM < 0) { | |||
widget = null; | |||
} else { | |||
widget = editor.getWidget(getColumn(editor.focusedColumnIndex)); | |||
widget = editor | |||
.getWidget(getColumn(editor.focusedColumnIndexDOM)); | |||
} | |||
EditorDomEvent<T> editorEvent = new EditorDomEvent<>( | |||
@@ -7556,8 +7558,7 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>, | |||
if (!event.getCell().isHeader()) { | |||
return; | |||
} | |||
if (event.getCell().getColumnIndex() < escalator | |||
.getColumnConfiguration().getFrozenColumnCount()) { | |||
if (event.getCell().getColumnIndex() < getFrozenColumnCount()) { | |||
return; | |||
} | |||
@@ -17,6 +17,7 @@ package com.vaadin.v7.tests.server.component.grid; | |||
import java.util.ArrayList; | |||
import java.util.Arrays; | |||
import java.util.Collections; | |||
import java.util.List; | |||
import org.junit.After; | |||
@@ -32,6 +33,7 @@ import com.vaadin.v7.event.SelectionEvent.SelectionListener; | |||
import com.vaadin.v7.shared.ui.grid.selection.MultiSelectionModelServerRpc; | |||
import com.vaadin.v7.shared.ui.grid.selection.MultiSelectionModelState; | |||
import com.vaadin.v7.ui.Grid; | |||
import com.vaadin.v7.ui.Grid.SelectionModel.HasUserSelectionAllowed; | |||
public class MultiSelectionModelTest { | |||
@@ -28,6 +28,7 @@ import com.vaadin.v7.event.SelectionEvent.SelectionListener; | |||
import com.vaadin.v7.shared.ui.grid.selection.SingleSelectionModelServerRpc; | |||
import com.vaadin.v7.ui.Grid; | |||
import com.vaadin.v7.ui.Grid.SelectionMode; | |||
import com.vaadin.v7.ui.Grid.SelectionModel.HasUserSelectionAllowed; | |||
import com.vaadin.v7.ui.Grid.SingleSelectionModel; | |||
public class SingleSelectionModelTest { |
@@ -158,56 +158,31 @@ public class LocaleService implements Serializable { | |||
/* | |||
* Date formatting (MM/DD/YYYY etc.) | |||
*/ | |||
DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.SHORT, | |||
DateFormat.SHORT, locale); | |||
DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.SHORT, | |||
locale); | |||
DateFormat timeFormat = DateFormat.getTimeInstance(DateFormat.SHORT, | |||
locale); | |||
if (!(dateFormat instanceof SimpleDateFormat)) { | |||
getLogger().warning("Unable to get default date pattern for locale " | |||
+ locale.toString()); | |||
dateFormat = new SimpleDateFormat(); | |||
} | |||
final String df = ((SimpleDateFormat) dateFormat).toPattern(); | |||
int timeStart = df.indexOf('H'); | |||
if (timeStart < 0) { | |||
timeStart = df.indexOf('h'); | |||
} | |||
final int ampm_first = df.indexOf('a'); | |||
// E.g. in Korean locale AM/PM is before h:mm | |||
// TODO should take that into consideration on client-side as well, | |||
// now always h:mm a | |||
if (ampm_first > 0 && ampm_first < timeStart) { | |||
timeStart = ampm_first; | |||
} | |||
// Hebrew locale has time before the date | |||
final boolean timeFirst = timeStart == 0; | |||
String dateformat; | |||
if (timeFirst) { | |||
int dateStart = df.indexOf(' '); | |||
if (ampm_first > dateStart) { | |||
dateStart = df.indexOf(' ', ampm_first); | |||
} | |||
dateformat = df.substring(dateStart + 1); | |||
} else { | |||
dateformat = df.substring(0, timeStart - 1); | |||
if (!(timeFormat instanceof SimpleDateFormat)) { | |||
getLogger().warning("Unable to get default time pattern for locale " | |||
+ locale.toString()); | |||
timeFormat = new SimpleDateFormat(); | |||
} | |||
final String datePattern = ((SimpleDateFormat) dateFormat).toPattern(); | |||
final String timePattern = ((SimpleDateFormat) timeFormat).toPattern(); | |||
localeData.dateFormat = dateformat.trim(); | |||
localeData.dateFormat = datePattern.trim(); | |||
/* | |||
* Time formatting (24 or 12 hour clock and AM/PM suffixes) | |||
*/ | |||
final String timeformat = df.substring(timeStart, df.length()); | |||
/* | |||
* Doesn't return second or milliseconds. | |||
* | |||
* We use timeformat to determine 12/24-hour clock | |||
*/ | |||
final boolean twelve_hour_clock = timeformat.contains("a"); | |||
final boolean twelve_hour_clock = timePattern.indexOf("a") > -1; | |||
// TODO there are other possibilities as well, like 'h' in french | |||
// (ignore them, too complicated) | |||
final String hour_min_delimiter = timeformat.contains(".") ? "." : ":"; | |||
// outWriter.print("\"tf\":\"" + timeformat + "\","); | |||
final String hour_min_delimiter = timePattern.indexOf(".") > -1 ? "." | |||
: ":"; | |||
localeData.twelveHourClock = twelve_hour_clock; | |||
localeData.hourMinuteDelimiter = hour_min_delimiter; | |||
if (twelve_hour_clock) { |
@@ -70,7 +70,7 @@ import elemental.json.JsonValue; | |||
* <li><code>init(cell)</code> - Prepares a cell for rendering. Corresponds to | |||
* {@link com.vaadin.client.renderers.ComplexRenderer#init(com.vaadin.client.widget.grid.RendererCellReference)} | |||
* .</li> | |||
* <li><code>destory(cell)</code> - Allows the renderer to release resources | |||
* <li><code>destroy(cell)</code> - Allows the renderer to release resources | |||
* allocate for a cell that will no longer be used. Corresponds to | |||
* {@link com.vaadin.client.renderers.ComplexRenderer#destroy(com.vaadin.client.widget.grid.RendererCellReference)} | |||
* .</li> |
@@ -15,12 +15,15 @@ | |||
*/ | |||
package com.vaadin.ui; | |||
import java.lang.reflect.Method; | |||
import java.util.Arrays; | |||
import java.util.HashSet; | |||
import org.junit.Assert; | |||
import com.vaadin.server.ClientConnector; | |||
import com.vaadin.server.ServerRpcManager; | |||
import com.vaadin.shared.communication.ServerRpc; | |||
import elemental.json.JsonObject; | |||
@@ -67,6 +70,29 @@ public class ComponentTest { | |||
} | |||
/** | |||
* Gets the server rpc handler registered for a component. | |||
* | |||
* @param connector | |||
* the connector which listens to the RPC | |||
* @param serverRpcClass | |||
* the server RPC class | |||
* @return the server RPC handler | |||
*/ | |||
public static <T extends ServerRpc> T getRpcProxy(ClientConnector connector, | |||
Class<T> serverRpcClass) { | |||
try { | |||
ServerRpcManager<?> rpcManager = connector | |||
.getRpcManager(serverRpcClass.getName()); | |||
Method method = ServerRpcManager.class | |||
.getDeclaredMethod("getImplementation"); | |||
method.setAccessible(true); | |||
return serverRpcClass.cast(method.invoke(rpcManager)); | |||
} catch (ReflectiveOperationException e) { | |||
throw new RuntimeException(e); | |||
} | |||
} | |||
/** | |||
* Asserts the set of properties that would be sent as state changes for the | |||
* given connector. |
@@ -0,0 +1,42 @@ | |||
package com.vaadin.tests.components.customlayout; | |||
import com.vaadin.annotations.Widgetset; | |||
import com.vaadin.server.VaadinRequest; | |||
import com.vaadin.ui.Button; | |||
import com.vaadin.ui.Button.ClickEvent; | |||
import com.vaadin.ui.Button.ClickListener; | |||
import com.vaadin.ui.CustomLayout; | |||
import com.vaadin.ui.TextField; | |||
import com.vaadin.ui.UI; | |||
import com.vaadin.ui.VerticalLayout; | |||
@Widgetset("com.vaadin.DefaultWidgetSet") | |||
public class CustomLayoutUpdateCaption extends UI { | |||
@Override | |||
protected void init(VaadinRequest vaadinRequest) { | |||
CustomLayout content = new CustomLayout(); | |||
content.setTemplateContents("<div>\n" | |||
+ " <div location=\"test1\"></div>\n" | |||
+ " <div location=\"test2\"></div>\n" | |||
+ " <div location=\"okbutton\"></div>\n" + "</div>"); | |||
content.setSizeUndefined(); | |||
setContent(content); | |||
Button loginButton = new Button("Test"); | |||
final TextField username1 = new TextField(); | |||
final TextField username2 = new TextField(); | |||
username1.setCaption("initial"); | |||
username2.setCaption("initial"); | |||
content.addComponent(username1, "test1"); | |||
content.addComponent(new VerticalLayout(username2), "test2"); | |||
content.addComponent(loginButton, "okbutton"); | |||
loginButton.addClickListener(new ClickListener() { | |||
@Override | |||
public void buttonClick(ClickEvent e) { | |||
username1.setCaption("updated"); | |||
username2.setCaption("updated"); | |||
} | |||
}); | |||
} | |||
} |
@@ -0,0 +1,80 @@ | |||
package com.vaadin.tests.components.draganddropwrapper; | |||
import com.vaadin.event.dd.DragAndDropEvent; | |||
import com.vaadin.event.dd.DropHandler; | |||
import com.vaadin.event.dd.acceptcriteria.AcceptAll; | |||
import com.vaadin.event.dd.acceptcriteria.AcceptCriterion; | |||
import com.vaadin.event.dd.acceptcriteria.ClientSideCriterion; | |||
import com.vaadin.event.dd.acceptcriteria.Not; | |||
import com.vaadin.server.ThemeResource; | |||
import com.vaadin.server.VaadinRequest; | |||
import com.vaadin.tests.components.AbstractTestUIWithLog; | |||
import com.vaadin.ui.Button; | |||
import com.vaadin.ui.Button.ClickEvent; | |||
import com.vaadin.ui.DragAndDropWrapper; | |||
import com.vaadin.ui.DragAndDropWrapper.DragStartMode; | |||
import com.vaadin.ui.Image; | |||
public class Html5DropDenied extends AbstractTestUIWithLog { | |||
@Override | |||
protected void setup(VaadinRequest request) { | |||
Image sample = new Image(); | |||
sample.setSource(new ThemeResource("../runo/icons/64/document.png")); | |||
Button neverButton = new Button("Never accepts drop"); | |||
neverButton.setId("never"); | |||
neverButton.addClickListener(new Button.ClickListener() { | |||
@Override | |||
public void buttonClick(ClickEvent event) { | |||
log("click on " + event.getButton().getCaption()); | |||
} | |||
}); | |||
DragAndDropWrapper neverAccept = new DragAndDropWrapper(neverButton); | |||
neverAccept.setSizeFull(); | |||
neverAccept.setDragStartMode(DragStartMode.NONE); | |||
neverAccept.setDropHandler(new DropHandler() { | |||
@Override | |||
public AcceptCriterion getAcceptCriterion() { | |||
return new Not((ClientSideCriterion) AcceptAll.get()); | |||
} | |||
@Override | |||
public void drop(DragAndDropEvent event) { | |||
log("This should never happen"); | |||
} | |||
}); | |||
Button alwaysButton = new Button("always accepts drop"); | |||
alwaysButton.setId("always"); | |||
alwaysButton.addClickListener(new Button.ClickListener() { | |||
@Override | |||
public void buttonClick(ClickEvent event) { | |||
log("click on " + event.getButton().getCaption()); | |||
} | |||
}); | |||
DragAndDropWrapper alwaysAccept = new DragAndDropWrapper(alwaysButton); | |||
alwaysAccept.setSizeFull(); | |||
alwaysAccept.setDragStartMode(DragStartMode.NONE); | |||
alwaysAccept.setDropHandler(new DropHandler() { | |||
@Override | |||
public AcceptCriterion getAcceptCriterion() { | |||
return AcceptAll.get(); | |||
} | |||
@Override | |||
public void drop(DragAndDropEvent event) { | |||
log("Drop on always accept"); | |||
} | |||
}); | |||
addComponent(sample); | |||
addComponent(neverAccept); | |||
addComponent(alwaysAccept); | |||
} | |||
} |
@@ -18,10 +18,14 @@ package com.vaadin.tests.components.grid; | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
import com.vaadin.annotations.Widgetset; | |||
import com.vaadin.server.VaadinRequest; | |||
import com.vaadin.tests.components.AbstractReindeerTestUI; | |||
import com.vaadin.ui.Button; | |||
import com.vaadin.ui.Grid; | |||
import com.vaadin.ui.Label; | |||
@Widgetset("com.vaadin.DefaultWidgetSet") | |||
public class JavaScriptRenderers extends AbstractReindeerTestUI { | |||
public static class ItemBean { | |||
@@ -81,6 +85,8 @@ public class JavaScriptRenderers extends AbstractReindeerTestUI { | |||
} | |||
} | |||
private Grid<ItemBean> grid; | |||
@Override | |||
protected void setup(VaadinRequest request) { | |||
List<ItemBean> items = new ArrayList<>(1000); | |||
@@ -92,6 +98,20 @@ public class JavaScriptRenderers extends AbstractReindeerTestUI { | |||
items.add(bean); | |||
} | |||
Label clientLog = new Label(); | |||
clientLog.setId("clientLog"); | |||
addComponent(clientLog); | |||
grid = createGrid(items); | |||
addComponent(grid); | |||
addComponent(new Button("Recreate grid", e -> { | |||
Grid<ItemBean> newGrid = createGrid(items); | |||
replaceComponent(grid, newGrid); | |||
grid = newGrid; | |||
})); | |||
} | |||
private Grid<ItemBean> createGrid(List<ItemBean> items) { | |||
Grid<ItemBean> grid = new Grid<>(); | |||
grid.addColumn(item -> item.getId().toString()).setCaption("Id"); | |||
@@ -99,10 +119,13 @@ public class JavaScriptRenderers extends AbstractReindeerTestUI { | |||
.setCaption("Bean"); | |||
grid.addColumn(ItemBean::getString, new JavaScriptStringRenderer()) | |||
.setCaption("String"); | |||
grid.addColumn(ItemBean::getString, | |||
new JavaScriptStringRendererWithDestoryMethod()) | |||
.setCaption("String2"); | |||
grid.setItems(items); | |||
addComponent(grid); | |||
return grid; | |||
} | |||
} |
@@ -0,0 +1,15 @@ | |||
package com.vaadin.tests.components.grid; | |||
import com.vaadin.annotations.JavaScript; | |||
import com.vaadin.tests.components.grid.JavaScriptRenderers.ItemBean; | |||
import com.vaadin.ui.renderers.AbstractJavaScriptRenderer; | |||
@JavaScript("JavaScriptStringRendererWithDestoryMethod.js") | |||
public class JavaScriptStringRendererWithDestoryMethod | |||
extends AbstractJavaScriptRenderer<ItemBean, String> { | |||
protected JavaScriptStringRendererWithDestoryMethod() { | |||
super(String.class); | |||
} | |||
} |
@@ -27,11 +27,7 @@ import com.vaadin.tests.components.AbstractReindeerTestUI; | |||
import com.vaadin.ui.Button; | |||
import com.vaadin.ui.Button.ClickEvent; | |||
import com.vaadin.ui.ConnectorTracker; | |||
<<<<<<< HEAD | |||
import com.vaadin.v7.ui.Table; | |||
======= | |||
import com.vaadin.ui.Table; | |||
>>>>>>> 62c0d73... Remove tracking of unregistered connectors (#8153) | |||
import elemental.json.JsonObject; | |||
@@ -2,4 +2,9 @@ com_vaadin_tests_components_grid_JavaScriptStringRenderer = function() { | |||
this.render = function(cell, data) { | |||
cell.element.textContent = data; | |||
} | |||
} | |||
this.destroy = function(cell) { | |||
document.getElementById("clientLog").innerHTML += "destroy: " | |||
+ cell.rowIndex + "/" + cell.columnIndex + "<br>"; | |||
} | |||
} |
@@ -0,0 +1,13 @@ | |||
com_vaadin_tests_components_grid_JavaScriptStringRendererWithDestoryMethod = function() { | |||
this.render = function(cell, data) { | |||
cell.element.textContent = data; | |||
// This one is for IE8 | |||
cell.element.innerText = data; | |||
} | |||
this.destory = function(cell) { | |||
document.getElementById("clientLog").innerHTML += "destory: " | |||
+ cell.rowIndex + "/" + cell.columnIndex + "<br>"; | |||
} | |||
} |
@@ -1,7 +1,10 @@ | |||
package com.vaadin.tests.components.combobox; | |||
import org.junit.Assert; | |||
import org.junit.Test; | |||
import org.openqa.selenium.Keys; | |||
import com.vaadin.testbench.By; | |||
import com.vaadin.testbench.elements.ComboBoxElement; | |||
import com.vaadin.tests.tb3.MultiBrowserTest; | |||
@@ -29,4 +32,41 @@ public class ComboBoxItemIconTest extends MultiBrowserTest { | |||
compareScreen("fi-au-selected"); | |||
} | |||
@Test | |||
public void iconResetOnSelectionCancelByEscape() { | |||
openTestURL(); | |||
ComboBoxElement cb = $(ComboBoxElement.class).get(1); | |||
assertSelection(cb, "hu.gif", "Hungary"); | |||
cb.openPopup(); | |||
cb.sendKeys(Keys.UP); | |||
assertSelection(cb, "au.gif", "Australia"); | |||
cb.sendKeys(Keys.ESCAPE); | |||
assertSelection(cb, "hu.gif", "Hungary"); | |||
} | |||
@Test | |||
public void iconResetOnSelectionCancelByClickingOutside() { | |||
openTestURL(); | |||
ComboBoxElement cb = $(ComboBoxElement.class).get(1); | |||
assertSelection(cb, "hu.gif", "Hungary"); | |||
cb.openPopup(); | |||
cb.sendKeys(Keys.UP); | |||
assertSelection(cb, "au.gif", "Australia"); | |||
findElement(By.tagName("body")).click(); | |||
assertSelection(cb, "hu.gif", "Hungary"); | |||
} | |||
private void assertSelection(ComboBoxElement cb, String imageSuffix, | |||
String caption) { | |||
Assert.assertEquals(caption, cb.getValue()); | |||
String imgSrc = cb.findElement(By.className("v-icon")) | |||
.getAttribute("src"); | |||
imgSrc = imgSrc.substring(imgSrc.lastIndexOf('/') + 1); | |||
Assert.assertEquals(imageSuffix, imgSrc); | |||
} | |||
} |
@@ -0,0 +1,30 @@ | |||
package com.vaadin.tests.components.customlayout; | |||
import java.util.List; | |||
import org.junit.Assert; | |||
import org.junit.Test; | |||
import com.vaadin.testbench.elements.ButtonElement; | |||
import com.vaadin.testbench.elements.TextFieldElement; | |||
import com.vaadin.tests.tb3.SingleBrowserTest; | |||
public class CustomLayoutUpdateCaptionTest extends SingleBrowserTest { | |||
@Test | |||
public void captionUpdated() { | |||
openTestURL(); | |||
List<TextFieldElement> tfs = $(TextFieldElement.class).all(); | |||
TextFieldElement tf1 = tfs.get(0); | |||
TextFieldElement tf2 = tfs.get(1); | |||
Assert.assertEquals("initial", tf1.getCaption()); | |||
Assert.assertEquals("initial", tf2.getCaption()); | |||
$(ButtonElement.class).first().click(); | |||
Assert.assertEquals("updated", tf1.getCaption()); | |||
Assert.assertEquals("updated", tf2.getCaption()); | |||
} | |||
} |
@@ -34,6 +34,11 @@ public class GridSelectionTest extends GridBasicsTest { | |||
assertTrue("row should become selected", getRow(0).isSelected()); | |||
toggleFirstRowSelection(); | |||
assertFalse("row shouldn't remain selected", getRow(0).isSelected()); | |||
toggleFirstRowSelection(); | |||
assertTrue("row should become selected", getRow(0).isSelected()); | |||
getGridElement().getCell(0, 0).click(); | |||
assertFalse("row shouldn't remain selected", getRow(0).isSelected()); | |||
} | |||
@Test | |||
@@ -106,6 +111,11 @@ public class GridSelectionTest extends GridBasicsTest { | |||
assertTrue("First row was not selected.", getRow(0).isSelected()); | |||
assertTrue("Selection event was not correct", logContainsText( | |||
"SingleSelectionEvent: Selected: DataObject[0]")); | |||
grid.getCell(0, 0).click(); | |||
assertFalse("First row was not deselected.", getRow(0).isSelected()); | |||
assertTrue("Deselection event was not correct", | |||
logContainsText("SingleSelectionEvent: Selected: none")); | |||
grid.getCell(5, 0).click(); | |||
assertTrue("Fifth row was not selected.", getRow(5).isSelected()); | |||
assertFalse("First row was still selected.", getRow(0).isSelected()); |
@@ -17,7 +17,10 @@ package com.vaadin.tests.components.grid; | |||
import org.junit.Assert; | |||
import org.junit.Test; | |||
import org.openqa.selenium.WebElement; | |||
import com.vaadin.testbench.By; | |||
import com.vaadin.testbench.elements.ButtonElement; | |||
import com.vaadin.testbench.elements.GridElement; | |||
import com.vaadin.testbench.elements.GridElement.GridCellElement; | |||
import com.vaadin.testbench.parallel.TestCategory; | |||
@@ -49,4 +52,20 @@ public class JavaScriptRenderersTest extends MultiBrowserTest { | |||
Assert.assertTrue( | |||
cell_1_1.getText().startsWith("Clicked 1 with key 2 at")); | |||
} | |||
@Test | |||
public void testJavaScriptRendererDestroy() { | |||
openTestURL("debug"); | |||
waitForDebugMessage( | |||
"Your JavaScript connector (com_vaadin_tests_components_grid_JavaScriptStringRendererWithDestoryMethod) has a typo. The destory method should be renamed to destroy."); | |||
$(ButtonElement.class).first().click(); | |||
WebElement log = findElement(By.id("clientLog")); | |||
String text = log.getText(); | |||
Assert.assertTrue(text.contains("destory: 19/3")); | |||
Assert.assertTrue(text.contains("destroy: 19/2")); | |||
Assert.assertTrue(text.contains("destroy: 0/2")); | |||
Assert.assertTrue(text.contains("destory: 0/3")); | |||
} | |||
} |
@@ -1,10 +1,14 @@ | |||
package com.vaadin.tests.themes.valo; | |||
import static org.hamcrest.core.Is.is; | |||
import static org.junit.Assert.assertFalse; | |||
import static org.junit.Assert.assertThat; | |||
import static org.junit.Assert.assertTrue; | |||
import org.junit.Test; | |||
import org.openqa.selenium.Keys; | |||
import org.openqa.selenium.WebElement; | |||
import org.openqa.selenium.interactions.Actions; | |||
import com.vaadin.testbench.By; | |||
import com.vaadin.testbench.elements.ButtonElement; | |||
@@ -31,7 +35,42 @@ public class ModalWindowTest extends SingleBrowserTest { | |||
is("none")); | |||
} | |||
@Test | |||
public void modal_curtains_close_correctly() { | |||
openTestURL(); | |||
openModalWindow(); | |||
new Actions(getDriver()).moveToElement(findHeaderElement()) | |||
.clickAndHold().moveByOffset(1, 1).perform(); | |||
assertTrue(isElementPresent(By.className("v-window-draggingCurtain"))); | |||
new Actions(getDriver()).sendKeys(findHeaderElement(), Keys.ESCAPE) | |||
.release().perform(); | |||
verifyCurtainsNotPresent(); | |||
openModalWindow(); | |||
new Actions(getDriver()).moveToElement(findResizingElement()) | |||
.clickAndHold().moveByOffset(1, 1).perform(); | |||
assertTrue(isElementPresent(By.className("v-window-resizingCurtain"))); | |||
new Actions(getDriver()).sendKeys(findResizingElement(), Keys.ESCAPE) | |||
.release().perform(); | |||
verifyCurtainsNotPresent(); | |||
} | |||
private void openModalWindow() { | |||
$(ButtonElement.class).get(1).click(); | |||
} | |||
} | |||
private WebElement findHeaderElement() { | |||
return findElement(By.className("v-window-header")); | |||
} | |||
private WebElement findResizingElement() { | |||
return findElement(By.className("v-window-resizebox")); | |||
} | |||
private void verifyCurtainsNotPresent() { | |||
assertFalse(isElementPresent(By.className("v-window-modalitycurtain"))); | |||
assertFalse(isElementPresent(By.className("v-window-draggingCurtain"))); | |||
assertFalse(isElementPresent(By.className("v-window-resizingCurtain"))); | |||
} | |||
} |
@@ -251,4 +251,8 @@ public abstract class GridBasicFeaturesTest extends MultiBrowserTest { | |||
} | |||
return null; | |||
} | |||
protected void toggleColumnHidden(int column) { | |||
selectMenuPath("Component", "Columns", "Column " + column, "Hidden"); | |||
} | |||
} |
@@ -208,6 +208,29 @@ public class GridColumnReorderTest extends GridBasicFeaturesTest { | |||
assertFalse(getGridElement().getHeaderCell(0, 2).isFrozen()); | |||
} | |||
@Test | |||
public void testColumnReorder_draggingFrozenColumnsContainingHiddenColumns_impossible() { | |||
// given | |||
openTestURL(); | |||
selectMenuPath("Component", "Size", "Width", "900px"); | |||
toggleColumnReordering(); | |||
setFrozenColumns(4); | |||
toggleColumnHidden(1); | |||
toggleColumnHidden(2); | |||
assertColumnHeaderOrder(0, 3, 4, 5); | |||
// when | |||
// drag frozen column out between non-frozen columns | |||
dragAndDropDefaultColumnHeader(1, 2, CellSide.RIGHT); | |||
// then | |||
// everything should be as before | |||
assertColumnHeaderOrder(0, 3, 4, 5); | |||
assertTrue(getGridElement().getHeaderCell(0, 0).isFrozen()); | |||
assertTrue(getGridElement().getHeaderCell(0, 1).isFrozen()); | |||
assertFalse(getGridElement().getHeaderCell(0, 2).isFrozen()); | |||
} | |||
@Test | |||
public void testColumnReorder_draggingColumnOnTopOfFrozenColumn_columnDroppedRightOfFrozenColumns() { | |||
// given |
@@ -153,13 +153,13 @@ public class GridColumnResizeTest extends GridBasicFeaturesTest { | |||
selectMenuPath("Component", "Columns", | |||
"Toggle all column hidden state"); | |||
// Hides although already hidden | |||
selectMenuPath("Component", "Columns", "Column 0", "Hidden"); | |||
toggleColumnHidden(0); | |||
// Shows | |||
selectMenuPath("Component", "Columns", "Column 0", "Hidden"); | |||
toggleColumnHidden(0); | |||
// Hides although already hidden | |||
selectMenuPath("Component", "Columns", "Column 2", "Hidden"); | |||
toggleColumnHidden(2); | |||
// Shows | |||
selectMenuPath("Component", "Columns", "Column 2", "Hidden"); | |||
toggleColumnHidden(2); | |||
GridCellElement cell = getGridElement().getCell(0, 1); | |||
dragResizeColumn(1, 0, -cell.getSize().getWidth()); | |||
assertGreaterOrEqual("Cell got too small.", cell.getSize().getWidth(), |
@@ -229,4 +229,17 @@ public class GridKeyboardNavigationTest extends GridBasicFeaturesTest { | |||
column == focusedColumn | |||
&& Math.abs(row - focusedRow) <= rowTolerance); | |||
} | |||
@Test | |||
public void testNavigateOverHiddenColumnToFrozenColumn() { | |||
openTestURL(); | |||
setFrozenColumns(3); | |||
toggleColumnHidden(1); | |||
getGridElement().getCell(0, 2).click(); | |||
assertFocusedCell(0, 2); | |||
new Actions(getDriver()).sendKeys(Keys.ARROW_LEFT).perform(); | |||
assertFocusedCell(0, 1); | |||
new Actions(getDriver()).sendKeys(Keys.ARROW_LEFT).perform(); | |||
assertFocusedCell(0, 0); | |||
} | |||
} |