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.

TestForMultipleStyleNames.java 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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;
  17. import java.util.ArrayList;
  18. import java.util.Collection;
  19. import java.util.Iterator;
  20. import com.vaadin.data.Property.ValueChangeEvent;
  21. import com.vaadin.data.Property.ValueChangeListener;
  22. import com.vaadin.data.util.IndexedContainer;
  23. import com.vaadin.ui.CustomComponent;
  24. import com.vaadin.ui.Label;
  25. import com.vaadin.ui.TwinColSelect;
  26. import com.vaadin.ui.VerticalLayout;
  27. /**
  28. * TODO: Note you need to add Theme under WebContent/VAADIN/Themes/mytheme in
  29. * order to see actual visible results on the browser. Currently changes are
  30. * visible only by inspecting DOM.
  31. *
  32. * @author Vaadin Ltd.
  33. */
  34. public class TestForMultipleStyleNames extends CustomComponent implements
  35. ValueChangeListener {
  36. private final VerticalLayout main = new VerticalLayout();
  37. private Label l;
  38. private final TwinColSelect s = new TwinColSelect();
  39. private ArrayList<String> styleNames2;
  40. public TestForMultipleStyleNames() {
  41. setCompositionRoot(main);
  42. createNewView();
  43. }
  44. public void createNewView() {
  45. main.removeAllComponents();
  46. main.addComponent(new Label(
  47. "TK5 supports multiple stylenames for components."));
  48. main.addComponent(new Label("Note you need to add Theme under"
  49. + " WebContent/VAADIN/Themes/mytheme"
  50. + " in order to see actual visible results"
  51. + " on the browser. Currently changes are"
  52. + " visible only by inspecting DOM."));
  53. styleNames2 = new ArrayList<String>();
  54. styleNames2.add("red");
  55. styleNames2.add("bold");
  56. styleNames2.add("italic");
  57. s.setContainerDataSource(new IndexedContainer(styleNames2));
  58. s.addListener(this);
  59. s.setImmediate(true);
  60. main.addComponent(s);
  61. l = new Label("Test labele");
  62. main.addComponent(l);
  63. }
  64. @Override
  65. public void valueChange(ValueChangeEvent event) {
  66. final String currentStyle = l.getStyleName();
  67. final String[] tmp = currentStyle.split(" ");
  68. final ArrayList<String> curStyles = new ArrayList<String>();
  69. for (int i = 0; i < tmp.length; i++) {
  70. if (tmp[i] != "") {
  71. curStyles.add(tmp[i]);
  72. }
  73. }
  74. final Collection<?> styles = (Collection<?>) s.getValue();
  75. for (final Iterator<?> iterator = styles.iterator(); iterator.hasNext();) {
  76. final String styleName = (String) iterator.next();
  77. if (curStyles.contains(styleName)) {
  78. // already added
  79. curStyles.remove(styleName);
  80. } else {
  81. l.addStyleName(styleName);
  82. }
  83. }
  84. for (final Iterator<String> iterator2 = curStyles.iterator(); iterator2
  85. .hasNext();) {
  86. final String object = iterator2.next();
  87. l.removeStyleName(object);
  88. }
  89. }
  90. }