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.replace;
029
030import org.opencms.gwt.client.ui.CmsLoadingAnimation;
031import org.opencms.gwt.client.ui.FontOpenCms;
032import org.opencms.gwt.client.ui.css.I_CmsConstantsBundle;
033import org.opencms.gwt.client.ui.css.I_CmsLayoutBundle;
034
035import com.google.gwt.core.client.GWT;
036import com.google.gwt.uibinder.client.UiBinder;
037import com.google.gwt.uibinder.client.UiField;
038import com.google.gwt.user.client.ui.Composite;
039import com.google.gwt.user.client.ui.FlowPanel;
040import com.google.gwt.user.client.ui.HTML;
041import com.google.gwt.user.client.ui.Widget;
042
043/**
044 * The replace dialog content widget.<p>
045 */
046public class CmsReplaceContentWidget extends Composite {
047
048    /** The UiBinder interface for this widget. */
049    interface I_CmsReplaceContentWidgetUiBinder extends UiBinder<FlowPanel, CmsReplaceContentWidget> {
050        // nothing to do
051    }
052
053    /** The UiBinder for this widget. */
054    private static I_CmsReplaceContentWidgetUiBinder uiBinder = GWT.create(I_CmsReplaceContentWidgetUiBinder.class);
055
056    /** The dialog content container. */
057    @UiField
058    protected FlowPanel m_container;
059
060    /** The dialog info widget. */
061    @UiField
062    protected HTML m_dialogInfo;
063
064    /** The loading panel. */
065    private FlowPanel m_loadingPanel;
066
067    /** The main panel. */
068    private FlowPanel m_mainPanel;
069
070    /** The replace info widget. */
071    private Widget m_replaceInfo;
072
073    /**
074     * Constructor.<p>
075     */
076    public CmsReplaceContentWidget() {
077
078        m_mainPanel = uiBinder.createAndBindUi(this);
079        initWidget(m_mainPanel);
080    }
081
082    /**
083     * Sets the dialog info message.<p>
084     *
085     * @param msg the message to display
086     * @param warning signals whether the message should be a warning or nor
087     */
088    public void displayDialogInfo(String msg, boolean warning) {
089
090        StringBuffer buffer = new StringBuffer(64);
091        if (!warning) {
092            buffer.append("<p class=\"");
093            buffer.append(I_CmsLayoutBundle.INSTANCE.uploadButton().dialogMessage());
094            buffer.append("\">");
095            buffer.append(msg);
096            buffer.append("</p>");
097        } else {
098            buffer.append(FontOpenCms.WARNING.getHtml(32, I_CmsConstantsBundle.INSTANCE.css().colorWarning()));
099            buffer.append("<p class=\"");
100            buffer.append(I_CmsLayoutBundle.INSTANCE.uploadButton().warningMessage());
101            buffer.append("\">");
102            buffer.append(msg);
103            buffer.append("</p>");
104        }
105        m_dialogInfo.setHTML(buffer.toString());
106    }
107
108    /**
109     * Removes the loading animation.<p>
110     */
111    public void removeLoadingAnimation() {
112
113        if (m_loadingPanel != null) {
114            m_loadingPanel.removeFromParent();
115            m_loadingPanel = null;
116        }
117    }
118
119    /**
120     * Sets the container widget content.<p>
121     *
122     * @param widget the container content
123     */
124    public void setContainerWidget(Widget widget) {
125
126        m_container.clear();
127        m_container.add(widget);
128    }
129
130    /**
131     * Sets the replace info widget.<p>
132     *
133     * @param replaceInfo the replace info widget
134     */
135    public void setReplaceInfo(Widget replaceInfo) {
136
137        if (m_replaceInfo != null) {
138            m_replaceInfo.removeFromParent();
139        }
140        m_replaceInfo = replaceInfo;
141        m_mainPanel.insert(m_replaceInfo, 0);
142    }
143
144    /**
145     * Creates the loading animation HTML and adds is to the content wrapper.<p>
146     *
147     * @param msg the message to display below the animation
148     */
149    public void showLoadingAnimation(String msg) {
150
151        removeLoadingAnimation();
152        m_loadingPanel = new FlowPanel();
153        m_loadingPanel.addStyleName(I_CmsLayoutBundle.INSTANCE.uploadButton().loadingPanel());
154        m_loadingPanel.addStyleName(org.opencms.gwt.client.ui.css.I_CmsLayoutBundle.INSTANCE.generalCss().cornerAll());
155
156        CmsLoadingAnimation animationDiv = new CmsLoadingAnimation();
157        animationDiv.addStyleName(I_CmsLayoutBundle.INSTANCE.uploadButton().loadingAnimation());
158        m_loadingPanel.add(animationDiv);
159
160        HTML messageDiv = new HTML();
161        messageDiv.addStyleName(I_CmsLayoutBundle.INSTANCE.uploadButton().loadingText());
162        messageDiv.setHTML(msg);
163        m_loadingPanel.add(messageDiv);
164
165        m_container.add(m_loadingPanel);
166    }
167}