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