DateField basic port

This commit is contained in:
Yuriy Artamonov 2013-02-12 14:45:28 +00:00
parent d83f21baed
commit 0c723d63dd
5 changed files with 102 additions and 85 deletions

View File

@ -49,8 +49,8 @@ public class WebComponentsFactory implements ComponentsFactory {
classes.put(Table.NAME, WebTable.class);
classes.put(TreeTable.NAME, WebTreeTable.class);
classes.put(GroupTable.NAME, WebGroupTable.class);
// classes.put(DateField.NAME, WebDateField.class);
// classes.put(TimeField.NAME, WebTimeField.class);
classes.put(DateField.NAME, WebDateField.class);
classes.put(TimeField.NAME, WebTimeField.class);
classes.put(LookupField.NAME, WebLookupField.class);
// classes.put(SearchField.NAME, WebSearchField.class);
classes.put(PickerField.NAME, WebPickerField.class);

View File

@ -17,6 +17,7 @@ import com.vaadin.server.FileResource;
import com.vaadin.server.Resource;
import com.vaadin.server.ThemeResource;
import com.vaadin.shared.ui.combobox.FilteringMode;
import com.vaadin.shared.ui.datefield.Resolution;
import com.vaadin.ui.*;
import com.vaadin.ui.Button;
import com.vaadin.ui.Component;
@ -357,31 +358,27 @@ public class WebComponentsHelper {
return FieldGroupLayout.CAPTION_ALIGN_LEFT;
}
}
/*
public static int convertDateFieldResolution(com.haulmont.cuba.gui.components.DateField.Resolution resolution) {
public static Resolution convertDateFieldResolution(com.haulmont.cuba.gui.components.DateField.Resolution resolution) {
switch (resolution) {
case MSEC: {
return com.vaadin.ui.DateField.RESOLUTION_MSEC;
}
case SEC: {
return com.vaadin.ui.DateField.RESOLUTION_SEC;
}
case HOUR: {
return com.vaadin.ui.DateField.RESOLUTION_HOUR;
}
case DAY: {
return com.vaadin.ui.DateField.RESOLUTION_DAY;
}
case MONTH: {
return com.vaadin.ui.DateField.RESOLUTION_MONTH;
}
case YEAR: {
return com.vaadin.ui.DateField.RESOLUTION_YEAR;
}
case SEC:
return Resolution.SECOND;
case HOUR:
return Resolution.HOUR;
case DAY:
return Resolution.DAY;
case MONTH:
return Resolution.MONTH;
case YEAR:
return Resolution.YEAR;
case MIN:
default: {
return com.vaadin.ui.DateField.RESOLUTION_MIN;
}
default:
return Resolution.MINUTE;
}
}*/
}
}

View File

@ -2,10 +2,6 @@
* Copyright (c) 2008 Haulmont Technology Ltd. All Rights Reserved.
* Haulmont Technology proprietary and confidential.
* Use is subject to license terms.
* Author: Dmitry Abramov
* Created: 22.12.2008 18:12:13
* $Id$
*/
package com.haulmont.cuba.web.gui.components;
@ -14,8 +10,9 @@ import com.haulmont.chile.core.model.MetaProperty;
import com.haulmont.chile.core.model.MetaPropertyPath;
import com.haulmont.chile.core.model.utils.InstanceUtils;
import com.haulmont.cuba.core.entity.Entity;
import com.haulmont.cuba.core.global.ConfigProvider;
import com.haulmont.cuba.core.global.UserSessionProvider;
import com.haulmont.cuba.core.global.AppBeans;
import com.haulmont.cuba.core.global.Configuration;
import com.haulmont.cuba.core.global.UserSessionSource;
import com.haulmont.cuba.gui.components.*;
import com.haulmont.cuba.gui.data.Datasource;
import com.haulmont.cuba.gui.data.ValueChangingListener;
@ -34,12 +31,16 @@ import java.util.Calendar;
import java.util.Date;
import java.util.List;
/**
* @author abramov
* @version $Id$
*/
public class WebDateField
/*extends
extends
WebAbstractComponent<DateFieldWrapper>
implements
DateField, Component.Wrapper*/ {
/*
DateField, Component.Wrapper {
private Resolution resolution;
private Object prevValue = null;
@ -50,8 +51,8 @@ public class WebDateField
private com.haulmont.cuba.web.toolkit.ui.DateField dateField;
private WebTimeField timeField;
protected List<ValueListener> listeners = new ArrayList<ValueListener>();
protected List<Field.Validator> validators = new ArrayList<Field.Validator>();
protected List<ValueListener> listeners = new ArrayList<>();
protected List<Field.Validator> validators = new ArrayList<>();
protected HorizontalLayout composition;
@ -74,7 +75,7 @@ public class WebDateField
composition.setSpacing(true);
dateField = new com.haulmont.cuba.web.toolkit.ui.DateField();
dateField.setResolution(com.haulmont.cuba.web.toolkit.ui.DateField.RESOLUTION_DAY);
dateField.setResolution(com.vaadin.shared.ui.datefield.Resolution.DAY);
dateField.setWidth("100%");
dateField.setImmediate(true);
@ -82,17 +83,12 @@ public class WebDateField
dateField.addValidator(new com.vaadin.data.Validator() {
@Override
public void validate(Object value) throws InvalidValueException {
if (value instanceof Date)
return;
if (!isValid(value)) {
dateField.requestRepaint();
throw new InvalidValueException("Unable to parse value: " + value);
}
}
@Override
public boolean isValid(Object value) {
return true;
// if (value instanceof Date)
// return;
// if (!isValid(value)) {
// dateField.markAsDirty();
// throw new InvalidValueException("Unable to parse value: " + value);
// }
}
});
@ -104,7 +100,7 @@ public class WebDateField
timeField.<MaskedTextField>getComponent().setInvalidAllowed(false);
timeField.<MaskedTextField>getComponent().setInvalidCommitted(true);
dateField.addListener(new Property.ValueChangeListener() {
dateField.addValueChangeListener(new Property.ValueChangeListener() {
@Override
public void valueChange(Property.ValueChangeEvent event) {
updateInstance();
@ -118,7 +114,7 @@ public class WebDateField
}
});
setResolution(Resolution.MIN);
if (ConfigProvider.getConfig(WebConfig.class).getCloseCalendarWhenDateSelected()) {
if (AppBeans.get(Configuration.class).getConfig(WebConfig.class).getCloseCalendarWhenDateSelected()) {
setCloseWhenDateSelected(true);
}
component = new DateFieldWrapper(this, composition);
@ -202,7 +198,8 @@ public class WebDateField
}
protected void __setCloseWhenDateSelected(boolean autoClose) {
dateField.setCloseWhenDateSelected(autoClose);
// vaadin7
// dateField.setCloseWhenDateSelected(autoClose);
}
@Override
@ -234,7 +231,7 @@ public class WebDateField
prevValue = getValue();
if (!editable)
return;
dateField.setValue(value);
dateField.setValue((Date) value);
timeField.setValue(value);
}
@ -374,11 +371,14 @@ public class WebDateField
}
private Date constructDate() {
final Date datePickerDate = (Date) dateField.getValue();
final Date datePickerDate = dateField.getValue();
if (datePickerDate == null) {
return null;
}
Calendar c = Calendar.getInstance(UserSessionProvider.getLocale());
UserSessionSource uss = AppBeans.get(UserSessionSource.class);
Calendar c = Calendar.getInstance(uss.getLocale());
c.setTime(datePickerDate);
if (timeField.getValue() == null) {
c.set(Calendar.HOUR_OF_DAY, 0);
@ -386,7 +386,7 @@ public class WebDateField
c.set(Calendar.SECOND, 0);
} else {
Calendar c2 = Calendar.getInstance(UserSessionProvider.getLocale());
Calendar c2 = Calendar.getInstance(uss.getLocale());
c2.setTime(timeField.<Date>getValue());
c.set(Calendar.HOUR_OF_DAY, c2.get(Calendar.HOUR_OF_DAY));
@ -461,5 +461,5 @@ public class WebDateField
for (Field.Validator validator : validators) {
validator.validate(value);
}
}*/
}
}
}

View File

@ -2,11 +2,6 @@
* Copyright (c) 2010 Haulmont Technology Ltd. All Rights Reserved.
* Haulmont Technology proprietary and confidential.
* Use is subject to license terms.
* Author: Konstantin Krivopustov
* Created: 09.12.2010 17:11:28
*
* $Id$
*/
package com.haulmont.cuba.web.gui.components;
@ -24,6 +19,8 @@ import com.haulmont.cuba.web.gui.data.PropertyWrapper;
import com.haulmont.cuba.web.toolkit.ui.MaskedTextField;
import com.vaadin.data.Property;
import com.vaadin.data.util.PropertyFormatter;
import com.vaadin.data.util.converter.Converter;
import com.vaadin.server.UserError;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@ -33,8 +30,12 @@ import java.text.SimpleDateFormat;
import java.util.Collection;
import java.util.Date;
public class WebTimeField /*extends WebAbstractField<MaskedTextField> implements TimeField, Component.Wrapper*/ {
/*private boolean showSeconds;
/**
* @author krivopustov
* @version $Id$
*/
public class WebTimeField extends WebAbstractField<MaskedTextField> implements TimeField, Component.Wrapper {
private boolean showSeconds;
private String mask;
private String placeholder;
@ -57,26 +58,23 @@ public class WebTimeField /*extends WebAbstractField<MaskedTextField> implements
component.addValidator(new com.vaadin.data.Validator() {
@Override
public void validate(Object value) throws InvalidValueException {
if (!isValid(value)) {
component.requestRepaint();
if (!(!(value instanceof String) || checkStringValue((String) value))) {
component.markAsDirty();
throw new InvalidValueException("Unable to parse value: " + value);
}
}
@Override
public boolean isValid(Object value) {
return (!(value instanceof String) || checkStringValue((String) value));
}
});
attachListener(component);
// vaadin7 rewrite to converter
final Property p = new AbstractPropertyWrapper() {
public Class<?> getType() {
return Date.class;
}
};
// vaadin7 rewrite to converter
component.setPropertyDataSource(
new PropertyFormatter(p) {
@ -101,7 +99,7 @@ public class WebTimeField /*extends WebAbstractField<MaskedTextField> implements
return date;
} catch (Exception e) {
log.warn("Unable to parse value of component " + getId() + "\n" + e.getMessage());
component.setComponentError(new com.vaadin.data.Validator.InvalidValueException("Invalid value"));
component.setComponentError(new UserError("Invalid value"));
return null;
}
} else
@ -169,6 +167,7 @@ public class WebTimeField /*extends WebAbstractField<MaskedTextField> implements
super.setValue(value);
}
@Override
public boolean getShowSeconds() {
return showSeconds;
}
@ -193,6 +192,7 @@ public class WebTimeField /*extends WebAbstractField<MaskedTextField> implements
}
}
@Override
public void setShowSeconds(boolean showSeconds) {
this.showSeconds = showSeconds;
if (showSeconds) {
@ -241,7 +241,7 @@ public class WebTimeField /*extends WebAbstractField<MaskedTextField> implements
}
@Override
protected Object valueOf(Object newValue) throws ConversionException {
protected Object valueOf(Object newValue) throws Converter.ConversionException {
if (newValue instanceof String) {
if (StringUtils.isNotEmpty((String) newValue) && !newValue.equals(placeholder)) {
try {
@ -252,7 +252,7 @@ public class WebTimeField /*extends WebAbstractField<MaskedTextField> implements
return date;
} catch (Exception e) {
log.warn("Unable to parse value of component " + getId() + "\n" + e.getMessage());
component.setComponentError(new com.vaadin.data.Validator.InvalidValueException("Invalid value"));
component.setComponentError(new UserError("Invalid value"));
return null;
}
} else
@ -263,5 +263,5 @@ public class WebTimeField /*extends WebAbstractField<MaskedTextField> implements
};
}
};
}*/
}
}

View File

@ -6,14 +6,21 @@
package com.haulmont.cuba.web.toolkit.ui;
/**
* <p>$Id$</p>
*
* @author devyatkin
*/
public class DateFieldWrapper /*extends CustomField*/ {
import com.haulmont.cuba.web.gui.components.WebDateField;
import com.vaadin.data.Property;
import com.vaadin.data.util.converter.Converter;
import com.vaadin.ui.Layout;
import org.apache.commons.lang.ObjectUtils;
/*private WebDateField dateField;
import java.util.Date;
/**
* @author devyatkin
* @version $Id$
*/
public class DateFieldWrapper extends CustomField {
private WebDateField dateField;
public DateFieldWrapper(WebDateField dateField, Layout composition) {
this.dateField = dateField;
@ -34,7 +41,7 @@ public class DateFieldWrapper /*extends CustomField*/ {
}
@Override
public void setValue(Object newValue) throws ReadOnlyException, ConversionException {
public void setValue(Object newValue) throws ReadOnlyException, Converter.ConversionException {
if (getPropertyDataSource() != null)
getPropertyDataSource().setValue(newValue);
dateField.setValue(newValue);
@ -81,5 +88,18 @@ public class DateFieldWrapper /*extends CustomField*/ {
// support dateField in editable table
if (newDataSource != null && !ObjectUtils.equals(newDataSource.getValue(), getValue()))
dateField.setValue(newDataSource.getValue());
}*/
}
@Override
public void setBuffered(boolean buffered) {
}
@Override
public boolean isBuffered() {
return false;
}
@Override
public void removeAllValidators() {
}
}