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     */
016    package org.opengion.plugin.column;
017    
018    import org.opengion.hayabusa.db.AbstractEditor;
019    import org.opengion.hayabusa.db.CellEditor;
020    import org.opengion.hayabusa.db.DBColumn;
021    import org.opengion.fukurou.util.XHTMLTag;
022    import org.opengion.hayabusa.common.HybsSystem;
023    import org.opengion.fukurou.util.Attributes;
024    import org.opengion.fukurou.util.StringUtil;
025    import 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 オブジェクト毎ã«?‘ã¤ä½œæ?ã•れã¾ã™ã?
037     * <del>ãªãŠã?ã“ã?クラスã«ã¯ã€å?ã‚ã?æ–?­—㌠_(アンãƒ??ãƒã?)ã®å ´åˆã?書込ã¿ç¦æ­¢ã«ãªã‚‹ä»•様ãŒ
038     * 標準的ã«å°Žå?ã•れã¦ã?¾ã™ã?</del>
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     */
047    public class Editor_TEXTAREA extends AbstractEditor {
048            //* ã“ã?プログラãƒ??VERSIONæ–?­—å?を設定ã—ã¾ã™ã?       {@value} */
049            private static final String VERSION = "5.1.7.0 (2010/06/01)" ;
050    
051            private  String           rows1          ;
052            private  String           rows2          ;
053    
054            /**
055             * ãƒ?ƒ•ォルトコンストラクターã€?
056             * ã“ã?コンストラクターã§ã€åŸºæœ¬ã‚ªãƒ–ジェクトを作æ?ã—ã¾ã™ã?
057             *
058             * @og.rev 3.1.1.1 (2003/04/03) å?‚ªãƒ–ジェクトã‹ã‚‰è?åˆ??インスタンスを返ã™ãƒ•ァクトリメソãƒ?ƒ‰ã‚’追åŠ??
059             *
060             */
061            public Editor_TEXTAREA() {
062                    // 4.3.4.4 (2009/01/01)
063    //              super();
064            }
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             *
077             * @param       clm     DBColumnオブジェク�
078             */
079            private Editor_TEXTAREA( final DBColumn clm ) {
080                    super( clm );
081                    String  disabled = clm.isWritable() ? null : "disabled" ;
082    
083                    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                    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                    String param = StringUtil.nval( clm.getEditorParam(),clm.getViewLength() );
093                    if( param != null && param.length() != 0 ) {
094                            int st = param.indexOf( ',' );
095                            if( st > 0 ) {
096                                    rows1 = param.substring( 0,st );
097                                    rows2 = rows1 ;
098                                    size1 = param.substring( st+1 );
099                                    size2 = size1;
100                            }
101                    }
102    
103                    attributes = new Attributes();
104                    attributes.set( "disabled" ,disabled );
105    
106                    attributes.addAttributes( clm.getEditorAttributes() );
107                    attributes.add( "class" ,clm.getDbType() );             // 4.0.0 (2005/01/31)
108    
109                    optAttr = attributes.get( "optionAttributes" );
110                    tagBuffer.add( XHTMLTag.textareaAttri( attributes ) );
111            }
112    
113            /**
114             * å?‚ªãƒ–ジェクトã‹ã‚‰è?åˆ??インスタンスを返ã—ã¾ã™ã?
115             * 自åˆ??身をキャãƒ?‚·ãƒ¥ã™ã‚‹ã®ã‹ã?æ–°ãŸã«ä½œæ?ã™ã‚‹ã®ã‹ã?ã€å„サブクラスã®å®Ÿè£?«
116             * ã¾ã‹ã•れã¾ã™ã?
117             *
118             * @og.rev 3.1.1.1 (2003/04/03) å?‚ªãƒ–ジェクトã‹ã‚‰è?åˆ??インスタンスを返ã™ãƒ•ァクトリメソãƒ?ƒ‰ã‚’追åŠ??
119             * @og.rev 3.1.2.1 (2003/04/10) synchronized ã‚’ã?削除ã—ã¾ã™ã?
120             *
121             * @param       clm     DBColumnオブジェク�
122             *
123             * @return      CellEditorオブジェク�
124             */
125            public CellEditor newInstance( final DBColumn clm ) {
126                    return new Editor_TEXTAREA( clm );
127            }
128    
129            /**
130             * ãƒ??ã‚¿ã®ç·¨é›?”¨æ–?­—å?ã‚’è¿”ã—ã¾ã™ã?
131             *
132             * @og.rev 4.3.7.2 (2009/06/15) 属æ?ã§idãŒå?力ã•れる場åˆã?ã€idã‚’å?力ã—ãªã?
133             * @og.rev 5.1.2.0 (2010/01/01) å…ˆé?ã®'_'ã«ã‚ˆã‚‹æ›¸ãè¾¼ã¿åˆ¶å¾¡ã‚’行ã‚ãªã??(ä»–ã?クラスã¨ã®å®Ÿè£??共通化)
134             * @og.rev 5.1.7.0 (2010/06/01) 動的プルãƒ?‚¦ãƒ³å®Ÿè£?¦‹ç›´ã?
135             *
136             * @param   value 入力å?
137             *
138             * @return  ãƒ??ã‚¿ã®ç·¨é›?”¨æ–?­—å?
139             */
140            @Override
141            public String getValue( final String value ) {
142    //              if( value != null && value.length() >= 1 && value.charAt(0) == '_' ) {
143    //                      return value.substring( 1 );
144    //              }
145    
146                    TagBuffer tag = new TagBuffer( "textarea" );
147                    tag.add( "name"    , name );
148                    if( attributes.get( "id" ) == null || attributes.get( "id" ).length() == 0 ) { // 4.3.7.2 (2009/06/15)
149                            tag.add( "id"      , name ); // 4.3.6.0 (2009/04/01)
150                    }
151                    tag.add( "cols"    , size1 );
152                    tag.add( "rows"    , rows1 );
153                    tag.add( tagBuffer.makeTag() );
154                    tag.add( optAttr );             // 3.5.5.8 (2004/05/20)
155                    tag.setBody( value );
156    
157                    return tag.makeTag();
158    //              return tag.makeTag() + createEventColumnJS( name, editor, -1, eventURL ); // 4.3.6.0 (2009/04/01)
159            }
160    
161            /**
162             * name属æ?を変ãˆãŸã?ãƒ??タ表示/ç·¨é›?”¨ã®HTMLæ–?­—å?を作æ?ã—ã¾ã™ã?
163             * ãƒ??ブル上ã? name 㫠行番å·ã‚’付加ã—ã¦ã€åå‰_è¡Œç•ªå· ã§ç™»éŒ²ã™ã‚‹ã‚­ãƒ¼ã‚’作æ?ã?
164             * ãƒªã‚¯ã‚¨ã‚¹ãƒˆæƒ…å ±ã‚’ï¼‘ã¤æ¯Žã?フィールドã§å‡¦ç?§ãã¾ã™ã?
165             *
166             * @og.rev 3.1.0.0 (2003/03/20) åå‰ã¨è¡Œç•ªå·ã®åŒºåˆ?‚Šè¨˜å·ã‚?"^" ã‹ã‚‰ "__" ã«å¤‰æ›´ã€?
167             * @og.rev 3.5.5.0 (2004/03/12) åå‰ã¨è¡Œç•ªå·ã®åŒºåˆ?‚Šè¨˜å·("__")ã‚’ã?HybsSystem.JOINT_STRING  ã«å¤‰æ›´ã€?
168             * @og.rev 4.3.7.2 (2009/06/15) 属æ?ã§idãŒå?力ã•れる場åˆã?ã€idã‚’å?力ã—ãªã?
169             * @og.rev 5.1.2.0 (2010/01/01) å…ˆé?ã®'_'ã«ã‚ˆã‚‹æ›¸ãè¾¼ã¿åˆ¶å¾¡ã‚’行ã‚ãªã??(ä»–ã?クラスã¨ã®å®Ÿè£??共通化)
170             * @og.rev 5.1.7.0 (2010/06/01) 動的プルãƒ?‚¦ãƒ³å®Ÿè£?¦‹ç›´ã?
171             *
172             * @param   row   行番å·
173             * @param   value 入力å?
174             *
175             * @return  ãƒ??タ表示/ç·¨é›?”¨ã®æ–?­—å?
176             */
177            @Override
178            public String getValue( final int row,final String value ) {
179    //              if( value != null && value.length() >= 1 && value.charAt(0) == '_' ) {
180    //                      return value.substring( 1 );
181    //              }
182    
183                    TagBuffer tag = new TagBuffer( "textarea" );
184                    String newName = name + HybsSystem.JOINT_STRING + row;
185                    // tag.add( "name"    , name + HybsSystem.JOINT_STRING + row );
186                    tag.add( "name"    , newName );
187                    if( attributes.get( "id" ) == null || attributes.get( "id" ).length() == 0 ) { // 4.3.7.2 (2009/06/15)
188                            tag.add( "id"      , newName );
189                    }
190                    tag.add( "cols"    , size2 );
191                    tag.add( "rows"    , rows2 );
192                    tag.add( tagBuffer.makeTag() );
193                    tag.add( optAttr );             // 3.5.5.8 (2004/05/20)
194                    tag.setBody( value );
195    
196                    return tag.makeTag( row,value );
197    //              return tag.makeTag( row,value ) + createEventColumnJS( name, editor, row, eventURL ); // 4.3.6.0 (2009/04/01)
198            }
199    }