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