You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

MyPickerWidget.java 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package com.vaadin.tests.minitutorials.v7a2;
  2. import com.google.gwt.dom.client.Document;
  3. import com.google.gwt.dom.client.Style.Unit;
  4. import com.google.gwt.user.client.Window;
  5. import com.google.gwt.user.client.ui.ComplexPanel;
  6. import com.google.gwt.user.client.ui.PushButton;
  7. import com.google.gwt.user.client.ui.TextBox;
  8. public class MyPickerWidget extends ComplexPanel {
  9. public static final String CLASSNAME = "mypicker";
  10. private final TextBox textBox = new TextBox();
  11. private final PushButton button = new PushButton("...");
  12. public MyPickerWidget() {
  13. setElement(Document.get().createDivElement());
  14. setStylePrimaryName(CLASSNAME);
  15. textBox.setStylePrimaryName(CLASSNAME + "-field");
  16. button.setStylePrimaryName(CLASSNAME + "-button");
  17. add(textBox, getElement());
  18. add(button, getElement());
  19. button.addClickHandler(
  20. event -> Window.alert("Calendar picker not yet supported!"));
  21. }
  22. public void setButtonText(String buttonText, boolean adjustSpace) {
  23. if (buttonText == null || buttonText.isEmpty()) {
  24. buttonText = "...";
  25. }
  26. button.setText(buttonText);
  27. if (adjustSpace) {
  28. adjustButtonSpace(button.getOffsetWidth());
  29. }
  30. }
  31. public void adjustButtonSpace(int width) {
  32. getElement().getStyle().setPaddingRight(width, Unit.PX);
  33. button.getElement().getStyle().setMarginRight(-width, Unit.PX);
  34. }
  35. }