Also use "event" as the name for eventstags/8.2.0.alpha3
// The show must go on | // The show must go on | ||||
onLoad(event); | onLoad(event); | ||||
} | } | ||||
}; | }; | ||||
/** | /** |
import com.vaadin.client.communication.ServerRpcQueue; | import com.vaadin.client.communication.ServerRpcQueue; | ||||
import com.vaadin.client.communication.StateChangeEvent; | import com.vaadin.client.communication.StateChangeEvent; | ||||
import com.vaadin.client.communication.StateChangeEvent.StateChangeHandler; | import com.vaadin.client.communication.StateChangeEvent.StateChangeHandler; | ||||
import com.vaadin.client.ui.layout.ElementResizeEvent; | |||||
import com.vaadin.client.ui.layout.ElementResizeListener; | import com.vaadin.client.ui.layout.ElementResizeListener; | ||||
import com.vaadin.shared.JavaScriptConnectorState; | import com.vaadin.shared.JavaScriptConnectorState; | ||||
import com.vaadin.shared.communication.MethodInvocation; | import com.vaadin.shared.communication.MethodInvocation; | ||||
if (listener == null) { | if (listener == null) { | ||||
LayoutManager layoutManager = LayoutManager | LayoutManager layoutManager = LayoutManager | ||||
.get(connector.getConnection()); | .get(connector.getConnection()); | ||||
listener = new ElementResizeListener() { | |||||
@Override | |||||
public void onElementResize(ElementResizeEvent e) { | |||||
invokeElementResizeCallback(e.getElement(), | |||||
callbackFunction); | |||||
} | |||||
}; | |||||
listener = event -> invokeElementResizeCallback(event.getElement(), | |||||
callbackFunction); | |||||
layoutManager.addElementResizeListener(element, listener); | layoutManager.addElementResizeListener(element, listener); | ||||
elementListeners.put(callbackFunction, listener); | elementListeners.put(callbackFunction, listener); | ||||
} | } |
import com.google.gwt.user.client.Window.Location; | import com.google.gwt.user.client.Window.Location; | ||||
import com.google.gwt.user.client.rpc.AsyncCallback; | import com.google.gwt.user.client.rpc.AsyncCallback; | ||||
import com.vaadin.client.ui.VNotification; | import com.vaadin.client.ui.VNotification; | ||||
import com.vaadin.client.ui.VNotification.EventListener; | |||||
import com.vaadin.client.ui.VNotification.HideEvent; | |||||
/** | /** | ||||
* Class that enables SuperDevMode using a ?superdevmode parameter in the url. | * Class that enables SuperDevMode using a ?superdevmode parameter in the url. | ||||
private void failed() { | private void failed() { | ||||
VNotification n = new VNotification(); | VNotification n = new VNotification(); | ||||
n.addEventListener(new EventListener() { | |||||
@Override | |||||
public void notificationHidden(HideEvent event) { | |||||
recompileWidgetsetAndStartInDevMode(serverUrl); | |||||
} | |||||
}); | |||||
n.addEventListener( | |||||
event -> recompileWidgetsetAndStartInDevMode( | |||||
serverUrl)); | |||||
n.show("Recompilation failed.<br/>" | n.show("Recompilation failed.<br/>" | ||||
+ "Make sure CodeServer is running, " | + "Make sure CodeServer is running, " | ||||
+ "check its output and click to retry", | + "check its output and click to retry", |
import com.vaadin.client.WidgetUtil; | import com.vaadin.client.WidgetUtil; | ||||
import com.vaadin.client.data.DataChangeHandler; | import com.vaadin.client.data.DataChangeHandler; | ||||
import com.vaadin.client.extensions.AbstractExtensionConnector; | import com.vaadin.client.extensions.AbstractExtensionConnector; | ||||
import com.vaadin.client.ui.layout.ElementResizeEvent; | |||||
import com.vaadin.client.ui.layout.ElementResizeListener; | import com.vaadin.client.ui.layout.ElementResizeListener; | ||||
import com.vaadin.client.widget.grid.HeightAwareDetailsGenerator; | import com.vaadin.client.widget.grid.HeightAwareDetailsGenerator; | ||||
import com.vaadin.client.widgets.Grid; | import com.vaadin.client.widgets.Grid; | ||||
private Registration dataChangeRegistration; | private Registration dataChangeRegistration; | ||||
private final Map<Element, ScheduledCommand> elementToResizeCommand = new HashMap<Element, Scheduler.ScheduledCommand>(); | private final Map<Element, ScheduledCommand> elementToResizeCommand = new HashMap<Element, Scheduler.ScheduledCommand>(); | ||||
private final ElementResizeListener detailsRowResizeListener = new ElementResizeListener() { | |||||
@Override | |||||
public void onElementResize(ElementResizeEvent e) { | |||||
if (elementToResizeCommand.containsKey(e.getElement())) { | |||||
Scheduler.get().scheduleFinally( | |||||
elementToResizeCommand.get(e.getElement())); | |||||
} | |||||
private final ElementResizeListener detailsRowResizeListener = event -> { | |||||
if (elementToResizeCommand.containsKey(event.getElement())) { | |||||
Scheduler.get().scheduleFinally( | |||||
elementToResizeCommand.get(event.getElement())); | |||||
} | } | ||||
}; | }; | ||||
} | } | ||||
}); | }); | ||||
hierarchyPanel.addListener(new SelectConnectorListener() { | |||||
@Override | |||||
public void select(ServerConnector connector, Element element) { | |||||
printState(connector, true); | |||||
} | |||||
}); | |||||
hierarchyPanel.addListener( | |||||
(connector, element) -> printState(connector, true)); | |||||
analyzeLayoutsPanel.addListener(new SelectConnectorListener() { | |||||
@Override | |||||
public void select(ServerConnector connector, Element element) { | |||||
printState(connector, true); | |||||
} | |||||
}); | |||||
analyzeLayoutsPanel.addListener( | |||||
(connector, element) -> printState(connector, true)); | |||||
content.setStylePrimaryName(VDebugWindow.STYLENAME + "-hierarchy"); | content.setStylePrimaryName(VDebugWindow.STYLENAME + "-hierarchy"); | ||||
package com.vaadin.client.ui; | package com.vaadin.client.ui; | ||||
import com.google.gwt.event.dom.client.DomEvent; | |||||
import com.vaadin.client.ui.VAbstractCalendarPanel.FocusOutListener; | |||||
import com.vaadin.client.ui.VAbstractCalendarPanel.SubmitListener; | import com.vaadin.client.ui.VAbstractCalendarPanel.SubmitListener; | ||||
/** | /** | ||||
} | } | ||||
}); | }); | ||||
calendarPanel.setFocusOutListener(new FocusOutListener() { | |||||
@Override | |||||
public boolean onFocusOut(DomEvent<?> event) { | |||||
updateValueFromPanel(); | |||||
return false; | |||||
} | |||||
calendarPanel.setFocusOutListener(event -> { | |||||
updateValueFromPanel(); | |||||
return false; | |||||
}); | }); | ||||
} | } | ||||
import com.google.gwt.dom.client.Element; | import com.google.gwt.dom.client.Element; | ||||
import com.google.gwt.event.dom.client.ClickEvent; | import com.google.gwt.event.dom.client.ClickEvent; | ||||
import com.google.gwt.event.dom.client.ClickHandler; | import com.google.gwt.event.dom.client.ClickHandler; | ||||
import com.google.gwt.event.dom.client.DomEvent; | |||||
import com.google.gwt.event.dom.client.KeyCodes; | import com.google.gwt.event.dom.client.KeyCodes; | ||||
import com.google.gwt.event.dom.client.MouseOutEvent; | import com.google.gwt.event.dom.client.MouseOutEvent; | ||||
import com.google.gwt.event.dom.client.MouseOutHandler; | import com.google.gwt.event.dom.client.MouseOutHandler; | ||||
import com.vaadin.client.BrowserInfo; | import com.vaadin.client.BrowserInfo; | ||||
import com.vaadin.client.ComputedStyle; | import com.vaadin.client.ComputedStyle; | ||||
import com.vaadin.client.VConsole; | import com.vaadin.client.VConsole; | ||||
import com.vaadin.client.ui.VAbstractCalendarPanel.FocusOutListener; | |||||
import com.vaadin.client.ui.VAbstractCalendarPanel.SubmitListener; | import com.vaadin.client.ui.VAbstractCalendarPanel.SubmitListener; | ||||
import com.vaadin.client.ui.aria.AriaHelper; | import com.vaadin.client.ui.aria.AriaHelper; | ||||
import com.vaadin.shared.ui.datefield.TextualDateFieldState; | import com.vaadin.shared.ui.datefield.TextualDateFieldState; | ||||
calendar = calendarPanel; | calendar = calendarPanel; | ||||
calendar.setParentField(this); | calendar.setParentField(this); | ||||
calendar.setFocusOutListener(new FocusOutListener() { | |||||
@Override | |||||
public boolean onFocusOut(DomEvent<?> event) { | |||||
event.preventDefault(); | |||||
closeCalendarPanel(); | |||||
return true; | |||||
} | |||||
calendar.setFocusOutListener(event -> { | |||||
event.preventDefault(); | |||||
closeCalendarPanel(); | |||||
return true; | |||||
}); | }); | ||||
// FIXME: Problem is, that the element with the provided id does not | // FIXME: Problem is, that the element with the provided id does not |
public void sendBufferedValues() { | public void sendBufferedValues() { | ||||
rpc.update(bufferedDateString, | rpc.update(bufferedDateString, | ||||
bufferedResolutions.entrySet().stream().collect(Collectors | bufferedResolutions.entrySet().stream().collect(Collectors | ||||
.toMap(e -> e.getKey().name(), e -> e.getValue()))); | |||||
.toMap(e -> e.getKey().name(), | |||||
e -> e.getValue()))); | |||||
bufferedDateString = null; | bufferedDateString = null; | ||||
bufferedResolutions.clear(); | bufferedResolutions.clear(); | ||||
} | } |
import com.google.gwt.aria.client.Roles; | import com.google.gwt.aria.client.Roles; | ||||
import com.google.gwt.core.client.GWT; | import com.google.gwt.core.client.GWT; | ||||
import com.google.gwt.dom.client.Element; | import com.google.gwt.dom.client.Element; | ||||
import com.google.gwt.dom.client.NativeEvent; | |||||
import com.google.gwt.event.dom.client.KeyCodes; | import com.google.gwt.event.dom.client.KeyCodes; | ||||
import com.google.gwt.user.client.DOM; | import com.google.gwt.user.client.DOM; | ||||
import com.google.gwt.user.client.Event; | import com.google.gwt.user.client.Event; | ||||
import com.google.gwt.user.client.ui.Label; | import com.google.gwt.user.client.ui.Label; | ||||
import com.google.gwt.user.client.ui.Widget; | import com.google.gwt.user.client.ui.Widget; | ||||
import com.vaadin.client.AnimationUtil; | import com.vaadin.client.AnimationUtil; | ||||
import com.vaadin.client.AnimationUtil.AnimationEndListener; | |||||
import com.vaadin.client.ApplicationConnection; | import com.vaadin.client.ApplicationConnection; | ||||
import com.vaadin.client.BrowserInfo; | import com.vaadin.client.BrowserInfo; | ||||
import com.vaadin.client.WidgetUtil; | import com.vaadin.client.WidgetUtil; | ||||
if (getStyleName() | if (getStyleName() | ||||
.contains(VOverlay.ADDITIONAL_CLASSNAME_ANIMATE_IN)) { | .contains(VOverlay.ADDITIONAL_CLASSNAME_ANIMATE_IN)) { | ||||
AnimationUtil.addAnimationEndListener(getElement(), | AnimationUtil.addAnimationEndListener(getElement(), | ||||
new AnimationEndListener() { | |||||
@Override | |||||
public void onAnimationEnd(NativeEvent event) { | |||||
if (AnimationUtil.getAnimationName(event) | |||||
.contains( | |||||
VOverlay.ADDITIONAL_CLASSNAME_ANIMATE_IN)) { | |||||
VNotification.this.hide(); | |||||
} | |||||
event -> { | |||||
if (AnimationUtil.getAnimationName(event).contains( | |||||
VOverlay.ADDITIONAL_CLASSNAME_ANIMATE_IN)) { | |||||
VNotification.this.hide(); | |||||
} | } | ||||
}); | }); | ||||
} else { | } else { |
import com.vaadin.client.UIDL; | import com.vaadin.client.UIDL; | ||||
import com.vaadin.client.communication.StateChangeEvent; | import com.vaadin.client.communication.StateChangeEvent; | ||||
import com.vaadin.client.ui.VAbstractCalendarPanel; | import com.vaadin.client.ui.VAbstractCalendarPanel; | ||||
import com.vaadin.client.ui.VAbstractCalendarPanel.FocusChangeListener; | |||||
import com.vaadin.client.ui.VAbstractDateFieldCalendar; | import com.vaadin.client.ui.VAbstractDateFieldCalendar; | ||||
import com.vaadin.shared.ui.datefield.InlineDateFieldState; | import com.vaadin.shared.ui.datefield.InlineDateFieldState; | ||||
protected void updateListeners() { | protected void updateListeners() { | ||||
if (isResolutionMonthOrHigher()) { | if (isResolutionMonthOrHigher()) { | ||||
getWidget().calendarPanel | getWidget().calendarPanel | ||||
.setFocusChangeListener(new FocusChangeListener() { | |||||
@Override | |||||
public void focusChanged(Date date) { | |||||
Date date2 = new Date(); | |||||
if (getWidget().calendarPanel.getDate() != null) { | |||||
date2.setTime(getWidget().calendarPanel | |||||
.getDate().getTime()); | |||||
} | |||||
/* | |||||
* Update the value of calendarPanel | |||||
*/ | |||||
date2.setYear(date.getYear()); | |||||
date2.setMonth(date.getMonth()); | |||||
getWidget().calendarPanel.setDate(date2); | |||||
/* | |||||
* Then update the value from panel to server | |||||
*/ | |||||
getWidget().updateValueFromPanel(); | |||||
.setFocusChangeListener(date -> { | |||||
Date date2 = new Date(); | |||||
if (getWidget().calendarPanel.getDate() != null) { | |||||
date2.setTime(getWidget().calendarPanel.getDate() | |||||
.getTime()); | |||||
} | } | ||||
/* | |||||
* Update the value of calendarPanel | |||||
*/ | |||||
date2.setYear(date.getYear()); | |||||
date2.setMonth(date.getMonth()); | |||||
getWidget().calendarPanel.setDate(date2); | |||||
/* | |||||
* Then update the value from panel to server | |||||
*/ | |||||
getWidget().updateValueFromPanel(); | |||||
}); | }); | ||||
} else { | } else { | ||||
getWidget().calendarPanel.setFocusChangeListener(null); | getWidget().calendarPanel.setFocusChangeListener(null); |
import com.vaadin.client.DateTimeService; | import com.vaadin.client.DateTimeService; | ||||
import com.vaadin.client.ui.VDateTimeCalendarPanel; | import com.vaadin.client.ui.VDateTimeCalendarPanel; | ||||
import com.vaadin.client.ui.VDateTimeCalendarPanel.TimeChangeListener; | |||||
import com.vaadin.client.ui.VPopupTimeCalendar; | import com.vaadin.client.ui.VPopupTimeCalendar; | ||||
import com.vaadin.shared.ui.Connect; | import com.vaadin.shared.ui.Connect; | ||||
import com.vaadin.shared.ui.datefield.DateTimeResolution; | import com.vaadin.shared.ui.datefield.DateTimeResolution; | ||||
if (getWidget().getCurrentResolution() | if (getWidget().getCurrentResolution() | ||||
.compareTo(DateTimeResolution.DAY) < 0) { | .compareTo(DateTimeResolution.DAY) < 0) { | ||||
getWidget().calendar | getWidget().calendar | ||||
.setTimeChangeListener(new TimeChangeListener() { | |||||
@Override | |||||
public void changed(int hour, int min, int sec, | |||||
int msec) { | |||||
Date d = getWidget().getDate(); | |||||
if (d == null) { | |||||
// date currently null, use the value from | |||||
// calendarPanel | |||||
// (~ client time at the init of the widget) | |||||
d = (Date) getWidget().calendar.getDate() | |||||
.clone(); | |||||
} | |||||
d.setHours(hour); | |||||
d.setMinutes(min); | |||||
d.setSeconds(sec); | |||||
DateTimeService.setMilliseconds(d, msec); | |||||
.setTimeChangeListener((hour, min, sec, msec) -> { | |||||
Date d = getWidget().getDate(); | |||||
if (d == null) { | |||||
// date currently null, use the value from | |||||
// calendarPanel | |||||
// (~ client time at the init of the widget) | |||||
d = (Date) getWidget().calendar.getDate().clone(); | |||||
} | |||||
d.setHours(hour); | |||||
d.setMinutes(min); | |||||
d.setSeconds(sec); | |||||
DateTimeService.setMilliseconds(d, msec); | |||||
// Always update time changes to the server | |||||
getWidget().updateValue(d); | |||||
// Always update time changes to the server | |||||
getWidget().updateValue(d); | |||||
// Update text field | |||||
getWidget().buildDate(); | |||||
} | |||||
// Update text field | |||||
getWidget().buildDate(); | |||||
}); | }); | ||||
} | } | ||||
} | } |
import com.vaadin.client.DateTimeService; | import com.vaadin.client.DateTimeService; | ||||
import com.vaadin.client.ui.VDateTimeCalendarPanel; | import com.vaadin.client.ui.VDateTimeCalendarPanel; | ||||
import com.vaadin.client.ui.VDateTimeCalendarPanel.TimeChangeListener; | |||||
import com.vaadin.client.ui.VDateTimeFieldCalendar; | import com.vaadin.client.ui.VDateTimeFieldCalendar; | ||||
import com.vaadin.shared.ui.Connect; | import com.vaadin.shared.ui.Connect; | ||||
import com.vaadin.shared.ui.datefield.DateTimeResolution; | import com.vaadin.shared.ui.datefield.DateTimeResolution; | ||||
if (getWidget().getCurrentResolution() | if (getWidget().getCurrentResolution() | ||||
.compareTo(DateTimeResolution.DAY) < 0) { | .compareTo(DateTimeResolution.DAY) < 0) { | ||||
getWidget().calendarPanel | getWidget().calendarPanel | ||||
.setTimeChangeListener(new TimeChangeListener() { | |||||
@Override | |||||
public void changed(int hour, int min, int sec, | |||||
int msec) { | |||||
Date d = getWidget().getDate(); | |||||
if (d == null) { | |||||
// date currently null, use the value from | |||||
// calendarPanel | |||||
// (~ client time at the init of the widget) | |||||
d = (Date) getWidget().calendarPanel.getDate() | |||||
.clone(); | |||||
} | |||||
d.setHours(hour); | |||||
d.setMinutes(min); | |||||
d.setSeconds(sec); | |||||
DateTimeService.setMilliseconds(d, msec); | |||||
// Always update time changes to the server | |||||
getWidget().calendarPanel.setDate(d); | |||||
getWidget().updateValueFromPanel(); | |||||
.setTimeChangeListener((hour, min, sec, msec) -> { | |||||
Date d = getWidget().getDate(); | |||||
if (d == null) { | |||||
// date currently null, use the value from | |||||
// calendarPanel | |||||
// (~ client time at the init of the widget) | |||||
d = (Date) getWidget().calendarPanel.getDate() | |||||
.clone(); | |||||
} | } | ||||
d.setHours(hour); | |||||
d.setMinutes(min); | |||||
d.setSeconds(sec); | |||||
DateTimeService.setMilliseconds(d, msec); | |||||
// Always update time changes to the server | |||||
getWidget().calendarPanel.setDate(d); | |||||
getWidget().updateValueFromPanel(); | |||||
}); | }); | ||||
} | } | ||||
} | } |
protected void updateListeners() { | protected void updateListeners() { | ||||
FocusChangeListener listener; | FocusChangeListener listener; | ||||
if (isResolutionMonthOrHigher()) { | if (isResolutionMonthOrHigher()) { | ||||
listener = new FocusChangeListener() { | |||||
@Override | |||||
public void focusChanged(Date date) { | |||||
if (isResolutionMonthOrHigher()) { | |||||
getWidget().updateValue(date); | |||||
getWidget().buildDate(); | |||||
Date date2 = getWidget().calendar.getDate(); | |||||
date2.setYear(date.getYear()); | |||||
date2.setMonth(date.getMonth()); | |||||
} | |||||
listener = date -> { | |||||
if (isResolutionMonthOrHigher()) { | |||||
getWidget().updateValue(date); | |||||
getWidget().buildDate(); | |||||
Date date2 = getWidget().calendar.getDate(); | |||||
date2.setYear(date.getYear()); | |||||
date2.setMonth(date.getMonth()); | |||||
} | } | ||||
}; | }; | ||||
} else { | } else { |
import com.google.gwt.dom.client.Element; | import com.google.gwt.dom.client.Element; | ||||
import com.google.gwt.user.client.DOM; | import com.google.gwt.user.client.DOM; | ||||
import com.google.gwt.user.client.Event; | import com.google.gwt.user.client.Event; | ||||
import com.google.gwt.user.client.EventListener; | |||||
import com.vaadin.client.WidgetUtil; | import com.vaadin.client.WidgetUtil; | ||||
import com.vaadin.client.ui.dd.DragAndDropHandler.DragAndDropCallback; | import com.vaadin.client.ui.dd.DragAndDropHandler.DragAndDropCallback; | ||||
dndHandler = new DragAndDropHandler(); | dndHandler = new DragAndDropHandler(); | ||||
DOM.sinkEvents(element, Event.ONMOUSEDOWN | Event.ONTOUCHSTART); | DOM.sinkEvents(element, Event.ONMOUSEDOWN | Event.ONTOUCHSTART); | ||||
DOM.setEventListener(element, new EventListener() { | |||||
@Override | |||||
public void onBrowserEvent(Event event) { | |||||
dndHandler.onDragStartOnDraggableElement(event, dndCallback); | |||||
event.stopPropagation(); | |||||
} | |||||
DOM.setEventListener(element, event -> { | |||||
dndHandler.onDragStartOnDraggableElement(event, dndCallback); | |||||
event.stopPropagation(); | |||||
}); | }); | ||||
} | } | ||||
import com.vaadin.client.communication.StateChangeEvent; | import com.vaadin.client.communication.StateChangeEvent; | ||||
import com.vaadin.client.ui.AbstractComponentConnector; | import com.vaadin.client.ui.AbstractComponentConnector; | ||||
import com.vaadin.client.ui.VFlash; | import com.vaadin.client.ui.VFlash; | ||||
import com.vaadin.client.ui.layout.ElementResizeEvent; | |||||
import com.vaadin.client.ui.layout.ElementResizeListener; | import com.vaadin.client.ui.layout.ElementResizeListener; | ||||
import com.vaadin.shared.ui.AbstractEmbeddedState; | import com.vaadin.shared.ui.AbstractEmbeddedState; | ||||
import com.vaadin.shared.ui.Connect; | import com.vaadin.shared.ui.Connect; | ||||
getWidget().rebuildIfNeeded(); | getWidget().rebuildIfNeeded(); | ||||
} | } | ||||
private final ElementResizeListener listener = new ElementResizeListener() { | |||||
public void onElementResize(ElementResizeEvent e) { | |||||
Element slot = e.getElement().getParentElement(); | |||||
getWidget().setSlotHeightAndWidth(slot.getOffsetHeight(), | |||||
slot.getOffsetWidth()); | |||||
} | |||||
private final ElementResizeListener listener = event -> { | |||||
Element slot = event.getElement().getParentElement(); | |||||
getWidget().setSlotHeightAndWidth(slot.getOffsetHeight(), | |||||
slot.getOffsetWidth()); | |||||
}; | }; | ||||
@Override | @Override |
import com.vaadin.client.ui.VFormLayout.Caption; | import com.vaadin.client.ui.VFormLayout.Caption; | ||||
import com.vaadin.client.ui.VFormLayout.ErrorFlag; | import com.vaadin.client.ui.VFormLayout.ErrorFlag; | ||||
import com.vaadin.client.ui.VFormLayout.VFormLayoutTable; | import com.vaadin.client.ui.VFormLayout.VFormLayoutTable; | ||||
import com.vaadin.client.ui.layout.ElementResizeEvent; | |||||
import com.vaadin.client.ui.layout.ElementResizeListener; | import com.vaadin.client.ui.layout.ElementResizeListener; | ||||
import com.vaadin.shared.ui.Connect; | import com.vaadin.shared.ui.Connect; | ||||
import com.vaadin.shared.ui.LayoutClickRpc; | import com.vaadin.shared.ui.LayoutClickRpc; | ||||
private Map<ComponentConnector, String> oldMaxWidths = null; | private Map<ComponentConnector, String> oldMaxWidths = null; | ||||
private static final ElementResizeListener DUMMY_FIRST_CELL_RESIZE_LISTENER = new ElementResizeListener() { | |||||
@Override | |||||
public void onElementResize(ElementResizeEvent e) { | |||||
// Ignore event, listener added just to make measurements available | |||||
} | |||||
private static final ElementResizeListener DUMMY_FIRST_CELL_RESIZE_LISTENER = event -> { | |||||
// Ignore event, listener added just to make measurements available | |||||
}; | }; | ||||
// Detects situations when there's something inside the FormLayout that | // Detects situations when there's something inside the FormLayout that | ||||
// prevents it from shrinking | // prevents it from shrinking | ||||
private ElementResizeListener resizeListener = new ElementResizeListener() { | |||||
@Override | |||||
public void onElementResize(ElementResizeEvent e) { | |||||
LayoutManager layoutManager = getLayoutManager(); | |||||
double tableWidth = layoutManager | |||||
.getOuterWidthDouble(getWidget().table.getElement()); | |||||
double ownWidth = layoutManager | |||||
.getInnerWidthDouble(getWidget().getElement()); | |||||
if (ownWidth < tableWidth) { | |||||
// Something inside the table prevents it from shrinking, | |||||
// temporarily force column widths | |||||
double excessWidth = tableWidth - ownWidth; | |||||
// All td elements in the component column have the same width, | |||||
// so we only need to check the width of the first one to know | |||||
// how wide the column is. | |||||
Element firstComponentTd = findFirstComponentTd(); | |||||
if (firstComponentTd == null) { | |||||
// Can't do anything if there are no rows | |||||
return; | |||||
} | |||||
private ElementResizeListener resizeListener = event -> { | |||||
LayoutManager layoutManager = getLayoutManager(); | |||||
double tableWidth = layoutManager | |||||
.getOuterWidthDouble(getWidget().table.getElement()); | |||||
double ownWidth = layoutManager | |||||
.getInnerWidthDouble(getWidget().getElement()); | |||||
if (ownWidth < tableWidth) { | |||||
// Something inside the table prevents it from shrinking, | |||||
// temporarily force column widths | |||||
double excessWidth = tableWidth - ownWidth; | |||||
// All td elements in the component column have the same width, | |||||
// so we only need to check the width of the first one to know | |||||
// how wide the column is. | |||||
Element firstComponentTd = findFirstComponentTd(); | |||||
if (firstComponentTd == null) { | |||||
// Can't do anything if there are no rows | |||||
return; | |||||
} | |||||
double componentColWidth = layoutManager | |||||
.getOuterWidthDouble(firstComponentTd); | |||||
double componentColWidth = layoutManager | |||||
.getOuterWidthDouble(firstComponentTd); | |||||
if (componentColWidth == -1) { | |||||
// Didn't get a proper width reading, best to not touch | |||||
// anything | |||||
return; | |||||
} | |||||
if (componentColWidth == -1) { | |||||
// Didn't get a proper width reading, best to not touch | |||||
// anything | |||||
return; | |||||
} | |||||
// Restrict content td width | |||||
// Round down to prevent interactions with fractional sizes of | |||||
// other columns | |||||
int targetWidth = (int) Math | |||||
.floor(componentColWidth - excessWidth); | |||||
// Restrict content td width | |||||
// Round down to prevent interactions with fractional sizes of | |||||
// other columns | |||||
int targetWidth = (int) Math.floor(componentColWidth - excessWidth); | |||||
// Target might be negative if captions are wider than the total | |||||
// available width | |||||
targetWidth = Math.max(0, targetWidth); | |||||
// Target might be negative if captions are wider than the total | |||||
// available width | |||||
targetWidth = Math.max(0, targetWidth); | |||||
if (oldMaxWidths == null) { | |||||
oldMaxWidths = new HashMap<>(); | |||||
} | |||||
if (oldMaxWidths == null) { | |||||
oldMaxWidths = new HashMap<>(); | |||||
} | |||||
for (ComponentConnector child : getChildComponents()) { | |||||
Element childElement = child.getWidget().getElement(); | |||||
if (!oldMaxWidths.containsKey(child)) { | |||||
oldMaxWidths.put(child, | |||||
childElement.getPropertyString("maxWidth")); | |||||
} | |||||
childElement.getStyle().setPropertyPx("maxWidth", | |||||
targetWidth); | |||||
layoutManager.reportOuterWidth(child, targetWidth); | |||||
for (ComponentConnector child : getChildComponents()) { | |||||
Element childElement = child.getWidget().getElement(); | |||||
if (!oldMaxWidths.containsKey(child)) { | |||||
oldMaxWidths.put(child, | |||||
childElement.getPropertyString("maxWidth")); | |||||
} | } | ||||
childElement.getStyle().setPropertyPx("maxWidth", targetWidth); | |||||
layoutManager.reportOuterWidth(child, targetWidth); | |||||
} | } | ||||
} | } | ||||
}; | }; |
protected void init() { | protected void init() { | ||||
super.init(); | super.init(); | ||||
selectionChangeRegistration = getWidget().getListBox() | selectionChangeRegistration = getWidget().getListBox() | ||||
.addChangeHandler(e -> selectionRpc | |||||
.addChangeHandler(event -> selectionRpc | |||||
.select(getWidget().getListBox().getSelectedValue())); | .select(getWidget().getListBox().getSelectedValue())); | ||||
} | } | ||||
super.init(); | super.init(); | ||||
selectionChangeRegistration = getWidget().addSelectionChangeHandler( | selectionChangeRegistration = getWidget().addSelectionChangeHandler( | ||||
e -> selectionRpc.select(getRowKey(e))); | |||||
event -> selectionRpc.select(getRowKey(event))); | |||||
} | } | ||||
@Override | @Override |
import com.vaadin.client.ui.Icon; | import com.vaadin.client.ui.Icon; | ||||
import com.vaadin.client.ui.LayoutClickEventHandler; | import com.vaadin.client.ui.LayoutClickEventHandler; | ||||
import com.vaadin.client.ui.aria.AriaHelper; | import com.vaadin.client.ui.aria.AriaHelper; | ||||
import com.vaadin.client.ui.layout.ElementResizeEvent; | |||||
import com.vaadin.client.ui.layout.ElementResizeListener; | import com.vaadin.client.ui.layout.ElementResizeListener; | ||||
import com.vaadin.shared.ComponentConstants; | import com.vaadin.shared.ComponentConstants; | ||||
import com.vaadin.shared.communication.URLReference; | import com.vaadin.shared.communication.URLReference; | ||||
} | } | ||||
}; | }; | ||||
private ElementResizeListener slotCaptionResizeListener = new ElementResizeListener() { | |||||
@Override | |||||
public void onElementResize(ElementResizeEvent e) { | |||||
private ElementResizeListener slotCaptionResizeListener = event -> { | |||||
// Get all needed element references | |||||
Element captionElement = e.getElement(); | |||||
// Get all needed element references | |||||
Element captionElement = event.getElement(); | |||||
// Caption position determines if the widget element is the first or | |||||
// last child inside the caption wrap | |||||
CaptionPosition pos = getWidget().getCaptionPositionFromElement( | |||||
captionElement.getParentElement()); | |||||
// Caption position determines if the widget element is the first or | |||||
// last child inside the caption wrap | |||||
CaptionPosition pos = getWidget().getCaptionPositionFromElement( | |||||
captionElement.getParentElement()); | |||||
// The default is the last child | |||||
Element widgetElement = captionElement.getParentElement() | |||||
.getLastChild().cast(); | |||||
// The default is the last child | |||||
Element widgetElement = captionElement.getParentElement().getLastChild() | |||||
.cast(); | |||||
// ...but if caption position is bottom or right, the widget is the | |||||
// first child | |||||
if (pos == CaptionPosition.BOTTOM || pos == CaptionPosition.RIGHT) { | |||||
widgetElement = captionElement.getParentElement() | |||||
.getFirstChildElement().cast(); | |||||
} | |||||
// ...but if caption position is bottom or right, the widget is the | |||||
// first child | |||||
if (pos == CaptionPosition.BOTTOM || pos == CaptionPosition.RIGHT) { | |||||
widgetElement = captionElement.getParentElement() | |||||
.getFirstChildElement().cast(); | |||||
} | |||||
if (captionElement == widgetElement) { | |||||
// Caption element already detached | |||||
Slot slot = getWidget().getSlot(widgetElement); | |||||
if (slot != null) { | |||||
slot.setCaptionResizeListener(null); | |||||
} | |||||
return; | |||||
if (captionElement == widgetElement) { | |||||
// Caption element already detached | |||||
Slot slot = getWidget().getSlot(widgetElement); | |||||
if (slot != null) { | |||||
slot.setCaptionResizeListener(null); | |||||
} | } | ||||
return; | |||||
} | |||||
String widgetWidth = widgetElement.getStyle().getWidth(); | |||||
String widgetHeight = widgetElement.getStyle().getHeight(); | |||||
String widgetWidth = widgetElement.getStyle().getWidth(); | |||||
String widgetHeight = widgetElement.getStyle().getHeight(); | |||||
if (widgetHeight.endsWith("%") && (pos == CaptionPosition.TOP | |||||
|| pos == CaptionPosition.BOTTOM)) { | |||||
getWidget().updateCaptionOffset(captionElement); | |||||
} else if (widgetWidth.endsWith("%") && (pos == CaptionPosition.LEFT | |||||
|| pos == CaptionPosition.RIGHT)) { | |||||
getWidget().updateCaptionOffset(captionElement); | |||||
} | |||||
if (widgetHeight.endsWith("%") && (pos == CaptionPosition.TOP | |||||
|| pos == CaptionPosition.BOTTOM)) { | |||||
getWidget().updateCaptionOffset(captionElement); | |||||
} else if (widgetWidth.endsWith("%") && (pos == CaptionPosition.LEFT | |||||
|| pos == CaptionPosition.RIGHT)) { | |||||
getWidget().updateCaptionOffset(captionElement); | |||||
} | |||||
updateLayoutHeight(); | |||||
updateLayoutHeight(); | |||||
if (needsExpand()) { | |||||
getWidget().updateExpandCompensation(); | |||||
} | |||||
if (needsExpand()) { | |||||
getWidget().updateExpandCompensation(); | |||||
} | } | ||||
}; | }; | ||||
private ElementResizeListener childComponentResizeListener = new ElementResizeListener() { | |||||
@Override | |||||
public void onElementResize(ElementResizeEvent e) { | |||||
updateLayoutHeight(); | |||||
if (needsExpand()) { | |||||
getWidget().updateExpandCompensation(); | |||||
} | |||||
private ElementResizeListener childComponentResizeListener = event -> { | |||||
updateLayoutHeight(); | |||||
if (needsExpand()) { | |||||
getWidget().updateExpandCompensation(); | |||||
} | } | ||||
}; | }; | ||||
private ElementResizeListener spacingResizeListener = new ElementResizeListener() { | |||||
@Override | |||||
public void onElementResize(ElementResizeEvent e) { | |||||
if (needsExpand()) { | |||||
getWidget().updateExpandCompensation(); | |||||
} | |||||
private ElementResizeListener spacingResizeListener = event -> { | |||||
if (needsExpand()) { | |||||
getWidget().updateExpandCompensation(); | |||||
} | } | ||||
}; | }; | ||||
import com.vaadin.client.communication.StateChangeEvent; | import com.vaadin.client.communication.StateChangeEvent; | ||||
import com.vaadin.client.ui.AbstractFieldConnector; | import com.vaadin.client.ui.AbstractFieldConnector; | ||||
import com.vaadin.client.ui.VSlider; | import com.vaadin.client.ui.VSlider; | ||||
import com.vaadin.client.ui.layout.ElementResizeEvent; | |||||
import com.vaadin.client.ui.layout.ElementResizeListener; | import com.vaadin.client.ui.layout.ElementResizeListener; | ||||
import com.vaadin.shared.ui.Connect; | import com.vaadin.shared.ui.Connect; | ||||
import com.vaadin.shared.ui.slider.SliderServerRpc; | import com.vaadin.shared.ui.slider.SliderServerRpc; | ||||
protected SliderServerRpc rpc = RpcProxy.create(SliderServerRpc.class, | protected SliderServerRpc rpc = RpcProxy.create(SliderServerRpc.class, | ||||
this); | this); | ||||
private final ElementResizeListener resizeListener = new ElementResizeListener() { | |||||
@Override | |||||
public void onElementResize(ElementResizeEvent e) { | |||||
getWidget().iLayout(); | |||||
} | |||||
}; | |||||
private final ElementResizeListener resizeListener = event -> getWidget() | |||||
.iLayout(); | |||||
@Override | @Override | ||||
public void init() { | public void init() { |
import com.google.gwt.event.shared.HandlerRegistration; | import com.google.gwt.event.shared.HandlerRegistration; | ||||
import com.google.gwt.user.client.DOM; | import com.google.gwt.user.client.DOM; | ||||
import com.google.gwt.user.client.Event; | import com.google.gwt.user.client.Event; | ||||
import com.google.gwt.user.client.EventListener; | |||||
import com.google.gwt.user.client.Timer; | import com.google.gwt.user.client.Timer; | ||||
import com.vaadin.client.BrowserInfo; | import com.vaadin.client.BrowserInfo; | ||||
import com.vaadin.client.DeferredWorker; | import com.vaadin.client.DeferredWorker; | ||||
if (isInvisibleScrollbar) { | if (isInvisibleScrollbar) { | ||||
Event.sinkEvents(root, Event.ONSCROLL); | Event.sinkEvents(root, Event.ONSCROLL); | ||||
Event.setEventListener(root, new EventListener() { | |||||
@Override | |||||
public void onBrowserEvent(Event event) { | |||||
invisibleScrollbarTemporaryResizer.show(); | |||||
} | |||||
}); | |||||
Event.setEventListener(root, | |||||
event -> invisibleScrollbarTemporaryResizer.show()); | |||||
root.getStyle().setVisibility(Visibility.HIDDEN); | root.getStyle().setVisibility(Visibility.HIDDEN); | ||||
} else { | } else { | ||||
Event.sinkEvents(root, 0); | Event.sinkEvents(root, 0); |
public UI createInstance(UICreateEvent event) { | public UI createInstance(UICreateEvent event) { | ||||
if (prototype) { | if (prototype) { | ||||
UI ui = serviceObjects.getService(); | UI ui = serviceObjects.getService(); | ||||
ui.addDetachListener(e -> serviceObjects.ungetService(ui)); | |||||
ui.addDetachListener(event2 -> serviceObjects.ungetService(ui)); | |||||
return ui; | return ui; | ||||
} | } | ||||
logService.ifPresent(log -> log.log(LogService.LOG_WARNING, | logService.ifPresent(log -> log.log(LogService.LOG_WARNING, |
} | } | ||||
if (navigator != null) { | if (navigator != null) { | ||||
popStateListenerRegistration = ui.getPage().addPopStateListener( | popStateListenerRegistration = ui.getPage().addPopStateListener( | ||||
e -> navigator.navigateTo(getState())); | |||||
event -> navigator.navigateTo(getState())); | |||||
} | } | ||||
} | } | ||||
public PushRequestHandler(VaadinServletService service) | public PushRequestHandler(VaadinServletService service) | ||||
throws ServiceException { | throws ServiceException { | ||||
service.addServiceDestroyListener(e -> destroy()); | |||||
service.addServiceDestroyListener(event -> destroy()); | |||||
final ServletConfig vaadinServletConfig = service.getServlet() | final ServletConfig vaadinServletConfig = service.getServlet() | ||||
.getServletConfig(); | .getServletConfig(); |
treeGrid.setHeightUndefined(); | treeGrid.setHeightUndefined(); | ||||
treeGrid.setHeightMode(HeightMode.UNDEFINED); | treeGrid.setHeightMode(HeightMode.UNDEFINED); | ||||
treeGrid.addExpandListener(e -> { | |||||
fireExpandEvent(e.getExpandedItem(), e.isUserOriginated()); | |||||
treeGrid.addExpandListener(event -> { | |||||
fireExpandEvent(event.getExpandedItem(), event.isUserOriginated()); | |||||
if (autoRecalculateWidth) { | if (autoRecalculateWidth) { | ||||
treeGrid.recalculateColumnWidths(); | treeGrid.recalculateColumnWidths(); | ||||
} | } | ||||
}); | }); | ||||
treeGrid.addCollapseListener(e -> { | |||||
fireCollapseEvent(e.getCollapsedItem(), e.isUserOriginated()); | |||||
treeGrid.addCollapseListener(event -> { | |||||
fireCollapseEvent(event.getCollapsedItem(), | |||||
event.isUserOriginated()); | |||||
if (autoRecalculateWidth) { | if (autoRecalculateWidth) { | ||||
treeGrid.recalculateColumnWidths(); | treeGrid.recalculateColumnWidths(); | ||||
} | } | ||||
}); | }); | ||||
treeGrid.addItemClickListener(e -> fireEvent( | |||||
new ItemClick<>(this, e.getItem(), e.getMouseEventDetails()))); | |||||
treeGrid.addItemClickListener(event -> fireEvent(new ItemClick<>(this, | |||||
event.getItem(), event.getMouseEventDetails()))); | |||||
} | } | ||||
/** | /** |
blueSlider = createRGBSlider("Blue", "blue"); | blueSlider = createRGBSlider("Blue", "blue"); | ||||
setRgbSliderValues(color); | setRgbSliderValues(color); | ||||
redSlider.addValueChangeListener(e -> { | |||||
double red = e.getValue(); | |||||
redSlider.addValueChangeListener(event -> { | |||||
double red = event.getValue(); | |||||
if (!updatingColors) { | if (!updatingColors) { | ||||
Color newColor = new Color((int) red, selectedColor.getGreen(), | Color newColor = new Color((int) red, selectedColor.getGreen(), | ||||
selectedColor.getBlue()); | selectedColor.getBlue()); | ||||
sliders.addComponent(redSlider); | sliders.addComponent(redSlider); | ||||
greenSlider.addValueChangeListener(e -> { | |||||
double green = e.getValue(); | |||||
greenSlider.addValueChangeListener(event -> { | |||||
double green = event.getValue(); | |||||
if (!updatingColors) { | if (!updatingColors) { | ||||
Color newColor = new Color(selectedColor.getRed(), (int) green, | Color newColor = new Color(selectedColor.getRed(), (int) green, | ||||
selectedColor.getBlue()); | selectedColor.getBlue()); | ||||
}); | }); | ||||
sliders.addComponent(greenSlider); | sliders.addComponent(greenSlider); | ||||
blueSlider.addValueChangeListener(e -> { | |||||
double blue = e.getValue(); | |||||
blueSlider.addValueChangeListener(event -> { | |||||
double blue = event.getValue(); | |||||
if (!updatingColors) { | if (!updatingColors) { | ||||
Color newColor = new Color(selectedColor.getRed(), | Color newColor = new Color(selectedColor.getRed(), | ||||
selectedColor.getGreen(), (int) blue); | selectedColor.getGreen(), (int) blue); |
* if the {@code rowNumber} is not in the backing data provider | * if the {@code rowNumber} is not in the backing data provider | ||||
* @see #setEnabled(boolean) | * @see #setEnabled(boolean) | ||||
*/ | */ | ||||
@Override | |||||
public void editRow(int rowNumber) | public void editRow(int rowNumber) | ||||
throws IllegalStateException, IllegalArgumentException { | throws IllegalStateException, IllegalArgumentException { | ||||
if (!isEnabled()) { | if (!isEnabled()) { |
@Override | @Override | ||||
public default Registration addSelectionListener( | public default Registration addSelectionListener( | ||||
SelectionListener<T> listener) { | SelectionListener<T> listener) { | ||||
return addMultiSelectionListener(e -> listener.selectionChange(e)); | |||||
return addMultiSelectionListener( | |||||
event -> listener.selectionChange(event)); | |||||
} | } | ||||
/** | /** |
@Override | @Override | ||||
public default Registration addSelectionListener( | public default Registration addSelectionListener( | ||||
SelectionListener<T> listener) { | SelectionListener<T> listener) { | ||||
return addSingleSelectionListener(e -> listener.selectionChange(e)); | |||||
return addSingleSelectionListener( | |||||
event -> listener.selectionChange(event)); | |||||
} | } | ||||
/** | /** |
protected void registerDropTargetRpc() { | protected void registerDropTargetRpc() { | ||||
registerRpc( | registerRpc( | ||||
(DropTargetRpc) (types, data, dropEffect, mouseEventDetails) -> | (DropTargetRpc) (types, data, dropEffect, mouseEventDetails) -> | ||||
onDrop(types, data, | |||||
onDrop(types, data, | |||||
DropEffect.valueOf(dropEffect.toUpperCase(Locale.ROOT)), | DropEffect.valueOf(dropEffect.toUpperCase(Locale.ROOT)), | ||||
mouseEventDetails)); | mouseEventDetails)); | ||||
} | } |
protected Validator<String> notEmpty = Validator.from(val -> !val.isEmpty(), | protected Validator<String> notEmpty = Validator.from(val -> !val.isEmpty(), | ||||
EMPTY_ERROR_MESSAGE); | EMPTY_ERROR_MESSAGE); | ||||
protected Converter<String, Integer> stringToInteger = Converter.from( | protected Converter<String, Integer> stringToInteger = Converter.from( | ||||
Integer::valueOf, String::valueOf, e -> NOT_NUMBER_ERROR_MESSAGE); | |||||
Integer::valueOf, String::valueOf, | |||||
e -> NOT_NUMBER_ERROR_MESSAGE); | |||||
protected Validator<Integer> notNegative = Validator.from(x -> x >= 0, | protected Validator<Integer> notNegative = Validator.from(x -> x >= 0, | ||||
NEGATIVE_ERROR_MESSAGE); | NEGATIVE_ERROR_MESSAGE); | ||||
List<String> selectionChanges = new ArrayList<>(); | List<String> selectionChanges = new ArrayList<>(); | ||||
Capture<List<String>> oldSelectionCapture = new Capture<>(); | Capture<List<String>> oldSelectionCapture = new Capture<>(); | ||||
((MultiSelectionModelImpl<String>) customGrid.getSelectionModel()) | ((MultiSelectionModelImpl<String>) customGrid.getSelectionModel()) | ||||
.addMultiSelectionListener(e -> { | |||||
selectionChanges.addAll(e.getValue()); | |||||
.addMultiSelectionListener(event -> { | |||||
selectionChanges.addAll(event.getValue()); | |||||
oldSelectionCapture | oldSelectionCapture | ||||
.setValue(new ArrayList<>(e.getOldSelection())); | |||||
.setValue(new ArrayList<>(event.getOldSelection())); | |||||
}); | }); | ||||
customGrid.getSelectionModel().select("Foo"); | customGrid.getSelectionModel().select("Foo"); |
selectionChanges = new ArrayList<>(); | selectionChanges = new ArrayList<>(); | ||||
selectionModel.addSingleSelectionListener( | selectionModel.addSingleSelectionListener( | ||||
e -> selectionChanges.add(e.getValue())); | |||||
event -> selectionChanges.add(event.getValue())); | |||||
} | } | ||||
@Test(expected = IllegalStateException.class) | @Test(expected = IllegalStateException.class) | ||||
List<String> selectionChanges = new ArrayList<>(); | List<String> selectionChanges = new ArrayList<>(); | ||||
List<String> oldSelectionValues = new ArrayList<>(); | List<String> oldSelectionValues = new ArrayList<>(); | ||||
((SingleSelectionModelImpl<String>) customGrid.getSelectionModel()) | ((SingleSelectionModelImpl<String>) customGrid.getSelectionModel()) | ||||
.addSingleSelectionListener(e -> { | |||||
selectionChanges.add(e.getValue()); | |||||
oldSelectionValues.add(e.getOldValue()); | |||||
.addSingleSelectionListener(event -> { | |||||
selectionChanges.add(event.getValue()); | |||||
oldSelectionValues.add(event.getOldValue()); | |||||
}); | }); | ||||
customGrid.getSelectionModel().select("Foo"); | customGrid.getSelectionModel().select("Foo"); |
treeData.addItem("Foo", "Baz"); | treeData.addItem("Foo", "Baz"); | ||||
treeGrid.setDataProvider(new TreeDataProvider<>(treeData)); | treeGrid.setDataProvider(new TreeDataProvider<>(treeData)); | ||||
treeGrid.addExpandListener(e -> expandEventFired = true); | |||||
treeGrid.addCollapseListener(e -> collapseEventFired = true); | |||||
treeGrid.addExpandListener(event -> expandEventFired = true); | |||||
treeGrid.addCollapseListener(event -> collapseEventFired = true); | |||||
// Test expand event | // Test expand event | ||||
assertFalse(expandEventFired); | assertFalse(expandEventFired); |
customField.setPlaceholder("Something"); | customField.setPlaceholder("Something"); | ||||
addComponent(customField); | addComponent(customField); | ||||
ok.addClickListener(e -> Notification.show("OK")); | |||||
ok.addClickListener(event -> Notification.show("OK")); | |||||
CaNCEL.addClickListener(e -> Notification.show("cancel")); | |||||
CaNCEL.addClickListener(event -> Notification.show("cancel")); | |||||
} | } | ||||
} | } |
public void clickDetachedButton() { | public void clickDetachedButton() { | ||||
Button b = new Button(); | Button b = new Button(); | ||||
AtomicInteger counter = new AtomicInteger(0); | AtomicInteger counter = new AtomicInteger(0); | ||||
b.addClickListener(e -> counter.incrementAndGet()); | |||||
b.addClickListener(event -> counter.incrementAndGet()); | |||||
b.click(); | b.click(); | ||||
assertEquals(1, counter.get()); | assertEquals(1, counter.get()); | ||||
private void addClickListener(Button b) { | private void addClickListener(Button b) { | ||||
clicked = false; | clicked = false; | ||||
b.addClickListener(e -> clicked = true); | |||||
b.addClickListener(event -> clicked = true); | |||||
} | } | ||||
} | } |
Button b3 = new Button("b3"); | Button b3 = new Button("b3"); | ||||
Button b4 = new Button("b4"); | Button b4 = new Button("b4"); | ||||
TestTabsheet tabsheet = new TestTabsheet(b1, b2, b3, b4); | TestTabsheet tabsheet = new TestTabsheet(b1, b2, b3, b4); | ||||
tabsheet.addSelectedTabChangeListener(e -> { | |||||
userOriginated.set(e.isUserOriginated()); | |||||
selected.set(e.getTabSheet().getSelectedTab()); | |||||
tabsheet.addSelectedTabChangeListener(event -> { | |||||
userOriginated.set(event.isUserOriginated()); | |||||
selected.set(event.getTabSheet().getSelectedTab()); | |||||
}); | }); | ||||
tabsheet.setSelectedTab(b2); | tabsheet.setSelectedTab(b2); |
final boolean[] eventFired = new boolean[1]; | final boolean[] eventFired = new boolean[1]; | ||||
ui.addComponentAttachListener( | ui.addComponentAttachListener( | ||||
e -> eventFired[0] = e.getAttachedComponent().equals(window)); | |||||
event -> eventFired[0] = event.getAttachedComponent() | |||||
.equals(window)); | |||||
ui.addWindow(window); | ui.addWindow(window); | ||||
assertTrue("Attach event is not fired for added window", eventFired[0]); | assertTrue("Attach event is not fired for added window", eventFired[0]); | ||||
} | } | ||||
final boolean[] eventFired = new boolean[1]; | final boolean[] eventFired = new boolean[1]; | ||||
ui.addComponentDetachListener( | ui.addComponentDetachListener( | ||||
e -> eventFired[0] = e.getDetachedComponent().equals(window)); | |||||
event -> eventFired[0] = event.getDetachedComponent() | |||||
.equals(window)); | |||||
ui.addWindow(window); | ui.addWindow(window); | ||||
ui.removeWindow(window); | ui.removeWindow(window); | ||||
AtomicReference<Map<String, String>> mapRef = new AtomicReference<>(); | AtomicReference<Map<String, String>> mapRef = new AtomicReference<>(); | ||||
AtomicReference<Map<String, String>> mapRefB = new AtomicReference<>(); | AtomicReference<Map<String, String>> mapRefB = new AtomicReference<>(); | ||||
navigator.addViewChangeListener(new ViewChangeListener() { | |||||
@Override | |||||
public boolean beforeViewChange(ViewChangeEvent event) { | |||||
mapRef.set(event.getParameterMap()); | |||||
mapRefB.set(event.getParameterMap("b")); | |||||
return true; | |||||
} | |||||
navigator.addViewChangeListener(event -> { | |||||
mapRef.set(event.getParameterMap()); | |||||
mapRefB.set(event.getParameterMap("b")); | |||||
return true; | |||||
}); | }); | ||||
navigator.navigateTo("view1"); | navigator.navigateTo("view1"); |
selectionChanges = new ArrayList<>(); | selectionChanges = new ArrayList<>(); | ||||
oldSelections = new ArrayList<>(); | oldSelections = new ArrayList<>(); | ||||
listing.addSelectionListener(e -> selectionChanges.add(e.getValue())); | |||||
listing.addSelectionListener(e -> oldSelections.add(e.getOldValue())); | |||||
listing.addSelectionListener( | |||||
event -> selectionChanges.add(event.getValue())); | |||||
listing.addSelectionListener( | |||||
event -> oldSelections.add(event.getOldValue())); | |||||
} | } | ||||
public static final Person PERSON_C = new Person("c", 3); | public static final Person PERSON_C = new Person("c", 3); |
ui.setContent(cb); | ui.setContent(cb); | ||||
AtomicBoolean userOriginated = new AtomicBoolean(false); | AtomicBoolean userOriginated = new AtomicBoolean(false); | ||||
cb.addValueChangeListener( | cb.addValueChangeListener( | ||||
e -> userOriginated.set(e.isUserOriginated())); | |||||
event -> userOriginated.set(event.isUserOriginated())); | |||||
ComponentTest.syncToClient(cb); | ComponentTest.syncToClient(cb); | ||||
ServerRpcManager.getRpcProxy(cb, CheckBoxServerRpc.class) | ServerRpcManager.getRpcProxy(cb, CheckBoxServerRpc.class) | ||||
.setChecked(true, new MouseEventDetails()); | .setChecked(true, new MouseEventDetails()); | ||||
ui.setContent(cb); | ui.setContent(cb); | ||||
AtomicBoolean userOriginated = new AtomicBoolean(true); | AtomicBoolean userOriginated = new AtomicBoolean(true); | ||||
cb.addValueChangeListener( | cb.addValueChangeListener( | ||||
e -> userOriginated.set(e.isUserOriginated())); | |||||
event -> userOriginated.set(event.isUserOriginated())); | |||||
cb.setValue(true); | cb.setValue(true); | ||||
assertFalse(userOriginated.get()); | assertFalse(userOriginated.get()); | ||||
userOriginated.set(true); | userOriginated.set(true); |
// Reset value whenever it changes (in a real case, this listener would | // Reset value whenever it changes (in a real case, this listener would | ||||
// do something with the selected value before discarding it) | // do something with the selected value before discarding it) | ||||
comboBox.addValueChangeListener(e -> comboBox.setValue(null)); | |||||
comboBox.addValueChangeListener(event -> comboBox.setValue(null)); | |||||
// "Attach" the component and initialize diffstate | // "Attach" the component and initialize diffstate | ||||
new MockUI().setContent(comboBox); | new MockUI().setContent(comboBox); |
@Override | @Override | ||||
protected void init(VaadinRequest request) { | protected void init(VaadinRequest request) { | ||||
setContent(new Button("Click Me", | setContent(new Button("Click Me", | ||||
e -> Notification.show(service.getText()))); | |||||
event -> Notification.show(service.getText()))); | |||||
} | } | ||||
} | } |
@Parameter(1) | @Parameter(1) | ||||
public String path; | public String path; | ||||
@Override | |||||
@Before | @Before | ||||
public void setup() throws Exception { | public void setup() throws Exception { | ||||
Assume.assumeTrue( | Assume.assumeTrue( |
*/ | */ | ||||
package com.vaadin.tests.integration.push; | package com.vaadin.tests.integration.push; | ||||
import java.util.Timer; | |||||
import java.util.TimerTask; | |||||
import com.vaadin.annotations.Push; | import com.vaadin.annotations.Push; | ||||
import com.vaadin.server.VaadinRequest; | import com.vaadin.server.VaadinRequest; | ||||
import com.vaadin.shared.ui.ContentMode; | import com.vaadin.shared.ui.ContentMode; | ||||
import com.vaadin.ui.Button; | import com.vaadin.ui.Button; | ||||
import com.vaadin.ui.Button.ClickEvent; | |||||
import com.vaadin.ui.Button.ClickListener; | import com.vaadin.ui.Button.ClickListener; | ||||
import com.vaadin.ui.Label; | import com.vaadin.ui.Label; | ||||
import java.util.Timer; | |||||
import java.util.TimerTask; | |||||
@Push | @Push | ||||
public class BasicPush extends AbstractTestUI { | public class BasicPush extends AbstractTestUI { | ||||
addComponent(lbl); | addComponent(lbl); | ||||
Button incrementButton = new Button("Increment", | Button incrementButton = new Button("Increment", | ||||
new ClickListener() { | |||||
@Override | |||||
public void buttonClick(ClickEvent event) { | |||||
clientCounter++; | |||||
lbl.setValue(String.valueOf(clientCounter)); | |||||
} | |||||
event -> { | |||||
clientCounter++; | |||||
lbl.setValue(String.valueOf(clientCounter)); | |||||
}); | }); | ||||
incrementButton.setId(INCREMENT_BUTTON_ID); | incrementButton.setId(INCREMENT_BUTTON_ID); | ||||
addComponent(incrementButton); | addComponent(incrementButton); | ||||
startTimer.setId(START_TIMER_ID); | startTimer.setId(START_TIMER_ID); | ||||
addComponent(startTimer); | addComponent(startTimer); | ||||
Button stopTimer = new Button("Stop timer", new ClickListener() { | |||||
@Override | |||||
public void buttonClick(ClickEvent event) { | |||||
if (task != null) { | |||||
task.cancel(); | |||||
task = null; | |||||
} | |||||
Button stopTimer = new Button("Stop timer", event -> { | |||||
if (task != null) { | |||||
task.cancel(); | |||||
task = null; | |||||
} | } | ||||
}); | }); | ||||
stopTimer.setId(STOP_TIMER_ID); | stopTimer.setId(STOP_TIMER_ID); |
name.setCaption("Type your name here:"); | name.setCaption("Type your name here:"); | ||||
Button button = new Button("Click Me"); | Button button = new Button("Click Me"); | ||||
button.addClickListener(e -> layout.addComponent( | |||||
button.addClickListener(event -> layout.addComponent( | |||||
new Label("Thanks " + name.getValue() + ", it works!"))); | new Label("Thanks " + name.getValue() + ", it works!"))); | ||||
layout.addComponents(name, button); | layout.addComponents(name, button); |
name.setCaption("Type your name here:"); | name.setCaption("Type your name here:"); | ||||
Button button = new Button("Click Me"); | Button button = new Button("Click Me"); | ||||
button.addClickListener(e -> layout.addComponent( | |||||
button.addClickListener(event -> layout.addComponent( | |||||
new Label("Thanks " + name.getValue() + ", it works!"))); | new Label("Thanks " + name.getValue() + ", it works!"))); | ||||
layout.addComponents(name, button); | layout.addComponents(name, button); |
void init() { | void init() { | ||||
setId("default-view"); | setId("default-view"); | ||||
Button button = new Button("Click Me!", | Button button = new Button("Click Me!", | ||||
e -> Notification.show(service.getText())); | |||||
event -> Notification.show(service.getText())); | |||||
addComponent(button); | addComponent(button); | ||||
} | } | ||||
void init() { | void init() { | ||||
setId("default-view"); | setId("default-view"); | ||||
Button button = new Button("Click Me!", | Button button = new Button("Click Me!", | ||||
e -> Notification.show(service.getText())); | |||||
event -> Notification.show(service.getText())); | |||||
addComponent(button); | addComponent(button); | ||||
} | } | ||||
import com.vaadin.server.VaadinRequest; | import com.vaadin.server.VaadinRequest; | ||||
import com.vaadin.ui.Button; | import com.vaadin.ui.Button; | ||||
import com.vaadin.ui.Button.ClickEvent; | |||||
import com.vaadin.ui.Label; | import com.vaadin.ui.Label; | ||||
import com.vaadin.ui.TextField; | import com.vaadin.ui.TextField; | ||||
import com.vaadin.ui.UI; | import com.vaadin.ui.UI; | ||||
name.setCaption("Type your name here:"); | name.setCaption("Type your name here:"); | ||||
Button button = new Button("Click Me"); | Button button = new Button("Click Me"); | ||||
button.addClickListener(new Button.ClickListener() { | |||||
@Override | |||||
public void buttonClick(ClickEvent clickEvent) { | |||||
layout.addComponent( | |||||
new Label("Thanks " + name.getValue() + ", it works!")); | |||||
} | |||||
}); | |||||
button.addClickListener( | |||||
event -> new Label( | |||||
"Thanks " + name.getValue() + ", it works!")); | |||||
getPage().getJavaScript().execute( | getPage().getJavaScript().execute( | ||||
"widgetsetinfo.innerText=document.querySelector('iframe').id;"); | "widgetsetinfo.innerText=document.querySelector('iframe').id;"); |
Optional<WebElement> toggleButton = getDriver() | Optional<WebElement> toggleButton = getDriver() | ||||
.findElement(By.className("v-grid-sidebar-content")) | .findElement(By.className("v-grid-sidebar-content")) | ||||
.findElements(By.className("column-hiding-toggle")).stream() | .findElements(By.className("column-hiding-toggle")).stream() | ||||
.filter(e -> e.getText().equals(toggleCaption)).findAny(); | |||||
.filter(e -> e.getText().equals(toggleCaption)) | |||||
.findAny(); | |||||
if (toggleButton.isPresent()) { | if (toggleButton.isPresent()) { | ||||
toggleButton.ifPresent(e -> e.click()); | toggleButton.ifPresent(e -> e.click()); | ||||
} else { | } else { |
import com.vaadin.server.LegacyApplication; | import com.vaadin.server.LegacyApplication; | ||||
import com.vaadin.server.LegacyVaadinServlet; | import com.vaadin.server.LegacyVaadinServlet; | ||||
import com.vaadin.server.ServiceException; | import com.vaadin.server.ServiceException; | ||||
import com.vaadin.server.SessionInitEvent; | |||||
import com.vaadin.server.SessionInitListener; | |||||
import com.vaadin.server.SystemMessages; | import com.vaadin.server.SystemMessages; | ||||
import com.vaadin.server.SystemMessagesInfo; | import com.vaadin.server.SystemMessagesInfo; | ||||
import com.vaadin.server.SystemMessagesProvider; | import com.vaadin.server.SystemMessagesProvider; | ||||
@Override | @Override | ||||
protected void servletInitialized() throws ServletException { | protected void servletInitialized() throws ServletException { | ||||
super.servletInitialized(); | super.servletInitialized(); | ||||
getService().addSessionInitListener(new SessionInitListener() { | |||||
@Override | |||||
public void sessionInit(SessionInitEvent event) | |||||
throws ServiceException { | |||||
onVaadinSessionStarted(event.getRequest(), event.getSession()); | |||||
} | |||||
}); | |||||
getService().addSessionInitListener( | |||||
event -> onVaadinSessionStarted(event.getRequest(), event.getSession())); | |||||
} | } | ||||
private void addDirectories(File parent, LinkedHashSet<String> packages, | private void addDirectories(File parent, LinkedHashSet<String> packages, |
import org.eclipse.jetty.server.Server; | import org.eclipse.jetty.server.Server; | ||||
import org.eclipse.jetty.server.ServerConnector; | import org.eclipse.jetty.server.ServerConnector; | ||||
import org.eclipse.jetty.util.Scanner; | import org.eclipse.jetty.util.Scanner; | ||||
import org.eclipse.jetty.util.Scanner.BulkListener; | |||||
import org.eclipse.jetty.util.log.JavaUtilLog; | import org.eclipse.jetty.util.log.JavaUtilLog; | ||||
import org.eclipse.jetty.util.ssl.SslContextFactory; | import org.eclipse.jetty.util.ssl.SslContextFactory; | ||||
import org.eclipse.jetty.webapp.WebAppContext; | import org.eclipse.jetty.webapp.WebAppContext; | ||||
scanner.setScanInterval(interval); | scanner.setScanInterval(interval); | ||||
scanner.setRecursive(true); | scanner.setRecursive(true); | ||||
scanner.addListener(new Scanner.BulkListener() { | |||||
@Override | |||||
public void filesChanged(List<String> filenames) | |||||
throws Exception { | |||||
webappcontext.stop(); | |||||
server.stop(); | |||||
webappcontext.start(); | |||||
server.start(); | |||||
} | |||||
scanner.addListener((BulkListener) e-> { | |||||
webappcontext.stop(); | |||||
server.stop(); | |||||
webappcontext.start(); | |||||
server.start(); | |||||
}); | }); | ||||
scanner.setReportExistingFilesOnStartup(false); | scanner.setReportExistingFilesOnStartup(false); | ||||
scanner.setFilenameFilter(new FilenameFilter() { | scanner.setFilenameFilter(new FilenameFilter() { |
import com.vaadin.server.VaadinRequest; | import com.vaadin.server.VaadinRequest; | ||||
import com.vaadin.ui.BrowserFrame; | import com.vaadin.ui.BrowserFrame; | ||||
import com.vaadin.ui.Button; | import com.vaadin.ui.Button; | ||||
import com.vaadin.ui.Button.ClickEvent; | |||||
import com.vaadin.ui.Button.ClickListener; | import com.vaadin.ui.Button.ClickListener; | ||||
import com.vaadin.ui.CustomComponent; | import com.vaadin.ui.CustomComponent; | ||||
import com.vaadin.ui.HorizontalLayout; | import com.vaadin.ui.HorizontalLayout; | ||||
import com.vaadin.ui.Label; | import com.vaadin.ui.Label; | ||||
import com.vaadin.ui.UI; | import com.vaadin.ui.UI; | ||||
import com.vaadin.ui.VerticalLayout; | import com.vaadin.ui.VerticalLayout; | ||||
import com.vaadin.v7.data.Property.ValueChangeEvent; | |||||
import com.vaadin.v7.data.Property.ValueChangeListener; | |||||
import com.vaadin.v7.data.util.BeanItemContainer; | import com.vaadin.v7.data.util.BeanItemContainer; | ||||
import com.vaadin.v7.ui.Table; | import com.vaadin.v7.ui.Table; | ||||
left.addComponent(createSpacer()); | left.addComponent(createSpacer()); | ||||
left.addComponent( | left.addComponent( | ||||
new Button("Commit actions", new Button.ClickListener() { | |||||
@Override | |||||
public void buttonClick(ClickEvent event) { | |||||
commitActions(); | |||||
} | |||||
})); | |||||
new Button("Commit actions", event -> commitActions())); | |||||
left.addComponent(createSpacer()); | left.addComponent(createSpacer()); | ||||
left.addComponent(new Button("Refresh", new Button.ClickListener() { | |||||
@Override | |||||
public void buttonClick(ClickEvent event) { | |||||
refreshTableContainer(); | |||||
} | |||||
})); | |||||
left.addComponent( | |||||
new Button("Refresh", event -> refreshTableContainer())); | |||||
Label expandSpacer = createSpacer(); | Label expandSpacer = createSpacer(); | ||||
left.addComponent(expandSpacer); | left.addComponent(expandSpacer); | ||||
} | } | ||||
private ClickListener createSetActionListener(final Action action) { | private ClickListener createSetActionListener(final Action action) { | ||||
return new ClickListener() { | |||||
@Override | |||||
public void buttonClick(ClickEvent event) { | |||||
setActions(action); | |||||
} | |||||
}; | |||||
return event -> setActions(action); | |||||
} | } | ||||
public void setActions(final Action action) { | public void setActions(final Action action) { | ||||
table.setHeight("100%"); | table.setHeight("100%"); | ||||
table.setMultiSelect(true); | table.setMultiSelect(true); | ||||
table.addValueChangeListener(new ValueChangeListener() { | |||||
@Override | |||||
public void valueChange(ValueChangeEvent event) { | |||||
@SuppressWarnings("unchecked") | |||||
Collection<ComparisonFailure> selectedRows = (Collection<ComparisonFailure>) table | |||||
.getValue(); | |||||
table.addValueChangeListener(event -> { | |||||
viewer.setItems(selectedRows); | |||||
} | |||||
@SuppressWarnings("unchecked") | |||||
Collection<ComparisonFailure> selectedRows = (Collection<ComparisonFailure>) table | |||||
.getValue(); | |||||
viewer.setItems(selectedRows); | |||||
}); | }); | ||||
table.addShortcutListener( | table.addShortcutListener( |
import com.vaadin.shared.ui.window.WindowRole; | import com.vaadin.shared.ui.window.WindowRole; | ||||
import com.vaadin.tests.components.AbstractReindeerTestUI; | import com.vaadin.tests.components.AbstractReindeerTestUI; | ||||
import com.vaadin.ui.Button; | import com.vaadin.ui.Button; | ||||
import com.vaadin.ui.Button.ClickEvent; | |||||
import com.vaadin.ui.Button.ClickListener; | |||||
import com.vaadin.ui.Window; | import com.vaadin.ui.Window; | ||||
/** | /** | ||||
@Override | @Override | ||||
protected void setup(VaadinRequest request) { | protected void setup(VaadinRequest request) { | ||||
Button closeButton = new Button("Close windows"); | Button closeButton = new Button("Close windows"); | ||||
closeButton.addClickListener(new ClickListener() { | |||||
@Override | |||||
public void buttonClick(ClickEvent event) { | |||||
while (!windows.isEmpty()) { | |||||
Window window = windows.pop(); | |||||
removeWindow(window); | |||||
} | |||||
closeButton.addClickListener(event -> { | |||||
while (!windows.isEmpty()) { | |||||
Window window = windows.pop(); | |||||
removeWindow(window); | |||||
} | } | ||||
}); | }); | ||||
Button regularButton = new Button("Regular"); | Button regularButton = new Button("Regular"); | ||||
regularButton.addClickListener(new ClickListener() { | |||||
@Override | |||||
public void buttonClick(ClickEvent event) { | |||||
Window regularWindow = new Window("Regular window"); | |||||
openWindow(regularWindow); | |||||
} | |||||
regularButton.addClickListener(event -> { | |||||
Window regularWindow = new Window("Regular window"); | |||||
openWindow(regularWindow); | |||||
}); | }); | ||||
Button alertButton = new Button("Alert"); | Button alertButton = new Button("Alert"); | ||||
alertButton.addClickListener(new ClickListener() { | |||||
@Override | |||||
public void buttonClick(ClickEvent event) { | |||||
Window alertWindow = new Window("Alert window"); | |||||
alertWindow.setAssistiveRole(WindowRole.ALERTDIALOG); | |||||
openWindow(alertWindow); | |||||
} | |||||
alertButton.addClickListener(event -> { | |||||
Window alertWindow = new Window("Alert window"); | |||||
alertWindow.setAssistiveRole(WindowRole.ALERTDIALOG); | |||||
openWindow(alertWindow); | |||||
}); | }); | ||||
addComponent(closeButton); | addComponent(closeButton); | ||||
addComponent(regularButton); | addComponent(regularButton); |
import com.vaadin.server.VaadinRequest; | import com.vaadin.server.VaadinRequest; | ||||
import com.vaadin.tests.components.AbstractTestUIWithLog; | import com.vaadin.tests.components.AbstractTestUIWithLog; | ||||
import com.vaadin.ui.Button; | import com.vaadin.ui.Button; | ||||
import com.vaadin.ui.Button.ClickEvent; | |||||
public class ActionsOnInvisibleComponents extends AbstractTestUIWithLog { | public class ActionsOnInvisibleComponents extends AbstractTestUIWithLog { | ||||
Button invisibleButton = new Button("Invisible button with shortcut"); | Button invisibleButton = new Button("Invisible button with shortcut"); | ||||
invisibleButton.setClickShortcut(KeyCode.A); | invisibleButton.setClickShortcut(KeyCode.A); | ||||
invisibleButton.addClickListener(new Button.ClickListener() { | |||||
@Override | |||||
public void buttonClick(ClickEvent event) { | |||||
log("Click event for invisible button"); | |||||
} | |||||
}); | |||||
invisibleButton | |||||
.addClickListener( | |||||
event -> log("Click event for invisible button")); | |||||
invisibleButton.setVisible(false); | invisibleButton.setVisible(false); | ||||
addComponent(invisibleButton); | addComponent(invisibleButton); | ||||
Button disabledButton = new Button("Disabled button with shortcut"); | Button disabledButton = new Button("Disabled button with shortcut"); | ||||
disabledButton.setClickShortcut(KeyCode.B); | disabledButton.setClickShortcut(KeyCode.B); | ||||
disabledButton.addClickListener(new Button.ClickListener() { | |||||
@Override | |||||
public void buttonClick(ClickEvent event) { | |||||
log("Click event for disabled button"); | |||||
} | |||||
}); | |||||
disabledButton | |||||
.addClickListener( | |||||
event -> log("Click event for disabled button")); | |||||
disabledButton.setEnabled(false); | disabledButton.setEnabled(false); | ||||
addComponent(disabledButton); | addComponent(disabledButton); | ||||
Button enabledButton = new Button("Enabled button with shortcut"); | Button enabledButton = new Button("Enabled button with shortcut"); | ||||
enabledButton.setClickShortcut(KeyCode.C); | enabledButton.setClickShortcut(KeyCode.C); | ||||
enabledButton.addClickListener(new Button.ClickListener() { | |||||
@Override | |||||
public void buttonClick(ClickEvent event) { | |||||
log("Click event for enabled button"); | |||||
} | |||||
}); | |||||
enabledButton | |||||
.addClickListener( | |||||
event -> log("Click event for enabled button")); | |||||
addComponent(enabledButton); | addComponent(enabledButton); | ||||
} | } |
import com.vaadin.shared.ui.ContentMode; | import com.vaadin.shared.ui.ContentMode; | ||||
import com.vaadin.tests.components.TestBase; | import com.vaadin.tests.components.TestBase; | ||||
import com.vaadin.ui.Button; | import com.vaadin.ui.Button; | ||||
import com.vaadin.ui.Button.ClickEvent; | |||||
import com.vaadin.ui.Label; | import com.vaadin.ui.Label; | ||||
import com.vaadin.ui.LegacyWindow; | import com.vaadin.ui.LegacyWindow; | ||||
addComponent(applications); | addComponent(applications); | ||||
Label thisApp = new Label("This applications: " + this); | Label thisApp = new Label("This applications: " + this); | ||||
Button close = new Button("Close this", new Button.ClickListener() { | |||||
@Override | |||||
public void buttonClick(ClickEvent event) { | |||||
LegacyWindow ui = (LegacyWindow) event.getButton().getUI(); | |||||
ui.getApplication().close(); | |||||
} | |||||
Button close = new Button("Close this", event -> { | |||||
LegacyWindow ui = (LegacyWindow) event.getButton().getUI(); | |||||
ui.getApplication().close(); | |||||
}); | }); | ||||
StringBuilder sb = new StringBuilder(); | StringBuilder sb = new StringBuilder(); |
import com.vaadin.tests.components.AbstractTestUIWithLog; | import com.vaadin.tests.components.AbstractTestUIWithLog; | ||||
import com.vaadin.ui.Alignment; | import com.vaadin.ui.Alignment; | ||||
import com.vaadin.ui.Button; | import com.vaadin.ui.Button; | ||||
import com.vaadin.ui.Button.ClickEvent; | |||||
import com.vaadin.ui.Button.ClickListener; | |||||
import com.vaadin.ui.CheckBox; | import com.vaadin.ui.CheckBox; | ||||
import com.vaadin.ui.Component; | import com.vaadin.ui.Component; | ||||
import com.vaadin.ui.HorizontalLayout; | import com.vaadin.ui.HorizontalLayout; | ||||
import com.vaadin.ui.Label; | import com.vaadin.ui.Label; | ||||
import com.vaadin.ui.Panel; | import com.vaadin.ui.Panel; | ||||
import com.vaadin.ui.VerticalLayout; | import com.vaadin.ui.VerticalLayout; | ||||
import com.vaadin.v7.data.Property.ValueChangeEvent; | |||||
import com.vaadin.v7.data.Property.ValueChangeListener; | |||||
import com.vaadin.v7.ui.TextField; | import com.vaadin.v7.ui.TextField; | ||||
/** | /** | ||||
addComponent(createConfigPanel()); | addComponent(createConfigPanel()); | ||||
addComponent(createServerConfigPanel()); | addComponent(createServerConfigPanel()); | ||||
addComponent(new Button("Say hello", new ClickListener() { | |||||
@Override | |||||
public void buttonClick(ClickEvent event) { | |||||
log("Hello"); | |||||
} | |||||
})); | |||||
addComponent(new Button("Say hello", event -> log("Hello"))); | |||||
} | } | ||||
/** | /** | ||||
createTemporaryResponseCodeSetters("UIDL", uidlResponse)); | createTemporaryResponseCodeSetters("UIDL", uidlResponse)); | ||||
vl.addComponent(createTemporaryResponseCodeSetters("Heartbeat", | vl.addComponent(createTemporaryResponseCodeSetters("Heartbeat", | ||||
heartbeatResponse)); | heartbeatResponse)); | ||||
vl.addComponent(new Button("Activate", new ClickListener() { | |||||
@Override | |||||
public void buttonClick(ClickEvent event) { | |||||
if (uidlResponse.code != null && uidlResponse.code != 200) { | |||||
getServlet().setUIDLResponseCode(CommErrorEmulatorUI.this, | |||||
uidlResponse.code, uidlResponse.time); | |||||
log("Responding with " + uidlResponse.code | |||||
+ " to UIDL requests for " + uidlResponse.time | |||||
+ "s"); | |||||
} | |||||
if (heartbeatResponse.code != null | |||||
&& heartbeatResponse.code != 200) { | |||||
getServlet().setHeartbeatResponseCode( | |||||
CommErrorEmulatorUI.this, heartbeatResponse.code, | |||||
heartbeatResponse.time); | |||||
log("Responding with " + heartbeatResponse.code | |||||
+ " to heartbeat requests for " | |||||
+ heartbeatResponse.time + "s"); | |||||
} | |||||
vl.addComponent(new Button("Activate", event -> { | |||||
if (uidlResponse.code != null && uidlResponse.code != 200) { | |||||
getServlet().setUIDLResponseCode(CommErrorEmulatorUI.this, | |||||
uidlResponse.code, uidlResponse.time); | |||||
log("Responding with " + uidlResponse.code | |||||
+ " to UIDL requests for " + uidlResponse.time + "s"); | |||||
} | |||||
if (heartbeatResponse.code != null | |||||
&& heartbeatResponse.code != 200) { | |||||
getServlet().setHeartbeatResponseCode(CommErrorEmulatorUI.this, | |||||
heartbeatResponse.code, heartbeatResponse.time); | |||||
log("Responding with " + heartbeatResponse.code | |||||
+ " to heartbeat requests for " + heartbeatResponse.time | |||||
+ "s"); | |||||
} | } | ||||
})); | })); | ||||
reconnectDialogMessage | reconnectDialogMessage | ||||
.setValue(getReconnectDialogConfiguration().getDialogText()); | .setValue(getReconnectDialogConfiguration().getDialogText()); | ||||
reconnectDialogMessage | reconnectDialogMessage | ||||
.addValueChangeListener(new ValueChangeListener() { | |||||
@Override | |||||
public void valueChange(ValueChangeEvent event) { | |||||
.addValueChangeListener(event -> | |||||
getReconnectDialogConfiguration().setDialogText( | getReconnectDialogConfiguration().setDialogText( | ||||
reconnectDialogMessage.getValue()); | |||||
} | |||||
}); | |||||
reconnectDialogMessage.getValue())); | |||||
final TextField reconnectDialogGaveUpMessage = new TextField( | final TextField reconnectDialogGaveUpMessage = new TextField( | ||||
"Reconnect gave up message"); | "Reconnect gave up message"); | ||||
reconnectDialogGaveUpMessage.setValue( | reconnectDialogGaveUpMessage.setValue( | ||||
getReconnectDialogConfiguration().getDialogTextGaveUp()); | getReconnectDialogConfiguration().getDialogTextGaveUp()); | ||||
reconnectDialogGaveUpMessage | reconnectDialogGaveUpMessage | ||||
.addValueChangeListener(new ValueChangeListener() { | |||||
@Override | |||||
public void valueChange(ValueChangeEvent event) { | |||||
.addValueChangeListener(event -> | |||||
getReconnectDialogConfiguration().setDialogTextGaveUp( | getReconnectDialogConfiguration().setDialogTextGaveUp( | ||||
reconnectDialogGaveUpMessage.getValue()); | |||||
} | |||||
}); | |||||
reconnectDialogGaveUpMessage.getValue())); | |||||
final TextField reconnectDialogReconnectAttempts = new TextField( | final TextField reconnectDialogReconnectAttempts = new TextField( | ||||
"Reconnect attempts"); | "Reconnect attempts"); | ||||
reconnectDialogReconnectAttempts.setConverter(Integer.class); | reconnectDialogReconnectAttempts.setConverter(Integer.class); | ||||
reconnectDialogReconnectAttempts.setConvertedValue( | reconnectDialogReconnectAttempts.setConvertedValue( | ||||
getReconnectDialogConfiguration().getReconnectAttempts()); | getReconnectDialogConfiguration().getReconnectAttempts()); | ||||
reconnectDialogReconnectAttempts | reconnectDialogReconnectAttempts | ||||
.addValueChangeListener(new ValueChangeListener() { | |||||
@Override | |||||
public void valueChange(ValueChangeEvent event) { | |||||
.addValueChangeListener(event -> | |||||
getReconnectDialogConfiguration().setReconnectAttempts( | getReconnectDialogConfiguration().setReconnectAttempts( | ||||
(Integer) reconnectDialogReconnectAttempts | (Integer) reconnectDialogReconnectAttempts | ||||
.getConvertedValue()); | |||||
} | |||||
}); | |||||
.getConvertedValue())); | |||||
final TextField reconnectDialogReconnectInterval = new TextField( | final TextField reconnectDialogReconnectInterval = new TextField( | ||||
"Reconnect interval (ms)"); | "Reconnect interval (ms)"); | ||||
reconnectDialogReconnectInterval.setConverter(Integer.class); | reconnectDialogReconnectInterval.setConverter(Integer.class); | ||||
reconnectDialogReconnectInterval.setConvertedValue( | reconnectDialogReconnectInterval.setConvertedValue( | ||||
getReconnectDialogConfiguration().getReconnectInterval()); | getReconnectDialogConfiguration().getReconnectInterval()); | ||||
reconnectDialogReconnectInterval | reconnectDialogReconnectInterval | ||||
.addValueChangeListener(new ValueChangeListener() { | |||||
@Override | |||||
public void valueChange(ValueChangeEvent event) { | |||||
.addValueChangeListener(event -> | |||||
getReconnectDialogConfiguration().setReconnectInterval( | getReconnectDialogConfiguration().setReconnectInterval( | ||||
(Integer) reconnectDialogReconnectInterval | (Integer) reconnectDialogReconnectInterval | ||||
.getConvertedValue()); | |||||
} | |||||
}); | |||||
.getConvertedValue())); | |||||
final TextField reconnectDialogGracePeriod = new TextField( | final TextField reconnectDialogGracePeriod = new TextField( | ||||
"Reconnect dialog grace period (ms)"); | "Reconnect dialog grace period (ms)"); | ||||
reconnectDialogGracePeriod.setConvertedValue( | reconnectDialogGracePeriod.setConvertedValue( | ||||
getReconnectDialogConfiguration().getDialogGracePeriod()); | getReconnectDialogConfiguration().getDialogGracePeriod()); | ||||
reconnectDialogGracePeriod | reconnectDialogGracePeriod | ||||
.addValueChangeListener(new ValueChangeListener() { | |||||
@Override | |||||
public void valueChange(ValueChangeEvent event) { | |||||
getReconnectDialogConfiguration().setDialogGracePeriod( | |||||
.addValueChangeListener( | |||||
event -> getReconnectDialogConfiguration() | |||||
.setDialogGracePeriod( | |||||
(Integer) reconnectDialogGracePeriod | (Integer) reconnectDialogGracePeriod | ||||
.getConvertedValue()); | |||||
} | |||||
}); | |||||
.getConvertedValue())); | |||||
final CheckBox reconnectDialogModal = new CheckBox( | final CheckBox reconnectDialogModal = new CheckBox( | ||||
"Reconnect dialog modality"); | "Reconnect dialog modality"); | ||||
timeField.setWidth("5em"); | timeField.setWidth("5em"); | ||||
Label l3 = new Label("seconds"); | Label l3 = new Label("seconds"); | ||||
responseCode.addValueChangeListener(new ValueChangeListener() { | |||||
@Override | |||||
public void valueChange(ValueChangeEvent event) { | |||||
Integer code = (Integer) responseCode.getConvertedValue(); | |||||
response.code = code; | |||||
} | |||||
responseCode.addValueChangeListener(event -> { | |||||
Integer code = (Integer) responseCode.getConvertedValue(); | |||||
response.code = code; | |||||
}); | }); | ||||
timeField.addValueChangeListener(new ValueChangeListener() { | |||||
@Override | |||||
public void valueChange(ValueChangeEvent event) { | |||||
Integer time = (Integer) timeField.getConvertedValue(); | |||||
response.time = time; | |||||
} | |||||
timeField.addValueChangeListener(event -> { | |||||
Integer time = (Integer) timeField.getConvertedValue(); | |||||
response.time = time; | |||||
}); | }); | ||||
hl.addComponents(l1, responseCode, l2, timeField, l3); | hl.addComponents(l1, responseCode, l2, timeField, l3); |
import com.vaadin.server.VaadinRequest; | import com.vaadin.server.VaadinRequest; | ||||
import com.vaadin.tests.components.AbstractTestUIWithLog; | import com.vaadin.tests.components.AbstractTestUIWithLog; | ||||
import com.vaadin.ui.Button; | import com.vaadin.ui.Button; | ||||
import com.vaadin.ui.Button.ClickEvent; | |||||
import com.vaadin.ui.JavaScript; | import com.vaadin.ui.JavaScript; | ||||
public class ConfirmBrowserTabClose extends AbstractTestUIWithLog { | public class ConfirmBrowserTabClose extends AbstractTestUIWithLog { | ||||
// 3. Choose to stay on the page after all | // 3. Choose to stay on the page after all | ||||
// 4. Click the button | // 4. Click the button | ||||
// There should be no error | // There should be no error | ||||
Button b = new Button("Say hello", new Button.ClickListener() { | |||||
@Override | |||||
public void buttonClick(ClickEvent event) { | |||||
log("Hello"); | |||||
} | |||||
}); | |||||
Button b = new Button("Say hello", event -> log("Hello")); | |||||
addComponent(b); | addComponent(b); | ||||
JavaScript | JavaScript | ||||
.eval("window.addEventListener('beforeunload', function (e) {" | .eval("window.addEventListener('beforeunload', function (e) {" |
statusDisplay.setId("bundleStatus"); | statusDisplay.setId("bundleStatus"); | ||||
Button refreshButton = new Button("Refresh status", | Button refreshButton = new Button("Refresh status", | ||||
e -> statusDisplay.updateStatus()); | |||||
event -> statusDisplay.updateStatus()); | |||||
refreshButton.setId("refresh"); | refreshButton.setId("refresh"); | ||||
Button rtaButton = new Button("Add RichTextArea (in the lazy bundle)", | Button rtaButton = new Button("Add RichTextArea (in the lazy bundle)", | ||||
e -> addComponent(new RichTextArea())); | |||||
event -> addComponent(new RichTextArea())); | |||||
rtaButton.setId("rta"); | rtaButton.setId("rta"); | ||||
addComponents(statusDisplay, refreshButton, rtaButton); | addComponents(statusDisplay, refreshButton, rtaButton); |
import com.vaadin.shared.JsonConstants; | import com.vaadin.shared.JsonConstants; | ||||
import com.vaadin.tests.components.AbstractReindeerTestUI; | import com.vaadin.tests.components.AbstractReindeerTestUI; | ||||
import com.vaadin.ui.Button; | import com.vaadin.ui.Button; | ||||
import com.vaadin.ui.Button.ClickEvent; | |||||
import com.vaadin.ui.Button.ClickListener; | |||||
import com.vaadin.ui.CheckBox; | import com.vaadin.ui.CheckBox; | ||||
public class CriticalNotifications extends AbstractReindeerTestUI { | public class CriticalNotifications extends AbstractReindeerTestUI { | ||||
Button sessionExpired = new Button("Session expired"); | Button sessionExpired = new Button("Session expired"); | ||||
addComponent(sessionExpired); | addComponent(sessionExpired); | ||||
sessionExpired.addClickListener(new ClickListener() { | |||||
@Override | |||||
public void buttonClick(ClickEvent event) { | |||||
showCriticalNotification( | |||||
systemMessages.getSessionExpiredCaption(), | |||||
systemMessages.getSessionExpiredMessage(), | |||||
getDetailsMessage(), | |||||
systemMessages.getSessionExpiredURL()); | |||||
} | |||||
}); | |||||
sessionExpired.addClickListener(event -> | |||||
showCriticalNotification(systemMessages.getSessionExpiredCaption(), | |||||
systemMessages.getSessionExpiredMessage(), getDetailsMessage(), | |||||
systemMessages.getSessionExpiredURL())); | |||||
Button authenticationError = new Button("Authentication error"); | Button authenticationError = new Button("Authentication error"); | ||||
addComponent(authenticationError); | addComponent(authenticationError); | ||||
authenticationError.addClickListener(new ClickListener() { | |||||
@Override | |||||
public void buttonClick(ClickEvent event) { | |||||
showCriticalNotification( | |||||
systemMessages.getAuthenticationErrorCaption(), | |||||
systemMessages.getAuthenticationErrorMessage(), | |||||
getDetailsMessage(), | |||||
systemMessages.getAuthenticationErrorURL()); | |||||
} | |||||
}); | |||||
authenticationError.addClickListener(event -> | |||||
showCriticalNotification(systemMessages.getAuthenticationErrorCaption(), | |||||
systemMessages.getAuthenticationErrorMessage(), | |||||
getDetailsMessage(), | |||||
systemMessages.getAuthenticationErrorURL())); | |||||
Button communicationError = new Button("Communication error"); | Button communicationError = new Button("Communication error"); | ||||
addComponent(communicationError); | addComponent(communicationError); | ||||
communicationError.addClickListener(new ClickListener() { | |||||
@Override | |||||
public void buttonClick(ClickEvent event) { | |||||
showCriticalNotification( | |||||
systemMessages.getCommunicationErrorCaption(), | |||||
systemMessages.getCommunicationErrorMessage(), | |||||
getDetailsMessage(), | |||||
systemMessages.getCommunicationErrorURL()); | |||||
} | |||||
}); | |||||
communicationError.addClickListener(event -> | |||||
showCriticalNotification(systemMessages.getCommunicationErrorCaption(), | |||||
systemMessages.getCommunicationErrorMessage(), | |||||
getDetailsMessage(), | |||||
systemMessages.getCommunicationErrorURL())); | |||||
Button internalError = new Button("Internal error"); | Button internalError = new Button("Internal error"); | ||||
addComponent(internalError); | addComponent(internalError); | ||||
internalError.addClickListener(new ClickListener() { | |||||
@Override | |||||
public void buttonClick(ClickEvent event) { | |||||
showCriticalNotification( | |||||
systemMessages.getInternalErrorCaption(), | |||||
systemMessages.getInternalErrorMessage(), | |||||
getDetailsMessage(), | |||||
systemMessages.getInternalErrorURL()); | |||||
} | |||||
}); | |||||
internalError.addClickListener(event -> | |||||
showCriticalNotification(systemMessages.getInternalErrorCaption(), | |||||
systemMessages.getInternalErrorMessage(), getDetailsMessage(), | |||||
systemMessages.getInternalErrorURL())); | |||||
Button cookiesDisabled = new Button("Cookies disabled"); | Button cookiesDisabled = new Button("Cookies disabled"); | ||||
addComponent(cookiesDisabled); | addComponent(cookiesDisabled); | ||||
cookiesDisabled.addClickListener(new ClickListener() { | |||||
@Override | |||||
public void buttonClick(ClickEvent event) { | |||||
showCriticalNotification( | |||||
systemMessages.getCookiesDisabledCaption(), | |||||
systemMessages.getCookiesDisabledMessage(), | |||||
getDetailsMessage(), | |||||
systemMessages.getCookiesDisabledURL()); | |||||
} | |||||
}); | |||||
cookiesDisabled.addClickListener(event -> showCriticalNotification( | |||||
systemMessages.getCookiesDisabledCaption(), | |||||
systemMessages.getCookiesDisabledMessage(), getDetailsMessage(), | |||||
systemMessages.getCookiesDisabledURL())); | |||||
Button custom = new Button("Custom"); | Button custom = new Button("Custom"); | ||||
addComponent(custom); | addComponent(custom); | ||||
custom.addClickListener(new ClickListener() { | |||||
@Override | |||||
public void buttonClick(ClickEvent event) { | |||||
custom.addClickListener( | |||||
event -> | |||||
showCriticalNotification("Custom caption", "Custom message", | showCriticalNotification("Custom caption", "Custom message", | ||||
"Custom details", "custom url"); | |||||
} | |||||
}); | |||||
"Custom details", "custom url")); | |||||
} | } | ||||
protected String getDetailsMessage() { | protected String getDetailsMessage() { | ||||
if (includeDetails.getValue()) { | if (includeDetails.getValue()) { | ||||
return "Some details for the error"; | return "Some details for the error"; | ||||
} else { | |||||
return null; | |||||
} | } | ||||
return null; | |||||
} | } | ||||
protected void showCriticalNotification(String caption, String message, | protected void showCriticalNotification(String caption, String message, |
import com.vaadin.server.VaadinRequest; | import com.vaadin.server.VaadinRequest; | ||||
import com.vaadin.tests.components.AbstractTestUIWithLog; | import com.vaadin.tests.components.AbstractTestUIWithLog; | ||||
import com.vaadin.ui.Button; | import com.vaadin.ui.Button; | ||||
import com.vaadin.ui.Button.ClickEvent; | |||||
import com.vaadin.ui.Label; | import com.vaadin.ui.Label; | ||||
public class DetachOldUIOnReload extends AbstractTestUIWithLog { | public class DetachOldUIOnReload extends AbstractTestUIWithLog { | ||||
@Override | @Override | ||||
protected void setup(VaadinRequest request) { | protected void setup(VaadinRequest request) { | ||||
addComponent(new Label("This is UI " + getUIId())); | addComponent(new Label("This is UI " + getUIId())); | ||||
addComponent(new Button("Reload page", new Button.ClickListener() { | |||||
@Override | |||||
public void buttonClick(ClickEvent event) { | |||||
getPage().reload(); | |||||
} | |||||
})); | |||||
addComponent(new Button("Reload page", event -> getPage().reload())); | |||||
addComponent(new Button("Read log messages from session", | addComponent(new Button("Read log messages from session", | ||||
new Button.ClickListener() { | |||||
@Override | |||||
public void buttonClick(ClickEvent event) { | |||||
for (String message : getSessionMessages(false)) { | |||||
log(message); | |||||
} | |||||
event -> { | |||||
for (String message : getSessionMessages(false)) { | |||||
log(message); | |||||
} | } | ||||
})); | })); | ||||
} | } |
import com.vaadin.event.ShortcutAction.KeyCode; | import com.vaadin.event.ShortcutAction.KeyCode; | ||||
import com.vaadin.tests.components.AbstractTestCase; | import com.vaadin.tests.components.AbstractTestCase; | ||||
import com.vaadin.ui.Button; | import com.vaadin.ui.Button; | ||||
import com.vaadin.ui.Button.ClickEvent; | |||||
import com.vaadin.ui.Button.ClickListener; | |||||
import com.vaadin.ui.Component; | import com.vaadin.ui.Component; | ||||
import com.vaadin.ui.FormLayout; | import com.vaadin.ui.FormLayout; | ||||
import com.vaadin.ui.HorizontalLayout; | import com.vaadin.ui.HorizontalLayout; | ||||
formLayout.addComponent(login); | formLayout.addComponent(login); | ||||
mainWindow.setContent(formLayout); | mainWindow.setContent(formLayout); | ||||
login.addClickListener(new ClickListener() { | |||||
@Override | |||||
public void buttonClick(final ClickEvent event) { | |||||
String username = userField.getValue(); | |||||
String password = passwordField.getValue(); | |||||
login.addClickListener(event -> { | |||||
String username = userField.getValue(); | |||||
String password = passwordField.getValue(); | |||||
user = username; | |||||
showMainWindow(); | |||||
} | |||||
user = username; | |||||
showMainWindow(); | |||||
}); | }); | ||||
} | } | ||||
title.addStyleName("header-title"); | title.addStyleName("header-title"); | ||||
header.addComponent(title); | header.addComponent(title); | ||||
Button logout = new Button("Logout"); | Button logout = new Button("Logout"); | ||||
logout.addClickListener(new ClickListener() { | |||||
@Override | |||||
public void buttonClick(final ClickEvent event) { | |||||
user = null; | |||||
showLoginWindow(); | |||||
} | |||||
logout.addClickListener(event -> { | |||||
user = null; | |||||
showLoginWindow(); | |||||
}); | }); | ||||
header.addComponent(logout); | header.addComponent(logout); | ||||
return header; | return header; |
import com.vaadin.server.VaadinRequest; | import com.vaadin.server.VaadinRequest; | ||||
import com.vaadin.tests.components.AbstractReindeerTestUIWithLog; | import com.vaadin.tests.components.AbstractReindeerTestUIWithLog; | ||||
import com.vaadin.ui.Button; | import com.vaadin.ui.Button; | ||||
import com.vaadin.ui.Button.ClickEvent; | |||||
import com.vaadin.ui.Component; | import com.vaadin.ui.Component; | ||||
import com.vaadin.ui.CssLayout; | import com.vaadin.ui.CssLayout; | ||||
import com.vaadin.ui.Label; | import com.vaadin.ui.Label; | ||||
protected void setup(VaadinRequest request) { | protected void setup(VaadinRequest request) { | ||||
addComponent(brokenLayout); | addComponent(brokenLayout); | ||||
addComponent(normalLayout); | addComponent(normalLayout); | ||||
addComponent(new Button("Toggle properly", new Button.ClickListener() { | |||||
@Override | |||||
public void buttonClick(ClickEvent event) { | |||||
toggle(true); | |||||
} | |||||
})); | |||||
addComponent(new Button("Toggle properly", event -> toggle(true))); | |||||
addComponent( | addComponent( | ||||
new Button("Toggle improperly", new Button.ClickListener() { | |||||
@Override | |||||
public void buttonClick(ClickEvent event) { | |||||
toggle(false); | |||||
} | |||||
})); | |||||
new Button("Toggle improperly", event -> toggle(false))); | |||||
} | } | ||||
private void toggle(boolean properly) { | private void toggle(boolean properly) { |
import com.vaadin.server.VaadinRequest; | import com.vaadin.server.VaadinRequest; | ||||
import com.vaadin.tests.components.AbstractReindeerTestUIWithLog; | import com.vaadin.tests.components.AbstractReindeerTestUIWithLog; | ||||
import com.vaadin.ui.Button; | import com.vaadin.ui.Button; | ||||
import com.vaadin.ui.Button.ClickEvent; | |||||
import com.vaadin.ui.Button.ClickListener; | |||||
public class ReconnectDialogUI extends AbstractReindeerTestUIWithLog { | public class ReconnectDialogUI extends AbstractReindeerTestUIWithLog { | ||||
.parseInt(request.getParameter("reconnectAttempts"))); | .parseInt(request.getParameter("reconnectAttempts"))); | ||||
} | } | ||||
Button b = new Button("Say hello"); | Button b = new Button("Say hello"); | ||||
b.addClickListener(new ClickListener() { | |||||
@Override | |||||
public void buttonClick(ClickEvent event) { | |||||
log("Hello from the server"); | |||||
} | |||||
}); | |||||
b.addClickListener(event -> log("Hello from the server")); | |||||
addComponent(b); | addComponent(b); | ||||
} | } |
package com.vaadin.tests.application; | package com.vaadin.tests.application; | ||||
import com.vaadin.annotations.PreserveOnRefresh; | import com.vaadin.annotations.PreserveOnRefresh; | ||||
import com.vaadin.server.Page.UriFragmentChangedEvent; | |||||
import com.vaadin.server.Page.UriFragmentChangedListener; | |||||
import com.vaadin.server.VaadinRequest; | import com.vaadin.server.VaadinRequest; | ||||
import com.vaadin.tests.components.AbstractTestUIWithLog; | import com.vaadin.tests.components.AbstractTestUIWithLog; | ||||
import com.vaadin.ui.Label; | import com.vaadin.ui.Label; | ||||
log("Initial fragment: " + getPage().getUriFragment()); | log("Initial fragment: " + getPage().getUriFragment()); | ||||
getPage().addUriFragmentChangedListener( | getPage().addUriFragmentChangedListener( | ||||
new UriFragmentChangedListener() { | |||||
@Override | |||||
public void uriFragmentChanged( | |||||
UriFragmentChangedEvent event) { | |||||
log("Fragment changed to " + event.getUriFragment()); | |||||
} | |||||
}); | |||||
event -> log("Fragment changed to " + event.getUriFragment())); | |||||
} | } | ||||
@Override | @Override |
import com.vaadin.server.VaadinRequest; | import com.vaadin.server.VaadinRequest; | ||||
import com.vaadin.tests.components.AbstractTestUIWithLog; | import com.vaadin.tests.components.AbstractTestUIWithLog; | ||||
import com.vaadin.ui.Button; | import com.vaadin.ui.Button; | ||||
import com.vaadin.ui.Button.ClickEvent; | |||||
import com.vaadin.ui.Button.ClickListener; | |||||
public class ResynchronizeUI extends AbstractTestUIWithLog { | public class ResynchronizeUI extends AbstractTestUIWithLog { | ||||
@Override | @Override | ||||
protected void setup(VaadinRequest request) { | protected void setup(VaadinRequest request) { | ||||
Button b = new Button("Resynchronize", new ClickListener() { | |||||
@Override | |||||
public void buttonClick(ClickEvent event) { | |||||
// Theme change is currently the only operation which always | |||||
// does resynchronize | |||||
setTheme("runo"); | |||||
log("Set theme to runo"); | |||||
} | |||||
Button b = new Button("Resynchronize", event -> { | |||||
// Theme change is currently the only operation which always | |||||
// does resynchronize | |||||
setTheme("runo"); | |||||
log("Set theme to runo"); | |||||
}); | }); | ||||
addComponent(b); | addComponent(b); | ||||
} | } |
import com.vaadin.tests.components.TestBase; | import com.vaadin.tests.components.TestBase; | ||||
import com.vaadin.ui.Button; | import com.vaadin.ui.Button; | ||||
import com.vaadin.ui.Button.ClickEvent; | |||||
import com.vaadin.ui.Notification; | import com.vaadin.ui.Notification; | ||||
import com.vaadin.ui.UI; | import com.vaadin.ui.UI; | ||||
@Override | @Override | ||||
protected void setup() { | protected void setup() { | ||||
Button button = new Button("Throw exception", | Button button = new Button("Throw exception", | ||||
new Button.ClickListener() { | |||||
@Override | |||||
public void buttonClick(ClickEvent event) { | |||||
throw new RuntimeException("You asked for it"); | |||||
} | |||||
event -> { | |||||
throw new RuntimeException("You asked for it"); | |||||
}); | }); | ||||
addComponent(button); | addComponent(button); |
import com.vaadin.tests.integration.FlagSeResource; | import com.vaadin.tests.integration.FlagSeResource; | ||||
import com.vaadin.tests.util.Log; | import com.vaadin.tests.util.Log; | ||||
import com.vaadin.ui.Button; | import com.vaadin.ui.Button; | ||||
import com.vaadin.ui.Button.ClickEvent; | |||||
import com.vaadin.ui.Embedded; | import com.vaadin.ui.Embedded; | ||||
import com.vaadin.ui.LegacyWindow; | import com.vaadin.ui.LegacyWindow; | ||||
import com.vaadin.ui.UI; | import com.vaadin.ui.UI; | ||||
public ThreadLocalInstances() { | public ThreadLocalInstances() { | ||||
mainWindow.addComponent(log); | mainWindow.addComponent(log); | ||||
mainWindow.addComponent(new Embedded("Icon", resource)); | mainWindow.addComponent(new Embedded("Icon", resource)); | ||||
mainWindow.addComponent(new Button("Sync", new Button.ClickListener() { | |||||
@Override | |||||
public void buttonClick(ClickEvent event) { | |||||
reportCurrentStatus("button listener"); | |||||
} | |||||
})); | |||||
mainWindow.addComponent(new Button("Sync", | |||||
event -> reportCurrentStatus("button listener"))); | |||||
reportStatus("class init", staticInitApplication, staticInitRoot); | reportStatus("class init", staticInitApplication, staticInitRoot); | ||||
reportCurrentStatus("app constructor"); | reportCurrentStatus("app constructor"); |
import com.vaadin.server.VaadinRequest; | import com.vaadin.server.VaadinRequest; | ||||
import com.vaadin.tests.components.AbstractTestUIWithLog; | import com.vaadin.tests.components.AbstractTestUIWithLog; | ||||
import com.vaadin.ui.Button; | import com.vaadin.ui.Button; | ||||
import com.vaadin.ui.Button.ClickEvent; | |||||
import com.vaadin.ui.Button.ClickListener; | |||||
import com.vaadin.ui.JavaScriptFunction; | import com.vaadin.ui.JavaScriptFunction; | ||||
import elemental.json.JsonArray; | import elemental.json.JsonArray; | ||||
} | } | ||||
}); | }); | ||||
getPage().getJavaScript().execute(reportTimings); | getPage().getJavaScript().execute(reportTimings); | ||||
Button b = new Button("test request", new ClickListener() { | |||||
@Override | |||||
public void buttonClick(ClickEvent event) { | |||||
getPage().getJavaScript().execute(reportTimings); | |||||
} | |||||
}); | |||||
Button b = new Button("test request", | |||||
event -> getPage().getJavaScript().execute(reportTimings)); | |||||
addComponent(b); | addComponent(b); | ||||
} | } | ||||
} | } |
import com.vaadin.server.VaadinRequest; | import com.vaadin.server.VaadinRequest; | ||||
import com.vaadin.tests.components.AbstractReindeerTestUI; | import com.vaadin.tests.components.AbstractReindeerTestUI; | ||||
import com.vaadin.ui.Button; | import com.vaadin.ui.Button; | ||||
import com.vaadin.ui.Button.ClickEvent; | |||||
import com.vaadin.ui.Notification; | import com.vaadin.ui.Notification; | ||||
public class VaadinSessionAttribute extends AbstractReindeerTestUI { | public class VaadinSessionAttribute extends AbstractReindeerTestUI { | ||||
getSession().setAttribute(Integer.class, Integer.valueOf(42 * 2)); | getSession().setAttribute(Integer.class, Integer.valueOf(42 * 2)); | ||||
addComponent( | addComponent( | ||||
new Button("Show attribute values", new Button.ClickListener() { | |||||
@Override | |||||
public void buttonClick(ClickEvent event) { | |||||
Notification notification = new Notification( | |||||
getSession().getAttribute(ATTR_NAME) + " & " | |||||
+ getSession() | |||||
.getAttribute(Integer.class)); | |||||
notification.setDelayMsec(Notification.DELAY_FOREVER); | |||||
notification.show(getPage()); | |||||
} | |||||
new Button("Show attribute values", event -> { | |||||
Notification notification = new Notification( | |||||
getSession().getAttribute(ATTR_NAME) + " & " | |||||
+ getSession().getAttribute(Integer.class)); | |||||
notification.setDelayMsec(Notification.DELAY_FOREVER); | |||||
notification.show(getPage()); | |||||
})); | })); | ||||
} | } | ||||
import com.vaadin.server.VaadinRequest; | import com.vaadin.server.VaadinRequest; | ||||
import com.vaadin.tests.components.AbstractReindeerTestUI; | import com.vaadin.tests.components.AbstractReindeerTestUI; | ||||
import com.vaadin.ui.Button; | import com.vaadin.ui.Button; | ||||
import com.vaadin.ui.Button.ClickEvent; | |||||
import com.vaadin.ui.Label; | import com.vaadin.ui.Label; | ||||
public class WebBrowserSize extends AbstractReindeerTestUI { | public class WebBrowserSize extends AbstractReindeerTestUI { | ||||
final Label browserSizeLabel = new Label("n/a"); | final Label browserSizeLabel = new Label("n/a"); | ||||
browserSizeLabel.setCaption("Client (browser window) size"); | browserSizeLabel.setCaption("Client (browser window) size"); | ||||
final Button update = new Button("Refresh", new Button.ClickListener() { | |||||
@Override | |||||
public void buttonClick(ClickEvent event) { | |||||
screenSizeLabel.setValue(getBrowser().getScreenWidth() + " x " | |||||
+ getBrowser().getScreenHeight()); | |||||
browserSizeLabel.setValue(getPage().getBrowserWindowWidth() | |||||
+ " x " + getPage().getBrowserWindowHeight()); | |||||
} | |||||
final Button update = new Button("Refresh", event -> { | |||||
screenSizeLabel.setValue(getBrowser().getScreenWidth() + " x " | |||||
+ getBrowser().getScreenHeight()); | |||||
browserSizeLabel.setValue(getPage().getBrowserWindowWidth() + " x " | |||||
+ getPage().getBrowserWindowHeight()); | |||||
}); | }); | ||||
addComponent(update); | addComponent(update); |
import com.vaadin.server.VaadinRequest; | import com.vaadin.server.VaadinRequest; | ||||
import com.vaadin.tests.components.AbstractReindeerTestUI; | import com.vaadin.tests.components.AbstractReindeerTestUI; | ||||
import com.vaadin.ui.Button; | |||||
import com.vaadin.ui.Button.ClickEvent; | |||||
import com.vaadin.ui.Label; | import com.vaadin.ui.Label; | ||||
public class WebBrowserTimeZone extends AbstractReindeerTestUI { | public class WebBrowserTimeZone extends AbstractReindeerTestUI { | ||||
"Browser to Europe/Helsinki offset difference"); | "Browser to Europe/Helsinki offset difference"); | ||||
final Label containsLabel = addLabel("Browser could be in Helsinki"); | final Label containsLabel = addLabel("Browser could be in Helsinki"); | ||||
addButton("Get TimeZone from browser", new Button.ClickListener() { | |||||
addButton("Get TimeZone from browser", event -> { | |||||
TimeZone hkiTZ = TimeZone.getTimeZone("Europe/Helsinki"); | |||||
int hkiOffset = hkiTZ.getOffset(new Date().getTime()); | |||||
@Override | |||||
public void buttonClick(ClickEvent event) { | |||||
TimeZone hkiTZ = TimeZone.getTimeZone("Europe/Helsinki"); | |||||
int hkiOffset = hkiTZ.getOffset(new Date().getTime()); | |||||
int browserOffset = getBrowser().getTimezoneOffset(); | |||||
int browserRawOffset = getBrowser().getRawTimezoneOffset(); | |||||
String[] tzs = TimeZone.getAvailableIDs(browserRawOffset); | |||||
int browserOffset = getBrowser().getTimezoneOffset(); | |||||
int browserRawOffset = getBrowser().getRawTimezoneOffset(); | |||||
String[] tzs = TimeZone.getAvailableIDs(browserRawOffset); | |||||
boolean contains = Arrays.asList(tzs).contains(hkiTZ.getID()); | |||||
boolean contains = Arrays.asList(tzs).contains(hkiTZ.getID()); | |||||
offsetLabel.setValue(String.valueOf(browserOffset)); | |||||
rawOffsetLabel.setValue(String.valueOf(browserRawOffset)); | |||||
diffLabel.setValue(String.valueOf(browserOffset - hkiOffset)); | |||||
containsLabel.setValue(contains ? "Yes" : "No"); | |||||
dstDiffLabel | |||||
.setValue(String.valueOf(getBrowser().getDSTSavings())); | |||||
dstInEffectLabel | |||||
.setValue(getBrowser().isDSTInEffect() ? "Yes" : "No"); | |||||
curDateLabel.setValue(getBrowser().getCurrentDate().toString()); | |||||
} | |||||
offsetLabel.setValue(String.valueOf(browserOffset)); | |||||
rawOffsetLabel.setValue(String.valueOf(browserRawOffset)); | |||||
diffLabel.setValue(String.valueOf(browserOffset - hkiOffset)); | |||||
containsLabel.setValue(contains ? "Yes" : "No"); | |||||
dstDiffLabel.setValue(String.valueOf(getBrowser().getDSTSavings())); | |||||
dstInEffectLabel | |||||
.setValue(getBrowser().isDSTInEffect() ? "Yes" : "No"); | |||||
curDateLabel.setValue(getBrowser().getCurrentDate().toString()); | |||||
}); | }); | ||||
} | } | ||||
import com.vaadin.tests.components.AbstractReindeerTestUI; | import com.vaadin.tests.components.AbstractReindeerTestUI; | ||||
import com.vaadin.ui.Alignment; | import com.vaadin.ui.Alignment; | ||||
import com.vaadin.ui.Button; | import com.vaadin.ui.Button; | ||||
import com.vaadin.ui.Button.ClickEvent; | |||||
import com.vaadin.ui.Button.ClickListener; | |||||
import com.vaadin.ui.GridLayout; | import com.vaadin.ui.GridLayout; | ||||
import com.vaadin.ui.HorizontalLayout; | import com.vaadin.ui.HorizontalLayout; | ||||
import com.vaadin.ui.Label; | import com.vaadin.ui.Label; | ||||
addCommentButton = new Button("Add Comment"); | addCommentButton = new Button("Add Comment"); | ||||
addCommentButton.setWidth("100%"); | addCommentButton.setWidth("100%"); | ||||
addCommentButton.addClickListener(new ClickListener() { | |||||
@Override | |||||
public void buttonClick(ClickEvent event) { | |||||
final Window w = new Window("Add comment"); | |||||
VerticalLayout vl = new VerticalLayout(); | |||||
vl.setMargin(true); | |||||
final TextField tf = new TextField(); | |||||
tf.setSizeFull(); | |||||
vl.addComponent(tf); | |||||
HorizontalLayout hl = new HorizontalLayout(); | |||||
Button okButton = new Button("OK"); | |||||
okButton.setWidth("100%"); | |||||
okButton.addClickListener(new ClickListener() { | |||||
@Override | |||||
public void buttonClick(ClickEvent event) { | |||||
addRow("[ " + tf.getValue() + " ]"); | |||||
tf.setValue(""); | |||||
w.close(); | |||||
removeWindow(w); | |||||
} | |||||
}); | |||||
Button cancelButton = new Button("Cancel"); | |||||
cancelButton.setWidth("100%"); | |||||
cancelButton.addClickListener(new ClickListener() { | |||||
@Override | |||||
public void buttonClick(ClickEvent event) { | |||||
tf.setValue(""); | |||||
w.close(); | |||||
removeWindow(w); | |||||
} | |||||
}); | |||||
hl.addComponent(cancelButton); | |||||
hl.addComponent(okButton); | |||||
hl.setSpacing(true); | |||||
hl.setWidth("100%"); | |||||
vl.addComponent(hl); | |||||
vl.setSpacing(true); | |||||
w.setContent(vl); | |||||
addWindow(w); | |||||
} | |||||
addCommentButton.addClickListener(event -> { | |||||
final Window w = new Window("Add comment"); | |||||
VerticalLayout vl = new VerticalLayout(); | |||||
vl.setMargin(true); | |||||
final TextField tf = new TextField(); | |||||
tf.setSizeFull(); | |||||
vl.addComponent(tf); | |||||
HorizontalLayout hl = new HorizontalLayout(); | |||||
Button okButton = new Button("OK"); | |||||
okButton.setWidth("100%"); | |||||
okButton.addClickListener(event2 -> { | |||||
addRow("[ " + tf.getValue() + " ]"); | |||||
tf.setValue(""); | |||||
w.close(); | |||||
removeWindow(w); | |||||
}); | |||||
Button cancelButton = new Button("Cancel"); | |||||
cancelButton.setWidth("100%"); | |||||
cancelButton.addClickListener(event2 -> { | |||||
tf.setValue(""); | |||||
w.close(); | |||||
removeWindow(w); | |||||
}); | |||||
hl.addComponent(cancelButton); | |||||
hl.addComponent(okButton); | |||||
hl.setSpacing(true); | |||||
hl.setWidth("100%"); | |||||
vl.addComponent(hl); | |||||
vl.setSpacing(true); | |||||
w.setContent(vl); | |||||
addWindow(w); | |||||
}); | }); | ||||
addComponent(addCommentButton); | addComponent(addCommentButton); | ||||
// Create a button and use this application for event handling | // Create a button and use this application for event handling | ||||
Button button = new Button(caption); | Button button = new Button(caption); | ||||
button.setWidth("40px"); | button.setWidth("40px"); | ||||
button.addClickListener(new ClickListener() { | |||||
@Override | |||||
public void buttonClick(ClickEvent event) { | |||||
// Get the button that was clicked | |||||
Button button = event.getButton(); | |||||
button.addClickListener(event -> { | |||||
// Get the button that was clicked | |||||
Button b = event.getButton(); | |||||
// Get the requested operation from the button caption | |||||
char requestedOperation = button.getCaption().charAt(0); | |||||
// Get the requested operation from the button caption | |||||
char requestedOperation = b.getCaption().charAt(0); | |||||
// Calculate the new value | |||||
double newValue = calculate(requestedOperation); | |||||
// Calculate the new value | |||||
double newValue = calculate(requestedOperation); | |||||
// Update the result label with the new value | |||||
display.setValue("" + newValue); | |||||
} | |||||
// Update the result label with the new value | |||||
display.setValue("" + newValue); | |||||
}); | }); | ||||
button.setId("button_" + caption); | button.setId("button_" + caption); | ||||
import com.vaadin.tests.components.AbstractTestCase; | import com.vaadin.tests.components.AbstractTestCase; | ||||
import com.vaadin.tests.util.Log; | import com.vaadin.tests.util.Log; | ||||
import com.vaadin.ui.Button; | import com.vaadin.ui.Button; | ||||
import com.vaadin.ui.Button.ClickEvent; | |||||
import com.vaadin.ui.Button.ClickListener; | |||||
import com.vaadin.ui.LegacyWindow; | import com.vaadin.ui.LegacyWindow; | ||||
public class ChangeSessionId extends AbstractTestCase { | public class ChangeSessionId extends AbstractTestCase { | ||||
mainWindow.addComponent(log); | mainWindow.addComponent(log); | ||||
mainWindow.addComponent(loginButton); | mainWindow.addComponent(loginButton); | ||||
mainWindow.addComponent( | mainWindow.addComponent( | ||||
new Button("Show session id", new Button.ClickListener() { | |||||
@Override | |||||
public void buttonClick(ClickEvent event) { | |||||
logSessionId(); | |||||
} | |||||
})); | |||||
new Button("Show session id", event -> logSessionId())); | |||||
setMainWindow(mainWindow); | setMainWindow(mainWindow); | ||||
loginButton.addClickListener(new ClickListener() { | |||||
@Override | |||||
public void buttonClick(ClickEvent event) { | |||||
String oldSessionId = getSessionId(); | |||||
VaadinService | |||||
.reinitializeSession(VaadinService.getCurrentRequest()); | |||||
String newSessionId = getSessionId(); | |||||
if (oldSessionId.equals(newSessionId)) { | |||||
log.log("FAILED! Both old and new session id is " | |||||
+ newSessionId); | |||||
} else { | |||||
log.log("Session id changed successfully from " | |||||
+ oldSessionId + " to " + newSessionId); | |||||
} | |||||
loginButton.addClickListener(event -> { | |||||
String oldSessionId = getSessionId(); | |||||
VaadinService | |||||
.reinitializeSession(VaadinService.getCurrentRequest()); | |||||
String newSessionId = getSessionId(); | |||||
if (oldSessionId.equals(newSessionId)) { | |||||
log.log("FAILED! Both old and new session id is " | |||||
+ newSessionId); | |||||
} else { | |||||
log.log("Session id changed successfully from " + oldSessionId | |||||
+ " to " + newSessionId); | |||||
} | } | ||||
}); | }); | ||||
logSessionId(); | logSessionId(); |
import com.vaadin.server.VaadinRequest; | import com.vaadin.server.VaadinRequest; | ||||
import com.vaadin.tests.components.AbstractTestUIWithLog; | import com.vaadin.tests.components.AbstractTestUIWithLog; | ||||
import com.vaadin.ui.Button; | import com.vaadin.ui.Button; | ||||
import com.vaadin.ui.Button.ClickEvent; | |||||
import com.vaadin.ui.Label; | import com.vaadin.ui.Label; | ||||
/** | /** | ||||
} | } | ||||
}); | }); | ||||
addComponent(new Button("Ping", new Button.ClickListener() { | |||||
@Override | |||||
public void buttonClick(ClickEvent event) { | |||||
log("pong"); | |||||
} | |||||
})); | |||||
addComponent(new Button("Ping", event -> log("pong"))); | |||||
} | } | ||||
private void logUIs() { | private void logUIs() { |
import com.vaadin.tests.components.AbstractReindeerTestUI; | import com.vaadin.tests.components.AbstractReindeerTestUI; | ||||
import com.vaadin.tests.util.Log; | import com.vaadin.tests.util.Log; | ||||
import com.vaadin.ui.Button; | import com.vaadin.ui.Button; | ||||
import com.vaadin.ui.Button.ClickEvent; | |||||
import com.vaadin.ui.UI; | import com.vaadin.ui.UI; | ||||
public class CloseSession extends AbstractReindeerTestUI { | public class CloseSession extends AbstractReindeerTestUI { | ||||
addComponent(log); | addComponent(log); | ||||
addComponent( | addComponent( | ||||
new Button("Close VaadinServiceSession and redirect elsewhere", | new Button("Close VaadinServiceSession and redirect elsewhere", | ||||
new Button.ClickListener() { | |||||
@Override | |||||
public void buttonClick(ClickEvent event) { | |||||
// Assuming Vaadin is deployed to the root | |||||
// context | |||||
getPage().setLocation( | |||||
"/statictestfiles/static.html"); | |||||
getSession().close(); | |||||
} | |||||
event -> { | |||||
// Assuming Vaadin is deployed to the root | |||||
// context | |||||
getPage().setLocation( | |||||
"/statictestfiles/static.html"); | |||||
getSession().close(); | |||||
})); | })); | ||||
addComponent(new Button("Close VaadinServiceSession and reopen page", | addComponent(new Button("Close VaadinServiceSession and reopen page", | ||||
new Button.ClickListener() { | |||||
@Override | |||||
public void buttonClick(ClickEvent event) { | |||||
getPage().setLocation(reopenUrl); | |||||
getSession().close(); | |||||
} | |||||
event -> { | |||||
getPage().setLocation(reopenUrl); | |||||
getSession().close(); | |||||
})); | })); | ||||
addComponent(new Button("Just close VaadinSession", | addComponent(new Button("Just close VaadinSession", | ||||
new Button.ClickListener() { | |||||
@Override | |||||
public void buttonClick(ClickEvent event) { | |||||
getSession().close(); | |||||
} | |||||
})); | |||||
event -> getSession().close())); | |||||
addComponent(new Button("Just close HttpSession", | addComponent(new Button("Just close HttpSession", | ||||
new Button.ClickListener() { | |||||
@Override | |||||
public void buttonClick(ClickEvent event) { | |||||
getSession().getSession().invalidate(); | |||||
} | |||||
})); | |||||
event -> getSession().getSession().invalidate())); | |||||
addComponent(new Button("Invalidate HttpSession and reopen page", | addComponent(new Button("Invalidate HttpSession and reopen page", | ||||
new Button.ClickListener() { | |||||
@Override | |||||
public void buttonClick(ClickEvent event) { | |||||
VaadinService.getCurrentRequest().getWrappedSession() | |||||
.invalidate(); | |||||
getPage().setLocation(reopenUrl); | |||||
} | |||||
event -> { | |||||
VaadinService.getCurrentRequest().getWrappedSession() | |||||
.invalidate(); | |||||
getPage().setLocation(reopenUrl); | |||||
})); | })); | ||||
addComponent(new Button("Invalidate HttpSession and redirect elsewhere", | addComponent(new Button("Invalidate HttpSession and redirect elsewhere", | ||||
new Button.ClickListener() { | |||||
@Override | |||||
public void buttonClick(ClickEvent event) { | |||||
VaadinService.getCurrentRequest().getWrappedSession() | |||||
.invalidate(); | |||||
getPage().setLocation("/statictestfiles/static.html"); | |||||
} | |||||
event -> { | |||||
VaadinService.getCurrentRequest().getWrappedSession() | |||||
.invalidate(); | |||||
getPage().setLocation("/statictestfiles/static.html"); | |||||
})); | })); | ||||
addComponent(new Button("Invalidate HttpSession in a background thread", | addComponent(new Button("Invalidate HttpSession in a background thread", | ||||
new Button.ClickListener() { | |||||
@Override | |||||
public void buttonClick(ClickEvent event) { | |||||
final HttpSession session = ((WrappedHttpSession) VaadinService | |||||
.getCurrentRequest().getWrappedSession()) | |||||
.getHttpSession(); | |||||
Thread t = new Thread(new Runnable() { | |||||
@Override | |||||
public void run() { | |||||
try { | |||||
Thread.sleep(1000); | |||||
} catch (InterruptedException e) { | |||||
e.printStackTrace(); | |||||
} | |||||
System.out.println( | |||||
"Invalidating session from thread " | |||||
+ session.getId()); | |||||
session.invalidate(); | |||||
System.out.println( | |||||
"Invalidated session from thread " | |||||
+ session.getId()); | |||||
event -> { | |||||
final HttpSession session = ((WrappedHttpSession) VaadinService | |||||
.getCurrentRequest().getWrappedSession()) | |||||
.getHttpSession(); | |||||
Thread t = new Thread(new Runnable() { | |||||
@Override | |||||
public void run() { | |||||
try { | |||||
Thread.sleep(1000); | |||||
} catch (InterruptedException e) { | |||||
e.printStackTrace(); | |||||
} | } | ||||
}); | |||||
t.start(); | |||||
} | |||||
System.out | |||||
.println("Invalidating session from thread " | |||||
+ session.getId()); | |||||
session.invalidate(); | |||||
System.out | |||||
.println("Invalidated session from thread " | |||||
+ session.getId()); | |||||
} | |||||
}); | |||||
t.start(); | |||||
})); | })); | ||||
} | } | ||||
import com.vaadin.server.VaadinService; | import com.vaadin.server.VaadinService; | ||||
import com.vaadin.server.VaadinSession; | import com.vaadin.server.VaadinSession; | ||||
import com.vaadin.tests.components.AbstractTestUIWithLog; | import com.vaadin.tests.components.AbstractTestUIWithLog; | ||||
import com.vaadin.ui.Button; | |||||
import com.vaadin.ui.Button.ClickEvent; | |||||
import com.vaadin.ui.UI; | import com.vaadin.ui.UI; | ||||
public class CloseUI extends AbstractTestUIWithLog { | public class CloseUI extends AbstractTestUIWithLog { | ||||
log("Same WrappedSession id? " + oldSessionId.equals(sessionId)); | log("Same WrappedSession id? " + oldSessionId.equals(sessionId)); | ||||
} | } | ||||
addButton("Log 'hello'", new Button.ClickListener() { | |||||
@Override | |||||
public void buttonClick(ClickEvent event) { | |||||
log("Hello"); | |||||
} | |||||
}); | |||||
addButton("Close UI", new Button.ClickListener() { | |||||
@Override | |||||
public void buttonClick(ClickEvent event) { | |||||
close(); | |||||
} | |||||
}); | |||||
addButton("Log 'hello'", event -> log("Hello")); | |||||
addButton("Close UI", event -> close()); | |||||
addButton("Close UI (background)", new Button.ClickListener() { | |||||
@Override | |||||
public void buttonClick(ClickEvent event) { | |||||
new UIRunSafelyThread(CloseUI.this) { | |||||
@Override | |||||
protected void runSafely() { | |||||
close(); | |||||
} | |||||
}.start(); | |||||
} | |||||
addButton("Close UI (background)", event -> { | |||||
new UIRunSafelyThread(CloseUI.this) { | |||||
@Override | |||||
protected void runSafely() { | |||||
close(); | |||||
} | |||||
}.start(); | |||||
}); | }); | ||||
addButton("Close UI and redirect to /statictestfiles/static.html", | addButton("Close UI and redirect to /statictestfiles/static.html", | ||||
new Button.ClickListener() { | |||||
@Override | |||||
public void buttonClick(ClickEvent event) { | |||||
getPage().setLocation("/statictestfiles/static.html"); | |||||
close(); | |||||
} | |||||
event -> { | |||||
getPage().setLocation("/statictestfiles/static.html"); | |||||
close(); | |||||
}); | }); | ||||
addButton( | addButton( | ||||
"Close UI and redirect to /statictestfiles/static.html (background)", | "Close UI and redirect to /statictestfiles/static.html (background)", | ||||
new Button.ClickListener() { | |||||
@Override | |||||
public void buttonClick(ClickEvent event) { | |||||
new UIRunSafelyThread(CloseUI.this) { | |||||
@Override | |||||
protected void runSafely() { | |||||
getPage().setLocation( | |||||
"/statictestfiles/static.html"); | |||||
close(); | |||||
} | |||||
}.start(); | |||||
} | |||||
event -> { | |||||
new UIRunSafelyThread(CloseUI.this) { | |||||
@Override | |||||
protected void runSafely() { | |||||
getPage().setLocation( | |||||
"/statictestfiles/static.html"); | |||||
close(); | |||||
} | |||||
}.start(); | |||||
}); | }); | ||||
} | } |
import com.vaadin.server.VaadinRequest; | import com.vaadin.server.VaadinRequest; | ||||
import com.vaadin.tests.components.AbstractTestUIWithLog; | import com.vaadin.tests.components.AbstractTestUIWithLog; | ||||
import com.vaadin.ui.Button.ClickEvent; | |||||
import com.vaadin.ui.Button.ClickListener; | |||||
public class SessionExpiration extends AbstractTestUIWithLog { | public class SessionExpiration extends AbstractTestUIWithLog { | ||||
@Override | @Override | ||||
protected void setup(VaadinRequest request) { | protected void setup(VaadinRequest request) { | ||||
getSession().getSession().setMaxInactiveInterval(2); | getSession().getSession().setMaxInactiveInterval(2); | ||||
addButton("Click to avoid expiration", new ClickListener() { | |||||
@Override | |||||
public void buttonClick(ClickEvent event) { | |||||
log("Clicked"); | |||||
} | |||||
}); | |||||
addButton("Click to avoid expiration", event -> log("Clicked")); | |||||
} | } | ||||
@Override | @Override |
import com.vaadin.server.VaadinService; | import com.vaadin.server.VaadinService; | ||||
import com.vaadin.tests.components.AbstractReindeerTestUI; | import com.vaadin.tests.components.AbstractReindeerTestUI; | ||||
import com.vaadin.ui.Button; | import com.vaadin.ui.Button; | ||||
import com.vaadin.ui.Button.ClickEvent; | |||||
import com.vaadin.ui.Button.ClickListener; | |||||
import com.vaadin.v7.data.Property.ValueChangeEvent; | |||||
import com.vaadin.v7.data.Property.ValueChangeListener; | |||||
import com.vaadin.v7.ui.NativeSelect; | import com.vaadin.v7.ui.NativeSelect; | ||||
import elemental.json.JsonObject; | import elemental.json.JsonObject; | ||||
localeSelect.addItem(new Locale("en", "US")); | localeSelect.addItem(new Locale("en", "US")); | ||||
localeSelect.addItem(new Locale("fi", "FI")); | localeSelect.addItem(new Locale("fi", "FI")); | ||||
localeSelect.addItem(Locale.GERMANY); | localeSelect.addItem(Locale.GERMANY); | ||||
localeSelect.addValueChangeListener(new ValueChangeListener() { | |||||
@Override | |||||
public void valueChange(ValueChangeEvent event) { | |||||
Locale locale = (Locale) localeSelect.getValue(); | |||||
setLocale(locale); | |||||
} | |||||
localeSelect.addValueChangeListener(event -> { | |||||
Locale locale = (Locale) localeSelect.getValue(); | |||||
setLocale(locale); | |||||
}); | }); | ||||
localeSelect.setValue(new Locale("fi", "FI")); | localeSelect.setValue(new Locale("fi", "FI")); | ||||
addComponent(localeSelect); | addComponent(localeSelect); | ||||
final MyButton failButton = new MyButton(); | final MyButton failButton = new MyButton(); | ||||
failButton.setCaption("Generate server side error"); | failButton.setCaption("Generate server side error"); | ||||
failButton.addClickListener(new ClickListener() { | |||||
@Override | |||||
public void buttonClick(ClickEvent event) { | |||||
failButton.fail = true; | |||||
failButton.markAsDirty(); | |||||
} | |||||
failButton.addClickListener(event -> { | |||||
failButton.fail = true; | |||||
failButton.markAsDirty(); | |||||
}); | }); | ||||
addComponent(failButton); | addComponent(failButton); | ||||
import com.vaadin.server.VaadinRequest; | import com.vaadin.server.VaadinRequest; | ||||
import com.vaadin.tests.components.AbstractReindeerTestUI; | import com.vaadin.tests.components.AbstractReindeerTestUI; | ||||
import com.vaadin.ui.Button; | import com.vaadin.ui.Button; | ||||
import com.vaadin.ui.Button.ClickEvent; | |||||
import com.vaadin.ui.GridLayout; | import com.vaadin.ui.GridLayout; | ||||
import com.vaadin.ui.UI; | import com.vaadin.ui.UI; | ||||
import com.vaadin.ui.VerticalLayout; | import com.vaadin.ui.VerticalLayout; | ||||
gl.setMargin(true); | gl.setMargin(true); | ||||
final Button testButton = new Button("Open Window", | final Button testButton = new Button("Open Window", | ||||
new Button.ClickListener() { | |||||
@Override | |||||
public void buttonClick(ClickEvent event) { | |||||
UI.getCurrent().addWindow(testWindow); | |||||
} | |||||
}); | |||||
event -> UI.getCurrent().addWindow(testWindow)); | |||||
uiLayout.addComponent(testButton); | uiLayout.addComponent(testButton); | ||||
} | } | ||||
@Override | @Override |
import com.vaadin.ui.AbsoluteLayout; | import com.vaadin.ui.AbsoluteLayout; | ||||
import com.vaadin.ui.AbsoluteLayout.ComponentPosition; | import com.vaadin.ui.AbsoluteLayout.ComponentPosition; | ||||
import com.vaadin.ui.Button; | 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.Label; | ||||
public class AbsoluteLayoutCorrectPositioningOfHiddenField extends TestBase { | public class AbsoluteLayoutCorrectPositioningOfHiddenField extends TestBase { | ||||
abs.addComponent(l, "top:20px;left:20px"); | abs.addComponent(l, "top:20px;left:20px"); | ||||
final Button action = new Button("Set visible"); | final Button action = new Button("Set visible"); | ||||
action.addClickListener(new ClickListener() { | |||||
@Override | |||||
public void buttonClick(ClickEvent event) { | |||||
if (l.isVisible()) { | |||||
l.setValue("Top 70, Left 20"); | |||||
ComponentPosition position = abs.getPosition(l); | |||||
position.setCSSString("top:70px;left:20px;"); | |||||
abs.setPosition(l, position); | |||||
} else { | |||||
l.setVisible(true); | |||||
action.setCaption("Move down"); | |||||
} | |||||
action.addClickListener(event -> { | |||||
if (l.isVisible()) { | |||||
l.setValue("Top 70, Left 20"); | |||||
ComponentPosition position = abs.getPosition(l); | |||||
position.setCSSString("top:70px;left:20px;"); | |||||
abs.setPosition(l, position); | |||||
} else { | |||||
l.setVisible(true); | |||||
action.setCaption("Move down"); | |||||
} | } | ||||
}); | }); | ||||
action.setId("actionButton"); | action.setId("actionButton"); |
import com.vaadin.ui.AbsoluteLayout; | import com.vaadin.ui.AbsoluteLayout; | ||||
import com.vaadin.ui.Alignment; | import com.vaadin.ui.Alignment; | ||||
import com.vaadin.ui.Button; | import com.vaadin.ui.Button; | ||||
import com.vaadin.ui.Button.ClickEvent; | |||||
import com.vaadin.ui.Embedded; | import com.vaadin.ui.Embedded; | ||||
import com.vaadin.ui.GridLayout; | import com.vaadin.ui.GridLayout; | ||||
import com.vaadin.ui.HorizontalLayout; | import com.vaadin.ui.HorizontalLayout; | ||||
btnLogin.setCaption("Login"); | btnLogin.setCaption("Login"); | ||||
btnLogin.setWidth("-1px"); | btnLogin.setWidth("-1px"); | ||||
btnLogin.setHeight("-1px"); | btnLogin.setHeight("-1px"); | ||||
btnLogin.addClickListener(new Button.ClickListener() { | |||||
@Override | |||||
public void buttonClick(Button.ClickEvent event) { | |||||
login(); | |||||
} | |||||
}); | |||||
btnLogin.addClickListener(event -> login()); | |||||
layoutLogin.addComponent(btnLogin); | layoutLogin.addComponent(btnLogin); | ||||
for (int index = 0; index < layoutLogin.getComponentCount(); index++) { | for (int index = 0; index < layoutLogin.getComponentCount(); index++) { | ||||
GridLayout gridButtons = new GridLayout(2, 3); | GridLayout gridButtons = new GridLayout(2, 3); | ||||
Button btn1 = new Button("Button one"); | Button btn1 = new Button("Button one"); | ||||
btn1.addClickListener(new Button.ClickListener() { | |||||
@Override | |||||
public void buttonClick(ClickEvent event) { | |||||
} | |||||
btn1.addClickListener(event -> { | |||||
}); | }); | ||||
gridButtons.addComponent(btn1, 0, 0); | gridButtons.addComponent(btn1, 0, 0); | ||||
Button btn2 = new Button("Button two"); | Button btn2 = new Button("Button two"); | ||||
btn2.addClickListener(new Button.ClickListener() { | |||||
@Override | |||||
public void buttonClick(ClickEvent event) { | |||||
} | |||||
btn2.addClickListener(event -> { | |||||
}); | }); | ||||
gridButtons.addComponent(btn2, 0, 1); | gridButtons.addComponent(btn2, 0, 1); | ||||
Button btn3 = new Button("Button three"); | Button btn3 = new Button("Button three"); | ||||
btn3.addClickListener(new Button.ClickListener() { | |||||
@Override | |||||
public void buttonClick(ClickEvent event) { | |||||
} | |||||
btn3.addClickListener(event -> { | |||||
}); | }); | ||||
gridButtons.addComponent(btn3, 1, 0); | gridButtons.addComponent(btn3, 1, 0); | ||||
import com.vaadin.tests.components.TestBase; | import com.vaadin.tests.components.TestBase; | ||||
import com.vaadin.ui.AbsoluteLayout; | import com.vaadin.ui.AbsoluteLayout; | ||||
import com.vaadin.ui.Button; | import com.vaadin.ui.Button; | ||||
import com.vaadin.ui.Button.ClickEvent; | |||||
import com.vaadin.ui.Component; | import com.vaadin.ui.Component; | ||||
import com.vaadin.ui.NativeButton; | import com.vaadin.ui.NativeButton; | ||||
addComponent(layout); | addComponent(layout); | ||||
addComponent(new Button("Change primary stylename", | addComponent(new Button("Change primary stylename", | ||||
new Button.ClickListener() { | |||||
@Override | |||||
public void buttonClick(ClickEvent event) { | |||||
layout.setPrimaryStyleName("my-second-absolute-layout"); | |||||
} | |||||
})); | |||||
event -> layout | |||||
.setPrimaryStyleName("my-second-absolute-layout"))); | |||||
} | } | ||||
@Override | @Override |
import com.vaadin.tests.components.TestBase; | import com.vaadin.tests.components.TestBase; | ||||
import com.vaadin.ui.AbsoluteLayout; | import com.vaadin.ui.AbsoluteLayout; | ||||
import com.vaadin.ui.Button; | import com.vaadin.ui.Button; | ||||
import com.vaadin.ui.Button.ClickEvent; | |||||
import com.vaadin.ui.ComponentContainer; | import com.vaadin.ui.ComponentContainer; | ||||
import com.vaadin.ui.VerticalLayout; | import com.vaadin.ui.VerticalLayout; | ||||
al.setHeight("200px"); | al.setHeight("200px"); | ||||
testButton = new Button("Click to move to inner layout", | testButton = new Button("Click to move to inner layout", | ||||
new Button.ClickListener() { | |||||
@Override | |||||
public void buttonClick(ClickEvent event) { | |||||
vl.addComponent(testButton); | |||||
} | |||||
}); | |||||
event -> vl.addComponent(testButton)); | |||||
al.addComponent(testButton); | al.addComponent(testButton); | ||||
addComponent(al); | addComponent(al); | ||||
Button b = new Button("Repaint inner layout", | Button b = new Button("Repaint inner layout", | ||||
new Button.ClickListener() { | |||||
@Override | |||||
public void buttonClick(ClickEvent event) { | |||||
vl.markAsDirty(); | |||||
} | |||||
}); | |||||
event -> vl.markAsDirty()); | |||||
addComponent(b); | addComponent(b); | ||||
} | } |
import com.vaadin.server.VaadinRequest; | import com.vaadin.server.VaadinRequest; | ||||
import com.vaadin.tests.components.AbstractReindeerTestUI; | import com.vaadin.tests.components.AbstractReindeerTestUI; | ||||
import com.vaadin.ui.Button; | import com.vaadin.ui.Button; | ||||
import com.vaadin.ui.Button.ClickEvent; | |||||
import com.vaadin.ui.CssLayout; | import com.vaadin.ui.CssLayout; | ||||
import com.vaadin.ui.Label; | import com.vaadin.ui.Label; | ||||
} | } | ||||
}; | }; | ||||
private Button buttonToAdd = new Button("Added from beforeClientResponse", | |||||
new Button.ClickListener() { | |||||
@Override | |||||
public void buttonClick(ClickEvent event) { | |||||
layout.addComponent(labelToRemove); | |||||
} | |||||
}) { | |||||
@Override | |||||
public void beforeClientResponse(boolean initial) { | |||||
super.beforeClientResponse(initial); | |||||
setCaption("Add label to layout"); | |||||
} | |||||
}; | |||||
private Label labelToRemove = new Label("Label to remove") { | private Label labelToRemove = new Label("Label to remove") { | ||||
int count = 0; | int count = 0; | ||||
} | } | ||||
}; | }; | ||||
private Button buttonToAdd = new Button("Added from beforeClientResponse", | |||||
event -> layout.addComponent(labelToRemove)) { | |||||
@Override | |||||
public void beforeClientResponse(boolean initial) { | |||||
super.beforeClientResponse(initial); | |||||
setCaption("Add label to layout"); | |||||
} | |||||
}; | |||||
@Override | @Override | ||||
protected void setup(VaadinRequest request) { | protected void setup(VaadinRequest request) { | ||||
layout.addComponent(labelToRemove); | layout.addComponent(labelToRemove); |
*/ | */ | ||||
package com.vaadin.tests.components.abstractcomponent; | package com.vaadin.tests.components.abstractcomponent; | ||||
import com.vaadin.event.ContextClickEvent; | |||||
import com.vaadin.event.ContextClickEvent.ContextClickListener; | import com.vaadin.event.ContextClickEvent.ContextClickListener; | ||||
import com.vaadin.server.VaadinRequest; | import com.vaadin.server.VaadinRequest; | ||||
import com.vaadin.tests.components.AbstractTestUIWithLog; | import com.vaadin.tests.components.AbstractTestUIWithLog; | ||||
import com.vaadin.ui.Button; | import com.vaadin.ui.Button; | ||||
import com.vaadin.ui.Button.ClickEvent; | |||||
public class ContextClickUI extends AbstractTestUIWithLog { | public class ContextClickUI extends AbstractTestUIWithLog { | ||||
@Override | @Override | ||||
protected void setup(VaadinRequest request) { | protected void setup(VaadinRequest request) { | ||||
final ContextClickListener listener = new ContextClickListener() { | |||||
@Override | |||||
public void contextClick(ContextClickEvent event) { | |||||
log("Received context click at (" + event.getClientX() + ", " | |||||
final ContextClickListener listener = event -> log( | |||||
"Received context click at (" + event.getClientX() + ", " | |||||
+ event.getClientY() + ")"); | + event.getClientY() + ")"); | ||||
} | |||||
}; | |||||
getUI().addContextClickListener(listener); | getUI().addContextClickListener(listener); | ||||
addComponent(new Button("Remove listener", new Button.ClickListener() { | |||||
@Override | |||||
public void buttonClick(ClickEvent event) { | |||||
getUI().removeContextClickListener(listener); | |||||
} | |||||
})); | |||||
addComponent(new Button("Remove listener", | |||||
event -> getUI().removeContextClickListener(listener))); | |||||
} | } | ||||
} | } |
import com.vaadin.server.VaadinRequest; | import com.vaadin.server.VaadinRequest; | ||||
import com.vaadin.tests.components.AbstractReindeerTestUI; | import com.vaadin.tests.components.AbstractReindeerTestUI; | ||||
import com.vaadin.ui.Button; | import com.vaadin.ui.Button; | ||||
import com.vaadin.ui.Button.ClickEvent; | |||||
import com.vaadin.ui.Label; | import com.vaadin.ui.Label; | ||||
import com.vaadin.v7.ui.TextField; | import com.vaadin.v7.ui.TextField; | ||||
addComponent(tf); | addComponent(tf); | ||||
Button updateButton = new Button("Update styles", | Button updateButton = new Button("Update styles", | ||||
new Button.ClickListener() { | |||||
event -> { | |||||
label.setPrimaryStyleName("updated"); | |||||
label.setStyleName("correctly"); | |||||
@Override | |||||
public void buttonClick(ClickEvent event) { | |||||
label.setPrimaryStyleName("updated"); | |||||
label.setStyleName("correctly"); | |||||
button.setPrimaryStyleName("updated"); | |||||
button.setStyleName("correctly"); | |||||
button.setPrimaryStyleName("updated"); | |||||
button.setStyleName("correctly"); | |||||
tf.setPrimaryStyleName("updated"); | |||||
tf.setStyleName("correctly"); | |||||
} | |||||
tf.setPrimaryStyleName("updated"); | |||||
tf.setStyleName("correctly"); | |||||
}); | }); | ||||
updateButton.setId("update-button"); | updateButton.setId("update-button"); | ||||
addComponent(updateButton); | addComponent(updateButton); |
Button button = new Button("Throw in beforeClientResponse") { | Button button = new Button("Throw in beforeClientResponse") { | ||||
private boolean throwInBeforeClientResponse = false; | private boolean throwInBeforeClientResponse = false; | ||||
{ | { | ||||
addClickListener(new ClickListener() { | |||||
@Override | |||||
public void buttonClick(ClickEvent event) { | |||||
throwInBeforeClientResponse = true; | |||||
// Make sure beforeClientResponse is called | |||||
markAsDirty(); | |||||
} | |||||
addClickListener(event -> { | |||||
throwInBeforeClientResponse = true; | |||||
// Make sure beforeClientResponse is called | |||||
markAsDirty(); | |||||
}); | }); | ||||
} | } | ||||
import com.vaadin.tests.widgetset.TestingWidgetSet; | import com.vaadin.tests.widgetset.TestingWidgetSet; | ||||
import com.vaadin.tests.widgetset.server.UseStateFromHierachyComponent; | import com.vaadin.tests.widgetset.server.UseStateFromHierachyComponent; | ||||
import com.vaadin.ui.Button; | import com.vaadin.ui.Button; | ||||
import com.vaadin.ui.Button.ClickEvent; | |||||
import com.vaadin.ui.Label; | import com.vaadin.ui.Label; | ||||
@Widgetset(TestingWidgetSet.NAME) | @Widgetset(TestingWidgetSet.NAME) | ||||
component.setContent(new Label("Content child")); | component.setContent(new Label("Content child")); | ||||
addComponent(component); | addComponent(component); | ||||
addComponent(new Button("Remove component", new Button.ClickListener() { | |||||
@Override | |||||
public void buttonClick(ClickEvent event) { | |||||
removeComponent(component); | |||||
} | |||||
})); | |||||
addComponent(new Button("Remove component", | |||||
event -> removeComponent(component))); | |||||
} | } | ||||
@Override | @Override |
((Container.Sortable) cb.getContainerDataSource()) | ((Container.Sortable) cb.getContainerDataSource()) | ||||
.sort(new Object[] { CAPTION }, new boolean[] { true }); | .sort(new Object[] { CAPTION }, new boolean[] { true }); | ||||
cb.setImmediate(true); | cb.setImmediate(true); | ||||
cb.addListener(new ValueChangeListener() { | |||||
@Override | |||||
public void valueChange(ValueChangeEvent event) { | |||||
updateLocale((Locale) localeSelect.getValue()); | |||||
} | |||||
}); | |||||
cb.addValueChangeListener( | |||||
event -> updateLocale((Locale) localeSelect.getValue())); | |||||
return cb; | return cb; | ||||
} | } | ||||
import com.vaadin.tests.components.TestBase; | import com.vaadin.tests.components.TestBase; | ||||
import com.vaadin.ui.Button; | 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.Notification; | ||||
import com.vaadin.v7.data.util.ObjectProperty; | import com.vaadin.v7.data.util.ObjectProperty; | ||||
import com.vaadin.v7.data.validator.StringLengthValidator; | import com.vaadin.v7.data.validator.StringLengthValidator; | ||||
tf.setBuffered(true); | tf.setBuffered(true); | ||||
tf.setRequired(true); | tf.setRequired(true); | ||||
Button b = new Button("Commit", new ClickListener() { | |||||
@Override | |||||
public void buttonClick(ClickEvent event) { | |||||
try { | |||||
tf.commit(); | |||||
if (tf.isValid()) { | |||||
getMainWindow().showNotification( | |||||
"OK! Form validated and no error was thrown", | |||||
Notification.TYPE_HUMANIZED_MESSAGE); | |||||
} else { | |||||
getMainWindow().showNotification( | |||||
"Form is invalid but no exception was thrown", | |||||
Notification.TYPE_ERROR_MESSAGE); | |||||
} | |||||
} catch (Exception e) { | |||||
if (tf.isValid()) { | |||||
getMainWindow().showNotification( | |||||
"Form is valid but an exception was thrown", | |||||
Notification.TYPE_ERROR_MESSAGE); | |||||
} else { | |||||
getMainWindow().showNotification( | |||||
"OK! Error was thrown for an invalid input", | |||||
Notification.TYPE_HUMANIZED_MESSAGE); | |||||
Button b = new Button("Commit", event -> { | |||||
try { | |||||
tf.commit(); | |||||
if (tf.isValid()) { | |||||
getMainWindow().showNotification( | |||||
"OK! Form validated and no error was thrown", | |||||
Notification.TYPE_HUMANIZED_MESSAGE); | |||||
} else { | |||||
getMainWindow().showNotification( | |||||
"Form is invalid but no exception was thrown", | |||||
Notification.TYPE_ERROR_MESSAGE); | |||||
} | |||||
} catch (Exception e) { | |||||
if (tf.isValid()) { | |||||
getMainWindow().showNotification( | |||||
"Form is valid but an exception was thrown", | |||||
Notification.TYPE_ERROR_MESSAGE); | |||||
} else { | |||||
getMainWindow().showNotification( | |||||
"OK! Error was thrown for an invalid input", | |||||
Notification.TYPE_HUMANIZED_MESSAGE); | |||||
} | |||||
} | } | ||||
} | } | ||||
}); | }); | ||||
addComponent(tf); | addComponent(tf); |
import com.vaadin.tests.components.TestBase; | import com.vaadin.tests.components.TestBase; | ||||
import com.vaadin.ui.Button; | import com.vaadin.ui.Button; | ||||
import com.vaadin.ui.Component.Event; | |||||
import com.vaadin.ui.Component.Listener; | |||||
import com.vaadin.v7.data.util.ObjectProperty; | import com.vaadin.v7.data.util.ObjectProperty; | ||||
import com.vaadin.v7.ui.TextField; | import com.vaadin.v7.ui.TextField; | ||||
// Button | // Button | ||||
Button button = new Button("Make data source read-only"); | Button button = new Button("Make data source read-only"); | ||||
button.addListener(new Listener() { | |||||
@Override | |||||
public void componentEvent(Event event) { | |||||
stateHolder.buttonClicked(); | |||||
} | |||||
}); | |||||
button.addListener(event -> stateHolder.buttonClicked()); | |||||
// Input field | // Input field | ||||
TextField input = new TextField("Field"); | TextField input = new TextField("Field"); |
import java.util.Date; | import java.util.Date; | ||||
import com.vaadin.ui.Button; | import com.vaadin.ui.Button; | ||||
import com.vaadin.ui.Button.ClickEvent; | |||||
import com.vaadin.v7.data.util.ObjectProperty; | import com.vaadin.v7.data.util.ObjectProperty; | ||||
import com.vaadin.v7.ui.PopupDateField; | import com.vaadin.v7.ui.PopupDateField; | ||||
property.setValue(new Date(2011 - 1900, 4, 6).getTime()); | property.setValue(new Date(2011 - 1900, 4, 6).getTime()); | ||||
addComponent(new Button("Set property value to 10000L", | addComponent(new Button("Set property value to 10000L", | ||||
new Button.ClickListener() { | |||||
@Override | |||||
public void buttonClick(ClickEvent event) { | |||||
property.setValue(10000L); | |||||
} | |||||
})); | |||||
event -> property.setValue(10000L))); | |||||
} | } | ||||
} | } |
import com.vaadin.tests.components.TestBase; | import com.vaadin.tests.components.TestBase; | ||||
import com.vaadin.tests.util.Log; | import com.vaadin.tests.util.Log; | ||||
import com.vaadin.v7.data.Property.ValueChangeEvent; | |||||
import com.vaadin.v7.data.Property.ValueChangeListener; | |||||
import com.vaadin.v7.data.util.ObjectProperty; | import com.vaadin.v7.data.util.ObjectProperty; | ||||
import com.vaadin.v7.data.validator.DoubleValidator; | import com.vaadin.v7.data.validator.DoubleValidator; | ||||
import com.vaadin.v7.data.validator.IntegerValidator; | import com.vaadin.v7.data.validator.IntegerValidator; | ||||
final TextField tf = new TextField("Enter an integer"); | final TextField tf = new TextField("Enter an integer"); | ||||
tf.setPropertyDataSource(new ObjectProperty<>(new Integer(2))); | tf.setPropertyDataSource(new ObjectProperty<>(new Integer(2))); | ||||
tf.setImmediate(true); | tf.setImmediate(true); | ||||
tf.addListener(new ValueChangeListener() { | |||||
@Override | |||||
public void valueChange(ValueChangeEvent event) { | |||||
try { | |||||
log.log("Value for " + tf.getCaption() + " changed to " | |||||
+ tf.getValue()); | |||||
log.log("Converted value is " + tf.getConvertedValue()); | |||||
} catch (Exception e) { | |||||
// TODO: handle exception | |||||
e.printStackTrace(); | |||||
} | |||||
tf.addValueChangeListener(event -> { | |||||
try { | |||||
log.log("Value for " + tf.getCaption() + " changed to " | |||||
+ tf.getValue()); | |||||
log.log("Converted value is " + tf.getConvertedValue()); | |||||
} catch (Exception e) { | |||||
// TODO: handle exception | |||||
e.printStackTrace(); | |||||
} | } | ||||
}); | }); | ||||
import com.vaadin.tests.components.TestBase; | import com.vaadin.tests.components.TestBase; | ||||
import com.vaadin.tests.util.Log; | import com.vaadin.tests.util.Log; | ||||
import com.vaadin.v7.data.Property.ValueChangeEvent; | |||||
import com.vaadin.v7.data.Property.ValueChangeListener; | import com.vaadin.v7.data.Property.ValueChangeListener; | ||||
import com.vaadin.v7.ui.TextField; | import com.vaadin.v7.ui.TextField; | ||||
final TextField tf = new TextField("Enter an integer"); | final TextField tf = new TextField("Enter an integer"); | ||||
tf.setConverter(Integer.class); | tf.setConverter(Integer.class); | ||||
tf.setImmediate(true); | tf.setImmediate(true); | ||||
tf.addListener(new ValueChangeListener() { | |||||
@Override | |||||
public void valueChange(ValueChangeEvent event) { | |||||
try { | |||||
log.log("Value for " + tf.getCaption() + " changed to " | |||||
+ tf.getValue()); | |||||
log.log("Converted value is " + tf.getConvertedValue()); | |||||
} catch (Exception e) { | |||||
// TODO: handle exception | |||||
e.printStackTrace(); | |||||
} | |||||
tf.addValueChangeListener(event -> { | |||||
try { | |||||
log.log("Value for " + tf.getCaption() + " changed to " | |||||
+ tf.getValue()); | |||||
log.log("Converted value is " + tf.getConvertedValue()); | |||||
} catch (Exception e) { | |||||
// TODO: handle exception | |||||
e.printStackTrace(); | |||||
} | } | ||||
}); | }); | ||||
import com.vaadin.server.VaadinRequest; | import com.vaadin.server.VaadinRequest; | ||||
import com.vaadin.tests.components.AbstractTestUIWithLog; | import com.vaadin.tests.components.AbstractTestUIWithLog; | ||||
import com.vaadin.ui.Button; | import com.vaadin.ui.Button; | ||||
import com.vaadin.ui.Button.ClickEvent; | |||||
import com.vaadin.ui.Button.ClickListener; | |||||
import com.vaadin.ui.TextField; | import com.vaadin.ui.TextField; | ||||
public class ShortcutAddAndRemove extends AbstractTestUIWithLog { | public class ShortcutAddAndRemove extends AbstractTestUIWithLog { | ||||
protected void setup(VaadinRequest request) { | protected void setup(VaadinRequest request) { | ||||
final Button logButton = new Button("Log a row (enter shortcut)"); | final Button logButton = new Button("Log a row (enter shortcut)"); | ||||
logButton.setClickShortcut(KeyCode.ENTER); | logButton.setClickShortcut(KeyCode.ENTER); | ||||
logButton.addClickListener(new ClickListener() { | |||||
@Override | |||||
public void buttonClick(ClickEvent event) { | |||||
log.log("Log button was clicked"); | |||||
} | |||||
}); | |||||
logButton.addClickListener(event -> log.log("Log button was clicked")); | |||||
final Button removeShortcut = new Button("Remove shortcut"); | final Button removeShortcut = new Button("Remove shortcut"); | ||||
removeShortcut.addClickListener(new ClickListener() { | |||||
@Override | |||||
public void buttonClick(ClickEvent event) { | |||||
logButton.removeClickShortcut(); | |||||
logButton.setCaption("Log a row (no shortcut)"); | |||||
} | |||||
removeShortcut.addClickListener(event -> { | |||||
logButton.removeClickShortcut(); | |||||
logButton.setCaption("Log a row (no shortcut)"); | |||||
}); | }); | ||||
final Button addShortcut = new Button("Add shortcut"); | final Button addShortcut = new Button("Add shortcut"); | ||||
addShortcut.addClickListener(new ClickListener() { | |||||
@Override | |||||
public void buttonClick(ClickEvent event) { | |||||
logButton.setClickShortcut(KeyCode.ENTER); | |||||
logButton.setCaption("Log a row (enter shortcut)"); | |||||
} | |||||
addShortcut.addClickListener(event -> { | |||||
logButton.setClickShortcut(KeyCode.ENTER); | |||||
logButton.setCaption("Log a row (enter shortcut)"); | |||||
}); | }); | ||||
addComponent(log); | addComponent(log); | ||||
addComponent(logButton); | addComponent(logButton); |
import com.vaadin.server.VaadinRequest; | import com.vaadin.server.VaadinRequest; | ||||
import com.vaadin.tests.components.AbstractTestUIWithLog; | import com.vaadin.tests.components.AbstractTestUIWithLog; | ||||
import com.vaadin.ui.Button; | import com.vaadin.ui.Button; | ||||
import com.vaadin.ui.Button.ClickEvent; | |||||
import com.vaadin.ui.Button.ClickListener; | |||||
public class ShortcutWhenBodyFocused extends AbstractTestUIWithLog { | public class ShortcutWhenBodyFocused extends AbstractTestUIWithLog { | ||||
@Override | @Override | ||||
protected void setup(VaadinRequest request) { | protected void setup(VaadinRequest request) { | ||||
Button b = new Button("Hello", new ClickListener() { | |||||
@Override | |||||
public void buttonClick(ClickEvent event) { | |||||
log("Hello clicked"); | |||||
} | |||||
}); | |||||
Button b = new Button("Hello", event -> log("Hello clicked")); | |||||
b.setClickShortcut(KeyCode.A); | b.setClickShortcut(KeyCode.A); | ||||
addComponent(b); | addComponent(b); | ||||
import com.vaadin.server.ErrorEvent; | import com.vaadin.server.ErrorEvent; | ||||
import com.vaadin.server.ErrorHandler; | import com.vaadin.server.ErrorHandler; | ||||
import com.vaadin.server.UserError; | import com.vaadin.server.UserError; | ||||
import com.vaadin.v7.data.Property.ValueChangeEvent; | |||||
import com.vaadin.v7.data.Property.ValueChangeListener; | |||||
import com.vaadin.v7.data.util.ObjectProperty; | import com.vaadin.v7.data.util.ObjectProperty; | ||||
import com.vaadin.v7.ui.ComboBox; | import com.vaadin.v7.ui.ComboBox; | ||||
import com.vaadin.v7.ui.TextField; | import com.vaadin.v7.ui.TextField; | ||||
dataType.addItem(Date.class); | dataType.addItem(Date.class); | ||||
dataType.addItem(String.class); | dataType.addItem(String.class); | ||||
dataType.addListener(new ValueChangeListener() { | |||||
@Override | |||||
public void valueChange(ValueChangeEvent event) { | |||||
dataType.addValueChangeListener(event -> | |||||
tf.setPropertyDataSource(new ObjectProperty<>(o, | tf.setPropertyDataSource(new ObjectProperty<>(o, | ||||
(Class<Object>) dataType.getValue())); | |||||
} | |||||
}); | |||||
(Class<Object>) dataType.getValue()))); | |||||
addComponent(dataType); | addComponent(dataType); | ||||
tf = new TextField("TextField"); | tf = new TextField("TextField"); |