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