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 = "6.4.2.0 (2016/01/29)" ; 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 * 064 * @param startNo 表示開始位置 065 * @param pageSize 表示件数 066 * 067 * @return DBTableModelから作成された HTML文字列 068 * @og.rtnNotNull 069 */ 070 @Override 071 public String create( final int startNo, final int pageSize ) { 072 if( getRowCount() == 0 ) { return ""; } 073 074 final int lastNo = getLastNo( startNo, pageSize ); 075 076 final StringBuilder out = new StringBuilder( BUFFER_LARGE ); 077 078 final int clmCnt = getColumnCount(); 079 for( int row=startNo; row<lastNo; row++ ) { 080 if( isSkip( row ) || isSkipNoEdit( row ) ) { continue; } 081 082 if( row != startNo ) { out.append( "<br />" ); } 083 084 out.append( "<span " ).append( getBgColorCycleClass(row) ).append( '>' ); // 6.0.2.5 (2014/10/31) char を append する。 085 // 6.3.9.1 (2015/11/27) カラムが一つも表示されないケースは、考えないことにする。 086 out.append( row+1 ); 087 for( int column=0; column<clmCnt; column++ ) { 088 if( isColumnDisplay( column ) ) { 089 out.append( ',' ).append( getValueLabel(row,column) ); // row+1 を append しているので、これでよい。 090 } 091 } 092 out.append( "</span>" ); 093 } 094 095 return out.toString(); 096 } 097 098 /** 099 * テーブルのバックグラウンドカラーの入れ替えのサイクルをセットします。 100 * 0以上(通常)、-1(ワーニング)、-2以下(エラー) 101 * 初期値は、0以上(通常)です。 102 * 103 * @param sycle 0以上(通常)、-1(ワーニング)、-2以下(エラー) 104 */ 105 @Override 106 public void setBgColorCycle( final int sycle ) { 107 if( sycle == -1 ) { // -1(ワーニング) 108 colorRow = BG_WARNING_COLOR ; 109 } 110 else if( sycle < -1 ) { // -2以下(エラー) 111 colorRow = BG_ERROR_COLOR ; 112 } 113 } 114 115 /** 116 * テーブルのバックグラウンドカラーの値をセットします。 117 * 118 * @param row 行番号( 0から始める ) 119 * 120 * @return 行の色を指定する class 属性( cssファイルで指定 ) 121 */ 122 @Override 123 protected String getBgColorCycleClass( final int row ) { 124 return colorRow ; 125 } 126 127 /** 128 * 表示項目の編集(並び替え)が可能かどうかを返します。 129 * 130 * @og.rev 5.1.6.0 (2010/05/01) 新規追加 131 * 132 * @return 表示項目の編集(並び替え)が可能かどうか(false:不可能) 133 */ 134 @Override 135 public boolean isEditable() { 136 return false; 137 } 138 139}