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.column; 017 018import org.opengion.hayabusa.common.HybsSystem; 019import org.opengion.hayabusa.db.AbstractEditor; 020import org.opengion.hayabusa.db.CellEditor; 021import org.opengion.hayabusa.db.DBColumn; 022import org.opengion.fukurou.util.XHTMLTag; 023import org.opengion.fukurou.util.TagBuffer; 024 025import static org.opengion.fukurou.util.StringUtil.isNull; // 6.1.1.0 (2015/01/17) 026 027/** 028 * HM エディターは、カラムのデータを時分編集する場合に使用するクラスです。 029 * 選択用ピッカーが付属します。 030 * 031 * 編集パラメータは、starthour , endhour , minutedivisions , showminutes の順に、 032 * CSV形式で与えます。 033 * 変数の数が少ない場合は、初期値が設定されます。 034 * 初期値は、starthour="6" endhour="20" minutedivisions="4" showminutes="true" です。 035 * 036 * ex) 6,19,4,true 037 * starthour :ピッカーの開始時間(0-23) 038 * endhour :ピッカーの終了時間(0-23) 039 * minutedivisions :単位「分」の分割数。4なら15分単位。(2-60) 040 * showminutes :分ピッカーの表示(true/false) 041 * usesecond :秒付き(6桁、秒は00固定)で値を返すかどうか(true/false) 042 * layout :表示の縦横(vertical/horizon) 043 * 044 * このエディタはeventColumnに対応していません。 045 * 046 * カラムの表示に必要な属性は, DBColumn オブジェクト より取り出します。 047 * このクラスは、DBColumn オブジェクト毎に1つ作成されます。 048 * 049 * @og.rev 5.6.5.2 (2013/06/21) 新規作成 050 * @og.rev 5.9.12.3 (2016/09/23) usesecond追加 051 * @og.rev 5.9.17.2 (2017/02/17) layout追加 052 * @og.rev 7.3.2.3 (2021/04/09) システム定数のICON_DIRやIMAGE_DIRを使用します。 053 * @og.group データ編集 054 * 055 * @version 5.0 056 * @author Takahashi Masakazu 057 * @since JDK6.0, 058 */ 059public class Editor_HM extends AbstractEditor { 060 /** このプログラムのVERSION文字列を設定します。 {@value} */ 061 private static final String VERSION = "8.0.3.0 (2021/12/17)" ; 062 063 // 7.3.2.3 (2021/04/09) システム定数のICON_DIRやIMAGE_DIRを使用します。 064 private static final String JSP_ICON = HybsSystem.sys( "JSP_ICON" ) ; 065 066// private static final String PIC1 = "<img src=\"../image/clock.png\" class=\"clockpick\" valuefield=\""; // altは付けない 067 private static final String PIC1 = "<img src=\"" + JSP_ICON + "/clock.png\" class=\"clockpick\" valuefield=\""; // altは付けない 068 069 // 7.0.1.0 (2018/10/15) XHTML → HTML5 対応(空要素の、"/>" 止めを、">" に変更します)。 070// private static final String PIC2 = " />"; 071 private static final String PIC2 = " >"; // 7.0.1.0 (2018/10/15) 072 073 // 6.9.8.0 (2018/05/28) 賛否両論:前のタグの終了属性を、入れておく事で、文字列連結数を減らす。(属性の飛ばしがないので、良しとします。) 074 private static final String OPT1 = "starthour=\""; 075// private static final String OPT2 = "endhour=\""; 076// private static final String OPT3 = "minutedivisions=\""; 077// private static final String OPT4 = "showminutes=\""; 078// private static final String OPT5 = "usesecond=\""; // 5.9.12.3 (2016/09/23) 079// private static final String OPT6 = "layout=\""; // 5.9.17.2 (2017/02/17) 080 private static final String OPT2 = "\" endhour=\""; 081 private static final String OPT3 = "\" minutedivisions=\""; 082 private static final String OPT4 = "\" showminutes=\""; 083 private static final String OPT5 = "\" usesecond=\""; // 5.9.12.3 (2016/09/23) 084 private static final String OPT6 = "\" layout=\""; // 5.9.17.2 (2017/02/17) 085 private static final String END_ATTR = "\" "; 086 087// private final String options; 088 private final String endTag; // 6.9.8.0 (2018/05/28) END_ATTR + options + PIC2 を、コンストラクターで行う。 089 090 // 6.9.8.0 (2018/05/28) disabled 時に、時間ピッカーを出さない対応 091 private final boolean disabled ; 092 093 /** 094 * デフォルトコンストラクター。 095 * このコンストラクターで、基本オブジェクトを作成します。 096 * 097 * @og.rev 6.9.8.0 (2018/05/28) disabled 時に、時間ピッカーを出さない対応 098 */ 099 public Editor_HM() { 100 super(); // 6.4.1.1 (2016/01/16) PMD refactoring. It is a good practice to call super() in a constructor 101 // 4.3.4.4 (2009/01/01) 102// options = null; // 6.9.8.0 (2018/05/28) options は、endTag に、入れておく。 103 disabled = false; // 6.9.8.0 (2018/05/28) disabled 時に、時間ピッカーを出さない対応 104 endTag = null; // 6.9.8.0 (2018/05/28) endTag は、disabled="false" なので、何でも良い。 105 } 106 107 /** 108 * DBColumnオブジェクトを指定したprivateコンストラクター。 109 * 110 * @og.rev 6.9.8.0 (2018/05/28) disabled 時に、時間ピッカーを出さない対応 111 * 112 * @param clm DBColumnオブジェクト 113 */ 114 private Editor_HM( final DBColumn clm ) { 115 super( clm ); 116 // 6.9.8.0 (2018/05/28) END_ATTR + options + PIC2 を、コンストラクターで行う。 117// options = createOptions( clm.getEditorParam() ); 118 tagBuffer.add( XHTMLTag.inputAttri( attributes ) ); 119 120 disabled = "disabled".equalsIgnoreCase( attributes.get( "disabled" ) ); // 6.9.8.0 (2018/05/28) disabled対応 121 endTag = disabled ? null 122 : END_ATTR + createOptions( clm.getEditorParam() ) + PIC2 ; // 6.9.8.0 (2018/05/28) options対応 123 } 124 125 /** 126 * 各オブジェクトから自分のインスタンスを返します。 127 * 自分自身をキャッシュするのか、新たに作成するのかは、各サブクラスの実装に 128 * まかされます。 129 * 130 * @param clm DBColumnオブジェクト 131 * 132 * @return CellEditorオブジェクト 133 * @og.rtnNotNull 134 */ 135 public CellEditor newInstance( final DBColumn clm ) { 136 return new Editor_HM( clm ); 137 } 138 139 /** 140 * データの編集用文字列を返します。 141 * 142 * @og.rev 6.9.8.0 (2018/05/28) disabled 時に、時間ピッカーを出さない対応 143 * @og.rev 8.0.3.0 (2021/12/17) イメージにname属性を付けるため、spanタグで囲います。 144 * 145 * @param value 入力値 146 * 147 * @return データの編集用文字列 148 * @og.rtnNotNull 149 */ 150 @Override 151 public String getValue( final String value ) { 152 // 6.1.1.0 (2015/01/17) TagBufferの連結記述 153 final String tag = new TagBuffer( "input" ) 154 .add( "name" , name ) 155 .add( "id" , name , isNull( attributes.get( "id" ) ) ) // 4.3.7.2 (2009/06/15) 156 .add( "value" , value ) 157 .add( "size" , size1 ) 158 .add( tagBuffer.makeTag() ) 159 .makeTag(); 160 161// return tag + PIC1 + name + END_ATTR + options + PIC2 ; 162// return disabled ? tag // 6.9.8.0 (2018/05/28) disabled 時に、時間ピッカーを出さない対応 163// : tag + PIC1 + name + endTag ; // 6.9.8.0 (2018/05/28) END_ATTR + options + PIC2 を、コンストラクターで行う。 164 165 // 8.0.3.0 (2021/12/17) 166 if( disabled ) { 167 return tag; 168 } else { 169 final StringBuilder buf = new StringBuilder(BUFFER_MIDDLE) 170 .append( tag ) 171 .append( "<span name=\"img" ).append( name ).append( "\">" ) // 8.0.3.0 (2021/12/17) 172 .append( PIC1 ) 173 .append( name ) 174 .append( endTag ) 175 .append( "</span>" ); // 8.0.3.0 (2021/12/17) 176 177 return buf.toString(); 178 } 179 } 180 181 /** 182 * name属性を変えた、データ表示/編集用のHTML文字列を作成します。 183 * テーブル上の name に 行番号を付加して、名前_行番号 で登録するキーを作成し, 184 * リクエスト情報を1つ毎のフィールドで処理できます。 185 * 186 * @og.rev 6.9.8.0 (2018/05/28) disabled 時に、時間ピッカーを出さない対応 187 * @og.rev 8.0.3.0 (2021/12/17) イメージにname属性を付けるため、spanタグで囲います。 188 * 189 * @param row 行番号 190 * @param value 入力値 191 * 192 * @return データ表示/編集用の文字列 193 * @og.rtnNotNull 194 */ 195 @Override 196 public String getValue( final int row,final String value ) { 197 final String name2 = name + HybsSystem.JOINT_STRING + row ; 198 199 // 6.1.1.0 (2015/01/17) TagBufferの連結記述 200 final String tag = new TagBuffer( "input" ) 201 .add( "name" , name2 ) 202 .add( "id" , name2 , isNull( attributes.get( "id" ) ) ) // 4.3.7.2 (2009/06/15) 203 .add( "value" , value ) 204 .add( "size" , size2 ) 205 .add( tagBuffer.makeTag() ) 206 .makeTag( row,value ); 207 208// return tag + PIC1 + name2 + END_ATTR + options + PIC2 ; 209// return disabled ? tag // 6.9.8.0 (2018/05/28) disabled 時に、時間ピッカーを出さない対応 210// : tag + PIC1 + name2 + endTag ; // 6.9.8.0 (2018/05/28) END_ATTR + options + PIC2 を、コンストラクターで行う。 211 212 // 8.0.3.0 (2021/12/17) 213 if( disabled ) { 214 return tag; 215 } else { 216 final StringBuilder buf = new StringBuilder(BUFFER_MIDDLE) 217 .append( tag ) 218 .append( "<span name=\"img" ).append( name2 ).append( "\">" ) // 8.0.3.0 (2021/12/17) 219 .append( PIC1 ) 220 .append( name2 ) 221 .append( endTag ) 222 .append( "</span>" ); // 8.0.3.0 (2021/12/17) 223 224 return buf.toString(); 225 } 226 } 227 228 /** 229 * 編集パラメータから、オプション文字列を作成します。 230 * 編集パラメータは、starthour , endhour , minutedivisions , showminutes の順に、 231 * CSV形式で与えます。 232 * 変数の数が少ない場合は、初期値が設定されます。 233 * 初期値は、starthour="6" endhour="20" minutedivisions="4" showminutes="true" です。 234 * 235 * @og.rev 5.9.12.3 (2016/09/23) usesecond対応 236 * @og.rfv 5.9.17.2 (2017/02/15) layout対応 237 * @og.rfv 6.9.8.0 (2018/05/28) 賛否両論:前のタグの終了属性を、入れておく事で、文字列連結数を減らす。(属性の飛ばしがないので、良しとします。) 238 * 239 * @param editPrm 編集パラメータ 240 * 241 * @return パラメータのオプション文字列 242 * @og.rtnNotNull 243 */ 244 private String createOptions( final String editPrm ){ 245 if( editPrm == null ) { return "" ;} 246 // 6.0.2.5 (2014/10/31) null でないことがわかっている値の冗長な null チェックがあります。 247 final String[] param = editPrm.split( "," ) ; 248 final String start = param.length > 0 ? param[0].trim() : "6" ; 249 final String end = param.length > 1 ? param[1].trim() : "20" ; 250 final String step = param.length > 2 ? param[2].trim() : "4" ; 251 final String min = param.length > 3 ? param[3].trim() : "true" ; 252 final String sec = param.length > 4 ? param[4].trim() : "false" ; // 5.9.12.3 (2016/09/23) 253 final String layout = param.length > 5 ? param[5].trim() : "vertical" ; // 5.9.17.2 (2017/02/15) 254 255// return OPT1 + start + END_ATTR + OPT2 + end + END_ATTR + OPT3 + step + END_ATTR + OPT4 + min + END_ATTR + OPT5 + sec + END_ATTR + OPT6 + layout + END_ATTR; // 5.9.12.3 (2016/09/23) 256 return OPT1 + start + OPT2 + end + OPT3 + step + OPT4 + min + OPT5 + sec + OPT6 + layout + END_ATTR; // 6.9.8.0 (2018/05/28) 257 } 258}