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.fukurou.util.Attributes;
019 import org.opengion.fukurou.util.TagBuffer;
020 import org.opengion.fukurou.util.XHTMLTag;
021 import org.opengion.hayabusa.common.HybsSystem;
022 import org.opengion.hayabusa.common.HybsSystemException;
023 import org.opengion.hayabusa.db.AbstractEditor;
024 import org.opengion.hayabusa.db.CellEditor;
025 import org.opengion.hayabusa.db.DBColumn;
026 import org.opengion.hayabusa.db.Selection;
027 import org.opengion.hayabusa.db.SelectionFactory;
028 import org.opengion.fukurou.util.StringFormat;
029
030 /**
031 * DBRADIO エãƒ?‚£ターは、カラãƒ??編é›?ƒ‘ラメーターのSQLæ–??実行結果より、動çš?�«ラジオボタンã‚?
032 * 作æ?して編é›?�™るå?合に使用するエãƒ?‚£タークラスですã?
033 *
034 * 編é›?ƒ‘ラメータには、ラジオボタンを作æ?するための、SQLæ–?‚’記述しますã?
035 * こã?SQLæ–??、select KEY,LABEL from xx ?¥?¥?¥ とã�?�†構文で、KEY部åˆ?�¨LABEL部åˆ?�Œ
036 * 選択されますã?å�?‚«ラãƒ??意味は次のようになりますã?
037 * 第?‘カラãƒ?å¿??) : ラジオボタンのキー(値)
038 * 第?’カラãƒ? : ラベル(æŒ?®šされなã�??合ã?、ラベルリソースの短縮ラベルを使用しまã�?
039 * 第?“カラãƒ? : クラス そã?オプションに色づけなどを行う為のæŒ?®šしますã?
040 * NULL(またã?、ゼロæ–?—å?)の場合ã?ã€?�©用されませんã€?
041 * 第?”カラãƒ? : こã?値は'false'又ã?'0'である場合にそã?ラジオボタンを選択不可にしますã?
042 * NULL(またã?、ゼロæ–?—å?)の場合ã?ã€?�¸択可能になりますã?
043 *
044 * å�?‚«ラãƒ??値(value値)に、AAA:BBB:CCC:DDD とã�?�†値を設定できますã?これはã€?
045 * $1,$2,$3,$4 に割り当てなおして、QUERYを実行しますã?またã?$1 は、本来の値としてã€?
046 * メニューの初期値設定等に使用しますã?上記ã?例では、AAA がå?で、それ以降ã?ã€?
047 * 引数になりますã?
048 * 又ã?$Cには自åˆ??身のカラãƒ?��を割り当てますã?
049 * こã?機è?を使用すれば、動çš?ƒ¡ニューを行ごとに条件を変えて作æ?することã�?
050 * 可能になりますã?
051 * 例:select KEY,LABEL from xx where KUBUN='$2' and CDK='$3'
052 * さらに、å?のæ–?—å?"AAA:BBB:CCC:DDD"はã€?0 に割り当てられますã?割り当てがなã�?
053 * 変数はã€?"(ゼロæ–?—å?)として、扱われますã?
054 *
055 * こã?エãƒ?‚£タはeventColumnに対応してã�?�¾せんã€?
056 *
057 * カラãƒ??表示にå¿?¦�な属æ?は, DBColumn オブジェクãƒ?より取り出しますã?
058 * こã?クラスは、DBColumn オブジェクト毎に?‘つ作æ?されますã?
059 *
060 * @og.rev 4.3.3.6 (2008/11/15) 新規作æ?
061 * @og.group ãƒ??タ編é›?
062 *
063 * @version 4.0
064 * @author Hiroki Nakamura
065 * @since JDK5.0,
066 */
067 public class Editor_DBRADIO extends AbstractEditor {
068 //* こã?プログラãƒ??VERSIONæ–?—å?を設定しますã? {@value} */
069 private static final String VERSION = "4.3.4.0 (2008/12/01)" ;
070
071 private final String query ;
072 private final String dbid ;
073 private final String lang;
074 private final boolean writable ;
075
076 /**
077 * ãƒ?ƒ•ォルトコンストラクターã€?
078 * こã?コンストラクターで、基本オブジェクトを作æ?しますã?
079 *
080 */
081 public Editor_DBRADIO() {
082 // 4.3.4.4 (2009/01/01)
083 // super();
084 query = null;
085 dbid = null;
086 lang = null;
087 writable = false;
088 }
089
090 /**
091 * コンストラクターã€?
092 *
093 * @param clm DBColumnオブジェクãƒ?
094 */
095 private Editor_DBRADIO( final DBColumn clm ) {
096 name = clm.getName();
097 dbid = clm.getDbid();
098 lang = clm.getLang();
099
100 query = clm.getEditorParam();
101 if( query == null || query.length() == 0 ) {
102 String errMsg = "DBRADIO Editor では、編é›?ƒ‘ラメータはå¿??ですã?"
103 + " name=[" + name + "]" + HybsSystem.CR ;
104 throw new HybsSystemException( errMsg );
105 }
106
107 writable = clm.isWritable();
108
109 attributes = new Attributes();
110 attributes.addAttributes( clm.getEditorAttributes() );
111
112 attributes.add( "class","RADIO" );
113 tagBuffer.add( XHTMLTag.inputAttri( attributes ) );
114
115 optAttr = attributes.get( "optionAttributes" );
116 }
117
118 /**
119 * å�?‚ªブジェクトからè?åˆ??インスタンスを返しますã?
120 * 自åˆ??身をキャãƒ?‚·ュするのかã?新たに作æ?するのかã?、各サブクラスの実è£?�«
121 * まかされますã?
122 *
123 * @param clm DBColumnオブジェクãƒ?
124 *
125 * @return CellEditorオブジェクãƒ?
126 */
127 public CellEditor newInstance( final DBColumn clm ) {
128 return new Editor_DBRADIO( clm );
129 }
130
131 /**
132 * ãƒ??タの編é›?”¨æ–?—å?を返しますã?
133 *
134 * @og.rev 4.3.4.0 (2008/12/01) $Cのカラãƒ?��置換えを追åŠ?
135 *
136 * @param value 入力å?
137 *
138 * @return ãƒ??タの編é›?”¨æ–?—å?
139 */
140 @Override
141 public String getValue( final String value ) {
142 // StringFormat format = new StringFormat( query,value);
143 StringFormat format = new StringFormat( query, value, name ); // 4.3.4.0 (2008/12/01)
144 String newQuery = format.format();
145 String newValue = format.getValue();
146 Selection selection = SelectionFactory.newDBRadioSelection( newQuery,dbid,lang );
147
148 final String radio ;
149 if( writable ) {
150 radio = selection.getRadio( name,newValue,true );
151 }
152 else {
153 radio = selection.getValueLabel( newValue );
154 }
155
156 TagBuffer tag = new TagBuffer( "pre" );
157 tag.add( tagBuffer.makeTag() );
158 tag.add( optAttr );
159 tag.setBody( radio );
160
161 return tag.makeTag();
162 }
163
164 /**
165 * name属æ?を変えたã?ãƒ??タ表示/編é›?”¨のHTMLæ–?—å?を作æ?しますã?
166 * ãƒ??ブル上ã? name に 行番号を付加して、名前_行番号 で登録するキーを作æ?ã�?
167 * リクエスト情報を1つ毎ã?フィールドで処ç�?�§きますã?
168 *
169 * @og.rev 4.3.4.0 (2008/12/01) $Cのカラãƒ?��置換えを追åŠ?
170 *
171 * @param row 行番号
172 * @param value 入力å?
173 *
174 * @return ãƒ??タ表示/編é›?”¨のæ–?—å?
175 */
176 @Override
177 public String getValue( final int row,final String value ) {
178 // StringFormat format = new StringFormat( query,value);
179 StringFormat format = new StringFormat( query, value, name ); // 4.3.4.0 (2008/12/01)
180 String newQuery = format.format();
181 String newValue = format.getValue();
182 Selection selection = SelectionFactory.newDBRadioSelection( newQuery,dbid,lang );
183
184 final String radio ;
185 if( writable ) {
186 radio = selection.getRadio( name + HybsSystem.JOINT_STRING + row,newValue,true );
187 }
188 else {
189 radio = selection.getRadioLabel( newValue );
190 }
191
192 TagBuffer tag = new TagBuffer( "pre" );
193 tag.add( tagBuffer.makeTag() );
194 tag.setBody( radio );
195 tag.add( optAttr );
196
197 return tag.makeTag( row,value );
198 }
199 }