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.db.CmsVaadinUpdateDBThread; 032import org.opencms.ui.CmsVaadinUtils; 033import org.opencms.ui.report.CmsStreamReportWidget; 034 035import java.io.FileNotFoundException; 036import java.io.FileOutputStream; 037import java.io.IOException; 038import java.io.OutputStream; 039 040import com.vaadin.server.FontAwesome; 041import com.vaadin.ui.Panel; 042import com.vaadin.v7.shared.ui.label.ContentMode; 043import com.vaadin.v7.ui.HorizontalLayout; 044import com.vaadin.v7.ui.Label; 045import com.vaadin.v7.ui.VerticalLayout; 046 047/** 048 * DB Update thread dialog.<p> 049 */ 050public class CmsUpdateStep03DBThreadDialog extends A_CmsUpdateDialog { 051 052 /**vaadin serial id. */ 053 private static final long serialVersionUID = 1L; 054 055 /**Vaadin component. */ 056 private Panel m_reportPanel; 057 058 /**Vaadin component. */ 059 private Label m_icon; 060 061 /**Vaadin component. */ 062 private Label m_iconFin; 063 064 /**Vaadin component. */ 065 private HorizontalLayout m_running; 066 067 /**Vaadin component. */ 068 private HorizontalLayout m_finished; 069 070 /** 071 * @see org.opencms.setup.updater.dialogs.A_CmsUpdateDialog#init(org.opencms.setup.CmsUpdateUI) 072 */ 073 @Override 074 public boolean init(CmsUpdateUI ui) { 075 076 CmsVaadinUtils.readAndLocalizeDesign(this, null, null); 077 super.init(ui, false, true); 078 079 setCaption("OpenCms Update-Wizard - Update database"); 080 m_icon.setContentMode(ContentMode.HTML); 081 m_icon.setValue(FontAwesome.CLOCK_O.getHtml()); 082 m_iconFin.setContentMode(ContentMode.HTML); 083 m_iconFin.setValue(FontAwesome.CHECK_CIRCLE_O.getHtml()); 084 m_finished.setVisible(false); 085 m_reportPanel.setContent(getReportContent()); 086 return true; 087 } 088 089 /** 090 * @see org.opencms.setup.updater.dialogs.A_CmsUpdateDialog#getNextDialog() 091 */ 092 @Override 093 A_CmsUpdateDialog getNextDialog() { 094 095 return new CmsUpdateStep04SettingsDialog(); 096 } 097 098 /** 099 * @see org.opencms.setup.updater.dialogs.A_CmsUpdateDialog#getPreviousDialog() 100 */ 101 @Override 102 A_CmsUpdateDialog getPreviousDialog() { 103 104 return null; 105 } 106 107 /** 108 * Gets the content.<p> 109 * 110 * @return VerticalLayout 111 */ 112 private VerticalLayout getReportContent() { 113 114 VerticalLayout layout = new VerticalLayout(); 115 layout.setHeight("100%"); 116 final CmsStreamReportWidget report = new CmsStreamReportWidget(); 117 report.setWidth("100%"); 118 report.setHeight("100%"); 119 enableOK(false); 120 Thread thread = new CmsVaadinUpdateDBThread(m_ui.getUpdateBean(), report); 121 thread.start(); 122 try { 123 OutputStream logStream = new FileOutputStream(m_ui.getUpdateBean().getLogName()); 124 report.setDelegateStream(logStream); 125 report.addReportFinishedHandler(() -> { 126 127 try { 128 logStream.close(); 129 report.getStream().close(); 130 enableOK(true); 131 m_finished.setVisible(true); 132 m_running.setVisible(false); 133 } catch (IOException e) { 134 // 135 } 136 }); 137 138 } catch (FileNotFoundException e1) { 139 // 140 } 141 layout.addComponent(report); 142 return layout; 143 } 144 145}