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.ui.components;
029
030import org.opencms.ui.A_CmsUI;
031import org.opencms.ui.CmsVaadinUtils;
032import org.opencms.ui.FontOpenCms;
033import org.opencms.ui.I_CmsDialogContext;
034import org.opencms.ui.I_CmsUpdateListener;
035import org.opencms.ui.apps.CmsAppWorkplaceUi;
036import org.opencms.ui.apps.I_CmsAppUIContext;
037import org.opencms.ui.apps.Messages;
038import org.opencms.ui.components.extensions.CmsGwtDialogExtension;
039
040import java.util.HashMap;
041import java.util.Map;
042
043import com.vaadin.server.Page.BrowserWindowResizeEvent;
044import com.vaadin.server.Page.BrowserWindowResizeListener;
045import com.vaadin.server.Responsive;
046import com.vaadin.ui.Button;
047import com.vaadin.ui.Button.ClickEvent;
048import com.vaadin.ui.Button.ClickListener;
049import com.vaadin.ui.Component;
050import com.vaadin.ui.CssLayout;
051import com.vaadin.ui.declarative.Design;
052
053/**
054 * The layout used within the app view.<p>
055 */
056public class CmsAppViewLayout extends CssLayout implements I_CmsAppUIContext, BrowserWindowResizeListener {
057
058    /** The serial version id. */
059    private static final long serialVersionUID = -290796815149968830L;
060
061    /** The app area. */
062    private CssLayout m_appArea;
063
064    /** The app id. */
065    private String m_appId;
066
067    private Map<String, Object> m_attributes = new HashMap<>();
068
069    /** The info area grid. */
070    private CssLayout m_infoArea;
071
072    /** The toolbar. */
073    private CmsToolBar m_toolbar;
074
075    /**
076     * Constructor.<p>
077     *
078     * @param appId the app id
079     */
080    public CmsAppViewLayout(String appId) {
081
082        m_appId = appId;
083        Design.read("CmsAppView.html", this);
084        Responsive.makeResponsive(this);
085        // setting the width to 100% within the java code is required by the responsive resize listeners
086        setWidth("100%");
087        m_toolbar.init(m_appId, this);
088    }
089
090    /**
091     * Creates the publish button.
092     *
093     * @param updateListener the update listener
094     * @return the publish button
095     */
096    public static Button createPublishButton(final I_CmsUpdateListener<String> updateListener) {
097
098        Button publishButton = CmsToolBar.createButton(
099            FontOpenCms.PUBLISH,
100            CmsVaadinUtils.getMessageText(Messages.GUI_PUBLISH_BUTTON_TITLE_0));
101        if (CmsAppWorkplaceUi.isOnlineProject()) {
102            // disable publishing in online project
103            publishButton.setEnabled(false);
104            publishButton.setDescription(CmsVaadinUtils.getMessageText(Messages.GUI_TOOLBAR_NOT_AVAILABLE_ONLINE_0));
105        }
106        publishButton.addClickListener(new ClickListener() {
107
108            /** Serial version id. */
109            private static final long serialVersionUID = 1L;
110
111            public void buttonClick(ClickEvent event) {
112
113                CmsAppWorkplaceUi.get().disableGlobalShortcuts();
114                CmsGwtDialogExtension extension = new CmsGwtDialogExtension(A_CmsUI.get(), updateListener);
115                extension.openPublishDialog();
116            }
117        });
118        return publishButton;
119    }
120
121    /**
122     * @see org.opencms.ui.apps.I_CmsAppUIContext#addPublishButton(org.opencms.ui.I_CmsUpdateListener)
123     */
124    public Button addPublishButton(final I_CmsUpdateListener<String> updateListener) {
125
126        Button publishButton = createPublishButton(updateListener);
127
128        addToolbarButton(publishButton);
129        return publishButton;
130    }
131
132    /**
133     * @see org.opencms.ui.apps.I_CmsAppUIContext#addToolbarButton(com.vaadin.ui.Component)
134     */
135    public void addToolbarButton(Component button) {
136
137        m_toolbar.addButtonLeft(button);
138    }
139
140    /**
141     * @see org.opencms.ui.apps.I_CmsAppUIContext#addToolbarButtonRight(com.vaadin.ui.Component)
142     */
143    public void addToolbarButtonRight(Component button) {
144
145        m_toolbar.addButtonRight(button);
146    }
147
148    /**
149     * @see com.vaadin.server.Page.BrowserWindowResizeListener#browserWindowResized(com.vaadin.server.Page.BrowserWindowResizeEvent)
150     */
151    public void browserWindowResized(BrowserWindowResizeEvent event) {
152
153        m_toolbar.browserWindowResized(event);
154    }
155
156    /**
157     * @see org.opencms.ui.apps.I_CmsAppUIContext#clearToolbarButtons()
158     */
159    public void clearToolbarButtons() {
160
161        m_toolbar.clearButtonsLeft();
162    }
163
164    /**
165     * Closes the toolbar popup views.<p>
166     */
167    public void closePopupViews() {
168
169        m_toolbar.closePopupViews();
170    }
171
172    /**
173     * @see org.opencms.ui.apps.I_CmsAppUIContext#enableDefaultToolbarButtons(boolean)
174     */
175    public void enableDefaultToolbarButtons(boolean enabled) {
176
177        m_toolbar.enableDefaultButtons(enabled);
178    }
179
180    /**
181     * @see org.opencms.ui.apps.I_CmsAppUIContext#getAppId()
182     */
183    public String getAppId() {
184
185        return m_appId;
186    }
187
188    /**
189     * @see org.opencms.ui.apps.I_CmsAppUIContext#getAttribute(java.lang.String)
190     */
191    public Object getAttribute(String key) {
192
193        return m_attributes.get(key);
194    }
195
196    /**
197     * @see org.opencms.ui.apps.I_CmsAppUIContext#hideToolbar()
198     */
199    public void hideToolbar() {
200
201        addStyleName(OpenCmsTheme.HIDDEN_TOOLBAR);
202        m_toolbar.setVisible(false);
203    }
204
205    /**
206     * @see org.opencms.ui.apps.I_CmsAppUIContext#removeToolbarButton(com.vaadin.ui.Component)
207     */
208    public void removeToolbarButton(Component button) {
209
210        m_toolbar.removeButton(button);
211    }
212
213    /**
214     * Sets the app content component.<p>
215     *
216     * @param appContent the app content
217     */
218    public void setAppContent(Component appContent) {
219
220        m_appArea.removeAllComponents();
221        if (appContent != null) {
222            m_appArea.addComponent(appContent);
223        }
224    }
225
226    /**
227     * @see org.opencms.ui.apps.I_CmsAppUIContext#setAppInfo(com.vaadin.ui.Component)
228     */
229    public void setAppInfo(Component infoContent) {
230
231        m_infoArea.removeAllComponents();
232        m_infoArea.addComponent(infoContent);
233    }
234
235    /**
236     * @see org.opencms.ui.apps.I_CmsAppUIContext#setAppTitle(java.lang.String)
237     */
238    public void setAppTitle(String title) {
239
240        CmsAppWorkplaceUi.setWindowTitle(title);
241        m_toolbar.setAppTitle(title);
242    }
243
244    /**
245     * @see org.opencms.ui.apps.I_CmsAppUIContext#setAttribute(java.lang.String, java.lang.Object)
246     */
247    public void setAttribute(String key, Object value) {
248
249        m_attributes.put(key, value);
250
251    }
252
253    /**
254     * @see org.opencms.ui.apps.I_CmsAppUIContext#setMenuDialogContext(org.opencms.ui.I_CmsDialogContext)
255     */
256    public void setMenuDialogContext(I_CmsDialogContext context) {
257
258        m_toolbar.setDialogContext(context);
259    }
260
261    /**
262     * @see org.opencms.ui.apps.I_CmsAppUIContext#showInfoArea(boolean)
263     */
264    public void showInfoArea(boolean show) {
265
266        m_infoArea.setVisible(show);
267    }
268
269    /**
270     * @see org.opencms.ui.apps.I_CmsAppUIContext#showToolbar()
271     */
272    public void showToolbar() {
273
274        removeStyleName(OpenCmsTheme.HIDDEN_TOOLBAR);
275        m_toolbar.setVisible(false);
276    }
277
278    /**
279     * @see org.opencms.ui.apps.I_CmsAppUIContext#updateOnChange()
280     */
281    public void updateOnChange() {
282
283        m_toolbar.updateAppIndicator();
284    }
285
286    /**
287     * @see org.opencms.ui.apps.I_CmsAppUIContext#updateUserInfo()
288     */
289    public void updateUserInfo() {
290
291        m_toolbar.refreshUserInfoDropDown();
292    }
293}