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 * ãƒªã‚¯ã‚¨ã‚¹ãƒˆæƒ…å ±ã‚’ï¼‘ã¤æ¯Žã?フィールドã§å‡¦ç?§ãã¾ã™ã? 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 }