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 */ 016package org.opengion.plugin.view; 017 018import org.opengion.hayabusa.common.HybsSystem; 019import org.opengion.hayabusa.common.HybsSystemException; 020import org.opengion.hayabusa.db.DBTableModel; 021import org.opengion.fukurou.util.StringUtil; 022import org.opengion.hayabusa.html.TableFormatter; 023 024import java.util.List; 025 026/** 027 * ヘッダ、フッタ、ボディを指定して作成する、自由レイアウトが可能な、カスタムテーブル表示クラスです。 028 * このクラスは、ViewForm_HTMLFormatTable クラスの代替えとしても使用できます。 029 * その場合は、thead のみ指定すれば、同じフォームが tbody にも適用されます。 030 * これは、まさに、ViewForm_HTMLFormatTable と同じです。 031 * 032 * AbstractViewForm により、setter/getterメソッドのデフォルト実装を提供しています。 033 * 各HTMLのタグに必要な setter/getterメソッドのみ,追加定義しています。 034 * 035 * AbstractViewForm を継承している為,ロケールに応じたラベルを出力させる事が出来ます。 036 * 037 * @og.group 画面表示 038 * 039 * @version 4.0 040 * @author Kazuhiko Hasegawa 041 * @since JDK5.0, 042 */ 043public class ViewForm_HTMLCustomTable extends ViewForm_HTMLTable { 044 //* このプログラムのVERSION文字列を設定します。 {@value} */ 045 private static final String VERSION = "5.1.6.0 (2010/05/01)" ; 046 047 // 3.5.4.0 (2003/11/25) TableFormatter クラス追加 048 // 4.3.1.0 (2008/09/08) protectedに変更 049 /** ヘッダーフォーマット変数 */ 050 protected TableFormatter headerFormat = null; 051 /** ボディーフォーマット配列変数 */ 052 protected TableFormatter[] bodyFormats = null; 053 /** フッターフォーマット変数 */ 054 protected TableFormatter footerFormat = null; 055 /** ボディーフォーマット数 */ 056 protected int bodyFormatsCount = 0; 057 058 // 3.5.4.6 (2004/01/30) 初期値変更 059 /** ボディーフォーマット最大数 初期値:{@value} */ 060 //protected static final int BODYFORMAT_MAX_COUNT = 10; 061 protected static final int BODYFORMAT_MAX_COUNT = 15; 062 063 // 4.3.4.4 (2009/01/01) 064// /** 065// * デフォルトコンストラクター 066// * 067// */ 068// public ViewForm_HTMLCustomTable() { 069// super(); 070// } 071 072 /** 073 * DBTableModel から HTML文字列を作成して返します。 074 * startNo(表示開始位置)から、pageSize(表示件数)までのView文字列を作成します。 075 * 表示残りデータが pageSize 以下の場合は,残りのデータをすべて出力します。 076 * 077 * @og.rev 3.5.0.0 (2003/09/17) BODY要素の noClass 属性を追加。 078 * @og.rev 3.5.0.0 (2003/09/17) <tr>属性は、元のフォーマットのまま使用します。 079 * @og.rev 3.5.2.0 (2003/10/20) ヘッダー繰り返し属性( headerSkipCount )を採用 080 * @og.rev 3.5.3.1 (2003/10/31) skip属性を採用。headerLine のキャッシュクリア 081 * @og.rev 3.5.4.0 (2003/11/25) TableFormatter クラスを使用するように変更。 082 * @og.rev 3.5.5.0 (2004/03/12) systemFormat(例:[KEY.カラム名]形式等)の対応 083 * @og.rev 3.5.5.0 (2004/03/12) No 欄そのものの作成判断ロジックを追加 084 * @og.rev 3.5.5.7 (2004/05/10) [#カラム名] , [$カラム名] に対応 085 * @og.rev 3.5.6.0 (2004/06/18) '!' 値のみ 追加 既存の '$' は、レンデラー 086 * @og.rev 3.5.6.2 (2004/07/05) makeFormat 処理をgetTableHead メソッドから移動 087 * @og.rev 3.5.6.4 (2004/07/16) ヘッダーとボディー部をJavaScriptで分離 088 * @og.rev 4.0.0.0 (2005/01/31) 新規作成(getColumnClassName ⇒ getColumnDbType) 089 * @og.rev 3.7.0.3 (2005/03/01) getBgColorCycleClass に、選択行マーカーを採用 090 * @og.rev 4.3.1.0 (2008/09/08) フォーマットが設定されていない場合のエラー追加・編集行のみを表示する属性(isSkipNoEdit)追加 091 * @og.rev 4.3.3.0 (2008/10/01) noTransition属性対応 092 * @og.rev 4.3.7.4 (2009/07/01) tbodyタグの入れ子を解消(FireFox対応) 093 * 094 * @param startNo 表示開始位置 095 * @param pageSize 表示件数 096 * 097 * @return DBTableModelから作成された HTML文字列 098 */ 099 @Override 100 public String create( final int startNo, final int pageSize ) { 101 if( getRowCount() == 0 ) { return ""; } // 暫定処置 102 103 // 4.3.1.0 (2008/09/08) 104 if( headerFormat == null ) { 105 String errMsg = "ViewTagで canUseFormat() = true の場合、Formatter は必須です。"; 106 throw new HybsSystemException( errMsg ); 107 } 108 109 headerLine = null; // 3.5.3.1 (2003/10/31) キャッシュクリア 110 111 int lastNo = getLastNo( startNo, pageSize ); 112 int blc = getBackLinkCount(); 113 int hsc = getHeaderSkipCount(); // 3.5.2.0 (2003/10/20) 114 int hscCnt = 1; // 3.5.2.0 (2003/10/20) 115 116 StringBuilder out = new StringBuilder( HybsSystem.BUFFER_LARGE ); 117 118 headerFormat.makeFormat( getDBTableModel() ); // 3.5.6.2 (2004/07/05) 移動 119 120 out.append( getCountForm( startNo,pageSize ) ); 121 out.append( getHeader() ); 122 123 if( bodyFormatsCount == 0 ) { 124 bodyFormats[0] = headerFormat ; 125 bodyFormatsCount ++ ; 126 } 127 else { 128 for( int i=0; i<bodyFormatsCount; i++ ) { 129 bodyFormats[i].makeFormat( getDBTableModel() ); 130 } 131 } 132 133// out.append("<tbody>").append( HybsSystem.CR ); // 4.3.7.4 (2009/07/01) 134 int bgClrCnt = 0; 135 for( int row=startNo; row<lastNo; row++ ) { 136// if( isSkip( row ) ) { continue; } // 3.5.3.1 (2003/10/31) 137 if( isSkip( row ) || isSkipNoEdit( row ) ) { continue; } // 4.3.1.0 (2008/09/08) 138 for( int i=0; i<bodyFormatsCount; i++ ) { 139 TableFormatter bodyFormat = bodyFormats[i]; 140 if( ! bodyFormat.isUse( row,getDBTableModel() ) ) { continue; } // 3.5.4.0 (2003/11/25) 141 out.append("<tbody").append( getBgColorCycleClass( bgClrCnt++,row ) ); 142 if( isNoTransition() ) { // 4.3.3.0 (2008/10/01) 143 out.append( getHiddenRowValue( row ) ); 144 } 145 out.append(">"); // 3.7.0.3 (2005/03/01) 146 out.append( bodyFormat.getTrTag() ); 147 148 // 3.5.5.0 (2004/03/12) No 欄そのものの作成判断追加 149 if( isNumberDisplay() ) { 150 String ckboxTD = "<td" + bodyFormat.getRowspan() + ">"; 151 out.append( makeCheckbox( ckboxTD,row,blc ) ); 152 } 153 154 int cl = 0; 155 for( ; cl < bodyFormat.getLocationSize(); cl++ ) { 156 String fmt = bodyFormat.getFormat(cl); 157 int loc = bodyFormat.getLocation(cl); // 3.5.5.0 158 if( ! bodyFormat.isNoClass() && loc >= 0 ) { // 3.5.5.7 (2004/05/10) 159 StringBuilder newtg = new StringBuilder( HybsSystem.BUFFER_LARGE ); 160 newtg.append("<td class=\""); 161 newtg.append( getColumnDbType(loc) ); // 4.0.0 (2005/01/31) 162 newtg.append("\" "); 163 String tdclass = newtg.toString(); 164 fmt = StringUtil.replace( bodyFormat.getFormat(cl) ,"<td", tdclass ); 165 } 166 out.append( fmt ); // 3.5.0.0 167 // 3.5.5.7 (2004/05/10) #,$ 対応 168 if( loc >= 0 ) { 169 switch( bodyFormat.getType(cl) ) { 170 case '#' : out.append( getColumnLabel(loc) ); break; 171 case '$' : out.append( getRendererValue(row,loc) ); break; 172 case '!' : out.append( getValue(row,loc) ); break; 173 default : out.append( getValueLabel(row,loc) ); break; 174 } 175 } 176 else { 177 out.append( bodyFormat.getSystemFormat(row,loc) ); 178 } 179 } 180 out.append( bodyFormat.getFormat(cl) ); 181 out.append("</tbody>").append( HybsSystem.CR ); 182 } 183 184 // 3.5.2.0 (2003/10/20) ヘッダー繰り返し属性( headerSkipCount )を採用 185 if( hsc > 0 && hscCnt % hsc == 0 ) { 186 out.append("<tbody class=\"row_h\"").append(" >"); 187 out.append( getHeadLine() ); 188 out.append("</tbody>"); 189 hscCnt = 1; 190 } 191 else { 192 hscCnt ++ ; 193 } 194 } 195 196 if( footerFormat != null ) { 197 out.append( getTableFoot() ); 198 } 199 200// out.append("</tbody>").append( HybsSystem.CR ); // 4.3.7.4 (2009/07/01) 201 out.append("</table>").append( HybsSystem.CR ); 202 203 out.append( getScrollBarEndDiv() ); // 3.8.0.3 (2005/07/15) 204 return out.toString(); 205 } 206 207 /** 208 * 内容をクリア(初期化)します。 209 * 210 * @og.rev 3.1.1.0 (2003/03/28) 同期メソッド(synchronized付き)を非同期に変更する。 211 * @og.rev 3.5.0.0 (2003/09/17) Noカラムに、表示を全て消せるように、class 属性を追加。 212 * @og.rev 3.5.4.0 (2003/11/25) TableFormatter クラスを使用するように変更。 213 * 214 */ 215 @Override 216 public void clear() { 217 super.clear(); 218 headerFormat = null; 219 bodyFormats = null; 220 footerFormat = null; 221 bodyFormatsCount = 0; 222 } 223 224 /** 225 * DBTableModel から テーブルのタグ文字列を作成して返します。 226 * 227 * @og.rev 3.5.0.0 (2003/09/17) <tr>属性は、元のフォーマットのまま使用します。 228 * @og.rev 3.5.1.0 (2003/10/03) Noカラムに、numberType 属性を追加 229 * @og.rev 3.5.2.0 (2003/10/20) ヘッダー繰り返し部をgetHeadLine()へ移動 230 * @og.rev 3.5.3.1 (2003/10/31) VERCHAR2 を VARCHAR2 に修正。 231 * @og.rev 3.5.4.0 (2003/11/25) TableFormatter クラスを使用するように変更。 232 * @og.rev 3.5.5.0 (2004/03/12) No 欄そのものの作成判断ロジックを追加 233 * @og.rev 3.5.6.2 (2004/07/05) makeFormat 処理をcreate メソッドの頭に移動 234 * @og.rev 3.5.6.5 (2004/08/09) thead に、id="header" を追加 235 * @og.rev 4.0.0.0 (2005/01/31) DBColumn の 属性(CLS_NM)から、DBTYPEに変更 236 * 237 * @return テーブルのタグ文字列 238 */ 239 @Override 240 protected String getTableHead() { 241 242 StringBuilder buf = new StringBuilder( HybsSystem.BUFFER_MIDDLE ); 243 // 3.5.5.0 (2004/03/12) No 欄そのものの作成判断追加 244 if( isNumberDisplay() ) { 245 buf.append("<colgroup class=\"X\" />"); // 4.0.0 (2005/01/31) 246 buf.append("<colgroup class=\"BIT\" />"); 247 buf.append("<colgroup class=\"S9\" />"); // 4.0.0 (2005/01/31) 248 buf.append(HybsSystem.CR); 249 } 250 251 // 3.5.2.0 (2003/10/20) ヘッダー繰り返し部をgetHeadLine()へ移動 252 buf.append("<thead id=\"header\">").append( HybsSystem.CR ); // 3.5.6.5 (2004/08/09) 253 buf.append( getHeadLine() ); 254 buf.append("</thead>").append( HybsSystem.CR ); 255 256 return buf.toString(); 257 } 258 259 /** 260 * ヘッダー繰り返し部を、getTableHead()メソッドから分離。 261 * 262 * @og.rev 3.5.6.2 (2004/07/05) HTMLCustomTableScrollBar 用に新規作成 263 * 264 * @return テーブルのタグ文字列 265 */ 266 @Override 267 protected String getHeadLine() { 268 return getHeadLine( "<th" ) ; 269 } 270 271 /** 272 * ヘッダー繰り返し部を、getTableHead()メソッドから分離。 273 * 274 * @og.rev 3.5.2.0 (2003/10/20) 新規作成 275 * @og.rev 3.5.4.0 (2003/11/25) TableFormatter クラスを使用するように変更。 276 * @og.rev 3.5.4.3 (2004/01/05) useCheckControl 属性の機能を追加 277 * @og.rev 3.5.4.6 (2004/01/30) numberType="none" 時の処理を追加(Noラベルを出さない) 278 * @og.rev 3.5.4.7 (2004/02/06) ヘッダーにソート機能用のリンクを追加します。 279 * @og.rev 3.5.5.0 (2004/03/12) systemFormat(例:[KEY.カラム名]形式等)の対応 280 * @og.rev 3.5.5.0 (2004/03/12) No 欄そのものの作成判断ロジックを追加 281 * @og.rev 3.5.6.2 (2004/07/05) HTMLCustomTableScrollBar 用に引数追加 282 * @og.rev 3.7.0.1 (2005/01/31) 全件チェックコントロール処理変更 283 * 284 * @param thTag タグの文字列 285 * 286 * @return テーブルのタグ文字列 287 */ 288 @Override 289 protected String getHeadLine( final String thTag ) { 290 if( headerLine != null ) { return headerLine; } // キャッシュを返す。 291 292 StringBuilder buf = new StringBuilder( HybsSystem.BUFFER_MIDDLE ); 293 294 buf.append( headerFormat.getTrTag() ).append( HybsSystem.CR ); 295 296 // 3.5.5.0 (2004/03/12) No 欄そのものの作成判断追加 297 if( isNumberDisplay() ) { 298 // 3.5.4.3 (2004/01/05) 追加分 299 if( isUseCheckControl() && "checkbox".equals( getSelectedType() ) ) { 300 buf.append( thTag ).append( headerFormat.getRowspan() ).append("></th>"); 301 buf.append( thTag ).append( headerFormat.getRowspan() ); 302 buf.append(">").append( getAllCheckControl() ).append( "</th>"); 303 buf.append( thTag ).append( headerFormat.getRowspan() ); 304 buf.append(">").append( getNumberHeader() ).append("</th>"); // 3.5.4.6 (2004/01/30) 305 } 306 else { 307 buf.append( thTag ).append(" colspan=\"3\""); 308 buf.append( headerFormat.getRowspan() ); 309 buf.append(">").append( getNumberHeader() ).append("</th>"); // 3.5.4.6 (2004/01/30) 310 } 311 } 312 313 int cl = 0; 314 for( ; cl < headerFormat.getLocationSize(); cl++ ) { 315 buf.append( StringUtil.replace( headerFormat.getFormat(cl) ,"td","th" )); 316 int loc = headerFormat.getLocation(cl); 317 if( loc >= 0 ) { buf.append( getSortedColumnLabel(loc) ); } 318 } 319 buf.append( StringUtil.replace( headerFormat.getFormat(cl) ,"td","th" ) ).append( HybsSystem.CR ); 320 321 headerLine = buf.toString(); 322 return headerLine; 323 } 324 325 /** 326 * DBTableModel から テーブルのタグ文字列を作成して返します。 327 * 328 * @og.rev 3.5.0.0 (2003/09/17) <tr>属性は、元のフォーマットのまま使用します。 329 * @og.rev 3.5.1.0 (2003/10/03) Noカラムに、numberType 属性を追加 330 * @og.rev 3.5.4.0 (2003/11/25) TableFormatter クラスを使用するように変更。 331 * @og.rev 3.5.4.7 (2004/02/06) ヘッダーにソート機能用のリンクを追加します。 332 * @og.rev 3.5.5.0 (2004/03/12) systemFormat(例:[KEY.カラム名]形式等)の対応 333 * @og.rev 3.5.5.0 (2004/03/12) No 欄そのものの作成判断ロジックを追加 334 * 335 * @return テーブルのタグ文字列 336 */ 337 protected String getTableFoot() { 338 footerFormat.makeFormat( getDBTableModel() ); 339 340 StringBuilder buf = new StringBuilder( HybsSystem.BUFFER_MIDDLE ); 341 342 buf.append("<tfoot>").append( HybsSystem.CR ); 343 buf.append( footerFormat.getTrTag() ).append( HybsSystem.CR ); 344 345 // 3.5.5.0 (2004/03/12) No 欄そのものの作成判断追加 346 if( isNumberDisplay() ) { 347 buf.append(" <th"); 348 buf.append(" colspan=\"3\""); 349 buf.append( footerFormat.getRowspan() ); 350 buf.append("></th>"); 351 } 352 353 int cl = 0; 354 for( ; cl < footerFormat.getLocationSize(); cl++ ) { 355 int loc = footerFormat.getLocation(cl); 356 if( loc >= 0 ) { buf.append( getSortedColumnLabel(loc) ); } 357 } 358 buf.append( footerFormat.getFormat(cl) ).append( HybsSystem.CR ); 359 buf.append("</tfoot>").append( HybsSystem.CR ); 360 361 return buf.toString(); 362 } 363 364 /** 365 * フォーマットを設定します。 366 * 367 * @og.rev 3.5.4.0 (2003/11/25) 新規作成 368 * @og.rev 3.5.4.4 (2004/01/16) 配列の最大数を変更 369 * @og.rev 3.5.5.5 (2004/04/23) headerFormat が定義されていない場合はエラー 370 * 371 * @param list TableFormatterのリスト 372 */ 373 @Override 374 public void setFormatterList( final List<TableFormatter> list ) { // 4.3.3.6 (2008/11/15) Generics警告対応 375 bodyFormats = new TableFormatter[BODYFORMAT_MAX_COUNT]; 376 377 bodyFormatsCount = 0; 378 for( int i=0; i<list.size(); i++ ) { 379 TableFormatter format = list.get( i ); // 4.3.3.6 (2008/11/15) Generics警告対応 380 381 switch( format.getFormatType() ) { 382 case TYPE_HEAD : headerFormat = format; break; 383 case TYPE_BODY : bodyFormats[bodyFormatsCount++] = format; break; 384 case TYPE_FOOT : footerFormat = format; break; 385 default : String errMsg = "FormatterType の定義外の値が指定されました。"; 386 // 4.3.4.4 (2009/01/01) 387 throw new HybsSystemException( errMsg ); 388 } 389 } 390 391 // 3.5.5.5 (2004/04/23) headerFormat が定義されていない場合はエラー 392 if( headerFormat == null ) { 393 String errMsg = "h:thead タグの、フォーマットの指定は必須です。"; 394 throw new HybsSystemException( errMsg ); 395 } 396 } 397 398 /** 399 * フォーマットメソッドを使用できるかどうかを問い合わせます。 400 * 401 * @return 使用可能(true)/ 使用不可能 (false) 402 */ 403 @Override 404 public boolean canUseFormat() { 405 return true; 406 } 407 408 /** 409 * ビューで表示したカラムの一覧をカンマ区切りで返します。 410 * 411 * @og.rev 5.1.6.0 (2010/05/01) 新規追加 412 * 413 * @return ビューで表示したカラムの一覧 414 */ 415 @Override 416 public String getViewClms() { 417 DBTableModel table = getDBTableModel(); 418 StringBuilder buf = new StringBuilder( HybsSystem.BUFFER_MIDDLE ); 419 for( int i=0; i<headerFormat.getLocationSize(); i++ ) { 420 if( buf.length() > 0 ) { buf.append( ',' ); } 421 buf.append( table.getColumnName( headerFormat.getLocation( i ) ) ); 422 } 423 return buf.toString(); 424 } 425}