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// 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}