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
018/**
019 * 検索結果を単純なリスト形式で表示するクラスです。
020 *
021 * このクラスでは、検索結果を単純なリストで表示します。
022 * 表示のみでこの表示フォーマットを利用してデータ編集を行うことはできません。
023 *
024 * 各カラムのデータは、カンマによって連結され、またヘッダー部分も出力されません。
025 * さらに各カラムの属性値に基づくclass属性等も一切出力されません。
026 *
027 * AbstractViewForm により、setter/getterメソッドのデフォルト実装を提供しています。
028 * 各HTMLのタグに必要な setter/getterメソッドのみ,追加定義しています。
029 *
030 * AbstractViewForm を継承している為,ロケールに応じたラベルを出力させる事が出来ます。
031 *
032 * @og.group 画面表示
033 *
034 * @version  4.0
035 * @author       Hiroki Nakamura
036 * @since    JDK5.0,
037 */
038public class ViewForm_HTMLSimpleList extends ViewForm_HTMLTable {
039        /** このプログラムのVERSION文字列を設定します。   {@value} */
040        private static final String VERSION = "7.0.1.0 (2018/10/15)" ;
041
042        // 警告時の行ごとに色を変更する時の、デフォルトクラス属性
043        private static final String BG_WARNING_COLOR = " class=\"row_warning\"";
044
045        // エラー時の行ごとに色を変更する時の、デフォルトクラス属性
046        private static final String BG_ERROR_COLOR = " class=\"row_error\"";
047
048        private String colorRow = "";
049
050        /**
051         * デフォルトコンストラクター
052         *
053         * @og.rev 6.4.2.0 (2016/01/29) PMD refactoring. Each class should declare at least one constructor.
054         */
055        public ViewForm_HTMLSimpleList() { super(); }           // これも、自動的に呼ばれるが、空のメソッドを作成すると警告されるので、明示的にしておきます。
056
057        /**
058         * DBTableModel から HTML文字列を作成して返します。
059         * startNo(表示開始位置)から、pageSize(表示件数)までのView文字列を作成します。
060         * 表示残りデータが pageSize 以下の場合は,残りのデータをすべて出力します。
061         *
062         * @og.rev 6.3.9.1 (2015/11/27) カラムが一つも表示されないケースは、考えないことにする。
063         * @og.rev 7.0.1.0 (2018/10/15) XHTML → HTML5 対応(空要素の、"/>" 止めを、">" に変更します)。
064         *
065         * @param  startNo        表示開始位置
066         * @param  pageSize   表示件数
067         *
068         * @return      DBTableModelから作成された HTML文字列
069         * @og.rtnNotNull
070         */
071        @Override
072        public String create( final int startNo, final int pageSize )  {
073                if( getRowCount() == 0 ) { return ""; }
074
075                final int lastNo = getLastNo( startNo, pageSize );
076
077                final StringBuilder out = new StringBuilder( BUFFER_LARGE );
078
079                final int clmCnt = getColumnCount();
080                for( int row=startNo; row<lastNo; row++ ) {
081                        if( isSkip( row ) || isSkipNoEdit( row ) ) { continue; }
082
083//                      if( row != startNo ) { out.append( "<br />" ); }
084                        if( row != startNo ) { out.append( "<br>" ); }                                                          // 7.0.1.0 (2018/10/15)
085
086                        out.append( "<span " ).append( getBgColorCycleClass(row) ).append( '>' );       // 6.0.2.5 (2014/10/31) char を append する。
087                        // 6.3.9.1 (2015/11/27) カラムが一つも表示されないケースは、考えないことにする。
088                        out.append( row+1 );
089                        for( int column=0; column<clmCnt; column++ ) {
090                                if( isColumnDisplay( column ) ) {
091                                        out.append( ',' ).append( getValueLabel(row,column) );                          // row+1 を append しているので、これでよい。
092                                }
093                        }
094                        out.append( "</span>" );
095                }
096
097                return out.toString();
098        }
099
100        /**
101         * テーブルのバックグラウンドカラーの入れ替えのサイクルをセットします。
102         * 0以上(通常)、-1(ワーニング)、-2以下(エラー)
103         * 初期値は、0以上(通常)です。
104         *
105         * @param  sycle  0以上(通常)、-1(ワーニング)、-2以下(エラー)
106         */
107        @Override
108        public void setBgColorCycle( final int sycle ) {
109                if( sycle == -1 ) {                                     // -1(ワーニング)
110                        colorRow                = BG_WARNING_COLOR ;
111                }
112                else if( sycle < -1 ) {                         // -2以下(エラー)
113                        colorRow                = BG_ERROR_COLOR ;
114                }
115        }
116
117        /**
118         * テーブルのバックグラウンドカラーの値をセットします。
119         *
120         * @param       row 行番号( 0から始める )
121         *
122         * @return      行の色を指定する class 属性( cssファイルで指定 )
123         */
124        @Override
125        protected String getBgColorCycleClass( final int row ) {
126                return colorRow ;
127        }
128
129        /**
130         * 表示項目の編集(並び替え)が可能かどうかを返します。
131         *
132         * @og.rev 5.1.6.0 (2010/05/01) 新規追加
133         *
134         * @return      表示項目の編集(並び替え)が可能かどうか(false:不可能)
135         */
136        @Override
137        public boolean isEditable() {
138                return false;
139        }
140
141}