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.db.AbstractRenderer;
019    import org.opengion.hayabusa.db.CellRenderer;
020    import org.opengion.hayabusa.db.DBColumn;
021    
022    import org.opengion.hayabusa.resource.ResourceFactory;
023    import org.opengion.hayabusa.resource.ResourceManager;
024    
025    /**
026     * DBLABEL レンãƒ?ƒ©ーは、å?をラベルリソースの表示ラベルに変換するクラスですã?
027     *
028     * DBMENU で同様ã?処ç�?‚’記述できますが、ラベルリソース に限定した使ã�?–¹ã‚?
029     * 想定してますã?
030     *
031     *  カラãƒ??表示にå¿?¦�な属æ?は, DBColumn オブジェクãƒ?より取り出しますã?
032     * こã?クラスは、DBColumn オブジェクト毎に?‘つ作æ?されますã?
033     *
034     * @og.rev 4.0.0.0 (2006/11/16) 新規作æ?
035     * @og.group ãƒ??タ表示
036     *
037     * @version  4.0
038     * @author   Kazuhiko Hasegawa
039     * @since    JDK5.0,
040     */
041    public class Renderer_DBLABEL extends AbstractRenderer {
042            //* こã?プログラãƒ??VERSIONæ–?­—å?を設定しますã?       {@value} */
043            private static final String VERSION = "4.0.0.0 (2006/11/16)" ;
044    
045            private static final CellRenderer dbCell = new Renderer_DBLABEL() ;
046    
047            private final ResourceManager resource ;
048    
049            /**
050             * ãƒ?ƒ•ォルトコンストラクターã€?
051             * こã?コンストラクターで、基本オブジェクトを作æ?しますã?
052             *
053             */
054            public Renderer_DBLABEL() {
055                    resource = ResourceFactory.newInstance( "ja" );         // 日本語だけ特別
056            }
057    
058            /**
059             * ãƒ?ƒ•ォルトコンストラクターã€?
060             *
061             * @param       clm     DBColumnオブジェクãƒ?
062             */
063            private Renderer_DBLABEL( final DBColumn clm ) {
064                    String lang = clm.getLang();
065                    resource = ResourceFactory.newInstance( lang );
066            }
067    
068            /**
069             * å�?‚ªブジェクトからè?åˆ??インスタンスを返しますã?
070             * 自åˆ??身をキャãƒ?‚·ュするのかã?新たに作æ?するのかã?、各サブクラスの実è£?�«
071             * まかされますã?
072             *
073             * @param       clm     DBColumnオブジェクãƒ?
074             *
075             * @return      CellRendererオブジェクãƒ?
076             */
077            public CellRenderer newInstance( final DBColumn clm ) {
078                    if( "ja".equalsIgnoreCase( clm.getLang() ) ) {
079                            return dbCell ;
080                    }
081    
082                    return new Renderer_DBLABEL( clm );
083            }
084    
085            /**
086             * ãƒ??タの表示用æ–?­—å?を返しますã?
087             *
088             * @param   value 入力å?
089             *
090             * @return  ãƒ??タの表示用æ–?­—å?
091             */
092            @Override
093            public String getValue( final String value ) {
094                    if( value == null || value.length() == 0 ) { return ""; }
095    
096                    return resource.getLabel( value );
097            }
098    }