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.db.AbstractEditor; 019import org.opengion.hayabusa.db.CellEditor; 020import org.opengion.hayabusa.db.DBColumn; 021import org.opengion.fukurou.util.XHTMLTag; 022import org.opengion.hayabusa.common.HybsSystem; 023import org.opengion.fukurou.util.Attributes; 024import org.opengion.fukurou.util.StringUtil; 025import org.opengion.fukurou.util.TagBuffer; 026 027import static org.opengion.fukurou.util.StringUtil.isNull; // 6.1.1.0 (2015/01/17) 028 029/** 030 * TEXTAREA エディターは、カラムのデータをテキストエリアで編集する場合に 031 * 使用するクラスです。 032 * 033 * 従来との違いは、cols 属性の最大値を、検索時(query画面)では、HTML_COLUMNS_MAXSIZE を、 034 * 登録時(result画面)では、HTML_VIEW_COLUMNS_MAXSIZE を使用します。 035 * エリアの大きさは、デフォルト値を使用するか、編集パラメータに、x,y形式で 036 * 指定します。 037 * カラムの表示に必要な属性は, DBColumn オブジェクト より取り出します。 038 * このクラスは、DBColumn オブジェクト毎に1つ作成されます。 039 * 040 * @og.rev 4.0.0.0 (2005/01/31) 新規作成 041 * @og.group データ編集 042 * 043 * @version 4.0 044 * @author Kazuhiko Hasegawa 045 * @since JDK5.0, 046 */ 047public class Editor_TEXTAREA extends AbstractEditor { 048 /** このプログラムのVERSION文字列を設定します。 {@value} */ 049 private static final String VERSION = "6.4.4.2 (2016/04/01)" ; 050 051 // 6.9.6.0 (2018/05/07) protected に変更します。 052 protected String cols1 ; // 6.4.4.2 (2016/04/01) size1 を使わずに、cols1 を使用 053 protected String cols2 ; // 6.4.4.2 (2016/04/01) size2 を使わずに、cols2 を使用 054 protected String rows1 ; 055 protected String rows2 ; 056 057 /** 058 * デフォルトコンストラクター。 059 * このコンストラクターで、基本オブジェクトを作成します。 060 * 061 * @og.rev 3.1.1.1 (2003/04/03) 各オブジェクトから自分のインスタンスを返すファクトリメソッドを追加。 062 * 063 */ 064 public Editor_TEXTAREA() { super(); } // これも、自動的に呼ばれるが、空のメソッドを作成すると警告されるので、明示的にしておきます。 065 066 /** 067 * コンストラクター。 068 * 069 * @og.rev 3.1.1.1 (2003/04/03) 各オブジェクトから自分のインスタンスを返すファクトリメソッドを追加。 070 * @og.rev 3.2.4.0 (2003/06/12) パラメータより、行列(row,column)情報があれば、その値を利用する。 071 * @og.rev 3.3.1.1 (2003/07/03) name , attributes 属性を final にする。 072 * @og.rev 3.4.0.0 (2003/09/01) 表示パラメータ、編集パラメータ、文字パラメータの追加。 073 * @og.rev 3.5.5.0 (2004/03/12) 漢字入力(IMEモード)をONにするのを、"K" と、"KX" のみとします。 074 * @og.rev 3.5.6.0 (2004/06/18) XHTMLTag の 内部配列 TEXTAREA_KEY を隠蔽します。 075 * @og.rev 4.0.0.0 (2005/01/31) DBColumn の getClassName() を getDbType() に変更 076 * @og.rev 6.4.4.2 (2016/04/01) size1,size2 を使わずに、cols1,cols2 を使用。 077 * 078 * @param clm DBColumnオブジェクト 079 */ 080 protected Editor_TEXTAREA( final DBColumn clm ) { 081 super( clm ); 082 final String disabled = clm.isWritable() ? null : "disabled" ; 083 084 final int r1 = clm.getTotalSize()/Integer.parseInt(size1) + 1; // 4.0.0 (2005/01/31) メソッド名変更 085 if( r1 > 5 ) { rows1 = "5"; } 086 else { rows1 = String.valueOf( r1 ); } 087 088 final int r2 = clm.getTotalSize()/Integer.parseInt(size2) + 1; // 4.0.0 (2005/01/31) メソッド名変更 089 if( r2 > 5 ) { rows2 = "5"; } 090 else { rows2 = String.valueOf( r2 ); } 091 092 // 3.7.0.4 (2005/03/14) size に、"rows,cols" を指定できるように変更 093 final String param = StringUtil.nval( clm.getEditorParam(),clm.getViewLength() ); 094 if( param != null && param.length() != 0 ) { 095 final int st = param.indexOf( ',' ); 096 if( st > 0 ) { 097 rows1 = param.substring( 0,st ); 098 rows2 = rows1 ; 099 cols1 = param.substring( st+1 ); 100 cols2 = cols1; 101 } 102 } 103 104 // 6.4.4.2 (2016/04/01) size1,size2 を使わずに、cols1,cols2 を使用。 105 if( cols1 == null || cols2 == null ) { 106 cols1 = size1 ; 107 cols2 = size2 ; 108 } 109 110 // 6.1.1.0 (2015/01/17) Attributesの連結記述 111 attributes = new Attributes() 112 .set( "disabled" , disabled ) 113 .set( clm.getEditorAttributes() ) // #addAttributes( Attributes ) の代替え 114 .add( "class" , clm.getDbType() ); // 4.0.0 (2005/01/31) 115 116 // 6.1.1.0 (2015/01/17) TagBufferの連結記述 117 tagBuffer.add( XHTMLTag.textareaAttri( attributes ) ) 118 .add( attributes.get( "optionAttributes" ) ); // 6.0.4.0 (2014/11/28) 119 120 } 121 122 /** 123 * 各オブジェクトから自分のインスタンスを返します。 124 * 自分自身をキャッシュするのか、新たに作成するのかは、各サブクラスの実装に 125 * まかされます。 126 * 127 * @og.rev 3.1.1.1 (2003/04/03) 各オブジェクトから自分のインスタンスを返すファクトリメソッドを追加。 128 * @og.rev 3.1.2.1 (2003/04/10) synchronized を、削除します。 129 * 130 * @param clm DBColumnオブジェクト 131 * 132 * @return CellEditorオブジェクト 133 * @og.rtnNotNull 134 */ 135 public CellEditor newInstance( final DBColumn clm ) { 136 return new Editor_TEXTAREA( clm ); 137 } 138 139 /** 140 * データの編集用文字列を返します。 141 * 142 * @og.rev 4.3.7.2 (2009/06/15) 属性でidが出力される場合は、idを出力しない 143 * @og.rev 5.1.2.0 (2010/01/01) 先頭の'_'による書き込み制御を行わない。(他のクラスとの実装の共通化) 144 * @og.rev 5.1.7.0 (2010/06/01) 動的プルダウン実装見直し 145 * @og.rev 6.4.4.2 (2016/04/01) size1,size2 を使わずに、cols1,cols2 を使用。 146 * 147 * @param value 入力値 148 * 149 * @return データの編集用文字列 150 * @og.rtnNotNull 151 */ 152 @Override 153 public String getValue( final String value ) { 154 // 6.1.1.0 (2015/01/17) TagBufferの連結記述 155 return new TagBuffer( "textarea" ) 156 .add( "name" , name ) 157 .add( "id" , name , isNull( attributes.get( "id" ) ) ) // 4.3.7.2 (2009/06/15) 158 .add( "cols" , cols1 ) // 6.4.4.2 (2016/04/01) 159 .add( "rows" , rows1 ) 160 .add( tagBuffer.makeTag() ) 161 .addBody( value ) 162 .makeTag(); 163 } 164 165 /** 166 * name属性を変えた、データ表示/編集用のHTML文字列を作成します。 167 * テーブル上の name に 行番号を付加して、名前_行番号 で登録するキーを作成し, 168 * リクエスト情報を1つ毎のフィールドで処理できます。 169 * 170 * @og.rev 3.1.0.0 (2003/03/20) 名前と行番号の区切り記号を "^" から "__" に変更。 171 * @og.rev 3.5.5.0 (2004/03/12) 名前と行番号の区切り記号("__")を、HybsSystem.JOINT_STRING に変更。 172 * @og.rev 4.3.7.2 (2009/06/15) 属性でidが出力される場合は、idを出力しない 173 * @og.rev 5.1.2.0 (2010/01/01) 先頭の'_'による書き込み制御を行わない。(他のクラスとの実装の共通化) 174 * @og.rev 5.1.7.0 (2010/06/01) 動的プルダウン実装見直し 175 * @og.rev 6.4.4.2 (2016/04/01) size1,size2 を使わずに、cols1,cols2 を使用。 176 * 177 * @param row 行番号 178 * @param value 入力値 179 * 180 * @return データ表示/編集用の文字列 181 * @og.rtnNotNull 182 */ 183 @Override 184 public String getValue( final int row,final String value ) { 185 final String newName = name + HybsSystem.JOINT_STRING + row; 186 187 // 6.1.1.0 (2015/01/17) TagBufferの連結記述 188 return new TagBuffer( "textarea" ) 189 .add( "name" , newName ) 190 .add( "id" , newName , isNull( attributes.get( "id" ) ) ) // 4.3.7.2 (2009/06/15) 191 .add( "cols" , cols2 ) // 6.4.4.2 (2016/04/01) 192 .add( "rows" , rows2 ) 193 .add( tagBuffer.makeTag() ) 194 .addBody( value ) 195 .makeTag( row,value ); 196 } 197}