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.

ItkColorPicker.java 2.4KB

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