Class TLcyMutableFileFormatWrapper


public class TLcyMutableFileFormatWrapper extends ALcyFormatWrapper

This format decorator adds workspace support for saving changed models. When saving the workspace, it uses the format's ILcdModelEncoder to export every ILcdModel of this format into a companion file. When the workspace is decoded, the companion file is decoded to restore the model, using the ILcdModelDecoder.

This format wrapper creates a ALcyWorkspaceObjectCodec for the ILcdModel's to achieve this, so you shouldn't have to provide one yourself.

The name of the companion file is either automatically chosen, or the user is prompted for input. See TLcyMutableFileFormatWrapper(ALcyFormat, boolean, boolean).

Assumptions:

  • model.getModelDescriptor().getDisplayName() is in sync with layer.getLabel(), so that getDisplayName() can be used as the name to present to the user. For instance, ILcySimulatorModelFactory only gets access to the model, not the layer.
  • The ILcdModelEncoders must adapt the source name of the model descriptor in their export method, so that the source name of the model always corresponds to the location where the model was last saved. In code: ILcdModel.getModelDescriptor().getSourceName() must be equal to the last destination name given to ILcdModelEncoder.export.
  • Constructor Details

    • TLcyMutableFileFormatWrapper

      public TLcyMutableFileFormatWrapper(ALcyFormat aFormat)

      Creates a wrapper for the given format that enables models to be saved. When a model is modified, it will ask the user to save the changes to a file name of choice.

      Equivalent to TLcyMutableFileFormatWrapper(aFormat, false, false)

      Parameters:
      aFormat - the format to add workspace saving for.
      See Also:
    • TLcyMutableFileFormatWrapper

      public TLcyMutableFileFormatWrapper(ALcyFormat aFormat, boolean aAutoSave, boolean aWorkspaceOnly)
      Creates a wrapper for the given format that enables models to be saved.
      Parameters:
      aFormat - the format to add workspace saving for.
      aAutoSave - if true, it automatically picks a name for the companion file to save the model to. If false, the user is prompted with a file chooser to pick an appropriate name for the companion file.
      aWorkspaceOnly - if true, hides the format's model decoders and encoders from ILcyLucyEnv. This means the user for example won't be able to load a companion file directly using File|Open. If false, the model decoders and encoders of the format are registered with the ILcyLucyEnv, as is normally the case, so they can be used by other parts of the application.