123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- /*
- @ITMillApache2LicenseForJavaFiles@
- */
-
- 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 IColorPicker 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 uidlId;
-
- /** 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 IColorPicker() {
- // 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,
- // and let the containing layout manage caption, etc.
- if (client.updateComponent(this, uidl, true)) {
- 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
- uidlId = 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 (uidlId == null || client == null) {
- return;
- }
-
- // Communicate the user interaction parameters to server. This call will
- // initiate an AJAX request to the server.
- client.updateVariable(uidlId, "colorname", newcolor, true);
- }
- }
|