Class IdvPersistenceManager

All Implemented Interfaces:
ActionListener, EventListener, IdvConstants, PrototypeManager

public class IdvPersistenceManager extends IdvManager implements PrototypeManager
This class defines what is to be saved when we are doing an advanced save of the state to a bundle
Author:
IDV development team
  • Field Details

  • Constructor Details

    • IdvPersistenceManager

      public IdvPersistenceManager(IntegratedDataViewer idv)
      The ctor
      Parameters:
      idv - The IDV
  • Method Details

    • getControlDescriptors

      public void getControlDescriptors(List l)
      Create and add into the list the specical ControlDescriptors that use the display templates.
      Parameters:
      l - List of control descriptors to add to
    • setFileMapping

      public void setFileMapping(List ids, List files)
      Define one or more file mappings. The ids is a list of Strings that are used to identify a data source. The files is a list of Lists of filenames, one list for each corresponding data source id. This gets used when we unpersist data sources. If we have any file mappings we pass these onto the data source so they can change their actual file
      Parameters:
      ids - List of String ids
      files - List of lists of filenames
    • clearFileMapping

      public void clearFileMapping()
      Clear any filemappings.
    • setAddWindows

      public void setAddWindows(boolean bl)
      create window in the ISL offscreen mode
    • addFileMapping

      public void addFileMapping(String identifier, List files)
      Add a file mapping. See above.
      Parameters:
      identifier - Id use to identify a data source
      files - List of files (or urls).
    • getFileAccessory

      public JPanel getFileAccessory()
      Create, if needed, and return te GUI panel to put into the file dialog when saving a file.
      Returns:
      The file accessory panel
    • categoriesToString

      public static String categoriesToString(List cats)
      Utility to convert a list of categories into a single string to show the user.
      Parameters:
      cats - List of categories - String.
      Returns:
      String representation
    • stringToCategories

      public static List stringToCategories(String category)
      Retur a list of categories from the given string
      Parameters:
      category - The string representation of the categories
      Returns:
      List of (String) categories
    • fileToCategories

      public static List<String> fileToCategories(String root, String filename)
      The given filename is a full path under the given root. This method prunes the root path from the filepath and splits the filepath into a list of categories.
      Parameters:
      root - File root
      filename - File path to split
      Returns:
      List of (String) categories
    • getBundleXml

      public static String getBundleXml(List<SavedBundle> bundles, boolean includeCategoryInUrl)
      Make the bundles xml
      Parameters:
      bundles - List of saved bundle
      includeCategoryInUrl - Should we add the category to the file name
      Returns:
      bundles.xml
    • getXmlBundles

      public List<SavedBundle> getXmlBundles(int type)
      get list of xml bundles for the given type
      Parameters:
      type - bundle type
      Returns:
      list of bundles
    • getFavorites

      public List<SavedBundle> getFavorites()
      Create, if needed, and return the list of SavedBundles
      Returns:
      List of saved bundles
    • getCurrentFileName

      public String getCurrentFileName()
      Get the last xidv filename for doing saves/saveas.
      Returns:
      The last xidv file name
    • setCurrentFileName

      public void setCurrentFileName(String f)
      Set the last xidv filename for doing saves/saveas.
      Parameters:
      f - The filename
    • doSaveAs

      public void doSaveAs()
      Have the user select an xidv filename and write the current application state to it. This also sets the current file name and adds the file to the history list.
    • doSaveAs

      public void doSaveAs(String filename)
      This api is called from the ISL to generate the zidv file using the export tag with what equals zidv and filename
    • moveCategory

      public void moveCategory(List fromCategories, List toCategories, int bundleType)
      Move the bundle category
      Parameters:
      fromCategories - The category to move
      toCategories - Where to move to
      bundleType - What type are we dealing with
    • export

      public void export(SavedBundle bundle, int bundleType)
      Export the bundle
      Parameters:
      bundle - The bundle
      bundleType - What type
    • rename

      public void rename(SavedBundle bundle, int bundleType)
      Rename the bundle
      Parameters:
      bundle - The bundle
      bundleType - What type
    • copyBundle

      public void copyBundle(SavedBundle bundle, List categories, int bundleType)
      Copy the bundle to the given category area
      Parameters:
      bundle - The bundle
      categories - The category location
      bundleType - What type
    • moveBundle

      public void moveBundle(SavedBundle bundle, List categories, int bundleType)
      Move the bundle to the given category area
      Parameters:
      bundle - The bundle
      categories - The category location
      bundleType - What type
    • moveOrCopyBundle

      public void moveOrCopyBundle(SavedBundle bundle, List categories, int bundleType, boolean move)
      Move or copy the bundle to the given category area, depending on the given argument.
      Parameters:
      bundle - The bundle
      categories - The category location
      bundleType - What type
      move - Move or copy
    • makeCategoryBox

      public JComboBox makeCategoryBox()
      make category widget
      Returns:
      box
    • doImport

      public void doImport(int bundleType, String file, String category)
      Import the given file as the given bundle type
      Parameters:
      bundleType - What type
      file - The file
      category - The category
    • getFavoritesCategories

      public List getFavoritesCategories()
      get categories
      Returns:
      categories
    • doSaveAsFavorite

      public void doSaveAsFavorite()
      Have the user select an xidv filename for their favorites
    • doSave

      public void doSave()
      Save the current state off to the current xidv filename
    • doSaveAsDefault

      public void doSaveAsDefault()
      Called from the menu command to save the current state as the default bundle
    • doOpenDefault

      public void doOpenDefault()
      Called from the menu command to open the default bundle
    • doSave

      public boolean doSave(String filename)
      Save the current state into the specified filename
      Parameters:
      filename - bundle file name to write to. If this ends in ".jnlp" then we base 64 encode the bundle and wrap it in a jnlp file.
      Returns:
      Was this save successful
    • getJnlpBundle

      public String getJnlpBundle(String xml)
      A utility to create a jnlp file from the given bundle
      Parameters:
      xml - The bundle xml
      Returns:
      The jnlp file xml
    • getJnlpBundle

      public String getJnlpBundle(String xml, boolean embedBundle, String extraArgs)
      A utility to create a jnlp file from the given bundle
      Parameters:
      xml - The bundle xml
      embedBundle - Embed the b64 encoded bundle right in the jnlp
      extraArgs - extra jnlp args
      Returns:
      The jnlp file xml
    • doSave

      public boolean doSave(String filename, boolean usePersistenceManager)
      Save the current state into the specified filename
      Parameters:
      filename - bundle file name to write to. If this ends in ".jnlp" then we base 64 encode the bundle and wrap it in a jnlp file.
      usePersistenceManager - If true then we use the persistence manager to determine what is to be saved.
      Returns:
      Was this save successful
    • doSave

      public boolean doSave(String filename, boolean usePersistenceManager, boolean fromIsl)
      Save the current state into the specified filename
      Parameters:
      filename - bundle file name to write to. If this ends in ".jnlp" then we base 64 encode the bundle and wrap it in a jnlp file.
      usePersistenceManager - If true then we use the persistence manager to determine what is to be saved.
      fromIsl - If this api is invoked from the ISL script and save a zidv bundle it will call the nogui api to save all display data
      Returns:
      Was this save successful
    • getBundleXml

      public String getBundleXml(boolean formatXml) throws Exception
      This creates an xml encoded hashtable that contains the application state.
      Parameters:
      formatXml - Should the result be formatted (i.e., new lines and indents for easy reading).
      Returns:
      The xml encoded application state
      Throws:
      Exception - the exception
    • getBundleXml

      public String getBundleXml(boolean formatXml, boolean usePersistenceManager) throws Exception
      This creates an xml encoded hashtable that contains the application state.
      Parameters:
      formatXml - Should the result be formatted (i.e., new lines and indents for easy reading).
      usePersistenceManager - If true then use the persistence manager to decide what is saved
      Returns:
      The xml encoded application state
      Throws:
      Exception - the exception
    • instantiateFromTemplate

      public DisplayControl instantiateFromTemplate(String templateFile)
      Create the DisplayControl from the bundle in the given templateFile
      Parameters:
      templateFile - File path to the template
      Returns:
      The instantiated DisplayControl
    • getAllCategories

      public List getAllCategories(int bundleType)
      Get a list of all of the categories for the given bundleType
      Parameters:
      bundleType - What type of bundle (e.g., favorites)
      Returns:
      List of (String) categories
    • getBundleTitle

      public String getBundleTitle(int bundleType)
      Get the title to use for the given bundle type
      Parameters:
      bundleType - The type of bundle (e.g., favorites)
      Returns:
      The title
    • getBundleDirectory

      public String getBundleDirectory(int bundleType)
      Get the directory that holds the given bundle type
      Parameters:
      bundleType - The type of bundle (e.g., favorites)
      Returns:
      The directory
    • getBundles

      public List<SavedBundle> getBundles(int bundleType)
      Get the list of SavedBundles
      Parameters:
      bundleType - The type of bundle (e.g., favorites)
      Returns:
      List of bundles
    • initBundleMenu

      public void initBundleMenu(int bundleType, JMenu bundleMenu)
      Initialize the bundle menu
      Parameters:
      bundleType - The type of bundle (e.g., favorites)
      bundleMenu - The menu
    • getWritableBundles

      public List getWritableBundles(int bundleType)
      Get the list of SavedBundles that are writable
      Parameters:
      bundleType - The type of bundle (e.g., favorites)
      Returns:
      List of writable bundles
    • saveDataSource

      public void saveDataSource(DataSource dataSource)
      Parameters:
      dataSource - data source to save
    • saveDisplayControlFavorite

      public void saveDisplayControlFavorite(DisplayControl displayControl, String templateName)
      Prompt the user for a name and write out the given display control as a bundle into the user's .unidata/idv/displaytemplates directory.
      Parameters:
      displayControl - The display control to write
      templateName - Possibly null initial name for the template
    • saveDisplayControl

      public void saveDisplayControl(DisplayControl displayControl)
      Write out the given display control
      Parameters:
      displayControl - The display control to write
    • saveDisplayControl

      public void saveDisplayControl(DisplayControl displayControl, File file)
      Write out the given display control to te given file
      Parameters:
      displayControl - The display control to write
      file - The file to write to
    • getLocalBundles

      public List<SavedBundle> getLocalBundles()
      Create, if needed, and return the list of locally saved SavedBundles
      Returns:
      List of saved bundles
    • getDataSourceBundles

      public List<SavedBundle> getDataSourceBundles()
      Get list of data soruce bundles
      Returns:
      data source bundle list
    • getDisplayTemplates

      public List<SavedBundle> getDisplayTemplates()
      Get the list of display templates. This is a list of String file paths
      Returns:
      List of display template
    • open

      public boolean open(SavedBundle bundle)
      Open the given bundle
      Parameters:
      bundle - The bundle to open
      Returns:
      success
    • open

      public boolean open(SavedBundle bundle, boolean askToRemove)
      Open the given bundle
      Parameters:
      bundle - bundle
      askToRemove - ask
      Returns:
      success
    • deleteBundle

      public void deleteBundle(String templateFile)
      Remove the given template
      Parameters:
      templateFile - The template file to remove
    • deleteBundleCategory

      public void deleteBundleCategory(int bundleType, String category)
      Delete the directory and all of its contents that the given category represents.
      Parameters:
      bundleType - The type of bundle (e.g., favorites)
      category - The category (really a directory path)
    • addBundleCategory

      public boolean addBundleCategory(int bundleType, String category)
      Add the directory
      Parameters:
      bundleType - The type of bundle (e.g., favorites)
      category - The category (really a directory path)
      Returns:
      true if the create was successfull. False if there already is a category with that name
    • getDataSourcesToPersist

      protected List getDataSourcesToPersist()
      Get the data sources we should persist
      Returns:
      Data sources to persist
    • addToBundle

      protected boolean addToBundle(Hashtable data, boolean usePersistenceManager, List displayControls) throws Exception
      This method adds into the given hashtable the data sources, display controls, view managers and extra gui state for later persistence.
      Parameters:
      data - The table to put things into
      usePersistenceManager - Should we use the settings of this manager
      displayControls - The display controls to add
      Returns:
      If user is ok
      Throws:
      Exception - When something bad happens
    • addToBundle

      protected boolean addToBundle(Hashtable data, List dataSources, List displayControls, List viewManagers, String jython)
      Add the given state, if non null, to the bundle hashtable
      Parameters:
      data - Holds the bundle state
      dataSources - List of data sources to add
      displayControls - List of displays to add
      viewManagers - List of view managers to add
      jython - jython to add
      Returns:
      If user is ok
    • loadB64Bundle

      public void loadB64Bundle(String base64Bundle)
      This converts the given base 64 encoded xml bundle into an xml String and loads it in. It prints out UI messages and shows the wait cursor.
      Parameters:
      base64Bundle - The base64 encoded xml bundle
    • decodeBase64Bundle

      public void decodeBase64Bundle(String base64Bundle)
      This does the actual work of converting the given base 64 encoded bundle xml into a String and loading it in.
      Parameters:
      base64Bundle - The base64 encoded xml bundle
    • decodeJnlpFile

      public void decodeJnlpFile(String filename)
      Decode the jnlp file
      Parameters:
      filename - the name of the file
    • extractBundleFromJnlp

      public String extractBundleFromJnlp(String filename)
      This reads in the jnlp xml from the given filename. It extracts from the "arguments" section of the xml the -b64bundle values. This is the base 64 encoded xml bundle. It then loads in the bundle.
      Parameters:
      filename - The name of the jnlp file.
      Returns:
      the bundle
    • decodeXmlFile

      public boolean decodeXmlFile(String xmlFile, boolean checkToRemove)
      Read in the contents of the given xmlFile and evaluate the xml
      Parameters:
      xmlFile - The bundle file
      checkToRemove - Should check the user preference to remove all/show dialog or not.
      Returns:
      success
    • decodeXmlFile

      public boolean decodeXmlFile(String xmlFile, boolean checkToRemove, boolean letUserChangeData)
      Read in the contents of the given xmlFile and evaluate the xml
      Parameters:
      xmlFile - file
      checkToRemove - check to remove
      letUserChangeData - Set the 'user changes data flag' on decoding
      Returns:
      everything cool
    • decodeXmlFile

      public boolean decodeXmlFile(String xmlFile, boolean checkToRemove, Hashtable bundleProperties)
      Read in the contents of the given xmlFile and evaluate the xml
      Parameters:
      xmlFile - The bundle file
      checkToRemove - Should check the user preference to remove all/show dialog or not.
      bundleProperties - set of properties
      Returns:
      success
    • decodeXmlFile

      public boolean decodeXmlFile(String xmlFile, String label, boolean checkToRemove)
      Read in the contents of the given xmlFile and evaluate the xml
      Parameters:
      xmlFile - The bundle file
      label - If non-null ten use this as te load dialog label
      checkToRemove - Should check the user preference to remove all/show dialog or not.
      Returns:
      success
    • decodeXmlFile

      public boolean decodeXmlFile(String xmlFile, String label, boolean checkToRemove, Hashtable bundleProperties)
      Import the bundle file
      Parameters:
      xmlFile - file name
      label - description for dialog
      checkToRemove - Should we ask the user about removing data/displays
      bundleProperties - set of properties
      Returns:
      success
    • decodeXmlFile

      public boolean decodeXmlFile(String xmlFile, String label, boolean checkToRemove, boolean letUserChangeData, Hashtable bundleProperties)
      decode the xml
      Parameters:
      xmlFile - file
      label - label
      checkToRemove - check to remove
      letUserChangeData - if true then ask user to change data paths
      bundleProperties - set of properties
      Returns:
      everything cool
    • decodeXml

      public void decodeXml(String xml, boolean fromCollab, String label, boolean showDialog)
      Using the XmlEncoder, decode the given xml string. This typically is a Hashtable, encoded by the doSave method, that holds a list of data sources, display controls, etc.

      This method wraps a call to decodeXmlInner, setting LOADINGXML flags, etc.

      Parameters:
      xml - The bundle xml
      fromCollab - Was this bundle from the collaboration facility. If it was we treat it differently.
      label - The label to use in the dialog
      showDialog - Should the dialog be shown
    • decodeXml

      public void decodeXml(String xml, boolean fromCollab, String xmlFile, String label, boolean showDialog, boolean shouldMerge, Hashtable bundleProperties, boolean didRemoveAll, boolean letUserChangeData)
      Using the XmlEncoder, decode the given xml string. This typically is a Hashtable, encoded by the doSave method, that holds a list of data sources, display controls, etc.

      This method wraps a call to decodeXmlInner, setting LOADINGXML flags, etc.

      Parameters:
      xml - The bundle xml
      fromCollab - Was this bundle from the collaboration facility. If it was we treat it differently.
      xmlFile - The filename this came from. May be null.
      label - The label to use in the dialog
      showDialog - Should the dialog be shown
      shouldMerge - Should we merge the windows/views in the bundle into the existing windows
      bundleProperties - set of properties
      didRemoveAll - Should we remove all data/displays
      letUserChangeData - Should popup the data path dialog
    • decodeXmlInner

      protected void decodeXmlInner(String xml, boolean fromCollab, String xmlFile, String label, boolean showDialog)
      This does the real work of decoding an xml bundle.
      Parameters:
      xml - The xml bundle
      fromCollab - Was this bundle from the collaboration facility. If it was we treat it differently.
      xmlFile - The filename where the xml came from - may be null.
      label - The label to show in the gui
      showDialog - Should the loadbundle dialog be shown
    • applyPropertiesToBundle

      protected String applyPropertiesToBundle(String xml)
      replace any macros in the bundle xml
      Parameters:
      xml - bundle xml
      Returns:
      replaced bundle xml
    • decodeXmlInner

      protected void decodeXmlInner(String xml, boolean fromCollab, String xmlFile, String label, boolean showDialog, boolean shouldMerge, Hashtable bundleProperties, boolean didRemoveAll, boolean letUserChangeData)
      This does the real work of decoding an xml bundle.
      Parameters:
      xml - The xml bundle
      fromCollab - Was this bundle from the collaboration facility. If it was we treat it differently.
      xmlFile - The filename where the xml came from - may be null.
      label - The label to show in the gui
      showDialog - Should the loadbundle dialog be shown
      shouldMerge - Should we merge the windows/views in the bundle into the existing windows
      bundleProperties - set of properties
      didRemoveAll - Was remove all called before we decoded the xml
      letUserChangeData - Should popup data path change dialog
    • changeData

      public void changeData(Object[] input)
      change data
      Parameters:
      input - the input
    • changeState

      public boolean changeState(DataSource dataSource)
      n/a
      Parameters:
      dataSource - the data source
      Returns:
      n/a
    • changeState

      public boolean changeState(DataSource dataSource, boolean andReload)
      n/a
      Parameters:
      dataSource - the data source
      andReload - and reload the data
      Returns:
      n/a
    • instantiateFromBundle

      protected void instantiateFromBundle(Hashtable ht, boolean fromCollab, LoadBundleDialog loadDialog, boolean shouldMerge, Hashtable bundleProperties, boolean didRemoveAll, boolean letUserChangeData) throws Exception
      The given Hashtable contains the objects taht were saved in the xml bundle file. The hashtable may contain a list of data sources, a list of display controls and a list of view managers. This method initializes these objects adn adds them into the current application state.
      Parameters:
      ht - Contains the unpersisted objects
      fromCollab - Was this bundle from the collaboration facility. If it was we treat it differently.
      loadDialog - The load bundle dialog
      shouldMerge - Should we merge the windows/views in the bundle into the existing windows
      bundleProperties - set of properties
      didRemoveAll - Was remove all called before we decoded the xml
      letUserChangeData - Should popup data path change dialog
      Throws:
      Exception - the exception
    • makeDataSourceFromXml

      public DataSourceResults makeDataSourceFromXml(String dataSourceXml)
      This creates a new data source from the xml encoded representation of a persisted data source. It is used in the data source history mechanism.
      Parameters:
      dataSourceXml - The xml encoded data source representation
      Returns:
      The results that hold the new data source.
    • getSaveViewState

      public boolean getSaveViewState()
      Should the view state be saved
      Returns:
      Save the view state
    • getSaveDisplays

      public boolean getSaveDisplays()
      Should the displays be saved
      Returns:
      Save the displays
    • getSaveDataSources

      public boolean getSaveDataSources()
      Should the data sources be saved
      Returns:
      Save the data sources
    • getSaveJython

      public boolean getSaveJython()
      Should the jython be saved
      Returns:
      Save the data sources
    • getSaveData

      public boolean getSaveData()
      Should the visad data be saved
      Returns:
      Save the visad data
    • getCurrentTemplateName

      public String getCurrentTemplateName()
      Get the CurrentTemplateName property.
      Returns:
      The CurrentTemplateName
    • writePrototype

      public void writePrototype(Object object)
      Save off the given object as a prototype
      Specified by:
      writePrototype in interface PrototypeManager
      Parameters:
      object - Object to write as prototype
    • clearPrototype

      public void clearPrototype(Class c)
      Clear the prototype for the given class
      Parameters:
      c - class
    • getPrototype

      public Object getPrototype(Class c)
      Instantiate a new object for the given class. This will return null if there is not a prototype defined for the class
      Specified by:
      getPrototype in interface PrototypeManager
      Parameters:
      c - class
      Returns:
      new object or null
    • getBundleIdvVersion

      public static String getBundleIdvVersion()
      Gets the bundle idv version.
      Returns:
      the bundle idv version