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     */
016    package org.opengion.plugin.column;
017    
018    import org.opengion.hayabusa.common.HybsSystem;
019    import org.opengion.hayabusa.db.AbstractEditor;
020    import org.opengion.hayabusa.db.CellEditor;
021    import org.opengion.hayabusa.db.DBColumn;
022    import org.opengion.hayabusa.db.Selection;
023    import org.opengion.fukurou.util.XHTMLTag;
024    import org.opengion.fukurou.util.Attributes;
025    import 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 オブジェクト毎に?つ作?されます?
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     */
048    public 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    //              super();
070                    selection = null;
071                    addNoValue = false;             // 3.5.5.7 (2004/05/10)
072                    seqFlag    = false;             // 3.6.0.6 (2004/10/22)
073            }
074    
075            /**
076             * コンストラクター?
077             *
078             * @og.rev 3.6.0.6 (2004/10/22) シーケンスアクセス機?(seqFlag)を追?ま?
079             * @og.rev 4.0.0.0 (2005/01/31) SelectionFactory ではなく?直接 Selection_CODE を作??
080             * @og.rev 4.0.0.0 (2006/11/24) TextField??属?設?
081             * @og.rev 4.0.0.0 (2007/11/07) SelectionオブジェクトをDBColumnから取?
082             * @og.rev 5.6.3.0 (2013/04/01) プル?ンのonChangeの設定??変更
083             *
084             * @param       clm     DBColumnオブジェク?
085             */
086            protected Editor_INMENU( final DBColumn clm ) {
087                    super( clm );
088                    tagBuffer.add( XHTMLTag.inputAttri( attributes ) );
089    
090                    addNoValue = clm.isAddNoValue() ;               // 3.5.5.7 (2004/05/10)
091                    seqFlag    = "SEQ".equals( clm.getEditorParam() );      // 3.6.0.6 (2004/10/22)
092    
093                    String  disabled = clm.isWritable() ? null : "disabled" ;
094    
095                    Attributes selAttri = new Attributes();
096                    selAttri.set( "disabled" ,disabled );
097    //              selAttri.set( "onChange" ,"selChanged(this);" );        // INMENU 特有?JavaScript
098    
099                    selAttri.addAttributes( clm.getEditorAttributes() );
100                    
101                    selAttri.set( "onChange" ,"selChanged(this);" );        // INMENU 特有?JavaScript 5.6.3.0 (2013/04/01) 場??
102                    
103                    selTagBuffer.add( XHTMLTag.selectAttri( selAttri ) );
104    
105                    selection = clm.getSelection();                                                 // 4.0.0.0 (2007/11/07)
106            }
107    
108            /**
109             * ?ブジェクトから???インスタンスを返します?
110             * 自??身をキャ?ュするのか?新たに作?するのか?、各サブクラスの実?
111             * まかされます?
112             *
113             * @param       clm     DBColumnオブジェク?
114             *
115             * @return      CellEditorオブジェク?
116             */
117            public CellEditor newInstance( final DBColumn clm ) {
118                    return new Editor_INMENU( clm );
119            }
120    
121            /**
122             * ??タの編???を返します?
123             *
124             * @og.rev 3.6.0.6 (2004/10/22) シーケンスアクセス機?(seqFlag)を追?ま?
125             * @og.rev 3.8.5.3 (2006/06/30) 位置を絶対位置??position:absolute;)
126             * @og.rev 4.3.7.2 (2009/06/15) 属?でidが?力される場合?、idを?力しな?
127             *
128             * @param       value 入力?
129             *
130             * @return      ??タの編???
131             */
132            @Override
133            public String getValue( final String value ) {
134    
135                    // input タグの作?
136                    TagBuffer intag = new TagBuffer( "input" );
137                    intag.add( "name"    , name );
138                    if( attributes.get( "id" ) == null || attributes.get( "id" ).length() == 0 ) { // 4.3.7.2 (2009/06/15)
139                            intag.add( "id"      , name );          // INMENU 特有?JavaScript用のキー
140                    }
141                    intag.add( "value"   , value );
142                    intag.add( "size"    , size1 );
143                    intag.add( tagBuffer.makeTag() );
144                    intag.add( optAttr );
145    
146                    // select タグの作?
147                    TagBuffer seltag = new TagBuffer( "select" );
148                    seltag.add( "id"      , name + ".sel" );        // INMENU 特有?JavaScript用のキー
149                    seltag.add( "style"   , "position:absolute;" ); // 3.8.5.3 (2006/06/30) 位置を絶対位置??
150                    seltag.add( selTagBuffer.makeTag() );
151                    seltag.add( optAttr );          // 3.5.5.8 (2004/05/20)
152    
153                    if( addNoValue ) {
154                            seltag.setBody( Selection.NO_VALUE_OPTION + selection.getOption( value,seqFlag ) );
155                    }
156                    else {
157                            seltag.setBody( selection.getOption( value,seqFlag ) );
158                    }
159    
160                    return intag.makeTag() + HybsSystem.CR +
161                                    seltag.makeTag() + HybsSystem.CR +
162                                    SEL1 + name + SEL2;
163            }
164    
165            /**
166             * name属?を変えた???タ表示/編?のHTML??を作?します?
167             * ??ブル上? name に 行番号を付加して、名前_行番号 で登録するキーを作??
168             * リクエスト情報を1つ毎?フィールドで処?きます?
169             *
170             * @og.rev 3.6.0.6 (2004/10/22) シーケンスアクセス機?(seqFlag)を追?ま?
171             * @og.rev 3.8.5.1 (2006/04/28) makeInputMenu 呼び出し時の引数記述ミスを修正
172             * @og.rev 3.8.5.3 (2006/06/30) 位置を絶対位置??position:absolute;)
173             * @og.rev 4.3.7.2 (2009/06/15) 属?でidが?力される場合?、idを?力しな?
174             *
175             * @param       row   行番号
176             * @param       value 入力?
177             *
178             * @return      ??タ表示/編?の??
179             */
180            @Override
181            public String getValue( final int row,final String value ) {
182    
183                    String name2 = name + HybsSystem.JOINT_STRING + row ;
184    
185                    // input タグの作?
186                    TagBuffer intag = new TagBuffer( "input" );
187                    intag.add( "name"    , name2 );
188                    if( attributes.get( "id" ) == null || attributes.get( "id" ).length() == 0 ) { // 4.3.7.2 (2009/06/15)
189                            intag.add( "id"      , name2 );         // INMENU 特有?JavaScript用のキー
190                    }
191                    intag.add( "value"   , value );
192                    intag.add( "size"    , size2 );
193                    intag.add( tagBuffer.makeTag() );
194                    intag.add( optAttr );
195    
196                    // select タグの作?
197                    TagBuffer seltag = new TagBuffer( "select" );
198                    seltag.add( "id"      , name2 + ".sel" );               // INMENU 特有?JavaScript用のキー
199                    seltag.add( "style"   , "position:absolute;" ); // 3.8.5.3 (2006/06/30) 位置を絶対位置??
200                    seltag.add( selTagBuffer.makeTag() );
201    
202                    if( addNoValue ) {
203                            seltag.setBody( Selection.NO_VALUE_OPTION + selection.getOption( value,seqFlag ) );
204                    }
205                    else {
206                            seltag.setBody( selection.getOption( value,seqFlag ) );
207                    }
208    
209                    return intag.makeTag( row,value ) + HybsSystem.CR +
210                                    seltag.makeTag( row,value ) + HybsSystem.CR +
211                                    SEL1 + name2 + SEL2;
212            }
213    }