2 * Copyright (C) 2011 Openismus GmbH
4 * This file is part of GWT-Glom.
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.
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
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/>.
20 package org.glom.web.client.ui.details;
22 import java.util.ArrayList;
24 import org.glom.web.shared.layout.Formatting;
25 import org.glom.web.shared.layout.LayoutGroup;
26 import org.glom.web.shared.layout.LayoutItem;
27 import org.glom.web.shared.layout.LayoutItemField;
28 import org.glom.web.shared.layout.LayoutItemPortal;
30 import com.google.gwt.dom.client.Style.Unit;
31 import com.google.gwt.user.client.ui.Composite;
32 import com.google.gwt.user.client.ui.FlowPanel;
33 import com.google.gwt.user.client.ui.Label;
36 * @author Ben Konrath <ben@bagu.org>
38 public class Group extends Composite {
39 private FlowPanel mainPanel = new FlowPanel();
40 private FlowPanel groupContents; // set in constructor
41 private final ArrayList<Label> dataLabels = new ArrayList<Label>();
42 FlowTable flowtable;// set in constructor
44 @SuppressWarnings("unused")
46 // disable default constructor
49 public Group(LayoutGroup layoutGroup, boolean subGroup, boolean mainTitleSet) {
50 mainPanel.setStyleName(subGroup ? "subgroup" : "group");
52 String groupTitle = layoutGroup.getTitle();
53 if (!groupTitle.isEmpty()) {
54 Label label = new Label(groupTitle);
57 // the "group-title" class could could be used for the subgroup title if the group title is empty
58 label.setStyleName(mainTitleSet ? "subgroup-title" : "group-title");
61 groupContents = new FlowPanel();
62 groupContents.setStyleName("group-contents");
63 mainPanel.add(groupContents);
65 // don't make a separate contents panel when the group title has not been set
66 groupContents = mainPanel;
69 flowtable = new FlowTable(layoutGroup.getColumnCount());
70 groupContents.add(flowtable);
72 // create the appropriate UI element for each child item
73 for (LayoutItem layoutItem : layoutGroup.getItems()) {
75 if (layoutItem instanceof LayoutItemField) {
76 addDetailsCell((LayoutItemField) layoutItem);
77 } else if (layoutItem instanceof LayoutItemPortal) {
78 FlowPanel portalCell = new FlowPanel();
79 portalCell.setStyleName("subgroup");
80 portalCell.setHeight("12em");
82 Label portalTitle = new Label("Portal Title"); // TODO: replace temporary title
83 portalTitle.setStyleName(mainTitleSet ? "subgroup-title" : "group-title");
84 portalCell.add(portalTitle);
86 FlowPanel portalContents = new FlowPanel();
87 portalContents.setStyleName("group-contents"); // using the same style as the group-contents element
89 // TODO add proper CellTable
90 Label tempPortalData = new Label("Portal Data");
91 tempPortalData.getElement().getStyle().setFontSize(2, Unit.EM);
92 portalContents.add(tempPortalData);
94 portalCell.add(portalContents);
95 flowtable.add(portalCell);
96 } else if (layoutItem instanceof LayoutGroup) {
97 // create a Group for the child group
98 Group group = new Group((LayoutGroup) layoutItem, true, mainTitleSet);
100 dataLabels.addAll(group.getDataLabels());
104 initWidget(mainPanel);
107 private void addDetailsCell(LayoutItemField layoutItemField) {
108 // Labels (text in div element) are being used so that the height of the details-data element can be set for
109 // the multiline height of LayoutItemFeilds. This allows the the data element to display the correct height
110 // if style is applied that shows the height. This has the added benefit of allowing the order of the label and
111 // data elements to be changed for right-to-left languages.
113 Label detailsLabel = new Label(layoutItemField.getTitle() + ":");
114 detailsLabel.setStyleName("details-label");
116 Label detailsData = new Label();
117 detailsData.setStyleName("details-data");
118 Formatting formatting = layoutItemField.getFormatting();
119 detailsData.setHeight(formatting.getTextFormatMultilineHeightLines() + "em");
121 FlowPanel detailsCell = new FlowPanel();
122 detailsCell.setStyleName("details-cell");
124 detailsCell.add(detailsLabel);
125 detailsCell.add(detailsData);
127 flowtable.add(detailsCell);
128 dataLabels.add(detailsData);
131 public ArrayList<Label> getDataLabels() {