|
| 1 | +/*- |
| 2 | + * #%L |
| 3 | + * OrgChart Add-on |
| 4 | + * %% |
| 5 | + * Copyright (C) 2017 - 2020 Flowing Code S.A. |
| 6 | + * %% |
| 7 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | + * you may not use this file except in compliance with the License. |
| 9 | + * You may obtain a copy of the License at |
| 10 | + * |
| 11 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | + * |
| 13 | + * Unless required by applicable law or agreed to in writing, software |
| 14 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | + * See the License for the specific language governing permissions and |
| 17 | + * limitations under the License. |
| 18 | + * #L% |
| 19 | + */ |
| 20 | +package com.flowingcode.vaadin.addons.orgchart; |
| 21 | + |
| 22 | +import java.util.Arrays; |
| 23 | + |
| 24 | +import com.flowingcode.vaadin.addons.orgchart.extra.TemplateLiteralRewriter; |
| 25 | +import com.vaadin.flow.component.orderedlayout.VerticalLayout; |
| 26 | + |
| 27 | +@SuppressWarnings("serial") |
| 28 | +public class ImageInTitleDemo extends VerticalLayout { |
| 29 | + |
| 30 | + public ImageInTitleDemo() { |
| 31 | + OrgChart component = getOrgChartData(); |
| 32 | + String nodeTemplate = |
| 33 | + "<div class='title'>" |
| 34 | + + "${item.data.imageUrl?`<img src=${item.data.imageUrl}></img>`:''}" |
| 35 | + + "${item.title}</div>" |
| 36 | + + "<div class='middle content'>${item.name}</div>" |
| 37 | + + "${item.data.mail?`<div class='custom content'>${item.data.mail}</div>`:''}"; |
| 38 | + component.setNodeTemplate("item", TemplateLiteralRewriter.rewriteFunction(nodeTemplate)); |
| 39 | + component.addClassNames("chart-container", "image-title-demo"); |
| 40 | + |
| 41 | + component.setChartTitle( |
| 42 | + "My Organization Chart Demo - Example 3 - CUSTOM TEMPLATE WITH IMAGE IN TITLE"); |
| 43 | + component.setChartNodeContent("title"); |
| 44 | + component.setChartExportButton(true); |
| 45 | + component.setChartExpandCollapse(true); |
| 46 | + |
| 47 | + setSizeFull(); |
| 48 | + add(component); |
| 49 | + } |
| 50 | + |
| 51 | + private OrgChart getOrgChartData() { |
| 52 | + OrgChartItem item1 = new OrgChartItem(1, "John Williams", "Director"); |
| 53 | + item1. setData( "mail", "[email protected]"); |
| 54 | + item1.setData("imageUrl", "images/users.png"); |
| 55 | + |
| 56 | + OrgChartItem item2 = new OrgChartItem(2, "Anna Thompson", "Administration"); |
| 57 | + item2. setData( "mail", "[email protected]"); |
| 58 | + item2.setData("imageUrl", "images/users.png"); |
| 59 | + |
| 60 | + OrgChartItem item3 = |
| 61 | + new OrgChartItem( |
| 62 | + 3, "Timothy Albert Henry Jones ", "Sub-Director of Administration Department"); |
| 63 | + item3. setData( "mail", "[email protected]"); |
| 64 | + item3.setData("imageUrl", "images/user.png"); |
| 65 | + |
| 66 | + item1.setChildren(Arrays.asList(item2, item3)); |
| 67 | + |
| 68 | + OrgChartItem item4 = new OrgChartItem(4, "Louise Night", "Department 1"); |
| 69 | + item4. setData( "mail", "[email protected]"); |
| 70 | + item4.setData("imageUrl", "images/user.png"); |
| 71 | + |
| 72 | + OrgChartItem item5 = new OrgChartItem(5, "John Porter", "Department 2"); |
| 73 | + item5. setData( "mail", "[email protected]"); |
| 74 | + item5.setData("imageUrl", "images/user.png"); |
| 75 | + |
| 76 | + OrgChartItem item6 = new OrgChartItem(6, "Charles Thomas", "Department 3"); |
| 77 | + item6. setData( "mail", "[email protected]"); |
| 78 | + item6.setData("imageUrl", "images/users.png"); |
| 79 | + |
| 80 | + item2.setChildren(Arrays.asList(item4, item5, item6)); |
| 81 | + |
| 82 | + OrgChartItem item7 = new OrgChartItem(7, "Michael Wood", "Section 3.1"); |
| 83 | + item7.setData("imageUrl", "images/user.png"); |
| 84 | + |
| 85 | + OrgChartItem item8 = new OrgChartItem(8, "Martha Brown", "Section 3.2"); |
| 86 | + item8.setData("imageUrl", "images/user.png"); |
| 87 | + |
| 88 | + OrgChartItem item9 = new OrgChartItem(9, "Mary Parker", "Section 3.3"); |
| 89 | + item9.setData("imageUrl", "images/user.png"); |
| 90 | + OrgChartItem item10 = new OrgChartItem(10, "Mary Williamson", "Section 3.4"); |
| 91 | + item10.setData("imageUrl", "images/user.png"); |
| 92 | + |
| 93 | + item6.setChildren(Arrays.asList(item7, item8, item9, item10)); |
| 94 | + |
| 95 | + return new OrgChart(item1); |
| 96 | + } |
| 97 | +} |
0 commit comments