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.SelectionCellEditor; // 6.2.2.0 (2015/03/27) 023import org.opengion.hayabusa.db.Selection; 024import org.opengion.hayabusa.db.SelectionFactory; // 5.7.3.0 (2014/02/07) 025import org.opengion.fukurou.util.Attributes; 026import org.opengion.fukurou.util.TagBuffer; 027import org.opengion.fukurou.util.XHTMLTag; 028 029/** 030 * BITBOX エディターは、カラムのデータをコードリソースに対応した 031 * チェックボックスで編集する場合に使用するクラスです。 032 * このチェックボックスは、複数選択されたコードリソースの値を、 033 * BIT演算で、論理和した結果のデータで管理します。 034 * 035 * 一覧登録する場合は、チェックボックスのみ表示されます。 036 * ラベル表示が必要な場合は、編集パラメータに、"useLabel"と 037 * 記述しておくことで、ラベルを出力することが可能です。 038 * 039 * 例) 040 * コードリソースには、1,2,4,8,… とBitを表す数を指定します。 041 * これを、チェックボックスで複数選択し、値を論理和で加算します。 042 * 043 * このエディタはeventColumnに対応していません。 044 * 045 * カラムの表示に必要な属性は, DBColumn オブジェクト より取り出します。 046 * このクラスは、DBColumn オブジェクト毎に1つ作成されます。 047 * 048 * @og.rev 6.2.2.4 (2015/04/24) 新規作成 049 * @og.group データ編集 050 * 051 * @version 6.2 052 * @author Kazuhiko Hasegawa 053 * @since JDK8.0, 054 */ 055public class Editor_BITBOX extends AbstractEditor implements SelectionCellEditor { 056 /** このプログラムのVERSION文字列を設定します。 {@value} */ 057 private static final String VERSION = "6.4.4.2 (2016/04/01)" ; 058 059 private final Selection selection ; 060 private final boolean writable ; 061 private final boolean useLabel ; // 4.3.3.0 (2008/10/01) 062 063 private String errMsg ; // 6.0.4.0 (2014/11/28) 064 065 /** 066 * デフォルトコンストラクター。 067 * このコンストラクターで、基本オブジェクトを作成します。 068 * 069 * @og.rev 6.2.2.4 (2015/04/24) 新規追加 070 */ 071 public Editor_BITBOX() { 072 super(); // 6.4.1.1 (2016/01/16) PMD refactoring. It is a good practice to call super() in a constructor 073 selection = null; 074 writable = false; 075 useLabel = false; // 4.3.3.0 (2008/10/01) 076 } 077 078 /** 079 * コンストラクター。 080 * 081 * @og.rev 6.2.2.4 (2015/04/24) 新規追加 082 * @og.rev 6.4.4.2 (2016/04/01) nameのfinal化 083 * 084 * @param clm DBColumnオブジェクト 085 */ 086 private Editor_BITBOX( final DBColumn clm ) { 087 // super(); // 6.4.1.1 (2016/01/16) PMD refactoring. It is a good practice to call super() in a constructor 088 super( clm ); // 6.4.4.2 (2016/04/01) nameのfinal化 089 // name = clm.getName(); 090 091 final String addKeyLabel = clm.getAddKeyLabel(); // 6.2.0.0 (2015/02/27) キー:ラベル形式 092 093 // 5.7.3.0 (2014/02/07) SelectionFactory 対応 094 selection = SelectionFactory.newSelection( "BITBOX" , clm.getCodeData(), addKeyLabel ); 095 096 // 6.0.4.0 (2014/11/28) selection が null の場合、警告表示します。 097 if( selection == null ) { 098 errMsg = "codeData が未設定です。" 099 + " name=" + name 100 + " label=" + clm.getLabel() 101 + " editType=" + clm.getEditor() ; 102 System.out.println( errMsg ); 103 } 104 105 writable = clm.isWritable(); 106 107 // 6.1.1.0 (2015/01/17) Attributesの連結記述 108 attributes = new Attributes() 109 .set( clm.getEditorAttributes() ) // #addAttributes( Attributes ) の代替え 110 .add( "class","BITBOX" ); 111 112 // 6.1.1.0 (2015/01/17) TagBufferの連結記述 113 tagBuffer.add( XHTMLTag.inputAttri( attributes ) ) 114 .add( attributes.get( "optionAttributes" ) ); // 6.0.4.0 (2014/11/28) 115 116 // 4.3.3.0 (2008/10/01) 117 useLabel = "useLabel".equalsIgnoreCase( clm.getEditorParam() ) ; 118 } 119 120 /** 121 * 各オブジェクトから自分のインスタンスを返します。 122 * 自分自身をキャッシュするのか、新たに作成するのかは、各サブクラスの実装に 123 * まかされます。 124 * 125 * @og.rev 6.2.2.4 (2015/04/24) 新規追加 126 * 127 * @param clm DBColumnオブジェクト 128 * 129 * @return CellEditorオブジェクト 130 * @og.rtnNotNull 131 */ 132 public CellEditor newInstance( final DBColumn clm ) { 133 return new Editor_BITBOX( clm ); 134 } 135 136 /** 137 * データの編集用文字列を返します。 138 * 139 * @og.rev 6.2.2.4 (2015/04/24) 新規追加 140 * 141 * @param value 入力値 142 * 143 * @return データの編集用文字列 144 * @og.rtnNotNull 145 */ 146 @Override 147 public String getValue( final String value ) { 148 // 6.0.4.0 (2014/11/28) selection が null の場合、警告表示します。 149 if( selection == null ) { 150 return "<span class=\"error\">" + errMsg + " value=" + value + "</span>"; 151 } 152 153 // 6.4.1.1 (2016/01/16) 3項演算子で対応。 154 final String bitbox = writable 155 ? selection.getOption( name,value,true ) 156 : selection.getValueLabel( value,true ); 157 158 // 6.1.1.0 (2015/01/17) TagBufferの連結記述 159 return new TagBuffer( "pre" ) 160 .add( tagBuffer.makeTag() ) 161 .addBody( bitbox ) 162 .makeTag(); 163 } 164 165 /** 166 * name属性を変えた、データ表示/編集用のHTML文字列を作成します。 167 * テーブル上の name に 行番号を付加して、名前_行番号 で登録するキーを作成し, 168 * リクエスト情報を1つ毎のフィールドで処理できます。 169 * 170 * @og.rev 6.2.2.4 (2015/04/24) 新規追加 171 * 172 * @param row 行番号 173 * @param value 入力値 174 * 175 * @return データ表示/編集用の文字列 176 * @og.rtnNotNull 177 */ 178 @Override 179 public String getValue( final int row,final String value ) { 180 // 6.0.4.0 (2014/11/28) selection が null の場合、警告表示します。 181 if( selection == null ) { 182 return "<span class=\"error\">" + errMsg + " value=" + value + " row=" + row + "</span>"; 183 } 184 185 // 6.4.1.1 (2016/01/16) 3項演算子で対応。 186 final String bitbox = writable 187 ? selection.getOption( name + HybsSystem.JOINT_STRING + row,value,useLabel ) 188 : selection.getValueLabel( value,useLabel ); 189 190 // 6.1.1.0 (2015/01/17) TagBufferの連結記述 191 return new TagBuffer( "pre" ) 192 .add( tagBuffer.makeTag() ) 193 .addBody( bitbox ) 194 .makeTag( row,value ); 195 } 196}