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 */
016package org.opengion.plugin.column;
017
018import org.opengion.hayabusa.common.HybsSystem;
019import org.opengion.hayabusa.db.AbstractEditor;
020import org.opengion.hayabusa.db.CellEditor;
021import org.opengion.hayabusa.db.DBColumn;
022import org.opengion.hayabusa.db.Selection;
023import org.opengion.hayabusa.db.SelectionFactory;               // 5.7.3.0 (2014/02/07)
024import org.opengion.fukurou.util.Attributes;
025import org.opengion.fukurou.util.TagBuffer;
026import 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 オブジェクト毎に1つ作成されます。
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 */
049public class Editor_RADIO extends AbstractEditor {
050        //* このプログラムのVERSION文字列を設定します。   {@value} */
051        private static final String VERSION = "5.7.3.0 (2014/02/07)" ;
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                selection = null;
065                writable  = false;
066                useLabel  = false; // 4.3.3.0 (2008/10/01)
067        }
068
069        /**
070         * コンストラクター。
071         *
072         * @og.rev 3.5.4.2 (2003/12/15) makeCodeSelection メソッドを CodeSelectionクラスに変更。
073         * @og.rev 3.5.5.7 (2004/05/10) SelectionFactory を使用して、オブジェクト作成
074         * @og.rev 4.0.0.0 (2005/01/31) SelectionFactory ではなく、直接 Selection_RADIO を作成。
075         * @og.rev 4.3.3.0 (2008/10/01) 編集パラメーターで明細表示時でもラベルが使えるように対応
076         * @og.rev 5.7.3.0 (2014/02/07) SelectionFactory 対応
077         *
078         * @param       clm     DBColumnオブジェクト
079         */
080        private Editor_RADIO( final DBColumn clm ) {
081        //      super( clm );
082                name  = clm.getName();
083                // 5.7.3.0 (2014/02/07) SelectionFactory 対応
084                selection = SelectionFactory.newSelection( "RADIO" , clm.getCodeData() );
085
086                writable = clm.isWritable();
087
088                attributes = new Attributes();
089                attributes.addAttributes( clm.getEditorAttributes() );
090
091                attributes.add( "class","RADIO" );                      // (2003/10/08 修正分)
092                tagBuffer.add( XHTMLTag.inputAttri( attributes ) );
093
094                optAttr = attributes.get( "optionAttributes" );
095
096                // 4.3.3.0 (2008/10/01)
097                useLabel = "useLabel".equalsIgnoreCase( clm.getEditorParam() ) ? true : false;
098        }
099
100        /**
101         * 各オブジェクトから自分のインスタンスを返します。
102         * 自分自身をキャッシュするのか、新たに作成するのかは、各サブクラスの実装に
103         * まかされます。
104         *
105         * @param       clm     DBColumnオブジェクト
106         *
107         * @return      CellEditorオブジェクト
108         */
109        public CellEditor newInstance( final DBColumn clm ) {
110                return new Editor_RADIO( clm );
111        }
112
113        /**
114         * データの編集用文字列を返します。
115         *
116         * @param       value 入力値
117         *
118         * @return      データの編集用文字列
119         */
120        @Override
121        public String getValue( final String value ) {
122                final String radio ;
123                if( writable ) {
124                        radio = selection.getRadio( name,value,true );
125                }
126                else {
127                        radio = selection.getValueLabel( value );
128                }
129
130                TagBuffer tag = new TagBuffer( "pre" );
131                tag.add( tagBuffer.makeTag() );
132                tag.add( optAttr );             // 3.5.5.8 (2004/05/20)
133                tag.setBody( radio );
134
135                return tag.makeTag();
136        }
137
138        /**
139         * name属性を変えた、データ表示/編集用のHTML文字列を作成します。
140         * テーブル上の name に 行番号を付加して、名前_行番号 で登録するキーを作成し,
141         * リクエスト情報を1つ毎のフィールドで処理できます。
142         *
143         * @og.rev 3.5.5.0 (2004/03/12) 名前と行番号の区切り記号("__")を、HybsSystem.JOINT_STRING  に変更。
144         * @og.rev 3.5.5.5 (2004/04/23) changeOptionAttributes を廃止します。
145         * @og.rev 4.3.3.0 (2008/10/01) 編集パラメーターで明細表示時でもラベルが使えるように対応
146         *
147         * @param       row   行番号
148         * @param       value 入力値
149         *
150         * @return      データ表示/編集用の文字列
151         */
152        @Override
153        public String getValue( final int row,final String value ) {
154                final String radio ;
155                if( writable ) {
156                        // 4.3.3.0 (2008/10/01)
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}