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 java.util.List;
019    
020    import org.opengion.fukurou.util.StringUtil;
021    import org.opengion.hayabusa.common.HybsSystem;
022    import org.opengion.hayabusa.common.HybsSystemException;
023    import org.opengion.hayabusa.db.DBTableModel;
024    import org.opengion.hayabusa.html.TableFormatter;
025    
026    /**
027     * ヘッ??部??フォーマットに応じたテーブルを?動作?する、フォーマットテーブル作?クラスです?
028     *
029     * AbstractViewForm により、setter/getterメソ?の?ォルト実?提供して?す?
030     * 各HTMLのタグに?な setter/getterメソ?のみ?追?義して?す?
031     * [XXXX]は、カラ??します?ラベル??力フィールドをそれぞれtdで囲?す?
032     * [#XXXX]は、対応するカラ??ラベルを?力します?
033     * [$XXXX]は、対応するカラ??レン?ーを?力します?
034     * [!XXXX]は、対応するカラ??値を?力します?
035     * 特殊記号の解釈?、HTMLFormatTextField系とHTMLFormatTable系で異なります?で
036     * ご注意く???
037     *
038     * AbstractViewForm を継承して?為,ロケールに応じたラベルを?力させる事が出来ます?
039     *
040     * @og.group 画面表示
041     *
042     * @version  4.0
043     * @author   Kazuhiko Hasegawa
044     * @since    JDK5.0,
045     */
046    public class ViewForm_HTMLFormatTable extends ViewForm_HTMLTable  {
047            //* こ?プログラ??VERSION??を設定します?       {@value} */
048            private static final String VERSION = "5.1.6.0 (2010/05/01)" ;
049    
050            // 3.5.4.0 (2003/11/25) TableFormatter クラス追?
051            private TableFormatter format = null;
052    
053            // 4.3.4.4 (2009/01/01)
054    //      /**
055    //       * ?ォルトコンストラクター
056    //       *
057    //       */
058    //      public ViewForm_HTMLFormatTable() {
059    //              super();
060    //      }
061    
062            /**
063             * DBTableModel から HTML??を作?して返します?
064             * startNo(表示開始位置)から、pageSize(表示件数)までのView??を作?します?
065             * 表示残り??タ?pageSize 以下?場合?,残りの??タをすべて出力します?
066             *
067             * @og.rev 3.5.0.0 (2003/09/17) BODY要?? noClass 属?を追??
068             * @og.rev 3.5.0.0 (2003/09/17) <tr>属?は、?のフォーマット?まま使用します?
069             * @og.rev 3.5.2.0 (2003/10/20) ヘッ??繰り返し属?( headerSkipCount )を採用
070             * @og.rev 3.5.3.1 (2003/10/31) skip属?を採用。headerLine のキャ?ュクリア
071             * @og.rev 3.5.4.0 (2003/11/25) TableFormatter クラスを使用するように変更?
072             * @og.rev 3.5.5.0 (2004/03/12) systemFormat(例:[KEY.カラ?]形式?の対?
073             * @og.rev 3.5.5.0 (2004/03/12) No ?のも?の作?判断ロジ?を追?
074             * @og.rev 3.5.5.7 (2004/05/10) [#カラ?] , [$カラ?] に対?
075             * @og.rev 3.5.6.0 (2004/06/18) '!' 値のみ 追?既存? '$' は、レン?ー
076             * @og.rev 3.5.6.4 (2004/07/16) ヘッ??とボディー部をJavaScriptで?
077             * @og.rev 3.7.0.3 (2005/03/01) getBgColorCycleClass に?択行?ーカーを採用
078             * @og.rev 4.0.0.0 (2005/01/31) 新規作?(getColumnClassName ?getColumnDbType)
079             * @og.rev 4.3.1.0 (2008/09/08) フォーマットが設定されて???合?エラー追??編??みを表示する属?(isSkipNoEdit)追?
080             * @og.rev 4.3.3.0 (2008/10/01) noTransition属?対?
081             * @og.rev 4.3.7.4 (2009/07/01) tbodyタグの入れ子を解?FireFox対?
082             *
083             * @param  startNo    表示開始位置
084             * @param  pageSize   表示件数
085             *
086             * @return  DBTableModelから作?され?HTML??
087             */
088            @Override
089            public String create( final int startNo, final int pageSize )  {
090                    if( getRowCount() == 0 ) { return ""; } // 暫定?置
091    
092                    // 4.3.1.0 (2008/09/08)
093                    if( format == null ) {
094                            String errMsg = "ViewTagで canUseFormat() = true の場合?Formatter は??です?";
095                            throw new HybsSystemException( errMsg );
096                    }
097    
098                    headerLine       = null;                // 3.5.3.1 (2003/10/31) キャ?ュクリア
099                    int lastNo = getLastNo( startNo, pageSize );
100                    int blc = getBackLinkCount();
101                    int hsc = getHeaderSkipCount();         // 3.5.2.0 (2003/10/20)
102                    int hscCnt = 1;                                         // 3.5.2.0 (2003/10/20)
103    
104                    StringBuilder out = new StringBuilder( HybsSystem.BUFFER_LARGE );
105    
106                    out.append( getCountForm( startNo,pageSize ) );
107                    out.append( getHeader() );
108    
109                    String ckboxTD = "  <td " + format.getRowspan() + ">";
110    //              out.append("<tbody>").append( HybsSystem.CR ); // 4.3.7.4 (2009/07/01)
111                    int bgClrCnt = 0;
112                    for( int row=startNo; row<lastNo; row++ ) {
113    //                      if( isSkip( row ) ) { continue; }               // 3.5.3.1 (2003/10/31)
114                            if( isSkip( row ) || isSkipNoEdit( row ) ) { continue; } // 4.3.1.0 (2008/09/08)
115                            if( ! format.isUse( row,getDBTableModel() ) ) { continue; }             // 3.5.4.0 (2003/11/25)
116                            out.append("<tbody").append( getBgColorCycleClass( bgClrCnt++,row ) );
117                            if( isNoTransition() ) { // 4.3.3.0 (2008/10/01)
118                                    out.append( getHiddenRowValue( row ) );
119                            }
120                            out.append(">");     // 3.7.0.3 (2005/03/01)
121                            out.append( format.getTrTag() );
122    
123                            // 3.5.5.0 (2004/03/12) No ?のも?の作?判断追?
124                            if( isNumberDisplay() ) {
125                                    out.append( makeCheckbox( ckboxTD,row,blc ) );
126                            }
127    
128                            int cl = 0;
129                            for( ; cl < format.getLocationSize(); cl++ ) {
130                                    String fmt = format.getFormat(cl);      // 3.5.0.0
131                                    int loc = format.getLocation(cl);       // 3.5.5.0
132                                    if( ! format.isNoClass() && loc >= 0 ) {     // 3.5.5.7 (2004/05/10)
133                                            StringBuilder newtg = new StringBuilder( HybsSystem.BUFFER_LARGE );
134                                            newtg.append("<td class=\"");
135                                            newtg.append( getColumnDbType(loc) );   // 4.0.0 (2005/01/31)
136                                            newtg.append("\" ");
137                                            String tdclass = newtg.toString();
138                                            fmt = StringUtil.replace( format.getFormat(cl) ,"<td", tdclass );
139                                    }
140                                    out.append( fmt );                      // 3.5.0.0
141                                    // 3.5.5.7 (2004/05/10) #,$ 対?
142                                    if( loc >= 0 ) {
143                                            switch( format.getType(cl) ) {
144                                                    case '#' : out.append( getColumnLabel(loc) );           break;
145                                                    case '$' : out.append( getRendererValue(row,loc) );     break;
146                                                    case '!' : out.append( getValue(row,loc) );                     break;
147                                                    default  : out.append( getValueLabel(row,loc) );        break;
148                                            }
149                                    }
150                                    else {
151                                            out.append( format.getSystemFormat(row,loc) );
152                                    }
153                            }
154                            out.append( format.getFormat(cl) );
155                            out.append("</tbody>").append( HybsSystem.CR );
156    
157                    // 3.5.2.0 (2003/10/20) ヘッ??繰り返し属?( headerSkipCount )を採用
158                            if( hsc > 0 && hscCnt % hsc == 0 ) {
159                                    out.append("<tbody class=\"row_h\"").append(" >");
160                                    out.append( getHeadLine() );
161                                    out.append("</tbody>");
162                                    hscCnt = 1;
163                            }
164                            else {
165                                    hscCnt ++ ;
166                            }
167                    }
168    //              out.append("</tbody>").append( HybsSystem.CR ); // 4.3.7.9 (2009/06/29)
169                    out.append("</table>").append( HybsSystem.CR );
170    
171                    out.append( getScrollBarEndDiv() );     // 3.8.0.3 (2005/07/15)
172                    return out.toString();
173            }
174    
175            /**
176             * ?をクリア(初期?します?
177             *
178             * @og.rev 3.1.1.0 (2003/03/28) 同期メソ?(synchronized付き)を非同期に変更する?
179             * @og.rev 3.5.0.0 (2003/09/17) Noカラ?、表示を?て消せるよ?、class 属?を追??
180             * @og.rev 3.5.4.0 (2003/11/25) TableFormatter クラスを使用するように変更?
181             *
182             */
183            @Override
184            public void clear() {
185                    super.clear();
186                    format          = null;
187            }
188    
189            /**
190             * DBTableModel から ??ブルのタグ??を作?して返します?
191             *
192             * @og.rev 3.2.4.0 (2003/06/12) makeFormat() する位置を移動?
193             * @og.rev 3.5.0.0 (2003/09/17) &lt;tr&gt;属?は、?のフォーマット?まま使用します?
194             * @og.rev 3.5.1.0 (2003/10/03) Noカラ?、numberType 属?を追?
195             * @og.rev 3.5.2.0 (2003/10/20) ヘッ??繰り返し部をgetHeadLine()へ移?
196             * @og.rev 3.5.3.1 (2003/10/31) VERCHAR2 ?VARCHAR2 に修正?
197             * @og.rev 3.5.5.0 (2004/03/12) No ?のも?の作?判断ロジ?を追?
198             * @og.rev 3.5.6.5 (2004/08/09) thead に、id="header" を追?
199             * @og.rev 4.0.0.0 (2005/01/31) DBColumn の 属?(CLS_NM)から、DBTYPEに変更
200             *
201             * @return  ??ブルのタグ??
202             */
203            @Override
204            protected String getTableHead() {
205    
206                    StringBuilder buf = new StringBuilder( HybsSystem.BUFFER_MIDDLE );
207                    // 3.5.5.0 (2004/03/12) No ?のも?の作?判断追?
208                    if( isNumberDisplay() ) {
209                            buf.append("<colgroup class=\"X\" />");
210                            buf.append("<colgroup class=\"BIT\" />");
211                            buf.append("<colgroup class=\"S9\" />");          // 4.0.0 (2005/01/31)
212                            buf.append(HybsSystem.CR);
213                    }
214    
215            // 3.5.2.0 (2003/10/20) ヘッ??繰り返し部をgetHeadLine()へ移?
216                    buf.append("<thead id=\"header\">").append( HybsSystem.CR );      // 3.5.6.5 (2004/08/09)
217                    buf.append( getHeadLine() );
218                    buf.append("</thead>").append( HybsSystem.CR );
219    
220                    return buf.toString();
221            }
222    
223            /**
224             * ヘッ??繰り返し部を?getTableHead()メソ?から??
225             *
226             * @og.rev 3.5.2.0 (2003/10/20) 新規作?
227             * @og.rev 3.5.4.0 (2003/11/25) TableFormatter クラスを使用するように変更?
228             * @og.rev 3.5.4.3 (2004/01/05) useCheckControl 属?の機?を追?
229             * @og.rev 3.5.4.6 (2004/01/30) numberType="none" 時?処?追?Noラベルを?さな?
230             * @og.rev 3.5.4.7 (2004/02/06) ヘッ??にソート機?用のリンクを追?ます?
231             * @og.rev 3.5.5.0 (2004/03/12) systemFormat(例:[KEY.カラ?]形式?の対?
232             * @og.rev 3.5.5.0 (2004/03/12) No ?のも?の作?判断ロジ?を追?
233             * @og.rev 3.7.0.1 (2005/01/31) 全件チェ?コントロール処?更
234             *
235             * @return      ??ブルのタグ??
236             */
237            @Override
238            protected String getHeadLine() {
239                    if( headerLine != null ) { return headerLine; }         // キャ?ュを返す?
240    
241                    StringBuilder buf = new StringBuilder( HybsSystem.BUFFER_MIDDLE );
242    
243                    buf.append( format.getTrTag() ).append( HybsSystem.CR );
244    
245                    // 3.5.5.0 (2004/03/12) No ?のも?の作?判断追?
246                    if( isNumberDisplay() ) {
247                            // 3.5.4.3 (2004/01/05) 追??
248                            if( isUseCheckControl() && "checkbox".equals( getSelectedType() ) ) {
249                                    buf.append("  <th" ).append( format.getRowspan() ).append("></th>");
250                                    buf.append("  <th" ).append( format.getRowspan() );
251                                    buf.append(">").append( getAllCheckControl() ).append( "</th>");
252                                    buf.append("  <th" ).append( format.getRowspan() ).append(">");   // 3.5.4.6 (2004/01/30)
253                                    buf.append( getNumberHeader() ).append("</th>");                          // 3.5.4.6 (2004/01/30)
254                            }
255                            else {
256                                    buf.append("  <th colspan=\"3\"");
257                                    buf.append( format.getRowspan() );
258                                    buf.append(">").append( getNumberHeader() ).append("</th>");   // 3.5.4.6 (2004/01/30)
259                            }
260                    }
261    
262                    int cl = 0;
263                    for( ; cl < format.getLocationSize(); cl++ ) {
264                            buf.append( StringUtil.replace( format.getFormat(cl) ,"td","th" ));
265                            int loc = format.getLocation(cl);
266                            if( loc >= 0 ) { buf.append( getSortedColumnLabel(loc) ); }
267                    }
268                    buf.append( StringUtil.replace( format.getFormat(cl) ,"td","th" ) ).append( HybsSystem.CR );
269    
270                    headerLine = buf.toString();
271                    return headerLine;
272            }
273    
274            /**
275             * フォーマットを設定します?
276             *
277             * @og.rev 3.5.4.0 (2003/11/25) 新規作?
278             * @param       list    TableFormatterのリス?
279             */
280            @Override
281            public void setFormatterList( final List<TableFormatter> list ) {         // 4.3.3.6 (2008/11/15) Generics警告対?
282                    format = list.get(0);           // 4.3.3.6 (2008/11/15) Generics警告対?
283                    format.makeFormat( getDBTableModel() );
284            }
285    
286            /**
287             * フォーマットメソ?を使用できるかど?を問?わせます?
288             *
289             * @return  使用可能(true)/ 使用不可能 (false)
290             */
291            @Override
292            public boolean canUseFormat() {
293                    return true;
294            }
295    
296            /**
297             * ビューで表示したカラ???をカンマ区?で返します?
298             *
299             * @og.rev 5.1.6.0 (2010/05/01) 新規追?
300             *
301             * @return      ビューで表示したカラ???
302             */
303            @Override
304            public String getViewClms() {
305                    DBTableModel table = getDBTableModel();
306                    StringBuilder buf = new StringBuilder( HybsSystem.BUFFER_MIDDLE );
307                    for( int i=0; i<format.getLocationSize(); i++ ) {
308                            if( buf.length() > 0 ) { buf.append( ',' ); }
309                            buf.append( table.getColumnName( format.getLocation( i ) ) );
310                    }
311                    return buf.toString();
312            }
313    }