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.view;
017    
018    import org.opengion.hayabusa.common.HybsSystem;
019    import org.opengion.hayabusa.common.HybsSystemException;
020    import org.opengion.hayabusa.html.TableFormatter;
021    
022    import java.util.List;
023    
024    /**
025     * フォーマットを外部から?して作?する自由レイアウト?、テキストフィールド表示クラスです?
026     *
027     * AbstractViewForm により、setter/getterメソ?の?ォルト実?提供して?す?
028     * 各HTMLのタグに?な setter/getterメソ?のみ?追?義して?す?
029     * [XXXX]は、カラ??します?ラベル??力フィールドをそれぞれtdで囲?す?
030     * [#XXXX]は、テーブルタグのtdを使用せず、ラベルと入力フィールドを出力します?
031     * [$XXXX]は、ラベルもtdも?さずに、?力フィールド?み出力します?
032     * [!XXXX]は、?のみ出力します?
033     * 特殊記号の解釈?、HTMLFormatTextField系とHTMLFormatTable系で異なります?で
034     * ご注意く???
035     *
036     * AbstractViewForm を継承して?為,ロケールに応じたラベルを?力させる事が出来ます?
037     *
038     * @og.group 画面表示
039     *
040     * @version  4.0
041     * @author   Kazuhiko Hasegawa
042     * @since    JDK5.0,
043     */
044    public class ViewForm_HTMLFormatTextField extends ViewForm_HTMLTextField {
045            //* こ?プログラ??VERSION??を設定します?       {@value} */
046            private static final String VERSION = "5.6.2.3 (2013/03/22)" ;
047    
048            // 4.0.0 (2005/01/31) HTML_LABEL_SEPARATOR ?boolean 変数として取得します?
049            private final String CLM = ( HybsSystem.sysBool( "HTML_LABEL_SEPARATOR" ) ) ? ":" : "" ;
050    
051            // 3.5.4.0 (2003/11/25) TableFormatter クラス追?
052            private TableFormatter format = null;
053    
054            // 4.3.4.4 (2009/01/01)
055    //      /**
056    //       * ?ォルトコンストラクター
057    //       *
058    //       */
059    //      public ViewForm_HTMLFormatTextField() {
060    //              super();
061    //      }
062    
063            /**
064             * フォーマットを設定します?
065             *
066             * @og.rev 3.5.4.0 (2003/11/25) 新規作?
067             * @param       list    TableFormatterのリス?
068             */
069            @Override
070            public void setFormatterList( final List<TableFormatter> list ) {         // 4.3.3.6 (2008/11/15) Generics警告対?
071                    format = list.get(0);           // 4.3.3.6 (2008/11/15) Generics警告対?
072                    format.makeFormat( getDBTableModel() );
073            }
074    
075            /**
076             * DBTableModel から HTML??を作?して返します?
077             * startNo(表示開始位置)から、pageSize(表示件数)までのView??を作?します?
078             * 表示残り??タ?pageSize 以下?場合?,残りの??タをすべて出力します?
079             *
080             * @og.rev 2.0.1.0 (2002/10/10) ラベル?、フィールドだけを取り出すフォーマットを追?
081             * @og.rev 2.0.1.0 (2002/10/10) ラベルとフィールド?セパレーターとして、コロン(??を使用するかど?を指定できる
082             * @og.rev 3.2.4.0 (2003/06/12) makeFormat() する位置を移動?
083             * @og.rev 3.5.4.0 (2003/11/25) TableFormatter クラスを使用するように変更?
084             * @og.rev 3.5.5.0 (2004/03/12) systemFormat(例:[KEY.カラ?]形式?の対?
085             * @og.rev 5.0.0.2 (2009/09/15) フォーマットが設定されて???合?エラー追?
086             * @og.rev 5.6.2.3 (2013/03/22) DBColumn に、useSLabel="false" の値をセ?します?
087             *
088             * @param  startNo    表示開始位置
089             * @param  pageSize   表示件数
090             *
091             * @return  DBTableModelから作?され?HTML??
092             */
093            @Override
094            public String create( final int startNo, final int pageSize )  {
095                    if( getRowCount() == 0 ) { return ""; } // 暫定?置
096    
097                    noSLabelSetting();              // 5.6.2.3 (2013/03/22) DBColumn に、useSLabel="false" の値をセ?します?
098    
099                    // 4.3.1.0 (2008/09/08)
100                    if( format == null ) {
101                            String errMsg = "ViewTagで canUseFormat() = true の場合?Formatter は??です?";
102                            throw new HybsSystemException( errMsg );
103                    }
104    
105                    StringBuilder out = new StringBuilder( HybsSystem.BUFFER_LARGE );
106                    out.append( getCountForm( startNo,pageSize ) );
107                    out.append( makeSelectNo( startNo ) ).append( HybsSystem.CR );
108    
109                    out.append( format.getTrTag() );
110                    int cl = 0;
111                    for( ; cl < format.getLocationSize(); cl++ ) {
112                            out.append( format.getFormat(cl) );
113                            int loc = format.getLocation(cl);
114                            if( loc < 0 ) {
115                                    out.append(  format.getSystemFormat(startNo,loc) ); // 5.0.0.2 (2009/09/15)
116                                    continue ;
117                            }
118    
119                            char type = format.getType(cl);
120                            if( type == '#' ) {
121                                    out.append("<span id=\"label\">");
122                                    out.append( getColumnLabel(loc) );
123                                    out.append( CLM );
124                                    out.append("</span>");
125                            }
126                            else if( type == '$' ) {
127                                    out.append( getValueLabel(startNo,loc) );
128                            }
129                            else if( type == '!' ) {
130                                    out.append( getValue(startNo,loc) );
131                            }
132                            else {
133                                    out.append("<td id=\"label\">");
134                                    out.append( getColumnLabel(loc) );
135                                    out.append( CLM );
136                                    out.append("</td>");
137                                    out.append("<td>");
138                                    out.append( getValueLabel(startNo,loc) );
139                                    out.append("</td>");
140                            }
141                    }
142                    out.append( format.getFormat(cl) );
143    
144                    return out.toString();
145            }
146    
147            /**
148             * ?をクリア(初期?します?
149             *
150             * @og.rev 2.0.1.0 (2002/10/10) ラベル?、フィールドだけを取り出すフォーマットを追?
151             * @og.rev 3.1.1.0 (2003/03/28) 同期メソ?(synchronized付き)を非同期に変更する?
152             * @og.rev 3.5.4.0 (2003/11/25) TableFormatter クラスを使用するように変更?
153             *
154             */
155            @Override
156            public void clear() {
157                    super.clear();
158                    format          = null;
159            }
160    
161            /**
162             * フォーマットメソ?を使用できるかど?を問?わせます?
163             *
164             * @return  使用可能(true)/ 使用不可能 (false)
165             */
166            @Override
167            public boolean canUseFormat() {
168                    return true;
169            }
170    
171            /**
172             * 表示?の編?並び替?が可能かど?を返しま?
173             *
174             * @og.rev 5.1.6.0 (2010/05/01) 新規追?
175             *
176             * @return      表示?の編?並び替?が可能かど?(false:不可能)
177             */
178            @Override
179            public boolean isEditable() {
180                    return false;
181            }
182    }