001 /* 002 * Copyright (c) 2009 The openGion Project. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 013 * either express or implied. See the License for the specific language 014 * governing permissions and limitations under the License. 015 */ 016 package org.opengion.plugin.view; 017 018 import java.util.List; 019 020 import org.opengion.hayabusa.common.HybsSystem; 021 import org.opengion.hayabusa.common.HybsSystemException; 022 import org.opengion.hayabusa.html.TableFormatter; 023 024 /** 025 * ヘッ??フッタ、??を指定して作?する、?由レイアウトが可能な、カスタ?ーブル表示クラスです? 026 * 従来は、?部バグのため、thead,tbody,tfoot タグを使わな?処?きませんでしたが? 027 * viewタグの BODY 部にフォーマットを記述する?で処?るよ?改?ました?5.6.3.3 (2013/04/19)) 028 * 029 * こ?タグでは、BODY部、また?、bodyFormats を繰り返す処?行います? 030 * ヘッ?があれ?、最初に?度のみ実行し、フ?があれ?、最後に実行します? 031 * こ?クラスが他と異なる?は、??のみ記述した場合?ヘッ?して使われず?ボディとしてのみ繰返し 032 * 使われます?また?bodyFormats のみの記述も可能です? 033 * 034 * こ?クラスは、ViewForm_HTMLFormatTable クラスの代替えとしても使用できます? 035 * そ?場合?、thead のみ?すれ?、同じフォー? tbody にも適用されます? 036 * これは、まさに、ViewForm_HTMLFormatTable と同じです? 037 * (※ 上記仕様が、未実?したので、対応しました?5.6.3.3 (2013/04/19) ) 038 * 039 * AbstractViewForm により、setter/getterメソ?の?ォルト実?提供して?す? 040 * 各HTMLのタグに?な setter/getterメソ?のみ?追?義して?す? 041 * 042 * AbstractViewForm を継承して?為,ロケールに応じたラベルを?力させる事が出来ます? 043 * 044 * <table border="1" frame="box" rules="all" > 045 * <tr><th>番号</th><th>headerFormat</th><th>bodyFormats</th><th>現状動? </th><th>変更?5.6.3.3以? </th></tr> 046 * <tr><td>? </td><td>な? </td><td>な? </td><td>headerのみ </td><td>body の繰り返し </td></tr> 047 * <tr><td>② </td><td>な? </td><td>あり </td><td>エラー </td><td>bodyFormats のみ繰り返す </td></tr> 048 * <tr><td>③ </td><td>あり </td><td>な? </td><td>headerのみ </td><td>body の繰り返し </td></tr> 049 * <tr><td>④ </td><td>あり </td><td>あり </td><td>それぞれ動?/td><td>?同じ </td></tr> 050 * <tr><td>⑤ </td><td>な? </td><td>な? </td><td>エラー </td><td>?同じ </td></tr> 051 * </table> 052 * 053 * @og.rev 3.7.1.1 (2005/05/23) 新規作? 054 * @og.rev 5.6.3.3 (2013/04/19) 処?更 055 * @og.group 画面表示 056 * 057 * @version 4.0 058 * @author Kazuhiko Hasegawa 059 * @since JDK5.0, 060 */ 061 public class ViewForm_CustomData extends ViewForm_HTMLTable { 062 //* こ?プログラ??VERSION??を設定します? {@value} */ 063 private static final String VERSION = "5.6.3.3 (2013/04/19)" ; 064 065 private TableFormatter headerFormat = null; 066 private TableFormatter[] bodyFormats = null; 067 private TableFormatter footerFormat = null; 068 private int bodyFormatsCount = 0; 069 070 private static final int BODYFORMAT_MAX_COUNT = 10; 071 072 // 4.3.4.4 (2009/01/01) 073 // /** 074 // * ?ォルトコンストラクター 075 // * 076 // */ 077 // public ViewForm_CustomData() { 078 // super(); 079 // } 080 081 /** 082 * DBTableModel から HTML??を作?して返します? 083 * startNo(表示開始位置)から、pageSize(表示件数)までのView??を作?します? 084 * 表示残り??タ?pageSize 以下?場合?,残りの??タをすべて出力します? 085 * 086 * @og.rev 4.3.1.0 (2008/09/08) フォーマットが設定されて???合?エラー追??編??みを表示する属?(isSkipNoEdit)追? 087 * @og.rev 5.6.3.3 (2013/04/19) headerFormatのみ、bodyFormatsのみ対? 088 * 089 * @param startNo 表示開始位置 090 * @param pageSize 表示件数 091 * 092 * @return DBTableModelから作?され?HTML?? 093 */ 094 @Override 095 public String create( final int startNo, final int pageSize ) { 096 if( getRowCount() == 0 ) { return ""; } // 暫定?置 097 098 // 4.3.1.0 (2008/09/08) 099 // 5.6.3.3 (2013/04/19) headerFormatのみ、bodyFormatsのみ対? 100 // if( headerFormat == null ) { 101 // String errMsg = "ViewTagで canUseFormat() = true の場合?Formatter は??です?"; 102 // throw new HybsSystemException( errMsg ); 103 // } 104 105 headerLine = null; // 3.5.3.1 (2003/10/31) キャ?ュクリア 106 107 int lastNo = getLastNo( startNo, pageSize ); 108 109 StringBuilder out = new StringBuilder( HybsSystem.BUFFER_LARGE ); 110 111 // 5.6.3.3 (2013/04/19) headerFormatのみ、bodyFormatsのみ対? 112 if( headerFormat != null ) { 113 headerFormat.makeFormat( getDBTableModel() ); // 3.5.6.2 (2004/07/05) 移? 114 } 115 116 if( bodyFormatsCount != 0 ) { 117 for( int i=0; i<bodyFormatsCount; i++ ) { 118 bodyFormats[i].makeFormat( getDBTableModel() ); 119 } 120 } 121 122 out.append( getHeader() ); 123 for( int row=startNo; row<lastNo; row++ ) { 124 // if( isSkip( row ) ) { continue; } // 3.5.3.1 (2003/10/31) 125 if( isSkip( row ) || isSkipNoEdit( row ) ) { continue; } // 4.3.1.0 (2008/09/08) 126 for( int i=0; i<bodyFormatsCount; i++ ) { 127 TableFormatter bodyFormat = bodyFormats[i]; 128 if( ! bodyFormat.isUse( row,getDBTableModel() ) ) { continue; } // 3.5.4.0 (2003/11/25) 129 130 int cl = 0; 131 for( ; cl < bodyFormat.getLocationSize(); cl++ ) { 132 String fmt = bodyFormat.getFormat(cl); 133 int loc = bodyFormat.getLocation(cl); // 3.5.5.0 134 out.append( fmt ); // 3.5.0.0 135 136 if( loc >= 0 ) { 137 switch( bodyFormat.getType(cl) ) { 138 case '#' : out.append( getColumnLabel(loc) ); break; 139 case '$' : out.append( getRendererValue(row,loc) ); break; 140 case '!' : out.append( getValue(row,loc) ); break; 141 default : out.append( getValueLabel(row,loc) ); break; 142 } 143 } 144 else { 145 out.append( bodyFormat.getSystemFormat(row,loc) ); 146 } 147 } 148 out.append( bodyFormat.getFormat(cl) ); 149 } 150 } 151 152 if( footerFormat != null ) { 153 out.append( getTableFoot() ); 154 } 155 156 return out.toString(); 157 } 158 159 /** 160 * ?をクリア(初期?します? 161 * 162 */ 163 @Override 164 public void clear() { 165 super.clear(); 166 headerFormat = null; 167 bodyFormats = null; 168 footerFormat = null; 169 bodyFormatsCount = 0; 170 } 171 172 /** 173 * DBTableModel から ??ブルのヘッ??タグ??を作?して返します? 174 * 175 * <del>これは、?部?キャ?ュして?ため、状況が変更される?度に? 176 * キャ?ュをクリアする?があります? 177 * 178 * @return ??ブルのヘッ??タグ?? 179 */ 180 @Override 181 protected String getHeader() { 182 if( headerFormat == null ) { return ""; } // 存在しな?ース 183 if( headerLine != null ) { return headerLine; } // キャ?ュを返す? 184 185 StringBuilder buf = new StringBuilder( HybsSystem.BUFFER_MIDDLE ); 186 187 int cl = 0; 188 for( ; cl < headerFormat.getLocationSize(); cl++ ) { 189 buf.append( headerFormat.getFormat(cl) ); 190 int loc = headerFormat.getLocation(cl); 191 if( loc >= 0 ) { buf.append( getSortedColumnLabel(loc) ); } 192 } 193 buf.append( headerFormat.getFormat(cl) ).append( HybsSystem.CR ); 194 195 headerLine = buf.toString(); 196 return headerLine; 197 } 198 199 /** 200 * DBTableModel から ??ブルのタグ??を作?して返します? 201 * 202 * @return ??ブルのタグ?? 203 */ 204 protected String getTableFoot() { 205 footerFormat.makeFormat( getDBTableModel() ); 206 207 StringBuilder buf = new StringBuilder( HybsSystem.BUFFER_MIDDLE ); 208 209 int cl = 0; 210 for( ; cl < footerFormat.getLocationSize(); cl++ ) { 211 int loc = footerFormat.getLocation(cl); 212 if( loc >= 0 ) { buf.append( getSortedColumnLabel(loc) ); } 213 } 214 buf.append( footerFormat.getFormat(cl) ).append( HybsSystem.CR ); 215 216 return buf.toString(); 217 } 218 219 /** 220 * フォーマットを設定します? 221 * 222 * @og.rev 5.6.3.3 (2013/04/19) headerFormatのみの場合?bodyFormats として使?? 223 * 224 * @param list TableFormatterのリス? 225 */ 226 @Override 227 public void setFormatterList( final List<TableFormatter> list ) { // 4.3.3.6 (2008/11/15) Generics警告対? 228 bodyFormats = new TableFormatter[BODYFORMAT_MAX_COUNT]; 229 230 bodyFormatsCount = 0; 231 for( int i=0; i<list.size(); i++ ) { 232 TableFormatter format = list.get( i ); // 4.3.3.6 (2008/11/15) Generics警告対? 233 234 switch( format.getFormatType() ) { 235 case TYPE_HEAD : headerFormat = format; break; 236 case TYPE_BODY : bodyFormats[bodyFormatsCount++] = format; break; 237 case TYPE_FOOT : footerFormat = format; break; 238 default : String errMsg = "FormatterType の定義外?値が指定されました?; 239 // 4.3.4.4 (2009/01/01) 240 throw new HybsSystemException( errMsg ); 241 } 242 } 243 244 // 5.6.3.3 (2013/04/19) headerFormatのみの場合?bodyFormats として使?? 245 if( bodyFormatsCount == 0 ) { // bodyFormats がな??合?、headerFormatをコピ?する? 246 if( headerFormat == null ) { 247 String errMsg = "thead タグか?また?、tbody タグによるフォーマット?????です?"; 248 throw new HybsSystemException( errMsg ); 249 } 250 else { 251 bodyFormats[bodyFormatsCount++] = headerFormat; 252 headerFormat = null; 253 } 254 } 255 } 256 257 /** 258 * フォーマットメソ?を使用できるかど?を問?わせます? 259 * 260 * @return 使用可能(true)/ 使用不可能 (false) 261 */ 262 @Override 263 public boolean canUseFormat() { 264 return true; 265 } 266 267 /** 268 * 表示?の編?並び替?が可能かど?を返しま? 269 * 270 * @og.rev 5.1.6.0 (2010/05/01) 新規追? 271 * 272 * @return 表示?の編?並び替?が可能かど?(false:不可能) 273 */ 274 @Override 275 public boolean isEditable() { 276 return false; 277 } 278 }