Skip to content

Commit 5d27851

Browse files
authored
Merge pull request #43 from FlowingCode/refactor-3.0
Integrate refactor-3.0 into master
2 parents 4ff4cb5 + 9307a1b commit 5d27851

39 files changed

+1403
-632
lines changed

README.md

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,20 @@
55
# App Layout Add-on
66

77
Vaadin Flow Java integration of https://github.com/PolymerElements/app-layout
8-
This addon is particularly usefull if you want to create a new application with some initial support for responsiveness.
8+
This addon is particularly useful if you want to create a new application with some initial support for responsiveness.
99

1010
## Features
1111

12-
* Left side menu with hamburguer button, and now with support for sub-menus and icons
13-
* Toolbar icons
14-
* Paper-cards with icons
15-
12+
* Left side menu with hamburguer button
13+
* Hierarchical menus with icons
14+
* Application header with logo, title and toolbar icons.
15+
* Menu separator
16+
* Support for left, middle and right click listeners.
17+
* Menu items accepts arbitrary content (such as checkboxes, or buttons)
18+
1619
## Online demo
1720

18-
[Online demo here](http://addonsv10.flowingcode.com/applayout)
21+
[Online demo here](http://addonsv14.flowingcode.com/applayout)
1922

2023
## Download release
2124

@@ -40,9 +43,9 @@ To see the demo, navigate to http://localhost:8080/
4043
- **Version 1.0.7** Added abstract RouterLayout and style mouse pointer as a hand.
4144
- **Version 1.0.8** Deprecate methods for removal in future releases.
4245

43-
## Roadmap
44-
45-
* Support for app-grid
46+
- **Version 2.1.0**
47+
The `MenuItem` class in package `com.flowingcode.addons.applayout.menu` was replaced by a `MenuItem` component (in package `com.flowingcode.addons.applayout`), which renders an item in the lateral menu, and `ToolbarIconButton`, which is a clickable icon (without label) suitable for use in the AppToolbar part. Some custom CSS selectors that depended on the internal menu item structure may need to be rewritten.
48+
Classes and methods deprecated in version 2.0 have been removed.
4649

4750
## Issue tracking
4851

@@ -77,26 +80,21 @@ Adding menu items with sub-menus & icons:
7780
```
7881
app.setMenuItems(new MenuItem("Say hello", "star", () -> showContent("Hello!")),
7982
new MenuItem("About", "cloud", () -> showContent("About")),
80-
new MenuItem("SubMenu", "build",
83+
new MenuItem("SubMenu").setIcon("build").add(
8184
new MenuItem("Hello Again", "inbox",()->showContent("Hello Again!")),
8285
new MenuItem("And Again",()->showContent("And Again!")),
83-
new MenuItem("SubMenu",
86+
new MenuItem("SubMenu").add(
8487
new MenuItem("Hello Again",()->showContent("Hello Again!")),
85-
new MenuItem("And Again",()->showContent("And Again!")))
86-
));
88+
new MenuItem("And Again",()->showContent("And Again!"))
89+
)
90+
)
91+
);
8792
```
8893
Toolbar icons:
8994
```
90-
app.setToolbarIconButtons(new MenuItem("Delete", "delete", ()->Notification.show("Delete action")),
91-
new MenuItem("Search", "search", ()->Notification.show("Search action")),
92-
new MenuItem("Close", "close", ()->Notification.show("Close action"))
93-
);
94-
```
95-
Using paper-cards:
96-
```
97-
H3 label = new H3();
98-
label.setSizeFull();
99-
label.setText(content);
100-
PaperCard pc = new PaperCard(label,new MenuItem("Delete", "delete", ()->Notification.show("Delete action from card")));
101-
pc.setWidth("100%");
102-
```
95+
app.setToolbarIconButtons(
96+
new ToolbarIconButton("Delete", "delete", ()->Notification.show("Delete action")),
97+
new ToolbarIconButton("Search", "search", ()->Notification.show("Search action")),
98+
new ToolbarIconButton("Close", "close", ()->Notification.show("Close action"))
99+
);
100+
```

pom.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44

55
<groupId>com.flowingcode.addons.applayout</groupId>
66
<artifactId>app-layout-addon</artifactId>
7-
<version>2.0.3-SNAPSHOT</version>
7+
<version>3.0.0-SNAPSHOT</version>
88
<name>App Layout Addon</name>
99
<description>Integration of app-layout for Vaadin Flow</description>
1010

1111
<properties>
12-
<vaadin.version>14.0.11</vaadin.version>
12+
<vaadin.version>14.0.14</vaadin.version>
1313

1414
<maven.compiler.source>1.8</maven.compiler.source>
1515
<maven.compiler.target>1.8</maven.compiler.target>
@@ -93,6 +93,7 @@
9393
</exclusion>
9494
</exclusions>
9595
</dependency>
96+
9697
<dependency>
9798
<groupId>org.slf4j</groupId>
9899
<artifactId>slf4j-simple</artifactId>

src/main/java/com/flowingcode/addons/applayout/AbstractFcAppRouterLayout.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* #%L
33
* App Layout Addon
44
* %%
5-
* Copyright (C) 2018 - 2019 Flowing Code
5+
* Copyright (C) 2018 - 2020 Flowing Code
66
* %%
77
* Licensed under the Apache License, Version 2.0 (the "License");
88
* you may not use this file except in compliance with the License.
@@ -40,11 +40,13 @@ public abstract class AbstractFcAppRouterLayout extends Div implements RouterLay
4040
private AppLayout app;
4141

4242
public AbstractFcAppRouterLayout() {
43-
setSizeFull();
43+
getElement().getStyle().set("width", "100%");
44+
getElement().getStyle().set("height", "100vh");
4445
getElement().getStyle().set("display", "flex");
4546
getElement().getStyle().set("flex-direction", "column");
4647
app = new AppLayout("");
4748
app.setHeight("32px");
49+
app.getElement().getStyle().set("flex-shrink", "0");
4850
app.addClassName("compact");
4951
app.setFixed(true);
5052
app.setSwipeOpen(false);

src/main/java/com/flowingcode/addons/applayout/AppDrawer.java

Lines changed: 51 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* #%L
33
* App Layout Addon
44
* %%
5-
* Copyright (C) 2018 - 2019 Flowing Code
5+
* Copyright (C) 2018 - 2020 Flowing Code
66
* %%
77
* Licensed under the Apache License, Version 2.0 (the "License");
88
* you may not use this file except in compliance with the License.
@@ -21,11 +21,10 @@
2121

2222

2323

24-
import java.util.ArrayList;
24+
import java.util.Collection;
2525
import java.util.Collections;
26-
import java.util.List;
26+
import java.util.Optional;
2727

28-
import com.flowingcode.addons.applayout.menu.MenuItem;
2928
import com.vaadin.flow.component.Component;
3029
import com.vaadin.flow.component.HasComponents;
3130
import com.vaadin.flow.component.Tag;
@@ -56,72 +55,73 @@ public AppDrawer(String title) {
5655
this(new H4(title));
5756
header.getElement().setAttribute("style", "text-align:center");
5857
}
59-
58+
6059
public AppDrawer(Component headerComponent) {
6160
this.header = headerComponent;
6261
getElement().setAttribute("id", "drawer");
6362
setSwipeOpen(true);
64-
this.add(headerComponent);
65-
this.add(pm);
66-
63+
6764
Registration[] r = new Registration[1];
6865
r[0] = getElement().addEventListener("app-drawer-transitioned", ev->{
6966
//need to adjust the height after the drawer has been rendered
7067
pm.getElement().executeJs("this.style.height='calc(100% - '+($0.scrollHeight+16)+'px)'", header);
7168
r[0].remove();
7269
});
70+
71+
removeAll();
7372
}
74-
73+
7574
public void setSwipeOpen(boolean swipeOpen) {
7675
getElement().setAttribute("swipe-open", swipeOpen);
7776
}
7877

79-
public void setMenuItems(List<MenuItem> menuItems) {
80-
Component[] components = createComponents(menuItems);
81-
pm.removeAll();
82-
pm.add(components);
83-
}
84-
85-
private Component[] createComponents(List<MenuItem> menuItems) {
86-
List<Component> components = new ArrayList<>();
87-
for (MenuItem menuItem : menuItems) {
88-
if (!menuItem.getSubMenuItems().isEmpty()) {
89-
components.add(collectMenus(menuItem));
78+
@Override
79+
public void add(Component... components) {
80+
for (Component c : components) {
81+
if (c instanceof MenuItem) {
82+
pm.add(c);
9083
} else {
91-
if (menuItem.getIcon()==null && menuItem.getImage()==null) {
92-
PaperItem pi = new PaperItem(menuItem.getLabel(),menuItem.getCommand(), this);
93-
pi.setEnabled(menuItem.isEnabled());
94-
components.add(pi);
95-
menuItem.setRefreshCallback(()->pi.setText(menuItem.getLabel()));
96-
} else {
97-
PaperIconItem pi;
98-
if (menuItem.getImage()!=null) {
99-
pi = new PaperIconItem(menuItem.getLabel(), menuItem.getImage(), menuItem.getCommand(), this);
100-
} else {
101-
pi = new PaperIconItem(menuItem.getLabel(), menuItem.getIcon(), menuItem.getCommand(), this);
102-
}
103-
104-
components.add(pi);
105-
pi.setEnabled(menuItem.isEnabled());
106-
menuItem.setRefreshCallback(()->{
107-
pi.setTitle(menuItem.getLabel());
108-
pi.setIcon(menuItem.getIcon());
109-
});
110-
}
84+
HasComponents.super.add(components);
11185
}
112-
}
113-
return components.toArray(new Component[] {});
114-
}
86+
}
87+
}
88+
89+
@Override
90+
public void remove(Component... components) {
91+
for (Component c : components) {
92+
if (c instanceof MenuItem) {
93+
pm.removeAll();
94+
} else {
95+
HasComponents.super.remove(components);
96+
}
97+
}
98+
}
99+
100+
@Override
101+
public void removeAll() {
102+
HasComponents.super.removeAll();
103+
this.add(header);
104+
this.add(pm);
105+
}
106+
107+
public void setMenuItems(Collection<? extends Component> menuItems) {
108+
pm.removeAll();
109+
menuItems.stream().forEach(pm::add);
110+
}
115111

116-
private CollapseButton collectMenus(MenuItem topMenuItem) {
117-
List<MenuItem> menuItems = topMenuItem.getSubMenuItems();
118-
Component[] components = createComponents(menuItems);
119-
CollapseButton collapseButton = new CollapseButton(topMenuItem.getLabel(), topMenuItem.getIcon(), topMenuItem.getImage(), components);
120-
collapseButton.setEnabled(topMenuItem.isEnabled());
121-
return collapseButton;
112+
/**Close the app-drawer.*/
113+
public void close() {
114+
getUI().ifPresent(ui->ui.getPage().executeJs("$0.close()", this));
122115
}
123116

124-
void toggle() {
125-
this.getElement().executeJs("this.toggle()");
117+
static Optional<AppDrawer> findAppDrawer(Component component) {
118+
while (component!=null) {
119+
if (component instanceof AppDrawer) {
120+
return Optional.of((AppDrawer)component);
121+
} else {
122+
component = component.getParent().orElse(null);
123+
}
124+
}
125+
return Optional.empty();
126126
}
127127
}

src/main/java/com/flowingcode/addons/applayout/AppHeader.java

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* #%L
33
* App Layout Addon
44
* %%
5-
* Copyright (C) 2018 - 2019 Flowing Code
5+
* Copyright (C) 2018 - 2020 Flowing Code
66
* %%
77
* Licensed under the Apache License, Version 2.0 (the "License");
88
* you may not use this file except in compliance with the License.
@@ -21,7 +21,6 @@
2121

2222

2323

24-
import com.flowingcode.addons.applayout.menu.MenuItem;
2524
import com.vaadin.flow.component.Component;
2625
import com.vaadin.flow.component.HasComponents;
2726
import com.vaadin.flow.component.Tag;
@@ -65,14 +64,6 @@ public AppToolbar getAppToolbar() {
6564
return appToolbar;
6665
}
6766

68-
public void setToolbarIconButtons(MenuItem[] menuItems) {
69-
appToolbar.setToolbarIconButtons(menuItems);
70-
}
71-
72-
public void setMenuIconVisible(boolean visible) {
73-
appToolbar.setMenuIconVisible(visible);
74-
}
75-
7667
/**Mantains the header fixed at the top so it never moves away.*/
7768
public void setFixed(boolean fixed) {
7869
this.getElement().setAttribute("fixed", fixed);

src/main/java/com/flowingcode/addons/applayout/AppLayout.java

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* #%L
33
* App Layout Addon
44
* %%
5-
* Copyright (C) 2018 - 2019 Flowing Code
5+
* Copyright (C) 2018 - 2020 Flowing Code
66
* %%
77
* Licensed under the Apache License, Version 2.0 (the "License");
88
* you may not use this file except in compliance with the License.
@@ -23,7 +23,6 @@
2323
import java.util.ArrayList;
2424
import java.util.Arrays;
2525

26-
import com.flowingcode.addons.applayout.menu.MenuItem;
2726
import com.vaadin.flow.component.Component;
2827
import com.vaadin.flow.component.dependency.CssImport;
2928
import com.vaadin.flow.component.dependency.HtmlImport;
@@ -54,8 +53,8 @@ public class AppLayout extends Div implements PageConfigurator {
5453

5554
static final String NPM_VERSION = "3.0.2";
5655

57-
AppDrawer drawer;
58-
AppHeader header;
56+
private AppDrawer drawer;
57+
private AppHeader header;
5958

6059
public AppLayout(String title) {
6160
drawer = new AppDrawer(title);
@@ -86,21 +85,34 @@ public void setHeight(String height) {
8685
header.setHeight(height);
8786
}
8887

89-
public void setMenuItems(MenuItem... menuitems) {
88+
public void setMenuItems(Component... menuitems) {
9089
drawer.setMenuItems(Arrays.asList(menuitems));
9190
}
9291

9392
public void clearMenuItems() {
9493
drawer.setMenuItems(new ArrayList<MenuItem>());
9594
}
9695

97-
public void setToolbarIconButtons(MenuItem... menuItems) {
98-
header.setToolbarIconButtons(menuItems);
96+
public void setToolbarIconButtons(Component... components) {
97+
header.getAppToolbar().clearToolbarIconButtons();
98+
header.getAppToolbar().addToolbarIconButtons(components);
99+
}
100+
101+
public void addToolbarIconButtons(Component... components) {
102+
header.getAppToolbar().addToolbarIconButtons(components);
103+
}
104+
105+
public void addToolbarIconButtonAsFirst(Component component) {
106+
header.getAppToolbar().addToolbarIconButtonAsFirst(component);
107+
}
108+
109+
public void clearToolbarIconButtons() {
110+
header.getAppToolbar().clearToolbarIconButtons();
99111
}
100112

101113
public void setMenuVisible(boolean visible) {
102114
drawer.setVisible(visible);
103-
header.setMenuIconVisible(visible);
115+
header.getAppToolbar().setMenuIconVisible(visible);
104116
}
105117

106118
public boolean isMenuVisible() {
@@ -131,4 +143,5 @@ public void setReveals(boolean reveals) {
131143
public void setSwipeOpen(boolean swipeOpen) {
132144
drawer.setSwipeOpen(swipeOpen);
133145
}
146+
134147
}

0 commit comments

Comments
 (0)