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.ui; 029 030import org.opencms.module.CmsModule; 031import org.opencms.setup.CmsSetupBean; 032import org.opencms.setup.CmsSetupComponent; 033import org.opencms.ui.CmsVaadinUtils; 034import org.opencms.util.CmsStringUtil; 035 036import java.util.ArrayList; 037import java.util.HashMap; 038import java.util.HashSet; 039import java.util.List; 040import java.util.Map; 041import java.util.Set; 042 043import com.vaadin.ui.Button; 044import com.vaadin.ui.CheckBox; 045import com.vaadin.ui.FormLayout; 046 047/** 048 * Setup step: Selecting components (= module groups). 049 */ 050public class CmsSetupStep04Modules extends A_CmsSetupStep { 051 052 /** Serial version id. */ 053 private static final long serialVersionUID = 1L; 054 055 /** Back button. */ 056 private Button m_backButton; 057 058 /** The list of check boxes for the components. */ 059 private List<CheckBox> m_componentCheckboxes = new ArrayList<>(); 060 061 /** The map of components, with their ids as keys. */ 062 private Map<String, CmsSetupComponent> m_componentMap = new HashMap<>(); 063 064 /** Panel for components. */ 065 private FormLayout m_components; 066 067 /** The forward button. */ 068 private Button m_forwardButton; 069 070 /** 071 * Creates a new instance. 072 * 073 * @param context the setup context 074 */ 075 public CmsSetupStep04Modules(I_SetupUiContext context) { 076 077 super(context); 078 079 CmsVaadinUtils.readAndLocalizeDesign(this, null, null); 080 CmsSetupBean bean = context.getSetupBean(); 081 bean.getAvailableModules(); 082 initComponents(bean.getComponents().elementList()); 083 m_forwardButton.addClickListener(evt -> forward()); 084 m_backButton.addClickListener(evt -> m_context.stepBack()); 085 } 086 087 /** 088 * Moves to the next step. 089 */ 090 private void forward() { 091 092 Set<String> selected = new HashSet<>(); 093 094 for (CheckBox checkbox : m_componentCheckboxes) { 095 CmsSetupComponent component = (CmsSetupComponent)(checkbox.getData()); 096 if (checkbox.getValue().booleanValue()) { 097 selected.add(component.getId()); 098 } 099 } 100 String error = null; 101 for (String compId : selected) { 102 CmsSetupComponent component = m_componentMap.get(compId); 103 for (String dep : component.getDependencies()) { 104 if (!selected.contains(dep)) { 105 error = "Unfulfilled dependency: The component " 106 + component.getName() 107 + " can not be installed because its dependency " 108 + m_componentMap.get(dep).getName() 109 + " is not selected"; 110 break; 111 } 112 } 113 } 114 if (error == null) { 115 Set<String> modules = new HashSet<>(); 116 117 for (CmsSetupComponent component : m_componentMap.values()) { 118 119 if (selected.contains(component.getId())) { 120 121 for (CmsModule module : m_context.getSetupBean().getAvailableModules().values()) { 122 if (component.match(module.getName())) { 123 modules.add(module.getName()); 124 } 125 } 126 } 127 } 128 List<String> moduleList = new ArrayList<>(modules); 129 m_context.getSetupBean().setInstallModules(CmsStringUtil.listAsString(moduleList, "|")); 130 m_context.stepForward(); 131 } else { 132 CmsSetupErrorDialog.showErrorDialog(error, error); 133 } 134 } 135 136 /** 137 * Initializes the components. 138 * 139 * @param components the components 140 */ 141 private void initComponents(List<CmsSetupComponent> components) { 142 143 for (CmsSetupComponent component : components) { 144 CheckBox checkbox = new CheckBox(); 145 checkbox.setValue(component.isChecked()); 146 checkbox.setCaption(component.getName() + " - " + component.getDescription()); 147 checkbox.setDescription(component.getDescription()); 148 checkbox.setData(component); 149 checkbox.setWidth("100%"); 150 m_components.addComponent(checkbox); 151 m_componentCheckboxes.add(checkbox); 152 m_componentMap.put(component.getId(), component); 153 154 } 155 } 156 157}