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 * JavaScript のツリー階層を持ったテーブル表示を行う、ツリーテーブル表示クラスです。 020 * 021 * AbstractViewForm により、setter/getterメソッドのデフォルト実装を提供しています。 022 * 各HTMLのタグに必要な setter/getterメソッドのみ,追加定義しています。 023 * 024 * AbstractViewForm を継承している為,ロケールに応じたラベルを出力させる事が出来ます。 025 * 026 * @og.rev 8.2.0.2 (2022/06/24) HTML5廃止対応 027 * @og.group 画面表示 028 * 029 * @version 4.0 030 * @author Kazuhiko Hasegawa 031 * @since JDK5.0, 032 */ 033public class ViewForm_HTMLTreeBOM extends ViewForm_HTMLTable { 034 /** このプログラムのVERSION文字列を設定します。 {@value} */ 035 private static final String VERSION = "6.4.5.0 (2016/04/08)" ; 036 037 /** カラムレベルのキー {@value} */ 038 public static final String COLUMN_LEVEL_KEY = "COLUMN_LEVEL"; 039 040 // 6.4.4.1 (2016/03/18) static final 定数化にします。 041 private static final String FUTTER = "initializeDocument()" + CR + "//-->" + CR + "</script>" + CR + "</table>" + CR ; 042 043 // 6.4.4.1 (2016/03/18) static final 定数化にします。 044 // 8.1.0.0 (2021/12/28) HTML5 準拠に見直し(<script> type属性削除) 045// private static final String HEADER = "<table id=\"viewTable\" border=\"0\" cellspacing=\"2\" cellpadding=\"0\" summary=\"bomTable\">" 046 private static final String HEADER = "<table id=\"viewTable\" border=\"0\" cellpadding=\"0\" style=\"border-spacing:2px;\" >" // 8.2.0.2 (2022/06/24) Modify 047// + CR + "<script type=\"text/javascript\">" + CR + "<!--" + CR + "aux0 = gFld('" ; 048 + CR + "<script>" + CR + "<!--" + CR + "aux0 = gFld('" ; 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_HTMLTreeBOM() { super(); } // これも、自動的に呼ばれるが、空のメソッドを作成すると警告されるので、明示的にしておきます。 056 057 /** 058 * DBTableModel から HTML文字列を作成して返します。 059 * startNo(表示開始位置)から、pageSize(表示件数)までのView文字列を作成します。 060 * 表示残りデータが pageSize 以下の場合は,残りのデータをすべて出力します。 061 * 062 * @og.rev 3.5.2.1 (2003/10/27) JavaScript 内のダブルコーテーションをシングルコーテーションに変更する。 063 * @og.rev 3.9.0.1 (2007/12/18) DBクラスを出力する。 064 * @og.rev 6.4.4.1 (2016/03/18) FUTTER を、static final 定数化にします。 065 * @og.rev 6.4.5.0 (2016/04/08) メソッド変更( getColumnDbType(int) → getClassName(int) ) 066 * 067 * @param stNo 表示開始位置 068 * @param pgSize 表示件数 069 * 070 * @return DBTableModelから作成された HTML文字列 071 * @og.rtnNotNull 072 */ 073 @Override 074 public String create( final int stNo, final int pgSize ) { 075 // このクラスでは、テーブル全データを使用します。 076 if( getRowCount() == 0 ) { return ""; } // 暫定処置 077 078 final int startNo = 0; 079 final int pageSize = getRowCount(); 080 081 final int lastNo = getLastNo( startNo, pageSize ); 082 083 final StringBuilder out = new StringBuilder( BUFFER_LARGE ).append( getHeader() ); 084 085 int level; 086 final int clmCnt = getColumnCount(); // 3.5.5.7 (2004/05/10) 087 for( int row=startNo; row<lastNo; row++ ) { 088 // カラム==0は、レベルを指定する。 089 level = Integer.parseInt( getValueLabel(row,0) ); 090 // 6.3.9.0 (2015/11/06) Found 'DD'-anomaly for variable(PMD) 091 final boolean isFld = row+1<lastNo && level < Integer.parseInt( getValueLabel(row+1,0) ); 092 out.append( getLevelScript( level,isFld ) ); 093 094 // カラム==0は、レベルを指定するので表示しない。 095 for( int column=1; column<clmCnt; column++ ) { 096 if( isColumnDisplay( column ) ) { 097 out.append("<td class=\"") // 3.9.0.1 (2007/12/18) 098 .append( getClassName(column) ) // 6.4.5.0 (2016/04/08) 099 .append("\"> ") 100 .append( getValueLabel(row,column) ) 101 .append("</td>"); 102 } 103 } 104 out.append( "', '', 'gold')" ); 105 if( level != 0 ) { 106 out.append( ')' ); // 6.0.2.5 (2014/10/31) char を append する。 107 } 108 out.append( CR ); 109 } 110 out.append( FUTTER ); // 6.4.4.1 (2016/03/18) 111 112 return out.toString(); 113 } 114 115 /** 116 * DBTableModel から テーブルのヘッダータグ文字列を作成して返します。 117 * JavaScript の TreeBody では、JavaScriptに関連する定義もこのヘッダーに 118 * 含めます。 119 * 120 * @og.rev 3.5.2.1 (2003/10/27) JavaScript 内のダブルコーテーションをシングルコーテーションに変更する。 121 * @og.rev 3.9.0.1 (2007/12/18) 文字サイズ変更スクリプト対応のため、id="viewTable"を出力 122 * @og.rev 6.4.4.1 (2016/03/18) HEADER を、static final 定数化にします。 123 * 124 * @return テーブルのヘッダータグ文字列 125 * @og.rtnNotNull 126 */ 127 @Override 128 protected String getHeader() { 129 // 6.4.4.1 (2016/03/18) HEADER を、static final 定数化にします。 130 final StringBuilder buf = new StringBuilder( BUFFER_MIDDLE ).append( HEADER ); 131 132 // カラム==0は、レベルを指定するので表示しない。 133 final int clmCnt = getColumnCount(); // 3.5.5.7 (2004/05/10) 134 for( int column=1; column<clmCnt; column++ ) { 135 if( isColumnDisplay( column ) ) { 136 buf.append( "<th>" ).append( getColumnLabel(column) ).append( "</th>" ); 137 } 138 } 139 buf.append( "', '', 'gold')" ).append( CR ); 140 141 return buf.toString(); 142 } 143 144 /** 145 * 行のレベルに応じた JavaScript関数のヘッダー部分を返します。 146 * 147 * @og.rev 3.5.2.1 (2003/10/27) JavaScript 内のダブルコーテーションをシングルコーテーションに変更する。 148 * 149 * @param lvl ツリーのレベル 150 * @param isFld フォルダかどうか[true:フォルダ/false:最下層] 151 * 152 * @return JavaScript関数のヘッダー部分 153 * @og.rtnNotNull 154 */ 155 private String getLevelScript( final int lvl,final boolean isFld ) { 156 157 final String auxX = "\taux" + ( lvl ); 158 final String auxY = "aux" + ( lvl-1 ); 159 160 final String rtn ; 161 if( isFld ) { 162 rtn = auxX + " = insFld(" + auxY + ", gFld('"; 163 } 164 else { 165 rtn = "\tinsFld(" + auxY + ", gLnk('CONTENTS','"; 166 } 167 168 return rtn; 169 } 170}