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.common.HybsSystemException;
020 import org.opengion.hayabusa.db.DBTableModel;
021 import org.opengion.fukurou.util.StringUtil;
022 import org.opengion.hayabusa.html.TableFormatter;
023
024 import java.util.List;
025
026 /**
027 * ヘッãƒ??フッタ、ã?ãƒ?‚£を指定して作æ?する、è?由レイアウトが可能な、カスタãƒ?ƒ†ーブル表示クラスですã?
028 * こã?クラスは、ViewForm_HTMLFormatTable クラスの代替えとしても使用できますã?
029 * そã?場合ã?、thead のみæŒ?®šすれã?、同じフォーãƒ?�Œ tbody にも適用されますã?
030 * これは、まさに、ViewForm_HTMLFormatTable と同じですã?
031 *
032 * AbstractViewForm により、setter/getterメソãƒ?ƒ‰のãƒ?ƒ•ォルト実è£?‚’提供してã�?�¾すã?
033 * 各HTMLのタグにå¿?¦�な setter/getterメソãƒ?ƒ‰のみ?Œ追åŠ?®š義してã�?�¾すã?
034 *
035 * AbstractViewForm を継承してã�?‚‹為,ロケールに応じたラベルをå?力させる事が出来ますã?
036 *
037 * @og.group 画面表示
038 *
039 * @version 4.0
040 * @author Kazuhiko Hasegawa
041 * @since JDK5.0,
042 */
043 public class ViewForm_HTMLCustomTable extends ViewForm_HTMLTable {
044 //* こã?プログラãƒ??VERSIONæ–?—å?を設定しますã? {@value} */
045 private static final String VERSION = "5.1.6.0 (2010/05/01)" ;
046
047 // 3.5.4.0 (2003/11/25) TableFormatter クラス追åŠ?
048 // 4.3.1.0 (2008/09/08) protectedに変更
049 /** ヘッãƒ??フォーマット変数 */
050 protected TableFormatter headerFormat = null;
051 /** ボディーフォーマットé?列変数 */
052 protected TableFormatter[] bodyFormats = null;
053 /** フッターフォーマット変数 */
054 protected TableFormatter footerFormat = null;
055 /** ボディーフォーマット数 */
056 protected int bodyFormatsCount = 0;
057
058 // 3.5.4.6 (2004/01/30) 初期値変更
059 /** ボディーフォーマット最大数 初期値:{@value} */
060 protected static final int BODYFORMAT_MAX_COUNT = 10;
061
062 // 4.3.4.4 (2009/01/01)
063 // /**
064 // * ãƒ?ƒ•ォルトコンストラクター
065 // *
066 // */
067 // public ViewForm_HTMLCustomTable() {
068 // super();
069 // }
070
071 /**
072 * DBTableModel から HTMLæ–?—å?を作æ?して返しますã?
073 * startNo(表示開始位置)から、pageSize(表示件数)までのViewæ–?—å?を作æ?しますã?
074 * 表示残りãƒ??タã�?pageSize 以下ã?場合ã?,残りのãƒ??タをすべて出力しますã?
075 *
076 * @og.rev 3.5.0.0 (2003/09/17) BODY要ç´?? noClass 属æ?を追åŠ??
077 * @og.rev 3.5.0.0 (2003/09/17) <tr>属æ?は、å?のフォーマットã?まま使用しますã?
078 * @og.rev 3.5.2.0 (2003/10/20) ヘッãƒ??繰り返し属æ?( headerSkipCount )を採用
079 * @og.rev 3.5.3.1 (2003/10/31) skip属æ?を採用。headerLine のキャãƒ?‚·ュクリア
080 * @og.rev 3.5.4.0 (2003/11/25) TableFormatter クラスを使用するように変更ã€?
081 * @og.rev 3.5.5.0 (2004/03/12) systemFormat(例:[KEY.カラãƒ?��]形式ç?の対å¿?
082 * @og.rev 3.5.5.0 (2004/03/12) No æ¬?��のもã?の作æ?判断ロジãƒ?‚¯を追åŠ?
083 * @og.rev 3.5.5.7 (2004/05/10) [#カラãƒ?��] , [$カラãƒ?��] に対å¿?
084 * @og.rev 3.5.6.0 (2004/06/18) '!' 値のみ 追åŠ?既存ã? '$' は、レンãƒ?ƒ©ー
085 * @og.rev 3.5.6.2 (2004/07/05) makeFormat 処ç�?‚’getTableHead メソãƒ?ƒ‰から移å‹?
086 * @og.rev 3.5.6.4 (2004/07/16) ヘッãƒ??とボディー部をJavaScriptでåˆ?›¢
087 * @og.rev 4.0.0.0 (2005/01/31) 新規作æ?(getColumnClassName â‡?getColumnDbType)
088 * @og.rev 3.7.0.3 (2005/03/01) getBgColorCycleClass にã€?�¸択行ã?ーカーを採用
089 * @og.rev 4.3.1.0 (2008/09/08) フォーマットが設定されてã�?�ªã�??合ã?エラー追åŠ??編é›?¡Œã?みを表示する属æ?(isSkipNoEdit)追åŠ?
090 * @og.rev 4.3.3.0 (2008/10/01) noTransition属æ?対å¿?
091 * @og.rev 4.3.7.4 (2009/07/01) tbodyタグの入れ子を解æ¶?FireFox対å¿?
092 *
093 * @param startNo 表示開始位置
094 * @param pageSize 表示件数
095 *
096 * @return DBTableModelから作æ?されã�?HTMLæ–?—å?
097 */
098 @Override
099 public String create( final int startNo, final int pageSize ) {
100 if( getRowCount() == 0 ) { return ""; } // 暫定å?置
101
102 // 4.3.1.0 (2008/09/08)
103 if( headerFormat == null ) {
104 String errMsg = "ViewTagで canUseFormat() = true の場合ã?Formatter はå¿??ですã?";
105 throw new HybsSystemException( errMsg );
106 }
107
108 headerLine = null; // 3.5.3.1 (2003/10/31) キャãƒ?‚·ュクリア
109
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 headerFormat.makeFormat( getDBTableModel() ); // 3.5.6.2 (2004/07/05) 移å‹?
118
119 out.append( getCountForm( startNo,pageSize ) );
120 out.append( getHeader() );
121
122 if( bodyFormatsCount == 0 ) {
123 bodyFormats[0] = headerFormat ;
124 bodyFormatsCount ++ ;
125 }
126 else {
127 for( int i=0; i<bodyFormatsCount; i++ ) {
128 bodyFormats[i].makeFormat( getDBTableModel() );
129 }
130 }
131
132 // out.append("<tbody>").append( HybsSystem.CR ); // 4.3.7.4 (2009/07/01)
133 int bgClrCnt = 0;
134 for( int row=startNo; row<lastNo; row++ ) {
135 // if( isSkip( row ) ) { continue; } // 3.5.3.1 (2003/10/31)
136 if( isSkip( row ) || isSkipNoEdit( row ) ) { continue; } // 4.3.1.0 (2008/09/08)
137 for( int i=0; i<bodyFormatsCount; i++ ) {
138 TableFormatter bodyFormat = bodyFormats[i];
139 if( ! bodyFormat.isUse( row,getDBTableModel() ) ) { continue; } // 3.5.4.0 (2003/11/25)
140 out.append("<tbody").append( getBgColorCycleClass( bgClrCnt++,row ) );
141 if( isNoTransition() ) { // 4.3.3.0 (2008/10/01)
142 out.append( getHiddenRowValue( row ) );
143 }
144 out.append(">"); // 3.7.0.3 (2005/03/01)
145 out.append( bodyFormat.getTrTag() );
146
147 // 3.5.5.0 (2004/03/12) No æ¬?��のもã?の作æ?判断追åŠ?
148 if( isNumberDisplay() ) {
149 String ckboxTD = "<td" + bodyFormat.getRowspan() + ">";
150 out.append( makeCheckbox( ckboxTD,row,blc ) );
151 }
152
153 int cl = 0;
154 for( ; cl < bodyFormat.getLocationSize(); cl++ ) {
155 String fmt = bodyFormat.getFormat(cl);
156 int loc = bodyFormat.getLocation(cl); // 3.5.5.0
157 if( ! bodyFormat.isNoClass() && loc >= 0 ) { // 3.5.5.7 (2004/05/10)
158 StringBuilder newtg = new StringBuilder( HybsSystem.BUFFER_LARGE );
159 newtg.append("<td class=\"");
160 newtg.append( getColumnDbType(loc) ); // 4.0.0 (2005/01/31)
161 newtg.append("\" ");
162 String tdclass = newtg.toString();
163 fmt = StringUtil.replace( bodyFormat.getFormat(cl) ,"<td", tdclass );
164 }
165 out.append( fmt ); // 3.5.0.0
166 // 3.5.5.7 (2004/05/10) #,$ 対å¿?
167 if( loc >= 0 ) {
168 switch( bodyFormat.getType(cl) ) {
169 case '#' : out.append( getColumnLabel(loc) ); break;
170 case '$' : out.append( getRendererValue(row,loc) ); break;
171 case '!' : out.append( getValue(row,loc) ); break;
172 default : out.append( getValueLabel(row,loc) ); break;
173 }
174 }
175 else {
176 out.append( bodyFormat.getSystemFormat(row,loc) );
177 }
178 }
179 out.append( bodyFormat.getFormat(cl) );
180 out.append("</tbody>").append( HybsSystem.CR );
181 }
182
183 // 3.5.2.0 (2003/10/20) ヘッãƒ??繰り返し属æ?( headerSkipCount )を採用
184 if( hsc > 0 && hscCnt % hsc == 0 ) {
185 out.append("<tbody class=\"row_h\"").append(" >");
186 out.append( getHeadLine() );
187 out.append("</tbody>");
188 hscCnt = 1;
189 }
190 else {
191 hscCnt ++ ;
192 }
193 }
194
195 if( footerFormat != null ) {
196 out.append( getTableFoot() );
197 }
198
199 // out.append("</tbody>").append( HybsSystem.CR ); // 4.3.7.4 (2009/07/01)
200 out.append("</table>").append( HybsSystem.CR );
201
202 out.append( getScrollBarEndDiv() ); // 3.8.0.3 (2005/07/15)
203 return out.toString();
204 }
205
206 /**
207 * å†?®¹をクリア(初期åŒ?しますã?
208 *
209 * @og.rev 3.1.1.0 (2003/03/28) 同期メソãƒ?ƒ‰(synchronized付き)を非同期に変更するã€?
210 * @og.rev 3.5.0.0 (2003/09/17) Noカラãƒ?�«、表示をå?て消せるよã�?�«、class 属æ?を追åŠ??
211 * @og.rev 3.5.4.0 (2003/11/25) TableFormatter クラスを使用するように変更ã€?
212 *
213 */
214 @Override
215 public void clear() {
216 super.clear();
217 headerFormat = null;
218 bodyFormats = null;
219 footerFormat = null;
220 bodyFormatsCount = 0;
221 }
222
223 /**
224 * DBTableModel から ãƒ??ブルのタグæ–?—å?を作æ?して返しますã?
225 *
226 * @og.rev 3.5.0.0 (2003/09/17) <tr>属æ?は、å?のフォーマットã?まま使用しますã?
227 * @og.rev 3.5.1.0 (2003/10/03) Noカラãƒ?�«、numberType 属æ?を追åŠ?
228 * @og.rev 3.5.2.0 (2003/10/20) ヘッãƒ??繰り返し部をgetHeadLine()へ移å‹?
229 * @og.rev 3.5.3.1 (2003/10/31) VERCHAR2 ã‚?VARCHAR2 に修正ã€?
230 * @og.rev 3.5.4.0 (2003/11/25) TableFormatter クラスを使用するように変更ã€?
231 * @og.rev 3.5.5.0 (2004/03/12) No æ¬?��のもã?の作æ?判断ロジãƒ?‚¯を追åŠ?
232 * @og.rev 3.5.6.2 (2004/07/05) makeFormat 処ç�?‚’create メソãƒ?ƒ‰の頭に移å‹?
233 * @og.rev 3.5.6.5 (2004/08/09) thead に、id="header" を追åŠ?
234 * @og.rev 4.0.0.0 (2005/01/31) DBColumn の 属æ?(CLS_NM)から、DBTYPEに変更
235 *
236 * @return ãƒ??ブルのタグæ–?—å?
237 */
238 @Override
239 protected String getTableHead() {
240
241 StringBuilder buf = new StringBuilder( HybsSystem.BUFFER_MIDDLE );
242 // 3.5.5.0 (2004/03/12) No æ¬?��のもã?の作æ?判断追åŠ?
243 if( isNumberDisplay() ) {
244 buf.append("<colgroup class=\"X\" />"); // 4.0.0 (2005/01/31)
245 buf.append("<colgroup class=\"BIT\" />");
246 buf.append("<colgroup class=\"S9\" />"); // 4.0.0 (2005/01/31)
247 buf.append(HybsSystem.CR);
248 }
249
250 // 3.5.2.0 (2003/10/20) ヘッãƒ??繰り返し部をgetHeadLine()へ移å‹?
251 buf.append("<thead id=\"header\">").append( HybsSystem.CR ); // 3.5.6.5 (2004/08/09)
252 buf.append( getHeadLine() );
253 buf.append("</thead>").append( HybsSystem.CR );
254
255 return buf.toString();
256 }
257
258 /**
259 * ヘッãƒ??繰り返し部をã?getTableHead()メソãƒ?ƒ‰からåˆ?›¢ã€?
260 *
261 * @og.rev 3.5.6.2 (2004/07/05) HTMLCustomTableScrollBar 用に新規作æ?
262 *
263 * @return ãƒ??ブルのタグæ–?—å?
264 */
265 @Override
266 protected String getHeadLine() {
267 return getHeadLine( "<th" ) ;
268 }
269
270 /**
271 * ヘッãƒ??繰り返し部をã?getTableHead()メソãƒ?ƒ‰からåˆ?›¢ã€?
272 *
273 * @og.rev 3.5.2.0 (2003/10/20) 新規作æ?
274 * @og.rev 3.5.4.0 (2003/11/25) TableFormatter クラスを使用するように変更ã€?
275 * @og.rev 3.5.4.3 (2004/01/05) useCheckControl 属æ?の機è?を追åŠ?
276 * @og.rev 3.5.4.6 (2004/01/30) numberType="none" 時ã?処ç�?‚’追åŠ?Noラベルをå?さなã�?
277 * @og.rev 3.5.4.7 (2004/02/06) ヘッãƒ??にソート機è?用のリンクを追åŠ?�—ますã?
278 * @og.rev 3.5.5.0 (2004/03/12) systemFormat(例:[KEY.カラãƒ?��]形式ç?の対å¿?
279 * @og.rev 3.5.5.0 (2004/03/12) No æ¬?��のもã?の作æ?判断ロジãƒ?‚¯を追åŠ?
280 * @og.rev 3.5.6.2 (2004/07/05) HTMLCustomTableScrollBar 用に引数追åŠ?
281 * @og.rev 3.7.0.1 (2005/01/31) 全件チェãƒ?‚¯コントロール処ç�?¤‰更
282 *
283 * @param thTag タグのæ–?—å?
284 *
285 * @return ãƒ??ブルのタグæ–?—å?
286 */
287 @Override
288 protected String getHeadLine( final String thTag ) {
289 if( headerLine != null ) { return headerLine; } // キャãƒ?‚·ュを返すã€?
290
291 StringBuilder buf = new StringBuilder( HybsSystem.BUFFER_MIDDLE );
292
293 buf.append( headerFormat.getTrTag() ).append( HybsSystem.CR );
294
295 // 3.5.5.0 (2004/03/12) No æ¬?��のもã?の作æ?判断追åŠ?
296 if( isNumberDisplay() ) {
297 // 3.5.4.3 (2004/01/05) 追åŠ??
298 if( isUseCheckControl() && "checkbox".equals( getSelectedType() ) ) {
299 buf.append( thTag ).append( headerFormat.getRowspan() ).append("></th>");
300 buf.append( thTag ).append( headerFormat.getRowspan() );
301 buf.append(">").append( getAllCheckControl() ).append( "</th>");
302 buf.append( thTag ).append( headerFormat.getRowspan() );
303 buf.append(">").append( getNumberHeader() ).append("</th>"); // 3.5.4.6 (2004/01/30)
304 }
305 else {
306 buf.append( thTag ).append(" colspan=\"3\"");
307 buf.append( headerFormat.getRowspan() );
308 buf.append(">").append( getNumberHeader() ).append("</th>"); // 3.5.4.6 (2004/01/30)
309 }
310 }
311
312 int cl = 0;
313 for( ; cl < headerFormat.getLocationSize(); cl++ ) {
314 buf.append( StringUtil.replace( headerFormat.getFormat(cl) ,"td","th" ));
315 int loc = headerFormat.getLocation(cl);
316 if( loc >= 0 ) { buf.append( getSortedColumnLabel(loc) ); }
317 }
318 buf.append( StringUtil.replace( headerFormat.getFormat(cl) ,"td","th" ) ).append( HybsSystem.CR );
319
320 headerLine = buf.toString();
321 return headerLine;
322 }
323
324 /**
325 * DBTableModel から ãƒ??ブルのタグæ–?—å?を作æ?して返しますã?
326 *
327 * @og.rev 3.5.0.0 (2003/09/17) <tr>属æ?は、å?のフォーマットã?まま使用しますã?
328 * @og.rev 3.5.1.0 (2003/10/03) Noカラãƒ?�«、numberType 属æ?を追åŠ?
329 * @og.rev 3.5.4.0 (2003/11/25) TableFormatter クラスを使用するように変更ã€?
330 * @og.rev 3.5.4.7 (2004/02/06) ヘッãƒ??にソート機è?用のリンクを追åŠ?�—ますã?
331 * @og.rev 3.5.5.0 (2004/03/12) systemFormat(例:[KEY.カラãƒ?��]形式ç?の対å¿?
332 * @og.rev 3.5.5.0 (2004/03/12) No æ¬?��のもã?の作æ?判断ロジãƒ?‚¯を追åŠ?
333 *
334 * @return ãƒ??ブルのタグæ–?—å?
335 */
336 protected String getTableFoot() {
337 footerFormat.makeFormat( getDBTableModel() );
338
339 StringBuilder buf = new StringBuilder( HybsSystem.BUFFER_MIDDLE );
340
341 buf.append("<tfoot>").append( HybsSystem.CR );
342 buf.append( footerFormat.getTrTag() ).append( HybsSystem.CR );
343
344 // 3.5.5.0 (2004/03/12) No æ¬?��のもã?の作æ?判断追åŠ?
345 if( isNumberDisplay() ) {
346 buf.append(" <th");
347 buf.append(" colspan=\"3\"");
348 buf.append( footerFormat.getRowspan() );
349 buf.append("></th>");
350 }
351
352 int cl = 0;
353 for( ; cl < footerFormat.getLocationSize(); cl++ ) {
354 int loc = footerFormat.getLocation(cl);
355 if( loc >= 0 ) { buf.append( getSortedColumnLabel(loc) ); }
356 }
357 buf.append( footerFormat.getFormat(cl) ).append( HybsSystem.CR );
358 buf.append("</tfoot>").append( HybsSystem.CR );
359
360 return buf.toString();
361 }
362
363 /**
364 * フォーマットを設定しますã?
365 *
366 * @og.rev 3.5.4.0 (2003/11/25) 新規作æ?
367 * @og.rev 3.5.4.4 (2004/01/16) 配å?のæœ?¤§数を変更
368 * @og.rev 3.5.5.5 (2004/04/23) headerFormat が定義されてã�?�ªã�??合ã?エラー
369 *
370 * @param list TableFormatterのリスãƒ?
371 */
372 @Override
373 public void setFormatterList( final List<TableFormatter> list ) { // 4.3.3.6 (2008/11/15) Generics警告対å¿?
374 bodyFormats = new TableFormatter[BODYFORMAT_MAX_COUNT];
375
376 bodyFormatsCount = 0;
377 for( int i=0; i<list.size(); i++ ) {
378 TableFormatter format = list.get( i ); // 4.3.3.6 (2008/11/15) Generics警告対å¿?
379
380 switch( format.getFormatType() ) {
381 case TYPE_HEAD : headerFormat = format; break;
382 case TYPE_BODY : bodyFormats[bodyFormatsCount++] = format; break;
383 case TYPE_FOOT : footerFormat = format; break;
384 default : String errMsg = "FormatterType の定義外ã?値が指定されましたã€?;
385 // 4.3.4.4 (2009/01/01)
386 throw new HybsSystemException( errMsg );
387 }
388 }
389
390 // 3.5.5.5 (2004/04/23) headerFormat が定義されてã�?�ªã�??合ã?エラー
391 if( headerFormat == null ) {
392 String errMsg = "h:thead タグの、フォーマットã?æŒ?®šã?å¿??ですã?";
393 throw new HybsSystemException( errMsg );
394 }
395 }
396
397 /**
398 * フォーマットメソãƒ?ƒ‰を使用できるかどã�?�‹を問ã�?�ˆわせますã?
399 *
400 * @return 使用可能(true)/ 使用不可能 (false)
401 */
402 @Override
403 public boolean canUseFormat() {
404 return true;
405 }
406
407 /**
408 * ビューで表示したカラãƒ??ä¸?¦§をカンマ区åˆ?‚Šで返しますã?
409 *
410 * @og.rev 5.1.6.0 (2010/05/01) 新規追åŠ?
411 *
412 * @return ビューで表示したカラãƒ??ä¸?¦§
413 */
414 @Override
415 public String getViewClms() {
416 DBTableModel table = getDBTableModel();
417 StringBuilder buf = new StringBuilder( HybsSystem.BUFFER_MIDDLE );
418 for( int i=0; i<headerFormat.getLocationSize(); i++ ) {
419 if( buf.length() > 0 ) { buf.append( ',' ); }
420 buf.append( table.getColumnName( headerFormat.getLocation( i ) ) );
421 }
422 return buf.toString();
423 }
424 }