Crystal Reports for Eclipse Developer Guide

To create a save behavior class

This example assumes that you have created a class, MyLocationInfo, that stores information about the custom report location and the temporary file that is used to store a copy of the report.
The example shows how to create a class that saves the report to a temporary file and copies the temporary file to the custom location.
  1. Click File > New > Class
    The" New Java Class" dialog box appears.
  2. Type the name of the class in the <Name> field.
    For example, type MySaveBehavior.
  3. Click Add.
    The "Implemented Interfaces Selection" dialog box appears.
  4. Type com.businessobjects.crystalreports.designer.sdk.input.ICrystalDocumentSaveBehavior and click OK.
  5. Click Finish.
    A java class that implements the ICrystalDocumentSaveBehavior interface is created.
  6. Create a member variable that stores the custom location information.
    public class MySaveBehavior implements ICrystalDocumentSaveBehavior
    {
      MyLocationInfo locationInfo = null;
    
      ...
    }
  7. Create a constructor that takes the custom location information as a parameter.
    public MySaveBehavior (MyLocationInfo locationInfo)
    {
      this.locationInfo = locationInfo;
    }
  8. Modify the doSave method to update the progress monitor and save the report.
    Save the report to the temporary file by calling save.
    public IEditorInput doSave(ICrystalReportsEditor editor, IProgressMonitor progress)
    {
        editor.getReportClientDocument().getMainReport().save();
    Copy the report from the temporary file to its custom location.

    Note: This example assumes that theMyLocationInfo contains the logic to copy the report to its custom location.
        locationInfo.copyTempFileToCustomLocation();
    Return the editor input.
       return editor.getEditorInput();
    } 
  9. Add exception handling code.
    public IEditorInput doSave(ICrystalReportsEditor editor, IProgressMonitor progress)
    {
      try
      {
        editor.getReportClientDocument().getMainReport().save();
        locationInfo.copyTempFileToCustomLocation();
        return editor.getEditorInput();
      }
      catch (ReportSDKException e)
      {
        e.printStackTrace();
      }
      catch (IOException e)
      {
        e.printStackTrace();
      }
      return null;
    }
  10. Modify the doSaveAs method to save the report.
    public IEditorInput doSaveAs (ICrystalReportsEditor editor, IProgressMonitor progress)
    {
      return EditorUtilities.getDefaultSaveBehavior().doSaveAs(editor, progress);
    }
  11. Modify the isDirty method to return true if the report has changed since it was last saved.
    public boolean isDirty(ICrystalReportsEditor editor)
    {
      return EditorUtilities.getDefaultSaveBehavior().isDirty(editor);
    }
  12. Modify the getAdapter method of the class that extends IEditorInput to return this save behavior class.
    public class MyEditorInput implements IEditorInput
    {  
      ...
    
      public Object getAdapter (Class adapter)
      {
        if (IReportClientDocumentFactory.class.equals (adapter))
          return new MyReportFactory (locationInfo);
    
        else if (ICrystalDocumentSaveBehavior.class.equals (adapter))
          return new MySaveBehavior(locationInfo);
       
        return null;
      }
    
      ...
    }
Example: A save behavior class
import java.io.IOException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.ui.IEditorInput;

import com.businessobjects.crystalreports.designer.sdk.ICrystalReportsEditor;
import com.businessobjects.crystalreports.designer.sdk.input.ICrystalDocumentSaveBehavior;
import com.businessobjects.crystalreports.designer.sdk.util.EditorUtilities;
import com.crystaldecisions.sdk.occa.report.lib.ReportSDKException;

public class MySaveBehavior implements ICrystalDocumentSaveBehavior
{
  
  MyLocationInfo locationInfo = null;
  
  public MySaveBehavior (MyLocationInfo locationInfo)
  {
    this.locationInfo = locationInfo;
  }

  public IEditorInput doSave(ICrystalReportsEditor editor, IProgressMonitor progress)
  {
    try
    {

      editor.getReportClientDocument().getMainReport().save();
 
      locationInfo.copyTempFileToCustomLocation();
      return editor.getEditorInput();
    }
    catch (ReportSDKException e)
    {
      e.printStackTrace();
    }
    catch (IOException e)
    {
      e.printStackTrace();
    }
    return null;
  }
 
  public IEditorInput doSaveAs (ICrystalReportsEditor editor, IProgressMonitor progress)
  {
    return EditorUtilities.getDefaultSaveBehavior().doSaveAs(editor, progress);
  }

  public boolean isDirty(ICrystalReportsEditor editor)
  {
    return EditorUtilities.getDefaultSaveBehavior().isDirty(editor);
  }
}



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