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.

RowAwareRendererConnector.java 2.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * Copyright 2000-2014 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.tests.widgetset.client.grid;
  17. import java.util.Arrays;
  18. import java.util.Collection;
  19. import com.google.gwt.dom.client.BrowserEvents;
  20. import com.google.gwt.dom.client.DivElement;
  21. import com.google.gwt.dom.client.NativeEvent;
  22. import com.google.gwt.user.client.DOM;
  23. import com.vaadin.client.connectors.AbstractRendererConnector;
  24. import com.vaadin.client.ui.grid.Cell;
  25. import com.vaadin.client.ui.grid.FlyweightCell;
  26. import com.vaadin.client.ui.grid.Renderer;
  27. import com.vaadin.client.ui.grid.renderers.ComplexRenderer;
  28. import com.vaadin.shared.communication.ServerRpc;
  29. import com.vaadin.shared.ui.Connect;
  30. @Connect(com.vaadin.tests.components.grid.RowAwareRenderer.class)
  31. public class RowAwareRendererConnector extends AbstractRendererConnector<Void> {
  32. public interface RowAwareRendererRpc extends ServerRpc {
  33. void clicky(String key);
  34. }
  35. public class RowAwareRenderer extends ComplexRenderer<Void> {
  36. @Override
  37. public Collection<String> getConsumedEvents() {
  38. return Arrays.asList(BrowserEvents.CLICK);
  39. }
  40. @Override
  41. public void init(FlyweightCell cell) {
  42. DivElement div = DivElement.as(DOM.createDiv());
  43. div.setAttribute("style",
  44. "border: 1px solid red; background: pink;");
  45. div.setInnerText("Click me!");
  46. cell.getElement().appendChild(div);
  47. }
  48. @Override
  49. public void render(FlyweightCell cell, Void data) {
  50. // NOOP
  51. }
  52. @Override
  53. public boolean onBrowserEvent(Cell cell, NativeEvent event) {
  54. int row = cell.getRow();
  55. String key = getRowKey(row);
  56. getRpcProxy(RowAwareRendererRpc.class).clicky(key);
  57. cell.getElement().setInnerText("row: " + row + ", key: " + key);
  58. return true;
  59. }
  60. }
  61. @Override
  62. protected Renderer<Void> createRenderer() {
  63. // cannot use the default createRenderer as RowAwareRenderer needs a
  64. // reference to its connector - it has no "real" no-argument constructor
  65. return new RowAwareRenderer();
  66. }
  67. }