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) &lt;tr&gt;属æ?は、å?のフォーマットã?まま使用しますã?
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) &lt;tr&gt;属æ?は、å?のフォーマットã?まま使用しますã?
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    }