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.fukurou.util.XHTMLTag; 023import org.opengion.fukurou.util.Attributes; 024import org.opengion.fukurou.util.TagBuffer; 025 026import org.opengion.hayabusa.db.Selection; // 6.4.4.0 (2016/03/11) 027import org.opengion.hayabusa.db.SelectionFactory; // 6.4.4.0 (2016/03/11) 028 029/** 030 * CHBOX2 エディターは、カラムのデータをチェックボックスで編集する場合に使用するクラスです。 031 * 032 * このエディターは、CHBOXとは異なりチェックボックス特有の制御を全く行いません。 033 * 特性としては、typeがcheckboxであるという1点を除いて、TEXT エディターと同じです 034 * 035 * ラベル表示が必要な場合は、編集パラメータに、"useLabel"と 036 * 記述しておくことで、ラベルを出力することが可能です。 037 * 038 * カラムの表示に必要な属性は, DBColumn オブジェクト より取り出します。 039 * このクラスは、DBColumn オブジェクト毎に1つ作成されます。 040 * 041 * 6.4.4.0 (2016/03/11) 042 * チェックボックスとして、チェックした値を送信する機能に、コードリソースの値を 043 * 指定できるようにします。これは、プルダウンメニューのマルチプルと同じ効果が 044 * 期待できます。 045 * コードリソースは、無くてもかまいません。 046 * 047 * @og.group データ編集 048 * 049 * @version 6.4 050 * @author Kazuhiko Hasegawa 051 * @since JDK8.0, 052 */ 053public class Editor_CHBOX2 extends AbstractEditor { 054 /** このプログラムのVERSION文字列を設定します。 {@value} */ 055 private static final String VERSION = "7.0.5.1 (2019/09/27)" ; 056 057 // 6.4.4.0 (2016/03/11) CHBOX2 は、Selection は、必須ではなく、定義されていれば使う程度 058 private final Selection selection ; // 6.4.4.0 (2016/03/11) 059 private final boolean writable ; 060 private final boolean useLabel ; // 4.3.3.0 (2008/10/01) 061 062 /** 063 * デフォルトコンストラクター。 064 * このコンストラクターで、基本オブジェクトを作成します。 065 * 066 * @og.rev 6.4.4.0 (2016/03/11) CHBOX2は、コードリソースも使用できるように変更。 067 */ 068 public Editor_CHBOX2() { 069 super(); // 6.4.1.1 (2016/01/16) PMD refactoring. It is a good practice to call super() in a constructor 070 selection = null; 071 writable = false; 072 useLabel = false; 073 } 074 075 /** 076 * DBColumnオブジェクトを指定したprivateコンストラクター。 077 * 078 * @og.rev 6.3.3.0 (2015/07/25) maxlength は不要なので削除 079 * @og.rev 6.4.4.0 (2016/03/11) CHBOX2は、コードリソースも使用できるように変更。 080 * @og.rev 7.0.5.1 (2019/09/27) optionAttributes が二重に設定されていたため、削除 081 * 082 * @param clm DBColumnオブジェクト 083 */ 084 private Editor_CHBOX2( final DBColumn clm ) { 085 super( clm ); 086 attributes.set( "type" , "checkbox" ); 087 attributes.set( "NO_MAXLEN" , "true" ); // 6.3.3.0 (2015/07/25) maxlength は不要なので削除 088 089 tagBuffer.add( XHTMLTag.inputAttri( attributes ) ); 090 091 // CHBOX2 は、コードリソース(selection)が存在しない場合もありうる。 092 final String addKeyLabel = clm.getAddKeyLabel(); // 6.2.0.0 (2015/02/27) キー:ラベル形式 093 selection = SelectionFactory.newSelection( "CHBOX" , clm.getCodeData(), addKeyLabel ); 094 095 // 6.4.4.0 (2016/03/11) CHBOX2は、コードリソースも使用できるように変更。 096 writable = clm.isWritable(); 097 098 // 6.1.1.0 (2015/01/17) Attributesの連結記述 099 attributes = new Attributes() 100 .set( clm.getEditorAttributes() ) // #addAttributes( Attributes ) の代替え 101 .add( "class","CHBOX" ); 102 103 // 6.1.1.0 (2015/01/17) TagBufferの連結記述 104 // 7.0.5.1 (2019/09/27) optionAttributes が二重に設定されていたため、削除 105 tagBuffer.add( XHTMLTag.inputAttri( attributes ) ); 106// .add( attributes.get( "optionAttributes" ) ); // 6.0.4.0 (2014/11/28) 107 108 useLabel = "useLabel".equalsIgnoreCase( clm.getEditorParam() ); 109 } 110 111 /** 112 * 各オブジェクトから自分のインスタンスを返します。 113 * 自分自身をキャッシュするのか、新たに作成するのかは、各サブクラスの実装に 114 * まかされます。 115 * 116 * @param clm DBColumnオブジェクト 117 * 118 * @return CellEditorオブジェクト 119 * @og.rtnNotNull 120 */ 121 public CellEditor newInstance( final DBColumn clm ) { 122 return new Editor_CHBOX2( clm ); 123 } 124 125 /** 126 * データの編集用文字列を返します。 127 * 128 * @og.rev 6.4.4.0 (2016/03/11) チェックボックスの横に値をラベル表示します 129 * 130 * @param value 値 131 * 132 * @return データの編集用文字列 133 * @og.rtnNotNull 134 */ 135 @Override 136 public String getValue( final String value ) { 137 final String chbox ; 138 139 if( selection == null ) { 140 chbox = new StringBuilder( BUFFER_MIDDLE ) 141 .append( "<label>" ) 142 .append( super.getValue( value ) ) 143 .append( value ) 144 .append( "</label>" ) 145 .toString(); 146 } 147 else { 148 if( writable ) { 149 chbox = selection.getOption( name,value,true ); // 6.2.2.4 (2015/04/24) 150 } 151 else { 152 chbox = selection.getValueLabel( value,true ); // 6.2.2.4 (2015/04/24) useLabel 153 } 154 } 155 156 return new TagBuffer( "pre" ) 157 .add( tagBuffer.makeTag() ) 158 .addBody( chbox ) 159 .makeTag(); 160 } 161 162 /** 163 * name属性を変えた、データ表示/編集用のHTML文字列を作成します。 164 * テーブル上の name に 行番号を付加して、名前_行番号 で登録するキーを作成し, 165 * リクエスト情報を1つ毎のフィールドで処理できます。 166 * 167 * @og.rev 6.4.4.0 (2016/03/11) チェックボックスの横に値をラベル表示します。 168 * 169 * @param row 行番号 170 * @param value 値 171 * 172 * @return データ表示/編集用の文字列 173 * @og.rtnNotNull 174 */ 175 @Override 176 public String getValue( final int row,final String value ) { 177 final String chbox ; 178 179 if( selection == null ) { 180 chbox = new StringBuilder( BUFFER_MIDDLE ) 181 .append( "<label>" ) 182 .append( super.getValue( row,value ) ) 183 .append( useLabel ? value : "" ) 184 .append( "</label>" ) 185 .toString(); 186 } 187 else { 188 if( writable ) { 189 chbox = selection.getOption( name + HybsSystem.JOINT_STRING + row,value,useLabel ); // 6.2.2.4 (2015/04/24) 190 } 191 else { 192 chbox = selection.getValueLabel( value,useLabel ); // 6.2.2.4 (2015/04/24) 193 } 194 } 195 196 return new TagBuffer( "pre" ) 197 .add( tagBuffer.makeTag() ) 198 .addBody( chbox ) 199 .makeTag( row,value ); 200 } 201}