2121
2222import com .flowingcode .vaadin .addons .DemoLayout ;
2323import com .flowingcode .vaadin .addons .GithubLink ;
24- import com .vaadin .flow . component . checkbox . Checkbox ;
24+ import com .flowingcode . vaadin .addons . demo . TabbedDemo ;
2525import com .vaadin .flow .component .dependency .StyleSheet ;
26- import com .vaadin .flow .component .html .IFrame ;
27- import com .vaadin .flow .component .orderedlayout .HorizontalLayout ;
28- import com .vaadin .flow .component .orderedlayout .VerticalLayout ;
29- import com .vaadin .flow .component .splitlayout .SplitLayout ;
30- import com .vaadin .flow .component .splitlayout .SplitLayout .Orientation ;
31- import com .vaadin .flow .component .tabs .Tab ;
32- import com .vaadin .flow .component .tabs .Tabs ;
3326import com .vaadin .flow .router .Route ;
3427
3528@ SuppressWarnings ("serial" )
3629@ StyleSheet ("context://frontend/styles/demo-styles.css" )
3730@ Route (value = "chipfield" , layout = DemoLayout .class )
3831@ GithubLink ("https://github.com/FlowingCode/ChipFieldAddon" )
39- public class ChipfieldDemoView extends VerticalLayout {
32+ public class ChipfieldDemoView extends TabbedDemo {
4033
4134 private static final String DATAPROVIDER_DEMO = "Data Provider" ;
4235 private static final String RESTRICTED_DEMO = "Restricted" ;
@@ -52,104 +45,10 @@ public class ChipfieldDemoView extends VerticalLayout {
5245 "https://github.com/FlowingCode/ChipFieldAddon/blob/master/src/test/java/com/flowingcode/vaadin/addons/chipfield/BinderDemo.java" ;
5346
5447 public ChipfieldDemoView () {
55- SplitLayout layout = new SplitLayout ();
56- layout .setOrientation (Orientation .HORIZONTAL );
57- layout .addToPrimary (new DataProviderDemo ());
58- layout .setSizeFull ();
59- IFrame iframe = new IFrame ();
60- iframe .getElement ().setAttribute ("frameborder" , "0" );
61- iframe .setMinHeight ("0" );
62- iframe .setMinWidth ("0" );
63- iframe .getElement ().setAttribute ("srcdoc" , getSrcdoc (DATAPROVIDER_SOURCE ));
64- iframe .setSizeFull ();
65- layout .addToSecondary (iframe );
6648
67- Tabs tabs = new Tabs ();
68- Tab demo1 = new Tab (DATAPROVIDER_DEMO );
69- Tab demo2 = new Tab (RESTRICTED_DEMO );
70- Tab demo3 = new Tab (DISABLED_DEMO );
71- Tab demo4 = new Tab (BINDER_DEMO );
72- tabs .setWidthFull ();
73- tabs .add (demo1 , demo2 , demo3 , demo4 );
74-
75- Checkbox orientationCB = new Checkbox ("Toggle Orientation" );
76- orientationCB .setValue (true );
77- orientationCB .addClassName ("smallcheckbox" );
78- orientationCB .addValueChangeListener (
79- cb -> {
80- if (cb .getValue ()) {
81- layout .setOrientation (Orientation .HORIZONTAL );
82- } else {
83- layout .setOrientation (Orientation .VERTICAL );
84- }
85- layout
86- .getPrimaryComponent ()
87- .getElement ()
88- .setAttribute ("style" , "width: 100%; height: 100%" );
89- iframe .setSizeFull ();
90- });
91- Checkbox codeCB = new Checkbox ("Show Source Code" );
92- codeCB .setValue (true );
93- codeCB .addClassName ("smallcheckbox" );
94- codeCB .addValueChangeListener (
95- cb -> {
96- if (cb .getValue ()) {
97- layout .setSplitterPosition (50 );
98- orientationCB .setEnabled (true );
99- } else {
100- layout .setSplitterPosition (100 );
101- orientationCB .setEnabled (false );
102- }
103- });
104- HorizontalLayout footer = new HorizontalLayout ();
105- footer .setWidthFull ();
106- footer .setJustifyContentMode (JustifyContentMode .END );
107- footer .add (codeCB , orientationCB );
108- add (tabs , layout , footer );
109-
110- setSizeFull ();
111-
112- tabs .addSelectedChangeListener (
113- e -> {
114- removeAll ();
115- switch (e .getSelectedTab ().getLabel ()) {
116- case DATAPROVIDER_DEMO :
117- iframe .getElement ().setAttribute ("srcdoc" , getSrcdoc (DATAPROVIDER_SOURCE ));
118- layout .addToPrimary (new DataProviderDemo ());
119- layout .addToSecondary (iframe );
120- add (tabs , layout , footer );
121- break ;
122- case RESTRICTED_DEMO :
123- iframe .getElement ().setAttribute ("srcdoc" , getSrcdoc (RESTRICTED_SOURCE ));
124- layout .addToPrimary (new RestrictedDemo ());
125- layout .addToSecondary (iframe );
126- add (tabs , layout , footer );
127- break ;
128- case DISABLED_DEMO :
129- iframe .getElement ().setAttribute ("srcdoc" , getSrcdoc (DISABLED_SOURCE ));
130- layout .addToPrimary (new DisabledDemo ());
131- layout .addToSecondary (iframe );
132- add (tabs , layout , footer );
133- break ;
134- case BINDER_DEMO :
135- iframe .getElement ().setAttribute ("srcdoc" , getSrcdoc (BINDER_SOURCE ));
136- layout .addToPrimary (new BinderDemo ());
137- layout .addToSecondary (iframe );
138- add (tabs , layout , footer );
139- break ;
140- default :
141- iframe .getElement ().setAttribute ("srcdoc" , getSrcdoc (DATAPROVIDER_SOURCE ));
142- layout .addToPrimary (new DataProviderDemo ());
143- layout .addToSecondary (iframe );
144- add (tabs , layout , footer );
145- break ;
146- }
147- });
148- }
149-
150- private String getSrcdoc (String sourceUrl ) {
151- return "<html style=\" overflow-y:hidden; height:100%;\" ><body style=\" overflow-y: scroll; height:100%;\" ><script src=\" https://gist-it.appspot.com/"
152- + sourceUrl
153- + "\" ></script></body></html>" ;
49+ addDemo (new DataProviderDemo (), DATAPROVIDER_DEMO , DATAPROVIDER_SOURCE );
50+ addDemo (new RestrictedDemo (), RESTRICTED_DEMO , RESTRICTED_SOURCE );
51+ addDemo (new DisabledDemo (), DISABLED_DEMO , DISABLED_SOURCE );
52+ addDemo (new BinderDemo (), BINDER_DEMO , BINDER_SOURCE );
15453 }
15554}
0 commit comments