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.db.AbstractEditor;
020    import org.opengion.hayabusa.db.CellEditor;
021    import org.opengion.hayabusa.db.DBColumn;
022    import org.opengion.hayabusa.db.Selection;
023    import org.opengion.hayabusa.db.Selection_RADIO;
024    import org.opengion.fukurou.util.Attributes;
025    import org.opengion.fukurou.util.TagBuffer;
026    import org.opengion.fukurou.util.XHTMLTag;
027    
028    /**
029     * RADIO エãƒ?‚£ã‚¿ãƒ¼ã¯ã€ã‚«ãƒ©ãƒ??ãƒ??タをコードリソースã«å¯¾å¿œã—ãŸãƒ©ã‚¸ã‚ªãƒœã‚¿ãƒ³ã§ç·¨é›?™ã‚?
030     * å ´åˆã«ä½¿ç”¨ã™ã‚‹ã‚¯ãƒ©ã‚¹ã§ã™ã?
031     * ラジオボタンã¯ã€ãƒ©ãƒ™ãƒ«ãŒãªã?Š¶æ…‹ã§è¡¨ç¤ºã•れる為ã€?‹ç”¨æ™‚ã«ã¯ã€ãƒ©ãƒ™ãƒ«ã«
032     * 値(é¸æŠžè‚¢ã®ãƒ©ãƒ™ãƒ«)を作æ?ã—ã¦ã€columnEditor ç­‰ã§ç™»éŒ²ã—ã¦ç½®ã?¦ãã ã•ã„ã€?
033     *
034     * ä¸?¦§æ¤œç´¢æ˜Žç´°ç™»éŒ²ç”»é¢ç­‰ã§ã€ãƒ©ãƒ™ãƒ«è¡¨ç¤ºãŒå¿?¦ãªå ´åˆã?ã€ç·¨é›?ƒ‘ラメータã«ã€?useLabel"ã¨
035     * 記述ã—ã¦ãŠãã“ã¨ã§ã€ãƒ©ãƒ™ãƒ«ã‚’å?力ã™ã‚‹ã“ã¨ãŒå¯èƒ½ã§ã™ã?
036     *
037     * ã“ã?エãƒ?‚£ã‚¿ã¯eventColumnã«å¯¾å¿œã—ã¦ã?¾ã›ã‚“ã€?
038     *
039     *  カラãƒ??表示ã«å¿?¦ãªå±žæ?ã¯, DBColumn オブジェクãƒ?よりå–り出ã—ã¾ã™ã?
040     * ã“ã?クラスã¯ã€DBColumn オブジェクト毎ã«?‘ã¤ä½œæ?ã•れã¾ã™ã?
041     *
042     * @og.rev 3.5.1.0 (2003/10/03) æ–°è¦ä½œæ?
043     * @og.group �?タ編�
044     *
045     * @version  4.0
046     * @author       Kazuhiko Hasegawa
047     * @since    JDK5.0,
048     */
049    public class Editor_RADIO extends AbstractEditor {
050            //* ã“ã?プログラãƒ??VERSIONæ–?­—å?を設定ã—ã¾ã™ã?       {@value} */
051            private static final String VERSION = "4.3.3.0 (2008/10/01)" ;
052    
053            private final Selection selection ;
054            private final boolean writable ;
055            private final boolean useLabel ; // 4.3.3.0 (2008/10/01)
056    
057            /**
058             * ãƒ?ƒ•ォルトコンストラクターã€?
059             * ã“ã?コンストラクターã§ã€åŸºæœ¬ã‚ªãƒ–ジェクトを作æ?ã—ã¾ã™ã?
060             *
061             */
062            public Editor_RADIO() {
063                    // 4.3.4.4 (2009/01/01)
064    //              super();
065                    selection = null;
066                    writable  = false;
067                    useLabel  = false; // 4.3.3.0 (2008/10/01)
068            }
069    
070            /**
071             * コンストラクター�
072             *
073             * @og.rev 3.5.4.2 (2003/12/15) makeCodeSelection メソãƒ?ƒ‰ã‚?CodeSelectionクラスã«å¤‰æ›´ã€?
074             * @og.rev 3.5.5.7 (2004/05/10) SelectionFactory を使用ã—ã¦ã€ã‚ªãƒ–ジェクト作æ?
075             * @og.rev 4.0.0.0 (2005/01/31) SelectionFactory ã§ã¯ãªãã?直接 Selection_RADIO を作æ?ã€?
076             * @og.rev 4.3.3.0 (2008/10/01) ç·¨é›?ƒ‘ãƒ©ãƒ¡ãƒ¼ã‚¿ãƒ¼ã§æ˜Žç´°è¡¨ç¤ºæ™‚ã§ã‚‚ラベルãŒä½¿ãˆã‚‹ã‚ˆã†ã«å¯¾å¿?
077             *
078             * @param       clm     DBColumnオブジェク�
079             */
080            private Editor_RADIO( final DBColumn clm ) {
081            //      super( clm );
082                    name  = clm.getName();
083                    selection = new Selection_RADIO( clm.getCodeData() );   // 4.0.0 (2005/01/31)
084    
085                    writable = clm.isWritable();
086    
087                    attributes = new Attributes();
088                    attributes.addAttributes( clm.getEditorAttributes() );
089    
090                    attributes.add( "class","RADIO" );                      // (2003/10/08 修正�
091                    tagBuffer.add( XHTMLTag.inputAttri( attributes ) );
092    
093                    optAttr = attributes.get( "optionAttributes" );
094    
095                    // 4.3.3.0 (2008/10/01)
096                    useLabel = ( "useLabel".equalsIgnoreCase( clm.getEditorParam() ) ) ? true : false;
097            }
098    
099            /**
100             * å?‚ªãƒ–ジェクトã‹ã‚‰è?åˆ??インスタンスを返ã—ã¾ã™ã?
101             * 自åˆ??身をキャãƒ?‚·ãƒ¥ã™ã‚‹ã®ã‹ã?æ–°ãŸã«ä½œæ?ã™ã‚‹ã®ã‹ã?ã€å„サブクラスã®å®Ÿè£?«
102             * ã¾ã‹ã•れã¾ã™ã?
103             *
104             * @param       clm     DBColumnオブジェク�
105             *
106             * @return      CellEditorオブジェク�
107             */
108            public CellEditor newInstance( final DBColumn clm ) {
109                    return new Editor_RADIO( clm );
110            }
111    
112            /**
113             * ãƒ??ã‚¿ã®ç·¨é›?”¨æ–?­—å?ã‚’è¿”ã—ã¾ã™ã?
114             *
115             * @param       value 入力å?
116             *
117             * @return      ãƒ??ã‚¿ã®ç·¨é›?”¨æ–?­—å?
118             */
119            @Override
120            public String getValue( final String value ) {
121                    final String radio ;
122                    if( writable ) {
123                            radio = selection.getRadio( name,value,true );
124                    }
125                    else {
126                            radio = selection.getValueLabel( value );
127                    }
128    
129                    TagBuffer tag = new TagBuffer( "pre" );
130                    tag.add( tagBuffer.makeTag() );
131                    tag.add( optAttr );             // 3.5.5.8 (2004/05/20)
132                    tag.setBody( radio );
133    
134                    return tag.makeTag();
135            }
136    
137            /**
138             * name属æ?を変ãˆãŸã?ãƒ??タ表示/ç·¨é›?”¨ã®HTMLæ–?­—å?を作æ?ã—ã¾ã™ã?
139             * ãƒ??ブル上ã? name 㫠行番å·ã‚’付加ã—ã¦ã€åå‰_è¡Œç•ªå· ã§ç™»éŒ²ã™ã‚‹ã‚­ãƒ¼ã‚’作æ?ã?
140             * ãƒªã‚¯ã‚¨ã‚¹ãƒˆæƒ…å ±ã‚’ï¼‘ã¤æ¯Žã?フィールドã§å‡¦ç?§ãã¾ã™ã?
141             *
142             * @og.rev 3.5.5.0 (2004/03/12) åå‰ã¨è¡Œç•ªå·ã®åŒºåˆ?‚Šè¨˜å·("__")ã‚’ã?HybsSystem.JOINT_STRING  ã«å¤‰æ›´ã€?
143             * @og.rev 3.5.5.5 (2004/04/23) changeOptionAttributes ã‚’å»?­¢ã—ã¾ã™ã?
144             * @og.rev 4.3.3.0 (2008/10/01) ç·¨é›?ƒ‘ãƒ©ãƒ¡ãƒ¼ã‚¿ãƒ¼ã§æ˜Žç´°è¡¨ç¤ºæ™‚ã§ã‚‚ラベルãŒä½¿ãˆã‚‹ã‚ˆã†ã«å¯¾å¿?
145             *
146             * @param       row   行番å·
147             * @param       value 入力å?
148             *
149             * @return      ãƒ??タ表示/ç·¨é›?”¨ã®æ–?­—å?
150             */
151            @Override
152            public String getValue( final int row,final String value ) {
153                    final String radio ;
154                    if( writable ) {
155                            // 4.3.3.0 (2008/10/01)
156    //                      radio = selection.getRadio( name + HybsSystem.JOINT_STRING + row,value,false );
157                            radio = selection.getRadio( name + HybsSystem.JOINT_STRING + row,value,useLabel );
158                    }
159                    else {
160                            radio = selection.getRadioLabel( value );
161                    }
162    
163                    TagBuffer tag = new TagBuffer( "pre" );
164                    tag.add( tagBuffer.makeTag() );
165                    tag.setBody( radio );
166                    tag.add( optAttr );             // 3.5.5.8 (2004/05/20)
167    
168                    return tag.makeTag( row,value );
169            }
170    }