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.db.DBTableModel;
020 import org.opengion.hayabusa.html.AbstractViewForm;
021 import org.opengion.fukurou.model.Formatter;
022 import org.opengion.fukurou.util.StringUtil;
023
024 /**
025 * 検索結果を?動的に表形式に変換する、テーブル作?クラスです?
026 *
027 * AbstractViewForm により、setter/getterメソ?の?ォルト実?提供して?す?
028 * 各HTMLのタグに?な setter/getterメソ?のみ?追?義して?す?
029 *
030 * AbstractViewForm を継承して?為,ロケールに応じたラベルを?力させる事が出来ます?
031 *
032 * @og.group 画面表示
033 *
034 * @version 4.0
035 * @author Kazuhiko Hasegawa
036 * @since JDK5.0,
037 */
038 public class ViewForm_HTMLTable extends AbstractViewForm {
039 //* こ?プログラ??VERSION??を設定します? {@value} */
040 private static final String VERSION = "5.3.4.0 (2011/04/01)" ;
041
042 // private String caption = null; // 表のタイトル 5.1.6.0 (2010/05/01) 削除
043 private String cacheTag = null; // 3.5.5.5 (2004/04/23)
044 private boolean isCache = false; // 3.5.5.5 (2004/04/23)
045 private int[] popupClmNo = null; // 3.8.6.1 (2006/10/20)
046
047 // protected int[] rowNo = null; // 5.1.6.0 (2010/05/01) 削除
048 /** ヘッ??部??キャ?ュ変数 */
049 protected String headerLine = null; // 3.5.2.0 (2003/10/20)
050
051 private final boolean useRowId = HybsSystem.sysBool( "USE_CHECKBOX_ROW_ID" ) ; // 3.6.0.0 (2004/09/17)
052
053 // 5.2.3.0 (2010/12/01) ??ブル罫線対?
054 private final String tableParam = HybsSystem.sys( "HTML_TABLE_PARAM" ) ;
055
056 // 3.6.0.0 (2004/09/17) チェ?済みの行?先?に、フォーカスを当てる??
057 private static final String LAYER_FOCUS = "<a href=\"#top\" name=\"h_fcs\" id=\"h_fcs\" ></a>" ;
058
059 // 4.3.4.4 (2009/01/01)
060 // /**
061 // * ?ォルトコンストラクター
062 // *
063 // */
064 // public ViewForm_HTMLTable() {
065 // super();
066 // super.clear();
067 // }
068
069 /**
070 * ?をクリア(初期?します?
071 *
072 * @og.rev 3.1.1.0 (2003/03/28) 同期メソ?(synchronized付き)を非同期に変更する?
073 * @og.rev 3.5.2.0 (2003/10/20) ヘッ??繰り返し属?( headerSkipCount )を採用
074 * @og.rev 3.5.5.5 (2004/04/23) cacheTag,isCache 属?追?チェ?ボックス作?用)
075 * @og.rev 3.5.6.2 (2004/07/05) bgColorCycle 変数の削除?
076 * @og.rev 3.8.6.1 (2006/10/20) popup の値を返す為のカラ?号配?(popupClmNo)追?
077 * @og.rev 5.1.6.0 (2010/05/01) caption 属?が使われて??め?削除する?
078 */
079 @Override
080 public void clear() {
081 super.clear();
082 // caption = null; // 表のタイトル
083 cacheTag = null; // 3.5.5.5 (2004/04/23)
084 isCache = false; // 3.5.5.5 (2004/04/23)
085 popupClmNo = null; // 3.8.6.1 (2006/10/20)
086 }
087
088 /**
089 * DBTableModel から HTML??を作?して返します?
090 * startNo(表示開始位置)から、pageSize(表示件数)までのView??を作?します?
091 * 表示残り??タ?pageSize 以下?場合?,残りの??タをすべて出力します?
092 *
093 * @og.rev 3.5.2.0 (2003/10/20) ヘッ??繰り返し属?( headerSkipCount )を採用
094 * @og.rev 3.5.3.1 (2003/10/31) skip属?を採用。headerLine のキャ?ュクリア
095 * @og.rev 3.5.5.0 (2004/03/12) No ?のも?の作?判断ロジ?を追?
096 * @og.rev 3.5.6.4 (2004/07/16) ヘッ??とボディー部をJavaScriptで?
097 * @og.rev 3.7.0.3 (2005/03/01) getBgColorCycleClass に?択行?ーカーを採用
098 * @og.rev 4.3.1.0 (2008/09/08) 編??みを表示する属?(isSkipNoEdit)追?
099 * @og.rev 4.3.3.0 (2008/10/01) noTransition属?対?
100 *
101 * @param startNo 表示開始位置
102 * @param pageSize 表示件数
103 *
104 * @return DBTableModelから作?され?HTML??
105 */
106 public String create( final int startNo, final int pageSize ) {
107 if( getRowCount() == 0 ) { return ""; } // 暫定?置
108
109 headerLine = null;
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 out.append( getCountForm( startNo,pageSize ) );
118 out.append( getHeader() );
119
120 String ckboxTD = " <td>";
121
122 out.append("<tbody>").append( HybsSystem.CR );
123 int bgClrCnt = 0;
124 int clmCnt = getColumnCount(); // 3.5.5.7 (2004/05/10)
125 for( int row=startNo; row<lastNo; row++ ) {
126 // if( isSkip( row ) ) { continue; } // 3.5.3.1 (2003/10/31)
127 if( isSkip( row ) || isSkipNoEdit( row ) ) { continue; } // 4.3.1.0 (2008/09/08)
128 out.append("<tr").append( getBgColorCycleClass( bgClrCnt++,row ) );
129 if( isNoTransition() ) { // 4.3.3.0 (2008/10/01)
130 out.append( getHiddenRowValue( row ) );
131 }
132 out.append(">"); // 3.7.0.3 (2005/03/01)
133 out.append( HybsSystem.CR );
134 // 3.5.5.0 (2004/03/12) No ?のも?の作?判断追?
135 if( isNumberDisplay() ) {
136 out.append( makeCheckbox( ckboxTD, row, blc ) ).append( HybsSystem.CR );
137 }
138 for(int column = 0; column < clmCnt; column++) {
139 if( isColumnDisplay( column ) ) {
140 out.append(" <td>");
141 out.append( getValueLabel(row,column) );
142 out.append("</td>").append( HybsSystem.CR );
143 }
144 }
145 out.append("</tr>").append( HybsSystem.CR );
146
147 // 3.5.2.0 (2003/10/20) ヘッ??繰り返し属?( headerSkipCount )を採用
148 if( hsc > 0 && hscCnt % hsc == 0 ) {
149 out.append( getHeadLine() );
150 hscCnt = 1;
151 }
152 else {
153 hscCnt ++ ;
154 }
155 }
156 out.append("</tbody>").append( HybsSystem.CR );
157 out.append("</table>").append( HybsSystem.CR );
158
159 out.append( getScrollBarEndDiv() ); // 3.8.0.3 (2005/07/15)
160
161 return out.toString();
162 }
163
164 /**
165 * 選択用のチェ?ボックスと行番号と変更タイ?A,C,D)を表示します?
166 *
167 * @og.rev 3.5.1.0 (2003/10/03) Noカラ?、numberType 属?を追?
168 * @og.rev 3.5.4.0 (2003/11/25) Formatter をローカル変数に変更
169 * @og.rev 3.5.4.1 (2003/12/01) table オブジェクト?セ??
170 * @og.rev 3.5.5.5 (2004/04/23) Attributes オブジェクト?セ??
171 * @og.rev 3.6.0.0 (2004/09/17) ガントチャート?移動時にチェ?するためのIDを追?
172 * @og.rev 3.6.0.0 (2004/09/17) チェ?済みの行?先?に、フォーカスを当てる??追?
173 * @og.rev 3.8.6.1 (2006/10/20) popup 用の値を設定する機?を追?
174 *
175 * @param ckboxTD チェ?ボックスのタグ(マルチカラ?のrowspan対?
176 * @param row 行番号
177 * @param blc バックラインカウン?先?へ戻るリンク間隔)
178 *
179 * @return tdタグで囲まれたチェ?ボックスのHTML??
180 */
181 protected String makeCheckbox( final String ckboxTD,final int row,final int blc ) {
182 StringBuilder out = new StringBuilder( HybsSystem.BUFFER_MIDDLE );
183
184 DBTableModel table = getDBTableModel() ;
185
186 String opAtt = null;
187 String fmt = getOptionTypeAttributes();
188 if( fmt != null ) {
189 Formatter format = new Formatter( table );
190 format.setFormat( fmt );
191 opAtt = format.getFormatString( row );
192 }
193
194 out.append( ckboxTD );
195 out.append( table.getModifyType( row ) );
196 out.append("</td>");
197 out.append( ckboxTD );
198
199 // 3.5.5.5 (2004/04/23) Attributes オブジェクト?セ??
200 String inputTag = makeChboxTag();
201 if( isWritable( row ) && inputTag != null ) {
202 out.append( inputTag );
203 if( opAtt != null ) { out.append( opAtt ); }
204 if( isChecked( row ) ) {
205 out.append( " checked=\"checked\"" );
206 }
207 if( useRowId ) { // 3.6.0.0 (2004/09/17)
208 out.append( " id=\"" );
209 out.append( HybsSystem.ROW_ID_KEY );
210 out.append( row ).append( "\"" );
211 }
212 if( popupClmNo != null ) { // 3.8.6.1 (2006/10/20)
213 out = makePopupReturn( out,row ); // ?で StringBuilder に append して?す?
214 }
215 out.append( " value=\"" ).append( row ).append( "\" />" );
216 }
217 out.append("</td>");
218 out.append( ckboxTD );
219
220 // 3.5.1.0 (2003/10/03) Noカラ?、numberType 属?を追?
221 if( blc != 0 && (row+1) % blc == 0 ) {
222 out.append( "<a href=\"#top\">" ).append( getNumberData( row ) ).append( "</a>");
223 } else {
224 out.append( getNumberData( row ) );
225 }
226
227 // 4.3.5.3 (2008/02/22) Focus2のアンカー位置をtdタグ?変更
228 if( isFirstChecked( row ) ) {
229 out.append( LAYER_FOCUS );
230 }
231 out.append("</td>");
232 // if( isFirstChecked( row ) ) {
233 // out.insert( 0,LAYER_FOCUS );
234 // }
235
236 return out.toString();
237 }
238
239 /**
240 * DBTableModel から ??ブルのヘッ??タグ??を作?して返します?
241 *
242 * @og.rev 3.5.2.0 (2003/10/20) ヘッ??そ?も?のキャ?ュはしな??
243 *
244 * @return ??ブルのヘッ??タグ??
245 */
246 protected String getHeader() {
247 return getTableTag() + getTableHead() ;
248 }
249
250 /**
251 * DBTableModel から ??ブルのタグ??を作?して返します?
252 *
253 * @og.rev 3.5.6.4 (2004/07/16) ヘッ??とボディー部をJavaScriptで?
254 * @og.rev 3.6.0.0 (2004/09/17) ヘッ??固定スクロールの簡?(スクロールバ?を右に出?
255 * @og.rev 3.6.0.5 (2004/10/18) 印刷時?罫線?力関連機?の追??id 属?を?力します?
256 * @og.rev 4.0.0.0 (2005/08/31) ??ブル表示の CSSファイル利用の有無
257 * @og.rev 5.1.6.0 (2010/05/01) caption 属?が使われて??め?削除する?
258 * @og.rev 5.2.3.0 (2010/12/01) ??ブル罫線対?
259 * @og.rev 5.3.4.0 (2011/04/01) ??ブル罫線?初期値チェ?変更
260 *
261 * @return ??ブルのタグ??
262 */
263 protected String getTableTag() {
264 StringBuilder buf = new StringBuilder( HybsSystem.BUFFER_MIDDLE );
265
266 buf.append( getScrollBarStartDiv() ); // 3.8.0.3 (2005/07/15)
267
268 buf.append("<table ");
269 // 5.2.3.0 (2010/12/01) ??ブル罫線対?
270 // if( tableParam != null ) { // 5.3.4.0 (2011/04/01)
271 if( tableParam != null && !tableParam.isEmpty() ) {
272 buf.append( tableParam );
273 buf.append( " " );
274 }
275 buf.append("id=\"viewTable\" ");
276 buf.append("class=\"").append( getTableClass() ).append( "\"" );
277
278 buf.append(">").append( HybsSystem.CR );
279
280 // if( caption != null ) {
281 // buf.append("<caption>");
282 // buf.append( caption );
283 // buf.append("</caption>").append( HybsSystem.CR );
284 // }
285
286 return buf.toString();
287 }
288
289 /**
290 * DBTableModel から ??ブルのタグ??を作?して返します?
291 *
292 * @og.rev 3.5.1.0 (2003/10/03) Noカラ?、numberType 属?を追?
293 * @og.rev 3.5.2.0 (2003/10/20) ヘッ??繰り返し部をgetHeadLine()へ移?
294 * @og.rev 3.5.3.1 (2003/10/31) VERCHAR2 ?VARCHAR2 に修正?
295 * @og.rev 3.5.5.0 (2004/03/12) No ?のも?の作?判断ロジ?を追?
296 * @og.rev 3.5.6.5 (2004/08/09) thead に、id="header" を追?
297 * @og.rev 4.0.0.0 (2005/01/31) DBColumn の 属?(CLS_NM)から、DBTYPEに変更
298 * @og.rev 4.0.0.0 (2005/01/31) 新規作?(getColumnClassName ?getColumnDbType)
299 *
300 * @return ??ブルのタグ??
301 */
302 protected String getTableHead() {
303 StringBuilder buf = new StringBuilder( HybsSystem.BUFFER_MIDDLE );
304
305 // 3.5.5.0 (2004/03/12) No ?のも?の作?判断追?
306 if( isNumberDisplay() ) {
307 buf.append("<colgroup class=\"X\" />"); // 4.0.0 (2005/01/31)
308 buf.append("<colgroup class=\"BIT\" />");
309 buf.append("<colgroup class=\"S9\" />"); // 4.0.0 (2005/01/31)
310 buf.append( HybsSystem.CR );
311 }
312
313 int clmCnt = getColumnCount(); // 3.5.5.7 (2004/05/10)
314 for(int column = 0; column < clmCnt; column++) {
315 if( isColumnDisplay( column ) ) {
316 buf.append("<colgroup class=\"" );
317 buf.append( getColumnDbType(column) ); // 4.0.0 (2005/01/31)
318 buf.append("\"/>");
319 buf.append( HybsSystem.CR );
320 }
321 }
322
323 // 3.5.2.0 (2003/10/20) ヘッ??繰り返し部をgetHeadLine()へ移?
324 buf.append("<thead id=\"header\">").append( HybsSystem.CR ); // 3.5.6.5 (2004/08/09)
325 buf.append( getHeadLine() );
326 buf.append("</thead>").append( HybsSystem.CR );
327
328 return buf.toString();
329 }
330
331 /**
332 * ヘッ??繰り返し部を?getTableHead()メソ?から??
333 *
334 * @og.rev 3.5.4.5 (2004/01/23) 実?getHeadLine( String thTag )に移?
335 *
336 * @return ??ブルのタグ??
337 */
338 protected String getHeadLine() {
339 return getHeadLine( "<th" ) ;
340 }
341
342 /**
343 * ヘッ??繰り返し部を?getTableHead()メソ?から??
344 *
345 * @og.rev 3.5.2.0 (2003/10/20) 新規作?
346 * @og.rev 3.5.4.3 (2004/01/05) useCheckControl 属?の機?を追?
347 * @og.rev 3.5.4.5 (2004/01/23) thタグの属?設定?来る様に新規追??
348 * @og.rev 3.5.4.6 (2004/01/30) numberType="none" 時?処?追?Noラベルを?さな?
349 * @og.rev 3.5.4.7 (2004/02/06) ヘッ??にソート機?用のリンクを追?ます?
350 * @og.rev 3.7.0.1 (2005/01/31) 全件チェ?コントロール処?更
351 *
352 * @param thTag タグの??
353 *
354 * @return ??ブルのタグ??
355 */
356 protected String getHeadLine( final String thTag ) {
357 if( headerLine != null ) { return headerLine; } // キャ?ュを返す?
358
359 StringBuilder buf = new StringBuilder( HybsSystem.BUFFER_MIDDLE );
360
361 buf.append("<tr class=\"row_h\"").append(" >").append( HybsSystem.CR );
362
363 // 3.5.5.0 (2004/03/12) No ?のも?の作?判断追?
364 if( isNumberDisplay() ) {
365 // 3.5.4.3 (2004/01/05) 追??
366 if( isUseCheckControl() && "checkbox".equals( getSelectedType() ) ) {
367 // 3.5.4.5 (2004/01/23) thタグの属?設定?来る様に変更?
368 buf.append( thTag ).append("></th>");
369 buf.append( thTag ).append(">").append( getAllCheckControl() ).append("</th>");
370 buf.append( thTag ).append(">").append( getNumberHeader() ).append("</th>"); // 3.5.4.6 (2004/01/30)
371 }
372 else {
373 // 3.5.4.5 (2004/01/23) thタグの属?設定?来る様に変更?
374 buf.append( thTag ).append(" colspan='3'>").append( getNumberHeader() ).append("</th>"); // 3.5.4.6 (2004/01/30)
375 }
376 }
377
378 buf.append( HybsSystem.CR );
379 int clmCnt = getColumnCount(); // 3.5.5.7 (2004/05/10)
380 for(int column = 0; column < clmCnt; column++) {
381 if( isColumnDisplay( column ) ) {
382 // 3.5.4.5 (2004/01/23) thタグの属?設定?来る様に変更?
383 buf.append( thTag ).append(">");
384 buf.append( getSortedColumnLabel(column) );
385 buf.append("</th>").append( HybsSystem.CR );
386 }
387 }
388 buf.append("</tr>").append( HybsSystem.CR );
389
390 headerLine = buf.toString();
391 return headerLine;
392 }
393
394 /**
395 * ??ブルのタイトルをセ?します?
396 *
397 * @og.rev 3.1.1.0 (2003/03/28) 同期メソ?(synchronized付き)を非同期に変更する?
398 * @og.rev 5.1.6.0 (2010/05/01) caption 属?が使われて??め?削除する?
399 *
400 * @param caption 属?
401 */
402 // public void setCaption( final String caption ) {
403 // this.caption = caption;
404 // }
405
406 /**
407 * フォーマットメソ?を使用できるかど?を問?わせます?
408 *
409 * @return 使用可能(true)/ 使用不可能(false)
410 */
411 public boolean canUseFormat() {
412 return false;
413 }
414
415 /**
416 * ogPopup で検索結果の値を返すキーを?CSV形式で?します?
417 *
418 * popup の検索結果を返す画面で、結果のラジオボタンにイベントセ?します?
419 * こ?場合?オープンもとのwindow に値を返しますが、そのキーをCSV形式で
420 * ?します?なお?設定?、init 以?つまり?DBTableModelは設定済み)の
421 * 状態で呼び出してください?エラーにしません)
422 * なお?こ?メソ?は、?表示(HTMLTable)関係?ビューのみでサポ?トして
423 * ?すが、チェ?メソ?の関係で、それ以外?ビューに適用しても???
424 * するようにします?(エラーにしません)
425 *
426 * @og.rev 3.8.6.1 (2006/10/20) 新規追?
427 *
428 * @param rtnKeys ogPopupで値を返すカラ?字?(CSV形?
429 */
430 @Override
431 public void setPopupReturnKeys( final String rtnKeys ) {
432 DBTableModel table = getDBTableModel() ;
433 if( table != null && table.getRowCount() > 0 && rtnKeys != null ) {
434 String[] clmNames = StringUtil.csv2Array( rtnKeys );
435 popupClmNo = new int[clmNames.length];
436 for( int i=0; i<clmNames.length; i++ ) {
437 int no = table.getColumnNo( clmNames[i] );
438 if( no >= 0 ) { popupClmNo[ i ] = no; }
439 }
440 }
441 }
442
443 /**
444 * ogPopup で検索結果の値を返すキーを?CSV形式で?します?
445 *
446 * popup の検索結果を返す画面で、結果のラジオボタンにイベントセ?します?
447 * こ?場合?オープンもとのwindow に値を返しますが、そのキーをCSV形式で
448 * ?します?なお?設定?、init 以?つまり?DBTableModelは設定済み)の
449 * 状態で呼び出してください?エラーにしません)
450 * なお?こ?メソ?は、?表示(HTMLTable)関係?ビューのみでサポ?トして
451 * ?すが、チェ?メソ?の関係で、それ以外?ビューに適用しても???
452 * するようにします?(エラーにしません)
453 * rtnPopup に値を渡す?合に、ダブルクオー?")、シングルクオー?')は?
454 * それぞれ、ASCII コー???22???2?に置き換えます?
455 *
456 * @og.rev 3.8.6.1 (2006/10/20) 新規追?
457 *
458 * @param buf StringBuilder 追?るStringBuilderオブジェク?
459 * @param rowNo 列番号
460 *
461 * @return 引数に??タを追?た後?同?ブジェク?
462 */
463 private StringBuilder makePopupReturn( final StringBuilder buf,final int rowNo ) {
464 buf.append( " onClick=\"rtnPopup(new Array(" );
465 int clmNo = popupClmNo[ 0 ];
466 String val = StringUtil.quoteFilter( getValue( rowNo,clmNo ) );
467 buf.append( "'" ).append( val ).append( "'" );
468 for( int i=1; i<popupClmNo.length; i++ ) {
469 clmNo = popupClmNo[ i ];
470 val = StringUtil.quoteFilter( getValue( rowNo,clmNo ) );
471 buf.append( ",'" ).append( val ).append( "'" );
472 }
473 buf.append( "));\"" );
474
475 return buf;
476 }
477
478 /**
479 * 選択用のチェ?ボックスの input タグを作?します?
480 *
481 * @og.rev 3.5.5.5 (2004/04/23) 新規作?
482 *
483 * @return チェ?ボックスのinputタグ
484 */
485 private String makeChboxTag() {
486 if( isCache ) { return cacheTag; }
487 isCache = true;
488
489 String type = getSelectedType(); // "checkbox"/"radio"/"hidden"
490
491 if( type != null ) {
492 StringBuilder buf = new StringBuilder();
493
494 buf.append( "<input type=\"" ).append( type ).append( "\" " );
495 buf.append( "name=\"" ).append( HybsSystem.ROW_SEL_KEY ).append( "\"" );
496
497 cacheTag = buf.toString();
498 }
499 return cacheTag ;
500 }
501
502 /**
503 * カラ??ラベル?短)を返します?
504 * カラ???名に対して,見える形の??を返します?
505 * ?には,リソースバンドルと?せて,?ロケール毎にラベル?
506 * ?えます?
507 *
508 * @og.rev 4.0.0.0 (2005/01/31) 新規追? shortLabel を返します?)
509 *
510 * @param column カラ?号
511 *
512 * @return カラ??ラベル?短)
513 */
514 @Override
515 protected String getColumnLabel( final int column ) {
516 return getDBColumn( column ).getShortLabel();
517 }
518 }