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        private  String cols1            ;              // 6.4.4.2 (2016/04/01) size1 を使わずに、cols1 を使用
052        private  String cols2            ;              // 6.4.4.2 (2016/04/01) size2 を使わずに、cols2 を使用
053        private  String rows1            ;
054        private  String rows2            ;
055
056        /**
057         * デフォルトコンストラクター。
058         * このコンストラクターで、基本オブジェクトを作成します。
059         *
060         * @og.rev 3.1.1.1 (2003/04/03) 各オブジェクトから自分のインスタンスを返すファクトリメソッドを追加。
061         *
062         */
063        public Editor_TEXTAREA() { super(); }           // これも、自動的に呼ばれるが、空のメソッドを作成すると警告されるので、明示的にしておきます。
064
065        /**
066         * コンストラクター。
067         *
068         * @og.rev 3.1.1.1 (2003/04/03) 各オブジェクトから自分のインスタンスを返すファクトリメソッドを追加。
069         * @og.rev 3.2.4.0 (2003/06/12) パラメータより、行列(row,column)情報があれば、その値を利用する。
070         * @og.rev 3.3.1.1 (2003/07/03) name , attributes 属性を final にする。
071         * @og.rev 3.4.0.0 (2003/09/01) 表示パラメータ、編集パラメータ、文字パラメータの追加。
072         * @og.rev 3.5.5.0 (2004/03/12) 漢字入力(IMEモード)をONにするのを、"K" と、"KX" のみとします。
073         * @og.rev 3.5.6.0 (2004/06/18) XHTMLTag の 内部配列 TEXTAREA_KEY を隠蔽します。
074         * @og.rev 4.0.0.0 (2005/01/31) DBColumn の getClassName() を getDbType() に変更
075         * @og.rev 6.4.4.2 (2016/04/01) size1,size2 を使わずに、cols1,cols2 を使用。
076         *
077         * @param       clm     DBColumnオブジェクト
078         */
079        protected Editor_TEXTAREA( final DBColumn clm ) {
080                super( clm );
081                final String  disabled = clm.isWritable() ? null : "disabled" ;
082
083                final int r1 = clm.getTotalSize()/Integer.parseInt(size1) + 1;          // 4.0.0 (2005/01/31) メソッド名変更
084                if( r1 > 5 ) { rows1 = "5"; }
085                else { rows1 = String.valueOf( r1 ); }
086
087                final int r2 = clm.getTotalSize()/Integer.parseInt(size2) + 1;          // 4.0.0 (2005/01/31) メソッド名変更
088                if( r2 > 5 ) { rows2 = "5"; }
089                else { rows2 = String.valueOf( r2 ); }
090
091                // 3.7.0.4 (2005/03/14) size に、"rows,cols" を指定できるように変更
092                final String param = StringUtil.nval( clm.getEditorParam(),clm.getViewLength() );
093                if( param != null && param.length() != 0 ) {
094                        final int st = param.indexOf( ',' );
095                        if( st > 0 ) {
096                                rows1 = param.substring( 0,st );
097                                rows2 = rows1 ;
098                                cols1 = param.substring( st+1 );
099                                cols2 = cols1;
100                        }
101                }
102
103                // 6.4.4.2 (2016/04/01) size1,size2 を使わずに、cols1,cols2 を使用。
104                if( cols1 == null || cols2 == null ) {
105                        cols1   = size1  ;
106                        cols2   = size2  ;
107                }
108
109                // 6.1.1.0 (2015/01/17) Attributesの連結記述
110                attributes = new Attributes()
111                                        .set( "disabled"        , disabled )
112                                        .set( clm.getEditorAttributes() )                               // #addAttributes( Attributes ) の代替え
113                                        .add( "class"           , clm.getDbType() );            // 4.0.0 (2005/01/31)
114
115                // 6.1.1.0 (2015/01/17) TagBufferの連結記述
116                tagBuffer.add( XHTMLTag.textareaAttri( attributes ) )
117                                 .add( attributes.get( "optionAttributes" ) );          // 6.0.4.0 (2014/11/28)
118
119        }
120
121        /**
122         * 各オブジェクトから自分のインスタンスを返します。
123         * 自分自身をキャッシュするのか、新たに作成するのかは、各サブクラスの実装に
124         * まかされます。
125         *
126         * @og.rev 3.1.1.1 (2003/04/03) 各オブジェクトから自分のインスタンスを返すファクトリメソッドを追加。
127         * @og.rev 3.1.2.1 (2003/04/10) synchronized を、削除します。
128         *
129         * @param       clm     DBColumnオブジェクト
130         *
131         * @return      CellEditorオブジェクト
132         * @og.rtnNotNull
133         */
134        public CellEditor newInstance( final DBColumn clm ) {
135                return new Editor_TEXTAREA( clm );
136        }
137
138        /**
139         * データの編集用文字列を返します。
140         *
141         * @og.rev 4.3.7.2 (2009/06/15) 属性でidが出力される場合は、idを出力しない
142         * @og.rev 5.1.2.0 (2010/01/01) 先頭の'_'による書き込み制御を行わない。(他のクラスとの実装の共通化)
143         * @og.rev 5.1.7.0 (2010/06/01) 動的プルダウン実装見直し
144         * @og.rev 6.4.4.2 (2016/04/01) size1,size2 を使わずに、cols1,cols2 を使用。
145         *
146         * @param   value 入力値
147         *
148         * @return  データの編集用文字列
149         * @og.rtnNotNull
150         */
151        @Override
152        public String getValue( final String value ) {
153                // 6.1.1.0 (2015/01/17) TagBufferの連結記述
154                return new TagBuffer( "textarea" )
155                                                .add( "name"    , name )
156                                                .add( "id"              , name , isNull( attributes.get( "id" ) ) )             // 4.3.7.2 (2009/06/15)
157                                                .add( "cols"    , cols1 )                               // 6.4.4.2 (2016/04/01)
158                                                .add( "rows"    , rows1 )
159                                                .add( tagBuffer.makeTag() )
160                                                .addBody( value )
161                                                .makeTag();
162
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        }
198}