2 * Copyright 2000-2021 Vaadin Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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
16 package com.vaadin.v7.client.ui.colorpicker;
18 import com.google.gwt.core.client.GWT;
19 import com.google.gwt.event.dom.client.ClickEvent;
20 import com.google.gwt.event.dom.client.ClickHandler;
21 import com.google.gwt.user.client.ui.Widget;
22 import com.vaadin.client.communication.RpcProxy;
23 import com.vaadin.client.communication.StateChangeEvent;
24 import com.vaadin.client.ui.colorpicker.VColorPickerGrid;
25 import com.vaadin.shared.ui.Connect;
26 import com.vaadin.shared.ui.Connect.LoadStyle;
27 import com.vaadin.v7.client.ui.AbstractLegacyComponentConnector;
28 import com.vaadin.v7.shared.ui.colorpicker.ColorPickerGridServerRpc;
29 import com.vaadin.v7.shared.ui.colorpicker.ColorPickerGridState;
30 import com.vaadin.v7.ui.components.colorpicker.ColorPickerGrid;
33 * A class that defines the default implementation for a color picker grid
34 * connector. Connects the server side {@link ColorPickerGrid} with the client
35 * side counterpart {@link VColorPickerGrid}
39 @Connect(value = ColorPickerGrid.class, loadStyle = LoadStyle.LAZY)
40 public class ColorPickerGridConnector extends AbstractLegacyComponentConnector
41 implements ClickHandler {
43 private ColorPickerGridServerRpc rpc = RpcProxy
44 .create(ColorPickerGridServerRpc.class, this);
47 protected Widget createWidget() {
48 return GWT.create(VColorPickerGrid.class);
52 public VColorPickerGrid getWidget() {
53 return (VColorPickerGrid) super.getWidget();
57 public ColorPickerGridState getState() {
58 return (ColorPickerGridState) super.getState();
62 public void onClick(ClickEvent event) {
63 rpc.select(getWidget().getSelectedX(), getWidget().getSelectedY());
67 public void onStateChanged(StateChangeEvent stateChangeEvent) {
68 super.onStateChanged(stateChangeEvent);
69 if (stateChangeEvent.hasPropertyChanged("rowCount")
70 || stateChangeEvent.hasPropertyChanged("columnCount")
71 || stateChangeEvent.hasPropertyChanged("updateGrid")) {
73 getWidget().updateGrid(getState().rowCount, getState().columnCount);
75 if (stateChangeEvent.hasPropertyChanged("changedX")
76 || stateChangeEvent.hasPropertyChanged("changedY")
77 || stateChangeEvent.hasPropertyChanged("changedColor")
78 || stateChangeEvent.hasPropertyChanged("updateColor")) {
80 getWidget().updateColor(getState().changedColor,
81 getState().changedX, getState().changedY);
83 if (!getWidget().isGridLoaded()) {
90 protected void init() {
92 getWidget().addClickHandler(this);