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.fukurou.system.OgBuilder ; // 6.4.4.1 (2016/03/18) 019import org.opengion.fukurou.util.XHTMLTag; 020import org.opengion.hayabusa.common.HybsSystem; 021import org.opengion.hayabusa.html.AbstractViewForm; 022import org.opengion.hayabusa.db.DBColumn; 023import org.opengion.hayabusa.db.DBColumnConfig; 024 025/** 026 * 検索結果から、テキストフィールドタグを自動生成する、テキストフィールド作成クラスです。 027 * 028 * AbstractViewForm により、setter/getterメソッドのデフォルト実装を提供しています。 029 * 各HTMLのタグに必要な setter/getterメソッドのみ,追加定義しています。 030 * 031 * AbstractViewForm を継承している為,ロケールに応じたラベルを出力させる事が出来ます。 032 * 033 * @og.group 画面表示 034 * 035 * @version 4.0 036 * @author Kazuhiko Hasegawa 037 * @since JDK5.0, 038 */ 039public class ViewForm_HTMLTextField extends AbstractViewForm { 040 /** このプログラムのVERSION文字列を設定します。 {@value} */ 041 private static final String VERSION = "6.4.4.1 (2016/03/18)" ; 042 043 // 4.0.0 (2005/01/31) HTML_LABEL_SEPARATOR を boolean 変数として取得します。 044 private final String CLM = HybsSystem.sysBool( "HTML_LABEL_SEPARATOR" ) ? ":" : "" ; 045 046 private String columnSpace = HybsSystem.sys( "HTML_COLUMS_SPACE" ) ; // 項目間のスペース 047 private int maxRowNumber = HybsSystem.sysInt( "HTML_MAXROW_NUMBER" ) ; // 縦方向の最大表示件数 048 private static final int PAGE_SIZE = 1; 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_HTMLTextField() { super(); } // これも、自動的に呼ばれるが、空のメソッドを作成すると警告されるので、明示的にしておきます。 056 057 /** 058 * DBTableModel から HTML文字列を作成して返します。 059 * startNo(表示開始位置)から、pageSize(表示件数)までのView文字列を作成します。 060 * 表示残りデータが pageSize 以下の場合は,残りのデータをすべて出力します。 061 * 062 * @og.rev 2.0.1.0 (2002/10/10) ラベルとフィールドのセパレーターとして、コロン(:)を使用するかどうかを指定できる 063 * @og.rev 3.6.0.5 (2004/10/18) 印刷時の罫線出力関連機能の追加。id 属性を出力します。 064 * @og.rev 5.6.2.3 (2013/03/22) DBColumn に、useSLabel="false" の値をセットします。 065 * 066 * @param startNo 表示開始位置 067 * @param pageSize 表示件数 068 * 069 * @return DBTableModelから作成された HTML文字列 070 * @og.rtnNotNull 071 */ 072 public String create( final int startNo, final int pageSize ) { 073 if( getRowCount() == 0 ) { return ""; } // 暫定処置 074 075 noSLabelSetting(); // 5.6.2.3 (2013/03/22) DBColumn に、useSLabel="false" の値をセットします。 076 077 final int numberOfColumns = getColumnDisplayCount() ; 078 // 6.3.9.1 (2015/11/27) Found 'DD'-anomaly for variable(PMD) 079 final String[] label = new String[numberOfColumns]; 080 final String[] value = new String[numberOfColumns]; 081 082 final int realCount = getColumnCount(); 083 int clmNo = 0; 084 for( int i=0; i<realCount; i++ ) { 085 if( isColumnDisplay(i) ) { 086 label[clmNo] = getColumnLabel(i); 087 value[clmNo] = getValueLabel(startNo,i); 088 clmNo++ ; 089 } 090 } 091 092 final int columnNumber = numberOfColumns / maxRowNumber + 1 ; 093 094 final StringBuilder out = new StringBuilder( BUFFER_LARGE ) 095 .append( getCountForm( startNo,pageSize ) ) 096 .append( makeSelectNo( startNo ) ).append( CR ) 097 .append("<table id=\"viewTextField\" border=\"0\" summary=\"ViewForm_HTMLTextField\" >"); // 3.6.0.5 (2004/10/18) 098 099 final int rowNumber = (numberOfColumns +1 )/ columnNumber ; 100 for( int row=0; row<rowNumber; row++ ) { 101 out.append("<tr>").append( CR ); 102 for( int clm=0; clm<columnNumber; clm++ ) { 103 final int realClm = row + clm * rowNumber ; 104 out.append("<td id=\"label\">"); 105 if( realClm < numberOfColumns ) { 106 out.append( label[realClm] ) 107 .append( CLM ); 108 } 109 out.append("</td>").append( CR ) 110 .append("<td>"); 111 if( realClm < numberOfColumns ) { out.append( value[realClm] ); } 112 out.append("</td>").append( CR ) 113 .append("<td width=\"").append( columnSpace ).append("\"> </td>").append( CR ); 114 } 115 out.append("</tr>").append( CR ); 116 } 117 out.append("</table>"); 118 119 return out.toString(); 120 } 121 122 /** 123 * DBColumn に、useSLabel="false" の値をセットします。 124 * 125 * @og.rev 5.6.2.3 (2013/03/22) 新規追加 126 * 127 */ 128 protected void noSLabelSetting() { 129 final int realCount = getColumnCount(); 130 131 for( int clmNo=0; clmNo<realCount; clmNo++ ) { 132 final DBColumnConfig config = getDBColumn( clmNo ).getConfig(); 133 config.setUseSLabel( "false" ); 134 135 setDBColumn( clmNo, new DBColumn( config ) ); 136 } 137 } 138 139 /** 140 * 画面に選択された番号を表示します。 141 * また、書き込み許可がある場合は、選択用の隠しフィールドを作成します。 142 * 143 * @og.rev 3.5.5.5 (2004/04/23) hidden の出力に、XHTMLTag.hidden を使用します。 144 * @og.rev 6.4.4.1 (2016/03/18) StringBuilderの代わりに、OgBuilderを使用する。 145 * 146 * @param row 行番号 147 * 148 * @return 隠しフィールドのHTML文字列 149 * @og.rtnNotNull 150 */ 151 protected String makeSelectNo( final int row ) { 152 return new OgBuilder() 153 .appendIf( isWritable( row ) , String.valueOf( row ) 154 , rowKey -> XHTMLTag.hidden( HybsSystem.ROW_SEL_KEY,rowKey ) ) 155 .toString(); 156 } 157 158 /** 159 * 内容をクリア(初期化)します。 160 * 161 * @og.rev 3.1.1.0 (2003/03/28) 同期メソッド(synchronized付き)を非同期に変更する。 162 * 163 */ 164 @Override 165 public void clear() { 166 super.clear(); 167 columnSpace = HybsSystem.sys( "HTML_COLUMS_SPACE" ) ; // 項目間のスペース 168 maxRowNumber = HybsSystem.sysInt( "HTML_MAXROW_NUMBER" ) ; // 縦方向の最大表示件数 169 } 170 171 /** 172 * 表示件数を取得します。 173 * 174 * @return 表示件数 175 */ 176 @Override 177 public int getPageSize() { 178 return PAGE_SIZE; 179 } 180 181 /** 182 * フォーマットメソッドを使用できるかどうかを問い合わせます。 183 * 184 * @return 使用可能(true)/ 使用不可能(false) 185 */ 186 public boolean canUseFormat() { 187 return false; 188 } 189 190 /** 191 * カラムのラベル名(長)を返します。 192 * カラムの項目名に対して,見える形の文字列を返します。 193 * 一般には,リソースバンドルと組合せて,各国ロケール毎にラベルを 194 * 切替えます。 195 * 196 * @og.rev 4.0.0.0 (2005/01/31) 新規追加( longLabel を返します。) 197 * 198 * @param column カラム番号 199 * 200 * @return カラムのラベル名(長) 201 */ 202 @Override 203 protected String getColumnLabel( final int column ) { 204 return getDBColumn( column ).getLongLabel(); 205 } 206 207 /** 208 * 表示項目の編集(並び替え)が可能かどうかを返します。 209 * 210 * @og.rev 5.1.6.0 (2010/05/01) 新規追加 211 * 212 * @return 表示項目の編集(並び替え)が可能かどうか(false:不可能) 213 */ 214 @Override 215 public boolean isEditable() { 216 return false; 217 } 218}