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.setup.comptest.CmsSetupTestResult; 031import org.opencms.setup.comptest.CmsSetupTests; 032import org.opencms.ui.CmsVaadinUtils; 033 034import java.util.List; 035 036import com.vaadin.ui.Button; 037import com.vaadin.ui.CheckBox; 038import com.vaadin.ui.Component; 039import com.vaadin.ui.Label; 040import com.vaadin.ui.VerticalLayout; 041 042/** 043 * Setup step: component check. 044 */ 045public class CmsSetupStep02ComponentCheck extends A_CmsSetupStep { 046 047 /** Test status enum. */ 048 enum TestColor { 049 /** Green. */ 050 green, 051 052 /** Red. */ 053 red, 054 055 /** Yellow. */ 056 yellow; 057 } 058 059 /** Message for green status. */ 060 public static final String STATUS_GREEN = "Your system uses components which have been tested to work properly with Alkacon OpenCms."; 061 062 /** Message for red status. */ 063 public static final String STATUS_RED = "Your system does not have the necessary components to use Alkacon OpenCms. It is assumed that OpenCms will not run on your system."; 064 065 /** Message for yellow status. */ 066 public static final String STATUS_YELLOW = "Your system uses components which have not been tested to work with Alkacon OpenCms. It is possible that OpenCms will not run on your system."; 067 068 /** Back button. */ 069 private Button m_backButton; 070 071 /** Confirmation checkbox. */ 072 private CheckBox m_confirmCheckbox; 073 074 /** Container for test failure notes. */ 075 private VerticalLayout m_failures; 076 077 /** Forward button. */ 078 private Button m_forwardButton; 079 080 /** Main layout. */ 081 private VerticalLayout m_mainLayout; 082 083 /** Status label.*/ 084 private Label m_status; 085 086 /** Container for test results. */ 087 private VerticalLayout m_testContainer; 088 089 /** 090 * Creates a new instance. 091 * 092 * @param context the context 093 */ 094 public CmsSetupStep02ComponentCheck(I_SetupUiContext context) { 095 096 super(context); 097 098 CmsVaadinUtils.readAndLocalizeDesign(this, null, null); 099 //m_icon.setContentMode(ContentMode.HTML); 100 CmsSetupTests tests = new CmsSetupTests(); 101 tests.runTests(context.getSetupBean()); 102 TestColor color = null; 103 color = TestColor.green; 104 if (tests.isRed()) { 105 color = TestColor.red; 106 } else if (tests.isYellow()) { 107 color = TestColor.yellow; 108 } else if (tests.isRed()) { 109 color = TestColor.red; 110 } 111 m_confirmCheckbox.addValueChangeListener(evt -> m_forwardButton.setEnabled(evt.getValue().booleanValue())); 112 updateColor(color); 113 showTestResults(tests.getTestResults()); 114 m_forwardButton.addClickListener(evt -> m_context.stepForward()); 115 m_backButton.addClickListener(evt -> m_context.stepBack()); 116 } 117 118 /** 119 * Sets test status. 120 */ 121 public void updateColor(TestColor color) { 122 123 switch (color) { 124 case green: 125 m_forwardButton.setEnabled(true); 126 m_confirmCheckbox.setVisible(false); 127 m_status.setValue(STATUS_GREEN); 128 break; 129 case yellow: 130 m_forwardButton.setEnabled(false); 131 m_confirmCheckbox.setVisible(true); 132 m_status.setValue(STATUS_YELLOW); 133 break; 134 case red: 135 m_forwardButton.setEnabled(false); 136 m_confirmCheckbox.setVisible(true); 137 m_status.setValue(STATUS_RED); 138 break; 139 default: 140 break; 141 } 142 } 143 144 /** 145 * Displays setup test results. 146 * 147 * @param testResults the test results 148 */ 149 private void showTestResults(List<CmsSetupTestResult> testResults) { 150 151 m_testContainer.removeAllComponents(); 152 VerticalLayout layout = new VerticalLayout(); 153 for (CmsSetupTestResult result : testResults) { 154 Component resultWidget = new CmsSetupTestResultWidget(result); 155 m_testContainer.addComponent(resultWidget); 156 if (!result.isGreen()) { 157 Label label = new Label(result.getInfo()); 158 label.setWidth("100%"); 159 m_failures.addComponent(label); 160 } 161 } 162 } 163 164}