Skip to Main Content

Oracle Forms

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Tutorial(Gantt chart - using JFreeChart PJC)

PeterValencicJul 20 2016 — edited Jul 22 2016

If someon will ever need it.. here is my example of Gantt chart in oracle forms using JFreeChart...

What you need:

1.) JfreeChart library from: JFreeChart

2.) some Java IDE (I used NetBeans)

Setup a Java project and add frmall.jar library and JFreeChart library to your project...

screenshot_1084.jpg

Here is my source code for GraphBean

package com.in2;

import java.awt.BorderLayout;

import java.awt.Color;

import java.awt.Frame;

import java.awt.GradientPaint;

import java.awt.Paint;

import java.awt.Rectangle;

import java.lang.reflect.Method;

import java.text.ParseException;

import java.text.SimpleDateFormat;

import java.util.Calendar;

import java.util.Date;

import oracle.forms.engine.Main;

import oracle.forms.handler.IHandler;

import oracle.forms.properties.ID;

import oracle.forms.ui.VBean;

import org.jfree.chart.ChartFactory;

import org.jfree.chart.ChartPanel;

import org.jfree.chart.JFreeChart;

import org.jfree.data.category.IntervalCategoryDataset;

import org.jfree.data.gantt.Task;

import org.jfree.data.gantt.TaskSeries;

import org.jfree.data.gantt.TaskSeriesCollection;

import org.jfree.data.time.SimpleTimePeriod;

/**

* Gantt chart - oracle forms

*

* @author peter valencic, 2016

*/

public class GrafBean extends VBean {

static SimpleDateFormat formatter = new SimpleDateFormat("dd.MM.yyyy");

private int x, y, w, h;

private Main formsMain = null;

private Frame formsTopFrame = null;

private IHandler m\_handler;

//graph method

protected static final ID CLEAR\_GRAPH = ID.registerProperty("CLEAR\_GRAPH");

protected static final ID REPAINT\_GRAPH = ID.registerProperty("REPAINT\_GRAPH");

protected static final ID GRAPH\_LABEL = ID.registerProperty("GRAPH\_LABEL");

//task series property

protected static final ID S1\_LABEL = ID.registerProperty("S1\_LABEL");

protected static final ID S2\_LABEL = ID.registerProperty("S2\_LABEL");

protected static final ID S3\_LABEL = ID.registerProperty("S3\_LABEL");

//axis labels

protected static final ID X\_LABEL = ID.registerProperty("X\_LABEL");

protected static final ID Y\_LABEL = ID.registerProperty("Y\_LABEL");

protected static final ID SET\_VALUE = ID.registerProperty("SET\_VALUE");

static TaskSeries s1 = new TaskSeries("SERIJA 1");

static TaskSeries s2 = new TaskSeries("SERIJA 2");

static TaskSeries s3 = new TaskSeries("SERIJA 3");

static TaskSeriesCollection collection = new TaskSeriesCollection();

static IntervalCategoryDataset dataset;

static JFreeChart chart;

static ChartPanel chartPanel;

//local

static String graphLabel = "";

static String s1Label = "";

static String s2Label = "";

static String s3Label = "";

static String xLabel = "";

static String yLabel = "";

public GrafBean() {

    super();

    System.out.println("=========================");

    System.out.println("= GraphBean v 1.0       =");

    System.out.println("=========================");

}

public void repaintGraph() {

    System.out.println("repaintGraph...");

    System.out.println("s1.getItemCount: " +s1.getItemCount() );

    System.out.println("s2.getItemCount: " +s2.getItemCount() );

    System.out.println("s3.getItemCount: " +s3.getItemCount() );

    collection = new TaskSeriesCollection();

    if (s1.getItemCount() > 0) {

        collection.add(s1);

    }

    if (s2.getItemCount() > 0) {

        collection.add(s2);

    }

    if (s3.getItemCount() > 0) {

        collection.add(s3);

    }

    chart = ChartFactory.createGanttChart(

            graphLabel, // chart title

            yLabel, // domain axis label

            xLabel, // range axis label

            collection, // data

            true, // include legend

            true, // tooltips

            false // urls

    );

    chart.setAntiAlias(true);

    Paint p = new GradientPaint(0, 0, Color.white, 1000, 0, Color.GREEN);

    chart.setBackgroundPaint(p);

    chart.fireChartChanged();

    chartPanel = new ChartPanel(chart);

    chartPanel.setPreferredSize(this.getSize()); // new java.awt.Dimension(500, 270));

    this.add(chartPanel, BorderLayout.CENTER);

    chartPanel.setVisible(true);

}

public void setValue(String cvsString) {

    if (cvsString == null) {

        return;

    }

    String\[\] nextLine = cvsString.split(";");

    String sindex = nextLine\[0\].trim();

    String sbarva = nextLine\[3\].trim();

    Date datum\_od = null;

    Date datum\_do = null;

    try {

        datum\_od = formatter.parse(nextLine\[1\].trim());

        datum\_do = formatter.parse(nextLine\[2\].trim());

    } catch (ParseException ex) {

        ex.printStackTrace();

    }

    System.out.println("\\tid: " + sindex);

    System.out.println("\\tsdatum\_od: " + datum\_od.toString());

    System.out.println("\\tsdatum\_do: " + datum\_do.toString());

    System.out.println("\\tsbarva: " + sbarva);

    if (sbarva.equalsIgnoreCase("X")) {

        System.out.println("Add S1");

        s1.add(new Task(sindex, new SimpleTimePeriod(datum\_od, datum\_do)));

    }

    if (sbarva.equalsIgnoreCase("K")) {

        System.out.println("Add S2");

        s2.add(new Task(sindex, new SimpleTimePeriod(datum\_od, datum\_do)));

    }

    if (sbarva.equalsIgnoreCase("I")) {

        System.out.println("Add S3");

        s3.add(new Task(sindex, new SimpleTimePeriod(datum\_od, datum\_do)));

    }

    System.out.println("======");

}

public void init(IHandler handler) {

    super.init(handler);

    m\_handler = handler;

    // get the Forms Main class

    try {

        Method method = handler.getClass().getMethod("getApplet", new Class\[0\]);

        Object applet = method.invoke(handler, new Object\[0\]);

        if (applet instanceof Main) {

            formsMain = (Main) applet;

        }

    } catch (Exception ex) {

        ex.printStackTrace();

    }

    formsTopFrame = formsMain.getFrame();

}

public boolean setProperty(ID property, Object value) {

    if (property == CLEAR\_GRAPH) {

        System.out.println("Clear graph...");

        s1.removeAll();

        s2.removeAll();

        s3.removeAll();

        return true;

    }

    if (property == REPAINT\_GRAPH) {

        System.out.println("Repaint graph...");

        repaintGraph();

        return true;

    }

    if (property == GRAPH\_LABEL) {

        graphLabel = (String) value;

        System.out.println("Graph Label: " + graphLabel);

        return true;

    }

    if (property == S1\_LABEL) {

        s1Label = (String) value;

        System.out.println("S1Label: " + s1Label);

        return true;

    }

    if (property == S2\_LABEL) {

        s2Label = (String) value;

        System.out.println("S2Label: " + s2Label);

        return true;

    }

    if (property == S3\_LABEL) {

        s3Label = (String) value;

        System.out.println("S3Label: " + s3Label);

        return true;

    }

    if (property == X\_LABEL) {

        xLabel = (String) value;

        System.out.println("xLabel: " + xLabel);

        return true;

    }

    if (property == Y\_LABEL) {

        yLabel = (String) value;

        System.out.println("yLabel: " + yLabel);

        return true;

    }

    if (property == SET\_VALUE) {

        System.out.println("Value:--> " + (String)value);

        setValue((String) value);

        return true;

    }

    return super.setProperty(property, value);

}

private static Date date(final int day, final int month, final int year) {

    Calendar calendar = Calendar.getInstance();

    calendar.set(year, month, day);

    Date result = calendar.getTime();

    return result;

}

}

Rebuild a project and make a JAR library.. in my case I have named it graphbean.jar

Sign jar file with certificate using jarsigner...

Deploy signed jar file on forms server in \forms\java folder

Modify formsweb.cfg and add graphbean.jar to archive parameter..

Make a simple form:

screenshot_1085.jpg

compile and run...

screenshot_1082.jpg

thats all

hope will help someone..

here is the signed JAR archive and source (FMB)..

https://drive.google.com/file/d/0B6Z9wNTXyUEeWGwzTGxJNm0wZ28/view?usp=sharing

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 19 2016
Added on Jul 20 2016
4 comments
1,597 views