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.projects; 029 030import org.opencms.file.CmsObject; 031import org.opencms.file.history.CmsHistoryProject; 032import org.opencms.main.CmsException; 033import org.opencms.main.OpenCms; 034import org.opencms.ui.A_CmsUI; 035import org.opencms.ui.CmsVaadinUtils; 036import org.opencms.ui.apps.Messages; 037import org.opencms.util.CmsUUID; 038 039import java.util.Date; 040import java.util.List; 041import java.util.Locale; 042 043import com.vaadin.v7.data.Item; 044import com.vaadin.v7.data.util.IndexedContainer; 045import com.vaadin.v7.shared.ui.label.ContentMode; 046import com.vaadin.v7.ui.Label; 047import com.vaadin.v7.ui.Table; 048import com.vaadin.ui.UI; 049 050/** 051 * The project history table.<p> 052 */ 053public class CmsProjectHistoryTable extends Table { 054 055 /** The serial version id. */ 056 private static final long serialVersionUID = 7343623156086839992L; 057 058 /** Publish date property. */ 059 public static final String PROP_PUBLISH_DATE = "publishDate"; 060 061 /** Publish user property. */ 062 public static final String PROP_PUBLISH_USER = "publishUser"; 063 064 /** The data container. */ 065 IndexedContainer m_container; 066 067 /** The project manager instance. */ 068 CmsProjectManager m_manager; 069 070 /** 071 * Constructor.<p> 072 */ 073 public CmsProjectHistoryTable() { 074 setSizeFull(); 075 m_container = new IndexedContainer(); 076 m_container.addContainerProperty(CmsProjectsTable.PROP_ID, CmsUUID.class, null); 077 m_container.addContainerProperty(CmsProjectsTable.PROP_NAME, String.class, ""); 078 m_container.addContainerProperty(CmsProjectsTable.PROP_DESCRIPTION, String.class, ""); 079 m_container.addContainerProperty(PROP_PUBLISH_DATE, Date.class, ""); 080 m_container.addContainerProperty(PROP_PUBLISH_USER, String.class, ""); 081 m_container.addContainerProperty(CmsProjectsTable.PROP_ORG_UNIT, String.class, ""); 082 m_container.addContainerProperty(CmsProjectsTable.PROP_OWNER, String.class, ""); 083 m_container.addContainerProperty(CmsProjectsTable.PROP_MANAGER, String.class, ""); 084 m_container.addContainerProperty(CmsProjectsTable.PROP_USER, String.class, ""); 085 m_container.addContainerProperty(CmsProjectsTable.PROP_DATE_CREATED, Date.class, ""); 086 m_container.addContainerProperty(CmsProjectsTable.PROP_RESOURCES, Label.class, ""); 087 088 setContainerDataSource(m_container); 089 setColumnHeader(CmsProjectsTable.PROP_NAME, CmsVaadinUtils.getMessageText(Messages.GUI_PROJECTS_NAME_0)); 090 setColumnHeader( 091 CmsProjectsTable.PROP_DESCRIPTION, 092 CmsVaadinUtils.getMessageText(Messages.GUI_PROJECTS_DESCRIPTION_0)); 093 setColumnHeader(PROP_PUBLISH_DATE, CmsVaadinUtils.getMessageText(Messages.GUI_PROJECTS_PUBLISH_DATE_0)); 094 setColumnHeader(PROP_PUBLISH_USER, CmsVaadinUtils.getMessageText(Messages.GUI_PROJECTS_PUBLISHED_BY_0)); 095 setColumnHeader( 096 CmsProjectsTable.PROP_ORG_UNIT, 097 CmsVaadinUtils.getMessageText(Messages.GUI_PROJECTS_ORG_UNIT_0)); 098 setColumnHeader(CmsProjectsTable.PROP_OWNER, CmsVaadinUtils.getMessageText(Messages.GUI_PROJECTS_OWNER_0)); 099 setColumnHeader( 100 CmsProjectsTable.PROP_MANAGER, 101 CmsVaadinUtils.getMessageText(Messages.GUI_PROJECTS_MANAGER_GROUP_0)); 102 setColumnHeader(CmsProjectsTable.PROP_USER, CmsVaadinUtils.getMessageText(Messages.GUI_PROJECTS_USER_GROUP_0)); 103 setColumnHeader( 104 CmsProjectsTable.PROP_DATE_CREATED, 105 CmsVaadinUtils.getMessageText(Messages.GUI_PROJECTS_DATE_CREATED_0)); 106 setColumnHeader( 107 CmsProjectsTable.PROP_RESOURCES, 108 CmsVaadinUtils.getMessageText(Messages.GUI_PROJECTS_RESOURCES_0)); 109 110 setSelectable(true); 111 setMultiSelect(true); 112 loadProjects(); 113 } 114 115 /** 116 * Loads the projects table.<p> 117 */ 118 public void loadProjects() { 119 120 CmsObject cms = A_CmsUI.getCmsObject(); 121 Locale locale = UI.getCurrent().getLocale(); 122 m_container.removeAllItems(); 123 boolean isMultiOU = false; 124 // hide ou column if only one ou exists 125 try { 126 isMultiOU = !OpenCms.getOrgUnitManager().getOrganizationalUnits(cms, "", true).isEmpty(); 127 } catch (CmsException e) { 128 // noop 129 } 130 if (isMultiOU) { 131 setVisibleColumns( 132 CmsProjectsTable.PROP_NAME, 133 CmsProjectsTable.PROP_DESCRIPTION, 134 PROP_PUBLISH_DATE, 135 PROP_PUBLISH_USER, 136 CmsProjectsTable.PROP_ORG_UNIT, 137 CmsProjectsTable.PROP_OWNER, 138 CmsProjectsTable.PROP_MANAGER, 139 CmsProjectsTable.PROP_USER, 140 CmsProjectsTable.PROP_DATE_CREATED, 141 CmsProjectsTable.PROP_RESOURCES); 142 } else { 143 setVisibleColumns( 144 CmsProjectsTable.PROP_NAME, 145 CmsProjectsTable.PROP_DESCRIPTION, 146 PROP_PUBLISH_DATE, 147 PROP_PUBLISH_USER, 148 CmsProjectsTable.PROP_OWNER, 149 CmsProjectsTable.PROP_MANAGER, 150 CmsProjectsTable.PROP_USER, 151 CmsProjectsTable.PROP_DATE_CREATED, 152 CmsProjectsTable.PROP_RESOURCES); 153 } 154 155 // get content 156 try { 157 List<CmsHistoryProject> projects = cms.getAllHistoricalProjects(); 158 for (CmsHistoryProject project : projects) { 159 Item item = m_container.addItem(new Integer(project.getPublishTag())); 160 if (item != null) { 161 item.getItemProperty(CmsProjectsTable.PROP_ID).setValue(project.getUuid()); 162 item.getItemProperty(CmsProjectsTable.PROP_NAME).setValue(project.getSimpleName()); 163 item.getItemProperty(CmsProjectsTable.PROP_DESCRIPTION).setValue(project.getDescription()); 164 item.getItemProperty(PROP_PUBLISH_DATE).setValue(new Date(project.getPublishingDate())); 165 item.getItemProperty(PROP_PUBLISH_USER).setValue(project.getPublishedByName(cms)); 166 try { 167 item.getItemProperty(CmsProjectsTable.PROP_ORG_UNIT).setValue( 168 OpenCms.getOrgUnitManager().readOrganizationalUnit(cms, project.getOuFqn()).getDisplayName( 169 locale)); 170 item.getItemProperty(CmsProjectsTable.PROP_OWNER).setValue( 171 cms.readUser(project.getOwnerId()).getName()); 172 item.getItemProperty(CmsProjectsTable.PROP_MANAGER).setValue( 173 cms.readGroup(project.getManagerGroupId()).getSimpleName()); 174 item.getItemProperty(CmsProjectsTable.PROP_USER).setValue( 175 cms.readGroup(project.getGroupId()).getSimpleName()); 176 } catch (CmsException e) { 177 // TODO Auto-generated catch block 178 e.printStackTrace(); 179 } 180 item.getItemProperty(CmsProjectsTable.PROP_DATE_CREATED).setValue( 181 new Date(project.getDateCreated())); 182 183 StringBuffer html = new StringBuffer(512); 184 for (String resource : cms.readProjectResources(project)) { 185 html.append(resource); 186 html.append("<br />"); 187 } 188 Label resLabel = new Label(); 189 resLabel.setContentMode(ContentMode.HTML); 190 resLabel.setValue(html.toString()); 191 item.getItemProperty(CmsProjectsTable.PROP_RESOURCES).setValue(resLabel); 192 } 193 } 194 m_container.sort(new Object[] {PROP_PUBLISH_DATE}, new boolean[] {false}); 195 } catch (CmsException e) { 196 // TODO Auto-generated catch block 197 e.printStackTrace(); 198 } 199 } 200}