|
| 1 | +/*- |
| 2 | + * #%L |
| 3 | + * OrgChart Add-on |
| 4 | + * %% |
| 5 | + * Copyright (C) 2017 - 2025 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.demo.DemoSource; |
| 25 | +import com.flowingcode.vaadin.addons.orgchart.extra.TemplateLiteralRewriter; |
| 26 | +import com.vaadin.flow.component.orderedlayout.VerticalLayout; |
| 27 | +import com.vaadin.flow.router.PageTitle; |
| 28 | +import com.vaadin.flow.router.Route; |
| 29 | + |
| 30 | +@SuppressWarnings("serial") |
| 31 | +@PageTitle("Hybrid Data Property") |
| 32 | +@DemoSource |
| 33 | +@Route(value = "orgchart/hybrid-data-property", layout = OrgchartDemoView.class) |
| 34 | +public class HybridDataPropertyDemo extends VerticalLayout { |
| 35 | + |
| 36 | + public HybridDataPropertyDemo() { |
| 37 | + OrgChart component = getExample(); |
| 38 | + String nodeTemplate = |
| 39 | + "<div class='title'>${item.title}</div>" |
| 40 | + + "<div class='middle content'>${item.name}</div>" |
| 41 | + + "${item.data.mail?`<div class='custom content'>${item.data.mail}</div>`:''}"; |
| 42 | + component.setNodeTemplate("item", TemplateLiteralRewriter.rewriteFunction(nodeTemplate)); |
| 43 | + component.addClassName("chart-container"); |
| 44 | + component.setChartTitle( |
| 45 | + "My Organization Chart Demo - Example 5 - HYBRID DATA PROPERTY WITH CUSTOM TEMPLATE"); |
| 46 | + component.setChartNodeContent("title"); |
| 47 | + setSizeFull(); |
| 48 | + add(component); |
| 49 | + } |
| 50 | + |
| 51 | + private OrgChart getExample() { |
| 52 | + OrgChartItem item1 = new OrgChartItem(1, "John Williams", "Director"); |
| 53 | + item1.setData("mail", "jwilliams@example.com"); |
| 54 | + item1.setClassName("blue-node"); |
| 55 | + OrgChartItem item2 = new OrgChartItem(2, "Anna Thompson", "Administration"); |
| 56 | + item2.setData("mail", "athomp@example.com"); |
| 57 | + item2.setClassName("blue-node"); |
| 58 | + |
| 59 | + // set item 2 as hybrid |
| 60 | + item2.setHybrid(true); |
| 61 | + |
| 62 | + OrgChartItem item3 = |
| 63 | + new OrgChartItem( |
| 64 | + 3, "Timothy Albert Henry Jones ", "Sub-Director of Administration Department"); |
| 65 | + item3.setData("mail", "timothy.albert.jones@example.com"); |
| 66 | + item1.setChildren(Arrays.asList(item2, item3)); |
| 67 | + OrgChartItem item4 = new OrgChartItem(4, "Louise Night", "Department 1"); |
| 68 | + item4.setData("mail", "lnight@example.com"); |
| 69 | + OrgChartItem item5 = new OrgChartItem(5, "John Porter", "Department 2"); |
| 70 | + item5.setData("mail", "jporter@example.com"); |
| 71 | + OrgChartItem item6 = new OrgChartItem(6, "Charles Thomas", "Department 3"); |
| 72 | + item6.setData("mail", "ctomas@example.com"); |
| 73 | + |
| 74 | + // set item 6 as hybrid |
| 75 | + item6.setHybrid(true); |
| 76 | + |
| 77 | + item2.setChildren(Arrays.asList(item4, item5, item6)); |
| 78 | + OrgChartItem item7 = new OrgChartItem(7, "Michael Wood", "Section 3.1"); |
| 79 | + OrgChartItem item8 = new OrgChartItem(8, "Martha Brown", "Section 3.2"); |
| 80 | + OrgChartItem item9 = new OrgChartItem(9, "Mary Parker", "Section 3.3"); |
| 81 | + OrgChartItem item10 = new OrgChartItem(10, "Mary Williamson", "Section 3.4"); |
| 82 | + item6.setChildren(Arrays.asList(item7, item8, item9, item10)); |
| 83 | + return new OrgChart(item1); |
| 84 | + } |
| 85 | +} |
0 commit comments