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 java.util.UUID; 019 020import org.opengion.fukurou.util.StringUtil; 021import org.opengion.fukurou.util.TagBuffer; 022import org.opengion.hayabusa.db.AbstractRenderer; 023import org.opengion.hayabusa.db.CellRenderer; 024import org.opengion.hayabusa.db.DBColumn; 025 026/** 027 * TEXTAREA レンデラは、カラムのデータをリッチテキストで表示する場合に 028 * 使用するクラスです。 029 * readonlyのテキストエリアでname属性は付けません。(データは送信されません) 030 * エリアの縦、横サイズはエディタのリッチテキストと同様にして算出されます。 031 * 032 * カラムの表示に必要な属性は, DBColumn オブジェクト より取り出します。 033 * このクラスは、DBColumn オブジェクト毎に1つ作成されます。 034 * 035 * @og.rev 5.9.32.0 (2018/05/02) 新規作成 036 * @og.group データ編集 037 * 038 * @version 4.0 039 * @author Takahashi Masakazu 040 * @since JDK5.0, 041 */ 042public class Renderer_RICHTEXT extends AbstractRenderer { 043 //* このプログラムのVERSION文字列を設定します。 {@value} */ 044 private static final String VERSION = "4.3.5.7 (2009/03/22)" ; 045 046 private final TagBuffer tagBuffer = new TagBuffer(); 047 048 private String size1; 049 private String size2; 050 051 /** 052 * デフォルトコンストラクター。 053 * このコンストラクターで、基本オブジェクトを作成します。 054 * 055 */ 056 public Renderer_RICHTEXT() { 057 // 何もありません。(super を呼び出しません) 058 } 059 060 // デフォルトの値設定 061 private void defaultSet() { 062 size1 = "150"; 063 size2 = "300"; 064 } 065 066 /** 067 * コンストラクター 068 * textareaのサイズを決めるため、sizeとrowを決定する 069 * editorの計算を移植。 070 * 071 * @param clm DBColumnオブジェクト 072 */ 073 private Renderer_RICHTEXT( final DBColumn clm ) { 074 // size に、"height,width" を指定できるように変更 075 String param = StringUtil.nval( clm.getEditorParam(),clm.getViewLength() ); 076 if( param != null && param.length() != 0 ) { 077 int st = param.indexOf( ',' ); 078 if( st > 0 ) { 079 size1 = param.substring( 0, st ); 080 size2 = param.substring( st + 1); 081 }else { 082 defaultSet(); 083 } 084 }else { 085 defaultSet(); 086 } 087 } 088 089 /** 090 * 各オブジェクトから自分のインスタンスを返します。 091 * 自分自身をキャッシュするのか、新たに作成するのかは、各サブクラスの実装に 092 * まかされます。 093 * 094 * @param clm DBColumnオブジェクト 095 * 096 * @return CellEditorオブジェクト 097 */ 098 public CellRenderer newInstance( final DBColumn clm ) { 099 return new Renderer_RICHTEXT( clm ); 100 } 101 102 /** 103 * データの表示用文字列を返します。 104 * 105 * @param value 入力値 106 * 107 * @return データの表示用文字列 108 */ 109 @Override 110 public String getValue( final String value ) { 111 // uuidをidとして使用する 112 String uuid = UUID.randomUUID().toString(); 113 114 TagBuffer tag = new TagBuffer( "textarea" ); 115 tag.add( "id" , uuid); 116 tag.add( tagBuffer.makeTag() ); 117 tag.setBody( value ); 118 119 return tag.makeTag() + createCLEditorSc(uuid); 120 } 121 122 /** 123 * データの表示用文字列を返します。 124 * 125 * @param row 行番号 126 * @param value 入力値 127 * 128 * @return データ表示用の文字列 129 */ 130 @Override 131 public String getValue( final int row,final String value ) { 132 // uuidをidとして使用する 133 String uuid = UUID.randomUUID().toString(); 134 TagBuffer tag = new TagBuffer( "textarea" ); 135 tag.add( "id" , uuid); 136 tag.add( tagBuffer.makeTag() ); 137 tag.setBody( value ); 138 139 return tag.makeTag( row,value ) + createCLEditorSc(uuid); 140 } 141 142 // CLEditorスクリプトの生成 143 private String createCLEditorSc(String id) { 144 StringBuilder js = new StringBuilder(); 145 js.append("<script type='text/javascript'>"); 146 js.append("var trg = $('#").append(id).append("').cleditor({"); 147 js.append("height:").append(size1); 148 js.append(",width:").append(size2); 149 js.append(",controls:''"); 150 js.append(",bodyStyle:'background-color: transparent;'})[0];"); 151 js.append("trg.disable('true');"); // 操作の無効化 152 js.append("trg.$toolbar.remove();"); // メニューバーの削除 153 js.append("trg.$main.css('background-color','transparent');"); // bodyのstyle設定 154 // linkは新規ウィンドウに表示 155 js.append("$('#").append(id).append("').next('iframe').contents().find('a').attr('target','_blank');"); 156 js.append("</script>"); 157 return js.toString(); 158 } 159}