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