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 org.glom.web.client.Utils;
23 import org.glom.web.shared.layout.LayoutGroup;
24 import org.glom.web.shared.layout.LayoutItem;
25 import org.glom.web.shared.layout.LayoutItemNotebook;
27 import com.google.gwt.dom.client.Style.Unit;
28 import com.google.gwt.user.client.ui.FlowPanel;
29 import com.google.gwt.user.client.ui.TabLayoutPanel;
30 import com.google.gwt.user.client.ui.Widget;
33 * @author Ben Konrath <ben@bagu.org>
36 public class Notebook extends Group {
38 @SuppressWarnings("unused")
40 // disable default constructor
44 * Create a new Notebook widget based on the specified LayoutItemNotebook DTO.
46 * @param layoutItemNotebook
48 public Notebook(LayoutItemNotebook layoutItemNotebook) {
49 TabLayoutPanel tabPanel = new TabLayoutPanel(1.6, Unit.EM);
51 int maxChildHeight = 0;
52 for (LayoutItem layoutItem : layoutItemNotebook.getItems()) {
53 if (!(layoutItem instanceof LayoutGroup))
54 // Ignore non-LayoutGroup items. This is what Glom 1.18 does.
57 Widget child = createChildWidget(layoutItem, false, false);
59 // update the maximum value of the child height if required
60 int childHeight = Utils.getWidgetHeight(child);
61 if (childHeight > maxChildHeight)
62 maxChildHeight = childHeight;
64 tabPanel.add(child, layoutItem.getTitle());
67 // Set the first tab as the default tab.
68 tabPanel.selectTab(0);
70 // The height needs to be set of the TabLayoutPanel to work.
71 // Use the max child height plus a few extra pixels for padding.
72 tabPanel.setHeight((maxChildHeight + 6) + "px");
74 FlowPanel mainPanel = getMainPanel();
75 mainPanel.add(tabPanel);
76 initWidget(mainPanel);