1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- package com.itmill.toolkit.demo.colorpicker.gwt.client.ui;
-
- import com.itmill.toolkit.terminal.gwt.client.ApplicationConnection;
- import com.itmill.toolkit.terminal.gwt.client.Paintable;
- import com.itmill.toolkit.terminal.gwt.client.UIDL;
-
- public class ItkColorPicker extends GwtColorPicker implements Paintable {
-
- /** Set the CSS class name to allow styling. */
- public static final String CLASSNAME = "example-colorpicker";
-
- /** Component identifier in UIDL communications. */
- String uidl_id;
-
- /** Reference to the server connection object. */
- ApplicationConnection client;
-
- /**
- * The constructor should first call super() to initialize the component and
- * then handle any initialization relevant to IT Mill Toolkit.
- */
- public ItkColorPicker() {
- // The superclass has a lot of relevant initialization
- super();
-
- // This method call of the Paintable interface sets the component
- // style name in DOM tree
- setStyleName(CLASSNAME);
- }
-
- /**
- * This method must be implemented to update the client-side component from
- * UIDL data received from server.
- *
- * This method is called when the page is loaded for the first time, and
- * every time UI changes in the component are received from the server.
- */
- public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
- // This call should be made first. Ensure correct implementation,
- // but don't let container manage caption etc.
- if (client.updateComponent(this, uidl, false))
- return;
-
- // Save reference to server connection object to be able to send
- // user interaction later
- this.client = client;
-
- // Save the UIDL identifier for the component
- uidl_id = uidl.getId();
-
- // Get value received from server and actualize it in the GWT component
- setColor(uidl.getStringVariable("colorname"));
- }
-
- /** Override the method to communicate the new value to server. */
- public void setColor(String newcolor) {
- // Ignore if no change
- if (newcolor.equals(currentcolor.getText()))
- return;
-
- // Let the original implementation to do whatever it needs to do
- super.setColor(newcolor);
-
- // Updating the state to the server can not be done before
- // the server connection is known, i.e., before updateFromUIDL()
- // has been called.
- if (uidl_id == null || client == null)
- return;
-
- // Communicate the user interaction parameters to server. This call will
- // initiate an AJAX request to the server.
- client.updateVariable(uidl_id, "colorname", newcolor, true);
- }
- }
|