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.common.HybsSystemException; 020 021import org.opengion.hayabusa.db.AbstractRenderer; 022import org.opengion.hayabusa.db.CellRenderer; 023import org.opengion.hayabusa.db.DBColumn; 024import org.opengion.hayabusa.db.Selection; 025import org.opengion.hayabusa.db.SelectionFactory; 026import org.opengion.fukurou.util.StringFormat; 027 028/** 029 * DBMENU レンデラーは、表示パラメータで指定された SQL文を実行し、 030 * プルダウンメニューで表示する場合に使用するクラスです。 031 * 032 * カラムの表示に必要な属性は, DBColumn オブジェクト より取り出します。 033 * このクラスは、DBColumn オブジェクト毎に1つ作成されます。 034 * 035 * @og.rev 3.2.3.0 (2003/06/06) 新規作成 036 * @og.rev 3.4.0.1 (2003/09/03) DB検索をリアルタイムに変更。 037 * @og.rev 3.5.4.2 (2003/12/15) 継承元クラスを、Editor_DBMENU から AbstractRenderer に変更。 038 * @og.group データ表示 039 * 040 * @version 4.0 041 * @author Kazuhiko Hasegawa 042 * @since JDK5.0, 043 */ 044public class Renderer_DBMENU extends AbstractRenderer { 045 //* このプログラムのVERSION文字列を設定します。 {@value} */ 046 private static final String VERSION = "5.6.2.3 (2013/03/22)" ; 047 048 private final String query ; 049 private final String dbid ; 050 private final String lang ; // 4.0.0 (2006/11/15) 051 private final String name ; 052 private final String useSLabel ; // 5.5.1.0 (2012/04/03) 053 private final String noDisplayVal ; // 5.6.2.3 (2013/03/22) 054 055 /** 056 * デフォルトコンストラクター。 057 * このコンストラクターで、基本オブジェクトを作成します。 058 * 059 * @og.rev 3.4.0.2 (2003/09/05) クラス内部見直し。query の final 化 060 * @og.rev 3.5.4.2 (2003/12/15) name , query 変数を、初期設定しておきます。 061 * @og.rev 5.6.2.3 (2013/03/22) noDisplayVal 変数初期化 062 * 063 */ 064 public Renderer_DBMENU() { 065 query = null; // 3.5.4.2 (2003/12/15) 066 dbid = null; 067 lang = null; // 4.0.0 (2006/11/15) 068 name = null; // 3.5.4.2 (2003/12/15) 069 useSLabel = "auto"; // 5.5.1.0 (2012/04/03) 070 noDisplayVal = null; // 5.5.1.0 (2012/04/03) 071 } 072 073 /** 074 * デフォルトコンストラクター。 075 * 076 * @og.rev 3.3.1.1 (2003/07/03) CodeSelection の設定において、バグ修正。 077 * @og.rev 3.4.0.1 (2003/09/03) 継承の親元の変更に伴う実装の移動。 078 * @og.rev 3.5.4.2 (2003/12/15) 継承元クラスを、Editor_DBMENU から AbstractRenderer に変更。 079 * @og.rev 3.5.5.9 (2004/06/07) editorParam 属性が null の場合は、エラーとします。 080 * @og.rev 5.6.2.3 (2013/03/22) noDisplayVal 変数追加 081 * 082 * @param clm DBColumnオブジェクト 083 */ 084 private Renderer_DBMENU( final DBColumn clm ) { 085 name = clm.getName(); 086 query = clm.getRendererParam(); 087 dbid = clm.getDbid(); 088 lang = clm.getLang(); // 4.0.0 (2006/11/15) 089 useSLabel = clm.getUseSLabel() ; // 5.5.1.0 (2012/04/03) 090 noDisplayVal = clm.getNoDisplayVal(); // 5.6.2.3 (2013/03/22) 091 092 // 3.5.5.9 (2004/06/07) 093 if( query == null || query.length() == 0 ) { 094 String errMsg = "DBMENU Renderer では、表示パラメータは必須です。" 095 + " name=[" + name + "]" + HybsSystem.CR ; 096 throw new HybsSystemException( errMsg ); 097 } 098 } 099 100 /** 101 * 各オブジェクトから自分のインスタンスを返します。 102 * 自分自身をキャッシュするのか、新たに作成するのかは、各サブクラスの実装に 103 * まかされます。 104 * 105 * @param clm DBColumnオブジェクト 106 * 107 * @return CellRendererオブジェクト 108 */ 109 public CellRenderer newInstance( final DBColumn clm ) { 110 return new Renderer_DBMENU( clm ); 111 } 112 113 /** 114 * データの表示用文字列を返します。 115 * 116 * ここでは、AAA:BBB:CCC:DDD という値を、$1,$2,$3,$4 に割り当てなおして、 117 * QUERYを実行します。また、$1 は、本来の値として、メニューの初期値設定等に 118 * 使用します。上記の例では、AAA が値で、それ以降は、引数になります。 119 * さらに、元の文字列"AAA:BBB:CCC:DDD"は、$0 に割り当てられます。割り当てがない 120 * 変数は、""(ゼロ文字列)として、扱われます。 121 * 122 * @og.rev 3.4.0.1 (2003/09/03) DB検索をリアルタイムに変更。 123 * @og.rev 3.4.0.2 (2003/09/05) AAA:BBB:CCC:DDD という値を、$1,$2,$3,$4 に割り当てます。 124 * @og.rev 3.5.4.2 (2003/12/15) makeCodeSelection メソッドを CodeSelectionクラスに変更。 125 * @og.rev 3.5.5.7 (2004/05/10) SelectionFactory を使用して、オブジェクト作成 126 * @og.rev 4.0.0.0 (2006/11/15) SelectionFactory に lang 属性を追加します。 127 * @og.rev 4.3.4.0 (2008/12/01) $Cのカラム名置換えを追加 128 * @og.rev 5.5.1.0 (2012/04/03) Slabel対応。"auto"は、false になります。 129 * @og.rev 5.6.2.3 (2013/03/22) noDisplayVal 変数追加 130 * 131 * @param value 入力値 132 * 133 * @return データの表示用文字列 134 */ 135 @Override 136 public String getValue( final String value ) { 137 // 5.6.2.3 (2013/03/22) noDisplayVal 変数追加 138 if( noDisplayVal != null && noDisplayVal.equalsIgnoreCase( value ) ) { return "" ; } 139 140 // StringFormat format = new StringFormat( query,value); 141 StringFormat format = new StringFormat( query, value, name ); // 4.3.4.0 (2008/12/01) 142 String newQuery = format.format(); 143 String newValue = format.getValue(); 144 145 Selection selection = SelectionFactory.newDBSelection( newQuery,dbid,lang ); 146 final boolean uslbl = "true".equalsIgnoreCase( useSLabel ); // 5.5.1.0 (2012/04/03) 147 return selection.getValueLabel( newValue,uslbl ); 148 } 149 150 /** 151 * name属性を変えた、データ表示/編集用のHTML文字列を作成します。 152 * テーブル上の name に 行番号を付加して、名前_行番号 で登録するキーを作成し, 153 * リクエスト情報を1つ毎のフィールドで処理できます。 154 * 155 * @og.rev 4.0.0.0 (2005/11/30) 一覧表示では、短縮ラベルを使用します。 156 * @og.rev 4.0.0.0 (2006/11/15) SelectionFactory に lang 属性を追加します。 157 * @og.rev 4.3.4.0 (2008/12/01) $Cのカラム名置換えを追加 158 * @og.rev 5.5.1.0 (2012/04/03) Slabel対応。"auto"は、true になります。 159 * @og.rev 5.6.2.3 (2013/03/22) noDisplayVal 変数追加 160 * 161 * @param row 行番号 162 * @param value 入力値 163 * 164 * @return データ表示/編集用の文字列 165 */ 166 @Override 167 public String getValue( final int row,final String value ) { 168 // 5.6.2.3 (2013/03/22) noDisplayVal 変数追加 169 if( noDisplayVal != null && noDisplayVal.equalsIgnoreCase( value ) ) { return "" ; } 170 171 // StringFormat format = new StringFormat( query,value); 172 StringFormat format = new StringFormat( query, value, name ); // 4.3.4.0 (2008/12/01) 173 String newQuery = format.format(); 174 String newValue = format.getValue(); 175 176 Selection selection = SelectionFactory.newDBSelection( newQuery,dbid,lang ); 177 final boolean uslbl = "auto".equalsIgnoreCase( useSLabel ) || "true".equalsIgnoreCase( useSLabel ); // 5.5.1.0 (2012/04/03) 178 return selection.getValueLabel( newValue,uslbl ); 179 } 180}