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.modules;
029
030import org.opencms.main.CmsLog;
031import org.opencms.main.OpenCms;
032import org.opencms.ui.components.CmsAutoItemCreatingComboBox;
033
034import java.io.File;
035import java.util.Collections;
036import java.util.List;
037
038import org.apache.commons.logging.Log;
039
040import com.google.common.collect.Lists;
041import com.vaadin.ui.Button;
042import com.vaadin.v7.data.Property.ValueChangeEvent;
043import com.vaadin.v7.data.Property.ValueChangeListener;
044import com.vaadin.v7.data.util.IndexedContainer;
045import com.vaadin.v7.ui.AbstractSelect.ItemCaptionMode;
046import com.vaadin.v7.ui.ComboBox;
047import com.vaadin.v7.ui.VerticalLayout;
048
049/**
050 * The form for importing a module from the application server.<p>
051 */
052public class CmsServerModuleImportForm extends A_CmsModuleImportForm {
053
054    /** The log instance for this class. */
055    private static final Log LOG = CmsLog.getLog(CmsServerModuleImportForm.class);
056
057    /** The Cancel button. */
058    private Button m_cancel;
059
060    /** The select box used to select the module. */
061    private ComboBox m_moduleSelect;
062
063    /** The OK button. */
064    private Button m_ok;
065
066    /** The site selector. */
067    private CmsAutoItemCreatingComboBox m_siteSelect;
068
069    /**
070     * Creates a new instance.<p>
071     *
072     * @param app the module manager app
073     */
074    public CmsServerModuleImportForm(CmsModuleApp app, VerticalLayout start, VerticalLayout report, Runnable run) {
075
076        super(app, start, report, run);
077        IndexedContainer options = new IndexedContainer();
078        options.addContainerProperty("label", String.class, "");
079        m_moduleSelect.setContainerDataSource(options);
080        m_moduleSelect.setItemCaptionMode(ItemCaptionMode.PROPERTY);
081        m_moduleSelect.setItemCaptionPropertyId("label");
082        m_moduleSelect.setNullSelectionAllowed(false);
083        String moduleDir = OpenCms.getSystemInfo().getAbsoluteRfsPathRelativeToWebInf("packages/modules");
084        File moduleDirFile = new File(moduleDir);
085        if (moduleDirFile.exists()) {
086            List<File> files = Lists.newArrayList(moduleDirFile.listFiles());
087            Collections.sort(files);
088            for (File file : files) {
089                if (file.isDirectory()) {
090                    continue;
091                }
092                String path = file.getAbsolutePath();
093                String name = file.getName();
094                options.addItem(path).getItemProperty("label").setValue(name);
095            }
096        }
097        m_moduleSelect.addValueChangeListener(new ValueChangeListener() {
098
099            public void valueChange(ValueChangeEvent event) {
100
101                String path = (String)(event.getProperty().getValue());
102                m_importFile = new CmsModuleImportFile(path);
103                m_ok.setEnabled(false);
104                validateModuleFile();
105            }
106        });
107    }
108
109    @Override
110    protected Button getCancelButton() {
111
112        return m_cancel;
113    }
114
115    @Override
116    protected Button getOkButton() {
117
118        return m_ok;
119    }
120
121    @Override
122    protected CmsAutoItemCreatingComboBox getSiteSelector() {
123
124        return m_siteSelect;
125    }
126
127}