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.dialogs.history; 029 030import org.opencms.file.CmsObject; 031import org.opencms.gwt.shared.CmsHistoryResourceBean; 032import org.opencms.gwt.shared.CmsHistoryVersion; 033import org.opencms.ui.A_CmsUI; 034import org.opencms.ui.CmsVaadinUtils; 035import org.opencms.ui.Messages; 036import org.opencms.ui.util.table.CmsTableUtil; 037import org.opencms.ui.util.table.Column; 038 039import java.util.Date; 040 041import com.vaadin.server.FontAwesome; 042import com.vaadin.ui.Button; 043import com.vaadin.v7.ui.CheckBox; 044 045/** 046 * Represents a row of the file history table.<p> 047 */ 048public class CmsHistoryRow { 049 050 /** The history resource bean. */ 051 private CmsHistoryResourceBean m_bean; 052 053 /** The V1 check box. */ 054 private CheckBox m_checkbox1 = new CheckBox(); 055 056 /** The V2 check box. */ 057 private CheckBox m_checkbox2 = new CheckBox(); 058 059 /** The Preview button. */ 060 private Button m_previewButton = CmsTableUtil.createIconButton( 061 FontAwesome.SEARCH, 062 CmsVaadinUtils.getMessageText(Messages.GUI_HISTORY_DIALOG_BUTTON_PREVIEW_0)); 063 064 /** The Restore button. */ 065 private Button m_restoreButton = CmsTableUtil.createIconButton( 066 FontAwesome.CLOCK_O, 067 CmsVaadinUtils.getMessageText(Messages.GUI_HISTORY_DIALOG_BUTTON_RESTORE_0)); 068 069 /** 070 * Creates a new instance.<p> 071 * 072 * @param bean the history resource bean 073 */ 074 public CmsHistoryRow(CmsHistoryResourceBean bean) { 075 076 m_bean = bean; 077 } 078 079 /** 080 * Formats the file version for display.<p> 081 * 082 * @param bean the history resource bean 083 * 084 * @return the formatted version 085 */ 086 public static String formatVersion(CmsHistoryResourceBean bean) { 087 088 CmsHistoryVersion hVersion = bean.getVersion(); 089 Integer v = hVersion.getVersionNumber(); 090 String result = "" + (v != null ? v.toString() : "-"); 091 String suffix = ""; 092 if (hVersion.isOnline()) { 093 suffix = " (Online)"; 094 } else if (hVersion.isOffline()) { 095 suffix = " (Offline)"; 096 } 097 result += suffix; 098 return result; 099 100 } 101 102 /** 103 * Gets the V1 check box.<p> 104 * 105 * @return the V1 check box 106 */ 107 @Column(header = "V1", order = 90) 108 public CheckBox getCheckBoxV1() { 109 110 return m_checkbox1; 111 } 112 113 /** 114 * Gets the V2 check box.<p> 115 * 116 * @return the V2 check box 117 */ 118 @Column(header = "V2", order = 100) 119 public CheckBox getCheckBoxV2() { 120 121 return m_checkbox2; 122 } 123 124 /** 125 * Gets the modification date.<p> 126 * 127 * @return the modification date 128 */ 129 @Column(header = Messages.GUI_HISTORY_DIALOG_COL_DATE_LASTMODIFIED_0, order = 60) 130 public Date getModificationDate() { 131 132 return new Date(m_bean.getModificationDate().getDate()); 133 } 134 135 /** 136 * Gets the path.<p> 137 * 138 * @return the path 139 */ 140 @Column(header = Messages.GUI_HISTORY_DIALOG_COL_PATH_0, order = 40, expandRatio = 1.0f, view = "wide") 141 public String getPath() { 142 143 String rootPath = m_bean.getRootPath(); 144 CmsObject cms = A_CmsUI.getCmsObject(); 145 String result = cms.getRequestContext().removeSiteRoot(rootPath); 146 return result; 147 } 148 149 /** 150 * Gets the preview button.<p> 151 * 152 * @return the preview button 153 */ 154 @Column(header = Messages.GUI_HISTORY_DIALOG_BUTTON_PREVIEW_0, order = 7) 155 public Button getPreviewButton() { 156 157 return m_previewButton; 158 } 159 160 /** 161 * Gets the publish date.<p> 162 * 163 * @return the publish date 164 */ 165 @Column(header = Messages.GUI_HISTORY_DIALOG_COL_DATE_PUBLISHED_0, order = 50) 166 public Date getPublishDate() { 167 168 if (m_bean.getPublishDate() == null) { 169 return null; 170 } 171 return new Date(m_bean.getPublishDate().getDate()); 172 } 173 174 /** 175 * Gets the restore button.<p> 176 * 177 * @return the restore button 178 */ 179 @Column(header = Messages.GUI_HISTORY_DIALOG_BUTTON_RESTORE_0, order = 6) 180 public Button getRestoreButton() { 181 182 if (m_bean.getVersion().getVersionNumber() == null) { 183 return null; 184 } 185 return m_restoreButton; 186 187 } 188 189 /** 190 * Gets the file size.<p> 191 * 192 * @return the file size 193 */ 194 @Column(header = org.opencms.workplace.commons.Messages.GUI_LABEL_SIZE_0, order = 80) 195 public Integer getSize() { 196 197 return Integer.valueOf(m_bean.getSize()); 198 } 199 200 /** 201 * Gets the last modification user.<p> 202 * 203 * @return the last modification user 204 */ 205 @Column(header = org.opencms.workplace.commons.Messages.GUI_LABEL_USER_LAST_MODIFIED_0, order = 70) 206 public String getUserLastModified() { 207 208 return m_bean.getUserLastModified(); 209 } 210 211 /** 212 * Gets the file version.<p> 213 * 214 * @return the file version 215 */ 216 @Column(header = org.opencms.workplace.commons.Messages.GUI_LABEL_VERSION_0, order = 30) 217 public String getVersion() { 218 219 return formatVersion(m_bean); 220 } 221 222}