Published — v. 5
/
カスタムフォーマッターの実装
カスタムフォーマッターの実装
カスタムフォーマッターは、「com.hof.mi.interfaces.CustomFormatter」classの実装です。このclassには、以下の関数を実装しなくてはいけません。
これらのメソッドは、必要に応じて上書きすることができます。
関数定義
public abstract String getName();
このメソッドは、カスタムフォーマッターの名前をStringとして返します。これは、ユーザーがフォーマッターを選択する際に表示される名前です。例:
public String getName() { return "My Formatter"; }
public abstract boolean acceptsNativeType(int type);
このメソッドは、フォーマッターが与えられたデータ型のフィールドをサポートする場合にtrueを返し、それ以外にはfalseを返します。サポートされている型の一覧は、付録に掲載されています。
例1:
public boolean acceptsNativeType(int type) { //accept text and numeric data if (type == TYPE_TEXT || type == TYPE_NUMERIC) { return true; } else { //don't allow any other types return false; } }
例2:
public boolean acceptsNativeType(int type) { // we can handle any type return true; }
public abstract String render(Object value, int renderType) throws Exception;
このメソッドは、単一の値を表示します。「renderType引数」は、レンダリングする出力型を決定します。Yellowfinは、書式設定されたカラム(列)のすべての値に対してこの関数を実行します。「renderTypeパラメーター」は、値の表示方法に関するヒントを提供します。PDF/XLS形式でドキュメントを出力する場合は、「RENDER_TEXT」型が使用されます。利用可能な「renderType」値の一覧は、付録に掲載されています。
public String render(Object value, int renderType) throws Exception { if (value == null) return null if (renderType == RENDER_LINK) // Render the value for a drill-through link. // In this case you almost always want to return a generic // representation of the value. return value.toString(); } // Return the formatted value return "Value: " + value.toString(); }
public boolean returnsHtml();
これは、フォーマッターに返される値がHTMLを含む場合はtrue、含まない場合はfalseを返します。デフォルトでは、この関数はfalseを返します。
public boolean compareConditionalAgainstFormattedValue();
この関数は、このフォーマッターを使用するフィールドが条件付き書式と書式設定された値を比較する必要がある場合はtrue、それ以外の場合はfalseを返します。デフォルトでは、この関数はfalseを返します。