Programatically create report ====> DataEngine.getPrintDataInfo: No Colums - Delete Report Format Order3 and start again [33]

51 views
Skip to first unread message

Martin V

unread,
Apr 20, 2014, 4:06:30 PM4/20/14
to idem...@googlegroups.com
Hello,
I'm working on WYSIVIG Editor for creating reports. So I'm trying to create Print Format and Print Format Items programatically. Here is what I do:

Here I create new Print Format :

public void saveAsNew(String printFormatName){
        logger
.debug("Saving scene as: '" + printFormatName + "' for table: '" + tableName + "'.");
       
       
//Save Print Format
       
MPrintFormat newPrintFormat = new MPrintFormat(Env.getCtx(), 0, null);
        newPrintFormat
.setName(printFormatName);                                            //this doesn't have to be uniqe across iDempiere system
        newPrintFormat
.setAD_Table_ID(dataProvider.getTableID(tableName));        
        newPrintFormat
.setAD_PrintColor_ID( MainScene.DEFAULT_IDEMPIERE_PRINT_COLOR_ID );    //this should be 100 TODO - better to implement new method searching for default colo
        newPrintFormat
.setAD_PrintPaper_ID( MainScene.DEFAULT_IDEMPIERE_PRINT_PAPER_ID );    //This should be 100
        newPrintFormat
.setAD_PrintFont_ID( MainScene.DEFAULT_IDEMPIERE_PRINT_FONT_ID );        //This should be 100
        newPrintFormat
.setIsStandardHeaderFooter(false);
        newPrintFormat
.setIsForm(true);        //we need header and footer
       
       
if( !newPrintFormat.save() ){
            logger
.error("Error during saving print format: " + newPrintFormat);
           
return;
       
}
       
       
int newPrintFormatID = newPrintFormat.get_ID();                                        //after succesfull save we have valid ID of newly created object
        logger
.trace( "New print format saved with ID: " +  newPrintFormatID);

        seqNo
= 0;
       
for(Widget widget: scene.getMainLayer().getChildren()){
            saveItemDB
(widget, newPrintFormatID, seqNo);
            seqNo
+= 10;
       
}

   
}

Here I'm creting new PrintFormatItems:
(So far it's only for text type elements)

private void saveItemDB(Widget widget, int formatID, int seqNo){

       
if(widget instanceof LabelWidget){
           
Font widgetFont = widget.getFont();
           
String labelText = ((LabelWidget) widget).getLabel();
           
Point widgetLocation = widget.getPreferredLocation();
           
           
int fontID = saveFont(widgetFont);                  //this method create new print font if doesn't exist yet
            logger
.trace("Font: " + widgetFont + " found in db as ID: " + fontID);
           
           
MPrintFormatItem item = new MPrintFormatItem(Env.getCtx(), 0, null);
            item
.setAD_PrintFont_ID(fontID);                    //Mandatory
//            item.setAD_PrintColor_ID(AD_PrintColor_ID);
            item
.setAD_PrintFormat_ID(formatID);                    //Mandatory - id of format to belong to
            item
.setName(labelText);                            //Mandatory name of printitem
            item
.setSeqNo(seqNo);
            item
.setXPosition(widgetLocation.x);
            item
.setYPosition(widgetLocation.y);
           
            item
.setPrintName(labelText);                        //text of label
            item
.setIsRelativePosition(false);
            item
.setSortNo(0);                                    //we don't need sorting
            item
.setLineAlignmentType("X");                        //we don't need aligment
            item
.setPrintFormatType("T");
           
           
if ( !item.save() ){
                logger
.error("Error whne sawing: " + item);
           
}
            logger
.trace("Item saved with ID: " + item.get_ID());
           
       
} else if(widget instanceof ImageWidget){
           
           
       
}
       

   
}Sem vložte kód...

When I run the code it's saved without problems, but when I try to view this in iDempiere I get this:

DataEngine.getPrintDataInfo: No Colums - Delete Report Format Order3 and start again [33]

With Exeption:

Exception in thread "AWT-EventQueue-0" java.lang.IllegalStateException: No print data (Delete Print Format and restart)
    at org.compiere.print.ReportEngine.layout(ReportEngine.java:285)
    at org.compiere.print.ReportEngine.getLayout(ReportEngine.java:296)
    at org.compiere.print.ReportEngine.getCtx(ReportEngine.java:333)
    at org.compiere.print.Viewer.<init>(Viewer.java:157)
    at org.compiere.print.SwingViewerProvider.openViewer(SwingViewerProvider.java:33)
    at org.compiere.print.ReportCtl.preview(ReportCtl.java:442)
    at org.compiere.print.AReport.launchReport(AReport.java:251)
    at org.compiere.print.AReport.launchReport(AReport.java:218)
    at org.compiere.print.AReport.actionPerformed(AReport.java:268)
    at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
    at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
    at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
    at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
    at javax.swing.AbstractButton.doClick(Unknown Source)
    at javax.swing.plaf.basic.BasicMenuItemUI.doClick(Unknown Source)
    at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(Unknown Source)
    at java.awt.Component.processMouseEvent(Unknown Source)
    at javax.swing.JComponent.processMouseEvent(Unknown Source)
    at java.awt.Component.processEvent(Unknown Source)
    at java.awt.Container.processEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Window.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    at java.awt.EventQueue.access$200(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue$4.run(Unknown Source)
    at java.awt.EventQueue$4.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)


But whe I first load valid report and then switch just to my created report. I get only first report and it loads and all items are displayed.
So could you tell me please what I'm missing?


Thank you in advance.

Reply all
Reply to author
Forward
0 new messages