Subversion Repository Public Repository

litesoft

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package com.temp.client.foundation.widget;

import com.temp.shared.utils.StringUtils;

import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.VerticalPanel;

public class PageHeader extends AbstractHorizontalLabeledPageWidget {
    private static final String PAGE_HEADER_STYLE_NAME = "page-header";
    private static final String TITLE_STYLE_NAME = "page-header-title";
    public static final String DESCRIPTION_STYLE_NAME = "section-description";

    private final VerticalPanel overallVerticalPanel = new VerticalPanel();
    private final VerticalPanel leftPanel = new VerticalPanel();
    private final VerticalPanel rightPanel = new VerticalPanel();
    private Label descriptionLabel;
    private Label bottomDescriptionLabel;

    public PageHeader() {
        super(PAGE_HEADER_STYLE_NAME, TITLE_STYLE_NAME);

        overallVerticalPanel.setWidth("100%");
        horizontalPanel.add(overallVerticalPanel);
        HorizontalPanel innerHorizontalPanel = new HorizontalPanel();
        overallVerticalPanel.add(innerHorizontalPanel);

        innerHorizontalPanel.add(leftPanel);
        innerHorizontalPanel.add(new LeftRightSiblings(false));
        innerHorizontalPanel.add(rightPanel);

        leftPanel.add(titleLabel);
    }

    public void setDescription(String description) {
        descriptionLabel = setLabelAsDescription(leftPanel, descriptionLabel, description);
    }

    public void setBottomDescription(String description) {
        bottomDescriptionLabel = setLabelAsDescription(overallVerticalPanel, bottomDescriptionLabel, description);
    }

    public VerticalPanel getLeftPanel() {
        return leftPanel;
    }

    public VerticalPanel getRightPanel() {
        return rightPanel;
    }

    public CompositeButton addButton(String name, ClickHandler clickHandler) {
        return addButton(new OurPushButton(name, clickHandler));
    }

    public CompositeButton addButton(CompositeButton button) {
        if (rightPanel.getWidgetCount() > 0) {
            rightPanel.add(new Spacer());
        }
        rightPanel.add(button);
        return button;
    }

    /**
     * Since "some" of the Browsers will treat a "table cell" that contains an
     * empty DIV (label) as if it does not implicitly get a 1em space when all
     * it contains is an empty label. So if the description is null or empty,
     * then the label must be removed!
     */
    private static Label setLabelAsDescription(VerticalPanel parent, Label label, String description) {
        description = StringUtils.noEmpty(description);
        if (description == null) {
            return removeDescriptionLabel(parent, label);
        }
        label = insureDescriptionLabel(parent, label);
        label.setText(description);
        return label;
    }

    private static Label insureDescriptionLabel(VerticalPanel parent, Label label) {
        if (label == null) {
            label = new Label();
            label.setStyleName(DESCRIPTION_STYLE_NAME);
            parent.add(label);
        }
        return label;
    }

    private static Label removeDescriptionLabel(VerticalPanel parent, Label label) {
        if (label != null) {
            parent.remove(label);
        }
        return null;
    }
}

Commits for litesoft/trunk/GWT_Sandbox/FormEngine/src/com/temp/client/foundation/widget/PageHeader.java

Diff revisions: vs.
Revision Author Commited Message
626 GeorgeS picture GeorgeS Wed 11 Apr, 2012 19:39:41 +0000