Example usage for com.google.gwt.i18n.client DateTimeFormat getPattern

List of usage examples for com.google.gwt.i18n.client DateTimeFormat getPattern

Introduction

In this page you can find the example usage for com.google.gwt.i18n.client DateTimeFormat getPattern.

Prototype

public String getPattern() 

Source Link

Document

Retrieve the pattern used in this DateTimeFormat object.

Usage

From source file:com.extjs.gxt.ui.client.widget.form.DateField.java

License:sencha.com license

@Override
protected boolean validateValue(String value) {
    if (!super.validateValue(value)) {
        return false;
    }/*from w  w  w  . j  a v a2 s.  com*/
    if (value.length() < 1) { // if it's blank and textfield didn't flag it then
        // it's valid
        return true;
    }

    DateTimeFormat format = getPropertyEditor().getFormat();

    Date date = null;

    try {
        date = getPropertyEditor().convertStringValue(value);
    } catch (Exception e) {

    }

    if (date == null) {
        String error = null;
        if (getMessages().getInvalidText() != null) {
            error = Format.substitute(getMessages().getInvalidText(), value, format.getPattern().toUpperCase());
        } else {
            error = GXT.MESSAGES.dateField_invalidText(value, format.getPattern().toUpperCase());
        }
        markInvalid(error);
        return false;
    }

    date = new DateWrapper(date).resetTime().asDate();

    if (minValue != null && date.before(minValue)) {
        String error = null;
        if (getMessages().getMinText() != null) {
            error = Format.substitute(getMessages().getMinText(), format.format(minValue));
        } else {
            error = GXT.MESSAGES.dateField_minText(format.format(minValue));
        }
        markInvalid(error);
        return false;
    }
    if (maxValue != null && date.after(maxValue)) {
        String error = null;
        if (getMessages().getMaxText() != null) {
            error = Format.substitute(getMessages().getMaxText(), format.format(maxValue));
        } else {
            error = GXT.MESSAGES.dateField_maxText(format.format(maxValue));
        }
        markInvalid(error);
        return false;
    }

    if (formatValue && getPropertyEditor().getFormat() != null) {
        setRawValue(getPropertyEditor().getStringValue(date));
    }

    return true;
}

From source file:com.spaceapplications.vaadin.addon.eventtimeline.gwt.client.VEventTimelineDisplay.java

@SuppressWarnings("deprecation")
private void plotHorizontalScale(long startTime, long endTime, long unitTime, float xUnit, boolean leftAlign) {

    if (unitTime <= 0 || xUnit <= 0) {
        return;/*from  w w  w .j  a va2s .  c  o m*/
    }

    float width = unitTime * xUnit;
    boolean shortDateFormat = width < 100;
    int year = widget.getStartDate().getYear();
    long time = (new Date(year, 0, 1)).getTime();

    DateTimeFormat formatter;
    if (unitTime < DAY) {
        formatter = shortDateFormat ? timeFormatShort : timeFormatLong;
    } else if (unitTime < MONTH) {
        formatter = shortDateFormat ? dayFormatShort : dayFormatLong;
    } else if (unitTime < YEAR) {
        formatter = shortDateFormat ? monthFormatShort : monthFormatLong;
    } else {
        formatter = shortDateFormat ? yearFormatShort : yearFormatLong;
    }

    if (gridColor != null) {
        canvas.setStrokeStyle(gridColor);
        canvas.setLineWidth(0.8);
        canvas.beginPath();
    }

    long stepsUntilInRange = (startTime - time) / unitTime;
    time += stepsUntilInRange * unitTime;

    while (time <= endTime) {
        if (time >= startTime - unitTime && time <= endTime + unitTime) {
            Label lbl = new Label();
            lbl.setStyleName(leftAlign ? CLASSNAME_SCALEDATE_LEFT : CLASSNAME_SCALEDATE);
            lbl.setWidth(width + "px");
            Date date = new Date(time);

            lbl.setText(widget.getDateTimeService().formatDate(date, formatter.getPattern()));

            long timeFromStart = time - startTime;
            float x = timeFromStart * xUnit;

            if (gridColor != null) {
                canvas.moveTo(x, 0);
                canvas.lineTo(x, canvas.getHeight());
            }

            displayComponentPanel.add(lbl, (int) x, displayComponentPanel.getOffsetHeight() - 15);
            horizontalScaleComponents.add(lbl);
        }

        if (unitTime == MONTH) {
            /*
             * Month resolution is not so easy since it changes depending on
             * the month. We use the Date to resolve the new time
             */
            time += DateTimeService.getNumberOfDaysInMonth(new Date(time)) * DAY;
        } else if (unitTime == YEAR) {
            /*
             * Take leap years into account
             */
            if (DateTimeService.isLeapYear(new Date(time))) {
                time += unitTime + DAY;
            } else {
                time += unitTime;
            }

        } else {
            time += unitTime;
        }
    }

    if (gridColor != null) {
        canvas.closePath();
        canvas.stroke();
    }
}

From source file:com.vaadin.addon.timeline.gwt.client.VTimelineDisplay.java

/**
 * Plots the horizontal scale/*  w  w w  . ja  v a  2 s .c o m*/
 * 
 * @param startTime
 *            The epoch time when the display area starts
 * @param endTime
 *            The epoch time when the display area ends
 * @param unitTime
 *            The time vs. pixel width ratio
 * @param xUnit
 *            The x-coordinate time vs. pixel unit ratio
 * @param leftAlign
 *            Should the label be left aligned
 */
@SuppressWarnings("deprecation")
private void plotHorizontalScale(long startTime, long endTime, long unitTime, float xUnit, boolean leftAlign) {

    if (unitTime <= 0 || xUnit <= 0) {
        return;
    }

    float width = unitTime * xUnit;
    boolean shortDateFormat = width < 100;
    int year = widget.getStartDate().getYear();
    long time = (new Date(year, 0, 1)).getTime();
    DateTimeFormat formatter = shortDateFormat ? widget.getDateFormats().getShortDateFormatter(unitTime)
            : widget.getDateFormats().getLongDateFormatter(unitTime);

    if (gridColor != null) {
        canvas.setStrokeStyle(gridColor);
        canvas.setLineWidth(0.5);
        canvas.beginPath();
    }

    long stepsUntilInRange = (startTime - time) / unitTime;
    time += stepsUntilInRange * unitTime;

    while (time <= endTime) {
        if (time >= startTime - unitTime && time <= endTime + unitTime) {
            Label lbl = new Label();
            lbl.setStyleName(leftAlign ? CLASSNAME_SCALEDATE_LEFT : CLASSNAME_SCALEDATE);
            lbl.setWidth(width + "px");
            Date date = new Date(time);

            lbl.setText(widget.getDateTimeService().formatDate(date, formatter.getPattern()));

            long timeFromStart = time - startTime;
            float x = timeFromStart * xUnit;

            if (gridColor != null) {
                canvas.moveTo(x, 0);
                canvas.lineTo(x, canvas.getHeight());
            }

            displayComponentPanel.add(lbl, (int) x, displayComponentPanel.getOffsetHeight() - 15);
            horizontalScaleComponents.add(lbl);
        }

        if (unitTime == VDateFormatInfo.MONTH) {
            /*
             * Month resolution is not so easy since it changes depending on
             * the month. We use the Date to resolve the new time
             */
            time += DateTimeService.getNumberOfDaysInMonth(new Date(time)) * VDateFormatInfo.DAY;
        } else if (unitTime == VDateFormatInfo.YEAR) {
            /*
             * Take leap years into account
             */
            if (DateTimeService.isLeapYear(new Date(time))) {
                time += unitTime + VDateFormatInfo.DAY;
            } else {
                time += unitTime;
            }

        } else {
            time += unitTime;
        }
    }

    if (gridColor != null) {
        canvas.closePath();
        canvas.stroke();
    }
}

From source file:org.drools.guvnor.client.common.DatePickerPopUp.java

License:Apache License

/**
 * Simple check, if time format has hours it has time.
 *
 * @param formatter//from w  w  w .  j  a  v a2  s. c o  m
 * @return
 */
private boolean hasTime(DateTimeFormat formatter) {
    return formatter.getPattern().contains("h") || formatter.getPattern().contains("H")
            || formatter.getPattern().contains("k") || formatter.getPattern().contains("K");
}

From source file:org.jahia.ajax.gwt.client.widget.form.CalendarField.java

License:Open Source License

@Override
protected boolean validateValue(String value) {
    if (!super.validateValue(value)) {
        return false;
    }//from w w  w  .  j a  va  2  s  .  c  om
    if (value.length() < 1) { // if it's blank and textfield didn't flag it then
        // it's valid
        return true;
    }

    DateTimeFormat format = getPropertyEditor().getFormat();

    Date date = null;

    try {
        date = getPropertyEditor().convertStringValue(value);
    } catch (Exception e) {

    }

    if (date == null) {
        String error = null;
        if (getMessages().getInvalidText() != null) {
            error = Format.substitute(getMessages().getInvalidText(), 0);
        } else {
            error = GXT.MESSAGES.dateField_invalidText(value, format.getPattern().toUpperCase());
        }
        markInvalid(error);
        return false;
    }

    if (minValue != null && date.before(minValue)) {
        String error = null;
        if (getMessages().getMinText() != null) {
            error = Format.substitute(getMessages().getMinText(), format.format(minValue));
        } else {
            error = GXT.MESSAGES.dateField_minText(format.format(minValue));
        }
        markInvalid(error);
        return false;
    }
    if (maxValue != null && date.after(maxValue)) {
        String error = null;
        if (getMessages().getMaxText() != null) {
            error = Format.substitute(getMessages().getMaxText(), format.format(maxValue));
        } else {
            error = GXT.MESSAGES.dateField_maxText(format.format(maxValue));
        }
        markInvalid(error);
        return false;
    }

    if (formatValue && getPropertyEditor().getFormat() != null) {
        setRawValue(getPropertyEditor().getFormat().format(date));
    }

    return true;
}

From source file:org.jbpm.console.ng.gc.client.util.UTCDateBoxImplHtml4.java

License:Apache License

@Override
public void setDateFormat(final DateTimeFormat dateFormat) {
    datebox.setFormat(dateFormat.getPattern());
    Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {
        @Override//from  w  w w .ja va2 s .co  m
        public void execute() {
            datebox.reload();
        }
    });
}

From source file:org.jbpm.workbench.common.client.util.UTCDateBoxImplHtml4.java

License:Apache License

@Override
public void setDateFormat(final DateTimeFormat dateFormat) {
    datebox.setFormat(DatePickerFormatUtilities.convertToBS3DateFormat(dateFormat.getPattern()));
    Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {
        @Override//from   ww w. j a  v a 2s  . c  om
        public void execute() {
            datebox.reload();
        }
    });
}