Skip to content

Commit 9415cc9

Browse files
committed
Package refactoring
1 parent 18c601e commit 9415cc9

File tree

5 files changed

+107
-115
lines changed

5 files changed

+107
-115
lines changed

src/main/java/com/flowingcode/vaadin/addons/demo/impl/SourceCodeView.java renamed to src/main/java/com/flowingcode/vaadin/addons/demo/SourceCodeView.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* limitations under the License.
1818
* #L%
1919
*/
20-
package com.flowingcode.vaadin.addons.demo.impl;
20+
package com.flowingcode.vaadin.addons.demo;
2121

2222
import com.vaadin.flow.component.Composite;
2323
import com.vaadin.flow.component.html.IFrame;

src/main/java/com/flowingcode/vaadin/addons/demo/impl/SplitLayoutDemo.java renamed to src/main/java/com/flowingcode/vaadin/addons/demo/SplitLayoutDemo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* limitations under the License.
1818
* #L%
1919
*/
20-
package com.flowingcode.vaadin.addons.demo.impl;
20+
package com.flowingcode.vaadin.addons.demo;
2121

2222
import com.vaadin.flow.component.Component;
2323
import com.vaadin.flow.component.Composite;

src/main/java/com/flowingcode/vaadin/addons/demo/TabbedDemo.java

Lines changed: 100 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,108 @@
1919
*/
2020
package com.flowingcode.vaadin.addons.demo;
2121

22+
import java.util.HashMap;
23+
import java.util.Map;
24+
2225
import com.vaadin.flow.component.Component;
26+
import com.vaadin.flow.component.checkbox.Checkbox;
27+
import com.vaadin.flow.component.dependency.StyleSheet;
28+
import com.vaadin.flow.component.orderedlayout.HorizontalLayout;
29+
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
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;
2333

24-
public interface TabbedDemo {
25-
/*
26-
* Demo with source code layout
27-
*/
28-
void addDemo(Component demo, String name, String sourceCodeUrl);
34+
@StyleSheet("context://frontend/styles/commons-demo/shared-styles.css")
35+
@SuppressWarnings("serial")
36+
public class TabbedDemo extends VerticalLayout {
37+
38+
private Tabs tabs;
39+
private HorizontalLayout footer;
40+
private SplitLayoutDemo<Component> currentLayout;
41+
private Map<Tab, Component> demos;
42+
private Checkbox orientationCB;
43+
private Checkbox codeCB;
44+
45+
@SuppressWarnings("unchecked")
46+
public TabbedDemo() {
47+
tabs = new Tabs();
48+
demos = new HashMap<>();
49+
tabs.setWidthFull();
50+
// Footer
51+
orientationCB = new Checkbox("Toggle Orientation");
52+
orientationCB.setValue(true);
53+
orientationCB.addClassName("smallcheckbox");
54+
orientationCB.addValueChangeListener(cb -> {
55+
updateSplitterOrientation();
56+
});
57+
codeCB = new Checkbox("Show Source Code");
58+
codeCB.setValue(true);
59+
codeCB.addClassName("smallcheckbox");
60+
codeCB.addValueChangeListener(cb -> {
61+
updateSplitterPosition();
62+
});
63+
footer = new HorizontalLayout();
64+
footer.setWidthFull();
65+
footer.setJustifyContentMode(JustifyContentMode.END);
66+
footer.add(codeCB, orientationCB);
67+
68+
tabs.addSelectedChangeListener(e -> {
69+
removeAll();
70+
// If current demo is instance of SplitLayoutDemo, add footer.
71+
Component currentDemo = demos.get(tabs.getSelectedTab());
72+
if (currentDemo instanceof SplitLayoutDemo) {
73+
currentLayout = (SplitLayoutDemo<Component>) currentDemo;
74+
this.add(tabs, currentLayout, footer);
75+
}
76+
else {
77+
this.add(tabs, currentDemo);
78+
}
79+
updateSplitterPosition();
80+
updateSplitterOrientation();
81+
});
2982

30-
/*
31-
* Demo without source code
83+
setSizeFull();
84+
}
85+
86+
/**
87+
*
88+
* @param demo the demo instance
89+
* @param name the demo name (tab label)
90+
* @param sourceCodeUrl the url of the demo, <b>null</b> to not show source code
91+
* section.
3292
*/
33-
void addDemo(Component demo, String name);
93+
public void addDemo(Component demo, String label, String sourceCodeUrl) {
94+
Tab tab = new Tab(label);
95+
if (sourceCodeUrl != null) {
96+
demos.put(tab, new SplitLayoutDemo<>(demo, sourceCodeUrl));
97+
} else {
98+
demos.put(tab, demo);
99+
}
100+
tabs.add(tab);
101+
}
102+
103+
public void addDemo(Component demo, String label) {
104+
addDemo(demo, label, null);
105+
}
106+
107+
private void updateSplitterPosition() {
108+
boolean b = codeCB.getValue();
109+
if (b) {
110+
currentLayout.setSplitterPosition(50);
111+
orientationCB.setEnabled(true);
112+
} else {
113+
currentLayout.setSplitterPosition(100);
114+
orientationCB.setEnabled(false);
115+
}
116+
}
117+
118+
private void updateSplitterOrientation() {
119+
boolean b = orientationCB.getValue();
120+
if (b) {
121+
currentLayout.setOrientation(Orientation.HORIZONTAL);
122+
} else {
123+
currentLayout.setOrientation(Orientation.VERTICAL);
124+
}
125+
}
34126
}

src/main/java/com/flowingcode/vaadin/addons/demo/impl/TabbedDemoImpl.java

Lines changed: 2 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -19,111 +19,10 @@
1919
*/
2020
package com.flowingcode.vaadin.addons.demo.impl;
2121

22-
import java.util.HashMap;
23-
import java.util.Map;
24-
2522
import com.flowingcode.vaadin.addons.demo.TabbedDemo;
26-
import com.vaadin.flow.component.Component;
27-
import com.vaadin.flow.component.checkbox.Checkbox;
28-
import com.vaadin.flow.component.dependency.StyleSheet;
29-
import com.vaadin.flow.component.orderedlayout.HorizontalLayout;
30-
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
31-
import com.vaadin.flow.component.splitlayout.SplitLayout.Orientation;
32-
import com.vaadin.flow.component.tabs.Tab;
33-
import com.vaadin.flow.component.tabs.Tabs;
3423

35-
@StyleSheet("context://frontend/styles/commons-demo/shared-styles.css")
3624
@SuppressWarnings("serial")
37-
public class TabbedDemoImpl extends VerticalLayout implements TabbedDemo {
38-
39-
private Tabs tabs;
40-
private HorizontalLayout footer;
41-
private SplitLayoutDemo<Component> currentLayout;
42-
private Map<Tab, Component> demos;
43-
private Checkbox orientationCB;
44-
private Checkbox codeCB;
45-
46-
@SuppressWarnings("unchecked")
47-
public TabbedDemoImpl() {
48-
tabs = new Tabs();
49-
demos = new HashMap<>();
50-
tabs.setWidthFull();
51-
// Footer
52-
orientationCB = new Checkbox("Toggle Orientation");
53-
orientationCB.setValue(true);
54-
orientationCB.addClassName("smallcheckbox");
55-
orientationCB.addValueChangeListener(cb -> {
56-
updateSplitterOrientation();
57-
});
58-
codeCB = new Checkbox("Show Source Code");
59-
codeCB.setValue(true);
60-
codeCB.addClassName("smallcheckbox");
61-
codeCB.addValueChangeListener(cb -> {
62-
updateSplitterPosition();
63-
});
64-
footer = new HorizontalLayout();
65-
footer.setWidthFull();
66-
footer.setJustifyContentMode(JustifyContentMode.END);
67-
footer.add(codeCB, orientationCB);
68-
69-
tabs.addSelectedChangeListener(e -> {
70-
removeAll();
71-
// If current demo is instance of SplitLayoutDemo, add footer.
72-
Component currentDemo = demos.get(tabs.getSelectedTab());
73-
if (currentDemo instanceof SplitLayoutDemo) {
74-
currentLayout = (SplitLayoutDemo<Component>) currentDemo;
75-
this.add(tabs, currentLayout, footer);
76-
}
77-
else {
78-
this.add(tabs, currentDemo);
79-
}
80-
updateSplitterPosition();
81-
updateSplitterOrientation();
82-
});
83-
84-
setSizeFull();
85-
}
86-
87-
/**
88-
*
89-
* @param demo the demo instance
90-
* @param name the demo name (tab label)
91-
* @param sourceCodeUrl the url of the demo, <b>null</b> to not show source code
92-
* section.
93-
*/
94-
@Override
95-
public void addDemo(Component demo, String label, String sourceCodeUrl) {
96-
Tab tab = new Tab(label);
97-
if (sourceCodeUrl != null) {
98-
demos.put(tab, new SplitLayoutDemo<>(demo, sourceCodeUrl));
99-
} else {
100-
demos.put(tab, demo);
101-
}
102-
tabs.add(tab);
103-
}
104-
105-
@Override
106-
public void addDemo(Component demo, String label) {
107-
addDemo(demo, label, null);
108-
}
109-
110-
private void updateSplitterPosition() {
111-
boolean b = codeCB.getValue();
112-
if (b) {
113-
currentLayout.setSplitterPosition(50);
114-
orientationCB.setEnabled(true);
115-
} else {
116-
currentLayout.setSplitterPosition(100);
117-
orientationCB.setEnabled(false);
118-
}
119-
}
25+
@Deprecated
26+
public class TabbedDemoImpl extends TabbedDemo {
12027

121-
private void updateSplitterOrientation() {
122-
boolean b = orientationCB.getValue();
123-
if (b) {
124-
currentLayout.setOrientation(Orientation.HORIZONTAL);
125-
} else {
126-
currentLayout.setOrientation(Orientation.VERTICAL);
127-
}
128-
}
12928
}

src/test/java/com/flowingcode/vaadin/addons/demo/impl/Demo.java renamed to src/test/java/com/flowingcode/vaadin/addons/demo/Demo.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@
1717
* limitations under the License.
1818
* #L%
1919
*/
20-
package com.flowingcode.vaadin.addons.demo.impl;
20+
package com.flowingcode.vaadin.addons.demo;
2121

22+
import com.flowingcode.vaadin.addons.demo.TabbedDemo;
2223
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
2324
import com.vaadin.flow.component.textfield.TextField;
2425
import com.vaadin.flow.router.Route;
@@ -38,7 +39,7 @@ public Demo() {
3839
vl.setSizeFull();
3940
vl.add(new TextField("Hello"));
4041

41-
TabbedDemoImpl tabbedDemo = new TabbedDemoImpl();
42+
TabbedDemo tabbedDemo = new TabbedDemo();
4243
tabbedDemo.addDemo(vl, "Demo 1", sourceCodeUrl);
4344

4445
vl2.add(new TextField("Hi"));

0 commit comments

Comments
 (0)