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             * リクエスト情報を1つ毎ã?フィールドで処ç�?�§きますã?
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    }