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行の判定出力用 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 * @og.rev 7.0.4.0 (2019/05/31) colgroup 廃止 422 * 423 * @return テーブルのタグ文字列 424 * @og.rtnNotNull 425 */ 426 @Override 427 protected String getTableHead() { 428 final StringBuilder buf = new StringBuilder( BUFFER_MIDDLE ); 429 430// // 3.5.5.0 (2004/03/12) No 欄そのものの作成判断追加 431// // 7.0.4.0 (2019/05/31) colgroup 廃止 432// if( isNumberDisplay() ) { 433// // 6.4.9.0 (2016/07/23) colgroupのHTML5対応(No欄) 434// buf.append( NUMBER_DISPLAY ); // 6.8.1.0 (2017/07/14) HTML5ネイティブ時でも、出力します。 435// // 6.8.1.0 (2017/07/14) HTML5対応ヘッダー出力設定時に、ブラウザを互換設定したときの対応。 436// // 6.8.2.0 (2017/10/13) makeNthChildの廃止と、makeCheckboxで、個別にclass指定するように変更。 437// // if( !useIE7Header ) { 438// // buf.append( "<style type=\"text/css\">" ).append( CR ); 439// // makeNthChild( buf,2,"BIT" ); 440// // makeNthChild( buf,3,"S9" ); 441// // buf.append( "</style>" ).append( CR ); // 6.4.9.1 (2016/08/05) 442// // } 443// } 444 445 // 3.5.2.0 (2003/10/20) ヘッダー繰り返し部をgetHeadLine()へ移動 446 buf.append("<thead id=\"header\">").append( CR ) // 3.5.6.5 (2004/08/09) 447 .append( getHeadLine() ) 448 .append("</thead>").append( CR ); 449 450 return buf.toString(); 451 } 452 453 /** 454 * ヘッダー繰り返し部を、getTableHead()メソッドから分離。 455 * 456 * @og.rev 6.1.2.0 (2015/01/24) キャッシュを返すのを、#getHeadLine() に移動。 457 * 458 * @return テーブルのタグ文字列 459 * @og.rtnNotNull 460 */ 461 @Override 462 protected String getHeadLine() { 463 if( headerLine == null ) { // キャッシュになければ、設定する。 464 headerLine = getHeadLine( "<th" + headerFormat.getRowspan() ) ; 465 } 466 467 return headerLine ; 468 } 469 470 /** 471 * ヘッダー繰り返し部を、getTableHead()メソッドから分離。 472 * 473 * @og.rev 6.1.2.0 (2015/01/24) キャッシュを返すのを、#getHeadLine() に移動。 474 * @og.rev 6.4.3.4 (2016/03/11) ヘッダーでもTableFormatterのType(#,$,!)に対応した値を出すようにする。 475 * @og.rev 6.4.4.2 (2016/04/01) TableFormatterのタイプ別値取得処理の共通部をまとめる。 476 * 477 * @param thTag タグの文字列 478 * 479 * @return テーブルのタグ文字列 480 * @og.rtnNotNull 481 */ 482 @Override 483 protected String getHeadLine( final String thTag ) { 484 485 final StringBuilder buf = new StringBuilder( BUFFER_MIDDLE ) 486 .append( headerFormat.getTrTag() ).append( CR ); 487 488 // 3.5.5.0 (2004/03/12) No 欄そのものの作成判断追加 489 if( isNumberDisplay() ) { 490 // 6.1.2.0 (2015/01/24) thTag に、headerFormat.getRowspan() を含ませて受け取る。 491 if( isUseCheckControl() && "checkbox".equals( getSelectedType() ) ) { 492 buf.append( thTag ).append( "></th>" ) 493 .append( thTag ).append( '>' ).append( getAllCheckControl() ).append( "</th>" ) // 6.0.2.5 (2014/10/31) char を append する。 494 .append( thTag ).append( '>' ).append( getNumberHeader() ).append( "</th>" ); // 6.0.2.5 (2014/10/31) char を append する。 495 } 496 else { 497 buf.append( thTag ).append( " colspan=\"3\">" ).append( getNumberHeader() ).append( "</th>" ); // 6.0.2.5 (2014/10/31) char を append する。 498 } 499 } 500 501 int cl = 0; 502 for( ; cl<headerFormat.getLocationSize(); cl++ ) { 503 buf.append( StringUtil.replace( headerFormat.getFormat(cl) ,"td","th" )); 504 final int loc = headerFormat.getLocation(cl); 505 // 6.4.3.4 (2016/03/11) ヘッダーでもTableFormatterのType(#,$,!)に対応した値を出すようにする。 506 if( loc >= 0 ) { 507 // 6.4.4.2 (2016/04/01) 処理の共通部をまとめる。 508 buf.append( getTypeCaseValue( headerFormat.getType(cl),-1,loc ) ); 509 } 510 } 511 buf.append( StringUtil.replace( headerFormat.getFormat(cl) ,"td","th" ) ).append( CR ); 512 513 return buf.toString(); // 6.1.2.0 (2015/01/24) 514 } 515 516 /** 517 * フォーマットを設定します。 518 * 519 * 520 * @param list TableFormatterのリスト 521 */ 522 @Override 523 public void setFormatterList( final List<TableFormatter> list ) { // 4.3.3.6 (2008/11/15) Generics警告対応 524 bodyFormats = new TableFormatter[BODYFORMAT_MAX_COUNT]; 525 526 bodyFormatsCount = 0; 527 for( int i=0; i<list.size(); i++ ) { 528 final TableFormatter format = list.get( i ); // 4.3.3.6 (2008/11/15) Generics警告対応 529 530 switch( format.getFormatType() ) { 531 case TYPE_HEAD : headerFormat = format; break; 532 case TYPE_BODY : bodyFormats[bodyFormatsCount++] = format; break; 533 case TYPE_FOOT : footerFormat = format; break; 534 default : final String errMsg = "FormatterType の定義外の値が指定されました。"; 535 // 4.3.4.4 (2009/01/01) 536 throw new HybsSystemException( errMsg ); 537 } 538 } 539 540 // 3.5.5.5 (2004/04/23) headerFormat が定義されていない場合はエラー 541 if( headerFormat == null ) { 542 final String errMsg = "h:thead タグの、フォーマットの指定は必須です。"; 543 throw new HybsSystemException( errMsg ); 544 } 545 } 546 547 /** 548 * フォーマットメソッドを使用できるかどうかを問い合わせます。 549 * 550 * @return 使用可能(true)/ 使用不可能 (false) 551 */ 552 @Override 553 public boolean canUseFormat() { 554 return true; 555 } 556 557 /** 558 * ビューで表示したカラムの一覧をCSV形式で返します。 559 * 560 * @og.rev 5.1.6.0 (2010/05/01) 新規追加 561 * @og.rev 6.2.0.1 (2015/03/06) TableFormatter#getLocation(int)の有効判定 562 * 563 * @return ビューで表示したカラムの一覧 564 * @og.rtnNotNull 565 */ 566 @Override 567 public String getViewClms() { 568 final DBTableModel table = getDBTableModel(); 569 final StringBuilder buf = new StringBuilder( BUFFER_MIDDLE ); 570 for( int i=0; i<headerFormat.getLocationSize(); i++ ) { 571 if( buf.length() > 0 ) { buf.append( ',' ); } 572 // 6.2.0.1 (2015/03/06) TableFormatter#getLocation(int)の有効判定 573 final int loc = headerFormat.getLocation(i); 574 if( loc >= 0 ) { buf.append( table.getColumnName( loc ) ); } 575 } 576 return buf.toString(); 577 } 578 579 /** 580 * 上下行のデータが同じ積上かどうかをチェックする。 581 * 582 * @param nRowIndex テーブルモデルの行番号 583 * @param astrOldValues 古いグルプーデータ配列 584 * 585 * @return 使用可能(true)/ 使用不可能 (false) 586 */ 587 private boolean isSameStack(final int nRowIndex, final String[] astrOldValues) { 588 boolean bRet = stackCols.length > 0 ; 589 if( bRet ) { 590 for( int nIndex=0; bRet && nIndex<stackCols.length ; nIndex++ ) { 591 bRet = astrOldValues[nIndex].equals( getValue( nRowIndex, stackCols[nIndex] ) ) ; 592 } 593 594 // 不一致時に astrOldValues に 新しい値を設定しておきます。 595 if( !bRet ) { 596 for( int nIndex=0; nIndex<stackCols.length; nIndex++ ) { 597 astrOldValues[nIndex] = getValue(nRowIndex, stackCols[nIndex]); 598 } 599 } 600 } 601 return bRet; 602 } 603 604 /** 605 * 対象カラムが積上げカラムかどうか。 606 * 607 * @param loc 列番号 608 * 609 * @return 対象(true)/ 非対象 (false) 610 */ 611 private boolean isStackClm(final int loc) { 612 boolean rtn = false; 613 for( int nIndex=0; nIndex<stackCols.length ; nIndex++ ) { 614 if( stackCols[nIndex] == loc ) { 615 rtn = true; 616 break; // 6.3.9.1 (2015/11/27) 617 } 618 } 619 return rtn; 620 } 621 622 /** 623 * 2つの日付の差を求めます。 624 * java.util.Date 型の日付 date1 - date2 が何日かを返します。 625 * 626 * @og.rev 5.5.8.3 (2012/11/17) 新規 627 * 628 * @param date1 日付 629 * @param date2 日付 630 * @return 2つの日付の差(日数 2-1) 同日なら0 631 */ 632 public static int differenceDays(final Date date1,final Date date2) { 633 final long datetime1 = date1.getTime(); 634 final long datetime2 = date2.getTime(); 635 final long one_date_time = 1000 * 60 * 60 * 24L; 636 return (int)((datetime2 - datetime1) / one_date_time); 637 } 638 639 /** 640 * 日付から枠番号を返す。 641 * 642 * @og.rev 5.5.8.3 (2012/11/17) 新規 643 * 644 * @param date 日付(YYYY/MM/DD) 645 * @param zoom Zoom設定値 646 * @param calFD ヘッダ初日 647 * 648 * @return 枠番号 649 */ 650 private int calNumber(final Date date, final String zoom, final Date calFD ) { 651 // 6.3.9.1 (2015/11/27) Found 'DD'-anomaly for variable(PMD) 652 final int rtn ; 653 if( zoom.equals( ViewStackTableParam.STACK_ZOOM_MONTH ) ){ 654 // 月だけは別の計算が必要 655 final Calendar cal1 = Calendar.getInstance(); 656 cal1.setTime( calFD ); 657 final Calendar cal2 = Calendar.getInstance(); 658 cal2.setTime( date ); 659 rtn = ( cal2.get( Calendar.YEAR )-cal1.get( Calendar.YEAR ) ) * 12 660 + ( cal2.get( Calendar.MONTH ) - cal1.get( Calendar.MONTH ) ); 661 } 662 else{ 663 final int diff = differenceDays( calFD, date ); 664 if( zoom.equals( ViewStackTableParam.STACK_ZOOM_WEEK )){ 665 rtn = diff/7; 666 } 667 else{ 668 rtn = diff; 669 } 670 } 671 return rtn; 672 } 673 674 /** 675 * テーブル本体の作成。 676 * 677 * @og.rev 5.5.8.3 (2012/11/17) 繰り返し利用するため分離 678 * @og.reb 5.6.1.2 (2013/02/22) td終了が抜けていたので追加、キャパシティ対応 679 * @og.reb 6.1.0.0 (2014/12/26) 引数に StringBuffer を追加し、それに、データを追記していく。 680 * @og.rev 6.4.3.4 (2016/03/11) tdに、[カラム]が無いケースで、次の[カラム]のクラス属性が、前方すべてのtdにセットされてしまう対応。 681 * @og.rev 6.4.4.2 (2016/04/01) TableFormatterのタイプ別値取得処理の共通部をまとめる。 682 * @og.rev 6.4.5.0 (2016/04/08) メソッド変更( getColumnDbType(int) → getClassName(int) ) 683 * @og.rev 6.8.1.1 (2017/07/22) ckboxTD変数は、<td> から <td に変更します(タグの最後が記述されていない状態でもらう)。 684 * @og.rev 6.8.2.0 (2017/10/13) makeNthChildの廃止と、makeCheckboxで、個別にclass指定するように変更。 685 * 686 * @param outBuf データを追加するStringBuffer 687 * @param row テーブルモデルのrow 688 * @param stackRow スタック行保存用 689 * @param bgClrCnt 背景色カウンタ 690 * @param blc チェックボックス用 691 * @param costAry コスト集計配列 692 * @param cap 能力 693 * 694 * @return テーブル本体のHTML(入力の out オブジェクトそのもの) 695 * @og.rtnNotNull 696 */ 697 private StringBuilder makeBodyTable( final StringBuilder outBuf, final int row, final int stackRow, 698 final int bgClrCnt, final int blc, final double[] costAry, final String cap ) { 699 int bcCnt = bgClrCnt; // 6.0.0.1 (2014/04/25) 引数を直接変更できなくする。 700 for( int i=0; i<bodyFormatsCount; i++ ) { 701 final TableFormatter bodyFormat = bodyFormats[i]; 702 if( ! bodyFormat.isUse( row,getDBTableModel() ) ) { continue; } 703 outBuf.append("<tbody").append( getBgColorCycleClass( bcCnt++,row ) ); 704 if( isNoTransition() ) { 705 outBuf.append( getHiddenRowValue( row ) ); 706 } 707 outBuf.append( STACK_TBODY ) 708 .append( STACK_ROW_PREFIX ).append( stackRow ).append( '\'' ) 709 .append( STACK_ID_PREFIX ).append( stackRow ).append( "'>" ) 710 .append( bodyFormat.getTrTag() ); 711 712 // No 欄そのものの作成判断追加 713 if( isNumberDisplay() ) { 714 final String ckboxTD = "<td" + bodyFormat.getRowspan(); // 6.8.1.1 (2017/07/22) 715 outBuf.append( makeCheckbox( ckboxTD,row,blc,true ) ); // 6.8.2.0 (2017/10/13) 716 } 717 718 int cl = 0; 719 for( ; cl<bodyFormat.getLocationSize(); cl++ ) { 720 String fmt = bodyFormat.getFormat(cl); 721 final int loc = bodyFormat.getLocation(cl); // 3.5.5.0 (2004/03/12) 722 if( ! bodyFormat.isNoClass() && loc >= 0 ) { // 3.5.5.7 (2004/05/10) 723 // 6.4.3.4 (2016/03/11) tdに、[カラム]が無いケースで、次の[カラム]のクラス属性が、前方すべてのtdにセットされてしまう対応。 724 final int idx = fmt.lastIndexOf( "<td" ); 725 if( idx >= 0 ) { // matchしてるので、あるはず 726 final String tdclass = " class=\"" + getClassName(loc) + "\" "; // 6.4.5.0 (2016/04/08) 727 fmt = fmt.substring( 0,idx+3 ) + tdclass + fmt.substring( idx+3 ) ; 728 } 729 } 730 outBuf.append( fmt ); 731 732 // locがstackに入っていれば出力 733 if( isStackClm(loc) ){ 734 if( loc >= 0 ) { 735 // 6.4.4.2 (2016/04/01) 処理の共通部をまとめる。 736 outBuf.append( getTypeCaseValue( bodyFormat.getType(cl),row,loc ) ); 737 } 738 else { 739 outBuf.append( bodyFormat.getSystemFormat(row,loc) ); 740 } 741 } 742 } 743 // 5.5.8.3 (2012/11/17)内部積上げの結果は出力場所の特定が難しいため一番最後尾にtd付きで出力しておきます 744 if( innerStack ){ 745 outBuf.append("</td><td><div class='stackDivParent' capacity='"+ cap + "' style='width:100%; position:relative;'>"); // 5.6.1.2 (2013/02/22) td終了追加 746 for( int cs=0; cs<costAry.length; cs++ ){ 747 outBuf.append("<div class='stackDiv' style='position:absolute; top:0px;' num='") 748 .append( cs) 749 .append("' stackedCost='") 750 .append( costAry[cs] ) 751 .append( "'></div>"); 752 } 753 outBuf.append("</div>"); 754 } 755 756 outBuf.append( bodyFormat.getFormat(cl) ) 757 .append("</tbody>").append( CR ); 758 } 759 return outBuf; 760 } 761}