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 = "8.2.0.2 (2022/06/24)" ; 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 * @og.rev 8.2.0.2 (2022/06/24) HTML5廃止対応 066 * 067 * @param startNo 表示開始位置 068 * @param pageSize 表示件数 069 * 070 * @return DBTableModelから作成された HTML文字列 071 * @og.rtnNotNull 072 */ 073 public String create( final int startNo, final int pageSize ) { 074 if( getRowCount() == 0 ) { return ""; } // 暫定処置 075 076 noSLabelSetting(); // 5.6.2.3 (2013/03/22) DBColumn に、useSLabel="false" の値をセットします。 077 078 final int numberOfColumns = getColumnDisplayCount() ; 079 // 6.3.9.1 (2015/11/27) Found 'DD'-anomaly for variable(PMD) 080 final String[] label = new String[numberOfColumns]; 081 final String[] value = new String[numberOfColumns]; 082 083 final int realCount = getColumnCount(); 084 int clmNo = 0; 085 for( int i=0; i<realCount; i++ ) { 086 if( isColumnDisplay(i) ) { 087 label[clmNo] = getColumnLabel(i); 088 value[clmNo] = getValueLabel(startNo,i); 089 clmNo++ ; 090 } 091 } 092 093 final int columnNumber = numberOfColumns / maxRowNumber + 1 ; 094 095 final StringBuilder out = new StringBuilder( BUFFER_LARGE ) 096 .append( getCountForm( startNo,pageSize ) ) 097 .append( makeSelectNo( startNo ) ).append( CR ) 098// .append("<table id=\"viewTextField\" border=\"0\" summary=\"ViewForm_HTMLTextField\" >"); // 3.6.0.5 (2004/10/18) 099 .append("<table id=\"viewTextField\" border=\"0\" >"); // 8.2.0.2 (2022/06/24) Modify 100 101 final int rowNumber = (numberOfColumns +1 )/ columnNumber ; 102 for( int row=0; row<rowNumber; row++ ) { 103 out.append("<tr>").append( CR ); 104 for( int clm=0; clm<columnNumber; clm++ ) { 105 final int realClm = row + clm * rowNumber ; 106 out.append("<td id=\"label\">"); 107 if( realClm < numberOfColumns ) { 108 out.append( label[realClm] ) 109 .append( CLM ); 110 } 111 out.append("</td>").append( CR ) 112 .append("<td>"); 113 if( realClm < numberOfColumns ) { out.append( value[realClm] ); } 114 out.append("</td>").append( CR ) 115// .append("<td width=\"").append( columnSpace ).append("\"> </td>").append( CR ); 116 .append("<td style=\"width:").append( columnSpace ).append(";\"> </td>").append( CR ); // 8.2.0.2 (2022/06/24) Modify 117 } 118 out.append("</tr>").append( CR ); 119 } 120 out.append("</table>"); 121 122 return out.toString(); 123 } 124 125 /** 126 * DBColumn に、useSLabel="false" の値をセットします。 127 * 128 * @og.rev 5.6.2.3 (2013/03/22) 新規追加 129 * 130 */ 131 protected void noSLabelSetting() { 132 final int realCount = getColumnCount(); 133 134 for( int clmNo=0; clmNo<realCount; clmNo++ ) { 135 final DBColumnConfig config = getDBColumn( clmNo ).getConfig(); 136 config.setUseSLabel( "false" ); 137 138 setDBColumn( clmNo, new DBColumn( config ) ); 139 } 140 } 141 142 /** 143 * 画面に選択された番号を表示します。 144 * また、書き込み許可がある場合は、選択用の隠しフィールドを作成します。 145 * 146 * @og.rev 3.5.5.5 (2004/04/23) hidden の出力に、XHTMLTag.hidden を使用します。 147 * @og.rev 6.4.4.1 (2016/03/18) StringBuilderの代わりに、OgBuilderを使用する。 148 * 149 * @param row 行番号 150 * 151 * @return 隠しフィールドのHTML文字列 152 * @og.rtnNotNull 153 */ 154 protected String makeSelectNo( final int row ) { 155 return new OgBuilder() 156 .appendIf( isWritable( row ) , String.valueOf( row ) 157 , rowKey -> XHTMLTag.hidden( HybsSystem.ROW_SEL_KEY,rowKey ) ) 158 .toString(); 159 } 160 161 /** 162 * 内容をクリア(初期化)します。 163 * 164 * @og.rev 3.1.1.0 (2003/03/28) 同期メソッド(synchronized付き)を非同期に変更する。 165 * 166 */ 167 @Override 168 public void clear() { 169 super.clear(); 170 columnSpace = HybsSystem.sys( "HTML_COLUMS_SPACE" ) ; // 項目間のスペース 171 maxRowNumber = HybsSystem.sysInt( "HTML_MAXROW_NUMBER" ) ; // 縦方向の最大表示件数 172 } 173 174 /** 175 * 表示件数を取得します。 176 * 177 * @return 表示件数 178 */ 179 @Override 180 public int getPageSize() { 181 return PAGE_SIZE; 182 } 183 184 /** 185 * フォーマットメソッドを使用できるかどうかを問い合わせます。 186 * 187 * @return 使用可能(true)/ 使用不可能(false) 188 */ 189 public boolean canUseFormat() { 190 return false; 191 } 192 193 /** 194 * カラムのラベル名(長)を返します。 195 * カラムの項目名に対して、見える形の文字列を返します。 196 * 一般には、リソースバンドルと組合せて、各国ロケール毎にラベルを 197 * 切替えます。 198 * 199 * @og.rev 4.0.0.0 (2005/01/31) 新規追加( longLabel を返します。) 200 * 201 * @param column カラム番号 202 * 203 * @return カラムのラベル名(長) 204 */ 205 @Override 206 protected String getColumnLabel( final int column ) { 207 return getDBColumn( column ).getLongLabel(); 208 } 209 210 /** 211 * 表示項目の編集(並び替え)が可能かどうかを返します。 212 * 213 * @og.rev 5.1.6.0 (2010/05/01) 新規追加 214 * 215 * @return 表示項目の編集(並び替え)が可能かどうか(false:不可能) 216 */ 217 @Override 218 public boolean isEditable() { 219 return false; 220 } 221}