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 */
016 package org.opengion.plugin.column;
017
018 import org.opengion.hayabusa.common.HybsSystem;
019 import org.opengion.hayabusa.common.HybsSystemException;
020 import org.opengion.hayabusa.db.AbstractEditor;
021 import org.opengion.hayabusa.db.CellEditor;
022 import org.opengion.hayabusa.db.DBColumn;
023 import org.opengion.hayabusa.db.Selection;
024 import org.opengion.hayabusa.db.SelectionFactory;
025 import org.opengion.fukurou.util.StringFormat;
026 import org.opengion.fukurou.util.XHTMLTag;
027 import org.opengion.fukurou.util.Attributes;
028 import org.opengion.fukurou.util.TagBuffer;
029
030 /**
031 * カラãƒ??編é›?ƒ‘ラメーターの?³?±?¬æ–??実行結果より、ã?ルãƒ?‚¦ンメニューを作æ?して
032 * 編é›?�™るå?合に使用するエãƒ?‚£タークラスですã?
033 *
034 * 編é›?ƒ‘ラメータには、ã?ルãƒ?‚¦ンメニューを作æ?するための、SQLæ–?‚’記述しますã?
035 * こã?SQLæ–??、select KEY,LABEL from xx ?¥?¥?¥ とã�?�†構文で、KEY部åˆ?�¨LABEL部åˆ?�Œ
036 * 選択されますã?
037 * 第ä¸?‚«ラãƒ??キー、第二カラãƒ??ラベルでこã??’つはå¿??ですã?第三カラãƒ??短縮ラベルã€?
038 * 第四カラãƒ??グルーãƒ?optgroup)、第五カラãƒ??色付け等に使ã�?‚¯ラスですã?
039 * 短縮ラベルが設定されてã�?‚‹場合ã?ä¸?¦§でこã?エãƒ?‚£タが適用されると短縮ラベル表示ã‚?
040 * した上でマウスオーバã?時ã?ãƒ??ルチップで通常のラベルを表示しますã?
041 *
042 * å�?‚«ラãƒ??値(value値)に、AAA:BBB:CCC:DDD とã�?�†値を設定できますã?これはã€?
043 * $1,$2,$3,$4 に割り当てなおして、QUERYを実行しますã?またã?$1 は、本来の値としてã€?
044 * メニューの初期値設定等に使用しますã?上記ã?例では、AAA がå?で、それ以降ã?ã€?
045 * 引数になりますã?
046 * 又ã?$Cには自åˆ??身のカラãƒ?��を割り当てますã?
047 * こã?機è?を使用すれば、動çš?ƒ¡ニューを行ごとに条件を変えて作æ?することã�?
048 * 可能になりますã?
049 * 例:select KEY,LABEL from xx where KUBUN='$2' and CDK='$3'
050 * さらに、å?のæ–?—å?"AAA:BBB:CCC:DDD"はã€?0 に割り当てられますã?割り当てがなã�?
051 * 変数はã€?"(ゼロæ–?—å?)として、扱われますã?
052 *
053 * 編é›?ƒ‘ラメータに"SEQ"と記述することで正方向にしか選べなã�?‚·ークメニューを実現できますã?
054 * これにより、シーケンスにスãƒ??タスをé?に挙げてã�?��ような、ã?ルãƒ?‚¦ンメニュー
055 * を作æ?することがå?来ますã?(é€?�«戻れなã�?ƒ¡ニュー)
056 *
057 * カラãƒ??表示にå¿?¦�な属æ?は, DBColumn オブジェクãƒ?より取り出しますã?
058 * こã?クラスは、DBColumn オブジェクト毎に?‘つ作æ?されますã?
059 *
060 * @og.rev 3.2.3.0 (2003/06/06) 新規作æ?
061 * @og.rev 3.4.0.1 (2003/09/03) ?¤?¢検索をリアルタイãƒ?�«変更ã€?
062 * @og.rev 4.3.6.0 (2009/04/01) eventColumn対å¿?
063 * @og.rev 5.4.3.6 (2012/01/19) コメント変更
064 * @og.group ãƒ??タ編é›?
065 *
066 * @version 4.0
067 * @author Kazuhiko Hasegawa
068 * @since JDK5.0,
069 */
070 public class Editor_DBMENU extends AbstractEditor {
071 //* こã?プログラãƒ??VERSIONæ–?—å?を設定しますã? {@value} */
072 private static final String VERSION = "5.5.1.0 (2012/04/03)" ;
073
074 private final String query ;
075 private final String dbid ;
076 private final String lang ; // 4.0.0 (2006/11/15)
077 private final boolean addNoValue ; // 3.5.5.7 (2004/05/10)
078 private final boolean seqFlag ; // 3.6.0.6 (2004/10/22)
079 private final String useSLabel ; // 5.5.1.0 (2012/04/03)
080
081 /**
082 * ãƒ?ƒ•ォルトコンストラクターã€?
083 * こã?コンストラクターで、基本オブジェクトを作æ?しますã?
084 *
085 * @og.rev 3.4.0.1 (2003/09/03) 初期値でQUERYæ–?‚’キープするã?
086 * @og.rev 3.6.0.6 (2004/10/22) シーケンスアクセス機è?(seqFlag)を追åŠ?�—まã�?
087 * @og.rev 5.5.1.0 (2012/04/03) Slabel対å¿?
088 *
089 */
090 public Editor_DBMENU() {
091 // 4.3.4.4 (2009/01/01)
092 // super();
093 query = null;
094 dbid = null;
095 lang = null; // 4.0.0 (2006/11/15)
096 addNoValue = false; // 3.5.5.7 (2004/05/10)
097 seqFlag = false; // 3.6.0.6 (2004/10/22)
098 useSLabel = "auto"; // 5.5.1.0 (2012/04/03)
099 }
100
101 /**
102 * コンストラクターã€?
103 *
104 * @og.rev 3.3.1.1 (2003/07/03) name , attributes 属æ?ã‚?final にするã€?
105 * @og.rev 3.4.0.1 (2003/09/03) 継承の親å…??変更に伴ã�?®Ÿè£??移動ã?
106 * @og.rev 3.5.5.7 (2004/05/10) addNoValue 属æ?を追åŠ?�—ますã?
107 * @og.rev 3.5.5.9 (2004/06/07) editorParam 属æ?ã�?null の場合ã?、エラーとしますã?
108 * @og.rev 3.5.6.0 (2004/06/18) XHTMLTag の å†?ƒ¨配å? SELECT_KEY を隠蔽しますã?
109 * @og.rev 3.6.0.6 (2004/10/22) シーケンスアクセス機è?(seqFlag)を追åŠ?�—まã�?
110 * @og.rev 5.1.7.0 (2010/06/01) 動的プルãƒ?‚¦ン実è£?¦‹直ã�?
111 * @og.rev 5.5.1.0 (2012/04/03) Slabel対å¿?
112 *
113 * @param clm DBColumnオブジェクãƒ?
114 */
115 private Editor_DBMENU( final DBColumn clm ) {
116 // super( clm );
117 name = clm.getName();
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 (2006/11/15)
122 seqFlag = false; // 3.6.0.6 (2004/10/22)
123 // eventColumn = clm.getEventColumn(); // 4.3.6.0 (2009/04/01)
124 // eventURL = clm.getEventURL(); // 4.3.6.0 (2009/04/01)
125 // editor = clm.getEditor(); // 4.3.6.0 (2009/04/01)
126 useSLabel = clm.getUseSLabel() ; // 5.5.1.0 (2012/04/03)
127
128 // 3.5.5.9 (2004/06/07)
129 if( query == null || query.length() == 0 ) {
130 String errMsg = "DBMENU Editor では、編é›?ƒ‘ラメータはå¿??ですã?"
131 + " name=[" + name + "]" + HybsSystem.CR ;
132 throw new HybsSystemException( errMsg );
133 }
134
135 String disabled = clm.isWritable() ? null : "disabled" ;
136
137 attributes = new Attributes();
138 attributes.set( "disabled" ,disabled );
139
140 attributes.addAttributes( clm.getEditorAttributes() );
141 optAttr = attributes.get( "optionAttributes" );
142 tagBuffer.add( XHTMLTag.selectAttri( attributes ) );
143 }
144
145 /**
146 * å�?‚ªブジェクトからè?åˆ??インスタンスを返しますã?
147 * 自åˆ??身をキャãƒ?‚·ュするのかã?新たに作æ?するのかã?、各サブクラスの実è£?�«
148 * まかされますã?
149 *
150 * @param clm DBColumnオブジェクãƒ?
151 *
152 * @return CellEditorオブジェクãƒ?
153 */
154 public CellEditor newInstance( final DBColumn clm ) {
155 return new Editor_DBMENU( clm );
156 }
157
158 /**
159 * ãƒ??タの編é›?”¨æ–?—å?を返しますã?
160 *
161 * ここでは、AAA:BBB:CCC:DDD とã�?�†値をã?$1,$2,$3,$4 に割り当てなおしてã€?
162 * QUERYを実行しますã?またã?$1 は、本来の値として、メニューの初期値設定等に
163 * 使用しますã?上記ã?例では、AAA がå?で、それ以降ã?、引数になりますã?
164 * さらに、å?のæ–?—å?"AAA:BBB:CCC:DDD"はã€?0 に割り当てられますã?割り当てがなã�?
165 * 変数はã€?"(ゼロæ–?—å?)として、扱われますã?
166 * 又ã?$Cには自åˆ??身のカラãƒ?��を割り当てますã?
167 *
168 * @og.rev 3.4.0.1 (2003/09/03) リアルタイãƒ?�§値を作æ?する様に変更ã€?
169 * @og.rev 3.5.5.5 (2004/04/23) 新規に Attributes オブジェクトを作æ?する方式を止めますã?
170 * @og.rev 4.3.7.2 (2009/06/15) 属æ?でidがå?力される場合ã?、idをå?力しなã�?
171 * @og.rev 5.1.3.0 (2010/02/01) ä¸?¦§表示のみで、ツールチップ表示を行うã€?
172 * @og.rev 5.1.7.0 (2010/06/01) 動的プルãƒ?‚¦ン実è£?¦‹直ã�?
173 * @og.rev 5.5.1.0 (2012/04/03) Slabel対å¿?
174 *
175 * @param value 入力å?
176 *
177 * @return ãƒ??タの編é›?”¨æ–?—å?
178 */
179 @Override
180 public String getValue( final String value ) {
181 // final boolean uslbl = !"true".equals(useSLabel) ? false : true; // 5.5.1.0 (2012/04/03)
182 final boolean uslbl = "true".equalsIgnoreCase( useSLabel ); // 5.5.1.0 (2012/04/03)
183
184 TagBuffer tag = new TagBuffer( "select" );
185 tag.add( "name" , name );
186 if( attributes.get( "id" ) == null || attributes.get( "id" ).length() == 0 ) { // 4.3.7.2 (2009/06/15)
187 tag.add( "id" , name ); // 4.3.6.0 (2009/04/01)
188 }
189 tag.add( tagBuffer.makeTag() );
190 tag.add( optAttr ); // 3.5.5.8 (2004/05/20)
191
192 // 5.1.3.0 (2010/02/01)
193 // tag = getOption( tag,value );
194 // tag = getOption( tag,value,false );
195 tag = getOption( tag,value,uslbl ); // 5.5.1.0 (2012/04/03)
196
197 return tag.makeTag();
198 // return tag.makeTag() + createEventColumnJS( name, editor, -1, eventURL ); // 4.3.6.0 (2009/04/01)
199 }
200
201 /**
202 * name属æ?を変えたã?ãƒ??タ表示/編é›?”¨のHTMLæ–?—å?を作æ?しますã?
203 * ãƒ??ブル上ã? name に 行番号を付加して、名前_行番号 で登録するキーを作æ?ã�?
204 * リクエスト情報を1つ毎ã?フィールドで処ç�?�§きますã?
205 *
206 * ここでは、AAA:BBB:CCC:DDD とã�?�†値をã?$1,$2,$3,$4 に割り当てなおしてã€?
207 * QUERYを実行しますã?またã?$1 は、本来の値として、メニューの初期値設定等に
208 * 使用しますã?上記ã?例では、AAA がå?で、それ以降ã?、引数になりますã?
209 * さらに、å?のæ–?—å?"AAA:BBB:CCC:DDD"はã€?0 に割り当てられますã?割り当てがなã�?
210 * 変数はã€?"(ゼロæ–?—å?)として、扱われますã?
211 * 又ã?$Cには自åˆ??身のカラãƒ?��を割り当てますã?
212 *
213 * @og.rev 2.0.0.3 (2002/09/26) optionAttributes 属æ?に "$i" を使ã�?�¨そã?行数に置き換る機è?を追åŠ??
214 * @og.rev 3.4.0.1 (2003/09/03) リアルタイãƒ?�§値を作æ?する様に変更ã€?
215 * @og.rev 3.5.5.0 (2004/03/12) 名前と行番号の区åˆ?‚Š記号("__")をã?HybsSystem.JOINT_STRING に変更ã€?
216 * @og.rev 3.5.5.5 (2004/04/23) 新規に Attributes オブジェクトを作æ?する方式を止めますã?
217 * @og.rev 4.3.7.2 (2009/06/15) 属æ?でidがå?力される場合ã?、idをå?力しなã�?
218 * @og.rev 5.1.3.0 (2010/02/01) ä¸?¦§表示のみで、ツールチップ表示を行うã€?
219 * @og.rev 5.1.7.0 (2010/06/01) 動的プルãƒ?‚¦ン実è£?¦‹直ã�?
220 * @og.rev 5.5.1.0 (2012/04/03) Slabel対å¿?
221 *
222 * @param row 行番号
223 * @param value 入力å?
224 *
225 * @return ãƒ??タ表示/編é›?”¨のæ–?—å?
226 */
227 @Override
228 public String getValue( final int row,final String value ) {
229 // final boolean uslbl = ("auto".equals(useSLabel) || "true".equals(useSLabel) ) ? true : false; // 5.5.1.0 (2012/04/03)
230 final boolean uslbl = "auto".equalsIgnoreCase( useSLabel ) || "true".equalsIgnoreCase( useSLabel ); // 5.5.1.0 (2012/04/03)
231
232 TagBuffer tag = new TagBuffer( "select" );
233 String newName = name + HybsSystem.JOINT_STRING + row; // 4.3.6.0 (2009/04/01)
234 //tag.add( "name" , name + HybsSystem.JOINT_STRING + row );
235 tag.add( "name", newName ); // 4.3.6.0 (2009/04/01)
236 if( attributes.get( "id" ) == null || attributes.get( "id" ).length() == 0 ) { // 4.3.7.2 (2009/06/15)
237 tag.add( "id" , newName ); // 4.3.6.0 (2009/04/01)
238 }
239 tag.add( tagBuffer.makeTag() );
240 tag.add( optAttr ); // 3.5.5.8 (2004/05/20)
241
242 // 5.1.3.0 (2010/02/01)
243 // tag = getOption( tag,value );
244 // tag = getOption( tag,value,true );
245 tag = getOption( tag,value,uslbl );
246
247 return tag.makeTag();
248 // return tag.makeTag() + createEventColumnJS( name, editor, row, eventURL ); // 4.3.6.0 (2009/04/01)
249 }
250
251 /**
252 * 初期値が選択済みの 選択肢(オプション)をTagBuffer に反映しますã?
253 * こã?オプションは、引数の値をå?期å?とするオプションタグ作æ?しã?TagBuffer
254 * に値を設定して返しますã?
255 *
256 * ここでは、AAA:BBB:CCC:DDD とã�?�†値をã?$1,$2,$3,$4 に割り当てなおしてã€?
257 * QUERYを実行しますã?またã?$1 は、本来の値として、メニューの初期値設定等に
258 * 使用しますã?上記ã?例では、AAA がå?で、それ以降ã?、引数になりますã?
259 * さらに、å?のæ–?—å?"AAA:BBB:CCC:DDD"はã€?0 に割り当てられますã?割り当てがなã�?
260 * 変数はã€?"(ゼロæ–?—å?)として、扱われますã?
261 * 又ã?$Cには自åˆ??身のカラãƒ?��を割り当てますã?
262 *
263 * @og.rev 3.5.5.7 (2004/05/10) getOption( String value )のå»?¢を受けて、新規作æ?
264 * @og.rev 3.6.0.6 (2004/10/22) シーケンスアクセス機è?(seqFlag)を追åŠ?�—まã�?
265 * @og.rev 4.0.0.0 (2006/11/15) SelectionFactory に lang 属æ?を追åŠ?�—ますã?
266 * @og.rev 4.3.4.0 (2008/12/01) $Cのカラãƒ?��置換えを追åŠ?
267 * @og.rev 5.1.3.0 (2010/02/01) ä¸?¦§表示のみで、ツールチップ表示を行うã€?
268 *
269 * @param buf タグæ–?—å?のバッファー
270 * @param value 選択されてã�?‚‹値
271 * @param useShortLabel ラベル(短)をã?ースとしたオプション表示を行うかどã�?�‹ã€?
272 *
273 * @return オプションタグ
274 */
275 private TagBuffer getOption( final TagBuffer buf,final String value,final boolean useShortLabel ) {
276
277 // StringFormat format = new StringFormat( query,value);
278 StringFormat format = new StringFormat( query, value, name ); // 4.3.4.0 (2008/12/01)
279 String newQuery = format.format();
280 String newValue = format.getValue();
281
282 Selection selection = SelectionFactory.newDBSelection( newQuery, dbid, lang );
283 boolean useMultiSelect = selection.useMultiSelect();
284 if( useMultiSelect ) {
285 buf.add( "onkeydown", "setKeySelect(this);" );
286 }
287
288 if( addNoValue ) {
289 // 5.1.3.0 (2010/02/01)
290 // buf.setBody( Selection.NO_VALUE_OPTION + selection.getOption( newValue, seqFlag ) );
291 buf.setBody( Selection.NO_VALUE_OPTION + selection.getOption( newValue, seqFlag, useShortLabel ) );
292 }
293 else {
294 // 5.1.3.0 (2010/02/01)
295 // buf.setBody( selection.getOption( newValue, seqFlag ) );
296 buf.setBody( selection.getOption( newValue, seqFlag, useShortLabel ) );
297 }
298
299 return buf;
300 }
301 }