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 2.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. package com.vaadin.tests;
  2. import java.util.ArrayList;
  3. import java.util.Collection;
  4. import java.util.List;
  5. import com.vaadin.ui.CustomComponent;
  6. import com.vaadin.ui.Label;
  7. import com.vaadin.ui.VerticalLayout;
  8. import com.vaadin.v7.data.Property.ValueChangeEvent;
  9. import com.vaadin.v7.data.Property.ValueChangeListener;
  10. import com.vaadin.v7.data.util.IndexedContainer;
  11. import com.vaadin.v7.ui.TwinColSelect;
  12. /**
  13. * TODO: Note you need to add Theme under WebContent/VAADIN/Themes/mytheme in
  14. * order to see actual visible results on the browser. Currently changes are
  15. * visible only by inspecting DOM.
  16. *
  17. * @author Vaadin Ltd.
  18. */
  19. public class TestForMultipleStyleNames extends CustomComponent
  20. implements ValueChangeListener {
  21. private final VerticalLayout main = new VerticalLayout();
  22. private Label l;
  23. private final TwinColSelect s = new TwinColSelect();
  24. private List<String> styleNames2;
  25. public TestForMultipleStyleNames() {
  26. setCompositionRoot(main);
  27. createNewView();
  28. }
  29. public void createNewView() {
  30. main.removeAllComponents();
  31. main.addComponent(
  32. new Label("TK5 supports multiple stylenames for components."));
  33. main.addComponent(new Label("Note you need to add Theme under"
  34. + " WebContent/VAADIN/Themes/mytheme"
  35. + " in order to see actual visible results"
  36. + " on the browser. Currently changes are"
  37. + " visible only by inspecting DOM."));
  38. styleNames2 = new ArrayList<>();
  39. styleNames2.add("red");
  40. styleNames2.add("bold");
  41. styleNames2.add("italic");
  42. s.setContainerDataSource(new IndexedContainer(styleNames2));
  43. s.addListener(this);
  44. s.setImmediate(true);
  45. main.addComponent(s);
  46. l = new Label("Test labele");
  47. main.addComponent(l);
  48. }
  49. @SuppressWarnings("unchecked")
  50. @Override
  51. public void valueChange(ValueChangeEvent event) {
  52. final String currentStyle = l.getStyleName();
  53. final List<String> curStyles = new ArrayList<>();
  54. for (String tmp : currentStyle.split(" ")) {
  55. if (tmp != "") {
  56. curStyles.add(tmp);
  57. }
  58. }
  59. final Collection<String> styles = (Collection<String>) s.getValue();
  60. for (final String styleName : styles) {
  61. if (curStyles.contains(styleName)) {
  62. // already added
  63. curStyles.remove(styleName);
  64. } else {
  65. l.addStyleName(styleName);
  66. }
  67. }
  68. for (final String object : curStyles) {
  69. l.removeStyleName(object);
  70. }
  71. }
  72. }