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.common.HybsSystemException; 020import org.opengion.hayabusa.db.AbstractEditor; 021import org.opengion.hayabusa.db.CellEditor; 022import org.opengion.hayabusa.db.DBColumn; 023import org.opengion.hayabusa.db.SelectionCellEditor; // 6.2.2.0 (2015/03/27) 024import org.opengion.hayabusa.db.Selection; 025import org.opengion.hayabusa.db.SelectionFactory; 026import org.opengion.fukurou.util.StringFormat; 027import org.opengion.fukurou.util.XHTMLTag; 028import org.opengion.fukurou.util.Attributes; 029import org.opengion.fukurou.util.TagBuffer; 030 031import static org.opengion.fukurou.util.StringUtil.isNull; // 6.1.1.0 (2015/01/17) 032 033/** 034 * INDBMENU エディターは、カラムの表示パラメーターのSQL文を実行結果より、 035 * 作成したプルダウンメニューと、テキストフィールドによる入力の両方をサポートする、 036 * 編集に使用するクラスです。 037 * 038 * JavaScript によりテキストフィールドとメニュー(コンボボックス)を重ね合わせて 039 * 表示しておき、メニューで選択した値を、テキストフィールドに設定しています。 040 * このエディタを使用するには、jsp/common/inputMenu.js を予め使用できるように 041 * 設定しておく必要があります。 042 * 043 * ここでは、AAA:BBB:CCC:DDD という値を、$1,$2,$3,$4 に割り当てなおして、 044 * QUERYを実行します。また、$1 は、本来の値として、メニューの初期値設定等に 045 * 使用します。上記の例では、AAA が値で、それ以降は、引数になります。 046 * さらに、元の文字列"AAA:BBB:CCC:DDD"は、$0 に割り当てられます。割り当てがない 047 * 変数は、""(ゼロ文字列)として、扱われます。 048 * 049 * このエディタはeventColumnに対応していません。 050 * 051 * カラムの表示に必要な属性は, DBColumn オブジェクト より取り出します。 052 * このクラスは、DBColumn オブジェクト毎に1つ作成されます。 053 * 054 * @og.rev 3.5.6.2 (2004/07/05) 新規作成 055 * @og.rev 6.2.2.0 (2015/03/27) SelectionCellEditor I/Fを追加 056 * @og.group データ編集 057 * 058 * @version 4.0 059 * @author Kazuhiko Hasegawa 060 * @since JDK5.0, 061 */ 062public class Editor_INDBMENU extends AbstractEditor implements SelectionCellEditor { 063 /** このプログラムのVERSION文字列を設定します。 {@value} */ 064 private static final String VERSION = "7.0.5.1 (2019/09/27)" ; 065 066 private static final String SEL1 = "<script type=\"text/javascript\">makeInputMenu('" ; 067 private static final String SEL2 = "');</script>" ; 068 069 private final String query ; 070 private final String dbid ; 071 private final String lang ; // 4.0.0 (2006/11/15) 072 private final boolean addNoValue ; // 3.5.5.7 (2004/05/10) 073 private final boolean seqFlag ; // 3.6.0.6 (2004/10/22) 074 private final String useSLabel ; // 6.2.0.0 (2015/02/27) SLABEL 対応 075 private final String addKeyLabel ; // 6.2.0.0 (2015/02/27) キー:ラベル形式 076 077 private final TagBuffer selTagBuffer = new TagBuffer() ; 078 079 /** 080 * デフォルトコンストラクター。 081 * このコンストラクターで、基本オブジェクトを作成します。 082 * 083 * @og.rev 3.6.0.6 (2004/10/22) シーケンスアクセス機能(seqFlag)を追加します 084 * @og.rev 6.2.0.0 (2015/02/27) SLABEL 対応 085 * @og.rev 6.2.0.0 (2015/02/27) キー:ラベル形式で表示するかどうかを、指定できるようにします。 086 * @og.rev 6.4.4.2 (2016/04/01) nameのfinal化 087 */ 088 public Editor_INDBMENU() { 089 super(); // 6.4.1.1 (2016/01/16) PMD refactoring. It is a good practice to call super() in a constructor 090 // 4.3.4.4 (2009/01/01) 091 query = null; 092 dbid = null; 093 lang = null; // 4.0.0 (2006/11/15) 094 addNoValue = false; // 3.5.5.7 (2004/05/10) 095 seqFlag = false; // 3.6.0.6 (2004/10/22) 096 // name = null; // 4.3.4.0 (2008/12/01) 097 useSLabel = "auto"; // 6.2.0.0 (2015/02/27) SLABEL 対応 098 addKeyLabel = null; // 6.2.0.0 (2015/02/27) キー:ラベル形式 099 } 100 101 /** 102 * DBColumnオブジェクトを指定したprivateコンストラクター。 103 * 104 * @og.rev 3.6.0.6 (2004/10/22) シーケンスアクセス機能(seqFlag)を追加します 105 * @og.rev 4.0.0.0 (2006/11/24) TextField分の属性設定 106 * @og.rev 5.6.3.0 (2013/04/01) プルダウンのonChangeの設定場所を変更 107 * @og.rev 6.2.0.0 (2015/02/27) SLABEL 対応 108 * @og.rev 6.2.0.0 (2015/02/27) キー:ラベル形式で表示するかどうかを、指定できるようにします。 109 * @og.rev 6.4.4.2 (2016/04/01) nameのfinal化 110 * @og.rev 7.0.5.1 (2019/09/27) optionAttributes が二重に設定されていたため、削除 111 * 112 * @param clm DBColumnオブジェクト 113 */ 114 private Editor_INDBMENU( final DBColumn clm ) { 115 super( clm ); 116 tagBuffer.add( XHTMLTag.inputAttri( attributes ) ); 117 118 addNoValue = clm.isAddNoValue() ; // 3.5.5.7 (2004/05/10) 119 query = clm.getEditorParam(); 120 dbid = clm.getDbid(); 121 lang = clm.getLang(); // 4.0.0.0 (2006/11/15) 122 seqFlag = false; // 3.6.0.6 (2004/10/22) 123 // name = clm.getName(); // 4.3.4.0 (2008/12/01) , 6.4.4.2 (2016/04/01) nameのfinal化 124 useSLabel = clm.getUseSLabel() ; // 6.2.0.0 (2015/02/27) SLABEL 対応 125 addKeyLabel = clm.getAddKeyLabel(); // 6.2.0.0 (2015/02/27) キー:ラベル形式 126 127 if( query == null || query.isEmpty() ) { 128 final String errMsg = "INDBMENU Editor では、編集パラメータは必須です。" 129 + " name=[" + name + "]" + CR ; 130 throw new HybsSystemException( errMsg ); 131 } 132 133 final String disabled = clm.isWritable() ? null : "disabled" ; 134 135 // 6.1.1.0 (2015/01/17) Attributesの連結記述 136 final Attributes selAttri = new Attributes() 137 .set( "disabled" ,disabled ) 138 .set( clm.getEditorAttributes() ) // #addAttributes( Attributes ) の代替え 139 .set( "onChange" ,"selChanged(this);" ); // INDBMENU 特有のJavaScript 5.6.3.0 (2013/03/01) 場所変更 140 141 // 6.1.1.0 (2015/01/17) TagBufferの連結記述 142 // 7.0.5.1 (2019/09/27) optionAttributes が二重に設定されていたため、削除 143 selTagBuffer.add( XHTMLTag.selectAttri( selAttri ) ); 144// .add( selAttri.get( "optionAttributes" ) ); // 6.0.4.0 (2014/11/28) 145 } 146 147 /** 148 * 各オブジェクトから自分のインスタンスを返します。 149 * 自分自身をキャッシュするのか、新たに作成するのかは、各サブクラスの実装に 150 * まかされます。 151 * 152 * @param clm DBColumnオブジェクト 153 * 154 * @return CellEditorオブジェクト 155 * @og.rtnNotNull 156 */ 157 public CellEditor newInstance( final DBColumn clm ) { 158 return new Editor_INDBMENU( clm ); 159 } 160 161 /** 162 * データの編集用文字列を返します。 163 * 164 * ここでは、AAA:BBB:CCC:DDD という値を、$1,$2,$3,$4 に割り当てなおして、 165 * QUERYを実行します。また、$1 は、本来の値として、メニューの初期値設定等に 166 * 使用します。上記の例では、AAA が値で、それ以降は、引数になります。 167 * さらに、元の文字列"AAA:BBB:CCC:DDD"は、$0 に割り当てられます。割り当てがない 168 * 変数は、""(ゼロ文字列)として、扱われます。 169 * 170 * @og.rev 3.8.5.3 (2006/06/30) 位置を絶対位置指定(position:absolute;) 171 * @og.rev 4.3.7.2 (2009/06/15) 属性でidが出力される場合は、idを出力しない 172 * @og.rev 6.2.0.0 (2015/02/27) SLABEL 対応 173 * @og.rev 6.4.5.3 (2016/05/13) value は、コロン区切りの先頭だけ分離する。 174 * 175 * @param value 入力値 176 * 177 * @return データの編集用文字列 178 * @og.rtnNotNull 179 */ 180 @Override 181 public String getValue( final String value ) { 182 final String newValue = StringFormat.getValue( value ); // 6.4.5.3 (2016/05/13) コロン区切りの先頭だけ 183 184 // input タグの作成 185 // 6.1.1.0 (2015/01/17) TagBufferの連結記述 186 final String intag = new TagBuffer( "input" ) 187 .add( "name" , name ) 188 .add( "id" , name , isNull( attributes.get( "id" ) ) ) // 4.3.7.2 (2009/06/15) 189 .add( "value" , newValue ) // 6.4.5.3 (2016/05/13) 190 .add( "size" , size1 ) 191 .add( tagBuffer.makeTag() ) 192 .makeTag(); 193 194 final boolean useSlbl = "true".equalsIgnoreCase( useSLabel ); // 6.2.0.0 (2015/02/27) 195 196 // select タグの作成 197 // 6.1.1.0 (2015/01/17) TagBufferの連結記述 198 final String seltag = getOption( 199 new TagBuffer( "select" ) 200 .add( "id" , name + ".sel" ) // INDBMENU 特有のJavaScript用のキー 201 .add( "style" , "position:absolute;" ) // 3.8.5.3 (2006/06/30) 位置を絶対位置指定 202 .add( selTagBuffer.makeTag() ) 203 , value 204 , useSlbl // 6.2.0.0 (2015/02/27) SLABEL 対応 205 ).makeTag() ; 206 207 return intag + CR + seltag + CR + SEL1 + name + SEL2; 208 } 209 210 /** 211 * name属性を変えた、データ表示/編集用のHTML文字列を作成します。 212 * テーブル上の name に 行番号を付加して、名前_行番号 で登録するキーを作成し, 213 * リクエスト情報を1つ毎のフィールドで処理できます。 214 * 215 * ここでは、AAA:BBB:CCC:DDD という値を、$1,$2,$3,$4 に割り当てなおして、 216 * QUERYを実行します。また、$1 は、本来の値として、メニューの初期値設定等に 217 * 使用します。上記の例では、AAA が値で、それ以降は、引数になります。 218 * さらに、元の文字列"AAA:BBB:CCC:DDD"は、$0 に割り当てられます。割り当てがない 219 * 変数は、""(ゼロ文字列)として、扱われます。 220 * 221 * @og.rev 3.8.5.1 (2006/04/28) makeInputMenu 呼び出し時の引数記述ミスを修正 222 * @og.rev 3.8.5.3 (2006/06/30) 位置を絶対位置指定(position:absolute;) 223 * @og.rev 4.3.7.2 (2009/06/15) 属性でidが出力される場合は、idを出力しない 224 * @og.rev 6.2.0.0 (2015/02/27) SLABEL 対応 225 * @og.rev 6.4.5.3 (2016/05/13) value は、コロン区切りの先頭だけ分離する。 226 * 227 * @param row 行番号 228 * @param value 入力値 229 * 230 * @return データ表示/編集用の文字列 231 * @og.rtnNotNull 232 */ 233 @Override 234 public String getValue( final int row,final String value ) { 235 final String name2 = name + HybsSystem.JOINT_STRING + row ; 236 final String newValue = StringFormat.getValue( value ); // 6.4.5.3 (2016/05/13) コロン区切りの先頭だけ 237 238 // input タグの作成 239 // 6.1.1.0 (2015/01/17) TagBufferの連結記述 240 final String intag = new TagBuffer( "input" ) 241 .add( "name" , name2 ) 242 .add( "id" , name2 , isNull( attributes.get( "id" ) ) ) // 4.3.7.2 (2009/06/15) 243 .add( "value" , newValue ) // 6.4.5.3 (2016/05/13) 244 .add( "size" , size2 ) 245 .add( tagBuffer.makeTag() ) 246 .makeTag( row,newValue ); // 6.4.5.3 (2016/05/13) [V] に割り当てる値。 247 248 final boolean useSlbl = "auto".equalsIgnoreCase( useSLabel ) || "true".equalsIgnoreCase( useSLabel ); // 6.2.0.0 (2015/02/27) 249 250 // select タグの作成 251 // 6.1.1.0 (2015/01/17) TagBufferの連結記述 252 final String seltag = getOption( 253 new TagBuffer( "select" ) 254 .add( "id" , name2 + ".sel" ) // INDBMENU 特有のJavaScript用のキー 255 .add( "style" , "position:absolute;" ) // 3.8.5.3 (2006/06/30) 位置を絶対位置指定 256 .add( selTagBuffer.makeTag() ) 257 , value 258 , useSlbl // 6.2.0.0 (2015/02/27) SLABEL 対応 259 ).makeTag( row,newValue ) ; // 6.4.5.3 (2016/05/13) [V] に割り当てる値。 260 261 return intag + CR + seltag + CR + SEL1 + name2 + SEL2; 262 } 263 264 /** 265 * 初期値が選択済みの 選択肢(オプション)をTagBuffer に反映します。 266 * このオプションは、引数の値を初期値とするオプションタグ作成し、TagBuffer 267 * に値を設定して返します。 268 * 269 * ここでは、AAA:BBB:CCC:DDD という値を、$1,$2,$3,$4 に割り当てなおして、 270 * QUERYを実行します。また、$1 は、本来の値として、メニューの初期値設定等に 271 * 使用します。上記の例では、AAA が値で、それ以降は、引数になります。 272 * さらに、元の文字列"AAA:BBB:CCC:DDD"は、$0 に割り当てられます。割り当てがない 273 * 変数は、""(ゼロ文字列)として、扱われます。 274 * 又、$Cには自分自身のカラム名を割り当てます。 275 * 276 * @og.rev 3.5.5.7 (2004/05/10) getOption( String value )の廃止を受けて、新規作成 277 * @og.rev 3.6.0.6 (2004/10/22) シーケンスアクセス機能(seqFlag)を追加します 278 * @og.rev 4.0.0.0 (2006/11/15) SelectionFactory に lang 属性を追加します。 279 * @og.rev 4.3.4.0 (2008/12/01) $C対応 280 * @og.rev 6.2.0.0 (2015/02/27) SLABEL 対応 281 * @og.rev 6.2.0.0 (2015/02/27) キー:ラベル形式で表示するかどうかを、指定できるようにします。 282 * 283 * @param buf 反映させるTagBufferオブジェクト 284 * @param value 選択されている値 285 * @param useSlbl ラベル(短)をベースとしたオプション表示を行うかどうか。 286 * 287 * @return オプションタグ 288 * @og.rtnNotNull 289 */ 290 private TagBuffer getOption( final TagBuffer buf,final String value,final boolean useSlbl ) { 291 292 // StringFormat format = new StringFormat( query,value ); 293 final StringFormat format = new StringFormat( query, value, name ); // 4.3.4.0 (2008/12/01) 294 final String newQuery = format.format(); 295 final String newValue = format.getValue(); 296 297 // 6.2.0.0 (2015/02/27) キー:ラベル形式 298 final Selection selection = SelectionFactory.newDBSelection( newQuery, dbid, lang, addKeyLabel ); 299 300 // 6.1.1.0 (2015/01/17) TagBufferの連結記述 301 return buf.addBody( Selection.NO_VALUE_OPTION , addNoValue ) // 5.5.1.0 (2012/04/03) 302 .addBody( selection.getOption( newValue, seqFlag, useSlbl ) ); // 6.2.0.0 (2015/02/27) SLABEL 対応 303 } 304}