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                // 4.3.4.4 (2009/01/01)
053//              super();
054        }
055
056        /**
057         * コンストラクター。
058         *
059         * @param       clm     DBColumnオブジェクト
060         */
061        private Editor_COLOR( final DBColumn clm ) {
062                super( clm );
063                attributes.add( "class"        ,"colorPicker" );
064                attributes.add( "readonly"        ,"readonly" );
065                tagBuffer.add( XHTMLTag.inputAttri( attributes ) );
066        }
067
068        /**
069         * 各オブジェクトから自分のインスタンスを返します。
070         * 自分自身をキャッシュするのか、新たに作成するのかは、各サブクラスの実装に
071         * まかされます。
072         *
073         * @param       clm     DBColumnオブジェクト
074         *
075         * @return      CellEditorオブジェクト
076         */
077        public CellEditor newInstance( final DBColumn clm ) {
078                return new Editor_COLOR( clm );
079        }
080
081        /**
082         * データの編集用文字列を返します。(色付き)
083         *
084         * @param       value 入力値
085         *
086         * @return      データの編集用文字列
087         */
088        @Override
089        public String getValue( final String value ) {
090
091                TagBuffer tag = new TagBuffer( "input" );
092                tag.add( "name"    , name );
093                if( attributes.get( "id" ) == null || attributes.get( "id" ).length() == 0 ) {
094                        tag.add( "id"      , name );
095                }
096                tag.add( "value"   , value );
097                tag.add( "size"    , size1 );
098                tag.add( "style" , "background-color:"+value+"; color:"+value+";" );
099                tag.add( tagBuffer.makeTag() );
100                tag.add( optAttr );
101
102                return tag.makeTag();
103        }
104
105        /**
106         * name属性を変えた、データ表示/編集用のHTML文字列を作成します。(色付き)
107         * テーブル上の name に 行番号を付加して、名前_行番号 で登録するキーを作成し,
108         * リクエスト情報を1つ毎のフィールドで処理できます。
109         *
110         * @param       row   行番号
111         * @param       value 入力値
112         *
113         * @return      データ表示/編集用の文字列
114         */
115        @Override
116        public String getValue( final int row,final String value ) {
117                TagBuffer tag = new TagBuffer( "input" );
118                String newName = name + HybsSystem.JOINT_STRING + row;
119                tag.add( "name"  , newName );
120                if( attributes.get( "id" ) == null || attributes.get( "id" ).length() == 0 ) {
121                        tag.add( "id"    , newName );
122                }
123                tag.add( "value"   , value );
124                tag.add( "size"    , size2 );
125                tag.add( "style" , "background-color:"+value+"; color:"+value+";" );
126                tag.add( tagBuffer.makeTag() );
127                tag.add( optAttr );
128
129                return tag.makeTag( row,value );
130        }
131}