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 */
016package org.opengion.plugin.view;
017
018import org.opengion.fukurou.util.StringUtil;
019import org.opengion.hayabusa.common.HybsSystemException;
020
021/**
022 * 検索結果を自動的に表形式に変換する、テーブル作成クラスです。
023 *
024 * ユーザー単位に表示するカラムの順番、表示可非を指定できるように対応します。
025 * setColumnDisplay( final String columnName ) に、指定された順番に
026 * 表示するというHTMLFormatTable の簡易版として用意します。
027 * 各HTMLのタグに必要な setter/getterメソッドのみ、追加定義しています。
028 *
029 * AbstractViewForm を継承している為、ロケールに応じたラベルを出力させる事が出来ます。
030 *
031 * @og.group 画面表示
032 * @og.rev 5.1.6.0 (2010/05/01) 新規作成
033 *
034 * @version  4.0
035 * @author       Kazuhiko Hasegawa
036 * @since    JDK5.0,
037 */
038public class ViewForm_HTMLSeqClmTable extends ViewForm_HTMLTable {
039        /** このプログラムのVERSION文字列を設定します。   {@value} */
040        private static final String VERSION = "7.0.4.0 (2019/05/31)" ;
041
042        private int[]   clmNo           ;               // 5.1.6.0 (2010/05/01)
043        private int             clmCnt          = -1;   // 5.1.6.0 (2010/05/01)
044
045        private String  viewClms        ;
046
047        /**
048         * デフォルトコンストラクター
049         *
050         * @og.rev 6.4.2.0 (2016/01/29) PMD refactoring. Each class should declare at least one constructor.
051         */
052        public ViewForm_HTMLSeqClmTable() { super(); }          // これも、自動的に呼ばれるが、空のメソッドを作成すると警告されるので、明示的にしておきます。
053
054        /**
055         * DBTableModel から HTML文字列を作成して返します。
056         * startNo(表示開始位置)から、pageSize(表示件数)までのView文字列を作成します。
057         * 表示残りデータが pageSize 以下の場合は、残りのデータをすべて出力します。
058         *
059         * @og.rev 5.5.4.2 (2012/07/13) editName指定時の編集対応
060         * @og.rev 6.3.9.0 (2015/11/06) コンストラクタで初期化されていないフィールドを null チェックなしで利用している(findbugs)
061         * @og.rev 6.4.2.1 (2016/02/05) clmNo == null のエラー判定を先に行う。
062         * @og.rev 6.8.1.1 (2017/07/22) ckboxTD変数は、<td> から <td に変更します(タグの最後が記述されていない状態でもらう)。
063         *
064         * @param  startNo        表示開始位置
065         * @param  pageSize   表示件数
066         *
067         * @return      DBTableModelから作成された HTML文字列
068         * @og.rtnNotNull
069         */
070        @Override
071        public String create( final int startNo, final int pageSize )  {
072                if( getRowCount() == 0 ) { return ""; } // 暫定処置
073
074                // 6.4.2.1 (2016/02/05) エラー判定を先に行う。
075                if( clmNo == null ) {
076                        final String errMsg = "#setColumnDisplay(String)を先に実行しておいてください。" ;
077                        throw new HybsSystemException( errMsg );
078                }
079
080                headerLine       = null;
081
082                final StringBuilder out = new StringBuilder( BUFFER_LARGE )
083                        .append( getCountForm( startNo,pageSize ) )
084                        .append( getHeader() )
085                        .append("<tbody>").append( CR );                // 6.4.1.1 (2016/01/16) PMD refactoring.
086
087                int bgClrCnt = 0;
088                // 6.4.1.1 (2016/01/16) PMD refactoring. Avoid declaring a variable if it is unreferenced before a possible exit point.
089                final String ckboxTD = "  <td";                                 // 6.8.1.1 (2017/07/22)
090                final int lastNo = getLastNo( startNo, pageSize );
091                final int blc = getBackLinkCount();
092                final int hsc = getHeaderSkipCount();                   // 3.5.2.0 (2003/10/20)
093                int hscCnt   = 1;                                                               // 3.5.2.0 (2003/10/20)
094                for( int row=startNo; row<lastNo; row++ ) {
095                        if( isSkip( row ) || isSkipNoEdit( row ) ) { continue; } // 4.3.1.0 (2008/09/08)
096                        out.append(" <tr").append( getBgColorCycleClass( bgClrCnt++,row ) );
097                        if( isNoTransition() ) {        // 4.3.3.0 (2008/10/01)
098                                out.append( getHiddenRowValue( row ) );
099                        }
100                        out.append('>').append( CR );                           // 6.0.2.5 (2014/10/31) char を append する。
101
102                        // 3.5.5.0 (2004/03/12) No 欄そのものの作成判断追加
103                        if( isNumberDisplay() ) {
104                                out.append( makeCheckbox( ckboxTD, row, blc ) ).append( CR );
105                        }
106
107                        // 5.1.6.0 (2010/05/01)
108                        for( int clm=0; clm<clmCnt; clm++ ) {
109                                final int column = clmNo[clm];
110                                if( isColumnDisplay( column ) ) {
111                                        out.append("  <td>")
112                                                .append( getValueLabel(row,column) )
113                                                .append("</td>").append( CR );
114                                }
115                        }
116
117                        // 5.5.4.2 (2012/07/13) mustとmuntAnyでwritableのものはdisplay:noneで出力する(可能な限り余分なものは出力しない)
118                        for( int column=0; column<clmCnt; column++ ) {
119                                if( !isColumnDisplay( column ) && ( isMustColumn( column ) || isMustAnyColumn(column) ) && isColumnWritable( column) ) {
120                                        out.append("  <td style=\"display:none\">")
121                                                .append( getValueLabel(row,column) )
122                                                .append("</td>").append( CR );
123                                }
124                        }
125
126                        out.append(" </tr>").append( CR );
127
128                        // 3.5.2.0 (2003/10/20) ヘッダー繰り返し属性( headerSkipCount )を採用
129                        if( hsc > 0 && hscCnt % hsc == 0 ) {
130                                out.append( getHeadLine() );
131                                hscCnt = 1;
132                        }
133                        else {
134                                hscCnt ++ ;
135                        }
136                }
137                out.append("</tbody>").append( CR )
138                        .append("</table>").append( CR )
139                        .append( getScrollBarEndDiv() );        // 3.8.0.3 (2005/07/15)
140
141                return out.toString();
142        }
143
144        /**
145         * DBTableModel から テーブルのタグ文字列を作成して返します。
146         *
147         * @og.rev 3.5.1.0 (2003/10/03) Noカラムに、numberType 属性を追加
148         * @og.rev 3.5.2.0 (2003/10/20) ヘッダー繰り返し部をgetHeadLine()へ移動
149         * @og.rev 3.5.3.1 (2003/10/31) VERCHAR2 を VARCHAR2 に修正。
150         * @og.rev 3.5.5.0 (2004/03/12) No 欄そのものの作成判断ロジックを追加
151         * @og.rev 3.5.6.5 (2004/08/09) thead に、id="header" を追加
152         * @og.rev 4.0.0.0 (2005/01/31) DBColumn の 属性(CLS_NM)から、DBTYPEに変更
153         * @og.rev 4.0.0.0 (2005/01/31) 新規作成(getColumnClassName ⇒ getColumnDbType)
154         * @og.rev 6.1.2.0 (2015/01/24) HTML5 で colgroup が効かない対応
155         * @og.rev 5.9.1.2 (2015/10/23) 自己終了警告対応
156         * @og.rev 6.3.9.0 (2015/11/06) コンストラクタで初期化されていないフィールドを null チェックなしで利用している(findbugs)
157         * @og.rev 6.4.2.1 (2016/02/05) clmNo == null のエラー判定を先に行う。
158         * @og.rev 6.4.4.1 (2016/03/18) NUMBER_DISPLAYを、static final 定数化します。
159         * @og.rev 6.4.5.0 (2016/04/08) メソッド変更( getColumnDbType(int) → getClassName(int) )
160         * @og.rev 6.4.6.1 (2016/06/03) DbType とClassName が複雑化しているため、とりあえずの暫定対策。
161         * @og.rev 5.9.14.3 (2016/11/25) editでの表示順変更に対応
162         * @og.rev 6.8.1.0 (2017/07/14) HTML5対応ヘッダー出力設定時に、ブラウザを互換設定したときの対応。
163         * @og.rev 6.9.5.0 (2018/04/23) USE_IE7_HEADER 廃止(false固定)
164         * @og.rev 7.0.4.0 (2019/05/31) colgroup 廃止
165         *
166         * @return      テーブルのタグ文字列
167         * @og.rtnNotNull
168         */
169        @Override
170        protected String getTableHead() {
171                // 6.3.9.0 (2015/11/06) コンストラクタで初期化されていないフィールドを null チェックなしで利用している(findbugs)
172                // 6.4.2.1 (2016/02/05) エラー判定を先に行う。
173                if( clmNo == null ) {
174                        final String errMsg = "#setColumnDisplay(String)を先に実行しておいてください。" ;
175                        throw new HybsSystemException( errMsg );
176                }
177
178                final StringBuilder buf = new StringBuilder( BUFFER_MIDDLE );
179
180                // 5.7.5.0 (2014/04/04) HTML5 で colgroup が効かない対応
181                // 本当は、tableタグの前に入れたかったが、ややこしいので table タグの直後に入れます。
182                // 互換モードでない場合専用。処理速度を気にするより、処理を一か所にまとめておきます。
183                // 6.9.5.0 (2018/04/23) USE_IE7_HEADER 廃止(false固定)
184//              if( !useIE7Header ) {
185                        // 8.1.0.0 (2021/12/28) HTML5 準拠に見直し(type="text/css" 不要)
186//                      buf.append( "<style type=\"text/css\">" ).append( CR );
187                        buf.append( "<style>" ).append( CR );
188                        int ad = 1;
189                        if( isNumberDisplay() ) {
190                                makeNthChild( buf,2,"BIT" );
191                                makeNthChild( buf,3,"S9"  );
192                                ad = 4;
193                        }
194
195                        // 6.4.2.1 (2016/02/05) 変数名がややこしいので、変更しておきます。
196                        // 5.9.14.3 (2016/11/25) editでの表示順変更に対応
197        //              final int cnt = getColumnCount();
198        //              for( int clm=0; clm<cnt; clm++ ) {
199                        for( int clm=0; clm<clmCnt; clm++ ) { // 5.9.14.3 (2016/11/25) 表示順変更に対応していなかった
200                                final int column = clmNo[clm];
201                                if( isColumnDisplay( column ) ) {
202                                        // 6.4.6.1 (2016/06/03) DbType とClassName が複雑化しているため、とりあえずの暫定対策。
203                                        makeNthChild( buf,ad,getClassName(column) );            // 6.4.6.1 (2016/06/03)
204                                        ad++ ;                  // tdタグの順番なので、表示する場合のみカウントする。
205                                }
206                        }
207                        buf.append( "</style>" ).append( CR );
208//              }
209
210//              // 3.5.5.0 (2004/03/12) No 欄そのものの作成判断追加
211//              // 7.0.4.0 (2019/05/31) colgroup 廃止
212//              if( isNumberDisplay() ) {
213//                      // 5.9.1.2 (2015/10/23) 自己終了警告対応
214//                      // 6.4.4.1 (2016/03/18) NUMBER_DISPLAYを、static final 定数化します。
215//                      buf.append( NUMBER_DISPLAY );           // 6.8.1.0 (2017/07/14) HTML5ネイティブ時でも、出力します。
216//              }
217
218                // 5.1.6.0 (2010/05/01)
219                // 7.0.4.0 (2019/05/31) colgroup 廃止
220//              for( int clm=0; clm<clmCnt; clm++ ) {
221//                      final int column = clmNo[clm];
222//                      if( isColumnDisplay( column ) ) {
223//                              buf.append("<colgroup class=\"" )
224//                                      .append( getClassName(column) )                 // 6.4.5.0 (2016/04/08)
225//                                      // 5.9.1.2 (2015/10/23) 自己終了警告対応
226//                                      .append("\"><!-- --></colgroup>")
227//                                      .append( CR );
228//                      }
229//              }
230
231        // 3.5.2.0 (2003/10/20) ヘッダー繰り返し部をgetHeadLine()へ移動
232                buf.append("<thead id=\"header\">").append( CR )        // 3.5.6.5 (2004/08/09)
233                        .append( getHeadLine() )
234                        .append("</thead>").append( CR );
235
236                return buf.toString();
237        }
238
239        /**
240         * ヘッダー繰り返し部を、getTableHead()メソッドから分離。
241         *
242         * @og.rev 3.5.2.0 (2003/10/20) 新規作成
243         * @og.rev 3.5.4.3 (2004/01/05) useCheckControl 属性の機能を追加
244         * @og.rev 3.5.4.5 (2004/01/23) thタグの属性設定出来る様に新規追加。
245         * @og.rev 3.5.4.6 (2004/01/30) numberType="none" 時の処理を追加(Noラベルを出さない)
246         * @og.rev 3.5.4.7 (2004/02/06) ヘッダーにソート機能用のリンクを追加します。
247         * @og.rev 3.7.0.1 (2005/01/31) 全件チェックコントロール処理変更
248         * @og.rev 6.1.2.0 (2015/01/24) キャッシュを返すのを、#getHeadLine() に移動。
249         * @og.rev 6.3.9.0 (2015/11/06) コンストラクタで初期化されていないフィールドを null チェックなしで利用している(findbugs)
250         * @og.rev 6.4.2.1 (2016/02/05) clmNo == null のエラー判定を先に行う。
251         *
252         * @param       thTag タグの文字列
253         *
254         * @return      テーブルのタグ文字列
255         * @og.rtnNotNull
256         */
257        @Override
258        protected String getHeadLine( final String thTag ) {
259                // 6.3.9.0 (2015/11/06) コンストラクタで初期化されていないフィールドを null チェックなしで利用している(findbugs)
260                // 6.4.2.1 (2016/02/05) エラー判定を先に行う。
261                if( clmNo == null ) {
262                        final String errMsg = "#setColumnDisplay(String)を先に実行しておいてください。" ;
263                        throw new HybsSystemException( errMsg );
264                }
265
266                final StringBuilder buf = new StringBuilder( BUFFER_MIDDLE )
267                        .append("<tr class=\"row_hu\">").append( CR );
268
269                // 3.5.5.0 (2004/03/12) No 欄そのものの作成判断追加
270                if( isNumberDisplay() ) {
271                        // 3.5.4.3 (2004/01/05) 追加分
272                        if( isUseCheckControl() && "checkbox".equals( getSelectedType() ) ) {
273                                // 3.5.4.5 (2004/01/23) thタグの属性設定出来る様に変更。
274                                // 6.0.2.5 (2014/10/31) char を append する。
275                                buf.append( thTag ).append("></th>")
276                                        .append( thTag ).append('>').append( getAllCheckControl() ).append("</th>")
277                                        .append( thTag ).append('>').append( getNumberHeader()    ).append("</th>");    // 3.5.4.6 (2004/01/30)
278                        }
279                        else {
280                                // 3.5.4.5 (2004/01/23) thタグの属性設定出来る様に変更。
281                                buf.append( thTag ).append(" colspan='3'>").append( getNumberHeader() ).append("</th>");        // 3.5.4.6 (2004/01/30)
282                        }
283                }
284                buf.append( CR );
285
286                // 5.1.6.0 (2010/05/01)
287                for( int clm=0; clm<clmCnt; clm++ ) {
288                        final int column = clmNo[clm];
289                        if( isColumnDisplay( column ) ) {
290                                // 3.5.4.5 (2004/01/23) thタグの属性設定出来る様に変更。
291                                buf.append( thTag ).append('>')         // 6.0.2.5 (2014/10/31) char を append する。
292                                        .append( getSortedColumnLabel(column) )
293                                        .append("</th>").append( CR );
294                        }
295                }
296                buf.append("</tr>").append( CR );
297
298                return buf.toString();                          // 6.1.2.0 (2015/01/24)
299        }
300
301        /**
302         * 表示可能カラム名を、CSV形式で与えます。
303         * 例:"OYA,KO,HJO,SU,DYSET,DYUPD"
304         * setColumnDisplay( int column,boolean rw ) の簡易版です。
305         * null を与えた場合は、なにもしません。
306         *
307         * @param       columnName      カラム名
308         */
309        @Override
310        public void setColumnDisplay( final String columnName ) {
311                super.setColumnDisplay( columnName );
312
313                if( columnName != null ) {
314                        final String[] clmNames = StringUtil.csv2Array( columnName );
315                        clmCnt = clmNames.length;
316                        clmNo  = new int[clmCnt];
317                        for( int i=0; i<clmCnt; i++ ) {
318                                clmNo[i] = getColumnNo( clmNames[i] );
319                        }
320                }
321                viewClms = columnName;
322        }
323
324        /**
325         * ビューで表示したカラムの一覧をCSV形式で返します。
326         *
327         * @og.rev 5.1.6.0 (2010/05/01) 新規追加
328         * @og.rev 6.0.2.4 (2014/10/17) Edit機能で、オリジナルのカラム列を取得する必要がある。
329         *
330         * @return      ビューで表示したカラムの一覧
331         */
332        @Override
333        public String getViewClms() {
334                // 6.3.9.1 (2015/11/27) A method should have only one exit point, and that should be the last statement in the method.(PMD)
335                return viewClms == null ? super.getViewClms() : viewClms ;
336        }
337}