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