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.hayabusa.common.HybsSystemException;
019import org.opengion.hayabusa.db.DBTableModel;
020import org.opengion.fukurou.util.HybsDateUtil;                                          // 6.4.2.0 (2016/01/29)
021import org.opengion.fukurou.util.StringUtil;
022import org.opengion.hayabusa.html.TableFormatter;
023import org.opengion.hayabusa.html.ViewStackTableParam;
024
025import java.util.Calendar;
026import java.util.Date;
027import java.util.List;
028
029/**
030 * 積上ガント表示専用のViewFormです。
031 * stackParamTagを利用する事でスタックガント用の行を出力する事が可能です。
032 * stackParamTagによりstackColumnsが指定された場合は、そのカラム毎にブレークして、
033 * stacklink属性により積上げ行の判別が可能なtbody行を出力します。
034 * その際、stackColumnsで指定されたカラム以外の[xxx]は処理されません(空白として出力)
035 * [xxx]以外で書かれた箇所、例えば<iGantBar>タグの本体部分等は出力されます。
036 * 
037 * ヘッダの表示にはstackHeaderタグを利用します。
038 * 
039 * [エンジン内部積上げを行わない場合]
040 * 積上の表示はJavaScriptによってiGantBarタグの箇所に作成されます。
041 * 積上げそのものもiGantBarによって出力されるガントを利用してJavaScriptで行っているため、
042 * 最大検索行数と表示行数に注意して下さい。
043 * 
044 * [エンジン内部積上げを行う場合]
045 * 工数積上げをエンジン内部で行いdivタグとして出力します。
046 * その後の描画(位置調整や色等)はJavaScriptで行います。
047 * ガント部分は出力されません。
048 * スタック部分はbody部分の最後尾に新たにtd作成するため、注意してください。
049 * paramタグでの指定で、costColumnが必須です。
050 * 
051 * 
052 * AbstractViewForm により、setter/getterメソッドのデフォルト実装を提供しています。
053 * 各HTMLのタグに必要な setter/getterメソッドのみ,追加定義しています。
054 *
055 * AbstractViewForm を継承している為,ロケールに応じたラベルを出力させる事が出来ます。
056 * 
057 * @og.rev 5.5.7.0 (2012/10/01) 新規作成
058 * @og.rev 5.5.8.3 (2012/11/17) 内部積上げ対応
059 * @og.rev 5.6.1.2 (2013/02/22) キャパシティ対応
060 * @og.group 画面表示
061 *
062 * @version  5.0
063 * @author       Takahashi Masakazu
064 * @since    JDK5.0,
065 */
066public class ViewForm_HTMLStackedGanttTable extends ViewForm_HTMLTable  {
067        /** このプログラムのVERSION文字列を設定します。   {@value} */
068        private static final String VERSION = "6.8.2.0 (2017/10/13)" ;
069
070        /** ボディーフォーマット最大数 初期値:{@value} */
071        protected static final int BODYFORMAT_MAX_COUNT = 10;
072        // stack行の判定出力用
073        protected static final String STACK_TBODY               = " stackline='true'";
074        protected static final String GANTT_TBODY               = " stackline='false'";
075        protected static final String STACK_ID_PREFIX   = " id='stack_";
076        protected static final String STACK_ROW_PREFIX  = " stackrow='";
077
078        /** ヘッダーフォーマット変数 */
079        protected TableFormatter                headerFormat    ;
080        /** ボディーフォーマット配列変数 */
081        protected TableFormatter[]              bodyFormats             ;
082        /** フッターフォーマット変数 */
083        protected TableFormatter                footerFormat    ;
084        /** ボディーフォーマット数 */
085        protected int                                   bodyFormatsCount;
086
087        // stack,gantt用
088        private int[]  stackCols                ;
089
090        // 5.5.8.3 (2012/11/17)
091        private int[]   costCols                ;               // 工数カラム、開始日カラム、終了日カラム
092        private boolean innerStack              = Boolean.parseBoolean( ViewStackTableParam.INNER_STACK_VALUE );
093        private boolean stackHoliday    = Boolean.parseBoolean( ViewStackTableParam.STACK_HOLIDAY_KEY );
094
095        private String[][] calArray                             ;               // headで作成されたカレンダーデータ                   // 6.3.9.1 (2015/11/27) 修飾子を、なし → private に変更。
096        private int capCol = -1                                 ;               // 5.6.1.2 (2013/02/22) 能力値カラム          // 6.3.9.1 (2015/11/27) 修飾子を、なし → private に変更。
097
098        /**
099         * DBTableModel から HTML文字列を作成して返します。
100         * startNo(表示開始位置)から、pageSize(表示件数)までのView文字列を作成します。
101         * 表示残りデータが pageSize 以下の場合は,残りのデータをすべて出力します。
102         *
103         *
104         * @og.rev 5.5.8.3 (2012/11/17) 内部積上げ対応
105         * @og.rev 5.6.1.2 (2013/02/22) キャパシティ対応
106         * @og.rev 5.6.2.1 (2013/06/13) 積上不具合修正
107         * @og.rev 6.2.0.0 (2015/02/27) フォーマット系の noDisplay 対応
108         * @og.rev 6.4.2.0 (2016/01/29) HybsDateUtil.getCalendar( String ) を直接利用するように修正します。
109         * @og.rev 6.4.3.4 (2016/03/11) tdに、[カラム]が無いケースで、次の[カラム]のクラス属性が、前方すべてのtdにセットされてしまう対応。
110         * @og.rev 6.4.4.2 (2016/04/01) TableFormatterのタイプ別値取得処理の共通部をまとめる。
111         * @og.rev 6.4.5.0 (2016/04/08) メソッド変更( getColumnDbType(int) → getClassName(int) )
112         * @og.rev 6.8.1.1 (2017/07/22) ckboxTD変数は、<td> から <td に変更します(タグの最後が記述されていない状態でもらう)。
113         * @og.rev 6.8.2.0 (2017/10/13) makeNthChildの廃止と、makeCheckboxで、個別にclass指定するように変更。
114         *
115         * @param  sttNo          表示開始位置
116         * @param  pgSize   表示件数
117         *
118         * @return      DBTableModelから作成された HTML文字列
119         * @og.rtnNotNull
120         */
121        @Override
122        public String create( final int sttNo, final int pgSize )  {
123                // ガントは、キーブレイクがあるため、全件表示します。
124                final int pageSize = getRowCount() ;
125                if( pageSize == 0 ) { return ""; }      // 暫定処置
126
127                // 4.3.1.0 (2008/09/08)
128                if( headerFormat == null ) {
129                        final String errMsg = "ViewTagで canUseFormat() = true の場合、Formatter は必須です。";
130                        throw new HybsSystemException( errMsg );
131                }
132
133                headerLine       = null;                // 3.5.3.1 (2003/10/31) キャッシュクリア
134
135                // 6.4.1.1 (2016/01/16) PMD refactoring. Avoid declaring a variable if it is unreferenced before a possible exit point.
136                // ガントは、キーブレイクがあるため、全件表示します。
137                final int startNo  = 0;
138
139                final int lastNo = getLastNo( startNo, pageSize );
140                final int blc = getBackLinkCount();
141
142                // このビューの特有な属性を初期化
143                paramInit();
144
145                headerFormat.makeFormat( getDBTableModel() );   // 3.5.6.2 (2004/07/05) 移動
146                // 6.2.0.0 (2015/02/27) フォーマット系の noDisplay 対応
147                setFormatNoDisplay( headerFormat );
148
149                final StringBuilder out = new StringBuilder( BUFFER_LARGE )
150                        .append( getCountForm( startNo,pageSize ) )
151                        .append( getHeader() );
152
153                if( bodyFormatsCount == 0 ) {
154                        bodyFormats[0] = headerFormat ;
155                        bodyFormatsCount ++ ;
156                }
157                else {
158                        for( int i=0; i<bodyFormatsCount; i++ ) {
159                                bodyFormats[i].makeFormat( getDBTableModel() );
160                                // 6.2.0.0 (2015/02/27) フォーマット系の noDisplay 対応
161                                setFormatNoDisplay( bodyFormats[i] );
162                        }
163                }
164
165                String[] astrOldStackKeys = new String[stackCols.length];
166                for( int nIndex=0; nIndex<astrOldStackKeys.length; nIndex++ ) {
167                        astrOldStackKeys[nIndex] = "";
168                }
169
170                int bgClrCnt = 0;
171                int stackRow = 0;
172
173                // 5.5.8.3 (2012/11/17)
174                double[] costAry = null;
175                // 6.3.9.1 (2015/11/27) Found 'DD'-anomaly for variable(PMD)
176                final Calendar firstCalday;
177                final String   calZoom ;                // 6.3.9.1 (2015/11/27)
178                if( innerStack ){
179                        costAry = new double[calArray.length];
180                        final String[] firstCal = calArray[0];
181                        firstCalday = HybsDateUtil.getCalendar(firstCal[0]);                                                    // 6.4.2.0 (2016/01/29)
182                        final Calendar fstCalEnd = HybsDateUtil.getCalendar(firstCal[2]);                               // 6.4.2.0 (2016/01/29)
183
184                        if( differenceDays(firstCalday.getTime(),fstCalEnd.getTime()) == 1 ){
185                                calZoom = ViewStackTableParam.STACK_ZOOM_DAY;
186                        }
187                        else if( differenceDays(firstCalday.getTime(),fstCalEnd.getTime()) == 7 ){
188                                calZoom = ViewStackTableParam.STACK_ZOOM_WEEK;
189                        }
190                        else{
191                                calZoom = ViewStackTableParam.STACK_ZOOM_MONTH;
192                        }
193                }
194                else {                                                  // 6.3.9.1 (2015/11/27)
195                        firstCalday = null;
196                        calZoom     = null;
197                }
198
199                String capacity = null;                 // 5.6.1.2 (2013/02/22)
200                for( int row=startNo; row<lastNo; row++ ) {
201                        // データのスキップは行わない
202
203                        // ガントのブレイク
204                //      if(! isSameGroup(row, astrOldGroupKeys)) {
205                                // 6.9.7.0 (2018/05/14) PMD These nested if statements could be combined
206//                              if( !isSameStack(row, astrOldStackKeys) && stackCols.length > 0 ) { // 積上のブレイク
207//                                      if( !(innerStack && row == startNo) ) {                                                 // 5.5.8.3 (2012/11/17) 内部積上げは後から積上げるので、初回は出力しない
208                                if( !isSameStack(row, astrOldStackKeys) && stackCols.length > 0         // 積上のブレイク
209                                        && !(innerStack && row == startNo ) ) {                                                 // 5.5.8.3 (2012/11/17) 内部積上げは後から積上げるので、初回は出力しない
210                                                stackRow = row;
211
212                                                makeBodyTable( out,innerStack ? row -1 : row, stackRow, bgClrCnt, blc, costAry, capacity );                     // 6.1.0.0 (2014/12/26) refactoring
213
214                                                if( innerStack ){
215                                                        costAry = new double[calArray.length];
216                                                }
217//                                      }
218                                }
219                                // 6.1.0.0 (2014/12/26) refactoring : Avoid if(x != y) ..; else ..;
220                                if( innerStack ){       // 5.5.8.3 (2012/11/17) 内部積上げをする場合
221                                        final double costDbl = Double.parseDouble( getValue(row,costCols[0]) ); //工数
222                                        final Calendar startDay = HybsDateUtil.getCalendar(getValue(row,costCols[1]));          // 6.4.2.0 (2016/01/29)
223                                        final Calendar endDay   = HybsDateUtil.getCalendar(getValue(row,costCols[2]));          // 6.4.2.0 (2016/01/29)
224
225                                        final Date startDayDate = startDay.getTime();
226                                        Date endDayDate = endDay.getTime();
227
228                                        // 5.6.1.2 (2013/02/22)
229                                        if( capCol > -1 ){
230                                                capacity = getValue(row,capCol);
231                                        }
232                                        else{
233                                                capacity = "1";
234                                        }
235
236                                        // 枠はそのままで計算
237                                        final int fromCell = calNumber(startDayDate,calZoom,firstCalday.getTime());
238                                        final int toCell   = calNumber(endDayDate,calZoom,firstCalday.getTime());       
239
240                                        endDay.add(Calendar.DATE, 1); // 終了日は範囲に入るので1つ進める
241                                        endDayDate = endDay.getTime();
242
243                                        int stackMother = differenceDays(startDayDate,endDayDate);
244                                        if( !stackHoliday ){
245                                                for( int cel=fromCell; cel<=toCell; cel++  ){
246                                                        if( "1".equals( calArray[cel][1] ) ){
247                                                                stackMother--;
248                                                        }
249                                                }
250                                        }
251
252                                        Date calFrom;
253                                        Date calTo;
254
255                                        for( int cel=fromCell; cel<=toCell; cel++ ){
256                                                calFrom = HybsDateUtil.getCalendar(calArray[cel][0]).getTime();                 // 6.4.2.0 (2016/01/29)
257                                                calTo   = HybsDateUtil.getCalendar(calArray[cel][2]).getTime();                 // 6.4.2.0 (2016/01/29)
258                                                if( calFrom.compareTo( startDayDate ) < 0 ){
259                                                        calFrom = startDayDate;
260                                                }
261                                                if( endDayDate.compareTo( calTo ) < 0 ){
262                                                        calTo = endDayDate;
263                                                }
264                                                // 6.3.9.1 (2015/11/27) Found 'DD'-anomaly for variable(PMD)
265                                                final int cellDays = differenceDays( calFrom, calTo );
266                                                if( stackHoliday ){
267                                                        costAry[cel] += (costDbl / stackMother) * cellDays;
268                                                }
269                                                else{
270                                                        // 休日のみの場合は積上げられない!
271                                                        if( !"1".equals( calArray[cel][1] ) ){
272                                                                costAry[cel] += (costDbl / stackMother) * cellDays;
273                                                        }
274                                                }
275                                        }
276                                }
277                                else{   // 5.5.8.3 (2012/11/17) 内部積上げの場合はガント部分は出力せずに積上げだけする。
278                                        for( int i=0; i<bodyFormatsCount; i++ ) {
279                                                final TableFormatter bodyFormat = bodyFormats[i];
280                                                if( ! bodyFormat.isUse( row,getDBTableModel() ) ) { continue; }         // 3.5.4.0 (2003/11/25)
281                                                out.append("<tbody").append( getBgColorCycleClass( bgClrCnt++,row ) );
282                                                if( isNoTransition() ) {        // 4.3.3.0 (2008/10/01)
283                                                        out.append( getHiddenRowValue( row ) );
284                                                }
285                                                out.append( GANTT_TBODY )
286                                                        .append( STACK_ROW_PREFIX ).append( stackRow ).append("'>")
287                                                        .append( bodyFormat.getTrTag() );
288
289                                                // 3.5.5.0 (2004/03/12) No 欄そのものの作成判断追加
290                                                if( isNumberDisplay() ) {
291                                                        final String ckboxTD = "<td" + bodyFormat.getRowspan();                 // 6.8.1.1 (2017/07/22)
292                                                        out.append( makeCheckbox( ckboxTD,row,blc,true ) );                             // 6.8.2.0 (2017/10/13)
293                                                }
294
295                                                int cl = 0;
296                                                for( ; cl<bodyFormat.getLocationSize(); cl++ ) {
297                                                        String fmt = bodyFormat.getFormat(cl);
298                                                        final int loc = bodyFormat.getLocation(cl);             // 3.5.5.0
299                                                        if( ! bodyFormat.isNoClass() && loc >= 0 ) {    // 3.5.5.7 (2004/05/10)
300                                                                // 6.4.3.4 (2016/03/11) tdに、[カラム]が無いケースで、次の[カラム]のクラス属性が、前方すべてのtdにセットされてしまう対応。
301                                                                final int idx = fmt.lastIndexOf( "<td" );
302                                                                if( idx >= 0 ) {        // matchしてるので、あるはず
303                                                                        final String tdclass = " class=\"" + getClassName(loc) + "\" ";                 // 6.4.5.0 (2016/04/08)
304                                                                        fmt = fmt.substring( 0,idx+3 ) + tdclass + fmt.substring( idx+3 ) ;
305                                                                }
306                                                        }
307                                                        out.append( fmt );                      // 3.5.0.0
308                                                        // 3.5.5.7 (2004/05/10) #,$ 対応
309                                                        if( loc >= 0 ) {
310                                                                // 6.4.4.2 (2016/04/01) 処理の共通部をまとめる。
311                                                                out.append( getTypeCaseValue( bodyFormat.getType(cl),row,loc ) );
312                                                        }
313                                                        else {
314                                                                out.append( bodyFormat.getSystemFormat(row,loc) );
315                                                        }
316                                                }
317                                                out.append( bodyFormat.getFormat(cl) )
318                                                        .append("</tbody>").append( CR );
319                                        }
320                                }
321                }
322
323                // 6.0.2.5 (2014/10/31) たぶん、カッコのコメントする位置間違いで使われてないようなので、一旦コメントする。
324        //      } // 5.6.5.2 (2013/06/21) 括弧の位置間違いのため修正
325
326                // 内部積上げ時は最終行の出力を行う
327                if( innerStack ){
328                        makeBodyTable( out, lastNo-1, stackRow, bgClrCnt, blc, costAry, capacity );                     // 6.1.0.0 (2014/12/26) refactoring
329                }
330
331                if( footerFormat != null ) {
332                        // 6.3.9.0 (2015/11/06) 引数にTableFormatterを渡して、処理の共有化を図る。
333                        out.append( getTableFoot( footerFormat ) );
334                }
335
336                out.append("</table>").append( CR )
337                        .append( getScrollBarEndDiv() );        // 3.8.0.3 (2005/07/15)
338
339                return out.toString();
340        }
341
342        /**
343         * 内容をクリア(初期化)します。
344         *
345         * @og.rev 5.5.8.3 (2012/11/17) 内部積上げのための修正
346         * @og.rev 5.6.1.2 (2013/02/22) キャパシティ対応
347         *
348         */
349        @Override
350        public void clear() {
351                super.clear();
352                headerFormat            = null;
353                bodyFormats                     = null;
354                footerFormat            = null;
355                bodyFormatsCount        = 0;
356                stackCols                       = null;                 // 5.5.8.3 (2012/11/17)
357                costCols                        = null;                 // 5.5.8.3 (2012/11/17)
358                innerStack                      = Boolean.parseBoolean( ViewStackTableParam.INNER_STACK_VALUE ); // 5.5.8.3 (2012/11/17)
359                calArray                        = null;                 // 5.5.8.3 (2012/11/17)
360                stackHoliday            = Boolean.parseBoolean( ViewStackTableParam.STACK_HOLIDAY_KEY ); // 5.5.8.3 (2012/11/17)
361                capCol                          = -1;                   // 5.6.1.2 (2013/02/22)
362        }
363
364        /**
365         * このビューに対する特別な初期化を行う。
366         *
367         * @og.rev 5.5.8.3 (2012/11/17)
368         * @og.rev 5.5.9.0 (2012/12/03) objectではなくArrayList化
369         * @og.rev 5.6.1.2 (2013/02/22) キャパシティ対応
370         * @og.rev 5.6.2.1 (2013/03/08) stackHolidayが抜けていたので追加
371         */
372        private void paramInit() {
373                final String costCol            = getParam( ViewStackTableParam.COST_COLUMNS_KEY,       ViewStackTableParam.COST_COLUMNS_VALUE  ); // 5.5.8.3 (2012/11/17)
374                innerStack                                      = getBoolParam( ViewStackTableParam.INNER_STACK_KEY     ); // 5.5.8.3 (2012/11/17)
375                stackHoliday                            = getBoolParam( ViewStackTableParam.STACK_HOLIDAY_KEY   ); // 5.6.2.1 (2013/03/08)
376
377                if( innerStack ){
378                        // 6.1.0.0 (2014/12/26) findBugs: Bug type ITA_INEFFICIENT_TO_ARRAY (click for details)
379                        // 長さが0の配列の引数で Collection.toArray() を使用しています。
380                        final List<String[]> lst = getViewArrayList();
381                        calArray = lst.toArray( new String[lst.size()][3] );
382                        if( calArray == null || costCol == null){
383                                final String errMsg = "ヘッダのカレンダデータ、costColumnsの設定は必須です。"+costCol;
384                                throw new HybsSystemException( errMsg );
385                        }
386                }
387
388                final DBTableModel table = getDBTableModel();
389
390                // 6.4.1.1 (2016/01/16) PMD refactoring. Avoid declaring a variable if it is unreferenced before a possible exit point.
391                final String strStackCols       = getParam( ViewStackTableParam.STACK_COLUMNS_KEY,      ViewStackTableParam.STACK_COLUMNS_VALUE );
392                final String[] stackKeys = StringUtil.csv2Array(strStackCols);
393                stackCols = new int[stackKeys.length];
394                for( int nIndex=0; nIndex<stackCols.length ; nIndex++ ) {
395                        stackCols[nIndex] = table.getColumnNo( stackKeys[nIndex] );
396                }
397
398                final String[] costKeys = StringUtil.csv2Array(costCol);
399                costCols = new int[costKeys.length];
400                for( int nIndex=0; nIndex<costCols.length ; nIndex++ ) {
401                        costCols[nIndex] = table.getColumnNo( costKeys[nIndex] );
402                }
403
404                // 5.6.1.2 (2013/02/22) キャパシティ
405                // 6.4.1.1 (2016/01/16) PMD refactoring. Avoid declaring a variable if it is unreferenced before a possible exit point.
406                final String capColName         = getParam( ViewStackTableParam.CAP_COLUMN_KEY, ViewStackTableParam.CAP_COLUMN_VALUE    ); // 5.6.1.2 (2013/02/22)
407                if( capColName != null && capColName.length() > 0 ){
408                        capCol = table.getColumnNo(capColName);
409                }
410        }
411
412        /**
413         * DBTableModel から テーブルのタグ文字列を作成して返します。
414         *
415         * @og.rev 5.9.1.2 (2015/10/23) 自己終了警告対応
416         * @og.rev 6.4.4.1 (2016/03/18) NUMBER_DISPLAYを、static final 定数化します。
417         * @og.rev 6.4.9.0 (2016/07/23) colgroupのHTML5対応(No欄)
418         * @og.rev 6.4.9.1 (2016/08/05) colgroupのHTML5対応(No欄)時の対応ミス修正
419         * @og.rev 6.8.1.0 (2017/07/14) HTML5対応ヘッダー出力設定時に、ブラウザを互換設定したときの対応。
420         * @og.rev 6.8.2.0 (2017/10/13) makeNthChildの廃止と、makeCheckboxで、個別にclass指定するように変更。
421         *
422         * @return      テーブルのタグ文字列
423         * @og.rtnNotNull
424         */
425        @Override
426        protected String getTableHead() {
427                final StringBuilder buf = new StringBuilder( BUFFER_MIDDLE );
428
429                // 3.5.5.0 (2004/03/12) No 欄そのものの作成判断追加
430                if( isNumberDisplay() ) {
431                        // 6.4.9.0 (2016/07/23) colgroupのHTML5対応(No欄)
432                                buf.append( NUMBER_DISPLAY );           // 6.8.1.0 (2017/07/14) HTML5ネイティブ時でも、出力します。
433                        // 6.8.1.0 (2017/07/14) HTML5対応ヘッダー出力設定時に、ブラウザを互換設定したときの対応。
434                        // 6.8.2.0 (2017/10/13) makeNthChildの廃止と、makeCheckboxで、個別にclass指定するように変更。
435        //              if( !useIE7Header ) { 
436        //                      buf.append( "<style type=\"text/css\">" ).append( CR );
437        //                      makeNthChild( buf,2,"BIT" );
438        //                      makeNthChild( buf,3,"S9"  );
439        //                      buf.append( "</style>" ).append( CR );          // 6.4.9.1 (2016/08/05)
440        //              }
441                }
442
443                // 3.5.2.0 (2003/10/20) ヘッダー繰り返し部をgetHeadLine()へ移動
444                buf.append("<thead id=\"header\">").append( CR )        // 3.5.6.5 (2004/08/09)
445                        .append( getHeadLine() )
446                        .append("</thead>").append( CR );
447
448                return buf.toString();
449        }
450
451        /**
452         * ヘッダー繰り返し部を、getTableHead()メソッドから分離。
453         *
454         * @og.rev 6.1.2.0 (2015/01/24) キャッシュを返すのを、#getHeadLine() に移動。
455         *
456         * @return      テーブルのタグ文字列
457         * @og.rtnNotNull
458         */
459        @Override
460        protected String getHeadLine() {
461                if( headerLine == null ) {                                      // キャッシュになければ、設定する。
462                        headerLine = getHeadLine( "<th" + headerFormat.getRowspan() ) ;
463                }
464
465                return headerLine ;
466        }
467
468        /**
469         * ヘッダー繰り返し部を、getTableHead()メソッドから分離。
470         *
471         * @og.rev 6.1.2.0 (2015/01/24) キャッシュを返すのを、#getHeadLine() に移動。
472         * @og.rev 6.4.3.4 (2016/03/11) ヘッダーでもTableFormatterのType(#,$,!)に対応した値を出すようにする。
473         * @og.rev 6.4.4.2 (2016/04/01) TableFormatterのタイプ別値取得処理の共通部をまとめる。
474         *
475         * @param       thTag タグの文字列
476         *
477         * @return      テーブルのタグ文字列
478         * @og.rtnNotNull
479         */
480        @Override
481        protected String getHeadLine( final String thTag ) {
482
483                final StringBuilder buf = new StringBuilder( BUFFER_MIDDLE )
484                                .append( headerFormat.getTrTag() ).append( CR );
485
486                // 3.5.5.0 (2004/03/12) No 欄そのものの作成判断追加
487                if( isNumberDisplay() ) {
488                        // 6.1.2.0 (2015/01/24) thTag に、headerFormat.getRowspan() を含ませて受け取る。
489                        if( isUseCheckControl() && "checkbox".equals( getSelectedType() ) ) {
490                                buf.append( thTag ).append( "></th>" )
491                                        .append( thTag ).append( '>' ).append( getAllCheckControl() ).append( "</th>" )         // 6.0.2.5 (2014/10/31) char を append する。
492                                        .append( thTag ).append( '>' ).append( getNumberHeader()    ).append( "</th>" );        // 6.0.2.5 (2014/10/31) char を append する。
493                        }
494                        else {
495                                buf.append( thTag ).append( " colspan=\"3\">" ).append( getNumberHeader() ).append( "</th>" );  // 6.0.2.5 (2014/10/31) char を append する。
496                        }
497                }
498
499                int cl = 0;
500                for( ; cl<headerFormat.getLocationSize(); cl++ ) {
501                        buf.append( StringUtil.replace( headerFormat.getFormat(cl) ,"td","th" ));
502                        final int loc = headerFormat.getLocation(cl);
503                        // 6.4.3.4 (2016/03/11) ヘッダーでもTableFormatterのType(#,$,!)に対応した値を出すようにする。
504                        if( loc >= 0 ) {
505                                // 6.4.4.2 (2016/04/01) 処理の共通部をまとめる。
506                                buf.append( getTypeCaseValue( headerFormat.getType(cl),-1,loc ) );
507                        }
508                }
509                buf.append( StringUtil.replace( headerFormat.getFormat(cl) ,"td","th" ) ).append( CR );
510
511                return buf.toString();                          // 6.1.2.0 (2015/01/24)
512        }
513
514        /**
515         * フォーマットを設定します。
516         *
517         *
518         * @param       list    TableFormatterのリスト
519         */
520        @Override
521        public void setFormatterList( final List<TableFormatter> list ) {               // 4.3.3.6 (2008/11/15) Generics警告対応
522                bodyFormats = new TableFormatter[BODYFORMAT_MAX_COUNT];
523
524                bodyFormatsCount = 0;
525                for( int i=0; i<list.size(); i++ ) {
526                        final TableFormatter format = list.get( i );            // 4.3.3.6 (2008/11/15) Generics警告対応
527
528                        switch( format.getFormatType() ) {
529                                case TYPE_HEAD : headerFormat = format; break;
530                                case TYPE_BODY : bodyFormats[bodyFormatsCount++] = format; break;
531                                case TYPE_FOOT : footerFormat = format; break;
532                                default : final String errMsg = "FormatterType の定義外の値が指定されました。";
533                                // 4.3.4.4 (2009/01/01)
534                                                  throw new HybsSystemException( errMsg );
535                        }
536                }
537
538                // 3.5.5.5 (2004/04/23) headerFormat が定義されていない場合はエラー
539                if( headerFormat == null ) {
540                        final String errMsg = "h:thead タグの、フォーマットの指定は必須です。";
541                        throw new HybsSystemException( errMsg );
542                }
543        }
544
545        /**
546         * フォーマットメソッドを使用できるかどうかを問い合わせます。
547         *
548         * @return  使用可能(true)/ 使用不可能 (false)
549         */
550        @Override
551        public boolean canUseFormat() {
552                return true;
553        }
554
555        /**
556         * ビューで表示したカラムの一覧をCSV形式で返します。
557         *
558         * @og.rev 5.1.6.0 (2010/05/01) 新規追加
559         * @og.rev 6.2.0.1 (2015/03/06) TableFormatter#getLocation(int)の有効判定
560         *
561         * @return      ビューで表示したカラムの一覧
562         * @og.rtnNotNull
563         */
564        @Override
565        public String getViewClms() {
566                final DBTableModel table = getDBTableModel();
567                final StringBuilder buf = new StringBuilder( BUFFER_MIDDLE );
568                for( int i=0; i<headerFormat.getLocationSize(); i++ ) {
569                        if( buf.length() > 0 ) { buf.append( ',' ); }
570                        // 6.2.0.1 (2015/03/06) TableFormatter#getLocation(int)の有効判定
571                        final int loc = headerFormat.getLocation(i);
572                        if( loc >= 0 ) { buf.append( table.getColumnName( loc ) ); }
573                }
574                return buf.toString();
575        }
576
577        /**
578         * 上下行のデータが同じ積上かどうかをチェックする。
579         *
580         * @param   nRowIndex テーブルモデルの行番号
581         * @param   astrOldValues 古いグルプーデータ配列
582         *
583         * @return  使用可能(true)/ 使用不可能 (false)
584         */
585        private boolean isSameStack(final int nRowIndex, final String[] astrOldValues) {
586                boolean bRet = stackCols.length > 0 ;
587                if( bRet ) {
588                        for( int nIndex=0; bRet && nIndex<stackCols.length ; nIndex++ ) {
589                                bRet = astrOldValues[nIndex].equals( getValue( nRowIndex, stackCols[nIndex] ) ) ;
590                        }
591
592                        // 不一致時に astrOldValues に 新しい値を設定しておきます。
593                        if( !bRet ) {
594                                for( int nIndex=0; nIndex<stackCols.length; nIndex++ ) {
595                                        astrOldValues[nIndex] = getValue(nRowIndex, stackCols[nIndex]);
596                                }
597                        }
598                }
599                return bRet;
600        }
601
602        /**
603         * 対象カラムが積上げカラムかどうか。
604         *
605         * @param   loc 列番号
606         *
607         * @return  対象(true)/ 非対象 (false)
608         */
609        private boolean isStackClm(final int loc) {
610                boolean rtn = false;
611                for( int nIndex=0; nIndex<stackCols.length ; nIndex++ ) {
612                        if( stackCols[nIndex] == loc ) {
613                                rtn = true;
614                                break;                          // 6.3.9.1 (2015/11/27)
615                        }
616                }
617                return rtn;
618        }
619
620        /**
621         * 2つの日付の差を求めます。
622         * java.util.Date 型の日付 date1 - date2 が何日かを返します。
623         * 
624         * @og.rev 5.5.8.3 (2012/11/17) 新規
625         * 
626         * @param date1    日付 
627         * @param date2    日付 
628         * @return    2つの日付の差(日数 2-1) 同日なら0
629         */
630        public static int differenceDays(final Date date1,final Date date2) {
631                final long datetime1 = date1.getTime();
632                final long datetime2 = date2.getTime();
633                final long one_date_time = 1000 * 60 * 60 * 24L;
634                return (int)((datetime2 - datetime1) / one_date_time);
635        }
636
637        /**
638         * 日付から枠番号を返す。
639         * 
640         * @og.rev 5.5.8.3 (2012/11/17) 新規
641         *
642         * @param   date 日付(YYYY/MM/DD)
643         * @param       zoom Zoom設定値
644         * @param       calFD ヘッダ初日
645         *
646         * @return  枠番号
647         */
648        private int calNumber(final Date date, final String zoom, final Date calFD ) {
649                // 6.3.9.1 (2015/11/27) Found 'DD'-anomaly for variable(PMD)
650                final int rtn ;
651                if( zoom.equals( ViewStackTableParam.STACK_ZOOM_MONTH ) ){
652                        // 月だけは別の計算が必要
653                        final Calendar cal1 = Calendar.getInstance();
654                        cal1.setTime( calFD );
655                        final Calendar cal2 = Calendar.getInstance();
656                        cal2.setTime( date );
657                        rtn = ( cal2.get( Calendar.YEAR )-cal1.get( Calendar.YEAR ) ) * 12
658                                        + ( cal2.get( Calendar.MONTH ) - cal1.get( Calendar.MONTH ) );
659                }
660                else{
661                        final int diff = differenceDays( calFD, date );
662                        if( zoom.equals( ViewStackTableParam.STACK_ZOOM_WEEK )){
663                                rtn = diff/7;
664                        }
665                        else{
666                                rtn = diff;
667                        }
668                }
669                return rtn;
670        }
671
672        /**
673         * テーブル本体の作成。
674         * 
675         * @og.rev 5.5.8.3 (2012/11/17) 繰り返し利用するため分離
676         * @og.reb 5.6.1.2 (2013/02/22) td終了が抜けていたので追加、キャパシティ対応
677         * @og.reb 6.1.0.0 (2014/12/26) 引数に StringBuffer を追加し、それに、データを追記していく。
678         * @og.rev 6.4.3.4 (2016/03/11) tdに、[カラム]が無いケースで、次の[カラム]のクラス属性が、前方すべてのtdにセットされてしまう対応。
679         * @og.rev 6.4.4.2 (2016/04/01) TableFormatterのタイプ別値取得処理の共通部をまとめる。
680         * @og.rev 6.4.5.0 (2016/04/08) メソッド変更( getColumnDbType(int) → getClassName(int) )
681         * @og.rev 6.8.1.1 (2017/07/22) ckboxTD変数は、&lt;td&gt; から &lt;td に変更します(タグの最後が記述されていない状態でもらう)。
682         * @og.rev 6.8.2.0 (2017/10/13) makeNthChildの廃止と、makeCheckboxで、個別にclass指定するように変更。
683         *
684         * @param   outBuf      データを追加するStringBuffer
685         * @param   row         テーブルモデルのrow
686         * @param       stackRow スタック行保存用
687         * @param       bgClrCnt 背景色カウンタ
688         * @param       blc             チェックボックス用
689         * @param       costAry コスト集計配列
690         * @param       cap             能力
691         *
692         * @return  テーブル本体のHTML(入力の out オブジェクトそのもの)
693         * @og.rtnNotNull
694         */
695        private StringBuilder makeBodyTable( final StringBuilder outBuf, final int row, final int stackRow,
696                                                                                         final int bgClrCnt, final int blc, final double[] costAry, final String cap ) {
697                int bcCnt = bgClrCnt;           // 6.0.0.1 (2014/04/25) 引数を直接変更できなくする。
698                for( int i=0; i<bodyFormatsCount; i++ ) {
699                        final TableFormatter bodyFormat = bodyFormats[i];
700                        if( ! bodyFormat.isUse( row,getDBTableModel() ) ) { continue; } 
701                        outBuf.append("<tbody").append( getBgColorCycleClass( bcCnt++,row ) );
702                        if( isNoTransition() ) { 
703                                outBuf.append( getHiddenRowValue( row ) );
704                        }
705                        outBuf.append( STACK_TBODY )
706                                .append( STACK_ROW_PREFIX ).append( stackRow ).append( '\'' )
707                                .append( STACK_ID_PREFIX  ).append( stackRow ).append( "'>" )
708                                .append( bodyFormat.getTrTag() );
709
710                        //  No 欄そのものの作成判断追加
711                        if( isNumberDisplay() ) {
712                                final String ckboxTD = "<td" + bodyFormat.getRowspan();                         // 6.8.1.1 (2017/07/22)
713                                outBuf.append( makeCheckbox( ckboxTD,row,blc,true ) );                          // 6.8.2.0 (2017/10/13)
714                        }
715
716                        int cl = 0;
717                        for( ; cl<bodyFormat.getLocationSize(); cl++ ) {
718                                String fmt = bodyFormat.getFormat(cl);
719                                final int loc = bodyFormat.getLocation(cl);             // 3.5.5.0 (2004/03/12)
720                                if( ! bodyFormat.isNoClass() && loc >= 0 ) {    // 3.5.5.7 (2004/05/10)
721                                        // 6.4.3.4 (2016/03/11) tdに、[カラム]が無いケースで、次の[カラム]のクラス属性が、前方すべてのtdにセットされてしまう対応。
722                                        final int idx = fmt.lastIndexOf( "<td" );
723                                        if( idx >= 0 ) {        // matchしてるので、あるはず
724                                                final String tdclass = " class=\"" + getClassName(loc) + "\" ";                 // 6.4.5.0 (2016/04/08)
725                                                fmt = fmt.substring( 0,idx+3 ) + tdclass + fmt.substring( idx+3 ) ;
726                                        }
727                                }
728                                outBuf.append( fmt );
729
730                                // locがstackに入っていれば出力
731                                if( isStackClm(loc) ){
732                                        if( loc >= 0 ) {
733                                                // 6.4.4.2 (2016/04/01) 処理の共通部をまとめる。
734                                                outBuf.append( getTypeCaseValue( bodyFormat.getType(cl),row,loc ) );
735                                        }
736                                        else {
737                                                outBuf.append( bodyFormat.getSystemFormat(row,loc) );
738                                        }
739                                }
740                        }
741                        // 5.5.8.3 (2012/11/17)内部積上げの結果は出力場所の特定が難しいため一番最後尾にtd付きで出力しておきます
742                        if( innerStack ){
743                                outBuf.append("</td><td><div class='stackDivParent' capacity='"+ cap + "' style='width:100%; position:relative;'>"); // 5.6.1.2 (2013/02/22) td終了追加
744                                for( int cs=0; cs<costAry.length; cs++ ){
745                                        outBuf.append("<div class='stackDiv' style='position:absolute; top:0px;' num='")
746                                                .append( cs)
747                                                .append("' stackedCost='")
748                                                .append( costAry[cs] )
749                                                .append( "'></div>");
750                                }
751                                outBuf.append("</div>");
752                        }
753
754                        outBuf.append( bodyFormat.getFormat(cl) )
755                                .append("</tbody>").append( CR );
756                }
757                return outBuf;
758        }
759}