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.db.AbstractRenderer; 019import org.opengion.hayabusa.db.CellRenderer; 020import org.opengion.hayabusa.db.DBColumn; 021import org.opengion.hayabusa.db.Selection; 022import org.opengion.hayabusa.db.SelectionFactory; // 5.7.3.0 (2014/02/07) 023 024/** 025 * CHBOX2 レンデラーは、カラムのデータをチェックボックスで表示する場合に使用するクラスです。 026 * 027 * カラムの表示に必要な属性は, DBColumn オブジェクト より取り出します。 028 * このクラスは、DBColumn オブジェクト毎に1つ作成されます。 029 * 030 * 一覧表示する場合は、通常は、□か■に、プラスしてラベルが表示されます。 031 * 表示パラメータの、"useLabel" は、常に、指定されているのと同じ状態です。 032 * 033 * @og.rev 6.4.4.0 (2016/03/11) 新規作成 034 * @og.group データ表示 035 * 036 * @version 6.2 037 * @author Kazuhiko Hasegawa 038 * @since JDK8.0, 039 */ 040public class Renderer_CHBOX2 extends AbstractRenderer { 041 /** このプログラムのVERSION文字列を設定します。 {@value} */ 042 private static final String VERSION = "6.4.9.1 (2016/08/05)" ; 043 044 private final Selection selection ; 045 private final boolean useKeyLabel ; // 6.2.0.0 (2015/02/27) キー:ラベル形式 046 047 /** 048 * デフォルトコンストラクター。 049 * このコンストラクターで、基本オブジェクトを作成します。 050 * 051 * @og.rev 6.4.4.0 (2016/03/11) 新規追加 052 * @og.rev 6.4.9.1 (2016/08/05) useLabel パラメータは常に有効になっている。 053 */ 054 public Renderer_CHBOX2() { 055 super(); // 6.4.1.1 (2016/01/16) PMD refactoring. It is a good practice to call super() in a constructor 056 selection = null; 057 useKeyLabel = true; 058 } 059 060 /** 061 * デフォルトコンストラクター。 062 * 063 * @og.rev 6.4.4.0 (2016/03/11) 新規追加 064 * @og.rev 6.4.6.0 (2016/05/27) getEditorParam → getRendererParam に修正 065 * @og.rev 6.4.9.1 (2016/08/05) useLabel パラメータは常に有効になっている。 066 * 067 * @param clm DBColumnオブジェクト 068 */ 069 private Renderer_CHBOX2( final DBColumn clm ) { 070 super(); // 6.4.1.1 (2016/01/16) PMD refactoring. It is a good practice to call super() in a constructor 071 useKeyLabel = "true".equalsIgnoreCase( clm.getAddKeyLabel() ) ; // 値:ラベル形式 072 073 // CHBOX2 は、コードリソース(selection)が存在しない場合もありうる。 074 final String addKeyLabel = clm.getAddKeyLabel(); // 6.2.0.0 (2015/02/27) キー:ラベル形式 075 selection = SelectionFactory.newSelection( "CHBOX" , clm.getCodeData() , addKeyLabel ); 076 077 } 078 079 /** 080 * 各オブジェクトから自分のインスタンスを返します。 081 * 自分自身をキャッシュするのか、新たに作成するのかは、各サブクラスの実装に 082 * まかされます。 083 * 084 * @og.rev 6.4.4.0 (2016/03/11) 新規追加 085 * 086 * @param clm DBColumnオブジェクト 087 * 088 * @return CellRendererオブジェクト 089 * @og.rtnNotNull 090 */ 091 public CellRenderer newInstance( final DBColumn clm ) { 092 return new Renderer_CHBOX2( clm ); 093 } 094 095 /** 096 * データの表示用文字列を返します。 097 * 098 * @og.rev 6.4.4.0 (2016/03/11) 新規追加 099 * 100 * @param value 入力値 101 * 102 * @return データの表示用文字列 103 * @og.rtnNotNull 104 */ 105 @Override 106 public String getValue( final String value ) { 107 // selection が null の場合もありうる。 108 final String chbox = selection == null 109 ? " ■" + value 110 : selection.getValueLabel( value,true ) ; 111 112 return "<pre class=\"CHBOX\">" + chbox + "</pre>" ; 113 } 114 115 /** 116 * データの一覧表示用文字列を返します。 117 * 一覧表示のため、useLabel が有効です。 118 * 119 * @og.rev 6.4.4.0 (2016/03/11) 新規追加 120 * 121 * @param row 行番号 122 * @param value 入力値 123 * 124 * @return データ表示/編集用の文字列 125 * @og.rtnNotNull 126 */ 127 @Override 128 public String getValue( final int row,final String value ) { 129 // selection が null の場合もありうる。 130 final String chbox = selection == null 131 ? " ■" + value 132 : selection.getValueLabel( value,true ) ; 133 134 return "<pre class=\"CHBOX\">" + chbox + "</pre>" ; 135 } 136 137 /** 138 * データ出力用の文字列を作成します。 139 * ファイル等に出力する形式を想定しますので、HTMLタグを含まない 140 * データを返します。 141 * 基本は、#getValue( String ) をそのまま返します。 142 * 143 * @og.rev 6.4.4.0 (2016/03/11) 新規追加 144 * 145 * @param value 入力値 146 * 147 * @return データ出力用の文字列 148 * @see #getValue( String ) 149 */ 150 @Override 151 public String getWriteValue( final String value ) { 152 // selection が null の場合もありうる。 153 return selection == null 154 ? value 155 : useKeyLabel 156 ? value + ':' + selection.getValueLabel( value,true ) 157 : selection.getValueLabel( value,false ); 158 } 159}