Details: add a colon after the field title.
[online-glom:gwt-glom.git] / src / main / java / org / glom / web / client / ui / FlowTable.java
1 /*
2  * Copyright (C) 2011 Openismus GmbH
3  *
4  * This file is part of GWT-Glom.
5  *
6  * GWT-Glom is free software: you can redistribute it and/or modify it
7  * under the terms of the GNU Lesser General Public License as published by the
8  * Free Software Foundation, either version 3 of the License, or (at your
9  * option) any later version.
10  *
11  * GWT-Glom is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
14  * for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with GWT-Glom.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20 package org.glom.web.client.ui;
21
22 import java.util.ArrayList;
23
24 import org.glom.web.shared.layout.LayoutGroup;
25 import org.glom.web.shared.layout.LayoutItem;
26 import org.glom.web.shared.layout.LayoutItemField;
27 import org.glom.web.shared.layout.LayoutItemPortal;
28
29 import com.google.gwt.user.client.ui.FlowPanel;
30 import com.google.gwt.user.client.ui.InlineLabel;
31 import com.google.gwt.user.client.ui.Label;
32
33 /**
34  * @author Ben Konrath <ben@bagu.org>
35  * 
36  */
37 class FlowTable extends FlowPanel {
38         FlowPanel groupContents = new FlowPanel();
39         private final ArrayList<InlineLabel> dataLabels = new ArrayList<InlineLabel>();
40
41         public FlowTable(LayoutGroup layoutGroup) {
42                 super();
43                 setStyleName("group");
44
45                 String groupTitle = layoutGroup.getTitle();
46                 if (!groupTitle.isEmpty()) {
47                         Label label = new Label(groupTitle);
48                         label.setStyleName("group-title");
49                         this.add(label);
50                 }
51
52                 groupContents.setStyleName("group-contents");
53                 this.add(groupContents);
54
55                 createLayout(layoutGroup, "");
56         }
57
58         private InlineLabel addDetailsCell(String title) {
59
60                 InlineLabel detailsLabel = new InlineLabel(title + ":");
61                 detailsLabel.setStyleName("details-label");
62
63                 InlineLabel detailsData = new InlineLabel();
64                 detailsData.setStyleName("details-data");
65
66                 FlowPanel fieldPanel = new FlowPanel();
67                 fieldPanel.setStyleName("details-cell");
68
69                 fieldPanel.add(detailsLabel);
70                 fieldPanel.add(detailsData);
71
72                 groupContents.add(fieldPanel);
73
74                 return detailsData;
75         }
76
77         /*
78          * Creates a basic indented layout without the flowtable.
79          */
80         private void createLayout(LayoutGroup layoutGroup, String indent) {
81                 if (layoutGroup == null)
82                         return;
83
84                 // look at each child item
85                 ArrayList<LayoutItem> layoutItems = layoutGroup.getItems();
86                 for (LayoutItem layoutItem : layoutItems) {
87
88                         if (layoutItem == null)
89                                 continue;
90
91                         String title = layoutItem.getTitle();
92                         if (layoutItem instanceof LayoutItemField) {
93                                 dataLabels.add(addDetailsCell(indent + title));
94                         } else if (layoutItem instanceof LayoutItemPortal) {
95                                 // ignore portals for now
96                                 continue;
97                         } else if (layoutItem instanceof LayoutGroup) {
98                                 // create a FlowTable for the child group
99                                 FlowTable flowTable = new FlowTable((LayoutGroup) layoutItem);
100                                 groupContents.add(flowTable);
101                                 dataLabels.addAll(flowTable.getDataLabels());
102                         }
103                 }
104         }
105
106         public ArrayList<InlineLabel> getDataLabels() {
107                 return dataLabels;
108         }
109 }