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.

CustomWidgetMapGenerator.java 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * Copyright 2011 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.terminal.gwt.widgetsetutils;
  17. import java.util.Collection;
  18. import java.util.HashSet;
  19. import com.vaadin.shared.ui.Connect;
  20. import com.vaadin.shared.ui.Connect.LoadStyle;
  21. import com.vaadin.terminal.gwt.client.ComponentConnector;
  22. import com.vaadin.terminal.gwt.client.ServerConnector;
  23. /**
  24. * An abstract helper class that can be used to easily build a widgetset with
  25. * customized load styles for each components. In three abstract methods one can
  26. * override the default values given in {@link Connect} annotations.
  27. *
  28. * @see WidgetMapGenerator
  29. *
  30. */
  31. public abstract class CustomWidgetMapGenerator extends WidgetMapGenerator {
  32. private Collection<Class<? extends ComponentConnector>> eagerPaintables = new HashSet<Class<? extends ComponentConnector>>();
  33. private Collection<Class<? extends ComponentConnector>> lazyPaintables = new HashSet<Class<? extends ComponentConnector>>();
  34. private Collection<Class<? extends ComponentConnector>> deferredPaintables = new HashSet<Class<? extends ComponentConnector>>();
  35. @Override
  36. protected LoadStyle getLoadStyle(Class<? extends ServerConnector> connector) {
  37. if (eagerPaintables == null) {
  38. init();
  39. }
  40. if (eagerPaintables.contains(connector)) {
  41. return LoadStyle.EAGER;
  42. }
  43. if (lazyPaintables.contains(connector)) {
  44. return LoadStyle.LAZY;
  45. }
  46. if (deferredPaintables.contains(connector)) {
  47. return LoadStyle.DEFERRED;
  48. }
  49. return super.getLoadStyle(connector);
  50. }
  51. private void init() {
  52. Class<? extends ComponentConnector>[] eagerComponents = getEagerComponents();
  53. if (eagerComponents != null) {
  54. for (Class<? extends ComponentConnector> class1 : eagerComponents) {
  55. eagerPaintables.add(class1);
  56. }
  57. }
  58. Class<? extends ComponentConnector>[] lazyComponents = getEagerComponents();
  59. if (lazyComponents != null) {
  60. for (Class<? extends ComponentConnector> class1 : lazyComponents) {
  61. lazyPaintables.add(class1);
  62. }
  63. }
  64. Class<? extends ComponentConnector>[] deferredComponents = getEagerComponents();
  65. if (deferredComponents != null) {
  66. for (Class<? extends ComponentConnector> class1 : deferredComponents) {
  67. deferredPaintables.add(class1);
  68. }
  69. }
  70. }
  71. /**
  72. * @return an array of components whose load style should be overridden to
  73. * {@link LoadStyle#EAGER}
  74. */
  75. protected abstract Class<? extends ComponentConnector>[] getEagerComponents();
  76. /**
  77. * @return an array of components whose load style should be overridden to
  78. * {@link LoadStyle#LAZY}
  79. */
  80. protected abstract Class<? extends ComponentConnector>[] getLazyComponents();
  81. /**
  82. * @return an array of components whose load style should be overridden to
  83. * {@link LoadStyle#DEFERRED}
  84. */
  85. protected abstract Class<? extends ComponentConnector>[] getDeferredComponents();
  86. }