Crystal Reports for Eclipse Developer Guide

To update the page when the report structure changes

Before you can complete the steps in this example, you must have a plug-in project includes the com.businessobjects.crystalreports.designer.sdk library, defines the com.businessobjects.crystalreports.designer.sdk.ReportEditorPage extension point, and includes a class that implements the UI for a report page.
You can add a listener to your report page that detects changes to the report. You can then update the report page to reflect changes that occur when report objects are added, removed or modified.
  1. Add the import statements that are used in this example.
    import com.crystaldecisions.sdk.occa.report.application.AdvancedClientDocumentEvent;
    import com.crystaldecisions.sdk.occa.report.application.IAdvancedClientDocumentEventListener;
    import org.eclipse.ui.IEditorPart;
    import org.eclipse.ui.IPropertyListener;
  2. Implement the IAdvancedClientDocumentEventListener interface.
    public class MyReportPage extends EditorPart implements ICrystalReportsEditorPage, 
         ICrystalDocumentChangedListener, IAdvancedClientDocumentEventListener
    {
    }
  3. Implement the onAdded method to update the page when report objects are added to the report.
    public void onAdded(AdvancedClientDocumentEvent event)
    {
       listViewer.refresh();
    }
  4. Implement the onChanged method to update the page when report objects are changed.
    public void onChanged(AdvancedClientDocumentEvent event)
    {
        listViewer.refresh();
    }
  5. Implement the onRemoved method to update the page when report objects are removed from the report.
    public void onRemoved(AdvancedClientDocumentEvent event)
    {
        listViewer.refresh();
    }
    
  6. Modify the attachToEditor method to add this page as a listener to the Crystal Reports editor when the page is initialized.
    This enables the page to respond to changes in the report document, for example, adding parameters. Calling documentChangedHelper initializes the UI when the page is initialized.
    public void attachToEditor(ICrystalReportsEditor editor)
      {
        myEditor = editor;
        setInput(myEditor.getEditorInput());
      
        myEditor.addDocumentChangedListener(this);
        documentChangedHelper(null, myEditor.getReportClientDocument(), true);
       
        myEditor.addPropertyListener (new IPropertyListener ()
        {
          public void propertyChanged(Object source, int propID)
          {
             if (propID == IEditorPart.PROP_INPUT)
                 setInput (myEditor.getEditorInput());
          }
        });
      }
  7. Update this page to listen to the active document.
    Modify the documentChangedHelper class to add this IAdvancedClientDocumentEventListener to the new document remove it from the old document.
    private void documentChangedHelper(IReportClientDocument oldReport, IReportClientDocument newReport, boolean mainChanged)
      {
        if (mainChanged)
        {
          if (oldReport != null)
            oldReport.getMainReport().removeAdvancedClientDocumentEventListener(this);
          if (newReport != null)
            newReport.getMainReport().addAdvancedClientDocumentEventListener(this);
        
          if (newReport == null)
            return;
    
          IDataDefinition definition = null;
          try 
          {
            definition = newReport.getDataDefController().getDataDefinition();
          } 
          catch(ReportSDKException e)
          {
            e.printStackTrace();
          }
    
          if (definition != null)
          {
            Fields parameters;
            parameters = definition.getParameterFields();
            listViewer.setInput(parameters);
          }
          else
          {
            listViewer.setInput(null);
          }
        }
      }



SAP BusinessObjects
http://www.sap.com/sapbusinessobjects/
Support services
http://service.sap.com/bosap-support/
Product Documentation on the Web
http://help.sap.com/