001/*
002 * This library is part of OpenCms -
003 * the Open Source Content Management System
004 *
005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com)
006 *
007 * This library is free software; you can redistribute it and/or
008 * modify it under the terms of the GNU Lesser General Public
009 * License as published by the Free Software Foundation; either
010 * version 2.1 of the License, or (at your option) any later version.
011 *
012 * This library is distributed in the hope that it will be useful,
013 * but WITHOUT ANY WARRANTY; without even the implied warranty of
014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015 * Lesser General Public License for more details.
016 *
017 * For further information about Alkacon Software, please see the
018 * company website: http://www.alkacon.com
019 *
020 * For further information about OpenCms, please see the
021 * project website: http://www.opencms.org
022 *
023 * You should have received a copy of the GNU Lesser General Public
024 * License along with this library; if not, write to the Free Software
025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
026 */
027
028package org.opencms.gwt.client.ui;
029
030import org.opencms.gwt.client.Messages;
031import org.opencms.util.CmsStringUtil;
032
033import com.google.gwt.core.client.GWT;
034import com.google.gwt.dom.client.DivElement;
035import com.google.gwt.dom.client.Element;
036import com.google.gwt.dom.client.HeadingElement;
037import com.google.gwt.dom.client.ParagraphElement;
038import com.google.gwt.dom.client.SpanElement;
039import com.google.gwt.dom.client.Style.Unit;
040import com.google.gwt.uibinder.client.UiBinder;
041import com.google.gwt.uibinder.client.UiField;
042import com.google.gwt.user.client.ui.Composite;
043import com.google.gwt.user.client.ui.FlowPanel;
044import com.google.gwt.user.client.ui.HTMLPanel;
045import com.google.gwt.user.client.ui.Widget;
046
047/**
048 * Header info widget.<p>
049 */
050public class CmsInfoHeader extends Composite {
051
052    /**
053     * @see com.google.gwt.uibinder.client.UiBinder
054     */
055    protected interface I_CmsInfoHeaderUiBinder extends UiBinder<HTMLPanel, CmsInfoHeader> {
056        // GWT interface, nothing to do here
057    }
058
059    /** The ui-binder instance for this class. */
060    private static I_CmsInfoHeaderUiBinder uiBinder = GWT.create(I_CmsInfoHeaderUiBinder.class);
061
062    @UiField
063    protected DivElement m_additionalWidgets;
064
065    /** The button bar. */
066    @UiField
067    protected Element m_buttonBar;
068
069    /** The description element. */
070    @UiField
071    protected ParagraphElement m_description;
072
073    /** The locale cell. */
074    @UiField
075    protected SpanElement m_locale;
076
077    /** The button bar next to the path information. */
078    @UiField
079    protected FlowPanel m_pathButtons;
080
081    /** The site host element. */
082    @UiField
083    protected SpanElement m_siteHost;
084
085    /** The title element. */
086    @UiField
087    protected HeadingElement m_title;
088
089    /** The type icon element. */
090    @UiField
091    protected DivElement m_typeIcon;
092
093    /** The main panel. */
094    private HTMLPanel m_main;
095
096    /**
097     * Constructor.<p>
098     *
099     * @param title the title
100     * @param description the description
101     * @param path the path
102     * @param locale the locale
103     * @param typeIcon the type icon CSS class
104     */
105    public CmsInfoHeader(String title, String description, String path, String locale, String typeIcon) {
106
107        m_main = uiBinder.createAndBindUi(this);
108        initWidget(m_main);
109        if (CmsStringUtil.isEmptyOrWhitespaceOnly(title)) {
110            title = Messages.get().key(Messages.GUI_NO_TITLE_0);
111        }
112        m_title.setInnerText(title);
113        m_description.setInnerText(description);
114        m_siteHost.setInnerText(path);
115        m_locale.setInnerText("[" + locale + "]");
116        if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(typeIcon)) {
117            m_typeIcon.addClassName(typeIcon);
118            m_typeIcon.getStyle().setWidth(24, Unit.PX);
119            m_typeIcon.getStyle().setHeight(24, Unit.PX);
120        } else {
121            m_typeIcon.removeFromParent();
122        }
123    }
124
125    /**
126     * Adds a button to the top right of the info header.<p>
127     *
128     * @param button the button to add
129     */
130    public void addButtonTopRight(Widget button) {
131
132        m_main.add(button, m_buttonBar);
133    }
134
135    public void addWidget(Widget widget) {
136
137        m_main.add(widget, m_additionalWidgets);
138    }
139
140    /**
141     * Gets the button bar next to the path information.
142     * 
143     * @return the button bar next to the path information
144     */
145    public FlowPanel getPathButtons() {
146
147        return m_pathButtons;
148    }
149}