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.SelectionCellEditor; // 6.2.2.0 (2015/03/27) 023import org.opengion.hayabusa.db.Selection; 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.rev 6.2.2.0 (2015/03/27) SelectionCellEditor I/Fを追加 045 * @og.group データ編集 046 * 047 * @version 4.0 048 * @author Kazuhiko Hasegawa 049 * @since JDK5.0, 050 */ 051public class Editor_RADIO extends AbstractEditor implements SelectionCellEditor { 052 /** このプログラムのVERSION文字列を設定します。 {@value} */ 053 private static final String VERSION = "6.4.4.2 (2016/04/01)" ; 054 055 private final Selection selection ; 056 private final boolean writable ; 057 private final boolean useLabel ; // 4.3.3.0 (2008/10/01) 058 059 private String errMsg ; // 6.0.4.0 (2014/11/28) 060 061 /** 062 * デフォルトコンストラクター。 063 * このコンストラクターで、基本オブジェクトを作成します。 064 * 065 */ 066 public Editor_RADIO() { 067 super(); // 6.4.1.1 (2016/01/16) PMD refactoring. It is a good practice to call super() in a constructor 068 // 4.3.4.4 (2009/01/01) 069 selection = null; 070 writable = false; 071 useLabel = false; // 4.3.3.0 (2008/10/01) 072 } 073 074 /** 075 * コンストラクター。 076 * 077 * @og.rev 3.5.4.2 (2003/12/15) makeCodeSelection メソッドを CodeSelectionクラスに変更。 078 * @og.rev 3.5.5.7 (2004/05/10) SelectionFactory を使用して、オブジェクト作成 079 * @og.rev 4.0.0.0 (2005/01/31) SelectionFactory ではなく、直接 Selection_RADIO を作成。 080 * @og.rev 4.3.3.0 (2008/10/01) 編集パラメーターで明細表示時でもラベルが使えるように対応 081 * @og.rev 5.7.3.0 (2014/02/07) SelectionFactory 対応 082 * @og.rev 6.0.4.0 (2014/11/28) selection が null の場合、警告表示します。 083 * @og.rev 6.0.4.0 (2014/11/28) optionAttributes は、コンストラクタで設定します。 084 * @og.rev 6.2.0.0 (2015/02/27) キー:ラベル形式で表示するかどうかを、指定できるようにします。 085 * @og.rev 6.4.4.2 (2016/04/01) nameがnullになってしまった。 086 * 087 * @param clm DBColumnオブジェクト 088 */ 089 private Editor_RADIO( final DBColumn clm ) { 090 // super(); // 6.4.1.1 (2016/01/16) PMD refactoring. It is a good practice to call super() in a constructor 091 super( clm ); // 6.4.4.2 (2016/04/01) nameがnullになってしまった。 092 // name = clm.getName(); 093 094 final String addKeyLabel = clm.getAddKeyLabel(); // 6.2.0.0 (2015/02/27) キー:ラベル形式 095 096 // 5.7.3.0 (2014/02/07) SelectionFactory 対応 097 selection = SelectionFactory.newSelection( "RADIO" , clm.getCodeData(), addKeyLabel ); 098 099 // 6.0.4.0 (2014/11/28) selection が null の場合、警告表示します。 100 if( selection == null ) { 101 errMsg = "codeData が未設定です。" 102 + " name=" + name 103 + " label=" + clm.getLabel() 104 + " editType=" + clm.getEditor() ; 105 System.out.println( errMsg ); 106 } 107 108 writable = clm.isWritable(); 109 110 // 6.1.1.0 (2015/01/17) Attributesの連結記述 111 attributes = new Attributes() 112 .set( clm.getEditorAttributes() ) // #addAttributes( Attributes ) の代替え 113 .add( "class","RADIO" ); // (2003/10/08 修正分) 114 115 // 6.1.1.0 (2015/01/17) TagBufferの連結記述 116 tagBuffer.add( XHTMLTag.inputAttri( attributes ) ) 117 .add( attributes.get( "optionAttributes" ) ); // 6.0.4.0 (2014/11/28) 118 119 // 4.3.3.0 (2008/10/01) 120 useLabel = "useLabel".equalsIgnoreCase( clm.getEditorParam() ) ; 121 } 122 123 /** 124 * 各オブジェクトから自分のインスタンスを返します。 125 * 自分自身をキャッシュするのか、新たに作成するのかは、各サブクラスの実装に 126 * まかされます。 127 * 128 * @param clm DBColumnオブジェクト 129 * 130 * @return CellEditorオブジェクト 131 * @og.rtnNotNull 132 */ 133 public CellEditor newInstance( final DBColumn clm ) { 134 return new Editor_RADIO( clm ); 135 } 136 137 /** 138 * データの編集用文字列を返します。 139 * 140 * @og.rev 6.0.4.0 (2014/11/28) selection が null の場合、警告表示します。 141 * @og.rev 6.2.2.4 (2015/04/24) getRadio廃止。getOption として、引数違いとして用意する。 142 * 143 * @param value 入力値 144 * 145 * @return データの編集用文字列 146 * @og.rtnNotNull 147 */ 148 @Override 149 public String getValue( final String value ) { 150 // 6.0.4.0 (2014/11/28) selection が null の場合、警告表示します。 151 if( selection == null ) { 152 return "<span class=\"error\">" + errMsg + " value=" + value + "</span>"; 153 } 154 155 final String radio ; 156 if( writable ) { 157 radio = selection.getOption( name,value,true ); // 6.2.2.4 (2015/04/24) 158 } 159 else { 160 radio = selection.getValueLabel( value,true ); // 6.2.2.4 (2015/04/24) useLabel 161 } 162 163 // 6.1.1.0 (2015/01/17) TagBufferの連結記述 164 return new TagBuffer( "pre" ) 165 .add( tagBuffer.makeTag() ) 166 .addBody( radio ) 167 .makeTag(); 168 169 } 170 171 /** 172 * name属性を変えた、データ表示/編集用のHTML文字列を作成します。 173 * テーブル上の name に 行番号を付加して、名前_行番号 で登録するキーを作成し, 174 * リクエスト情報を1つ毎のフィールドで処理できます。 175 * 176 * @og.rev 3.5.5.0 (2004/03/12) 名前と行番号の区切り記号("__")を、HybsSystem.JOINT_STRING に変更。 177 * @og.rev 3.5.5.5 (2004/04/23) changeOptionAttributes を廃止します。 178 * @og.rev 4.3.3.0 (2008/10/01) 編集パラメーターで明細表示時でもラベルが使えるように対応 179 * @og.rev 6.0.4.0 (2014/11/28) selection が null の場合、警告表示します。 180 * @og.rev 6.2.2.4 (2015/04/24) getRadio廃止。getOption として、引数違いとして用意する。 181 * 182 * @param row 行番号 183 * @param value 入力値 184 * 185 * @return データ表示/編集用の文字列 186 * @og.rtnNotNull 187 */ 188 @Override 189 public String getValue( final int row,final String value ) { 190 // 6.0.4.0 (2014/11/28) selection が null の場合、警告表示します。 191 if( selection == null ) { 192 return "<span class=\"error\">" + errMsg + " value=" + value + " row=" + row + "</span>"; 193 } 194 195 final String radio ; 196 if( writable ) { 197 // 4.3.3.0 (2008/10/01) 198 radio = selection.getOption( name + HybsSystem.JOINT_STRING + row,value,useLabel ); // 6.2.2.4 (2015/04/24) 199 } 200 else { 201 radio = selection.getValueLabel( value,useLabel ); // 6.2.2.4 (2015/04/24) 202 } 203 204 // 6.1.1.0 (2015/01/17) TagBufferの連結記述 205 return new TagBuffer( "pre" ) 206 .add( tagBuffer.makeTag() ) 207 .addBody( radio ) 208 .makeTag( row,value ); 209 210 } 211}