001/* 002 * This library is part of OpenCms - 003 * the Open Source Content Management System 004 * 005 * Copyright (C) Alkacon Software (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.gwt.client.ui.resourceinfo; 029 030import org.opencms.db.CmsResourceState; 031import org.opencms.gwt.client.CmsCoreProvider; 032import org.opencms.gwt.client.I_CmsDescendantResizeHandler; 033import org.opencms.gwt.client.ui.CmsListItemWidget; 034import org.opencms.gwt.client.ui.CmsScrollPanel; 035import org.opencms.gwt.client.ui.contextmenu.CmsContextMenuButton; 036import org.opencms.gwt.client.ui.contextmenu.CmsContextMenuHandler; 037import org.opencms.gwt.client.ui.css.I_CmsLayoutBundle; 038import org.opencms.gwt.client.util.CmsDomUtil; 039import org.opencms.gwt.client.util.CmsResourceStateUtil; 040import org.opencms.gwt.shared.CmsCoreData.AdeContext; 041import org.opencms.gwt.shared.CmsResourceStatusBean; 042 043import java.util.List; 044import java.util.Map.Entry; 045 046import com.google.gwt.core.client.GWT; 047import com.google.gwt.event.logical.shared.CloseEvent; 048import com.google.gwt.event.logical.shared.CloseHandler; 049import com.google.gwt.event.logical.shared.OpenEvent; 050import com.google.gwt.event.logical.shared.OpenHandler; 051import com.google.gwt.uibinder.client.UiBinder; 052import com.google.gwt.uibinder.client.UiField; 053import com.google.gwt.user.client.Timer; 054import com.google.gwt.user.client.ui.Composite; 055import com.google.gwt.user.client.ui.FlowPanel; 056import com.google.gwt.user.client.ui.HasText; 057import com.google.gwt.user.client.ui.SimplePanel; 058import com.google.gwt.user.client.ui.Widget; 059 060/** 061 * A widget used to display various resource information to a user.<p> 062 */ 063public class CmsResourceInfoView extends Composite implements I_CmsDescendantResizeHandler { 064 065 /** 066 * The uiBinder interface for this widget.<p> 067 */ 068 interface I_CmsResourceInfoViewUiBinder extends UiBinder<Widget, CmsResourceInfoView> { 069 // empty 070 } 071 072 /** The uiBinder instance for this widget. */ 073 private static I_CmsResourceInfoViewUiBinder uiBinder = GWT.create(I_CmsResourceInfoViewUiBinder.class); 074 075 /** 076 * Text field for resource information.<p> 077 */ 078 @UiField 079 protected HasText m_dateCreated; 080 081 /** 082 * Text field for resource information.<p> 083 */ 084 @UiField 085 protected HasText m_dateExpired; 086 087 /** 088 * Text field for resource information.<p> 089 */ 090 @UiField 091 protected HasText m_dateLastModified; 092 093 /** 094 * Text field for resource information.<p> 095 */ 096 @UiField 097 protected HasText m_dateReleased; 098 099 /** 100 * The container for the file info box.<p> 101 */ 102 @UiField 103 protected SimplePanel m_infoBoxContainer; 104 105 /** 106 * The info panel.<p> 107 */ 108 @UiField 109 protected FlowPanel m_infoPanel; 110 111 /** 112 * Text field for resource information.<p> 113 */ 114 @UiField 115 protected HasText m_lastProject; 116 117 /** 118 * Text field for resource information.<p> 119 */ 120 @UiField 121 protected HasText m_locales; 122 123 /** 124 * Text field for resource information.<p> 125 */ 126 @UiField 127 protected HasText m_lockState; 128 129 /** 130 * Text field for resource information.<p> 131 */ 132 @UiField 133 protected HasText m_navText; 134 135 /** 136 * Text field for resource information.<p> 137 */ 138 @UiField 139 protected HasText m_permissions; 140 141 /** 142 * Text field for resource information.<p> 143 */ 144 @UiField 145 protected HasText m_resourceType; 146 147 /** 148 * Scroll panel for resource information.<p> 149 */ 150 @UiField 151 protected CmsScrollPanel m_scrollPanel; 152 153 /** 154 * Text field for resource information.<p> 155 */ 156 @UiField 157 protected HasText m_size; 158 159 /** 160 * Text field for resource information.<p> 161 */ 162 @UiField 163 protected HasText m_state; 164 165 /** 166 * Text field for resource information.<p> 167 */ 168 @UiField 169 protected HasText m_title; 170 171 /** 172 * Text field for resource information.<p> 173 */ 174 @UiField 175 protected HasText m_userCreated; 176 177 /** 178 * Text field for resource information.<p> 179 */ 180 @UiField 181 protected HasText m_userLastModified; 182 183 /** 184 * Contains the additional information lines.<p> 185 */ 186 @UiField 187 protected FlowPanel m_additionalParams; 188 189 /** The context menu handler. */ 190 private CmsContextMenuHandler m_menuHandler; 191 192 /** 193 * Creates a new widget instance.<p> 194 * 195 * @param status the resource information to display 196 * @param menuHandler the context menu handler 197 */ 198 public CmsResourceInfoView(CmsResourceStatusBean status, CmsContextMenuHandler menuHandler) { 199 200 initWidget(uiBinder.createAndBindUi(this)); 201 m_menuHandler = menuHandler; 202 m_scrollPanel.setHeight(CmsResourceInfoDialog.SCROLLPANEL_HEIGHT + "px"); 203 initContent(status); 204 } 205 206 /** 207 * Initializes the content.<p> 208 * 209 * @param status the status data 210 */ 211 public void initContent(CmsResourceStatusBean status) { 212 213 m_infoBoxContainer.clear(); 214 CmsListItemWidget infoBox = new CmsListItemWidget(status.getListInfo()); 215 infoBox.addOpenHandler(new OpenHandler<CmsListItemWidget>() { 216 217 public void onOpen(OpenEvent<CmsListItemWidget> event) { 218 219 CmsDomUtil.resizeAncestor(getParent()); 220 } 221 }); 222 infoBox.addCloseHandler(new CloseHandler<CmsListItemWidget>() { 223 224 public void onClose(CloseEvent<CmsListItemWidget> event) { 225 226 CmsDomUtil.resizeAncestor(getParent()); 227 } 228 }); 229 CmsContextMenuButton menuButton = new CmsContextMenuButton( 230 status.getStructureId(), 231 m_menuHandler, 232 AdeContext.resourceinfo); 233 menuButton.addStyleName(I_CmsLayoutBundle.INSTANCE.listItemWidgetCss().permaVisible()); 234 infoBox.addButton(menuButton); 235 m_infoBoxContainer.add(infoBox); 236 m_dateCreated.setText(status.getDateCreated()); 237 m_dateExpired.setText(status.getDateExpired()); 238 m_dateLastModified.setText(status.getDateLastModified()); 239 m_dateReleased.setText(status.getDateReleased()); 240 m_lastProject.setText(status.getLastProject()); 241 m_lockState.setText(status.getLockState()); 242 CmsResourceState state = status.getStateBean(); 243 String stateStyle = CmsResourceStateUtil.getStateStyle(state); 244 String stateText = CmsResourceStateUtil.getStateName(state); 245 m_state.setText(makeSpan(stateStyle, stateText)); 246 m_title.setText(status.getTitle()); 247 m_navText.setText(status.getNavText()); 248 m_permissions.setText(status.getPermissions()); 249 m_resourceType.setText(status.getResourceType()); 250 m_size.setText("" + status.getSize() + " Bytes"); 251 m_userCreated.setText(status.getUserCreated()); 252 m_userLastModified.setText(status.getUserLastModified()); 253 254 List<String> locales = status.getLocales(); 255 if (locales != null) { 256 StringBuffer buffer = new StringBuffer(); 257 int index = 0; 258 for (String locale : locales) { 259 if (locale.equals(CmsCoreProvider.get().getLocale())) { 260 buffer.append("<b>"); 261 buffer.append(locale); 262 buffer.append("</b>"); 263 } else { 264 buffer.append(locale); 265 } 266 if (index != (locales.size() - 1)) { 267 buffer.append(", "); 268 } 269 index += 1; 270 } 271 m_locales.setText(buffer.toString()); 272 } else { 273 m_locales.setText(""); 274 } 275 m_additionalParams.clear(); 276 if (status.getAdditionalAttributes() != null) { 277 for (Entry<String, String> entry : status.getAdditionalAttributes().entrySet()) { 278 CmsResourceInfoLine line = new CmsResourceInfoLine(); 279 line.setLabel(entry.getKey()); 280 line.setText(entry.getValue()); 281 m_additionalParams.add(line); 282 } 283 } 284 285 } 286 287 /** 288 * @see org.opencms.gwt.client.I_CmsDescendantResizeHandler#onResizeDescendant() 289 */ 290 public void onResizeDescendant() { 291 292 Timer timer = new Timer() { 293 294 @Override 295 public void run() { 296 297 m_scrollPanel.onResizeDescendant(); 298 299 } 300 }; 301 timer.schedule(100); 302 } 303 304 /** 305 * Helper method to generate the HTML for a span with a CSS class and some text.<p> 306 * 307 * @param className the CSS class 308 * @param text the text 309 * 310 * @return the HTML for the span 311 */ 312 private String makeSpan(String className, String text) { 313 314 return "<span class='" + className + "'>" + text + "</span>"; 315 } 316}