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.Selection;
023import org.opengion.fukurou.util.XHTMLTag;
024import org.opengion.fukurou.util.Attributes;
025import org.opengion.fukurou.util.TagBuffer;
026
027/**
028 * INMENU エディターは、コードリソースに対応したプルダウンメニューと、
029 * テキストフィールドによる入力の両方をサポートする、編集に使用するクラスです。
030 *
031 * JavaScript によりテキストフィールドとメニュー(コンボボックス)を重ね合わせて
032 * 表示しておき、メニューで選択した値を、テキストフィールドに設定しています。
033 * このエディタを使用するには、jsp/common/inputMenu.js を予め使用できるように
034 * 設定しておく必要があります。
035 *
036 * このエディタはeventColumnに対応していません。
037 *
038 *  カラムの表示に必要な属性は, DBColumn オブジェクト より取り出します。
039 * このクラスは、DBColumn オブジェクト毎に1つ作成されます。
040 *
041 * @og.rev 3.5.6.2 (2004/07/05) 新規作成
042 * @og.group データ編集
043 *
044 * @version  4.0
045 * @author       Kazuhiko Hasegawa
046 * @since    JDK5.0,
047 */
048public class Editor_INMENU extends AbstractEditor {
049        //* このプログラムのVERSION文字列を設定します。   {@value} */
050        private static final String VERSION = "5.6.3.0 (2013/04/01)" ;
051
052        private static final String SEL1 = "<script type=\"text/javascript\">makeInputMenu('" ;
053        private static final String SEL2 = "');</script>" ;
054
055        /** セレクションオブジェクト */
056        protected Selection     selection ;
057        private final boolean addNoValue ;
058        private final boolean seqFlag ;                 // 3.6.0.6 (2004/10/22)
059        private final TagBuffer selTagBuffer = new TagBuffer() ;
060
061        /**
062         * デフォルトコンストラクター。
063         * このコンストラクターで、基本オブジェクトを作成します。
064         *
065         * @og.rev 3.6.0.6 (2004/10/22) シーケンスアクセス機能(seqFlag)を追加します
066         */
067        public Editor_INMENU() {
068                // 4.3.4.4 (2009/01/01)
069                selection = null;
070                addNoValue = false;             // 3.5.5.7 (2004/05/10)
071                seqFlag    = false;             // 3.6.0.6 (2004/10/22)
072        }
073
074        /**
075         * コンストラクター。
076         *
077         * @og.rev 3.6.0.6 (2004/10/22) シーケンスアクセス機能(seqFlag)を追加します
078         * @og.rev 4.0.0.0 (2005/01/31) SelectionFactory ではなく、直接 Selection_CODE を作成。
079         * @og.rev 4.0.0.0 (2006/11/24) TextField分の属性設定
080         * @og.rev 4.0.0.0 (2007/11/07) SelectionオブジェクトをDBColumnから取得
081         * @og.rev 5.6.3.0 (2013/04/01) プルダウンのonChangeの設定場所を変更
082         *
083         * @param       clm     DBColumnオブジェクト
084         */
085        protected Editor_INMENU( final DBColumn clm ) {
086                super( clm );
087                tagBuffer.add( XHTMLTag.inputAttri( attributes ) );
088
089                addNoValue = clm.isAddNoValue() ;               // 3.5.5.7 (2004/05/10)
090                seqFlag    = "SEQ".equals( clm.getEditorParam() );      // 3.6.0.6 (2004/10/22)
091
092                String  disabled = clm.isWritable() ? null : "disabled" ;
093
094                Attributes selAttri = new Attributes();
095                selAttri.set( "disabled" ,disabled );
096
097                selAttri.addAttributes( clm.getEditorAttributes() );
098                
099                selAttri.set( "onChange" ,"selChanged(this);" );        // INMENU 特有のJavaScript 5.6.3.0 (2013/04/01) 場所移動
100                
101                selTagBuffer.add( XHTMLTag.selectAttri( selAttri ) );
102
103                selection = clm.getSelection();                                                 // 4.0.0.0 (2007/11/07)
104        }
105
106        /**
107         * 各オブジェクトから自分のインスタンスを返します。
108         * 自分自身をキャッシュするのか、新たに作成するのかは、各サブクラスの実装に
109         * まかされます。
110         *
111         * @param       clm     DBColumnオブジェクト
112         *
113         * @return      CellEditorオブジェクト
114         */
115        public CellEditor newInstance( final DBColumn clm ) {
116                return new Editor_INMENU( clm );
117        }
118
119        /**
120         * データの編集用文字列を返します。
121         *
122         * @og.rev 3.6.0.6 (2004/10/22) シーケンスアクセス機能(seqFlag)を追加します
123         * @og.rev 3.8.5.3 (2006/06/30) 位置を絶対位置指定(position:absolute;)
124         * @og.rev 4.3.7.2 (2009/06/15) 属性でidが出力される場合は、idを出力しない
125         *
126         * @param       value 入力値
127         *
128         * @return      データの編集用文字列
129         */
130        @Override
131        public String getValue( final String value ) {
132
133                // input タグの作成
134                TagBuffer intag = new TagBuffer( "input" );
135                intag.add( "name"    , name );
136                if( attributes.get( "id" ) == null || attributes.get( "id" ).length() == 0 ) { // 4.3.7.2 (2009/06/15)
137                        intag.add( "id"      , name );          // INMENU 特有のJavaScript用のキー
138                }
139                intag.add( "value"   , value );
140                intag.add( "size"    , size1 );
141                intag.add( tagBuffer.makeTag() );
142                intag.add( optAttr );
143
144                // select タグの作成
145                TagBuffer seltag = new TagBuffer( "select" );
146                seltag.add( "id"      , name + ".sel" );        // INMENU 特有のJavaScript用のキー
147                seltag.add( "style"   , "position:absolute;" ); // 3.8.5.3 (2006/06/30) 位置を絶対位置指定
148                seltag.add( selTagBuffer.makeTag() );
149                seltag.add( optAttr );          // 3.5.5.8 (2004/05/20)
150
151                if( addNoValue ) {
152                        seltag.setBody( Selection.NO_VALUE_OPTION + selection.getOption( value,seqFlag ) );
153                }
154                else {
155                        seltag.setBody( selection.getOption( value,seqFlag ) );
156                }
157
158                return intag.makeTag() + HybsSystem.CR +
159                                seltag.makeTag() + HybsSystem.CR +
160                                SEL1 + name + SEL2;
161        }
162
163        /**
164         * name属性を変えた、データ表示/編集用のHTML文字列を作成します。
165         * テーブル上の name に 行番号を付加して、名前_行番号 で登録するキーを作成し,
166         * リクエスト情報を1つ毎のフィールドで処理できます。
167         *
168         * @og.rev 3.6.0.6 (2004/10/22) シーケンスアクセス機能(seqFlag)を追加します
169         * @og.rev 3.8.5.1 (2006/04/28) makeInputMenu 呼び出し時の引数記述ミスを修正
170         * @og.rev 3.8.5.3 (2006/06/30) 位置を絶対位置指定(position:absolute;)
171         * @og.rev 4.3.7.2 (2009/06/15) 属性でidが出力される場合は、idを出力しない
172         *
173         * @param       row   行番号
174         * @param       value 入力値
175         *
176         * @return      データ表示/編集用の文字列
177         */
178        @Override
179        public String getValue( final int row,final String value ) {
180
181                String name2 = name + HybsSystem.JOINT_STRING + row ;
182
183                // input タグの作成
184                TagBuffer intag = new TagBuffer( "input" );
185                intag.add( "name"    , name2 );
186                if( attributes.get( "id" ) == null || attributes.get( "id" ).length() == 0 ) { // 4.3.7.2 (2009/06/15)
187                        intag.add( "id"      , name2 );         // INMENU 特有のJavaScript用のキー
188                }
189                intag.add( "value"   , value );
190                intag.add( "size"    , size2 );
191                intag.add( tagBuffer.makeTag() );
192                intag.add( optAttr );
193
194                // select タグの作成
195                TagBuffer seltag = new TagBuffer( "select" );
196                seltag.add( "id"      , name2 + ".sel" );               // INMENU 特有のJavaScript用のキー
197                seltag.add( "style"   , "position:absolute;" ); // 3.8.5.3 (2006/06/30) 位置を絶対位置指定
198                seltag.add( selTagBuffer.makeTag() );
199
200                if( addNoValue ) {
201                        seltag.setBody( Selection.NO_VALUE_OPTION + selection.getOption( value,seqFlag ) );
202                }
203                else {
204                        seltag.setBody( selection.getOption( value,seqFlag ) );
205                }
206
207                return intag.makeTag( row,value ) + HybsSystem.CR +
208                                seltag.makeTag( row,value ) + HybsSystem.CR +
209                                SEL1 + name2 + SEL2;
210        }
211}