arraylistpowerbuilderdatawindowuser-object

Power Builder 10.5 user object array to datawindow table


I am new to Power Builder and I would like to ask how can I represent my objects in a table form. For example, given an ArrayList in java I have implemented the code like this:

    table = new JTable();
    scrollPane.setViewportView(table);


    DefaultTableModel tableModel = 
            new DefaultTableModel(
                        new String[] {
                                "ScheduleNo", 
                                "Start Date", 
                                "End Date", 
                                "No of days", 
                                "Principal Expected", 
                                "Interest Expected", 
                                "EMI amount", 
                                "Factor", 
                                "MeanFactor"}
                        , 0);

    for (Schedule s : pf.getSchedules()){
           Integer schNo  = s.getScheduleNo();
           String startDate = df.format(s.getStartDate());
           String endDate = df.format(s.getEndDate());
           Integer noofdays = s.getNoOfDays();
           String prinExp = String.format("%.2f", s.getPrincipalAmt());
           String intExp = String.format("%.2f", s.getInterestAmt());
           String emi = String.format("%.2f", s.getAmortizedAmount());
           String factor = String.format("%.6f", s.getFactor());
           String mean = String.format("%.6f", s.getProductByFactor());


           Object[]data = {schNo, startDate, endDate, noofdays, prinExp, intExp, 
                   emi, factor, mean};

           tableModel.addRow(data);
        }

    table.setModel(tableModel);

But I cannot find a way to do it in PowerBuilder without having a connection to a database and pick the data from there which is totally not the case.

The data come from an User Object array[] and have exactly the same form like in the Java example above.


Solution

  • Without really knowing what you are trying to accomplish it appears to me that you could use a 'normal' PowerBuilder datawindow but when you define it you make it's datasource as external. This type of datawindow does not require a connection to a database. You define the 'fields' of the datasource as strings, numeric, etc. when you create it.

    In code you can create a datawindow (or datastore for that matter) control, assign the external datasource datawindow object to it, insert a row, then populate the fields with data of the corresponding datatype.

    Example usage:

    datawindow ldw
    long llrow
    ldw = CREATE datawindow
    ldw.dataobject = 'myExternalDatawindowObject'
    llrow = ldw.insertrow(0)
    ldw.setitem(llrow,'stringcolumn','my example string')
    ldw.setitem(llrow,'numericcolumn',1234)