|
1 | | -package com.flowingcode.addons.applayout; |
2 | | - |
3 | | -/*- |
4 | | - * #%L |
5 | | - * App Layout Addon |
6 | | - * %% |
7 | | - * Copyright (C) 2018 Flowing Code |
8 | | - * %% |
9 | | - * Licensed under the Apache License, Version 2.0 (the "License"); |
10 | | - * you may not use this file except in compliance with the License. |
11 | | - * You may obtain a copy of the License at |
12 | | - * |
13 | | - * http://www.apache.org/licenses/LICENSE-2.0 |
14 | | - * |
15 | | - * Unless required by applicable law or agreed to in writing, software |
16 | | - * distributed under the License is distributed on an "AS IS" BASIS, |
17 | | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
18 | | - * See the License for the specific language governing permissions and |
19 | | - * limitations under the License. |
20 | | - * #L% |
21 | | - */ |
22 | | - |
23 | | -import java.util.ArrayList; |
24 | | -import java.util.List; |
25 | | - |
26 | | -import com.flowingcode.addons.applayout.menu.MenuItem; |
27 | | -import com.vaadin.flow.component.Component; |
28 | | -import com.vaadin.flow.component.HasComponents; |
29 | | -import com.vaadin.flow.component.Tag; |
30 | | -import com.vaadin.flow.component.dependency.HtmlImport; |
31 | | -import com.vaadin.flow.component.html.Div; |
32 | | - |
33 | | -/** |
34 | | - * Component that renders the app toolbar |
35 | | - * |
36 | | - * @author mlopez |
37 | | - * |
38 | | - */ |
39 | | -@SuppressWarnings("serial") |
40 | | -@Tag("app-toolbar") |
41 | | -@HtmlImport("bower_components/app-layout/app-toolbar/app-toolbar.html") |
42 | | -public class AppToolbar extends Component implements HasComponents { |
43 | | - |
44 | | - PaperIconButton menu; |
45 | | - Div divTitle; |
46 | | - |
47 | | - public AppToolbar(String title, AppDrawer drawer) { |
48 | | - menu = new PaperIconButton("menu"); |
49 | | - menu.getElement().setAttribute("onclick", "" + drawer.getId().get() + ".toggle()"); |
50 | | - divTitle = new Div(); |
51 | | - divTitle.setText(title); |
52 | | - divTitle.getElement().setAttribute("main-title", true); |
53 | | - this.add(menu,divTitle); |
54 | | - } |
55 | | - |
56 | | - public void setToolbarIconButtons(MenuItem[] menuItems) { |
57 | | - List<PaperIconButton> toolbarIconButtons = createToolbarIconButtons(menuItems); |
58 | | - this.removeAll(); |
59 | | - this.add(menu,divTitle); |
60 | | - toolbarIconButtons.forEach(tib->this.add(tib)); |
61 | | - } |
62 | | - |
63 | | - private List<PaperIconButton> createToolbarIconButtons(MenuItem[] menuItems) { |
64 | | - List<PaperIconButton> result = new ArrayList<>(); |
65 | | - for (MenuItem menuItem : menuItems) { |
66 | | - result.add(new PaperIconButton(menuItem.getIcon(),menuItem.getCommand())); |
67 | | - } |
68 | | - return result; |
69 | | - } |
70 | | - |
71 | | - |
72 | | -} |
| 1 | +package com.flowingcode.addons.applayout; |
| 2 | + |
| 3 | +/*- |
| 4 | + * #%L |
| 5 | + * App Layout Addon |
| 6 | + * %% |
| 7 | + * Copyright (C) 2018 Flowing Code |
| 8 | + * %% |
| 9 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 10 | + * you may not use this file except in compliance with the License. |
| 11 | + * You may obtain a copy of the License at |
| 12 | + * |
| 13 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 14 | + * |
| 15 | + * Unless required by applicable law or agreed to in writing, software |
| 16 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 17 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 18 | + * See the License for the specific language governing permissions and |
| 19 | + * limitations under the License. |
| 20 | + * #L% |
| 21 | + */ |
| 22 | + |
| 23 | +import java.util.ArrayList; |
| 24 | +import java.util.List; |
| 25 | + |
| 26 | +import com.flowingcode.addons.applayout.menu.MenuItem; |
| 27 | +import com.vaadin.flow.component.Component; |
| 28 | +import com.vaadin.flow.component.HasComponents; |
| 29 | +import com.vaadin.flow.component.Tag; |
| 30 | +import com.vaadin.flow.component.dependency.HtmlImport; |
| 31 | +import com.vaadin.flow.component.html.Div; |
| 32 | + |
| 33 | +/** |
| 34 | + * Component that renders the app toolbar |
| 35 | + * |
| 36 | + * @author mlopez |
| 37 | + * |
| 38 | + */ |
| 39 | +@SuppressWarnings("serial") |
| 40 | +@Tag("app-toolbar") |
| 41 | +@HtmlImport("bower_components/app-layout/app-toolbar/app-toolbar.html") |
| 42 | +public class AppToolbar extends Component implements HasComponents { |
| 43 | + |
| 44 | + PaperIconButton menu; |
| 45 | + Div divTitle; |
| 46 | + |
| 47 | + public AppToolbar(String title, AppDrawer drawer) { |
| 48 | + menu = new PaperIconButton("menu"); |
| 49 | + menu.getElement().setAttribute("onclick", "" + drawer.getId().get() + ".toggle()"); |
| 50 | + divTitle = new Div(); |
| 51 | + divTitle.setText(title); |
| 52 | + divTitle.getElement().setAttribute("main-title", true); |
| 53 | + this.add(menu,divTitle); |
| 54 | + } |
| 55 | + |
| 56 | + public void setToolbarIconButtons(MenuItem[] menuItems) { |
| 57 | + List<PaperIconButton> toolbarIconButtons = createToolbarIconButtons(menuItems); |
| 58 | + this.removeAll(); |
| 59 | + this.add(menu,divTitle); |
| 60 | + toolbarIconButtons.forEach(tib->this.add(tib)); |
| 61 | + } |
| 62 | + |
| 63 | + private List<PaperIconButton> createToolbarIconButtons(MenuItem[] menuItems) { |
| 64 | + List<PaperIconButton> result = new ArrayList<>(); |
| 65 | + for (MenuItem menuItem : menuItems) { |
| 66 | + PaperIconButton paperIconButton = new PaperIconButton(menuItem.getIcon(),menuItem.getCommand()); |
| 67 | + menuItem.setRefreshCallback(() -> paperIconButton.setIcon(menuItem.getIcon())); |
| 68 | + result.add(paperIconButton); |
| 69 | + } |
| 70 | + return result; |
| 71 | +} |
| 72 | + |
| 73 | + |
| 74 | +} |
0 commit comments