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 * @og.rev 5.9.14.3 (2016/11/25) editでの表示順変更に対応 151 * 152 * @return テーブルのタグ文字列 153 */ 154 @Override 155 protected String getTableHead() { 156 StringBuilder buf = new StringBuilder( HybsSystem.BUFFER_MIDDLE ); 157 158 // 5.9.3.3 (2015/12/26) HTML5 で colgroup が効かない対応 159 // 互換モードでない場合専用。処理速度を気にするより、処理を一か所にまとめておきます。 160 if( !useIE7Header ) { 161 buf.append( "<style type=\"text/css\">" ) 162 .append( HybsSystem.CR ); 163 int ad ; 164 if( isNumberDisplay() ) { 165 makeNthChild( buf,2,"BIT" ); 166 makeNthChild( buf,3,"S9" ); 167 ad = 4; 168 } 169 else { 170 ad = 1; 171 } 172 173// final int clmCnt = getColumnCount(); 174// for( int column=0; column<clmCnt; column++ ) { 175 for( int clm=0; clm<clmCnt; clm++ ) { // 5.9.14.3 (2016/11/25) 表示順変更に対応していなかった 176 int column = clmNo[clm]; 177 if( isColumnDisplay( column ) ) { 178 makeNthChild( buf,ad,getColumnDbType(column) ); 179 ad++ ; // tdタグの順番なので、表示する場合のみカウントする。 180 } 181 } 182 buf.append( "</style>" ) 183 .append( HybsSystem.CR ); 184 } 185 186 // 3.5.5.0 (2004/03/12) No 欄そのものの作成判断追加 187 if( isNumberDisplay() ) { 188// buf.append("<colgroup class=\"X\" />"); // 4.0.0 (2005/01/31) 189// buf.append("<colgroup class=\"BIT\" />"); 190// buf.append("<colgroup class=\"S9\" />"); // 4.0.0 (2005/01/31) 191 buf.append("<colgroup class=\"X\" ><!-- --></colgroup>"); // 5.9.1.2 (2015/10/23) 192 buf.append("<colgroup class=\"BIT\" ><!-- --></colgroup>"); 193 buf.append("<colgroup class=\"S9\" ><!-- --></colgroup>"); 194 buf.append( HybsSystem.CR ); 195 } 196 197// int clmCnt = getColumnCount(); // 3.5.5.7 (2004/05/10) 198 // 5.1.6.0 (2010/05/01) 199// for(int column = 0; column < clmCnt; column++) { 200 for(int clm = 0; clm < clmCnt; clm++) { 201 int column = clmNo[clm]; 202 if( isColumnDisplay( column ) ) { 203 buf.append("<colgroup class=\"" ); 204 buf.append( getColumnDbType(column) ); // 4.0.0 (2005/01/31) 205// buf.append("\"/>"); 206 buf.append("\"><!-- --></colgroup>"); // 5.9.1.2 (2015/10/23) 207 buf.append( HybsSystem.CR ); 208 } 209 } 210 211 // 3.5.2.0 (2003/10/20) ヘッダー繰り返し部をgetHeadLine()へ移動 212 buf.append("<thead id=\"header\">").append( HybsSystem.CR ); // 3.5.6.5 (2004/08/09) 213 buf.append( getHeadLine() ); 214 buf.append("</thead>").append( HybsSystem.CR ); 215 216 return buf.toString(); 217 } 218 219 /** 220 * ヘッダー繰り返し部を、getTableHead()メソッドから分離。 221 * 222 * @og.rev 3.5.2.0 (2003/10/20) 新規作成 223 * @og.rev 3.5.4.3 (2004/01/05) useCheckControl 属性の機能を追加 224 * @og.rev 3.5.4.5 (2004/01/23) thタグの属性設定出来る様に新規追加。 225 * @og.rev 3.5.4.6 (2004/01/30) numberType="none" 時の処理を追加(Noラベルを出さない) 226 * @og.rev 3.5.4.7 (2004/02/06) ヘッダーにソート機能用のリンクを追加します。 227 * @og.rev 3.7.0.1 (2005/01/31) 全件チェックコントロール処理変更 228 * 229 * @param thTag タグの文字列 230 * 231 * @return テーブルのタグ文字列 232 */ 233 @Override 234 protected String getHeadLine( final String thTag ) { 235 if( headerLine != null ) { return headerLine; } // キャッシュを返す。 236 237 StringBuilder buf = new StringBuilder( HybsSystem.BUFFER_MIDDLE ); 238 239// buf.append("<tr class=\"row_h\"").append(" >").append( HybsSystem.CR ); 240 buf.append("<tr class=\"row_hu\"").append(" >").append( HybsSystem.CR ); 241 242 // 3.5.5.0 (2004/03/12) No 欄そのものの作成判断追加 243 if( isNumberDisplay() ) { 244 // 3.5.4.3 (2004/01/05) 追加分 245 if( isUseCheckControl() && "checkbox".equals( getSelectedType() ) ) { 246 // 3.5.4.5 (2004/01/23) thタグの属性設定出来る様に変更。 247 buf.append( thTag ).append("></th>"); 248 buf.append( thTag ).append(">").append( getAllCheckControl() ).append("</th>"); 249 buf.append( thTag ).append(">").append( getNumberHeader() ).append("</th>"); // 3.5.4.6 (2004/01/30) 250 } 251 else { 252 // 3.5.4.5 (2004/01/23) thタグの属性設定出来る様に変更。 253 buf.append( thTag ).append(" colspan='3'>").append( getNumberHeader() ).append("</th>"); // 3.5.4.6 (2004/01/30) 254 } 255 } 256 257 buf.append( HybsSystem.CR ); 258// int clmCnt = getColumnCount(); // 3.5.5.7 (2004/05/10) 259 // 5.1.6.0 (2010/05/01) 260// for(int column = 0; column < clmCnt; column++) { 261 for(int clm = 0; clm < clmCnt; clm++) { 262 int column = clmNo[clm]; 263 if( isColumnDisplay( column ) ) { 264 // 3.5.4.5 (2004/01/23) thタグの属性設定出来る様に変更。 265 buf.append( thTag ).append(">"); 266 buf.append( getSortedColumnLabel(column) ); 267 buf.append("</th>").append( HybsSystem.CR ); 268 } 269 } 270 buf.append("</tr>").append( HybsSystem.CR ); 271 272 headerLine = buf.toString(); 273 return headerLine; 274 } 275 276 /** 277 * 表示可能カラム名を、カンマ区切りで与えます。 278 * 例:"OYA,KO,HJO,SU,DYSET,DYUPD" 279 * setColumnDisplay( int column,boolean rw ) の簡易版です。 280 * null を与えた場合は,なにもしません。 281 * 282 * @param columnName カラム名 283 */ 284 @Override 285 public void setColumnDisplay( final String columnName ) { 286 super.setColumnDisplay( columnName ); 287 288 if( columnName != null ) { 289 String[] clmNames = StringUtil.csv2Array( columnName ); 290 clmCnt = clmNames.length; 291 clmNo = new int[clmCnt]; 292 for( int i=0; i<clmCnt; i++ ) { 293 clmNo[i] = getColumnNo( clmNames[i] ); 294 } 295 } 296 this.viewClms = columnName; 297 } 298 299 /** 300 * ビューで表示したカラムの一覧をカンマ区切りで返します。 301 * 302 * @og.rev 5.1.6.0 (2010/05/01) 新規追加 303 * @og.rev 5.8.6.0 (2015/04/03) オリジナルカラム対応 304 * 305 * @return ビューで表示したカラムの一覧 306 */ 307 @Override 308 public String getViewClms() { 309 if( viewClms == null ) { return super.getViewClms(); } // 5.8.6.0 (2015/04/03) 310 return viewClms; 311 } 312}