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.ade.sitemap.client.alias; 029 030import org.opencms.gwt.client.ui.css.I_CmsCellTableResources; 031import org.opencms.gwt.client.util.CmsDomUtil; 032 033import com.google.gwt.safehtml.shared.SafeHtml; 034import com.google.gwt.safehtml.shared.SafeHtmlUtils; 035import com.google.gwt.user.cellview.client.CellTable; 036import com.google.gwt.user.cellview.client.LoadingStateChangeEvent; 037import com.google.gwt.user.client.Timer; 038 039/** 040 * Various static utility methods for dealing with cell tables.<p> 041 */ 042public final class CmsCellTableUtil { 043 044 /** CSS class for the error text. */ 045 public static final String STATUS_ERROR = I_CmsCellTableResources.INSTANCE.cellTableStyle().statusError(); 046 047 /** CSS class for the 'Status OK' text. */ 048 public static final String STATUS_OK = I_CmsCellTableResources.INSTANCE.cellTableStyle().statusOk(); 049 050 /** 051 * Hidden constructor.<p> 052 */ 053 private CmsCellTableUtil() { 054 055 // nothing 056 } 057 058 /** 059 * Ensures that surrounding scroll panels are notified when a table changes size.<p> 060 * 061 * @param table the table for which the parent scroll panels should be notified 062 */ 063 public static void ensureCellTableParentResize(final CellTable<?> table) { 064 065 // we need to update the scroll panel when the table is redrawn, but the redraw() method of the table is asynchronous, 066 // i.e. it only schedules an actual redraw. However, the method which is responsible for the actual redrawing triggers a 067 // loading state event before it does the redrawing. Using a timer at this point, we can execute code after the redrawing 068 // has happend. 069 table.addLoadingStateChangeHandler(new LoadingStateChangeEvent.Handler() { 070 071 public void onLoadingStateChanged(LoadingStateChangeEvent event) { 072 073 Timer resizeTimer = new Timer() { 074 075 @Override 076 public void run() { 077 078 CmsDomUtil.resizeAncestor(table); 079 } 080 }; 081 resizeTimer.schedule(10); 082 } 083 }); 084 } 085 086 /** 087 * Formats the HTML for the error column of a cell table given an error message.<p> 088 * 089 * @param error the error message (null for no error) 090 * 091 * @return the SafeHtml representing the contents of the error cell 092 */ 093 public static SafeHtml formatErrorHtml(String error) { 094 095 String text; 096 String cssClass; 097 String title = ""; 098 099 if (error == null) { 100 text = CmsAliasMessages.messageStatusOk(); 101 cssClass = STATUS_OK; 102 } else { 103 text = CmsAliasMessages.messageStatusError(); 104 title = SafeHtmlUtils.htmlEscape(error); 105 cssClass = STATUS_ERROR; 106 } 107 String html = "<div class='" + cssClass + "' title='" + title + "'>" + text + "</div>"; 108 return SafeHtmlUtils.fromSafeConstant(html); 109 } 110 111}