Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Smartgwt 6.1 Bug: Print ListGrid no check boxes

    Hi,

    I tried to print out a listGrid... this is working, but I realized, that images like checkBoxes won't be printed. They refer to images which does not exist in Tahoe. So they are currently not printed!

    Example:
    HTML source code: sc/skins/Tahoe/images/DynamicForm/checked_Disabled.png
    Existing image: sc/skins/Tahoe/images/DynamicForm/cb-checked-disable.png

    best wishes
    Andy

    SmartGWT: 6.1d LGPL 16 may
    Browser: Chrome

    Code:
    import java.util.Date;
    import java.util.LinkedHashMap;
    
    import com.google.gwt.user.datepicker.client.CalendarUtil;
    import com.smartgwt.client.data.Criteria;
    import com.smartgwt.client.data.DataSource;
    import com.smartgwt.client.data.Record;
    import com.smartgwt.client.data.RecordList;
    import com.smartgwt.client.data.events.DataChangedEvent;
    import com.smartgwt.client.data.events.DataChangedHandler;
    import com.smartgwt.client.data.fields.DataSourceBooleanField;
    import com.smartgwt.client.data.fields.DataSourceDateField;
    import com.smartgwt.client.data.fields.DataSourceFloatField;
    import com.smartgwt.client.data.fields.DataSourceSequenceField;
    import com.smartgwt.client.data.fields.DataSourceTextField;
    import com.smartgwt.client.types.Alignment;
    import com.smartgwt.client.types.AutoFitWidthApproach;
    import com.smartgwt.client.types.FetchMode;
    import com.smartgwt.client.types.FieldType;
    import com.smartgwt.client.types.GroupStartOpen;
    import com.smartgwt.client.types.Overflow;
    import com.smartgwt.client.types.RecordDropAppearance;
    import com.smartgwt.client.types.SummaryFunctionType;
    import com.smartgwt.client.util.PrintHTMLCallback;
    import com.smartgwt.client.util.PrintProperties;
    import com.smartgwt.client.widgets.Canvas;
    import com.smartgwt.client.widgets.HTMLPane;
    import com.smartgwt.client.widgets.PrintCanvas;
    import com.smartgwt.client.widgets.Window;
    import com.smartgwt.client.widgets.events.ClickEvent;
    import com.smartgwt.client.widgets.events.ClickHandler;
    import com.smartgwt.client.widgets.form.DynamicForm;
    import com.smartgwt.client.widgets.grid.ListGrid;
    import com.smartgwt.client.widgets.grid.ListGridField;
    import com.smartgwt.client.widgets.grid.ListGridRecord;
    import com.smartgwt.client.widgets.layout.VLayout;
    import com.smartgwt.client.widgets.toolbar.ToolStrip;
    import com.smartgwt.client.widgets.toolbar.ToolStripButton;
    import com.smartgwt.client.widgets.viewer.DetailViewer;
    
    public class GTestGrid
    {
    
        private ListGrid listGrid;
        private DynamicForm editorForm;
    
        public GTestGrid()
        {
            initPopUp();
        }
    
        private void initPopUp()
        {
            initListGrid();
            initEditorForm();
    
            VLayout layout = new VLayout();
            layout.setSize( "100%", "100%" );
            layout.setMembers( editorForm, getToolBar(), listGrid );
            layout.setOverflow( Overflow.HIDDEN );
    
            Window window = new Window();
            window.setOverflow( Overflow.HIDDEN );
            window.setSize( "100%", "100%" );
            window.setCanDragResize( true );
            window.setShowMaximizeButton( true );
            window.setShowMinimizeButton( true );
            window.setShowCloseButton( false );
            window.setAnimateMinimize( true );
            window.setShowCloseButton( true );
            window.setModalMaskOpacity( 50 );
            window.setIsModal( true );
            window.setShowModalMask( true );
            window.centerInPage();
            window.addItem( layout );
    
            window.draw();
    
            // listGrid.getResultSet().addDataChangedHandler( new DataChangedHandler()
            // {
            //
            // @Override
            // public void onDataChanged( DataChangedEvent event )
            // {
            // double totalAmount = 0;
            //
            // // Gets all records of the listGrid
            // Record[] records = getAssignments();
            //
            // for ( int i = 0; i < records.length; i++ )
            // {
            // totalAmount = totalAmount + records[i].getAttributeAsDouble( CAssignedPaymentsRec.total_amount );
            // }
            // }
            // } );
    
            // add Records
            addRecords( 2 );
        }
    
        private void initListGrid()
        {
            final DataSource dataSource = getDataSource();
            listGrid = new ListGrid()
            {
                @Override
                protected Canvas getCellHoverComponent( Record record, Integer rowNum, Integer colNum )
                {
                    Criteria criteria = new Criteria();
                    criteria.addCriteria( dataSource.getPrimaryKeyFieldName(),
                                          record.getAttribute( dataSource.getPrimaryKeyFieldName() ) );
    
                    DetailViewer viewer = new DetailViewer();
                    viewer.setEmptyCellValue( "---" );
                    viewer.setDataSource( dataSource );
                    viewer.setWrapValues( false );
                    viewer.setWrapLabel( false );
                    viewer.setShowShadow( true );
                    viewer.setShowEmptyField( false );
                    viewer.setShowHiddenFields( true );
                    viewer.setShowEmptyField( false );
                    viewer.setShowDetailFields( true );
                    viewer.fetchData( criteria );
    
                    return viewer;
                }
            };
    
            listGrid.setMargin( 25 );
            listGrid.setDataSource( dataSource );
            listGrid.setAutoFetchData( true );
    
            listGrid.setShowFilterEditor( true );
            listGrid.setAllowFilterExpressions( true );
            listGrid.setShowRowNumbers( true );
            listGrid.setFastCellUpdates( true );
            listGrid.setEmptyCellValue( "---" );
            listGrid.setAllowFilterExpressions( true );
            listGrid.setDataFetchMode( FetchMode.BASIC );
            listGrid.setWrapHeaderTitles( true );
            listGrid.setCanResizeFields( true );
            listGrid.setCellPadding( 4 );
            listGrid.setFixedRecordHeights( false );
            listGrid.setGroupByMaxRecords( 1000 );
            listGrid.setBodyOverflow( Overflow.AUTO );
            listGrid.setOverflow( Overflow.AUTO );
            listGrid.setLeaveScrollbarGap( false );
            listGrid.setAutoFitWidthApproach( AutoFitWidthApproach.BOTH );
            listGrid.setAutoFitHeaderHeights( true );
            listGrid.setAutoSizeHeaderSpans( true );
            listGrid.setCanAutoFitFields( false );
            listGrid.setRecordDropAppearance( RecordDropAppearance.BOTH );
            listGrid.setCanHover( true );
            listGrid.setShowHover( true );
            listGrid.setShowHoverComponents( true );
            listGrid.setHoverDelay( 100 );
    
            listGrid.setCanAddFormulaFields( true );
            listGrid.setCanAddSummaryFields( true );
    
            // Sets Columns
            setColumns( listGrid );
    
        }
    
        private void setColumns( ListGrid listGrid )
        {
            ListGridField idField = new ListGridField( "id" );
            idField.setWidth( "10%" );
            idField.setAlign( Alignment.CENTER );
            idField.setShowGroupSummary( false );
            idField.setHidden( true );
            idField.setCanEdit( false );
    
            ListGridField descriptionField = new ListGridField( "description" );
            descriptionField.setWidth( "60%" );
            descriptionField.setCanEdit( false );
    
            ListGridField netField = new ListGridField( "netAmount" );
            netField.setSummaryFunction( SummaryFunctionType.SUM );
            netField.setShowGroupSummary( true );
            netField.setShowGridSummary( true );
            netField.setWidth( "10%" );
            netField.setAlign( Alignment.CENTER );
            netField.setFormat( "#,###,##0.00" );
    
            ListGridField taxField = new ListGridField( "taxAmount" );
            taxField.setWidth( "10%" );
            taxField.setSummaryFunction( SummaryFunctionType.SUM );
            taxField.setShowGroupSummary( true );
            taxField.setShowGridSummary( true );
            taxField.setAlign( Alignment.CENTER );
            taxField.setFormat( "#,###,##0.00" );
    
            ListGridField grossField = new ListGridField( "grossAmoumnt" );
            grossField.setSummaryFunction( SummaryFunctionType.SUM );
            grossField.setShowGroupSummary( true );
            grossField.setShowGridSummary( true );
            grossField.setAlign( Alignment.CENTER );
            grossField.setWidth( "10%" );
            grossField.setFormat( "#,###,##0.00" );
    
            ListGridField currencyField = new ListGridField( "currency" );
            currencyField.setAlign( Alignment.CENTER );
            currencyField.setWidth( "8%" );
            currencyField.setCanEdit( false );
    
            ListGridField dateField = new ListGridField( "date" );
            dateField.setWidth( "15%" );
            dateField.setAlign( Alignment.LEFT );
    
            ListGridField paidField = new ListGridField( "paid", "Paid" );
    
            listGrid.setFields( idField, descriptionField, netField, taxField, grossField, paidField, dateField );
    
            // Group ListGrid
            listGrid.setGroupByField( "currency" );
            listGrid.setGroupStartOpen( GroupStartOpen.ALL );
            listGrid.setShowGroupSummary( true );
            listGrid.setShowGridSummary( true );
    
        }
    
        private DataSource getDataSource()
        {
            DataSource ds = new DataSource();
            ds.setID( "payments" );
            ds.setClientOnly( true );
    
            DataSourceSequenceField idField = new DataSourceSequenceField( "id", "ID" );
            idField.setPrimaryKey( true );
            idField.setHidden( true );
    
            DataSourceTextField descriptionField = new DataSourceTextField( "description", "Description" );
            descriptionField.setRequired( true );
    
            DataSourceFloatField netField = new DataSourceFloatField( "netAmount", "Net Amount" );
            netField.setRequired( true );
            netField.setDecimalPrecision( 2 );
            netField.setDecimalPad( 2 );
            netField.setType( FieldType.LOCALEFLOAT );
    
            DataSourceFloatField taxField = new DataSourceFloatField( "taxAmount", "Tax Amount" );
            taxField.setRequired( true );
            taxField.setDecimalPrecision( 2 );
            taxField.setDecimalPad( 2 );
            taxField.setType( FieldType.LOCALEFLOAT );
    
            DataSourceFloatField grossField = new DataSourceFloatField( "grossAmoumnt", "Gross Amount" );
            grossField.setRequired( true );
            grossField.setDecimalPrecision( 2 );
            grossField.setDecimalPad( 2 );
            grossField.setType( FieldType.LOCALEFLOAT );
    
            DataSourceTextField currencyField = new DataSourceTextField( "currency", "Currency" );
            currencyField.setValueMap( getCurrencys() );
            currencyField.setRequired( true );
    
            DataSourceBooleanField paidField = new DataSourceBooleanField( "paid", "Paid" );
    
            DataSourceDateField dateField = new DataSourceDateField( "date", "Date" );
    
            ds.setFields( idField, descriptionField, netField, taxField, grossField, currencyField, paidField, dateField );
    
            return ds;
        }
    
        private void initEditorForm()
        {
            editorForm = new DynamicForm();
            editorForm.setDataSource( listGrid.getDataSource() );
            editorForm.setAutoFocus( true );
            editorForm.setWidth100();
            editorForm.setMargin( 25 );
            editorForm.setUseAllDataSourceFields( true );
    
            editorForm.editNewRecord();
        }
    
        private ToolStrip getToolBar()
        {
            ToolStrip toolbar = new ToolStrip();
            toolbar.setWidth100();
    
            ToolStripButton buttonAddToGrid = new ToolStripButton( "Add To Grid" );
            buttonAddToGrid.addClickHandler( new ClickHandler()
            {
                public void onClick( ClickEvent event )
                {
                    if ( editorForm.validate() == true )
                    {
                        editorForm.submit();
                    }
                }
            } );
    
            ToolStripButton buttonNewRecord = new ToolStripButton( "New Record" );
            buttonNewRecord.addClickHandler( new ClickHandler()
            {
                public void onClick( ClickEvent event )
                {
                    editorForm.editNewRecord();
                }
            } );
    
            ToolStripButton buttonPrint = new ToolStripButton( "Print" );
            buttonPrint.addClickHandler( new ClickHandler()
            {
    
                @Override
                public void onClick( ClickEvent event )
                {
                    // Direct Print
                    PrintProperties prop = new PrintProperties();
                    prop.setPrintForExport( true );
    
                    String html = listGrid.getPrintHTML( prop, new PrintHTMLCallback()
                    {
    
                        @Override
                        public void setHTML( String html )
                        {
                            System.out.println( html );
                            final HTMLPane htmlPane = new HTMLPane();
                            htmlPane.setContents( html );
                            PrintCanvas.printComponents( new Object[] { htmlPane } );
                        }
                    } );
    
                    System.out.println( html );
                }
            } );
    
            toolbar.addButton( buttonNewRecord );
            toolbar.addButton( buttonAddToGrid );
            toolbar.addButton( buttonPrint );
    
            return toolbar;
    
        }
    
        public Record[] getAssignments()
        {
            RecordList recordList = null;
            if ( listGrid.isGrouped() )
            {
                recordList = listGrid.getOriginalRecordList();
            }
            else
            {
                recordList = listGrid.getResultSet();
            }
    
            Record[] result = (Record[]) recordList.toArray();
    
            return result;
        }
    
        public LinkedHashMap<String, String> getCurrencys()
        {
            LinkedHashMap<String, String> items = new LinkedHashMap<String, String>();
    
            items.put( "1", "EUR" );
            items.put( "2", "GBP" );
            items.put( "3", "CHF" );
            items.put( "4", "SEK" );
            items.put( "5", "DKK" );
            items.put( "6", "PLN" );
            items.put( "7", "BGN" );
            items.put( "8", "CZK" );
            items.put( "9", "HUF" );
            items.put( "10", "HRK" );
            items.put( "11", "RUB" );
            items.put( "12", "RON" );
    
            return items;
        }
    
        private void addRecords( int counter )
        {
            Date date = getFirstDayOfMonth( new Date() );
            Date date2 = getFirstDayOfMonth( new Date() );
    
            for ( int i = 0; i < counter; i++ )
            {
                ListGridRecord record = new ListGridRecord();
                record.setAttribute( "id", 1 + i );
                record.setAttribute( "description", "Test " + 1 + i );
                record.setAttribute( "netAmount", new Double( 1000 + i ) );
                record.setAttribute( "taxAmount", new Double( 0 ) );
                record.setAttribute( "grossAmoumnt", new Double( 1000 + i ) );
                record.setAttribute( "currency", "1" );
                record.setAttribute( "paid", "true" );
    
                CalendarUtil.addDaysToDate( date, 1 );
                record.setAttribute( "date", date );
    
                listGrid.addData( record );
            }
    
            for ( int i = 0; i < counter; i++ )
            {
                ListGridRecord record = new ListGridRecord();
                record.setAttribute( "id", ( ( counter + 1 ) + i ) );
                record.setAttribute( "description", "Test " + 1 + i );
                record.setAttribute( "netAmount", new Double( 1 + i ) );
                record.setAttribute( "taxAmount", new Double( 0 ) );
                record.setAttribute( "grossAmoumnt", new Double( 1 + i ) );
                record.setAttribute( "currency", "1" );
    
                CalendarUtil.addDaysToDate( date2, 1 );
                record.setAttribute( "date", date2 );
    
                listGrid.addData( record );
            }
        }
    
        // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
        /**
         * Returns the first day of the current month
         */
        // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
        public static Date getFirstDayOfMonth( Date date )
        {
            CalendarUtil.resetTime( date );
            CalendarUtil.setToFirstDayOfMonth( date );
    
            return date;
        }
    
    }

    #2
    Thanks for the notification. We've made a change to address this issue. Please try the next nightly build dated May 20 or above

    Regards
    Isomorphic Software

    Comment


      #3
      Thanks! So I tried nightly from 21. may and now it seems that this build is refering to "cb-uncheck-disable.png" instead of "cb-uncheck-disabled.png"... now it seems that listGrids do not have any checkBoxes at all

      Thanks
      Andy


      Click image for larger version

Name:	noCheckBoxes.jpg
Views:	77
Size:	2.9 KB
ID:	244747

      Comment


        #4
        We failed to update this thread, but this issue should now be resolved. Please let us know if you're still seeing it.

        Thanks
        Isomorphic Software

        Comment


          #5
          Hey sorry... I was not online... it is fixed!

          Thanks
          Andy

          Comment

          Working...
          X