com.vaadin.client.ui.datefield.AbstractDateFieldConnector Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of vaadin-client Show documentation
Show all versions of vaadin-client Show documentation
Vaadin is a web application framework for Rich Internet Applications (RIA).
Vaadin enables easy development and maintenance of fast and
secure rich web
applications with a stunning look and feel and a wide browser support.
It features a server-side architecture with the majority of the logic
running
on the server. Ajax technology is used at the browser-side to ensure a
rich
and interactive user experience.
/*
* Copyright 2000-2016 Vaadin Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.vaadin.client.ui.datefield;
import java.util.Map;
import java.util.Optional;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import com.vaadin.client.ApplicationConnection;
import com.vaadin.client.LocaleNotLoadedException;
import com.vaadin.client.Paintable;
import com.vaadin.client.UIDL;
import com.vaadin.client.VConsole;
import com.vaadin.client.ui.AbstractFieldConnector;
import com.vaadin.client.ui.VDateField;
import com.vaadin.shared.ui.datefield.DateFieldConstants;
public abstract class AbstractDateFieldConnector>
extends AbstractFieldConnector implements Paintable {
@Override
public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
if (!isRealUpdate(uidl)) {
return;
}
// Save details
getWidget().client = client;
getWidget().paintableId = uidl.getId();
getWidget().setReadonly(isReadOnly());
getWidget().setEnabled(isEnabled());
if (uidl.hasAttribute("locale")) {
final String locale = uidl.getStringAttribute("locale");
try {
getWidget().dts.setLocale(locale);
getWidget().setCurrentLocale(locale);
} catch (final LocaleNotLoadedException e) {
getWidget().setCurrentLocale(getWidget().dts.getLocale());
VConsole.error("Tried to use an unloaded locale \"" + locale
+ "\". Using default locale ("
+ getWidget().getCurrentLocale() + ").");
VConsole.error(e);
}
}
// We show week numbers only if the week starts with Monday, as ISO 8601
// specifies
getWidget().setShowISOWeekNumbers(
uidl.getBooleanAttribute(DateFieldConstants.ATTR_WEEK_NUMBERS)
&& getWidget().dts.getFirstDayOfWeek() == 1);
// Remove old stylename that indicates current resolution
setWidgetStyleName(getWidget().getStylePrimaryName() + "-"
+ getWidget().resolutionAsString(), false);
updateResolution(uidl);
// Add stylename that indicates current resolution
setWidgetStyleName(getWidget().getStylePrimaryName() + "-"
+ getWidget().resolutionAsString(), true);
getWidget().setCurrentDate(getTimeValues(uidl));
}
private void updateResolution(UIDL uidl) {
Optional newResolution = getWidget().getResolutions().filter(
res -> uidl.hasVariable(getWidget().getResolutionVariable(res)))
.findFirst();
getWidget().setCurrentResolution(newResolution.orElse(null));
}
protected Map getTimeValues(UIDL uidl) {
Stream resolutions = getWidget().getResolutions();
R resolution = getWidget().getCurrentResolution();
return resolutions
.collect(Collectors.toMap(Function.identity(),
res -> (resolution.compareTo(res) <= 0)
? uidl.getIntVariable(
getWidget().getResolutionVariable(res))
: -1));
}
@SuppressWarnings("unchecked")
@Override
public VDateField getWidget() {
return (VDateField) super.getWidget();
}
}