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.containerpage.client.ui;
029
030import org.opencms.ade.containerpage.client.Messages;
031import org.opencms.gwt.client.ui.CmsList;
032import org.opencms.gwt.client.ui.CmsListItem;
033import org.opencms.gwt.client.ui.CmsPushButton;
034import org.opencms.gwt.client.ui.CmsScrollPanel;
035
036import java.util.Iterator;
037
038import com.google.gwt.core.client.GWT;
039import com.google.gwt.event.dom.client.ClickEvent;
040import com.google.gwt.uibinder.client.UiBinder;
041import com.google.gwt.uibinder.client.UiField;
042import com.google.gwt.uibinder.client.UiHandler;
043import com.google.gwt.user.client.ui.FlowPanel;
044import com.google.gwt.user.client.ui.Widget;
045
046/**
047 * Content of the tool-bar menu favorite tab.<p>
048 *
049 * @since 8.0.0
050 */
051public class CmsFavoriteTab extends A_CmsClipboardTab {
052
053    /** The ui-binder interface for this widget. */
054    interface I_CmsFavoriteTabUiBinder extends UiBinder<Widget, CmsFavoriteTab> {
055        // GWT interface, nothing to do here
056    }
057
058    /** The ui-binder for this widget. */
059    private static I_CmsFavoriteTabUiBinder uiBinder = GWT.create(I_CmsFavoriteTabUiBinder.class);
060
061    /** Button panel shown while editing the favorites. */
062    @UiField
063    protected FlowPanel m_buttonEditingPanel;
064
065    /** Button panel shown while using the favorites. */
066    @UiField
067    protected FlowPanel m_buttonUsePanel;
068
069    /** The cancel edit button. */
070    @UiField
071    protected CmsPushButton m_cancelButton;
072
073    /** The clip-board menu. */
074    protected CmsToolbarClipboardMenu m_clipboard;
075
076    /** The edit button. */
077    @UiField
078    protected CmsPushButton m_editButton;
079
080    /** The list panel holding the favorite elements. */
081    @UiField(provided = true)
082    protected CmsList<CmsListItem> m_listPanel = new CmsList<CmsListItem>();
083
084    /** The save favorites button. */
085    @UiField
086    protected CmsPushButton m_saveButton;
087
088    /** The scroll panel. */
089    @UiField
090    protected CmsScrollPanel m_scrollPanel;
091
092    /**
093     * Constructor.<p>
094     *
095     * @param clipboard the clip-board menu
096     */
097    public CmsFavoriteTab(CmsToolbarClipboardMenu clipboard) {
098
099        initWidget(uiBinder.createAndBindUi(this));
100        m_clipboard = clipboard;
101        m_buttonEditingPanel.setVisible(false);
102        m_editButton.setText(Messages.get().key(Messages.GUI_BUTTON_EDITFAVORITES_TEXT_0));
103        m_editButton.setTitle(Messages.get().key(Messages.GUI_BUTTON_EDITFAVORITES_TEXT_0));
104        m_editButton.disable(Messages.get().key(Messages.GUI_TAB_FAVORITES_NO_ELEMENTS_0));
105        m_saveButton.setText(Messages.get().key(Messages.GUI_BUTTON_SAVE_TEXT_0));
106        m_saveButton.setTitle(Messages.get().key(Messages.GUI_BUTTON_SAVE_TEXT_0));
107        m_cancelButton.setText(Messages.get().key(Messages.GUI_BUTTON_CANCEL_TEXT_0));
108        m_cancelButton.setTitle(Messages.get().key(Messages.GUI_BUTTON_CANCEL_TEXT_0));
109        m_listPanel.setDropEnabled(true);
110    }
111
112    /**
113     * @see org.opencms.ade.containerpage.client.ui.A_CmsClipboardTab#addListItem(org.opencms.gwt.client.ui.CmsListItem)
114     */
115    @Override
116    public void addListItem(CmsListItem item) {
117
118        super.addListItem(item);
119        if (m_listPanel.getWidgetCount() > 0) {
120            m_editButton.enable();
121        }
122    }
123
124    /**
125     * @see org.opencms.ade.containerpage.client.ui.A_CmsClipboardTab#clearList()
126     */
127    @Override
128    public void clearList() {
129
130        super.clearList();
131        m_editButton.disable(Messages.get().key(Messages.GUI_TAB_FAVORITES_NO_ELEMENTS_0));
132    }
133
134    /**
135     * @see org.opencms.ade.containerpage.client.ui.A_CmsClipboardTab#getList()
136     */
137    @Override
138    public CmsList<CmsListItem> getList() {
139
140        return m_listPanel;
141    }
142
143    /**
144     * @see org.opencms.ade.containerpage.client.ui.A_CmsClipboardTab#getScrollPanel()
145     */
146    @Override
147    public CmsScrollPanel getScrollPanel() {
148
149        return m_scrollPanel;
150    }
151
152    /**
153     * Returns the favorite list item iterator.<p>
154     *
155     * @return the iterator
156     */
157    public Iterator<Widget> iterator() {
158
159        return m_listPanel.iterator();
160    }
161
162    /**
163     * Saves the favorites.<p>
164     */
165    public void saveFavorites() {
166
167        m_clipboard.saveFavorites();
168        if (m_listPanel.getWidgetCount() < 1) {
169            m_editButton.disable(Messages.get().key(Messages.GUI_TAB_FAVORITES_NO_ELEMENTS_0));
170        }
171        m_buttonEditingPanel.setVisible(false);
172        m_buttonUsePanel.setVisible(true);
173    }
174
175    /**
176     * Cancels the editing.<p>
177     *
178     * @param event the click event
179     */
180    @UiHandler("m_cancelButton")
181    void cancelAction(ClickEvent event) {
182
183        m_clipboard.reloadFavorites();
184        m_buttonEditingPanel.setVisible(false);
185        m_buttonUsePanel.setVisible(true);
186    }
187
188    /**
189     * Starts the editing.<p>
190     *
191     * @param event the click event
192     */
193    @UiHandler("m_editButton")
194    void editAction(ClickEvent event) {
195
196        m_clipboard.enableFavoritesEdit();
197        m_buttonUsePanel.setVisible(false);
198        m_buttonEditingPanel.setVisible(true);
199    }
200
201    /**
202     * Saves the favorite list.<p>
203     *
204     * @param event the click event
205     */
206    @UiHandler("m_saveButton")
207    void saveAction(ClickEvent event) {
208
209        saveFavorites();
210    }
211}