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; 023// import org.opengion.hayabusa.db.Selection_RADIO; // 5.7.3.0 (2014/02/07) SelectionFactory を使う様に変更 024import org.opengion.hayabusa.db.SelectionFactory; // 5.7.3.0 (2014/02/07) 025import org.opengion.fukurou.util.Attributes; 026import org.opengion.fukurou.util.TagBuffer; 027import org.opengion.fukurou.util.XHTMLTag; 028 029/** 030 * RADIO エディターは、カラムのデータをコードリソースに対応したラジオボタンで編集する 031 * 場合に使用するクラスです。 032 * ラジオボタンは、ラベルがない状態で表示される為、運用時には、ラベルに 033 * 値(選択肢のラベル)を作成して、columnEditor 等で登録して置いてください。 034 * 035 * 一覧検索明細登録画面等で、ラベル表示が必要な場合は、編集パラメータに、"useLabel"と 036 * 記述しておくことで、ラベルを出力することが可能です。 037 * 038 * このエディタはeventColumnに対応していません。 039 * 040 * カラムの表示に必要な属性は, DBColumn オブジェクト より取り出します。 041 * このクラスは、DBColumn オブジェクト毎に1つ作成されます。 042 * 043 * @og.rev 3.5.1.0 (2003/10/03) 新規作成 044 * @og.group データ編集 045 * 046 * @version 4.0 047 * @author Kazuhiko Hasegawa 048 * @since JDK5.0, 049 */ 050public class Editor_RADIO extends AbstractEditor { 051 //* このプログラムのVERSION文字列を設定します。 {@value} */ 052 private static final String VERSION = "5.7.3.0 (2014/02/07)" ; 053 054 private final Selection selection ; 055 private final boolean writable ; 056 private final boolean useLabel ; // 4.3.3.0 (2008/10/01) 057 058 /** 059 * デフォルトコンストラクター。 060 * このコンストラクターで、基本オブジェクトを作成します。 061 * 062 */ 063 public Editor_RADIO() { 064 // 4.3.4.4 (2009/01/01) 065// super(); 066 selection = null; 067 writable = false; 068 useLabel = false; // 4.3.3.0 (2008/10/01) 069 } 070 071 /** 072 * コンストラクター。 073 * 074 * @og.rev 3.5.4.2 (2003/12/15) makeCodeSelection メソッドを CodeSelectionクラスに変更。 075 * @og.rev 3.5.5.7 (2004/05/10) SelectionFactory を使用して、オブジェクト作成 076 * @og.rev 4.0.0.0 (2005/01/31) SelectionFactory ではなく、直接 Selection_RADIO を作成。 077 * @og.rev 4.3.3.0 (2008/10/01) 編集パラメーターで明細表示時でもラベルが使えるように対応 078 * @og.rev 5.7.3.0 (2014/02/07) SelectionFactory 対応 079 * 080 * @param clm DBColumnオブジェクト 081 */ 082 private Editor_RADIO( final DBColumn clm ) { 083 // super( clm ); 084 name = clm.getName(); 085 // 5.7.3.0 (2014/02/07) SelectionFactory 対応 086// selection = new Selection_RADIO( clm.getCodeData() ); // 4.0.0 (2005/01/31) 087 selection = SelectionFactory.newSelection( "RADIO" , clm.getCodeData() ); 088 089 writable = clm.isWritable(); 090 091 attributes = new Attributes(); 092 attributes.addAttributes( clm.getEditorAttributes() ); 093 094 attributes.add( "class","RADIO" ); // (2003/10/08 修正分) 095 tagBuffer.add( XHTMLTag.inputAttri( attributes ) ); 096 097 optAttr = attributes.get( "optionAttributes" ); 098 099 // 4.3.3.0 (2008/10/01) 100 useLabel = ( "useLabel".equalsIgnoreCase( clm.getEditorParam() ) ) ? true : false; 101 } 102 103 /** 104 * 各オブジェクトから自分のインスタンスを返します。 105 * 自分自身をキャッシュするのか、新たに作成するのかは、各サブクラスの実装に 106 * まかされます。 107 * 108 * @param clm DBColumnオブジェクト 109 * 110 * @return CellEditorオブジェクト 111 */ 112 public CellEditor newInstance( final DBColumn clm ) { 113 return new Editor_RADIO( clm ); 114 } 115 116 /** 117 * データの編集用文字列を返します。 118 * 119 * @param value 入力値 120 * 121 * @return データの編集用文字列 122 */ 123 @Override 124 public String getValue( final String value ) { 125 final String radio ; 126 if( writable ) { 127 radio = selection.getRadio( name,value,true ); 128 } 129 else { 130 radio = selection.getValueLabel( value ); 131 } 132 133 TagBuffer tag = new TagBuffer( "pre" ); 134 tag.add( tagBuffer.makeTag() ); 135 tag.add( optAttr ); // 3.5.5.8 (2004/05/20) 136 tag.setBody( radio ); 137 138 return tag.makeTag(); 139 } 140 141 /** 142 * name属性を変えた、データ表示/編集用のHTML文字列を作成します。 143 * テーブル上の name に 行番号を付加して、名前_行番号 で登録するキーを作成し, 144 * リクエスト情報を1つ毎のフィールドで処理できます。 145 * 146 * @og.rev 3.5.5.0 (2004/03/12) 名前と行番号の区切り記号("__")を、HybsSystem.JOINT_STRING に変更。 147 * @og.rev 3.5.5.5 (2004/04/23) changeOptionAttributes を廃止します。 148 * @og.rev 4.3.3.0 (2008/10/01) 編集パラメーターで明細表示時でもラベルが使えるように対応 149 * 150 * @param row 行番号 151 * @param value 入力値 152 * 153 * @return データ表示/編集用の文字列 154 */ 155 @Override 156 public String getValue( final int row,final String value ) { 157 final String radio ; 158 if( writable ) { 159 // 4.3.3.0 (2008/10/01) 160// radio = selection.getRadio( name + HybsSystem.JOINT_STRING + row,value,false ); 161 radio = selection.getRadio( name + HybsSystem.JOINT_STRING + row,value,useLabel ); 162 } 163 else { 164 radio = selection.getRadioLabel( value ); 165 } 166 167 TagBuffer tag = new TagBuffer( "pre" ); 168 tag.add( tagBuffer.makeTag() ); 169 tag.setBody( radio ); 170 tag.add( optAttr ); // 3.5.5.8 (2004/05/20) 171 172 return tag.makeTag( row,value ); 173 } 174}