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.file.CmsObject; 031import org.opencms.file.CmsResource; 032import org.opencms.ui.A_CmsUI; 033import org.opencms.ui.I_CmsDialogContext; 034import org.opencms.ui.I_CmsDialogContext.ContextType; 035import org.opencms.ui.apps.CmsFileExplorer; 036import org.opencms.ui.apps.I_CmsContextProvider; 037import org.opencms.ui.apps.projects.CmsProjectManagerConfiguration; 038import org.opencms.ui.components.CmsFileTable; 039import org.opencms.ui.components.CmsFileTableDialogContext; 040import org.opencms.ui.components.OpenCmsTheme; 041import org.opencms.ui.contextmenu.I_CmsSimpleContextMenuEntry; 042 043import java.util.List; 044import java.util.Set; 045 046import com.vaadin.ui.Component; 047import com.vaadin.v7.ui.Table; 048import com.vaadin.v7.ui.Table.CellStyleGenerator; 049 050/** 051 * Result table for broken internal relations.<p> 052 */ 053public class CmsLinkValidationInternalTable extends CmsFileTable implements I_CmsUpdatableComponent { 054 055 /**vaadin serial id.*/ 056 private static final long serialVersionUID = -5023815553518761192L; 057 058 /**CmsObject. */ 059 private CmsObject m_cms; 060 061 /**Intro Component. */ 062 private Component m_introComponent; 063 064 /**Empty result component. */ 065 private Component m_nullComponent; 066 067 /** The available menu entries. */ 068 private List<I_CmsSimpleContextMenuEntry<Set<String>>> m_menuEntries; 069 070 /**Link Validator to provide validation logic. */ 071 private A_CmsLinkValidator m_linkValidator; 072 073 /** Resources to check.*/ 074 private List<String> m_resourcesToCheck; 075 076 /** 077 * Constructor for table.<p> 078 * @param introComponent Intro Component 079 * @param nullComponent null component 080 * @param linkValidator provider for validation methods 081 */ 082 public CmsLinkValidationInternalTable( 083 Component introComponent, 084 Component nullComponent, 085 A_CmsLinkValidator linkValidator) { 086 087 super(null, linkValidator.getTableProperties()); 088 applyWorkplaceAppSettings(); 089 setContextProvider(new I_CmsContextProvider() { 090 091 /** 092 * @see org.opencms.ui.apps.I_CmsContextProvider#getDialogContext() 093 */ 094 public I_CmsDialogContext getDialogContext() { 095 096 CmsFileTableDialogContext context = new CmsFileTableDialogContext( 097 CmsProjectManagerConfiguration.APP_ID, 098 ContextType.fileTable, 099 CmsLinkValidationInternalTable.this, 100 CmsLinkValidationInternalTable.this.getSelectedResources()); 101 context.setEditableProperties(CmsFileExplorer.INLINE_EDIT_PROPERTIES); 102 return context; 103 } 104 }); 105 setSizeFull(); 106 addPropertyProvider(linkValidator); 107 if (linkValidator.getClickListener() != null) { 108 CmsLinkValidationInternalTable.this.m_fileTable.addItemClickListener(linkValidator.getClickListener()); 109 addAdditionalStyleGenerator(new CellStyleGenerator() { 110 111 public String getStyle(Table source, Object itemId, Object propertyId) { 112 113 if (linkValidator.getTableProperty().equals(propertyId)) { 114 return " " + OpenCmsTheme.HOVER_COLUMN; 115 } 116 return ""; 117 } 118 }); 119 } 120 m_linkValidator = linkValidator; 121 m_introComponent = introComponent; 122 m_nullComponent = nullComponent; 123 124 } 125 126 /** 127 * @see org.opencms.ui.apps.linkvalidation.I_CmsUpdatableComponent#update(java.util.List) 128 */ 129 public void update(List<String> resourcePaths) { 130 131 m_resourcesToCheck = resourcePaths; 132 reload(); 133 134 } 135 136 /** 137 * Reloads the table.<p> 138 */ 139 void reload() { 140 141 List<CmsResource> broken = m_linkValidator.failedResources(m_resourcesToCheck); 142 143 if (broken.size() > 0) { 144 setVisible(true); 145 m_introComponent.setVisible(false); 146 m_nullComponent.setVisible(false); 147 } else { 148 setVisible(false); 149 m_introComponent.setVisible(false); 150 m_nullComponent.setVisible(true); 151 } 152 fillTable(getRootCms(), broken); 153 } 154 155 /** 156 * Creates a root- cms object.<p> 157 * 158 * @return CmsObject 159 */ 160 private CmsObject getRootCms() { 161 162 if (m_cms == null) { 163 m_cms = A_CmsUI.getCmsObject(); 164 m_cms.getRequestContext().setSiteRoot(""); 165 } 166 return m_cms; 167 } 168 169}