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 025/** 026 * HM エディターは、カラムのデータを時分編集する場合に使用するクラスです。 027 * 選択用ピッカーが付属します。 028 * 029 * optionとして、次の項目をEditParamでカンマ区切りで指定可能です。 030 * ex) 6,19,4,true 031 * starthour :ピッカーの開始時間(0-23) 032 * endhour :ピッカーの終了時間(0-23) 033 * minutedivisions :単位「分」の分割数。4なら15分単位。(2-60) 034 * showminutes :分ピッカーの表示(true/false) 035 * usesecond : 秒付き(6桁、秒は00固定)で値を返すかどうか(true/false) 036 * layout : 表示の縦横(vertical/horizon) 037 * 038 * このエディタはeventColumnに対応していません。 039 * 040 * カラムの表示に必要な属性は, DBColumn オブジェクト より取り出します。 041 * このクラスは、DBColumn オブジェクト毎に1つ作成されます。 042 * 043 * @og.rev 5.6.5.2 (2013/06/21) 新規作成 044 * @og.rev 5.9.12.3 (2016/09/23) usesecond追加 045 * @og.rev 5.9.17.2 (2017/02/17) layout追加 046 * @og.group データ編集 047 * 048 * @version 5.0 049 * @author Takahashi Masakazu 050 * @since JDK6.0, 051 */ 052public class Editor_HM extends AbstractEditor { 053 //* このプログラムのVERSION文字列を設定します。 {@value} */ 054 private static final String VERSION = "5.6.5.2 (2013/06/21)" ; 055 056 private static final String PIC1 = "<img src=\"../image/clock.png\" class=\"clockpick\" valuefield=\""; // altは付けない 057 private static final String PIC2 = " />"; 058 059 private static final String OPT1 = "starthour=\""; 060 private static final String OPT2 = "endhour=\""; 061 private static final String OPT3 = "minutedivisions=\""; 062 private static final String OPT4 = "showminutes=\""; 063 private static final String OPT5 = "usesecond=\""; // 5.9.12.3 (2016/09/23) 064 private static final String OPT6 = "layout=\""; // 5.9.17.2 (2017/02/17) 065 private static final String END_ATTR = "\" "; 066 067 private final String options; 068 069 /** 070 * デフォルトコンストラクター。 071 * このコンストラクターで、基本オブジェクトを作成します。 072 * 073 */ 074 public Editor_HM() { 075 // 4.3.4.4 (2009/01/01) 076// super(); 077 options = null; 078 } 079 080 /** 081 * コンストラクター。 082 * 083 * @param clm DBColumnオブジェクト 084 */ 085 private Editor_HM( final DBColumn clm ) { 086 super( clm ); 087 options = createOptions(clm.getEditorParam()); 088 tagBuffer.add( XHTMLTag.inputAttri( attributes ) ); 089 } 090 091 /** 092 * 各オブジェクトから自分のインスタンスを返します。 093 * 自分自身をキャッシュするのか、新たに作成するのかは、各サブクラスの実装に 094 * まかされます。 095 * 096 * @param clm DBColumnオブジェクト 097 * 098 * @return CellEditorオブジェクト 099 */ 100 public CellEditor newInstance( final DBColumn clm ) { 101 return new Editor_HM( clm ); 102 } 103 104 /** 105 * データの編集用文字列を返します。 106 * 107 * 108 * @param value 入力値 109 * 110 * @return データの編集用文字列 111 */ 112 @Override 113 public String getValue( final String value ) { 114 TagBuffer tag = new TagBuffer( "input" ); 115 tag.add( "name" , name ); 116 if( attributes.get( "id" ) == null || attributes.get( "id" ).length() == 0 ) { // 4.3.7.2 (2009/06/15) 117 tag.add( "id" , name ); 118 } 119 tag.add( "value" , value ); 120 tag.add( "size" , size1 ); 121 tag.add( tagBuffer.makeTag() ); 122 tag.add( optAttr ); 123 124 return tag.makeTag() + PIC1 + name + END_ATTR + options + PIC2 ; 125 } 126 127 /** 128 * name属性を変えた、データ表示/編集用のHTML文字列を作成します。 129 * テーブル上の name に 行番号を付加して、名前_行番号 で登録するキーを作成し, 130 * リクエスト情報を1つ毎のフィールドで処理できます。 131 * 132 * @param row 行番号 133 * @param value 入力値 134 * 135 * @return データ表示/編集用の文字列 136 */ 137 @Override 138 public String getValue( final int row,final String value ) { 139 TagBuffer tag = new TagBuffer( "input" ); 140 String name2 = name + HybsSystem.JOINT_STRING + row ; 141 tag.add( "name" , name2); 142 if( attributes.get( "id" ) == null || attributes.get( "id" ).length() == 0 ) { // 4.3.7.2 (2009/06/15) 143 tag.add( "id" , name2); 144 } 145 tag.add( "value" , value ); 146 tag.add( "size" , size2 ); 147 tag.add( tagBuffer.makeTag() ); 148 tag.add( optAttr ); // 3.5.5.8 (2004/05/20) 149 150 return tag.makeTag( row,value ) + PIC1 + name2 + END_ATTR + options + PIC2 ; 151 } 152 153 /** 154 * 編集パラメータから、オプション文字列を作成します。 155 * 編集パラメータは、starthour , endhour , minutedivisions , showminutes の順に、 156 * カンマ区切り文字列で与えます。 157 * 変数の数が少ない場合は、初期値が設定されます。 158 * 初期値は、starthour="6" endhour="20" minutedivisions="4" showminutes="true" です。 159 * 160 * @og.rev 5.9.12.3 (2016/09/23) usesecond対応 161 * @og.rfv 5.9.17.2 (2017/02/15) layout対応 162 * 163 * @param editPrm 編集パラメータ 164 * 165 * @return パラメータのオプション文字列 166 */ 167 private String createOptions( final String editPrm ){ 168 if( editPrm == null){ return "" ;} 169 String[] param = (editPrm == null) ? new String[0] : editPrm.split( "," ) ; 170 String start = (param.length > 0) ? param[0].trim() : "6" ; 171 String end = (param.length > 1) ? param[1].trim() : "20" ; 172 String step = (param.length > 2) ? param[2].trim() : "4" ; 173 String min = (param.length > 3) ? param[3].trim() : "true" ; 174 String sec = (param.length > 4) ? param[4].trim() : "false" ; // 5.9.12.3 (2016/09/23) 175 String layout = (param.length > 5) ? param[5].trim() : "vertical" ; // 5.9.17.2 (2017/02/15) 176 177// return OPT1 + start + END_ATTR + OPT2 + end + END_ATTR + OPT3 + step + END_ATTR + OPT4 + min + END_ATTR; 178// return OPT1 + start + END_ATTR + OPT2 + end + END_ATTR + OPT3 + step + END_ATTR + OPT4 + min + END_ATTR + OPT5 + sec + END_ATTR; // 5.9.12.3 (2016/09/23) 179 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) 180 181 } 182}