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.db.DBTableModel;
020
021/**
022 * 各フィールド情報から、動的にカラムを作成する動的カラム一覧表示クラスです。
023 *
024 * AbstractViewForm により、setter/getterメソッドのデフォルト実装を提供しています。
025 * 各HTMLのタグに必要な setter/getterメソッドのみ,追加定義しています。
026 *
027 * AbstractViewForm を継承している為,ロケールに応じたラベルを出力させる事が出来ます。
028 *
029 * @og.group 画面表示
030 *
031 * @version  4.0
032 * @author   Kazuhiko Hasegawa
033 * @since    JDK5.0,
034 */
035public class ViewForm_HTMLDynamic extends ViewForm_HTMLTable  {
036        //* このプログラムのVERSION文字列を設定します。   {@value} */
037        private static final String VERSION = "5.1.6.0 (2010/05/01)" ;
038
039        /** カラムの値を返す場合の、カラムキー名称 {@value} */
040        public static final String COLUMN_RETURN_KEY = "COLUMN_RETURN";
041        private int rtnColumnNo = -1;   // column_return カラムの番号
042
043        /**
044         * 初期化します。
045         * ここでは、内部で使用されているキャッシュをクリアし、
046         * 新しいモデル(DBTableModel)と言語(lang) を元に内部データを再構築します。
047         * ただし、設定情報は、以前の状態がそのままキープされています。
048         *
049         * @og.rev 3.1.1.0 (2003/03/28) 同期メソッド(synchronized付き)を非同期に変更する。
050         * @og.rev 3.5.6.1 (2004/06/25) lang 言語コード 属性を削除します。
051         *
052         * @param       table   DBTableModelオブジェクト
053         */
054        @Override
055        public void init( final DBTableModel table ) {
056                super.init( table );
057                int clmCnt = getColumnCount();
058                for( int i=0; i<clmCnt; i++ ) {
059                        if( COLUMN_RETURN_KEY.equalsIgnoreCase( getColumnName(i) )) {
060                                rtnColumnNo = i;
061                                break;
062                        }
063                }
064        }
065
066        /**
067         * DBTableModel から HTML文字列を作成して返します。
068         * startNo(表示開始位置)から、pageSize(表示件数)までのView文字列を作成します。
069         * 表示残りデータが pageSize 以下の場合は,残りのデータをすべて出力します。
070         *
071         * @og.rev 3.5.4.0 (2003/11/25) getBgColorCycleClass の返す文字列を変更する。
072         * @og.rev 3.5.6.4 (2004/07/16) ヘッダーとボディー部をJavaScriptで分離
073         *
074         * @param  startNo    表示開始位置
075         * @param  pageSize   表示件数
076         *
077         * @return  DBTableModelから作成された HTML文字列
078         */
079        @Override
080        public String create( final int startNo, final int pageSize )  {
081                if( getRowCount() == 0 ) { return ""; } // 暫定処置
082
083                int lastNo = getLastNo( startNo, pageSize );
084
085                StringBuilder out = new StringBuilder( HybsSystem.BUFFER_LARGE );
086
087                out.append( getCountForm( startNo,pageSize ) );
088                out.append( getHeader() );
089
090                int rowIndex = 0;
091                out.append("<tbody>").append( HybsSystem.CR );
092                out.append("<tr").append( getBgColorCycleClass( rowIndex++ ) ).append(">");
093                int clmCnt = getColumnCount();  // 3.5.5.7 (2004/05/10)
094                for( int row=startNo; row<lastNo; row++ ) {
095                        for(int column = 0; column < clmCnt; column++) {
096                                if( isColumnReturn( row,column ) ) {
097                                        out.append("</tr>");
098                                        out.append("<tr").append( getBgColorCycleClass( rowIndex++ ) ).append(">");
099                                }
100                                else if( isColumnDisplay( column ) ) {
101                                        out.append("  <td>");
102                                        out.append( getValueLabel(row,column) );
103                                        out.append("</td>").append( HybsSystem.CR );
104                                }
105                        }
106                }
107                out.append("</tr>").append( HybsSystem.CR );
108                out.append("</tbody>").append( HybsSystem.CR );
109                out.append("</table>").append( HybsSystem.CR );
110
111                out.append( getScrollBarEndDiv() );     // 3.8.0.3 (2005/07/15)
112                return out.toString();
113        }
114
115        /**
116         * DBTableModel から テーブルのタグ文字列を作成して返します。
117         *
118         * @return  テーブルのタグ文字列
119         */
120        @Override
121        protected String getTableHead() {
122                // ヘッダーは,不要です。
123                return "";
124        }
125
126        /**
127         * カラムが表示可能かどうかを返します。
128         * もし,表示不可の場合は,このカラムの全データが,表示対象から外されます。
129         *
130         * @param   row         行番号
131         * @param   column      カラム番号
132         *
133         * @return  表示可能(true)/不可能(false)
134         */
135        private boolean isColumnReturn( final int row,final int column ) {
136                boolean rtnFlag = false;
137
138                if( rtnColumnNo == column &&
139                        "1".equals( getValue( row,column ) ) ) {
140                                rtnFlag = true;
141                }
142
143                return rtnFlag;
144        }
145
146        /**
147         * 表示項目の編集(並び替え)が可能かどうかを返します
148         *
149         * @og.rev 5.1.6.0 (2010/05/01) 新規追加
150         *
151         * @return      表示項目の編集(並び替え)が可能かどうか(false:不可能)
152         */
153        @Override
154        public boolean isEditable() {
155                return false;
156        }
157}