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