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.apps.dbmanager;
029
030import org.opencms.ui.A_CmsUI;
031import org.opencms.ui.CmsVaadinUtils;
032import org.opencms.ui.FontOpenCms;
033import org.opencms.ui.components.CmsBasicDialog;
034import org.opencms.ui.report.CmsReportWidget;
035
036import com.vaadin.ui.Button;
037import com.vaadin.ui.Button.ClickEvent;
038import com.vaadin.v7.shared.ui.label.ContentMode;
039import com.vaadin.v7.ui.HorizontalLayout;
040import com.vaadin.v7.ui.Label;
041import com.vaadin.v7.ui.VerticalLayout;
042
043/**
044 * Class for the synchronization dialog.<p>
045 */
046public class CmsDbSynchDialog extends CmsBasicDialog {
047
048    /**vaadin serial id.*/
049    private static final long serialVersionUID = -1818182416175306822L;
050
051    /**cancel button.*/
052    Button m_cancelButton;
053
054    /**Runnable for close action.*/
055    Runnable m_closeRunnable;
056
057    /**Vaadin component.*/
058    HorizontalLayout m_confirm;
059
060    /**icon. */
061    Label m_icon;
062
063    /**Ok button. */
064    Button m_okButton;
065
066    /**Vaadin component. */
067    VerticalLayout m_report;
068
069    /**
070     * public constructor.<p>
071     *
072     * @param closeRunnable gets called on cancel
073     */
074    public CmsDbSynchDialog(Runnable closeRunnable) {
075
076        CmsVaadinUtils.readAndLocalizeDesign(this, CmsVaadinUtils.getWpMessagesForCurrentLocale(), null);
077
078        m_report.setVisible(false);
079        m_closeRunnable = closeRunnable;
080
081        //Setup icon
082        m_icon.setContentMode(ContentMode.HTML);
083        m_icon.setValue(FontOpenCms.WARNING.getHtml());
084
085        m_okButton.addClickListener(new Button.ClickListener() {
086
087            private static final long serialVersionUID = 7329358907650680436L;
088
089            public void buttonClick(ClickEvent event) {
090
091                showReport();
092
093            }
094        });
095
096        m_cancelButton.addClickListener(new Button.ClickListener() {
097
098            private static final long serialVersionUID = 4143312166220501488L;
099
100            public void buttonClick(ClickEvent event) {
101
102                m_closeRunnable.run();
103
104            }
105        });
106    }
107
108    /**
109     * shows the synchronization report.<p>
110     */
111    protected void showReport() {
112
113        m_confirm.setVisible(false);
114        m_report.setVisible(true);
115        CmsSynchronizeThread thread = new CmsSynchronizeThread(A_CmsUI.getCmsObject());
116        thread.start();
117        CmsReportWidget widget = new CmsReportWidget(thread);
118        widget.setHeight("100%");
119        widget.setWidth("100%");
120        m_report.addComponent(widget);
121        m_okButton.setVisible(false);
122        m_cancelButton.setCaption(CmsVaadinUtils.getMessageText(org.opencms.ui.Messages.GUI_BUTTON_CLOSE_DIALOG_0));
123    }
124}