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.column;
017    
018    import org.opengion.hayabusa.common.HybsSystem;
019    import org.opengion.hayabusa.common.HybsSystemException;
020    
021    import org.opengion.hayabusa.db.AbstractRenderer;
022    import org.opengion.hayabusa.db.CellRenderer;
023    import org.opengion.hayabusa.db.DBColumn;
024    import org.opengion.hayabusa.db.Selection;
025    import org.opengion.hayabusa.db.SelectionFactory;
026    import org.opengion.fukurou.util.StringFormat;
027    
028    /**
029     * DBMENU レンãƒ?ƒ©ーは、表示パラメータでæŒ?®šされた SQLæ–?‚’実行しã€?
030     * プルãƒ?‚¦ンメニューで表示する場合に使用するクラスですã?
031     *
032     *  カラãƒ??表示にå¿?¦�な属æ?は, DBColumn オブジェクãƒ?より取り出しますã?
033     * こã?クラスは、DBColumn オブジェクト毎に?‘つ作æ?されますã?
034     *
035     * @og.rev 3.2.3.0 (2003/06/06) 新規作æ?
036     * @og.rev 3.4.0.1 (2003/09/03) ?¤?¢検索をリアルタイãƒ?�«変更ã€?
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     */
044    public 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) ?¤?¢検索をリアルタイãƒ?�«変更ã€?
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".equals(useSLabel) ? false : true; // 5.5.1.0 (2012/04/03)
147                    final boolean uslbl = "true".equalsIgnoreCase( useSLabel );             // 5.5.1.0 (2012/04/03)
148    //              return selection.getValueLabel( newValue );
149                    return selection.getValueLabel( newValue,uslbl );
150            }
151    
152            /**
153             * name属æ?を変えたã?ãƒ??タ表示/編é›?”¨のHTMLæ–?­—å?を作æ?しますã?
154             * ãƒ??ブル上ã? name に 行番号を付加して、名前_行番号 で登録するキーを作æ?ã�?
155             * リクエスト情報を1つ毎ã?フィールドで処ç�?�§きますã?
156             *
157             * @og.rev 4.0.0.0 (2005/11/30) ä¸?¦§表示では、短縮ラベルを使用しますã?
158             * @og.rev 4.0.0.0 (2006/11/15) SelectionFactory に lang 属æ?を追åŠ?�—ますã?
159             * @og.rev 4.3.4.0 (2008/12/01) $Cのカラãƒ?��置換えを追åŠ?
160             * @og.rev 5.5.1.0 (2012/04/03) Slabel対応ã?"auto"は、true になりますã?
161             * @og.rev 5.6.2.3 (2013/03/22) noDisplayVal 変数追åŠ?
162             *
163             * @param   row   行番号
164             * @param   value 入力å?
165             *
166             * @return  ãƒ??タ表示/編é›?”¨のæ–?­—å?
167             */
168            @Override
169            public String getValue( final int row,final String value ) {
170                    // 5.6.2.3 (2013/03/22) noDisplayVal 変数追åŠ?
171                    if( noDisplayVal != null && noDisplayVal.equalsIgnoreCase( value ) ) { return "" ; }
172    
173                    // StringFormat format = new StringFormat( query,value);
174                    StringFormat format = new StringFormat( query, value, name ); // 4.3.4.0 (2008/12/01)
175                    String newQuery = format.format();
176                    String newValue = format.getValue();
177    
178                    Selection selection = SelectionFactory.newDBSelection( newQuery,dbid,lang );
179    //              final boolean uslbl = ("auto".equals(useSLabel) || "true".equals(useSLabel) ) ? true : false; // 5.5.1.0 (2012/04/03)
180                    final boolean uslbl = "auto".equalsIgnoreCase( useSLabel ) || "true".equalsIgnoreCase( useSLabel );             // 5.5.1.0 (2012/04/03)
181    //              return selection.getValueLabel( newValue,true );
182                    return selection.getValueLabel( newValue,uslbl );
183            }
184    }