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