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.hayabusa.taglib; 017 018import static org.opengion.fukurou.util.StringUtil.nval; 019 020import java.util.ArrayList; 021import java.util.Collections; 022import java.util.Enumeration; 023import java.util.HashMap; 024import java.util.List; 025import java.util.Map; 026 027import org.opengion.fukurou.util.StringUtil; 028import org.opengion.fukurou.util.TagBuffer; 029import org.opengion.hayabusa.common.HybsSystem; 030import org.opengion.hayabusa.common.HybsSystemException; 031import org.opengion.hayabusa.db.DBColumn; 032import org.opengion.hayabusa.db.DBEditConfig; 033import org.opengion.hayabusa.db.DBLastSql; 034import org.opengion.hayabusa.db.DBTableModel; 035 036/** 037 * 画面表示、集計に関する設定情報の表示、登録を行うためのタグです。 038 * (このタグは標準の設定編集画面に組み込んで使用され、各画面JSPから呼び出すことはありません) 039 * 040 * このタグは、ユーザー単位に管理されるエディット設定オブジェクトに対するI/Fの機能を 041 * 提供しています。このエディット設定オブジェクトについては、画面毎に設定を行うため、 042 * タグの呼び出しには、画面IDが必須となっています。 043 * 044 * 具体的な機能としては、3つの機能を提供します。 045 * (1)設定画面表示(command="GET") 046 * ユーザー単位に管理されるエディット設定オブジェクトをHTMLに変換して表示 047 * また、表示カラムの一覧(カンマ区切り)については、画面側のJavaScriptで再設定を行うため、 048 * その値を"viewClms"という名前のhiddenタグで出力します。 049 * (2)エディット名一覧(command="LIST") 050 * 指定の画面IDに対して、設定されているエディット名の一覧をプルダウン(selectタグ)に 051 * 変換して表示します。(name="editName") 052 * (3)設定情報登録/削除(command="SET"/"DELETE") 053 * (1)で設定された内容に対して、エディット名を指定してその内容を保存/削除します。 054 * 情報の保存は、command="GET"で表示される項目名と連動していますので、単独での使用は 055 * できません。 056 * 057 * @og.formSample 058 * ●形式:一般ユーザーが直接組み込むことはありません。 059 * ●body:なし 060 * 061 * ●Tag定義: 062 * <og:editConfig 063 * command ○【TAG】command を指定します(必須)。 064 * gamenId ○【TAG】画面ID を指定します(必須)。 065 * editName 【TAG】エディット名 を指定します 066 * debug 【TAG】デバッグ情報を出力するかどうか[true/false]を指定します(初期値:false) 067 * /> 068 * 069 * ●使用例 070 * <og:editConfig command="{@command}" gamenId="{@gamenId}" editName="{@editName}" /> 071 * 072 * <og:editConfig 073 * command = command設定 (GET/LIST/SET/REMOVE) 074 * gamenId = "GE0000" 画面ID 075 * [ editName ] = "EDITNAME" エディット名 076 * /> 077 * 078 * @og.group エディット設定 079 * 080 * @og.rev 5.3.6.0 (2011/06/01) 081 * 082 * @version 5.0 083 * @author Hiroki Nakamura 084 * @since JDK6.0, 085 */ 086public class EditConfigTag extends CommonTagSupport { 087 //* このプログラムのVERSION文字列を設定します。 {@value} */ 088 private static final String VERSION = "5.7.5.2 (2014/04/11)" ; 089 090 private static final long serialVersionUID = 575220140411L ; 091 092 private static final String VIEW_PREFIX = "EDIT_VIEW_"; 093 private static final String SUM_PREFIX = "EDIT_SUM_"; 094 private static final String GROUP_PREFIX = "EDIT_GROUP_"; 095 private static final String SUBTOTAL_PREFIX = "EDIT_SUBTOTAL_"; 096 private static final String TOTAL_PREFIX = "EDIT_TOTAL_"; 097 private static final String ORDERBY_PREFIX = "EDIT_ORDERBY_"; 098 private static final String DESC_PREFIX = "EDIT_DESC_"; 099 private static final String GRANDTOTAL_PREFIX = "EDIT_GRANDTOTAL_"; 100 private static final String COMMON_PREFIX = "EDIT_COMMON_"; 101 102 private String command = null; // EW" 、アップロード="COPY|INSERT" 103 private String gamenId = null; 104 private String editName = null; 105 106 private transient DBTableModel table = null; // 5.5.2.4 (2012/05/16) transient 定義追加 107 private transient DBEditConfig config = null; // 5.5.2.4 (2012/05/16) transient 定義追加 108 109 private boolean orderOnly = false; // 5.5.5.2 (2012/08/10) 110 111 /** 112 * Taglibの開始タグが見つかったときに処理する doStartTag() を オーバーライドします。 113 * 114 * @return 後続処理の指示(SKIP_BODY) 115 */ 116 @Override 117 public int doStartTag() { 118 return SKIP_BODY ; // Body を評価しない 119 } 120 121 /** 122 * Taglibの終了タグが見つかったときに処理する doEndTag() を オーバーライドします。 123 * 124 * @og.rev 5.7.1.2 (2013/12/20) msg ⇒ errMsg 変更 125 * 126 * @return 後続処理の指示 127 */ 128 @Override 129 public int doEndTag() { 130 debugPrint(); 131 132 StringBuilder buf = new StringBuilder( HybsSystem.BUFFER_MIDDLE ); 133 134 // エディット情報をHTMLに変換して表示します。 135 // 表示に当たって、最後に発行されたQUERYのtableId、scopeをチェックした上で 136 // 表示するかを判断します。 137 if( "GET".equals( command ) ) { 138 DBLastSql lastSql = (DBLastSql)getSessionAttribute( HybsSystem.DB_LAST_SQL_KEY ); 139 if( lastSql != null ) { 140 if( !lastSql.isViewEditable() ) { 141 // この画面は、項目の並び替えはできません。 142 String rtn = "<b style=\"font-color:red;\">" + getResource().getLabel( "GEE0003" ) + "</b>"; 143 jspPrint( rtn ); 144 } 145 else if( lastSql.isGuiMatch( gamenId ) ) { 146 setScope( lastSql.getScope() ); 147 table = (DBTableModel)getObject( lastSql.getTableId() ); 148 if( table != null ) { 149 config = getUser().getEditConfig( gamenId, editName ); 150 String viewClms = null; 151 if( config == null ) { 152 viewClms = lastSql.getViewClmNames(); 153 config = new DBEditConfig(); 154 } 155 else { 156 viewClms = config.getViewClms(); 157 } 158 buf.append( makeEditTable( viewClms ) ); 159 } 160 } 161 } 162 } 163 // エディット情報を保存します。 164 else if( "SET".equals( command ) ) { 165 if( editName == null || editName.length() == 0 ) { 166 String errMsg = "エディット名が指定されていません。"; 167 throw new HybsSystemException( errMsg ); // 5.7.1.2 (2013/12/20) msg ⇒ errMsg 変更 168 } 169 saveEditConfig(); 170 } 171 // エディット情報を削除します。 172 else if( "DELETE".equals( command ) ) { 173 if( editName == null || editName.length() == 0 ) { 174 String errMsg = "エディット名が指定されていません。"; 175 throw new HybsSystemException( errMsg ); // 5.7.1.2 (2013/12/20) msg ⇒ errMsg 変更 176 } 177 deleteEditConfig(); 178 } 179 // 指定された画面IDに対するエディット情報の一覧(プルダウン)を表示します。 180 else if( "LIST".equals( command ) ) { 181 DBEditConfig[] configs = getUser().getEditConfigs( gamenId ); 182 if( configs != null && configs.length > 0 ) { 183 buf.append( getEditSelect( configs ) ).append( HybsSystem.CR ); 184 } 185 } 186 187 jspPrint( buf.toString() ); 188 189 return EVAL_PAGE ; 190 } 191 192 /** 193 * タグリブオブジェクトをリリースします。 194 * キャッシュされて再利用されるので、フィールドの初期設定を行います。 195 * 196 * @og.rev 5.5.5.2 (2012/08/10) orderOnly対応 197 */ 198 @Override 199 protected void release2() { 200 super.release2(); 201 command = "GET"; 202 gamenId = null; 203 editName = null; 204 table = null; 205 config = null; 206 orderOnly = false; //5.5.5.2 (2012/08/10) 207 } 208 209 /** 210 * エディット情報をHTMLに変換して表示します。 211 * 212 * @og.rev 5.4.2.0 (2011/12/01) 入替え対象のカラム列でのみスクロールが表示されるように対応します。 213 * @og.rev 5.5.5.2 (2012/08/10) orderOnly対応 214 * 215 * @param viewClms 表示カラム(カンマ区切り) 216 * 217 * @return エディット情報のHTML 218 */ 219 private String makeEditTable( final String viewClms ) { 220 StringBuilder buf = new StringBuilder( HybsSystem.BUFFER_MIDDLE ); 221 222 boolean useSum = getUseSum( viewClms ); 223 String[] viewGroups = StringUtil.csv2Array( viewClms, '|' ); 224 buf.append( "<input type=\"hidden\" name=\"viewClms\" id=\"viewClms\" value=\"" + viewClms + "\"/>" ); 225 buf.append( "<div />" ); 226 buf.append( "<div style=\"float:left;\">" ); 227 buf.append( makeLabelRow( useSum ) ); 228 buf.append( "</div>" ); 229 buf.append( "<div id=\"clmLayer\" style=\" float:left; width: 670px;overflow-x:scroll;\">" ); 230 for( int i=0; i<viewGroups.length; i++ ) { 231 if( i > 0 ) { 232 buf.append( makeSeparateRow( useSum ) ); 233 } 234 buf.append( "<table class=\"clmGroup\" style=\"float:left;\"><tr>" ); 235 String[] clms = StringUtil.csv2Array( viewGroups[i] ); 236 for( int j=0; j<clms.length; j++ ) { 237 String clm = ( !clms[j].startsWith( "!" ) ? clms[j] : clms[j].substring( 1 ) ); 238 if( "rowCount".equals( clm ) ) { continue; } 239 boolean isView = ( !clms[j].startsWith( "!" ) ? true : false ); 240 buf.append( makeColumnRow( clm, isView, useSum, config ) ); 241 } 242 buf.append( "</tr></table>" ); 243 } 244 buf.append( "</div>" ); 245 246 String grandTotalLabel = "<b>" + getDBColumn( GRANDTOTAL_PREFIX + "LABEL" ).getLongLabel() + ":</b>"; 247 buf.append( "<div style=\"clear:both;\">" ); 248 buf.append( "<table>" ); 249 buf.append( makeCheckbox( GRANDTOTAL_PREFIX, config.useGrandTotal(), "h", grandTotalLabel, orderOnly ) ); // 5.5.5.2 (2012/08/10) 250 buf.append( "</table>" ); 251 buf.append( "</div>" ); 252 253 return buf.toString(); 254 } 255 256 /** 257 * エディット情報のヘッダー(ラベル行)のHTMLを生成します。 258 * 259 * @og.rev 5.4.2.0 (2011/12/01) 表示項目の全チェック機能を追加 260 * @og.rev 5.5.5.2 (2012/08/10) orderOnly対応 261 * 262 * @param useSum 集計対象のカラム(=NUMBER型)が存在しているか 263 * 264 * @return エディット情報のヘッダー(ラベル行)のHTML 265 */ 266 private String makeLabelRow( final boolean useSum ) { 267 StringBuilder buf = new StringBuilder( HybsSystem.BUFFER_SMALL ); 268 String commonLabel = "<b>" + getDBColumn( COMMON_PREFIX + "LABEL" ).getLongLabel() + ":</b>"; 269 String canEditCommon = HybsSystem.sys( "EDIT_COMMON_ROLES" ); 270 271 String groupLabel = "<b>" + getDBColumn( GROUP_PREFIX + "LABEL" ).getLongLabel() + "</b>"; 272 groupLabel += "<img id=\"groupBtn\" src=\"" + HybsSystem.sys( "JSP" ) + "/image/ball-green.gif\" />"; 273 274 buf.append( "<table><tr>" ); 275 buf.append( "<td style=\"margin:0px; padding:0px;\"><table>" ); 276 if( getUser().isAccess( canEditCommon ) ) { 277 buf.append( makeCheckbox( COMMON_PREFIX, config.isCommon(), "h", commonLabel, orderOnly ) ); // 5.5.5.2 (2012/08/10) 278 } 279 else { 280 buf.append( makeLabel ( commonLabel ) ); 281 } 282 String viewLabel = "<b>" + getDBColumn( VIEW_PREFIX + "LABEL" ).getLongLabel() + ":</b>"; 283 buf.append( makeCheckbox( "VIEW_ALL_CHECK", true, "h", viewLabel, orderOnly ) ); // 5.5.5.2 (2012/08/10) 284 if( useSum ) { 285 buf.append( makeLabel ( SUM_PREFIX + "LABEL" ) ); 286 } 287 buf.append( makeCell ( groupLabel, "h" ) ); 288 buf.append( makeLabel ( SUBTOTAL_PREFIX + "LABEL" ) ); 289 buf.append( makeLabel ( TOTAL_PREFIX + "LABEL" ) ); 290 buf.append( makeLabel ( ORDERBY_PREFIX + "LABEL" ) ); 291 buf.append( makeLabel ( DESC_PREFIX + "LABEL" ) ); 292 buf.append( "</table></td>" ); 293 buf.append( "</tr></table>" ); 294 return buf.toString(); 295 } 296 297 /** 298 * エディット情報のカラム列のHTMLを生成します。 299 * 300 * @og.rev 5.5.5.2 (2012/08/10) orderOnly対応 301 * @og.rev 5.7.5.2 (2014/04/11) 降順はorderOnlyに関わらず編集可能にする 302 * 303 * @param clm カラム 304 * @param isView 表示対象かどうか 305 * @param useSum 集計対象のカラム(=NUMBER型)が存在しているか 306 * @param config エディット設定オブジェクト 307 * 308 * @return エディット情報のカラム列のHTMLを生成します。 309 */ 310 private String makeColumnRow( final String clm, final boolean isView, final boolean useSum, final DBEditConfig config ) { 311 StringBuilder buf = new StringBuilder( HybsSystem.BUFFER_SMALL ); 312 313 int clmNo = table.getColumnNo( clm, false ); 314 DBColumn column = ( clmNo < 0 ? getDBColumn( clm ) : table.getDBColumn( clmNo ) ); 315 buf.append( "<td name=\"" ).append( clm ).append( "\" class=\"sortItem\" style=\"margin:0px; padding:0px;\">" ); 316 buf.append( "<table>" ); 317 buf.append( makeLabel ( column.getLongLabel() ) ); 318 buf.append( makeCheckbox( VIEW_PREFIX + clm, isView , "0", null, orderOnly ) ); // 5.5.5.2 (2012/08/10) 319 if( useSum ) { 320 boolean isSumClm = isNumberClm( clm ); 321 buf.append( makeCheckbox( SUM_PREFIX + clm, config.isSumClm( clm ) , "1", isSumClm , null, orderOnly ) ); // 5.5.5.2 (2012/08/10) 322 } 323 buf.append( makeCheckbox( GROUP_PREFIX + clm, config.isGroupClm( clm ) , "0", null, orderOnly ) ); // 5.5.5.2 (2012/08/10) 324 buf.append( makeCheckbox( SUBTOTAL_PREFIX + clm, config.isSubTotalClm( clm ) , "1", null, orderOnly ) ); // 5.5.5.2 (2012/08/10) 325 buf.append( makeCheckbox( TOTAL_PREFIX + clm, config.isTotalClm( clm ) , "0", null, orderOnly ) ); // 5.5.5.2 (2012/08/10) 326 buf.append( makeInput ( ORDERBY_PREFIX + clm, config.getOrder( clm ) , "1", null ) ); 327// buf.append( makeCheckbox( DESC_PREFIX + clm, config.isOrderByDesc( clm ) , "0", null, orderOnly ) ); // 5.5.5.2 (2012/08/10) 328 buf.append( makeCheckbox( DESC_PREFIX + clm, config.isOrderByDesc( clm ) , "0", null, false ) ); // 5.7.5.1 (2014/04/11) 329 buf.append( "</table>" ); 330 buf.append( "</td>" ); 331 332 return buf.toString(); 333 } 334 335 /** 336 * チェックボックスのHTML文字列を生成します。 337 * 生成したHTMLは以下のようになります。 338 * 例)<tr><td class="row_[bgCnt]" ...>[prefix]<input type="checkbox" name="[clm]" ... /></td></tr> 339 * 340 * @param clm カラム 341 * @param checked 初期チェックするかどうか 342 * @param bgCnt 背景色ゼブラカラーの指定("0"or"1"or"h") 343 * @param prefix チェックボックスのタグの前に挿入するHTML文字列 344 * @param readonly リードオンリー 345 * 346 * @og.rev 5.5.5.2 (2012/08/10) readOnly追加 347 * 348 * @return チェックボックスのHMTL文字列 349 */ 350 private String makeCheckbox( final String clm, final boolean checked, final String bgCnt, final String prefix, final boolean readonly ) { 351 return makeCheckbox( clm, checked, bgCnt, true, prefix, readonly ); 352 } 353 354 /** 355 * チェックボックスのHTML文字列を生成します。 356 * 生成したHTMLは以下のようになります。 357 * 例)<tr><td class="row_[bgCnt]" ...>[prefix]<input type="checkbox" name="[clm]" ... /></td></tr> 358 * 359 * @param clm カラム 360 * @param checked 初期チェックするかどうか 361 * @param bgCnt 背景色ゼブラカラーの指定("0"or"1"or"h") 362 * @param isChbox チェックボックスを生成するかどうか(falseの場合、チェックボックスのinputタグは生成されません) 363 * @param prefix チェックボックスのタグの前に挿入するHTML文字列 364 * @param readonly リードオンリー 365 * 366 * @og.rev 5.5.5.2 (2012/08/10) readOnly追加 367 * 368 * @return チェックボックスのHMTL文字列 369 */ 370 private String makeCheckbox( final String clm, final boolean checked, final String bgCnt, final boolean isChbox, final String prefix, final boolean readonly ) { 371 if( isChbox ) { 372 String suffix = ""; 373 TagBuffer tag = new TagBuffer( "input" ); 374 tag.add( "type", "checkbox" ); 375 tag.add( "name", clm ); 376 tag.add( "value", "1" ); 377 if( checked ) { 378 tag.add( "checked", "checked" ); 379 } 380 if( readonly ){ // 5.5.5.2 (2012/08/10) 381 tag.add( "disabled", "disabled" ); 382 if( checked ){ 383 TagBuffer tag2 = new TagBuffer( "input" ); 384 tag2.add( "type", "hidden" ); 385 tag2.add( "name", clm ); 386 tag2.add( "value", "1" ); 387 suffix += tag2.makeTag(); 388 } 389 390 } 391 return makeCell( ( prefix == null ? "" : prefix ) + tag.makeTag() + suffix, bgCnt ); // 5.5.5.2 (2012/08/10) 392 } 393 else { 394 return makeCell( ( prefix == null ? "" : prefix ) + " ", bgCnt ); 395 } 396 } 397 398 /** 399 * テキスト入力HTML文字列を生成します。 400 * 生成したHTMLは以下のようになります。 401 * 例)<tr><td class="row_[bgCnt]" ...>[prefix]<input type="text" name="[clm]" ... /></td></tr> 402 * 403 * @param clm カラム 404 * @param value 初期チェックするかどうか 405 * @param bgCnt 背景色ゼブラカラーの指定("0"or"1"or"h") 406 * @param prefix チェックボックスのタグの前に挿入するHTML文字列 407 * 408 * @return チェックボックスのHMTL文字列 409 */ 410 private String makeInput( final String clm, final String value, final String bgCnt, final String prefix ) { 411 TagBuffer tag = new TagBuffer( "input" ); 412 tag.add( "type", "text" ); 413 tag.add( "name", clm ); 414 tag.add( "value", value ); 415 tag.add( "style", "width: 10px; font-size:10px;" ); 416 tag.add( "maxlength", "2" ); 417 tag.add( "class", "S9" ); 418 419 return makeCell( ( prefix == null ? "" : prefix ) + tag.makeTag(), bgCnt ); 420 } 421 422 /** 423 * 左右分割されている際の分割列のHTML文字列を生成します。 424 * 425 * @param useSum 集計対象のカラム(=NUMBER型)が存在しているか 426 * 427 * @return チェックボックスのHMTL文字列 428 */ 429 private String makeSeparateRow( final boolean useSum ) { 430 StringBuilder buf = new StringBuilder( HybsSystem.BUFFER_SMALL ); 431 432 buf.append( "<table style=\"float:left;\"><tr>" ); 433 buf.append( "<td style=\"margin:0px; padding:0px;\"><table>" ); 434 buf.append( makeCell( " ", "h" ) ); // ラベル 435 buf.append( makeCell( " ", "h" ) ); // 表示 436 if( useSum ) { 437 buf.append( makeCell( " ", "h" ) ); // 集計項目 438 } 439 buf.append( makeCell( " ", "h" ) ); // 集計キー 440 buf.append( makeCell( " ", "h" ) ); // 小計キー 441 buf.append( makeCell( " ", "h" ) ); // 合計キー 442 buf.append( makeCell( " ", "h" ) ); // 表示順 443 buf.append( makeCell( " ", "h" ) ); // 昇順・降順 444 buf.append( "</table></td>"); 445 buf.append( "</tr></table>" ); 446 447 return buf.toString(); 448 } 449 450 /** 451 * ラベルのHTML文字列を生成します。 452 * 453 * @param clm カラム 454 * 455 * @return ラベルのHTML文字列 456 */ 457 private String makeLabel( final String clm ) { 458 return makeCell( getDBColumn( clm ).getLongLabel(), "h" ); 459 } 460 461 /** 462 * セルのHTML文字列を生成します。 463 * 464 * @param body tdタグ内のHTML文字列 465 * @param bgCnt 背景色ゼブラカラーの指定("0"or"1"or"h") 466 * 467 * @return セルのHTML文字列 468 */ 469 private String makeCell( final String body, final String bgCnt ) { 470 return "<tr><td align=\"center\" style=\"height:22px;\" class=\"row_" + bgCnt + "\">" + body + "</td></tr>"; 471 } 472 473 /** 474 * このエディット設定で集計対象のカラム(=NUMBER型)が存在しているかを返します。 475 * 476 * @param viewClms カラム 477 * 478 * @return 集計対象のカラム(=NUMBER型)が存在しているか 479 */ 480 private boolean getUseSum( final String viewClms ) { 481 if( viewClms == null ) { return false; } 482 483 boolean rtn = false; 484 String[] clms = StringUtil.csv2Array( viewClms.replace( '|', ',' ) ); 485 for( int j=0; j<clms.length; j++ ) { 486 String clm = ( !clms[j].startsWith( "!" ) ? clms[j] : clms[j].substring( 1 ) ); 487 rtn = isNumberClm( clm ); 488 if( rtn ) { break; } 489 } 490 return rtn; 491 } 492 493 /** 494 * 引数のカラムがNUMBER型かどうかをチェックします。 495 * 496 * @param clm カラム 497 * 498 * @return NUMBER型かどうか 499 */ 500 private boolean isNumberClm( final String clm ) { 501 if( clm == null ) { return false; } 502 503 int no = table.getColumnNo( clm, false ); 504 if( no >= 0 ) { 505 DBColumn dbClm = table.getDBColumn( table.getColumnNo( clm ) ); 506 // 6.0.0.1 (2014/04/25) These nested if statements could be combined 507 if( dbClm != null && "NUMBER".equals( dbClm.getClassName()) ) { 508 return true; 509 } 510 } 511 return false; 512 } 513 514 /** 515 * エディット設定情報を保存します。 516 */ 517 private void saveEditConfig() { 518 String viewClms = getRequest().getParameter( "viewClms" ); 519 String sumClms = getColumns( SUM_PREFIX ); 520 String groupClms = getColumns( GROUP_PREFIX ); 521 String subTotalClms = getColumns( SUBTOTAL_PREFIX ); 522 String totalClms = getColumns( TOTAL_PREFIX ); 523 String useGrandTotal= getRequest().getParameter( GRANDTOTAL_PREFIX ); 524 String orderByClms = getOrderByColumns(); 525 String isCommon = getRequest().getParameter( COMMON_PREFIX ); 526 527 DBEditConfig config 528 = new DBEditConfig( editName, viewClms, sumClms, groupClms 529 , subTotalClms, totalClms, useGrandTotal, orderByClms, isCommon ); 530 531 getUser().addEditConfig( gamenId, editName, config ); 532 } 533 534 /** 535 * エディット設定情報を削除します。 536 */ 537 private void deleteEditConfig() { 538 getUser().deleteEditConfig( gamenId, editName ); 539 } 540 541 /** 542 * パラメーターから引数のプレフィックスをキーに、チェックされたカラム一覧(カンマ区切り)を返します。 543 * 544 * @param prefixKey 各キーの取得するためのプレフィックス 545 * 546 * @return カラム一覧(カンマ区切り) 547 */ 548 private String getColumns( final String prefixKey ) { 549 StringBuilder buf = new StringBuilder(); 550 551 Enumeration<?> enume = getParameterNames(); 552 while( enume.hasMoreElements() ) { 553 String key = (String)(enume.nextElement()); 554 if( key.startsWith( prefixKey ) ) { 555 String val = getRequest().getParameter( key ); 556 if( "1".equals( val ) ) { 557 String clm = key.substring( prefixKey.length() ); 558 if( buf.length() > 0 ) { buf.append( "," ); } 559 buf.append( clm ); 560 } 561 } 562 } 563 564 return buf.toString(); 565 } 566 567 /** 568 * 表示順のカラム一覧(カンマ区切り)を返します。 569 * 570 * @return 表示順のカラム一覧(カンマ区切り) 571 */ 572 private String getOrderByColumns() { 573 Enumeration<?> enume = getParameterNames(); 574 List<Integer> orderNo = new ArrayList<Integer>(); 575 Map<Integer,String> orderClm = new HashMap<Integer,String>(); 576 while( enume.hasMoreElements() ) { 577 String key = (String)(enume.nextElement()); 578 if( key.startsWith( ORDERBY_PREFIX ) ) { 579 String val = getRequest().getParameter( key ); 580 if( val != null && val.length() > 0 ) { 581 String clm = key.substring( ORDERBY_PREFIX.length() ); 582 String desc = getRequest().getParameter( DESC_PREFIX + clm ); 583 if( "1".equals( desc ) ) { 584 clm = "!" + clm; 585 } 586 // 数字項目以外が入力された場合は無視 587 Integer odno = null; 588 try { 589 odno = Integer.valueOf( val ); 590 } 591 catch ( NumberFormatException ex ) { 592 continue; 593 } 594 String str = orderClm.get( odno ); 595 // 同じ番号の場合でも重ならないように振り直しする。 596 while( str != null ) { 597 odno = Integer.valueOf( odno.intValue() + 1 ); 598 str = orderClm.get( odno ); 599 } 600 orderClm.put( odno, clm ); 601 orderNo.add( odno ); 602 } 603 } 604 } 605 606 Collections.sort( orderNo ); 607 608 StringBuilder buf = new StringBuilder(); 609 for( Integer i : orderNo ) { 610 if( buf.length() > 0 ) { buf.append( "," ); } 611 String clm = orderClm.get( i ); 612 buf.append( clm ); 613 } 614 615 return buf.toString(); 616 } 617 618 /** 619 * エディット設定一覧のプルダウンメニューを作成します。 620 * 621 * @param configs DBEditConfig配列 622 * 623 * @return エディット一覧のプルダウン 624 */ 625 private String getEditSelect( final DBEditConfig[] configs ) { 626 DBColumn column = getDBColumn( "editName" ); 627 628 StringBuilder buf = new StringBuilder(); 629 buf.append( "<span class=\"label editName\">" ) 630 .append( column.getLongLabel() ) 631 .append( ":</span><span class=\"editName\">" ) 632 .append( "<select name=\"editName\">" ) 633 .append( "<option />" ); 634 for( DBEditConfig config : configs ) { 635 String name = config.getEditName(); 636 buf.append( "<option value=\"" ).append( name ).append( "\"" ); 637 if( config.isCommon() ) { 638 buf.append( " class=\"commonEdit\"" ); 639 } 640 buf.append( "\">" ); 641 buf.append( name ).append( "</option>" ); 642 } 643 buf.append( "</select></span>" ); 644 return buf.toString(); 645 } 646 647 /** 648 * 【TAG】command を指定します。 649 * 650 * @og.tag 651 * command を指定します。 652 * [GET/LIST/SET/DELETE]のみが設定可能です。それ以外の場合、何も処理されません。 653 * 654 * @param cmd コマンド[GET/LIST/SET/DELETE] 655 */ 656 public void setCommand( final String cmd ) { 657 command = nval( getRequestParameter( cmd ),command ); 658 } 659 660 /** 661 * 【TAG】画面ID を指定します。 662 * 663 * @og.tag 664 * 画面ID を指定します。 665 * 666 * @param key 画面ID 667 */ 668 public void setGamenId( final String key ) { 669 gamenId = nval( getRequestParameter( key ),gamenId ); 670 } 671 672 /** 673 * 【TAG】エディット名 を指定します。 674 * 675 * @og.tag 676 * エディット名 を指定します。 677 * commandがSETまたはDELETEの場合は必須です。 678 * commandがGETまたはLISTの場合は無効です。 679 * 680 * @param name エディット名 681 */ 682 public void setEditName( final String name ) { 683 editName = nval( getRequestParameter( name ),editName ); 684 } 685 686 /** 687 * 【TAG】チェックボックスのリードオンリー化を行います 688 * 689 * @og.tag 690 * 順番の入れ替えと、表示順の設定のみを行う場合にtrueにします。 691 * 表示/非表示切替や、集計機能は利用できなくなります。 692 * (チェックボックスのリードオンリーはできないため、実際にはdisable+hiddenで出力しています) 693 * 694 * @og.rev 5.5.5.2 (2012/08/10) 新規追加 695 * 696 * @param flag [true:リードオンリー/それ以外:編集可] 697 */ 698 public void setOrderOnly( final String flag ) { 699 orderOnly = nval( getRequestParameter( flag ),orderOnly ); 700 } 701 702 /** 703 * このオブジェクトの文字列表現を返します。 704 * 基本的にデバッグ目的に使用します。 705 * 706 * @return このクラスの文字列表現 707 */ 708 @Override 709 public String toString() { 710 return org.opengion.fukurou.util.ToString.title( this.getClass().getName() ) 711 .println( "VERSION" ,VERSION ) 712 .println( "command" ,command ) 713 .println( "gamenId" ,gamenId ) 714 .println( "editName" ,editName ) 715 .println( "Other..." ,getAttributes().getAttribute() ) 716 .fixForm().toString() ; 717 } 718}