FileDocCategorySizeDatePackage
DateTimeFormatExampleController.javaAPI DocExample3510Mon Aug 27 20:11:56 BST 2007com.google.gwt.sample.i18n.client

DateTimeFormatExampleController

public class DateTimeFormatExampleController extends AbstractFormatExampleController
Demonstrates how to use {@link DateTimeFormat}.

Fields Summary
private static final String
DEFAULT_INPUT
private com.google.gwt.i18n.client.DateTimeFormat
activeFormat
private final DateTimeFormatExampleConstants
constants
Constructors Summary
public DateTimeFormatExampleController(DateTimeFormatExampleConstants constants)


   

     
    super(DEFAULT_INPUT, constants.dateTimeFormatPatterns());
    this.constants = constants;
  
Methods Summary
protected java.lang.StringdoGetPattern(java.lang.String patternKey)

    // Date + Time
    if ("fullDateTime".equals(patternKey)) {
      return DateTimeFormat.getFullDateTimeFormat().getPattern();
    }

    if ("longDateTime".equals(patternKey)) {
      return DateTimeFormat.getLongDateTimeFormat().getPattern();
    }

    if ("mediumDateTime".equals(patternKey)) {
      return DateTimeFormat.getMediumDateTimeFormat().getPattern();
    }
    
    if ("shortDateTime".equals(patternKey)) {
      return DateTimeFormat.getShortDateTimeFormat().getPattern();
    }

    // Date only
    if ("fullDate".equals(patternKey)) {
      return DateTimeFormat.getFullDateFormat().getPattern();
    }

    if ("longDate".equals(patternKey)) {
      return DateTimeFormat.getLongDateFormat().getPattern();
    }

    if ("mediumDate".equals(patternKey)) {
      return DateTimeFormat.getMediumDateFormat().getPattern();
    }
    
    if ("shortDate".equals(patternKey)) {
      return DateTimeFormat.getShortDateFormat().getPattern();
    }

    // Time only
    if ("fullTime".equals(patternKey)) {
      return DateTimeFormat.getFullTimeFormat().getPattern();
    }

    if ("longTime".equals(patternKey)) {
      return DateTimeFormat.getLongTimeFormat().getPattern();
    }

    if ("mediumTime".equals(patternKey)) {
      return DateTimeFormat.getMediumTimeFormat().getPattern();
    }
    
    if ("shortTime".equals(patternKey)) {
      return DateTimeFormat.getShortTimeFormat().getPattern();
    }
    
    throw new IllegalArgumentException("Unknown pattern key '" + patternKey
        + "'");
  
protected voiddoParseAndRememberPattern(java.lang.String pattern)

    activeFormat = DateTimeFormat.getFormat(pattern);
  
protected voiddoParseInput(java.lang.String toParse, com.google.gwt.user.client.ui.HasText output, com.google.gwt.user.client.ui.HasText error)

    error.setText("");
    if (!"".equals(toParse)) {
      try {
        Date x = new Date(toParse);
        String s = activeFormat.format(x);
        output.setText(s);
      } catch (IllegalArgumentException e) {
        String errMsg = constants.failedToParseInput();
        error.setText(errMsg);
      }
    } else {
      output.setText("<None>");
    }
  
public DateTimeFormatExampleConstantsgetConstants()

    return constants;