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.hayabusa.db;
017    
018    import org.opengion.hayabusa.common.HybsSystem;
019    import org.opengion.fukurou.util.Attributes;
020    import org.opengion.fukurou.util.TagBuffer;
021    
022    /**
023     * CellEditor の具象クラスで、カラãƒ??ãƒ??タを編é›?�™るå?合に使用するクラスですã?
024     *
025     *  カラãƒ??表示にå¿?¦�な属æ?は, DBColumn オブジェクãƒ?より取り出しますã?
026     * こã?クラスは、DBColumn オブジェクト毎に?‘つ作æ?されますã?
027     *
028     * @og.group ãƒ??タ編é›?
029     *
030     * @version  4.0
031     * @author       Kazuhiko Hasegawa
032     * @since    JDK5.0,
033     */
034    public abstract class AbstractEditor implements CellEditor {
035            private final int COLUMNS_MAXSIZE = HybsSystem.sysInt( "HTML_COLUMNS_MAXSIZE" ) ;       // 表示フィールドã?大きさ
036            // 3.5.4.7 (2004/02/06) viewタグで表示する場合ã?カラãƒ??大きさ
037            private final int VIEW_COLUMNS_MAXSIZE = HybsSystem.sysInt( "HTML_VIEW_COLUMNS_MAXSIZE" ) ;
038    
039            // 3.3.1.1 (2003/07/03) name , attributes 属æ?ã‚?final にするã€?
040            protected  Attributes     attributes ;          // SubClass で誤って new することを防止
041            protected  String                 name           ;
042            protected  String                 size1          ;
043            protected  String                 size2          ;
044            protected  String                 optAttr        ;
045            protected  TagBuffer      tagBuffer = new TagBuffer() ;
046    //      protected  String                 eventColumn; // 4.3.6.0 (2009/04/01)
047    //      protected  String                 eventURL;        // 4.3.6.0 (2009/04/01)
048    //      protected  String                 editor;          // 4.3.6.0 (2009/04/01)
049    
050            /**
051             * ãƒ?ƒ•ォルトコンストラクターã€?
052             * こã?コンストラクターで、基本オブジェクトを作æ?しますã?
053             *
054             * @og.rev 3.1.1.1 (2003/04/03) å�?‚ªブジェクトからè?åˆ??インスタンスを返すファクトリメソãƒ?ƒ‰を追åŠ??
055             *
056             */
057            public AbstractEditor() {
058                    // ここでは処ç�?‚’行いませんã€?
059            }
060    
061            /**
062             * コンストラクターã€?
063             *
064             * @og.rev 3.1.1.1 (2003/04/03) å�?‚ªブジェクトからè?åˆ??インスタンスを返すファクトリメソãƒ?ƒ‰を追åŠ??
065             * @og.rev 3.5.4.2 (2003/12/15) 漢字å?åŠ?IMEモーãƒ?をONにするのをã?"K" のみとしますã?
066             * @og.rev 3.5.4.2 (2003/12/15) size ã�?1 の場合ã?CSSファイルでサイズæŒ?®šを行うクラスをå?力しますã?
067             * @og.rev 3.5.4.6 (2004/01/30) 漢字å?åŠ?IMEモーãƒ?をONにするのをã?"K" とã€?KX" のみとしますã?
068             * @og.rev 3.5.5.5 (2004/04/23) maxlength の導å?
069             * @og.rev 4.0.0.0 (2005/01/31) getFieldSize メソãƒ?ƒ‰ã‚?XHTMLTag から DBColumn へ移å‹?
070             * @og.rev 5.1.7.0 (2010/06/01) 動的プルãƒ?‚¦ン実è£?¦‹直ã�?
071             *
072             * @param       clm     DBColumnオブジェクãƒ?
073             */
074            protected AbstractEditor( final DBColumn clm ) {
075                    name                     = clm.getName();
076                    String  disabled = clm.isWritable() ? null : "disabled" ;
077    //              eventColumn = clm.getEventColumn(); // 4.3.6.0 (2009/04/01)
078    //              eventURL        = clm.getEventURL();    // 4.3.6.0 (2009/04/01)
079    //              editor          = clm.getEditor();              // 4.3.6.0 (2009/04/01)
080    
081                    int maxlength = clm.getTotalSize();             // 4.0.0 (2005/01/31) メソãƒ?ƒ‰名変更
082    
083                    attributes = new Attributes();
084                    attributes.set( "type"            ,"text" );
085                    attributes.set( "maxlength"   ,String.valueOf( maxlength ) );
086                    attributes.set( "disabled"        ,disabled );
087    
088                    attributes.addAttributes( clm.getEditorAttributes() );
089    
090                    String clazz = clm.getDbType();
091                    attributes.add( "class" ,clazz );
092                    if( maxlength <= 5 ) {
093                            attributes.add( "class" ,"S0" + maxlength );
094                    }
095    
096                    optAttr = attributes.get( "optionAttributes" );
097    
098                    // 3.5.5.5 (2004/04/23) size の導å?、å?期å?は、ä¸?¦§表のサイズにしますã?
099                    String size = clm.getViewLength();              // 4.0.0 (2005/01/31)
100                    if( size != null ) {
101                            if( size.indexOf(',') >= 0 ) {
102                                    size = size.substring( 0,size.indexOf(',') ) ;
103                            }
104                            size1 = size ;
105                            size2 = size ;
106                    }
107                    else {
108                            // 4.0.0 (2005/01/31) getFieldSize メソãƒ?ƒ‰ã‚?XHTMLTag から DBColumn へ移å‹?
109                            size1 = String.valueOf(clm.getFieldSize( maxlength,COLUMNS_MAXSIZE )) ;
110                            size2 = String.valueOf(clm.getFieldSize( maxlength,VIEW_COLUMNS_MAXSIZE )) ;
111                    }
112            }
113    
114            /**
115             * ãƒ??タの編é›?”¨æ–?­—å?を返しますã?
116             *
117             * @og.rev 3.5.5.5 (2004/04/23) viewSize の導å?
118             * @og.rev 4.3.7.2 (2009/06/15) 属æ?でidがå?力される場合ã?、idをå?力しなã�?
119             * @og.rev 5.1.7.0 (2010/06/01) 動的プルãƒ?‚¦ン実è£?¦‹直ã�?
120             *
121             * @param       value 値
122             *
123             * @return      ãƒ??タの編é›?”¨æ–?­—å?
124             */
125            public String getValue( final String value ) {
126    
127                    TagBuffer tag = new TagBuffer( "input" );
128                    tag.add( "name"    , name );
129                    if( attributes.get( "id" ) == null || attributes.get( "id" ).length() == 0 ) { // 4.3.7.2 (2009/06/15)
130                            tag.add( "id"      , name ); // 4.3.6.0 (2009/04/01)
131                    }
132                    tag.add( "value"   , value );
133                    tag.add( "size"    , size1 );
134                    tag.add( tagBuffer.makeTag() );
135                    tag.add( optAttr );             // 3.5.5.8 (2004/05/20)
136    
137                    return tag.makeTag();
138    //              return tag.makeTag() + createEventColumnJS( name, editor, -1, eventURL ); // 4.3.6.0 (2009/04/01)
139            }
140    
141            /**
142             * name属æ?を変えたã?ãƒ??タ表示/編é›?”¨のHTMLæ–?­—å?を作æ?しますã?
143             * ãƒ??ブル上ã? name に 行番号を付加して、名前_行番号 で登録するキーを作æ?ã�?
144             * リクエスト情報を1つ毎ã?フィールドで処ç�?�§きますã?
145             *
146             * @og.rev 2.0.0.3 (2002/09/26) optionAttributes 属æ?に "$i" を使ã�?�¨そã?行数に置き換る機è?を追åŠ??
147             * @og.rev 3.1.0.0 (2003/03/20) 名前と行番号の区åˆ?‚Š記号ã‚?"^" から "__" に変更ã€?
148             * @og.rev 3.5.4.2 (2003/12/15) getFieldSize をã?XHTMLTag.getFieldSize に変更ã€?
149             * @og.rev 3.5.4.7 (2004/02/06) viewタグで表示する場合ã?カラãƒ??大きさ VIEW_COLUMNS_MAXSIZE 追åŠ?
150             * @og.rev 3.5.5.0 (2004/03/12) 名前と行番号の区åˆ?‚Š記号("__")をã?HybsSystem.JOINT_STRING  に変更ã€?
151             * @og.rev 3.5.5.5 (2004/04/23) viewSize の導å?、å?期å?は、ä¸?¦§表にあわせましたã€?
152             * @og.rev 3.5.5.5 (2004/04/23) 新規に Attributes オブジェクトを作æ?する方式を止めますã?
153             * @og.rev 4.3.7.2 (2009/06/15) 属æ?でidがå?力される場合ã?、idをå?力しなã�?
154             * @og.rev 5.1.7.0 (2010/06/01) 動的プルãƒ?‚¦ン実è£?¦‹直ã�?
155             *
156             * @param       row   行番号
157             * @param       value 値
158             *
159             * @return      ãƒ??タ表示/編é›?”¨のæ–?­—å?
160             */
161            public String getValue( final int row,final String value ) {
162                    TagBuffer tag = new TagBuffer( "input" );
163                    String newName = name + HybsSystem.JOINT_STRING + row;
164                    // tag.add( "name"    , name + HybsSystem.JOINT_STRING + row );
165                    tag.add( "name"  , newName ); // 4.3.6.0 (2009/04/01)
166                    if( attributes.get( "id" ) == null || attributes.get( "id" ).length() == 0 ) { // 4.3.7.2 (2009/06/15)
167                            tag.add( "id"    , newName ); // 4.3.6.0 (2009/04/01)
168                    }
169                    tag.add( "value"   , value );
170                    tag.add( "size"    , size2 );
171                    tag.add( tagBuffer.makeTag() );
172                    tag.add( optAttr );             // 3.5.5.8 (2004/05/20)
173    
174                    return tag.makeTag( row,value );
175    //              return tag.makeTag( row,value ) + createEventColumnJS( name, editor, row, eventURL );
176            }
177    
178    //      /**
179    //       * EventColumnをセãƒ?ƒˆした場合に出力するJavaScriptを作りますã?
180    //       * 吐かれるJavaScriptは
181    //       * eventColumnに対してchangeイベント発生時にmakeColumnを呼びますã?
182    //       * なおかつ?‘度changeイベントを発生させますã?
183    //       * 以下ã?ようなJavaScriptとなりますã?
184    //       * $(function(){$('#EMPNO').change(function(){makeColumn(...);}).change();});
185    //       *
186    //       * rowにè²??値をå?れると__iをå?力しませんã€?
187    //       *
188    //       * @og.rev 4.3.6.0 (2009/04/01)
189    //       *
190    //       * @param clmName
191    //       * @param clmEditor
192    //       * @param row
193    //       * @param URL
194    //       */
195    //      protected String createEventColumnJS( final String clmName, final String clmEditor, final int row, final String URL ){
196    //              if( eventColumn != null && eventColumn.length() > 0 ){
197    //                      StringBuilder rtn = new StringBuilder();
198    //                      String[] evntCols = StringUtil.csv2Array( eventColumn );
199    //                      for( int i=0; i<evntCols.length; i++ ){
200    //                              rtn.append( "<script type=\"text/javascript\">" )
201    //                                      .append( "$(function(){$('#" )
202    //                                      .append( evntCols[i] );
203    //                              if( row >= 0 ){
204    //                                      rtn.append( HybsSystem.JOINT_STRING ).append( row );
205    //                              }
206    //
207    //                              rtn.append( "').change(function(){" )
208    //                                      .append( "makeColumn('" )
209    //                                      .append( clmName );
210    //                              if( row >= 0 ){
211    //                                      rtn.append( HybsSystem.JOINT_STRING ).append( row );
212    //                              }
213    //                              rtn.append( "','" )
214    //                                      .append( clmName ).append( "',EC_" )
215    //                                      .append( clmName )
216    //                                      .append( ",'" )
217    //                                      .append( clmEditor ).append( "','" )
218    //                                      .append( URL ).append( "');}).change();});" )
219    //                                      .append( "</script>" );
220    //                      }
221    //                      return rtn.toString();
222    //              }
223    //              return "";
224    //      }
225    }