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.ade.sitemap.client.toolbar;
029
030import org.opencms.ade.sitemap.client.Messages;
031import org.opencms.ade.sitemap.client.ui.css.I_CmsSitemapLayoutBundle;
032import org.opencms.gwt.client.ui.CmsList;
033import org.opencms.gwt.client.ui.CmsPushButton;
034import org.opencms.gwt.client.ui.CmsScrollPanel;
035import org.opencms.gwt.client.ui.I_CmsListItem;
036import org.opencms.gwt.client.ui.I_CmsTruncable;
037
038import com.google.gwt.core.shared.GWT;
039import com.google.gwt.event.dom.client.ClickHandler;
040import com.google.gwt.user.client.ui.Composite;
041import com.google.gwt.user.client.ui.FlowPanel;
042
043/**
044 * Tab widget to display a CmsList.<p>
045 */
046public class CmsListTab extends Composite implements I_CmsTruncable {
047
048    /** Text metrics key for truncation. */
049    public static final String TM_LITST_MENU = "TM_LITST_MENU";
050
051    /** The optional clear list button. */
052    private CmsPushButton m_clearButton;
053
054    /** The list. */
055    private CmsList<? extends I_CmsListItem> m_list;
056
057    /** The main panel. */
058    private FlowPanel m_panel;
059
060    /** The scroll panel. */
061    private CmsScrollPanel m_scrollPanel;
062
063    /**
064     * Constructor.<p>
065     *
066     * @param list the list
067     */
068    public CmsListTab(CmsList<? extends I_CmsListItem> list) {
069
070        m_list = list;
071        m_panel = new FlowPanel();
072        initWidget(m_panel);
073        setStyleName(org.opencms.gwt.client.ui.css.I_CmsLayoutBundle.INSTANCE.tabbedPanelCss().tabPanel());
074        m_scrollPanel = GWT.create(CmsScrollPanel.class);
075        m_scrollPanel.addStyleName(
076            org.opencms.gwt.client.ui.css.I_CmsLayoutBundle.INSTANCE.generalCss().buttonCornerAll());
077        m_scrollPanel.addStyleName(I_CmsSitemapLayoutBundle.INSTANCE.clipboardCss().clipboardList());
078        m_panel.add(m_scrollPanel);
079        m_scrollPanel.add(m_list);
080    }
081
082    /**
083     * Adds a clear list button to the tab.<p>
084     *
085     * @param clickHandler the button click handler
086     */
087    public void addClearListButton(ClickHandler clickHandler) {
088
089        m_clearButton = new CmsPushButton();
090        m_clearButton.setText(Messages.get().key(Messages.GUI_CLIPBOARD_CLEAR_LIST_0));
091        m_clearButton.setTitle(Messages.get().key(Messages.GUI_CLIPBOARD_CLEAR_LIST_0));
092        m_clearButton.addClickHandler(clickHandler);
093        m_clearButton.addStyleName(I_CmsSitemapLayoutBundle.INSTANCE.clipboardCss().listClearButton());
094        m_panel.add(m_clearButton);
095    }
096
097    /**
098     * Returns the required height.<p>
099     *
100     * @return the height
101     */
102    public int getRequiredHeight() {
103
104        return m_list.getElement().getClientHeight() + 12;
105    }
106
107    /**
108     * Returns the scroll panel.<p>
109     *
110     * @return the scroll panel
111     */
112    public CmsScrollPanel getScrollPanel() {
113
114        return m_scrollPanel;
115    }
116
117    /**
118     * Sets the clear list button enabled.<p>
119     *
120     * @param enabled <code>true</code> to enable the button
121     */
122    public void setClearButtonEnabled(boolean enabled) {
123
124        if (enabled) {
125            m_clearButton.enable();
126        } else {
127            m_clearButton.disable(Messages.get().key(Messages.GUI_DISABLE_CLEAR_LIST_0));
128        }
129    }
130
131    /**
132     * @see org.opencms.gwt.client.ui.I_CmsTruncable#truncate(java.lang.String, int)
133     */
134    public void truncate(String textMetricsKey, int clientWidth) {
135
136        m_list.truncate(TM_LITST_MENU, clientWidth);
137    }
138}