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