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 = "7.0.1.0 (2018/10/15)" ; 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 * DBColumnオブジェクトを指定したprivateコンストラクター。 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 * @og.rev 7.0.1.0 (2018/10/15) style属性の作成に、TagBuffer利用。 096 * 097 * @param value 入力値 098 * 099 * @return データの編集用文字列 100 * @og.rtnNotNull 101 */ 102 @Override 103 public String getValue( final String value ) { 104// // 6.3.6.1 (2015/08/28) style属性のマージ 105// final String inStyle = style == null ? "background-color:"+value+"; color:"+value+";" 106// : style + "background-color:"+value+"; color:"+value+";" ; 107 108 // 7.0.1.0 (2018/10/15) style属性の作成に、TagBuffer利用 109 final String inStyle = new TagBuffer().startCss( null ) 110 .addOptions( style ) // null で未登録 111 .add( "background-color" , value ) 112 .add( "color" , value ) 113 .add( "cursor" , "default" ) // 標準のreadonlyを、禁止カーソルにしたため。 114 .makeTag(); 115 116 // 6.1.1.0 (2015/01/17) TagBufferの連結記述 117 return new TagBuffer( "input" ) 118 .add( "name" , name ) 119 .add( "id" , name , isNull( attributes.get( "id" ) ) ) // 4.3.7.2 (2009/06/15) 120 .add( "value" , value ) 121 .add( "size" , size1 ) 122 .add( "style" , inStyle ) 123 .add( tagBuffer.makeTag() ) 124 .makeTag(); 125 } 126 127 /** 128 * name属性を変えた、データ表示/編集用のHTML文字列を作成します。(色付き) 129 * テーブル上の name に 行番号を付加して、名前_行番号 で登録するキーを作成し、 130 * リクエスト情報を1つ毎のフィールドで処理できます。 131 * 132 * @og.rev 6.3.6.1 (2015/08/28) style属性のマージ。 133 * @og.rev 7.0.1.0 (2018/10/15) style属性の作成に、TagBuffer利用。 134 * 135 * @param row 行番号 136 * @param value 入力値 137 * 138 * @return データ表示/編集用の文字列 139 * @og.rtnNotNull 140 */ 141 @Override 142 public String getValue( final int row,final String value ) { 143 final String newName = name + HybsSystem.JOINT_STRING + row; 144 145// // 6.3.6.1 (2015/08/28) style属性のマージ 146// final String inStyle = style == null ? "background-color:"+value+"; color:"+value+";" 147// : style + "background-color:"+value+"; color:"+value+";" ; 148 149 // 7.0.1.0 (2018/10/15) style属性の作成に、TagBuffer利用 150 final String inStyle = new TagBuffer().startCss( null ) 151 .addOptions( style ) // null で未登録 152 .add( "background-color" , value ) 153 .add( "color" , value ) 154 .add( "cursor" , "default" ) // 標準のreadonlyを、禁止カーソルにしたため。 155 .makeTag(); 156 157 // 6.1.1.0 (2015/01/17) TagBufferの連結記述 158 return new TagBuffer( "input" ) 159 .add( "name" , newName ) 160 .add( "id" , newName , isNull( attributes.get( "id" ) ) ) // 4.3.7.2 (2009/06/15) 161 .add( "value" , value ) 162 .add( "size" , size2 ) 163 .add( "style" , inStyle ) 164 .add( tagBuffer.makeTag() ) 165 .makeTag( row,value ); 166 } 167}