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