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 com.google.gwt.core.client.GWT; 031import com.google.gwt.resources.client.ClientBundle; 032import com.google.gwt.resources.client.CssResource; 033import com.google.gwt.user.client.ui.Composite; 034import com.google.gwt.user.client.ui.FlexTable; 035import com.google.gwt.user.client.ui.FlowPanel; 036import com.google.gwt.user.client.ui.Label; 037 038/** 039 * A widget used for displaying the results of an alias import operation.<p> 040 */ 041public class CmsImportResultList extends Composite { 042 043 /** The CSS classes used for this widget.<p> */ 044 public static interface I_Css extends CssResource { 045 046 /** 047 * CSS class accessor.<p> 048 * 049 * @return a CSS class 050 */ 051 String aliasImportError(); 052 053 /** 054 * CSS class accessor.<p> 055 * 056 * @return a CSS class 057 */ 058 String aliasImportOk(); 059 060 /** 061 * CSS class accessor.<p> 062 * 063 * @return a CSS class 064 */ 065 String aliasImportOverwrite(); 066 067 /** 068 * CSS class accessor.<p> 069 * 070 * @return a CSS class 071 */ 072 String rightLabel(); 073 } 074 075 /** 076 * The resource bundle used for this widget.<p> 077 */ 078 public static interface I_Resources extends ClientBundle { 079 080 /** 081 * CSS bundle accessor.<p> 082 * 083 * @return the CSS bundle for this widget 084 */ 085 @Source("resultlabel.gss") 086 I_Css css(); 087 } 088 089 /** 090 * Static instance of the resource bundle for this widget.<p> 091 */ 092 public static final I_Resources RESOURCES = GWT.create(I_Resources.class); 093 094 static { 095 RESOURCES.css().ensureInjected(); 096 } 097 098 /** A label which is displayed before any alias files are imported. */ 099 protected Label m_emptyLabel; 100 101 /** The main panel containing the other parts of this widget.<p> */ 102 private FlowPanel m_root = new FlowPanel(); 103 104 /** The table containing the messages for each single import operation. */ 105 private FlexTable m_table = new FlexTable(); 106 107 /** 108 * Default constructor.<p> 109 */ 110 public CmsImportResultList() { 111 112 m_root.add(m_table); 113 initWidget(m_root); 114 ensureEmptyLabel(); 115 } 116 117 /** 118 * Adds a single line of the import result to the widget.<p> 119 * 120 * @param leftText the text to display on the left 121 * @param rightText the text to display on the right 122 * @param styleName the style which should be applied to the right text 123 */ 124 public void addRow(String leftText, String rightText, String styleName) { 125 126 ensureTable(); 127 ensureNoEmptyLabel(); 128 int row = m_table.getRowCount(); 129 m_table.setWidget(row, 0, new Label(leftText)); 130 Label rightLabel = new Label(rightText); 131 rightLabel.addStyleName(styleName); 132 rightLabel.addStyleName(RESOURCES.css().rightLabel()); 133 m_table.setWidget(row, 1, rightLabel); 134 } 135 136 /** 137 * Clears the result list.<p> 138 */ 139 public void clear() { 140 141 m_root.clear(); 142 ensureEmptyLabel(); 143 m_table = null; 144 } 145 146 /** 147 * Ensures the existence of the 'empty' label.<p> 148 */ 149 protected void ensureEmptyLabel() { 150 151 if (m_emptyLabel == null) { 152 m_emptyLabel = new Label(CmsAliasMessages.messagesEmptyImportResult()); 153 } 154 m_root.add(m_emptyLabel); 155 } 156 157 /** 158 * Ensure that the 'empty' label does not exist.<p> 159 */ 160 protected void ensureNoEmptyLabel() { 161 162 if (m_emptyLabel != null) { 163 m_emptyLabel.removeFromParent(); 164 m_emptyLabel = null; 165 } 166 } 167 168 /** 169 * Ensures that the table is present in the widget.<p> 170 */ 171 private void ensureTable() { 172 173 if (m_table == null) { 174 m_table = new FlexTable(); 175 m_root.add(m_table); 176 } 177 178 } 179 180}