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.fukurou.util.StringUtil; 019import org.opengion.hayabusa.common.HybsSystem; 020import org.opengion.hayabusa.common.HybsSystemException; 021 022/** 023 * 検索結果を自動的に表形式に変換する、テーブル作成クラスです。 024 * 025 * ユーザー単位に表示するカラムの順番、表示可非を指定できるように対応します。 026 * setColumnDisplay( final String columnName ) に、指定された順番に 027 * 表示するというHTMLFormatTable の簡易版として用意します。 028 * 各HTMLのタグに必要な setter/getterメソッドのみ,追加定義しています。 029 * 030 * AbstractViewForm を継承している為,ロケールに応じたラベルを出力させる事が出来ます。 031 * 032 * @og.group 画面表示 033 * @og.rev 5.1.6.0 (2010/05/01) 新規作成 034 * 035 * @version 4.0 036 * @author Kazuhiko Hasegawa 037 * @since JDK5.0, 038 */ 039public class ViewForm_HTMLSeqClmTable extends ViewForm_HTMLTable { 040 //* このプログラムのVERSION文字列を設定します。 {@value} */ 041 private static final String VERSION = "5.5.4.2 (2012/07/13)" ; 042 043 private int[] clmNo = null; // 5.1.6.0 (2010/05/01) 044 private int clmCnt = -1; // 5.1.6.0 (2010/05/01) 045 046 private String viewClms = null; // 047 048 /** 049 * DBTableModel から HTML文字列を作成して返します。 050 * startNo(表示開始位置)から、pageSize(表示件数)までのView文字列を作成します。 051 * 表示残りデータが pageSize 以下の場合は,残りのデータをすべて出力します。 052 * 053 * @og.rev 5.5.4.2 (2012/07/13) editName指定時の編集対応 054 * 055 * @param startNo 表示開始位置 056 * @param pageSize 表示件数 057 * 058 * @return DBTableModelから作成された HTML文字列 059 */ 060 @Override 061 public String create( final int startNo, final int pageSize ) { 062 if( getRowCount() == 0 ) { return ""; } // 暫定処置 063 064 if( clmCnt < 0 ) { 065 String errMsg = "ViewForm_HTMLSeqClmTable クラスの実行前に、setColumnDisplay しておく必要があります。"; 066 throw new HybsSystemException( errMsg ); 067 } 068 069 headerLine = null; 070 int lastNo = getLastNo( startNo, pageSize ); 071 int blc = getBackLinkCount(); 072 int hsc = getHeaderSkipCount(); // 3.5.2.0 (2003/10/20) 073 int hscCnt = 1; // 3.5.2.0 (2003/10/20) 074 075 StringBuilder out = new StringBuilder( HybsSystem.BUFFER_LARGE ); 076 077 out.append( getCountForm( startNo,pageSize ) ); 078 out.append( getHeader() ); 079 080 String ckboxTD = " <td>"; 081 082 out.append("<tbody>").append( HybsSystem.CR ); 083 int bgClrCnt = 0; 084// int clmCnt = getColumnCount(); // 3.5.5.7 (2004/05/10) 085 for( int row=startNo; row<lastNo; row++ ) { 086 if( isSkip( row ) || isSkipNoEdit( row ) ) { continue; } // 4.3.1.0 (2008/09/08) 087 out.append("<tr").append( getBgColorCycleClass( bgClrCnt++,row ) ); 088 if( isNoTransition() ) { // 4.3.3.0 (2008/10/01) 089 out.append( getHiddenRowValue( row ) ); 090 } 091 out.append(">"); // 3.7.0.3 (2005/03/01) 092 out.append( HybsSystem.CR ); 093 // 3.5.5.0 (2004/03/12) No 欄そのものの作成判断追加 094 if( isNumberDisplay() ) { 095 out.append( makeCheckbox( ckboxTD, row, blc ) ).append( HybsSystem.CR ); 096 } 097 // 5.1.6.0 (2010/05/01) 098// for(int column = 0; column < clmCnt; column++) { 099 for(int clm = 0; clm < clmCnt; clm++) { 100 int column = clmNo[clm]; 101 if( isColumnDisplay( column ) ) { 102 out.append(" <td>"); 103 out.append( getValueLabel(row,column) ); 104 out.append("</td>").append( HybsSystem.CR ); 105 } 106 } 107 108 109 // 5.5.4.2 (2012/07/13) mustとmuntAnyでwritableのものはdisplay:noneで出力する(可能な限り余分なものは出力しない) 110 for(int column = 0; column < clmCnt; column++) { 111 if( !isColumnDisplay( column ) && ( isMustColumn( column ) || isMustAnyColumn(column) ) && isColumnWritable( column) ) { 112 out.append(" <td style=\"display:none\">"); 113 out.append( getValueLabel(row,column) ); 114 out.append("</td>").append( HybsSystem.CR ); 115 } 116 } 117 118 119 out.append("</tr>").append( HybsSystem.CR ); 120 121 // 3.5.2.0 (2003/10/20) ヘッダー繰り返し属性( headerSkipCount )を採用 122 if( hsc > 0 && hscCnt % hsc == 0 ) { 123 out.append( getHeadLine() ); 124 hscCnt = 1; 125 } 126 else { 127 hscCnt ++ ; 128 } 129 } 130 out.append("</tbody>").append( HybsSystem.CR ); 131 out.append("</table>").append( HybsSystem.CR ); 132 133 out.append( getScrollBarEndDiv() ); // 3.8.0.3 (2005/07/15) 134 135 return out.toString(); 136 } 137 138 /** 139 * DBTableModel から テーブルのタグ文字列を作成して返します。 140 * 141 * @og.rev 3.5.1.0 (2003/10/03) Noカラムに、numberType 属性を追加 142 * @og.rev 3.5.2.0 (2003/10/20) ヘッダー繰り返し部をgetHeadLine()へ移動 143 * @og.rev 3.5.3.1 (2003/10/31) VERCHAR2 を VARCHAR2 に修正。 144 * @og.rev 3.5.5.0 (2004/03/12) No 欄そのものの作成判断ロジックを追加 145 * @og.rev 3.5.6.5 (2004/08/09) thead に、id="header" を追加 146 * @og.rev 4.0.0.0 (2005/01/31) DBColumn の 属性(CLS_NM)から、DBTYPEに変更 147 * @og.rev 4.0.0.0 (2005/01/31) 新規作成(getColumnClassName ⇒ getColumnDbType) 148 * @og.rev 5.9.1.2 (2015/10/23) 自己終了警告対応 149 * @og.rev 5.9.3.3 (2015/12/26) colgroup対応 150 * 151 * @return テーブルのタグ文字列 152 */ 153 @Override 154 protected String getTableHead() { 155 StringBuilder buf = new StringBuilder( HybsSystem.BUFFER_MIDDLE ); 156 157 // 5.9.3.3 (2015/12/26) HTML5 で colgroup が効かない対応 158 // 互換モードでない場合専用。処理速度を気にするより、処理を一か所にまとめておきます。 159 if( !useIE7Header ) { 160 buf.append( "<style type=\"text/css\">" ) 161 .append( HybsSystem.CR ); 162 int ad ; 163 if( isNumberDisplay() ) { 164 makeNthChild( buf,2,"BIT" ); 165 makeNthChild( buf,3,"S9" ); 166 ad = 4; 167 } 168 else { 169 ad = 1; 170 } 171 172 final int clmCnt = getColumnCount(); 173 for( int column=0; column<clmCnt; column++ ) { 174 if( isColumnDisplay( column ) ) { 175 makeNthChild( buf,ad,getColumnDbType(column) ); 176 ad++ ; // tdタグの順番なので、表示する場合のみカウントする。 177 } 178 } 179 buf.append( "</style>" ) 180 .append( HybsSystem.CR ); 181 } 182 183 // 3.5.5.0 (2004/03/12) No 欄そのものの作成判断追加 184 if( isNumberDisplay() ) { 185// buf.append("<colgroup class=\"X\" />"); // 4.0.0 (2005/01/31) 186// buf.append("<colgroup class=\"BIT\" />"); 187// buf.append("<colgroup class=\"S9\" />"); // 4.0.0 (2005/01/31) 188 buf.append("<colgroup class=\"X\" ><!-- --></colgroup>"); // 5.9.1.2 (2015/10/23) 189 buf.append("<colgroup class=\"BIT\" ><!-- --></colgroup>"); 190 buf.append("<colgroup class=\"S9\" ><!-- --></colgroup>"); 191 buf.append( HybsSystem.CR ); 192 } 193 194// int clmCnt = getColumnCount(); // 3.5.5.7 (2004/05/10) 195 // 5.1.6.0 (2010/05/01) 196// for(int column = 0; column < clmCnt; column++) { 197 for(int clm = 0; clm < clmCnt; clm++) { 198 int column = clmNo[clm]; 199 if( isColumnDisplay( column ) ) { 200 buf.append("<colgroup class=\"" ); 201 buf.append( getColumnDbType(column) ); // 4.0.0 (2005/01/31) 202// buf.append("\"/>"); 203 buf.append("\"><!-- --></colgroup>"); // 5.9.1.2 (2015/10/23) 204 buf.append( HybsSystem.CR ); 205 } 206 } 207 208 // 3.5.2.0 (2003/10/20) ヘッダー繰り返し部をgetHeadLine()へ移動 209 buf.append("<thead id=\"header\">").append( HybsSystem.CR ); // 3.5.6.5 (2004/08/09) 210 buf.append( getHeadLine() ); 211 buf.append("</thead>").append( HybsSystem.CR ); 212 213 return buf.toString(); 214 } 215 216 /** 217 * ヘッダー繰り返し部を、getTableHead()メソッドから分離。 218 * 219 * @og.rev 3.5.2.0 (2003/10/20) 新規作成 220 * @og.rev 3.5.4.3 (2004/01/05) useCheckControl 属性の機能を追加 221 * @og.rev 3.5.4.5 (2004/01/23) thタグの属性設定出来る様に新規追加。 222 * @og.rev 3.5.4.6 (2004/01/30) numberType="none" 時の処理を追加(Noラベルを出さない) 223 * @og.rev 3.5.4.7 (2004/02/06) ヘッダーにソート機能用のリンクを追加します。 224 * @og.rev 3.7.0.1 (2005/01/31) 全件チェックコントロール処理変更 225 * 226 * @param thTag タグの文字列 227 * 228 * @return テーブルのタグ文字列 229 */ 230 @Override 231 protected String getHeadLine( final String thTag ) { 232 if( headerLine != null ) { return headerLine; } // キャッシュを返す。 233 234 StringBuilder buf = new StringBuilder( HybsSystem.BUFFER_MIDDLE ); 235 236// buf.append("<tr class=\"row_h\"").append(" >").append( HybsSystem.CR ); 237 buf.append("<tr class=\"row_hu\"").append(" >").append( HybsSystem.CR ); 238 239 // 3.5.5.0 (2004/03/12) No 欄そのものの作成判断追加 240 if( isNumberDisplay() ) { 241 // 3.5.4.3 (2004/01/05) 追加分 242 if( isUseCheckControl() && "checkbox".equals( getSelectedType() ) ) { 243 // 3.5.4.5 (2004/01/23) thタグの属性設定出来る様に変更。 244 buf.append( thTag ).append("></th>"); 245 buf.append( thTag ).append(">").append( getAllCheckControl() ).append("</th>"); 246 buf.append( thTag ).append(">").append( getNumberHeader() ).append("</th>"); // 3.5.4.6 (2004/01/30) 247 } 248 else { 249 // 3.5.4.5 (2004/01/23) thタグの属性設定出来る様に変更。 250 buf.append( thTag ).append(" colspan='3'>").append( getNumberHeader() ).append("</th>"); // 3.5.4.6 (2004/01/30) 251 } 252 } 253 254 buf.append( HybsSystem.CR ); 255// int clmCnt = getColumnCount(); // 3.5.5.7 (2004/05/10) 256 // 5.1.6.0 (2010/05/01) 257// for(int column = 0; column < clmCnt; column++) { 258 for(int clm = 0; clm < clmCnt; clm++) { 259 int column = clmNo[clm]; 260 if( isColumnDisplay( column ) ) { 261 // 3.5.4.5 (2004/01/23) thタグの属性設定出来る様に変更。 262 buf.append( thTag ).append(">"); 263 buf.append( getSortedColumnLabel(column) ); 264 buf.append("</th>").append( HybsSystem.CR ); 265 } 266 } 267 buf.append("</tr>").append( HybsSystem.CR ); 268 269 headerLine = buf.toString(); 270 return headerLine; 271 } 272 273 /** 274 * 表示可能カラム名を、カンマ区切りで与えます。 275 * 例:"OYA,KO,HJO,SU,DYSET,DYUPD" 276 * setColumnDisplay( int column,boolean rw ) の簡易版です。 277 * null を与えた場合は,なにもしません。 278 * 279 * @param columnName カラム名 280 */ 281 @Override 282 public void setColumnDisplay( final String columnName ) { 283 super.setColumnDisplay( columnName ); 284 285 if( columnName != null ) { 286 String[] clmNames = StringUtil.csv2Array( columnName ); 287 clmCnt = clmNames.length; 288 clmNo = new int[clmCnt]; 289 for( int i=0; i<clmCnt; i++ ) { 290 clmNo[i] = getColumnNo( clmNames[i] ); 291 } 292 } 293 this.viewClms = columnName; 294 } 295 296 /** 297 * ビューで表示したカラムの一覧をカンマ区切りで返します。 298 * 299 * @og.rev 5.1.6.0 (2010/05/01) 新規追加 300 * @og.rev 5.8.6.0 (2015/04/03) オリジナルカラム対応 301 * 302 * @return ビューで表示したカラムの一覧 303 */ 304 @Override 305 public String getViewClms() { 306 if( viewClms == null ) { return super.getViewClms(); } // 5.8.6.0 (2015/04/03) 307 return viewClms; 308 } 309}