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.column; 017 018import org.opengion.hayabusa.common.HybsSystem; 019import org.opengion.hayabusa.db.AbstractEditor; 020import org.opengion.hayabusa.db.CellEditor; 021import org.opengion.hayabusa.db.DBColumn; 022import org.opengion.hayabusa.db.SelectionCellEditor; // 6.2.2.0 (2015/03/27) 023import org.opengion.hayabusa.db.Selection; 024import org.opengion.hayabusa.db.SelectionFactory; 025import org.opengion.fukurou.util.XHTMLTag; 026import org.opengion.fukurou.util.Attributes; 027import org.opengion.fukurou.util.TagBuffer; 028 029import static org.opengion.fukurou.util.StringUtil.isNull; // 6.1.1.0 (2015/01/17) 030 031/** 032 * MENU エディターは、カラムのデータをコードリソースに対応した 033 * プルダウンメニューで編集する場合に使用するクラスです。 034 * 035 * 編集パラメータに"SEQ"と記述することで正方向にしか選べないプルダウンメニューを実現できます。 036 * これにより、シーケンスにステータスを順に挙げていくような、プルダウンメニュー 037 * を作成することが出来ます。(逆に戻れないメニュー) 038 * 039 * カラムの表示に必要な属性は、DBColumn オブジェクト より取り出します。 040 * このクラスは、DBColumn オブジェクト毎に1つ作成されます。 041 * 042 * @og.rev 6.2.2.0 (2015/03/27) SelectionCellEditor I/Fを追加 043 * @og.group データ編集 044 * 045 * @version 4.0 046 * @author Kazuhiko Hasegawa 047 * @since JDK5.0, 048 */ 049public class Editor_MENU extends AbstractEditor implements SelectionCellEditor { 050 /** このプログラムのVERSION文字列を設定します。 {@value} */ 051 private static final String VERSION = "7.0.5.1 (2019/09/27)" ; 052 053 // 3.2.3.0 (2003/06/06) final を削除。サブクラスからアクセスできるように変更。 054 /** セレクションオブジェクト */ 055 private final Selection selection ; // 6.0.4.0 (2014/11/28) サブクラスからの参照を廃止 056 private final boolean addNoValue ; // 3.5.5.7 (2004/05/10) 057 /** シーケンスフラグ */ 058 private final boolean seqFlag ; // 6.0.4.0 (2014/11/28) サブクラスからの参照を廃止 059 private final String useSLabel ; // 5.5.1.0 (2012/04/03) 060 061 private String errMsg ; // 6.0.4.0 (2014/11/28) 062 063 /** 064 * デフォルトコンストラクター。 065 * このコンストラクターで、基本オブジェクトを作成します。 066 * 067 * @og.rev 3.1.1.1 (2003/04/03) 各オブジェクトから自分のインスタンスを返すファクトリメソッドを追加。 068 * @og.rev 3.6.0.6 (2004/10/22) シーケンスアクセス機能(seqFlag)を追加します 069 * @og.rev 5.5.1.0 (2012/04/03) Slabel対応 070 */ 071 public Editor_MENU() { 072 super(); // 6.4.1.1 (2016/01/16) PMD refactoring. It is a good practice to call super() in a constructor 073 // 4.3.4.4 (2009/01/01) 074 selection = null; 075 addNoValue = false; // 3.5.5.7 (2004/05/10) 076 seqFlag = false; // 3.6.0.6 (2004/10/22) 077 useSLabel = "auto"; // 5.5.1.0 (2012/04/03) 078 } 079 080 /** 081 * コンストラクター。 082 * 083 * @og.rev 3.1.1.1 (2003/04/03) 各オブジェクトから自分のインスタンスを返すファクトリメソッドを追加。 084 * @og.rev 3.3.1.1 (2003/07/03) name , attributes 属性を final にする。 085 * @og.rev 3.5.4.2 (2003/12/15) makeCodeSelection メソッドを CodeSelectionクラスに変更。 086 * @og.rev 3.5.5.7 (2004/05/10) SelectionFactory を使用して、オブジェクト作成 087 * @og.rev 3.5.5.7 (2004/05/10) addNoValue 属性を追加します。 088 * @og.rev 3.5.6.0 (2004/06/18) XHTMLTag の 内部配列 SELECT_KEY を隠蔽します。 089 * @og.rev 3.6.0.6 (2004/10/22) シーケンスアクセス機能(seqFlag)を追加します 090 * @og.rev 4.0.0.0 (2005/01/31) Selection_CODE の作成の引数を CodeData に変更。 091 * @og.rev 4.0.0.0 (2007/11/07) SelectionオブジェクトをDBColumnから取得 092 * @og.rev 5.1.7.0 (2010/06/01) 動的プルダウン実装見直し 093 * @og.rev 5.5.1.0 (2012/04/03) Slabel対応 094 * @og.rev 6.0.4.0 (2014/11/28) optionAttributes は、コンストラクタで設定します。 095 * @og.rev 6.0.4.0 (2014/11/28) サブクラスで タイプを指定するための対応 096 * @og.rev 6.2.0.0 (2015/02/27) キー:ラベル形式(KVMENU)で表示するかどうかを、指定できるようにします。 097 * @og.rev 6.2.6.0 (2015/06/19) type別Selectionの場合、ラベルリソースを使用する為、言語を引数で渡す。 098 * @og.rev 6.4.4.2 (2016/04/01) nameのfinal化 099 * @og.rev 6.9.5.0 (2018/04/23) useMultiSelect 廃止 100 * @og.rev 7.0.5.1 (2019/09/27) optionAttributes が二重に設定されていたため、削除 101 * 102 * @param clm DBColumnオブジェクト 103 * @param type MENUのサブクラスのタイプ(FILES,KEYVAL,NUM,HM,YMD) 104 */ 105 protected Editor_MENU( final DBColumn clm , final String type ) { 106 // super(); // 6.4.1.1 (2016/01/16) PMD refactoring. It is a good practice to call super() in a constructor 107 super( clm ); // 6.4.4.2 (2016/04/01) nameのfinal化 108 // name = clm.getName(); 109 addNoValue = clm.isAddNoValue() ; // 3.5.5.7 (2004/05/10) 110 seqFlag = "SEQ".equals( clm.getEditorParam() ); // 3.6.0.6 (2004/10/22) 111 useSLabel = clm.getUseSLabel() ; // 5.5.1.0 (2012/04/03) 112 113 final String lang = clm.getLang(); // 6.2.6.0 (2015/06/19) 114 final String addKeyLabel = clm.getAddKeyLabel(); // 6.2.0.0 (2015/02/27) キー:ラベル形式 115 final String disabled = clm.isWritable() ? null : "disabled" ; 116 117 // 6.1.1.0 (2015/01/17) Attributesの連結記述 118 attributes = new Attributes() 119 .set( "disabled" ,disabled ) 120 .set( clm.getEditorAttributes() ); // #addAttributes( Attributes ) の代替え 121 122 // 6.1.1.0 (2015/01/17) TagBufferの連結記述 123 // 7.0.5.1 (2019/09/27) optionAttributes が二重に設定されていたため、削除 124 tagBuffer.add( XHTMLTag.selectAttri( attributes ) ); 125// .add( attributes.get( "optionAttributes" ) ); // 6.0.4.0 (2014/11/28) 126 127 // 6.0.4.0 (2014/11/28) selection は、Column から取得するのではなく、Factory で作成する。 128 // 6.4.1.1 (2016/01/16) PMD refactoring. Avoid if (x != y) ..; else ..; 129 selection = type == null 130 ? SelectionFactory.newSelection( "MENU",clm.getCodeData(),addKeyLabel ) // 6.2.0.0 (2015/02/27) 131 : SelectionFactory.newSelection( type,clm.getEditorParam(),lang ); 132 133// // 6.0.4.0 (2014/11/28) useMultiSelect は、selection ではなく、colomn から取得する。 134// // 6.9.5.0 (2018/04/23) useMultiSelect 廃止 135// if( clm.useMultiSelect() ) { tagBuffer.add( "onkeydown" , "setKeySelect(this);" ); } 136 137 // 6.0.4.0 (2014/11/28) selection が null の場合、警告表示します。 138 if( selection == null ) { 139 errMsg = "codeData が未設定です。" 140 + " name=" + name 141 + " label=" + clm.getLabel() 142 + " editType=" + clm.getEditor() ; 143 System.out.println( errMsg ); 144 } 145 } 146 147 /** 148 * 各オブジェクトから自分のインスタンスを返します。 149 * 自分自身をキャッシュするのか、新たに作成するのかは、各サブクラスの実装に 150 * まかされます。 151 * 152 * @og.rev 3.1.1.1 (2003/04/03) 各オブジェクトから自分のインスタンスを返すファクトリメソッドを追加。 153 * @og.rev 3.1.2.1 (2003/04/10) synchronized を、削除します。 154 * @og.rev 6.0.4.0 (2014/11/28) サブクラスで タイプを指定するための対応 155 * 156 * @param clm DBColumnオブジェクト 157 * 158 * @return CellEditorオブジェクト 159 * @og.rtnNotNull 160 */ 161 public CellEditor newInstance( final DBColumn clm ) { 162 return new Editor_MENU( clm , null ); 163 } 164 165 /** 166 * データの編集用文字列を返します。 167 * 168 * @og.rev 3.5.5.5 (2004/04/23) 新規に Attributes オブジェクトを作成する方式を止めます。 169 * @og.rev 3.5.5.7 (2004/05/10) addNoValue 属性を追加します。 170 * @og.rev 3.6.0.6 (2004/10/22) シーケンスアクセス機能(seqFlag)を追加します 171 * @og.rev 4.3.7.2 (2009/06/15) 属性でidが出力される場合は、idを出力しない 172 * @og.rev 5.1.3.0 (2010/02/01) 一覧表示のみで、ツールチップ表示を行う。 173 * @og.rev 5.1.7.0 (2010/06/01) 動的プルダウン実装見直し 174 * @og.rev 5.5.1.0 (2012/04/03) useSLabel対応 175 * @og.rev 6.0.4.0 (2014/11/28) selection が null の場合、警告表示します。 176 * 177 * @param value 入力値 178 * 179 * @return データの編集用文字列 180 * @og.rtnNotNull 181 */ 182 @Override 183 public String getValue( final String value ) { 184 // 6.0.4.0 (2014/11/28) selection が null の場合、警告表示します。 185 if( selection == null ) { 186 return "<span class=\"error\">" + errMsg + " value=" + value + "</span>"; 187 } 188 189 final boolean useSlbl = "true".equalsIgnoreCase( useSLabel ); // 5.5.1.0 (2012/04/03) 190 191 // 6.1.1.0 (2015/01/17) TagBufferの連結記述 192 return new TagBuffer( "select" ) 193 .add( "name" , name ) // 4.3.6.0 (2009/04/01) 194 .add( "id" , name , isNull( attributes.get( "id" ) ) ) // 4.3.7.2 (2009/06/15) 195 .add( tagBuffer.makeTag() ) 196 .addBody( Selection.NO_VALUE_OPTION , addNoValue ) // 5.5.1.0 (2012/04/03) 197 .addBody( selection.getOption( value,seqFlag,useSlbl ) ) 198 .makeTag(); 199 } 200 201 /** 202 * name属性を変えた、データ表示/編集用のHTML文字列を作成します。 203 * テーブル上の name に 行番号を付加して、名前_行番号 で登録するキーを作成し、 204 * リクエスト情報を1つ毎のフィールドで処理できます。 205 * 206 * @og.rev 2.0.0.3 (2002/09/26) optionAttributes 属性に "$i" を使うとその行数に置き換る機能を追加。 207 * @og.rev 3.1.0.0 (2003/03/20) 名前と行番号の区切り記号を "^" から "__" に変更。 208 * @og.rev 3.5.5.0 (2004/03/12) 名前と行番号の区切り記号("__")を、HybsSystem.JOINT_STRING に変更。 209 * @og.rev 3.5.5.5 (2004/04/23) 新規に Attributes オブジェクトを作成する方式を止めます。 210 * @og.rev 3.5.5.7 (2004/05/10) addNoValue 属性を追加します。 211 * @og.rev 3.6.0.6 (2004/10/22) シーケンスアクセス機能(seqFlag)を追加します 212 * @og.rev 4.3.7.2 (2009/06/15) 属性でidが出力される場合は、idを出力しない 213 * @og.rev 5.1.3.0 (2010/02/01) 一覧表示のみで、ツールチップ表示を行う。 214 * @og.rev 5.1.7.0 (2010/06/01) 動的プルダウン実装見直し 215 * @og.rev 5.5.1.0 (2012/04/03) useSLabel対応 216 * @og.rev 6.0.4.0 (2014/11/28) selection が null の場合、警告表示します。 217 * 218 * @param row 行番号 219 * @param value 入力値 220 * 221 * @return データ表示/編集用の文字列 222 * @og.rtnNotNull 223 */ 224 @Override 225 public String getValue( final int row,final String value ) { 226 // 6.0.4.0 (2014/11/28) selection が null の場合、警告表示します。 227 if( selection == null ) { 228 return "<span class=\"error\">" + errMsg + " value=" + value + " row=" + row + "</span>"; 229 } 230 231 final boolean useSlbl = "auto".equalsIgnoreCase( useSLabel ) || "true".equalsIgnoreCase( useSLabel ); // 5.5.1.0 (2012/04/03) 232 233 // 6.1.1.0 (2015/01/17) TagBufferの連結記述 234 final String newName = name + HybsSystem.JOINT_STRING + row; // 4.3.6.0 (2009/04/01) 235 return new TagBuffer( "select" ) 236 .add( "name" , newName ) // 4.3.6.0 (2009/04/01) 237 .add( "id" , newName , isNull( attributes.get( "id" ) ) ) // 4.3.7.2 (2009/06/15) 238 .add( tagBuffer.makeTag() ) 239 .addBody( Selection.NO_VALUE_OPTION , addNoValue ) // 5.5.1.0 (2012/04/03) 240 .addBody( selection.getOption( value,seqFlag,useSlbl ) ) 241 .makeTag( row,value ); 242 } 243}