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.common.HybsSystemException; 020import org.opengion.hayabusa.html.TableFormatter; 021 022import java.util.List; 023 024/** 025 * フォーマットを外部から指定して作成する自由レイアウトの、テキストフィールド表示クラスです。 026 * 027 * AbstractViewForm により、setter/getterメソッドのデフォルト実装を提供しています。 028 * 各HTMLのタグに必要な setter/getterメソッドのみ,追加定義しています。 029 * [XXXX]は、カラムを指定します。ラベル+入力フィールドをそれぞれtdで囲います。 030 * [#XXXX]は、テーブルタグのtdを使用せず、ラベルと入力フィールドを出力します。 031 * [$XXXX]は、ラベルもtdも出さずに、入力フィールドのみ出力します。 032 * [!XXXX]は、値のみ出力します。 033 * 特殊記号の解釈は、HTMLFormatTextField系とHTMLFormatTable系で異なりますので 034 * ご注意ください。 035 * 036 * AbstractViewForm を継承している為,ロケールに応じたラベルを出力させる事が出来ます。 037 * 038 * @og.group 画面表示 039 * 040 * @version 4.0 041 * @author Kazuhiko Hasegawa 042 * @since JDK5.0, 043 */ 044public class ViewForm_HTMLFormatTextField extends ViewForm_HTMLTextField { 045 //* このプログラムのVERSION文字列を設定します。 {@value} */ 046 private static final String VERSION = "5.6.2.3 (2013/03/22)" ; 047 048 // 4.0.0 (2005/01/31) HTML_LABEL_SEPARATOR を boolean 変数として取得します。 049 private final String CLM = HybsSystem.sysBool( "HTML_LABEL_SEPARATOR" ) ? ":" : "" ; 050 051 // 3.5.4.0 (2003/11/25) TableFormatter クラス追加 052 private TableFormatter format = null; 053 054 /** 055 * フォーマットを設定します。 056 * 057 * @og.rev 3.5.4.0 (2003/11/25) 新規作成 058 * @param list TableFormatterのリスト 059 */ 060 @Override 061 public void setFormatterList( final List<TableFormatter> list ) { // 4.3.3.6 (2008/11/15) Generics警告対応 062 format = list.get(0); // 4.3.3.6 (2008/11/15) Generics警告対応 063 format.makeFormat( getDBTableModel() ); 064 } 065 066 /** 067 * DBTableModel から HTML文字列を作成して返します。 068 * startNo(表示開始位置)から、pageSize(表示件数)までのView文字列を作成します。 069 * 表示残りデータが pageSize 以下の場合は,残りのデータをすべて出力します。 070 * 071 * @og.rev 2.0.1.0 (2002/10/10) ラベルだけ、フィールドだけを取り出すフォーマットを追加 072 * @og.rev 2.0.1.0 (2002/10/10) ラベルとフィールドのセパレーターとして、コロン(:)を使用するかどうかを指定できる 073 * @og.rev 3.2.4.0 (2003/06/12) makeFormat() する位置を移動。 074 * @og.rev 3.5.4.0 (2003/11/25) TableFormatter クラスを使用するように変更。 075 * @og.rev 3.5.5.0 (2004/03/12) systemFormat(例:[KEY.カラム名]形式等)の対応 076 * @og.rev 5.0.0.2 (2009/09/15) フォーマットが設定されていない場合のエラー追加 077 * @og.rev 5.6.2.3 (2013/03/22) DBColumn に、useSLabel="false" の値をセットします。 078 * 079 * @param startNo 表示開始位置 080 * @param pageSize 表示件数 081 * 082 * @return DBTableModelから作成された HTML文字列 083 */ 084 @Override 085 public String create( final int startNo, final int pageSize ) { 086 if( getRowCount() == 0 ) { return ""; } // 暫定処置 087 088 noSLabelSetting(); // 5.6.2.3 (2013/03/22) DBColumn に、useSLabel="false" の値をセットします。 089 090 // 4.3.1.0 (2008/09/08) 091 if( format == null ) { 092 String errMsg = "ViewTagで canUseFormat() = true の場合、Formatter は必須です。"; 093 throw new HybsSystemException( errMsg ); 094 } 095 096 StringBuilder out = new StringBuilder( HybsSystem.BUFFER_LARGE ); 097 out.append( getCountForm( startNo,pageSize ) ); 098 out.append( makeSelectNo( startNo ) ).append( HybsSystem.CR ); 099 100 out.append( format.getTrTag() ); 101 int cl = 0; 102 for( ; cl < format.getLocationSize(); cl++ ) { 103 out.append( format.getFormat(cl) ); 104 int loc = format.getLocation(cl); 105 if( loc < 0 ) { 106 out.append( format.getSystemFormat(startNo,loc) ); // 5.0.0.2 (2009/09/15) 107 continue ; 108 } 109 110 char type = format.getType(cl); 111 if( type == '#' ) { 112 out.append("<span id=\"label\">"); 113 out.append( getColumnLabel(loc) ); 114 out.append( CLM ); 115 out.append("</span>"); 116 } 117 else if( type == '$' ) { 118 out.append( getValueLabel(startNo,loc) ); 119 } 120 else if( type == '!' ) { 121 out.append( getValue(startNo,loc) ); 122 } 123 else { 124 out.append("<td id=\"label\">"); 125 out.append( getColumnLabel(loc) ); 126 out.append( CLM ); 127 out.append("</td>"); 128 out.append("<td>"); 129 out.append( getValueLabel(startNo,loc) ); 130 out.append("</td>"); 131 } 132 } 133 out.append( format.getFormat(cl) ); 134 135 return out.toString(); 136 } 137 138 /** 139 * 内容をクリア(初期化)します。 140 * 141 * @og.rev 2.0.1.0 (2002/10/10) ラベルだけ、フィールドだけを取り出すフォーマットを追加 142 * @og.rev 3.1.1.0 (2003/03/28) 同期メソッド(synchronized付き)を非同期に変更する。 143 * @og.rev 3.5.4.0 (2003/11/25) TableFormatter クラスを使用するように変更。 144 * 145 */ 146 @Override 147 public void clear() { 148 super.clear(); 149 format = null; 150 } 151 152 /** 153 * フォーマットメソッドを使用できるかどうかを問い合わせます。 154 * 155 * @return 使用可能(true)/ 使用不可能 (false) 156 */ 157 @Override 158 public boolean canUseFormat() { 159 return true; 160 } 161 162 /** 163 * 表示項目の編集(並び替え)が可能かどうかを返します 164 * 165 * @og.rev 5.1.6.0 (2010/05/01) 新規追加 166 * 167 * @return 表示項目の編集(並び替え)が可能かどうか(false:不可能) 168 */ 169 @Override 170 public boolean isEditable() { 171 return false; 172 } 173}