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.

ColorPickerGridConnector.java 3.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * Copyright 2000-2016 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.client.ui.colorpicker;
  17. import com.google.gwt.core.client.GWT;
  18. import com.google.gwt.event.dom.client.ClickEvent;
  19. import com.google.gwt.event.dom.client.ClickHandler;
  20. import com.google.gwt.user.client.ui.Widget;
  21. import com.vaadin.client.communication.RpcProxy;
  22. import com.vaadin.client.communication.StateChangeEvent;
  23. import com.vaadin.client.ui.AbstractComponentConnector;
  24. import com.vaadin.shared.ui.Connect;
  25. import com.vaadin.shared.ui.Connect.LoadStyle;
  26. import com.vaadin.shared.ui.colorpicker.ColorPickerGridServerRpc;
  27. import com.vaadin.shared.ui.colorpicker.ColorPickerGridState;
  28. import com.vaadin.ui.components.colorpicker.ColorPickerGrid;
  29. /**
  30. * A class that defines the default implementation for a color picker grid
  31. * connector. Connects the server side
  32. * {@link com.vaadin.ui.components.colorpicker.ColorPickerGrid} with the client
  33. * side counterpart {@link VColorPickerGrid}
  34. *
  35. * @since 7.0.0
  36. */
  37. @Connect(value = ColorPickerGrid.class, loadStyle = LoadStyle.LAZY)
  38. public class ColorPickerGridConnector extends AbstractComponentConnector
  39. implements ClickHandler {
  40. private ColorPickerGridServerRpc rpc = RpcProxy
  41. .create(ColorPickerGridServerRpc.class, this);
  42. @Override
  43. protected Widget createWidget() {
  44. return GWT.create(VColorPickerGrid.class);
  45. }
  46. @Override
  47. public VColorPickerGrid getWidget() {
  48. return (VColorPickerGrid) super.getWidget();
  49. }
  50. @Override
  51. public ColorPickerGridState getState() {
  52. return (ColorPickerGridState) super.getState();
  53. }
  54. @Override
  55. public void onClick(ClickEvent event) {
  56. rpc.select(getWidget().getSelectedX(), getWidget().getSelectedY());
  57. }
  58. @Override
  59. public void onStateChanged(StateChangeEvent stateChangeEvent) {
  60. super.onStateChanged(stateChangeEvent);
  61. if (stateChangeEvent.hasPropertyChanged("rowCount")
  62. || stateChangeEvent.hasPropertyChanged("columnCount")
  63. || stateChangeEvent.hasPropertyChanged("updateGrid")) {
  64. getWidget().updateGrid(getState().rowCount, getState().columnCount);
  65. }
  66. if (stateChangeEvent.hasPropertyChanged("changedX")
  67. || stateChangeEvent.hasPropertyChanged("changedY")
  68. || stateChangeEvent.hasPropertyChanged("changedColor")
  69. || stateChangeEvent.hasPropertyChanged("updateColor")) {
  70. getWidget().updateColor(getState().changedColor,
  71. getState().changedX, getState().changedY);
  72. if (!getWidget().isGridLoaded()) {
  73. rpc.refresh();
  74. }
  75. }
  76. }
  77. @Override
  78. protected void init() {
  79. super.init();
  80. getWidget().addClickHandler(this);
  81. }
  82. }