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.linkvalidation;
029
030import org.opencms.main.OpenCms;
031import org.opencms.relations.CmsExternalLinksValidationResult;
032import org.opencms.ui.A_CmsUI;
033import org.opencms.ui.CmsVaadinUtils;
034import org.opencms.ui.apps.Messages;
035import org.opencms.ui.report.CmsReportWidget;
036
037import com.vaadin.v7.shared.ui.label.ContentMode;
038import com.vaadin.ui.Button;
039import com.vaadin.ui.Button.ClickEvent;
040import com.vaadin.ui.Button.ClickListener;
041import com.vaadin.ui.FormLayout;
042import com.vaadin.v7.ui.Label;
043import com.vaadin.v7.ui.VerticalLayout;
044
045/**
046 * Class for the external link validation.<p>
047 */
048public class CmsLinkValidationExternal extends VerticalLayout {
049
050    /**vaadin serial id.*/
051    private static final long serialVersionUID = 4901058101922988640L;
052
053    /**Button to start validation. */
054    private Button m_exec;
055
056    /**Label showing last report.*/
057    private Label m_oldReport;
058
059    /**Vaadin component. */
060    private FormLayout m_threadReport;
061
062    /**
063     * constructor.<p>
064     */
065    protected CmsLinkValidationExternal() {
066
067        CmsVaadinUtils.readAndLocalizeDesign(this, CmsVaadinUtils.getWpMessagesForCurrentLocale(), null);
068
069        m_oldReport.setContentMode(ContentMode.HTML);
070        m_oldReport.setHeight("500px");
071        m_oldReport.addStyleName("v-scrollable");
072        m_oldReport.addStyleName("o-report");
073
074        CmsExternalLinksValidationResult result = OpenCms.getLinkManager().getPointerLinkValidationResult();
075        if (result == null) {
076            m_oldReport.setValue(CmsVaadinUtils.getMessageText(Messages.GUI_LINKVALIDATION_NO_VALIDATION_YET_0));
077        } else {
078            m_oldReport.setValue(
079                result.toHtml(OpenCms.getWorkplaceManager().getWorkplaceLocale(A_CmsUI.getCmsObject())));
080        }
081
082        m_exec.addClickListener(new ClickListener() {
083
084            private static final long serialVersionUID = -3281073871585942686L;
085
086            public void buttonClick(ClickEvent event) {
087
088                startValidation();
089            }
090        });
091    }
092
093    /**Enables the button to start the validation.<p> */
094    void enableButton() {
095
096        m_exec.setEnabled(true);
097    }
098
099    /**Starts the validation.<p> */
100    void startValidation() {
101
102        m_oldReport.setVisible(false);
103        m_threadReport.removeAllComponents();
104        CmsExternalLinksValidatorThread thread = new CmsExternalLinksValidatorThread(
105            A_CmsUI.getCmsObject(),
106            new Runnable() {
107
108                public void run() {
109
110                    enableButton();
111                }
112
113            });
114        thread.start();
115        CmsReportWidget reportWidget = new CmsReportWidget(thread);
116        reportWidget.setHeight("500px");
117        m_threadReport.addComponent(reportWidget);
118        m_exec.setEnabled(false);
119    }
120}