[JAVA] Create a Yellowfin custom formatter and display the minus of the number as △ (triangle)

In some cases, negative numbers are written as "△ 100,000" in accounting materials. Yellowfin can achieve this with ** Custom Formatter **.

** Yellowfin plugins ** such as custom formatters are developed in Java. This time, I am using Eclipse (Pleiades which is a Japanese version of Eclipse).

The development method is described in Yellowfin's online manual. Basics of plugin development Creating a custom formatter In this article, we will proceed while folding, so please refer to the manual as appropriate.

Creating a Java project

Create a new Java project. Even if the Java version is 7, it is written in the manual, so JRE should select java7. .. image001.png

Click Next and change the Default Output Folder to ** / ROOT / WEB-INF / classes **. image002.png

Right-click on the project and select Import. image003.png

Select File System and click Next. image004.png

** Go to / appserver / webapps / ROOT **. Select ROOT and click Open. image005.png

Select everything under ROOT and check the "Create links in workspace" checkbox in the "Extended" item. image006.png

Project structure

Right-click on the project and select Build Path> Configure Build Path from the menu. image007.png

Click Library. image008.png

Click the Add JAR button and enter i4 in the search bar. Select "i4-core.jar" and "i4-mi.jar" from the search results. image009.png

Create a new folder with the name ** META-INF ** under the src folder. Create a new folder named ** services ** under that folder. image010.png image011.png

Create a file called ** com.hof.mi.interfaces.CustomFormatter ** under the services folder. image012.png image013.png

Write com.company.yellowfin.formatters.SankakuFormatter in the created file. This will be the fully qualified class name of the custom formatter you create. image014.png

Creating a custom formatter

Right-click on the project and select New> Package. Name the new package ** com.company.yellowfin.formatters **. (Match with the fully qualified class name you set earlier) image015.png image016.png

Right-click on the package you created and select New> File. The file name is ** SankakuFormatter.java **. (This is also combined with the fully qualified class name) image017.png image018.png

Paste the following code into SankakuFormatter.java.

SankakuFormatter.java


package com.company.yellowfin.formatters;
import java.text.NumberFormat;

import com.hof.mi.interfaces.CustomFormatter;

public class SankakuFormatter extends CustomFormatter {
    public String getName() {
            return "Triangular formatter";
    }
    public boolean acceptsNativeType(int type) {
            // We only handle numeric types
            if (type == TYPE_NUMERIC) return true;
            return false;
    }
    public String render(Object value, int renderType) throws Exception {
            if (value == null) return null;
            if (renderType == RENDER_LINK) {
                  // Return a generic version of the value
                  return value.toString();
            }

    // Create a String representing the value
    NumberFormat nf = NumberFormat.getNumberInstance();
    String mark = "";
    String valStr = value.toString();
    double valNum = Double.parseDouble(valStr);
    double val = valNum;
    if (valNum < 0 ) {
    	mark = "△";
    	val = Math.abs(val);
    	}
    return mark + nf.format(val);
    }
}
image019.png

By the way, the code example that I referred to is in the online manual.

Creating a JAR file

Right-click on the project and select Export. image020.png

Select "JAR File". image021.png

Select all ** except ** .settings and ROOT, specify the JAR file name (here ** SankakuFormatter.jar **) and export. image022.png

New plugin added to Yellowfin

From the Yellowfin plugin management screen, add the created JAR file as a new plugin. image023.png

Example of use in Yellowfin report

The custom formatter created this time is named ** Triangle Formatter **. The name is specified in ** getName () ** in SankakuFormatter.java. This formatter allows you to format negative numbers with the "△" symbol.

For example, suppose you have the following simple data. image024.png

For this number, specify "triangular formatter" in the format. image025.png

Then, the negative number is displayed as a triangle symbol! image026.png

At first glance, it may seem that the string has been modified to have a symbol, but in reality, the data itself remains a numeric type just by changing the apparent format, so it is possible to apply conditional formatting. image027.png image028.png

Bonus: The JAR file created this time

I put the created JAR file on Github. Please use it if you like! https://github.com/hadatuna/SankakuFormatter

Recommended Posts

Create a Yellowfin custom formatter and display the minus of the number as △ (triangle)
Display the average value of the evaluation as a star
Let's create a TODO application in Java 5 Switch the display of TODO
Takes out the HashMap value and returns the result sorted by the value of value as a list.
Pass arguments to the method and receive the result of the operation as a return value
Count the number of occurrences of a string in Ruby
[Java] Throw a request and display the screen ② (GET / POST)
[Ruby] Questions and verification about the number of method arguments
Command to check the number and status of Java threads
[Java] Throw a request and display the screen (GET / POST)
I want to call a method and count the number
I tried JAX-RS and made a note of the procedure
A program that counts the number of words in a List
Create more Tabs and Fragments in the Fragment of BottomNavigationView
Find the number of days in a month with Kotlin
Create a large number of records with one command using the Ruby on Rails seeds.rb file
I tried to express the result of before and after of Date class with a number line
Generate a serial number with Hibernate (JPA) TableGenerator and store it in the Id of String.