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 */
016 package org.opengion.plugin.view;
017
018 import java.util.List;
019
020 import org.opengion.fukurou.util.StringUtil;
021 import org.opengion.hayabusa.common.HybsSystem;
022 import org.opengion.hayabusa.common.HybsSystemException;
023 import org.opengion.hayabusa.db.DBTableModel;
024 import org.opengion.hayabusa.html.TableFormatter;
025
026 /**
027 * ヘッãƒ??部åˆ??フォーマットに応じたテーブルをè?動作æ?する、フォーマットテーブル作æ?クラスですã?
028 *
029 * AbstractViewForm により、setter/getterメソãƒ?ƒ‰のãƒ?ƒ•ォルト実è£?‚’提供してã�?�¾すã?
030 * 各HTMLのタグにå¿?¦�な setter/getterメソãƒ?ƒ‰のみ?Œ追åŠ?®š義してã�?�¾すã?
031 * [XXXX]は、カラãƒ?‚’æŒ?®šしますã?ラベル?‹å?力フィールドをそれぞれtdで囲ã�?�¾すã?
032 * [#XXXX]は、対応するカラãƒ??ラベルをå?力しますã?
033 * [$XXXX]は、対応するカラãƒ??レンãƒ?ƒ©ーをå?力しますã?
034 * [!XXXX]は、対応するカラãƒ??値をå?力しますã?
035 * 特殊記号の解釈ã?、HTMLFormatTextField系とHTMLFormatTable系で異なりますã?で
036 * ご注意くã�?�•ã�??
037 *
038 * AbstractViewForm を継承してã�?‚‹為,ロケールに応じたラベルをå?力させる事が出来ますã?
039 *
040 * @og.group 画面表示
041 *
042 * @version 4.0
043 * @author Kazuhiko Hasegawa
044 * @since JDK5.0,
045 */
046 public class ViewForm_HTMLFormatTable extends ViewForm_HTMLTable {
047 //* こã?プログラãƒ??VERSIONæ–?—å?を設定しますã? {@value} */
048 private static final String VERSION = "5.1.6.0 (2010/05/01)" ;
049
050 // 3.5.4.0 (2003/11/25) TableFormatter クラス追åŠ?
051 private TableFormatter format = null;
052
053 // 4.3.4.4 (2009/01/01)
054 // /**
055 // * ãƒ?ƒ•ォルトコンストラクター
056 // *
057 // */
058 // public ViewForm_HTMLFormatTable() {
059 // super();
060 // }
061
062 /**
063 * DBTableModel から HTMLæ–?—å?を作æ?して返しますã?
064 * startNo(表示開始位置)から、pageSize(表示件数)までのViewæ–?—å?を作æ?しますã?
065 * 表示残りãƒ??タã�?pageSize 以下ã?場合ã?,残りのãƒ??タをすべて出力しますã?
066 *
067 * @og.rev 3.5.0.0 (2003/09/17) BODY要ç´?? noClass 属æ?を追åŠ??
068 * @og.rev 3.5.0.0 (2003/09/17) <tr>属æ?は、å?のフォーマットã?まま使用しますã?
069 * @og.rev 3.5.2.0 (2003/10/20) ヘッãƒ??繰り返し属æ?( headerSkipCount )を採用
070 * @og.rev 3.5.3.1 (2003/10/31) skip属æ?を採用。headerLine のキャãƒ?‚·ュクリア
071 * @og.rev 3.5.4.0 (2003/11/25) TableFormatter クラスを使用するように変更ã€?
072 * @og.rev 3.5.5.0 (2004/03/12) systemFormat(例:[KEY.カラãƒ?��]形式ç?の対å¿?
073 * @og.rev 3.5.5.0 (2004/03/12) No æ¬?��のもã?の作æ?判断ロジãƒ?‚¯を追åŠ?
074 * @og.rev 3.5.5.7 (2004/05/10) [#カラãƒ?��] , [$カラãƒ?��] に対å¿?
075 * @og.rev 3.5.6.0 (2004/06/18) '!' 値のみ 追åŠ?既存ã? '$' は、レンãƒ?ƒ©ー
076 * @og.rev 3.5.6.4 (2004/07/16) ヘッãƒ??とボディー部をJavaScriptでåˆ?›¢
077 * @og.rev 3.7.0.3 (2005/03/01) getBgColorCycleClass にã€?�¸択行ã?ーカーを採用
078 * @og.rev 4.0.0.0 (2005/01/31) 新規作æ?(getColumnClassName â‡?getColumnDbType)
079 * @og.rev 4.3.1.0 (2008/09/08) フォーマットが設定されてã�?�ªã�??合ã?エラー追åŠ??編é›?¡Œã?みを表示する属æ?(isSkipNoEdit)追åŠ?
080 * @og.rev 4.3.3.0 (2008/10/01) noTransition属æ?対å¿?
081 * @og.rev 4.3.7.4 (2009/07/01) tbodyタグの入れ子を解æ¶?FireFox対å¿?
082 *
083 * @param startNo 表示開始位置
084 * @param pageSize 表示件数
085 *
086 * @return DBTableModelから作æ?されã�?HTMLæ–?—å?
087 */
088 @Override
089 public String create( final int startNo, final int pageSize ) {
090 if( getRowCount() == 0 ) { return ""; } // 暫定å?置
091
092 // 4.3.1.0 (2008/09/08)
093 if( format == null ) {
094 String errMsg = "ViewTagで canUseFormat() = true の場合ã?Formatter はå¿??ですã?";
095 throw new HybsSystemException( errMsg );
096 }
097
098 headerLine = null; // 3.5.3.1 (2003/10/31) キャãƒ?‚·ュクリア
099 int lastNo = getLastNo( startNo, pageSize );
100 int blc = getBackLinkCount();
101 int hsc = getHeaderSkipCount(); // 3.5.2.0 (2003/10/20)
102 int hscCnt = 1; // 3.5.2.0 (2003/10/20)
103
104 StringBuilder out = new StringBuilder( HybsSystem.BUFFER_LARGE );
105
106 out.append( getCountForm( startNo,pageSize ) );
107 out.append( getHeader() );
108
109 String ckboxTD = " <td " + format.getRowspan() + ">";
110 // out.append("<tbody>").append( HybsSystem.CR ); // 4.3.7.4 (2009/07/01)
111 int bgClrCnt = 0;
112 for( int row=startNo; row<lastNo; row++ ) {
113 // if( isSkip( row ) ) { continue; } // 3.5.3.1 (2003/10/31)
114 if( isSkip( row ) || isSkipNoEdit( row ) ) { continue; } // 4.3.1.0 (2008/09/08)
115 if( ! format.isUse( row,getDBTableModel() ) ) { continue; } // 3.5.4.0 (2003/11/25)
116 out.append("<tbody").append( getBgColorCycleClass( bgClrCnt++,row ) );
117 if( isNoTransition() ) { // 4.3.3.0 (2008/10/01)
118 out.append( getHiddenRowValue( row ) );
119 }
120 out.append(">"); // 3.7.0.3 (2005/03/01)
121 out.append( format.getTrTag() );
122
123 // 3.5.5.0 (2004/03/12) No æ¬?��のもã?の作æ?判断追åŠ?
124 if( isNumberDisplay() ) {
125 out.append( makeCheckbox( ckboxTD,row,blc ) );
126 }
127
128 int cl = 0;
129 for( ; cl < format.getLocationSize(); cl++ ) {
130 String fmt = format.getFormat(cl); // 3.5.0.0
131 int loc = format.getLocation(cl); // 3.5.5.0
132 if( ! format.isNoClass() && loc >= 0 ) { // 3.5.5.7 (2004/05/10)
133 StringBuilder newtg = new StringBuilder( HybsSystem.BUFFER_LARGE );
134 newtg.append("<td class=\"");
135 newtg.append( getColumnDbType(loc) ); // 4.0.0 (2005/01/31)
136 newtg.append("\" ");
137 String tdclass = newtg.toString();
138 fmt = StringUtil.replace( format.getFormat(cl) ,"<td", tdclass );
139 }
140 out.append( fmt ); // 3.5.0.0
141 // 3.5.5.7 (2004/05/10) #,$ 対å¿?
142 if( loc >= 0 ) {
143 switch( format.getType(cl) ) {
144 case '#' : out.append( getColumnLabel(loc) ); break;
145 case '$' : out.append( getRendererValue(row,loc) ); break;
146 case '!' : out.append( getValue(row,loc) ); break;
147 default : out.append( getValueLabel(row,loc) ); break;
148 }
149 }
150 else {
151 out.append( format.getSystemFormat(row,loc) );
152 }
153 }
154 out.append( format.getFormat(cl) );
155 out.append("</tbody>").append( HybsSystem.CR );
156
157 // 3.5.2.0 (2003/10/20) ヘッãƒ??繰り返し属æ?( headerSkipCount )を採用
158 if( hsc > 0 && hscCnt % hsc == 0 ) {
159 out.append("<tbody class=\"row_h\"").append(" >");
160 out.append( getHeadLine() );
161 out.append("</tbody>");
162 hscCnt = 1;
163 }
164 else {
165 hscCnt ++ ;
166 }
167 }
168 // out.append("</tbody>").append( HybsSystem.CR ); // 4.3.7.9 (2009/06/29)
169 out.append("</table>").append( HybsSystem.CR );
170
171 out.append( getScrollBarEndDiv() ); // 3.8.0.3 (2005/07/15)
172 return out.toString();
173 }
174
175 /**
176 * å†?®¹をクリア(初期åŒ?しますã?
177 *
178 * @og.rev 3.1.1.0 (2003/03/28) 同期メソãƒ?ƒ‰(synchronized付き)を非同期に変更するã€?
179 * @og.rev 3.5.0.0 (2003/09/17) Noカラãƒ?�«、表示をå?て消せるよã�?�«、class 属æ?を追åŠ??
180 * @og.rev 3.5.4.0 (2003/11/25) TableFormatter クラスを使用するように変更ã€?
181 *
182 */
183 @Override
184 public void clear() {
185 super.clear();
186 format = null;
187 }
188
189 /**
190 * DBTableModel から ãƒ??ブルのタグæ–?—å?を作æ?して返しますã?
191 *
192 * @og.rev 3.2.4.0 (2003/06/12) makeFormat() する位置を移動ã?
193 * @og.rev 3.5.0.0 (2003/09/17) <tr>属æ?は、å?のフォーマットã?まま使用しますã?
194 * @og.rev 3.5.1.0 (2003/10/03) Noカラãƒ?�«、numberType 属æ?を追åŠ?
195 * @og.rev 3.5.2.0 (2003/10/20) ヘッãƒ??繰り返し部をgetHeadLine()へ移å‹?
196 * @og.rev 3.5.3.1 (2003/10/31) VERCHAR2 ã‚?VARCHAR2 に修正ã€?
197 * @og.rev 3.5.5.0 (2004/03/12) No æ¬?��のもã?の作æ?判断ロジãƒ?‚¯を追åŠ?
198 * @og.rev 3.5.6.5 (2004/08/09) thead に、id="header" を追åŠ?
199 * @og.rev 4.0.0.0 (2005/01/31) DBColumn の 属æ?(CLS_NM)から、DBTYPEに変更
200 *
201 * @return ãƒ??ブルのタグæ–?—å?
202 */
203 @Override
204 protected String getTableHead() {
205
206 StringBuilder buf = new StringBuilder( HybsSystem.BUFFER_MIDDLE );
207 // 3.5.5.0 (2004/03/12) No æ¬?��のもã?の作æ?判断追åŠ?
208 if( isNumberDisplay() ) {
209 buf.append("<colgroup class=\"X\" />");
210 buf.append("<colgroup class=\"BIT\" />");
211 buf.append("<colgroup class=\"S9\" />"); // 4.0.0 (2005/01/31)
212 buf.append(HybsSystem.CR);
213 }
214
215 // 3.5.2.0 (2003/10/20) ヘッãƒ??繰り返し部をgetHeadLine()へ移å‹?
216 buf.append("<thead id=\"header\">").append( HybsSystem.CR ); // 3.5.6.5 (2004/08/09)
217 buf.append( getHeadLine() );
218 buf.append("</thead>").append( HybsSystem.CR );
219
220 return buf.toString();
221 }
222
223 /**
224 * ヘッãƒ??繰り返し部をã?getTableHead()メソãƒ?ƒ‰からåˆ?›¢ã€?
225 *
226 * @og.rev 3.5.2.0 (2003/10/20) 新規作æ?
227 * @og.rev 3.5.4.0 (2003/11/25) TableFormatter クラスを使用するように変更ã€?
228 * @og.rev 3.5.4.3 (2004/01/05) useCheckControl 属æ?の機è?を追åŠ?
229 * @og.rev 3.5.4.6 (2004/01/30) numberType="none" 時ã?処ç�?‚’追åŠ?Noラベルをå?さなã�?
230 * @og.rev 3.5.4.7 (2004/02/06) ヘッãƒ??にソート機è?用のリンクを追åŠ?�—ますã?
231 * @og.rev 3.5.5.0 (2004/03/12) systemFormat(例:[KEY.カラãƒ?��]形式ç?の対å¿?
232 * @og.rev 3.5.5.0 (2004/03/12) No æ¬?��のもã?の作æ?判断ロジãƒ?‚¯を追åŠ?
233 * @og.rev 3.7.0.1 (2005/01/31) 全件チェãƒ?‚¯コントロール処ç�?¤‰更
234 *
235 * @return ãƒ??ブルのタグæ–?—å?
236 */
237 @Override
238 protected String getHeadLine() {
239 if( headerLine != null ) { return headerLine; } // キャãƒ?‚·ュを返すã€?
240
241 StringBuilder buf = new StringBuilder( HybsSystem.BUFFER_MIDDLE );
242
243 buf.append( format.getTrTag() ).append( HybsSystem.CR );
244
245 // 3.5.5.0 (2004/03/12) No æ¬?��のもã?の作æ?判断追åŠ?
246 if( isNumberDisplay() ) {
247 // 3.5.4.3 (2004/01/05) 追åŠ??
248 if( isUseCheckControl() && "checkbox".equals( getSelectedType() ) ) {
249 buf.append(" <th" ).append( format.getRowspan() ).append("></th>");
250 buf.append(" <th" ).append( format.getRowspan() );
251 buf.append(">").append( getAllCheckControl() ).append( "</th>");
252 buf.append(" <th" ).append( format.getRowspan() ).append(">"); // 3.5.4.6 (2004/01/30)
253 buf.append( getNumberHeader() ).append("</th>"); // 3.5.4.6 (2004/01/30)
254 }
255 else {
256 buf.append(" <th colspan=\"3\"");
257 buf.append( format.getRowspan() );
258 buf.append(">").append( getNumberHeader() ).append("</th>"); // 3.5.4.6 (2004/01/30)
259 }
260 }
261
262 int cl = 0;
263 for( ; cl < format.getLocationSize(); cl++ ) {
264 buf.append( StringUtil.replace( format.getFormat(cl) ,"td","th" ));
265 int loc = format.getLocation(cl);
266 if( loc >= 0 ) { buf.append( getSortedColumnLabel(loc) ); }
267 }
268 buf.append( StringUtil.replace( format.getFormat(cl) ,"td","th" ) ).append( HybsSystem.CR );
269
270 headerLine = buf.toString();
271 return headerLine;
272 }
273
274 /**
275 * フォーマットを設定しますã?
276 *
277 * @og.rev 3.5.4.0 (2003/11/25) 新規作æ?
278 * @param list TableFormatterのリスãƒ?
279 */
280 @Override
281 public void setFormatterList( final List<TableFormatter> list ) { // 4.3.3.6 (2008/11/15) Generics警告対å¿?
282 format = list.get(0); // 4.3.3.6 (2008/11/15) Generics警告対å¿?
283 format.makeFormat( getDBTableModel() );
284 }
285
286 /**
287 * フォーマットメソãƒ?ƒ‰を使用できるかどã�?�‹を問ã�?�ˆわせますã?
288 *
289 * @return 使用可能(true)/ 使用不可能 (false)
290 */
291 @Override
292 public boolean canUseFormat() {
293 return true;
294 }
295
296 /**
297 * ビューで表示したカラãƒ??ä¸?¦§をカンマ区åˆ?‚Šで返しますã?
298 *
299 * @og.rev 5.1.6.0 (2010/05/01) 新規追åŠ?
300 *
301 * @return ビューで表示したカラãƒ??ä¸?¦§
302 */
303 @Override
304 public String getViewClms() {
305 DBTableModel table = getDBTableModel();
306 StringBuilder buf = new StringBuilder( HybsSystem.BUFFER_MIDDLE );
307 for( int i=0; i<format.getLocationSize(); i++ ) {
308 if( buf.length() > 0 ) { buf.append( ',' ); }
309 buf.append( table.getColumnName( format.getLocation( i ) ) );
310 }
311 return buf.toString();
312 }
313 }