OSDN Git Service

Ver8.5.2.0
[opengion/opengionV8.git] / uap / webapps / gf / src / org / opengion / hayabusa / db / AbstractEditor.java
1 /*
2  * Copyright (c) 2009 The openGion Project.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific language
14  * governing permissions and limitations under the License.
15  */
16 package org.opengion.hayabusa.db;
17
18 import org.opengion.hayabusa.common.HybsSystem;
19 import org.opengion.fukurou.system.HybsConst ;                                  // 6.1.0.0 (2014/12/26)
20 import org.opengion.fukurou.util.Attributes;
21 import org.opengion.fukurou.util.TagBuffer;
22
23 import static org.opengion.fukurou.util.StringUtil.isNull;              // 6.1.0.0 (2014/12/26)
24
25 /**
26  * CellEditor の具象クラスで、カラムのデータを編集する場合に使用するクラスです。
27  *
28  *  カラムの表示に必要な属性は、DBColumn オブジェクト より取り出します。
29  * このクラスは、DBColumn オブジェクト毎に1つ作成されます。
30  *
31  * @og.group データ編集
32  *
33  * @version  4.0
34  * @author       Kazuhiko Hasegawa
35  * @since    JDK5.0,
36  */
37 public abstract class AbstractEditor implements CellEditor {
38         private final int COLUMNS_MAXSIZE = HybsSystem.sysInt( "HTML_COLUMNS_MAXSIZE" ) ;       // 表示フィールドの大きさ
39         // 3.5.4.7 (2004/02/06) viewタグで表示する場合のカラムの大きさ
40         private final int VIEW_COLUMNS_MAXSIZE = HybsSystem.sysInt( "HTML_VIEW_COLUMNS_MAXSIZE" ) ;
41
42         /** システムの改行コードを設定します。*/
43         protected static final String CR                 = HybsConst.CR;                        // 6.1.0.0 (2014/12/26) refactoring
44         /** StringBilderなどの初期値を設定します。 {@value} */
45         protected static final int BUFFER_MIDDLE = HybsConst.BUFFER_MIDDLE;     // 6.1.0.0 (2014/12/26) refactoring
46
47         // 3.3.1.1 (2003/07/03) name , attributes 属性を final にする。
48         /** attributes 属性 */
49         protected  Attributes   attributes ;            // SubClass で誤って new することを防止
50
51         // 6.4.4.2 (2016/04/01) size1,size2,name,tagBuffer をfinal化します。
52         /** 実数桁数 */
53         protected  final String         size1            ;
54         /** 小数点桁数 */
55         protected  final String         size2            ;
56         /** 名前 */
57         protected  final String         name             ;
58         /** タグバッファー */
59         protected  final TagBuffer      tagBuffer = new TagBuffer() ;
60
61         /**
62          * デフォルトコンストラクター。
63          * このコンストラクターで、基本オブジェクトを作成します。
64          *
65          * @og.rev 3.1.1.1 (2003/04/03) 各オブジェクトから自分のインスタンスを返すファクトリメソッドを追加。
66          * @og.rev 6.4.3.3 (2016/03/04) PMD refactoring. Each class should declare at least one constructor.
67          *
68          */
69         public AbstractEditor() {
70                 super();
71                 name    = "null" ;
72                 size1   = "20"   ;
73                 size2   = "30"   ;
74         }
75
76         /**
77          * コンストラクター。
78          *
79          * @og.rev 3.1.1.1 (2003/04/03) 各オブジェクトから自分のインスタンスを返すファクトリメソッドを追加。
80          * @og.rev 3.5.4.2 (2003/12/15) 漢字入力(IMEモード)をONにするのを、"K" のみとします。
81          * @og.rev 3.5.4.2 (2003/12/15) size が 1 の場合、CSSファイルでサイズ指定を行うクラスを出力します。
82          * @og.rev 3.5.4.6 (2004/01/30) 漢字入力(IMEモード)をONにするのを、"K" と、"KX" のみとします。
83          * @og.rev 3.5.5.5 (2004/04/23) maxlength の導入
84          * @og.rev 4.0.0.0 (2005/01/31) getFieldSize メソッドを XHTMLTag から DBColumn へ移動
85          * @og.rev 5.1.7.0 (2010/06/01) 動的プルダウン実装見直し
86          * @og.rev 6.0.4.0 (2014/11/28) optionAttributes は、コンストラクタで設定します。
87          * @og.rev 6.2.0.0 (2015/02/27) 小さなカラムのサイズ指定は、すでに廃止 ("S0" + 桁数(1~5))
88          * @og.rev 6.2.0.0 (2015/02/27) フィールドサイズ 追加(VIEW_LENGTHと分離して、役割を明確にする)
89          *
90          * @param       clm     DBColumnオブジェクト
91          */
92         protected AbstractEditor( final DBColumn clm ) {
93                 name = clm.getName();
94                 final String disabled = clm.isWritable() ? null : "disabled" ;
95
96                 final int maxlength = clm.getTotalSize();               // 4.0.0 (2005/01/31) メソッド名変更
97
98                 // 6.1.1.0 (2015/01/17) Attributesの連結記述
99                 attributes = new Attributes()
100                                                 .set( "type"            , "text" )
101                                                 .set( "maxlength"       , String.valueOf( maxlength ) )
102                                                 .set( "disabled"        , disabled )
103                                                 .set( clm.getEditorAttributes() )                                       // #addAttributes( Attributes ) の代替え
104                                                 .add( "class"           , clm.getDbType() );                    // clazz 属性として使用
105
106                 // 6.1.1.0 (2015/01/17) TagBufferの連結記述
107                 tagBuffer.add( attributes.get( "optionAttributes" ) );  // 6.0.4.0 (2014/11/28)
108
109                 // 3.5.5.5 (2004/04/23) size の導入、初期値は、一覧表のサイズにします。
110
111                 // 6.2.0.0 (2015/02/27) フィールドサイズ 追加(VIEW_LENGTHと分離して、役割を明確にする)
112                 size1 = String.valueOf( clm.getFieldSize( COLUMNS_MAXSIZE      ) );
113                 size2 = String.valueOf( clm.getFieldSize( VIEW_COLUMNS_MAXSIZE ) );
114         }
115
116         /**
117          * データの編集用文字列を返します。
118          *
119          * @og.rev 3.5.5.5 (2004/04/23) viewSize の導入
120          * @og.rev 4.3.7.2 (2009/06/15) 属性でidが出力される場合は、idを出力しない
121          * @og.rev 5.1.7.0 (2010/06/01) 動的プルダウン実装見直し
122          *
123          * @param       value 値
124          *
125          * @return      データの編集用文字列
126          * @og.rtnNotNull
127          */
128         @Override       // CellEditor
129         public String getValue( final String value ) {
130                 // 6.1.1.0 (2015/01/17) TagBufferの連結記述
131                 return new TagBuffer( "input" )
132                                         .add( "name"    , name )                                                                                // 4.3.6.0 (2009/04/01)
133                                         .add( "id"              , name , isNull( attributes.get( "id" ) ) )             // 4.3.7.2 (2009/06/15)
134                                         .add( "value"   , value )
135                                         .add( "size"    , size1 )
136                                         .add( tagBuffer.makeTag() )
137                                         .makeTag();
138         }
139
140         /**
141          * name属性を変えた、データ表示/編集用のHTML文字列を作成します。
142          * テーブル上の name に 行番号を付加して、名前_行番号 で登録するキーを作成し、
143          * リクエスト情報を1つ毎のフィールドで処理できます。
144          *
145          * @og.rev 2.0.0.3 (2002/09/26) optionAttributes 属性に "$i" を使うとその行数に置き換る機能を追加。
146          * @og.rev 3.1.0.0 (2003/03/20) 名前と行番号の区切り記号を "^" から "__" に変更。
147          * @og.rev 3.5.4.2 (2003/12/15) getFieldSize を、XHTMLTag.getFieldSize に変更。
148          * @og.rev 3.5.4.7 (2004/02/06) viewタグで表示する場合のカラムの大きさ VIEW_COLUMNS_MAXSIZE 追加
149          * @og.rev 3.5.5.0 (2004/03/12) 名前と行番号の区切り記号("__")を、HybsSystem.JOINT_STRING  に変更。
150          * @og.rev 3.5.5.5 (2004/04/23) viewSize の導入、初期値は、一覧表にあわせました。
151          * @og.rev 3.5.5.5 (2004/04/23) 新規に Attributes オブジェクトを作成する方式を止めます。
152          * @og.rev 4.3.7.2 (2009/06/15) 属性でidが出力される場合は、idを出力しない
153          * @og.rev 5.1.7.0 (2010/06/01) 動的プルダウン実装見直し
154          *
155          * @param       row   行番号
156          * @param       value 値
157          *
158          * @return      データ表示/編集用の文字列
159          * @og.rtnNotNull
160          */
161         @Override       // CellEditor
162         public String getValue( final int row,final String value ) {
163                 final String newName = name + HybsSystem.JOINT_STRING + row;
164
165                 // 6.1.1.0 (2015/01/17) TagBufferの連結記述
166                 return new TagBuffer( "input" )
167                                         .add( "name"    , newName )                                                                             // 4.3.6.0 (2009/04/01)
168                                         .add( "id"              , newName , isNull( attributes.get( "id" ) ) )  // 4.3.7.2 (2009/06/15)
169                                         .add( "value"   , value )
170                                         .add( "size"    , size2 )
171                                         .add( tagBuffer.makeTag() )
172                                         .makeTag( row,value );
173         }
174 }