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.

IColorPicker.java 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. @ITMillApache2LicenseForJavaFiles@
  3. */
  4. package com.itmill.toolkit.demo.colorpicker.gwt.client.ui;
  5. import com.itmill.toolkit.terminal.gwt.client.ApplicationConnection;
  6. import com.itmill.toolkit.terminal.gwt.client.Paintable;
  7. import com.itmill.toolkit.terminal.gwt.client.UIDL;
  8. public class IColorPicker extends GwtColorPicker implements Paintable {
  9. /** Set the CSS class name to allow styling. */
  10. public static final String CLASSNAME = "example-colorpicker";
  11. /** Component identifier in UIDL communications. */
  12. String uidlId;
  13. /** Reference to the server connection object. */
  14. ApplicationConnection client;
  15. /**
  16. * The constructor should first call super() to initialize the component and
  17. * then handle any initialization relevant to IT Mill Toolkit.
  18. */
  19. public IColorPicker() {
  20. // The superclass has a lot of relevant initialization
  21. super();
  22. // This method call of the Paintable interface sets the component
  23. // style name in DOM tree
  24. setStyleName(CLASSNAME);
  25. }
  26. /**
  27. * This method must be implemented to update the client-side component from
  28. * UIDL data received from server.
  29. *
  30. * This method is called when the page is loaded for the first time, and
  31. * every time UI changes in the component are received from the server.
  32. */
  33. public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
  34. // This call should be made first. Ensure correct implementation,
  35. // and let the containing layout manage caption, etc.
  36. if (client.updateComponent(this, uidl, true)) {
  37. return;
  38. }
  39. // Save reference to server connection object to be able to send
  40. // user interaction later
  41. this.client = client;
  42. // Save the UIDL identifier for the component
  43. uidlId = uidl.getId();
  44. // Get value received from server and actualize it in the GWT component
  45. setColor(uidl.getStringVariable("colorname"));
  46. }
  47. /** Override the method to communicate the new value to server. */
  48. public void setColor(String newcolor) {
  49. // Ignore if no change
  50. if (newcolor.equals(currentcolor.getText())) {
  51. return;
  52. }
  53. // Let the original implementation to do whatever it needs to do
  54. super.setColor(newcolor);
  55. // Updating the state to the server can not be done before
  56. // the server connection is known, i.e., before updateFromUIDL()
  57. // has been called.
  58. if (uidlId == null || client == null) {
  59. return;
  60. }
  61. // Communicate the user interaction parameters to server. This call will
  62. // initiate an AJAX request to the server.
  63. client.updateVariable(uidlId, "colorname", newcolor, true);
  64. }
  65. }