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 = "6.9.8.0 (2018/05/28)" ; 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 * 144 * @param value 入力値 145 * 146 * @return データの編集用文字列 147 * @og.rtnNotNull 148 */ 149 @Override 150 public String getValue( final String value ) { 151 // 6.1.1.0 (2015/01/17) TagBufferの連結記述 152 final String tag = new TagBuffer( "input" ) 153 .add( "name" , name ) 154 .add( "id" , name , isNull( attributes.get( "id" ) ) ) // 4.3.7.2 (2009/06/15) 155 .add( "value" , value ) 156 .add( "size" , size1 ) 157 .add( tagBuffer.makeTag() ) 158 .makeTag(); 159 160// return tag + PIC1 + name + END_ATTR + options + PIC2 ; 161 return disabled ? tag // 6.9.8.0 (2018/05/28) disabled 時に、時間ピッカーを出さない対応 162 : tag + PIC1 + name + endTag ; // 6.9.8.0 (2018/05/28) END_ATTR + options + PIC2 を、コンストラクターで行う。 163 } 164 165 /** 166 * name属性を変えた、データ表示/編集用のHTML文字列を作成します。 167 * テーブル上の name に 行番号を付加して、名前_行番号 で登録するキーを作成し, 168 * リクエスト情報を1つ毎のフィールドで処理できます。 169 * 170 * @og.rev 6.9.8.0 (2018/05/28) disabled 時に、時間ピッカーを出さない対応 171 * 172 * @param row 行番号 173 * @param value 入力値 174 * 175 * @return データ表示/編集用の文字列 176 * @og.rtnNotNull 177 */ 178 @Override 179 public String getValue( final int row,final String value ) { 180 final String name2 = name + HybsSystem.JOINT_STRING + row ; 181 182 // 6.1.1.0 (2015/01/17) TagBufferの連結記述 183 final String tag = new TagBuffer( "input" ) 184 .add( "name" , name2 ) 185 .add( "id" , name2 , isNull( attributes.get( "id" ) ) ) // 4.3.7.2 (2009/06/15) 186 .add( "value" , value ) 187 .add( "size" , size2 ) 188 .add( tagBuffer.makeTag() ) 189 .makeTag( row,value ); 190 191// return tag + PIC1 + name2 + END_ATTR + options + PIC2 ; 192 return disabled ? tag // 6.9.8.0 (2018/05/28) disabled 時に、時間ピッカーを出さない対応 193 : tag + PIC1 + name2 + endTag ; // 6.9.8.0 (2018/05/28) END_ATTR + options + PIC2 を、コンストラクターで行う。 194 } 195 196 /** 197 * 編集パラメータから、オプション文字列を作成します。 198 * 編集パラメータは、starthour , endhour , minutedivisions , showminutes の順に、 199 * CSV形式で与えます。 200 * 変数の数が少ない場合は、初期値が設定されます。 201 * 初期値は、starthour="6" endhour="20" minutedivisions="4" showminutes="true" です。 202 * 203 * @og.rev 5.9.12.3 (2016/09/23) usesecond対応 204 * @og.rfv 5.9.17.2 (2017/02/15) layout対応 205 * @og.rfv 6.9.8.0 (2018/05/28) 賛否両論:前のタグの終了属性を、入れておく事で、文字列連結数を減らす。(属性の飛ばしがないので、良しとします。) 206 * 207 * @param editPrm 編集パラメータ 208 * 209 * @return パラメータのオプション文字列 210 * @og.rtnNotNull 211 */ 212 private String createOptions( final String editPrm ){ 213 if( editPrm == null ) { return "" ;} 214 // 6.0.2.5 (2014/10/31) null でないことがわかっている値の冗長な null チェックがあります。 215 final String[] param = editPrm.split( "," ) ; 216 final String start = param.length > 0 ? param[0].trim() : "6" ; 217 final String end = param.length > 1 ? param[1].trim() : "20" ; 218 final String step = param.length > 2 ? param[2].trim() : "4" ; 219 final String min = param.length > 3 ? param[3].trim() : "true" ; 220 final String sec = param.length > 4 ? param[4].trim() : "false" ; // 5.9.12.3 (2016/09/23) 221 final String layout = param.length > 5 ? param[5].trim() : "vertical" ; // 5.9.17.2 (2017/02/15) 222 223// 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) 224 return OPT1 + start + OPT2 + end + OPT3 + step + OPT4 + min + OPT5 + sec + OPT6 + layout + END_ATTR; // 6.9.8.0 (2018/05/28) 225 } 226}