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.Selection; 023import org.opengion.fukurou.util.XHTMLTag; 024import org.opengion.fukurou.util.Attributes; 025import org.opengion.fukurou.util.TagBuffer; 026 027/** 028 * MENU エディターは、カラムのデータをコードリソースに対応した 029 * プルダウンメニューで編集する場合に使用するクラスです。 030 * 031 * カラムの表示に必要な属性は, DBColumn オブジェクト より取り出します。 032 * このクラスは、DBColumn オブジェクト毎に1つ作成されます。 033 * 034 * @og.group データ編集 035 * 036 * @version 4.0 037 * @author Kazuhiko Hasegawa 038 * @since JDK5.0, 039 */ 040public class Editor_MENU extends AbstractEditor { 041 //* このプログラムのVERSION文字列を設定します。 {@value} */ 042 private static final String VERSION = "5.5.1.0 (2012/04/03)" ; 043 044 // 3.2.3.0 (2003/06/06) final を削除。サブクラスからアクセスできるように変更。 045 /** セレクションオブジェクト */ 046 protected Selection selection ; 047 private final boolean addNoValue ; // 3.5.5.7 (2004/05/10) 048 /** シーケンスフラグ */ 049 protected boolean seqFlag ; // 3.6.0.6 (2004/10/22) 050 private final String useSLabel ; // 5.5.1.0 (2012/04/03) 051 052 /** 053 * デフォルトコンストラクター。 054 * このコンストラクターで、基本オブジェクトを作成します。 055 * 056 * @og.rev 3.1.1.1 (2003/04/03) 各オブジェクトから自分のインスタンスを返すファクトリメソッドを追加。 057 * @og.rev 3.6.0.6 (2004/10/22) シーケンスアクセス機能(seqFlag)を追加します 058 * @og.rev 5.5.1.0 (2012/04/03) Slabel対応 059 * 060 */ 061 public Editor_MENU() { 062 // 4.3.4.4 (2009/01/01) 063 selection = null; 064 addNoValue = false; // 3.5.5.7 (2004/05/10) 065 seqFlag = false; // 3.6.0.6 (2004/10/22) 066 useSLabel = "auto"; // 5.5.1.0 (2012/04/03) 067 } 068 069 /** 070 * コンストラクター。 071 * 072 * @og.rev 3.1.1.1 (2003/04/03) 各オブジェクトから自分のインスタンスを返すファクトリメソッドを追加。 073 * @og.rev 3.3.1.1 (2003/07/03) name , attributes 属性を final にする。 074 * @og.rev 3.5.4.2 (2003/12/15) makeCodeSelection メソッドを CodeSelectionクラスに変更。 075 * @og.rev 3.5.5.7 (2004/05/10) SelectionFactory を使用して、オブジェクト作成 076 * @og.rev 3.5.5.7 (2004/05/10) addNoValue 属性を追加します。 077 * @og.rev 3.5.6.0 (2004/06/18) XHTMLTag の 内部配列 SELECT_KEY を隠蔽します。 078 * @og.rev 3.6.0.6 (2004/10/22) シーケンスアクセス機能(seqFlag)を追加します 079 * @og.rev 4.0.0.0 (2005/01/31) Selection_CODE の作成の引数を CodeData に変更。 080 * @og.rev 4.0.0.0 (2007/11/07) SelectionオブジェクトをDBColumnから取得 081 * @og.rev 5.1.7.0 (2010/06/01) 動的プルダウン実装見直し 082 * @og.rev 5.5.1.0 (2012/04/03) Slabel対応 083 * 084 * @param clm DBColumnオブジェクト 085 */ 086 protected Editor_MENU( final DBColumn clm ) { 087 // super( clm ); 088 name = clm.getName(); 089 addNoValue = clm.isAddNoValue() ; // 3.5.5.7 (2004/05/10) 090 seqFlag = "SEQ".equals( clm.getEditorParam() ); // 3.6.0.6 (2004/10/22) 091 useSLabel = clm.getUseSLabel() ; // 5.5.1.0 (2012/04/03) 092 093 String disabled = clm.isWritable() ? null : "disabled" ; 094 095 attributes = new Attributes(); 096 attributes.set( "disabled" ,disabled ); 097 098 attributes.addAttributes( clm.getEditorAttributes() ); 099 optAttr = attributes.get( "optionAttributes" ); 100 tagBuffer.add( XHTMLTag.selectAttri( attributes ) ); 101 102 selection = clm.getSelection(); // 4.0.0 (2005/01/31) 103 // 5.6.1.1 (2013/02/08) 暫定処置 104 if( selection != null ) { 105 boolean useMultiSelect = selection.useMultiSelect(); 106 if( useMultiSelect ) { tagBuffer.add( "onkeydown" , "setKeySelect(this);" ); } 107 } 108 } 109 110 /** 111 * 各オブジェクトから自分のインスタンスを返します。 112 * 自分自身をキャッシュするのか、新たに作成するのかは、各サブクラスの実装に 113 * まかされます。 114 * 115 * @og.rev 3.1.1.1 (2003/04/03) 各オブジェクトから自分のインスタンスを返すファクトリメソッドを追加。 116 * @og.rev 3.1.2.1 (2003/04/10) synchronized を、削除します。 117 * 118 * @param clm DBColumnオブジェクト 119 * 120 * @return CellEditorオブジェクト 121 */ 122 public CellEditor newInstance( final DBColumn clm ) { 123 return new Editor_MENU( clm ); 124 } 125 126 /** 127 * データの編集用文字列を返します。 128 * 129 * @og.rev 3.5.5.5 (2004/04/23) 新規に Attributes オブジェクトを作成する方式を止めます。 130 * @og.rev 3.5.5.7 (2004/05/10) addNoValue 属性を追加します。 131 * @og.rev 3.6.0.6 (2004/10/22) シーケンスアクセス機能(seqFlag)を追加します 132 * @og.rev 4.3.7.2 (2009/06/15) 属性でidが出力される場合は、idを出力しない 133 * @og.rev 5.1.3.0 (2010/02/01) 一覧表示のみで、ツールチップ表示を行う。 134 * @og.rev 5.1.7.0 (2010/06/01) 動的プルダウン実装見直し 135 * @og.rev 5.5.1.0 (2012/04/03) useSLabel対応 136 * 137 * @param value 入力値 138 * 139 * @return データの編集用文字列 140 */ 141 @Override 142 public String getValue( final String value ) { 143 final boolean uslbl = "true".equalsIgnoreCase( useSLabel ); // 5.5.1.0 (2012/04/03) 144 145 TagBuffer tag = new TagBuffer( "select" ); 146 tag.add( "name" , name ); 147 tag.add( tagBuffer.makeTag() ); 148 tag.add( optAttr ); // 3.5.5.8 (2004/05/20) 149 if( attributes.get( "id" ) == null || attributes.get( "id" ).length() == 0 ) { // 4.3.7.2 (2009/06/15) 150 tag.add( "id" , name ); // 4.3.6.0 (2009/04/01) 151 } 152 153 if( addNoValue ) { 154 // 5.1.3.0 (2010/02/01) 155 tag.setBody( Selection.NO_VALUE_OPTION + selection.getOption( value,seqFlag,uslbl ) ); // 5.5.1.0 (2012/04/03) 156 } 157 else { 158 // 5.1.3.0 (2010/02/01) 159 tag.setBody( selection.getOption( value,seqFlag,uslbl ) ); // 5.5.1.0 (2012/04/03) 160 } 161 162 return tag.makeTag(); 163 } 164 165 /** 166 * name属性を変えた、データ表示/編集用のHTML文字列を作成します。 167 * テーブル上の name に 行番号を付加して、名前_行番号 で登録するキーを作成し, 168 * リクエスト情報を1つ毎のフィールドで処理できます。 169 * 170 * @og.rev 2.0.0.3 (2002/09/26) optionAttributes 属性に "$i" を使うとその行数に置き換る機能を追加。 171 * @og.rev 3.1.0.0 (2003/03/20) 名前と行番号の区切り記号を "^" から "__" に変更。 172 * @og.rev 3.5.5.0 (2004/03/12) 名前と行番号の区切り記号("__")を、HybsSystem.JOINT_STRING に変更。 173 * @og.rev 3.5.5.5 (2004/04/23) 新規に Attributes オブジェクトを作成する方式を止めます。 174 * @og.rev 3.5.5.7 (2004/05/10) addNoValue 属性を追加します。 175 * @og.rev 3.6.0.6 (2004/10/22) シーケンスアクセス機能(seqFlag)を追加します 176 * @og.rev 4.3.7.2 (2009/06/15) 属性でidが出力される場合は、idを出力しない 177 * @og.rev 5.1.3.0 (2010/02/01) 一覧表示のみで、ツールチップ表示を行う。 178 * @og.rev 5.1.7.0 (2010/06/01) 動的プルダウン実装見直し 179 * @og.rev 5.5.1.0 (2012/04/03) useSLabel対応 180 * 181 * @param row 行番号 182 * @param value 入力値 183 * 184 * @return データ表示/編集用の文字列 185 */ 186 @Override 187 public String getValue( final int row,final String value ) { 188 final boolean uslbl = "auto".equalsIgnoreCase( useSLabel ) || "true".equalsIgnoreCase( useSLabel ); // 5.5.1.0 (2012/04/03) 189 190 TagBuffer tag = new TagBuffer( "select" ); 191 String newName = name + HybsSystem.JOINT_STRING + row; // 4.3.6.0 (2009/04/01) 192 // tag.add( "name" , name + HybsSystem.JOINT_STRING + row ); 193 tag.add( "name", newName ); // 4.3.6.0 (2009/04/01) 194 if( attributes.get( "id" ) == null || attributes.get( "id" ).length() == 0 ) { // 4.3.7.2 (2009/06/15) 195 tag.add( "id" , newName ); // 4.3.6.0 (2009/04/01) 196 } 197 tag.add( tagBuffer.makeTag() ); 198 tag.add( optAttr ); // 3.5.5.8 (2004/05/20) 199 200 if( addNoValue ) { 201 // 5.1.3.0 (2010/02/01) 202 tag.setBody( Selection.NO_VALUE_OPTION + selection.getOption( value,seqFlag,uslbl ) ); // 5.5.1.0 (2012/04/03) 203 } 204 else { 205 // 5.1.3.0 (2010/02/01) 206 tag.setBody( selection.getOption( value,seqFlag,uslbl ) ); // 5.5.1.0 (2012/04/03) 207 } 208 209 return tag.makeTag( row,value ); 210 } 211}