Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

DateFieldConnector.java 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * Copyright 2000-2014 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.client.tokka.connectors.fields;
  17. import com.google.gwt.event.dom.client.ChangeEvent;
  18. import com.google.gwt.event.dom.client.ChangeHandler;
  19. import com.google.gwt.user.client.ui.TextBox;
  20. import com.vaadin.client.communication.StateChangeEvent;
  21. import com.vaadin.client.ui.AbstractComponentConnector;
  22. import com.vaadin.shared.tokka.ui.components.fields.DateFieldServerRpc;
  23. import com.vaadin.shared.tokka.ui.components.fields.DateFieldState;
  24. import com.vaadin.shared.ui.Connect;
  25. import com.vaadin.shared.ui.Connect.LoadStyle;
  26. @Connect(value = com.vaadin.tokka.ui.components.fields.DateField.class, loadStyle = LoadStyle.EAGER)
  27. public class DateFieldConnector extends AbstractComponentConnector {
  28. @Override
  29. protected void init() {
  30. getWidget().addChangeHandler(new ChangeHandler() {
  31. @Override
  32. public void onChange(ChangeEvent event) {
  33. String value = getWidget().getValue();
  34. value = (value == null) ? "" : value.trim();
  35. // TODO validation
  36. getRpcProxy(DateFieldServerRpc.class).setDate(value);
  37. }
  38. });
  39. }
  40. @Override
  41. public DateFieldState getState() {
  42. return (DateFieldState) super.getState();
  43. }
  44. @Override
  45. public TextBox getWidget() {
  46. return (TextBox) super.getWidget();
  47. }
  48. @Override
  49. public void onStateChanged(StateChangeEvent stateChangeEvent) {
  50. // TODO Split into separate @OnStateChanged methods
  51. super.onStateChanged(stateChangeEvent);
  52. final TextBox w = getWidget();
  53. final DateFieldState state = getState();
  54. w.setReadOnly(state.readOnly);
  55. w.getElement().setAttribute("placeholder", "DD-MM-YYYY");
  56. w.getElement().setAttribute("maxlength", "10");
  57. w.setValue(state.date);
  58. }
  59. }