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.group データ編集 053 * 054 * @version 5.0 055 * @author Takahashi Masakazu 056 * @since JDK6.0, 057 */ 058public class Editor_HM extends AbstractEditor { 059 /** このプログラムのVERSION文字列を設定します。 {@value} */ 060 private static final String VERSION = "5.9.17.2 (2017/02/17)" ; 061 062 private static final String PIC1 = "<img src=\"../image/clock.png\" class=\"clockpick\" valuefield=\""; // altは付けない 063 private static final String PIC2 = " />"; 064 065 private static final String OPT1 = "starthour=\""; 066 private static final String OPT2 = "endhour=\""; 067 private static final String OPT3 = "minutedivisions=\""; 068 private static final String OPT4 = "showminutes=\""; 069 private static final String OPT5 = "usesecond=\""; // 5.9.12.3 (2016/09/23) 070 private static final String OPT6 = "layout=\""; // 5.9.17.2 (2017/02/17) 071 private static final String END_ATTR = "\" "; 072 073 private final String options; 074 075 /** 076 * デフォルトコンストラクター。 077 * このコンストラクターで、基本オブジェクトを作成します。 078 * 079 */ 080 public Editor_HM() { 081 super(); // 6.4.1.1 (2016/01/16) PMD refactoring. It is a good practice to call super() in a constructor 082 // 4.3.4.4 (2009/01/01) 083 options = null; 084 } 085 086 /** 087 * コンストラクター。 088 * 089 * @param clm DBColumnオブジェクト 090 */ 091 private Editor_HM( final DBColumn clm ) { 092 super( clm ); 093 options = createOptions(clm.getEditorParam()); 094 tagBuffer.add( XHTMLTag.inputAttri( attributes ) ); 095 } 096 097 /** 098 * 各オブジェクトから自分のインスタンスを返します。 099 * 自分自身をキャッシュするのか、新たに作成するのかは、各サブクラスの実装に 100 * まかされます。 101 * 102 * @param clm DBColumnオブジェクト 103 * 104 * @return CellEditorオブジェクト 105 * @og.rtnNotNull 106 */ 107 public CellEditor newInstance( final DBColumn clm ) { 108 return new Editor_HM( clm ); 109 } 110 111 /** 112 * データの編集用文字列を返します。 113 * 114 * @param value 入力値 115 * 116 * @return データの編集用文字列 117 * @og.rtnNotNull 118 */ 119 @Override 120 public String getValue( final String value ) { 121 // 6.1.1.0 (2015/01/17) TagBufferの連結記述 122 final String tag = new TagBuffer( "input" ) 123 .add( "name" , name ) 124 .add( "id" , name , isNull( attributes.get( "id" ) ) ) // 4.3.7.2 (2009/06/15) 125 .add( "value" , value ) 126 .add( "size" , size1 ) 127 .add( tagBuffer.makeTag() ) 128 .makeTag(); 129 130 return tag + PIC1 + name + END_ATTR + options + PIC2 ; 131 132 } 133 134 /** 135 * name属性を変えた、データ表示/編集用のHTML文字列を作成します。 136 * テーブル上の name に 行番号を付加して、名前_行番号 で登録するキーを作成し, 137 * リクエスト情報を1つ毎のフィールドで処理できます。 138 * 139 * @param row 行番号 140 * @param value 入力値 141 * 142 * @return データ表示/編集用の文字列 143 * @og.rtnNotNull 144 */ 145 @Override 146 public String getValue( final int row,final String value ) { 147 final String name2 = name + HybsSystem.JOINT_STRING + row ; 148 149 // 6.1.1.0 (2015/01/17) TagBufferの連結記述 150 final String tag = new TagBuffer( "input" ) 151 .add( "name" , name2 ) 152 .add( "id" , name2 , isNull( attributes.get( "id" ) ) ) // 4.3.7.2 (2009/06/15) 153 .add( "value" , value ) 154 .add( "size" , size2 ) 155 .add( tagBuffer.makeTag() ) 156 .makeTag( row,value ); 157 158 return tag + PIC1 + name2 + END_ATTR + options + PIC2 ; 159 160 } 161 162 /** 163 * 編集パラメータから、オプション文字列を作成します。 164 * 編集パラメータは、starthour , endhour , minutedivisions , showminutes の順に、 165 * CSV形式で与えます。 166 * 変数の数が少ない場合は、初期値が設定されます。 167 * 初期値は、starthour="6" endhour="20" minutedivisions="4" showminutes="true" です。 168 * 169 * @og.rev 5.9.12.3 (2016/09/23) usesecond対応 170 * @og.rfv 5.9.17.2 (2017/02/15) layout対応 171 * 172 * @param editPrm 編集パラメータ 173 * 174 * @return パラメータのオプション文字列 175 * @og.rtnNotNull 176 */ 177 private String createOptions( final String editPrm ){ 178 if( editPrm == null ) { return "" ;} 179 // 6.0.2.5 (2014/10/31) null でないことがわかっている値の冗長な null チェックがあります。 180 final String[] param = editPrm.split( "," ) ; 181 final String start = param.length > 0 ? param[0].trim() : "6" ; 182 final String end = param.length > 1 ? param[1].trim() : "20" ; 183 final String step = param.length > 2 ? param[2].trim() : "4" ; 184 final String min = param.length > 3 ? param[3].trim() : "true" ; 185 final String sec = param.length > 4 ? param[4].trim() : "false" ; // 5.9.12.3 (2016/09/23) 186 final String layout = param.length > 5 ? param[5].trim() : "vertical" ; // 5.9.17.2 (2017/02/15) 187 188 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) 189 } 190}