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.fukurou.util.TagBuffer; 023import org.opengion.fukurou.util.XHTMLTag; 024 025import static org.opengion.fukurou.util.StringUtil.isNull; // 6.1.1.0 (2015/01/17) 026 027/** 028 * COLOR エディターは、カラムのデータをカラーピッカーで選択する場合に使用するクラスです。 029 * 値は#FFFFFFのように#付き7桁で入ります。 030 * 031 * カラムの表示に必要な属性は, DBColumn オブジェクト より取り出します。 032 * このクラスは、DBColumn オブジェクト毎に1つ作成されます。 033 * 034 * @og.group データ編集 035 * 036 * @og.rev 5.5.4.0 (2012/07/02) 新規作成 037 * 038 * @version 4.0 039 * @author Kazuhiko Hasegawa 040 * @since JDK5.0, 041 */ 042public class Editor_COLOR extends AbstractEditor { 043 /** このプログラムのVERSION文字列を設定します。 {@value} */ 044 private static final String VERSION = "6.3.6.1 (2015/08/28)" ; 045 046 // 6.3.6.1 (2015/08/28) style属性のマージ 047 private final String style; 048 049 /** 050 * デフォルトコンストラクター。 051 * このコンストラクターで、基本オブジェクトを作成します。 052 * 053 * @og.rev 3.1.1.1 (2003/04/03) 各オブジェクトから自分のインスタンスを返すファクトリメソッドを追加。 054 * @og.rev 6.3.6.1 (2015/08/28) style属性のマージ。 055 */ 056 public Editor_COLOR() { 057 super(); // 6.4.1.1 (2016/01/16) PMD refactoring. It is a good practice to call super() in a constructor 058 style = null; 059 } 060 061 /** 062 * コンストラクター。 063 * 064 * @og.rev 6.3.6.1 (2015/08/28) style属性のマージ。 065 * 066 * @param clm DBColumnオブジェクト 067 */ 068 private Editor_COLOR( final DBColumn clm ) { 069 super( clm ); 070 style = attributes.remove( "style" ); // 6.3.6.1 (2015/08/28) あれば、キーから削除。 071 072 attributes.add( "class" ,"colorPicker" ); 073 attributes.add( "readonly" ,"readonly" ); 074 tagBuffer.add( XHTMLTag.inputAttri( attributes ) ); 075 } 076 077 /** 078 * 各オブジェクトから自分のインスタンスを返します。 079 * 自分自身をキャッシュするのか、新たに作成するのかは、各サブクラスの実装に 080 * まかされます。 081 * 082 * @param clm DBColumnオブジェクト 083 * 084 * @return CellEditorオブジェクト 085 * @og.rtnNotNull 086 */ 087 public CellEditor newInstance( final DBColumn clm ) { 088 return new Editor_COLOR( clm ); 089 } 090 091 /** 092 * データの編集用文字列を返します。(色付き) 093 * 094 * @og.rev 6.3.6.1 (2015/08/28) style属性のマージ。 095 * 096 * @param value 入力値 097 * 098 * @return データの編集用文字列 099 * @og.rtnNotNull 100 */ 101 @Override 102 public String getValue( final String value ) { 103 // 6.3.6.1 (2015/08/28) style属性のマージ 104 final String inStyle = style == null ? "background-color:"+value+"; color:"+value+";" 105 : style + "background-color:"+value+"; color:"+value+";" ; 106 107 // 6.1.1.0 (2015/01/17) TagBufferの連結記述 108 return new TagBuffer( "input" ) 109 .add( "name" , name ) 110 .add( "id" , name , isNull( attributes.get( "id" ) ) ) // 4.3.7.2 (2009/06/15) 111 .add( "value" , value ) 112 .add( "size" , size1 ) 113 .add( "style" , inStyle ) 114 .add( tagBuffer.makeTag() ) 115 .makeTag(); 116 } 117 118 /** 119 * name属性を変えた、データ表示/編集用のHTML文字列を作成します。(色付き) 120 * テーブル上の name に 行番号を付加して、名前_行番号 で登録するキーを作成し, 121 * リクエスト情報を1つ毎のフィールドで処理できます。 122 * 123 * @og.rev 6.3.6.1 (2015/08/28) style属性のマージ。 124 * 125 * @param row 行番号 126 * @param value 入力値 127 * 128 * @return データ表示/編集用の文字列 129 * @og.rtnNotNull 130 */ 131 @Override 132 public String getValue( final int row,final String value ) { 133 final String newName = name + HybsSystem.JOINT_STRING + row; 134 135 // 6.3.6.1 (2015/08/28) style属性のマージ 136 final String inStyle = style == null ? "background-color:"+value+"; color:"+value+";" 137 : style + "background-color:"+value+"; color:"+value+";" ; 138 139 // 6.1.1.0 (2015/01/17) TagBufferの連結記述 140 return new TagBuffer( "input" ) 141 .add( "name" , newName ) 142 .add( "id" , newName , isNull( attributes.get( "id" ) ) ) // 4.3.7.2 (2009/06/15) 143 .add( "value" , value ) 144 .add( "size" , size2 ) 145 .add( "style" , inStyle ) 146 .add( tagBuffer.makeTag() ) 147 .makeTag( row,value ); 148 } 149}