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.setup.updater.dialogs;
029
030import org.opencms.setup.CmsUpdateUI;
031import org.opencms.setup.ui.CmsSetupErrorDialog;
032import org.opencms.setup.xml.CmsXmlConfigUpdater;
033import org.opencms.ui.CmsVaadinUtils;
034import org.opencms.ui.FontOpenCms;
035
036import com.vaadin.server.FontAwesome;
037import com.vaadin.v7.data.Validator;
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.PasswordField;
042import com.vaadin.v7.ui.TextField;
043
044/**
045 * Settings dialog.<p>
046 */
047public class CmsUpdateStep04SettingsDialog extends A_CmsUpdateDialog {
048
049    /**Validator for admin data. */
050    class UserValidator implements Validator {
051
052        private static final long serialVersionUID = 1L;
053
054        public void validate(Object value) throws InvalidValueException {
055
056            if (m_ui.getUpdateBean().isValidUser()) {
057                return;
058            }
059            throw new InvalidValueException("The entered user / password is not correct");
060        }
061
062    }
063
064    /**Vaddin serial id. */
065    private static final long serialVersionUID = 1L;
066
067    /**vaadin component. */
068    private Label m_errorMessage;
069
070    /**vaadin component. */
071    private Label m_icon;
072
073    /**vaadin component. */
074    private TextField m_adminUser;
075
076    /**vaadin component. */
077    private PasswordField m_adminPassword;
078
079    /**vaadin component. */
080    private TextField m_siteRoot;
081
082    /**vaadin component. */
083    private TextField m_appRoot;
084
085    /**vaadin component. */
086    private TextField m_configFolder;
087
088    /**vaadin component. */
089    private HorizontalLayout m_beforeRun;
090
091    /**vaadin component. */
092    private Label m_icon0;
093
094    /**
095     * @see org.opencms.setup.updater.dialogs.A_CmsUpdateDialog#init(org.opencms.setup.CmsUpdateUI)
096     */
097    @Override
098    public boolean init(CmsUpdateUI ui) {
099
100        CmsVaadinUtils.readAndLocalizeDesign(this, null, null);
101        super.init(ui, true, true);
102        setCaption("OpenCms Update-Wizard - Settings");
103        m_icon.setContentMode(ContentMode.HTML);
104        m_icon.setValue(FontOpenCms.WARNING.getHtml());
105
106        m_adminUser.setValue(ui.getUpdateBean().getAdminUser());
107        m_adminPassword.setValue(ui.getUpdateBean().getAdminPwd());
108        m_siteRoot.setValue(ui.getUpdateBean().getUpdateSite());
109        m_appRoot.setValue(ui.getUpdateBean().getWebAppRfsPath());
110        m_configFolder.setValue(ui.getUpdateBean().getConfigRfsPath());
111        m_icon0.setContentMode(ContentMode.HTML);
112        m_icon0.setValue(FontAwesome.WRENCH.getHtml());
113        return true;
114    }
115
116    /**
117     * @see org.opencms.setup.updater.dialogs.A_CmsUpdateDialog#submitDialog()
118     */
119    @Override
120    protected boolean submitDialog() {
121
122        m_ui.getUpdateBean().setAdminPwd(m_adminPassword.getValue());
123        m_ui.getUpdateBean().setAdminUser(m_adminUser.getValue());
124        m_ui.getUpdateBean().setUpdateSite(m_siteRoot.getValue());
125
126        CmsXmlConfigUpdater configUpdater = m_ui.getUpdateBean().getXmlConfigUpdater();
127        if (!configUpdater.isDone()) {
128            try {
129                configUpdater.transformConfig();
130                m_adminPassword.removeAllValidators();
131                m_adminPassword.addValidator(new UserValidator());
132            } catch (Exception e) {
133                CmsSetupErrorDialog.showErrorDialog("Unable to transform configs", e);
134                return false;
135            }
136        } else {
137            m_adminPassword.removeAllValidators();
138            m_adminPassword.addValidator(new UserValidator());
139        }
140
141        return m_adminPassword.isValid();
142    }
143
144    /**
145     * @see org.opencms.setup.updater.dialogs.A_CmsUpdateDialog#getNextDialog()
146     */
147    @Override
148    A_CmsUpdateDialog getNextDialog() {
149
150        return new CmsUpdateStep05Modules();
151    }
152
153    /**
154     * @see org.opencms.setup.updater.dialogs.A_CmsUpdateDialog#getPreviousDialog()
155     */
156    @Override
157    A_CmsUpdateDialog getPreviousDialog() {
158
159        return new CmsUpdateStep01LicenseDialog();
160    }
161}