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.fukurou.util.XHTMLTag;
023    import org.opengion.fukurou.util.TagBuffer;
024    
025    /**
026     * HM エãƒ?‚£ã‚¿ãƒ¼ã¯ã€ã‚«ãƒ©ãƒ??ãƒ??タを時åˆ?·¨é›?™ã‚‹å?åˆã«ä½¿ç”¨ã™ã‚‹ã‚¯ãƒ©ã‚¹ã§ã™ã?
027     * é¸æŠžç”¨ãƒ”ãƒƒã‚«ãƒ¼ãŒä»˜å±žã—ã¾ã™ã?
028     * 
029     * optionã¨ã—ã¦ã€æ¬¡ã®é ?›®ã‚’EditParamã§ã‚«ãƒ³ãƒžåŒºåˆ?‚Šã§æŒ?®šå¯èƒ½ã§ã™ã?
030     * ex) 6,19,4,true
031     * starthour            ?šãƒ”ãƒ?‚«ãƒ¼ã®é–‹å§‹æ™‚é–?0-23)
032     * endhour                      ?šãƒ”ãƒ?‚«ãƒ¼ã®çµ‚äº?™‚é–?0-23)
033     * minutedivisions      ?šå˜ä½ã?åˆ??ã®åˆ?‰²æ•°ã€?ãªã‚?5åˆ?˜ä½ã?(2-60)
034     * showminutes          ?šå?ピッカーã®è¡¨ç¤º(true/false)
035     * 
036     * ã“ã?エãƒ?‚£ã‚¿ã¯eventColumnã«å¯¾å¿œã—ã¦ã?¾ã›ã‚“ã€?
037     *
038     *  カラãƒ??表示ã«å¿?¦ãªå±žæ?ã¯, DBColumn オブジェクãƒ?よりå–り出ã—ã¾ã™ã?
039     * ã“ã?クラスã¯ã€DBColumn オブジェクト毎ã«?‘ã¤ä½œæ?ã•れã¾ã™ã?
040     *
041     * @og.rev 5.6.5.2 (2013/06/21) æ–°è¦ä½œæ?
042     * @og.group �?タ編�
043     *
044     * @version  5.0
045     * @author   Takahashi Masakazu
046     * @since    JDK6.0,
047     */
048    public class Editor_HM extends AbstractEditor {
049            //* ã“ã?プログラãƒ??VERSIONæ–?­—å?を設定ã—ã¾ã™ã?       {@value} */
050            private static final String VERSION = "5.6.5.2 (2013/06/21)" ;
051    
052            private static final String PIC1 = "<img src=\"../image/clock.png\" class=\"clockpick\"  valuefield=\""; // altã¯ä»˜ã‘ãªã?
053            private static final String PIC2 = " />";
054            
055            private static final String OPT1 = "starthour=\"";
056            private static final String OPT2 = "endhour=\"";
057            private static final String OPT3 = "minutedivisions=\"";
058            private static final String OPT4 = "showminutes=\"";
059            private static final String END_ATTR = "\" ";
060            
061            private final String options;
062    
063            /**
064             * ãƒ?ƒ•ォルトコンストラクターã€?
065             * ã“ã?コンストラクターã§ã€åŸºæœ¬ã‚ªãƒ–ジェクトを作æ?ã—ã¾ã™ã?
066             *
067             */
068            public Editor_HM() {
069                    // 4.3.4.4 (2009/01/01)
070    //              super();
071                    options = null;
072            }
073    
074            /**
075             * コンストラクター�
076             *
077             * @param       clm     DBColumnオブジェク�
078             */
079            private Editor_HM( final DBColumn clm ) {
080                    super( clm );
081                    options = createOptions(clm.getEditorParam());
082                    tagBuffer.add( XHTMLTag.inputAttri( attributes ) );
083            }
084    
085            /**
086             * å?‚ªãƒ–ジェクトã‹ã‚‰è?åˆ??インスタンスを返ã—ã¾ã™ã?
087             * 自åˆ??身をキャãƒ?‚·ãƒ¥ã™ã‚‹ã®ã‹ã?æ–°ãŸã«ä½œæ?ã™ã‚‹ã®ã‹ã?ã€å„サブクラスã®å®Ÿè£?«
088             * ã¾ã‹ã•れã¾ã™ã?
089             *
090             * @param       clm     DBColumnオブジェク�
091             *
092             * @return      CellEditorオブジェク�
093             */
094            public CellEditor newInstance( final DBColumn clm ) {
095                    return new Editor_HM( clm );
096            }
097    
098            /**
099             * ãƒ??ã‚¿ã®ç·¨é›?”¨æ–?­—å?ã‚’è¿”ã—ã¾ã™ã?
100             *
101             *
102             * @param       value 入力å?
103             *
104             * @return      ãƒ??ã‚¿ã®ç·¨é›?”¨æ–?­—å?
105             */
106            @Override
107            public String getValue( final String value ) {
108                    TagBuffer tag = new TagBuffer( "input" );
109                    tag.add( "name"    , name );
110                    if( attributes.get( "id" ) == null || attributes.get( "id" ).length() == 0 ) { // 4.3.7.2 (2009/06/15)
111                            tag.add( "id"      , name );
112                    }
113                    tag.add( "value"   , value );
114                    tag.add( "size"    , size1 );
115                    tag.add( tagBuffer.makeTag() );
116                    tag.add( optAttr );             
117    
118                    return tag.makeTag() + PIC1 + name + END_ATTR + options + PIC2 ;
119            }
120    
121            /**
122             * name属æ?を変ãˆãŸã?ãƒ??タ表示/ç·¨é›?”¨ã®HTMLæ–?­—å?を作æ?ã—ã¾ã™ã?
123             * ãƒ??ブル上ã? name 㫠行番å·ã‚’付加ã—ã¦ã€åå‰_è¡Œç•ªå· ã§ç™»éŒ²ã™ã‚‹ã‚­ãƒ¼ã‚’作æ?ã?
124             * ãƒªã‚¯ã‚¨ã‚¹ãƒˆæƒ…å ±ã‚’ï¼‘ã¤æ¯Žã?フィールドã§å‡¦ç?§ãã¾ã™ã?
125             *
126             * @param       row   行番å·
127             * @param       value 入力å?
128             *
129             * @return      ãƒ??タ表示/ç·¨é›?”¨ã®æ–?­—å?
130             */
131            @Override
132            public String getValue( final int row,final String value ) {
133                    TagBuffer tag = new TagBuffer( "input" );
134                    String name2 =  name + HybsSystem.JOINT_STRING + row ;
135                    tag.add( "name"    , name2);
136                    if( attributes.get( "id" ) == null || attributes.get( "id" ).length() == 0 ) { // 4.3.7.2 (2009/06/15)
137                            tag.add( "id"      , name2);
138                    }
139                    tag.add( "value"   , value );
140                    tag.add( "size"    , size2 );
141                    tag.add( tagBuffer.makeTag() );
142                    tag.add( optAttr );             // 3.5.5.8 (2004/05/20)
143    
144                    return tag.makeTag( row,value ) + PIC1 + name2 + END_ATTR + options + PIC2 ;
145            }
146    
147            /**
148             * ç·¨é›?ƒ‘ラメータã‹ã‚‰ã€ã‚ªãƒ—ションæ–?­—å?を作æ?ã—ã¾ã™ã?
149             * ç·¨é›?ƒ‘ラメータã¯ã€starthour , endhour , minutedivisions , showminutes ã®é ?«ã€?
150             * カンマ区åˆ?‚Šæ–?­—å?ã§ä¸Žãˆã¾ã™ã?
151             * å¤‰æ•°ã®æ•°ãŒå°‘ãªã??åˆã?ã€å?期å?ãŒè¨­å®šã•れã¾ã™ã?
152             * åˆæœŸå€¤ã¯ã€starthour="6" endhour="20" minutedivisions="4" showminutes="true" ã§ã™ã?
153             *
154             * @param       editPrm  ç·¨é›?ƒ‘ラメータ
155             *
156             * @return      パラメータã®ã‚ªãƒ—ションæ–?­—å?
157             */
158            private String createOptions( final String editPrm ){
159                    if( editPrm == null){ return "" ;}
160                    String[] param = (editPrm == null) ? new String[0] : editPrm.split( "," ) ;
161                    String start = (param.length > 0) ? param[0].trim() : "6" ;
162                    String end   = (param.length > 1) ? param[1].trim() : "20" ;
163                    String step  = (param.length > 2) ? param[2].trim() : "4" ;
164                    String min   = (param.length > 3) ? param[3].trim() : "true" ;
165                    
166                    return OPT1 + start + END_ATTR + OPT2 + end + END_ATTR + OPT3 + step + END_ATTR + OPT4 + min + END_ATTR;
167            }
168    }