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.view;
017
018import org.opengion.hayabusa.common.HybsSystem;
019import org.opengion.hayabusa.common.HybsSystemException;
020import org.opengion.hayabusa.html.TableFormatter;
021
022import 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 */
044public 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}