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