Class MultiDataObject

java.lang.Object
org.openide.loaders.DataObject
org.openide.loaders.MultiDataObject
All Implemented Interfaces:
Serializable, org.openide.nodes.Node.Cookie, org.openide.util.HelpCtx.Provider, org.openide.util.Lookup.Provider
Direct Known Subclasses:
DataFolder, DataShadow, InstanceDataObject, XMLDataObject

public class MultiDataObject extends DataObject
Provides support for handling of data objects with multiple files. One file is represented by one MultiDataObject.Entry. Each handler has one primary entry and zero or more secondary entries.
See Also:
  • Constructor Details

  • Method Details

    • getMultiFileLoader

      public final MultiFileLoader getMultiFileLoader()
      Getter for the multi file loader that created this object.
      Returns:
      the multi loader for the object
    • files

      public Set<org.openide.filesystems.FileObject> files()
      Description copied from class: DataObject
      Get all contained files. These file objects should ideally have had the important flag set appropriately.

      The default implementation returns a set consisting only of the primary file.

      Overrides:
      files in class DataObject
      Returns:
      set of files
    • isDeleteAllowed

      public boolean isDeleteAllowed()
      Description copied from class: DataObject
      Test whether the object may be deleted.
      Specified by:
      isDeleteAllowed in class DataObject
      Returns:
      true if it may
    • isCopyAllowed

      public boolean isCopyAllowed()
      Description copied from class: DataObject
      Test whether the object may be copied.
      Specified by:
      isCopyAllowed in class DataObject
      Returns:
      true if it may
    • isMoveAllowed

      public boolean isMoveAllowed()
      Description copied from class: DataObject
      Test whether the object may be moved.
      Specified by:
      isMoveAllowed in class DataObject
      Returns:
      true if it may
    • isRenameAllowed

      public boolean isRenameAllowed()
      Description copied from class: DataObject
      Test whether the object may be renamed.
      Specified by:
      isRenameAllowed in class DataObject
      Returns:
      true if it may
    • getHelpCtx

      public org.openide.util.HelpCtx getHelpCtx()
      Description copied from class: DataObject
      Get help context for this object.
      Specified by:
      getHelpCtx in interface org.openide.util.HelpCtx.Provider
      Specified by:
      getHelpCtx in class DataObject
      Returns:
      the help context
    • createNodeDelegate

      protected org.openide.nodes.Node createNodeDelegate()
      Provides node that should represent this data object.
      Overrides:
      createNodeDelegate in class DataObject
      Returns:
      the node representation
      See Also:
    • addSecondaryEntry

      protected final void addSecondaryEntry(MultiDataObject.Entry fe)
      Add a new secondary entry to the list.
      Parameters:
      fe - the entry to add
    • removeSecondaryEntry

      protected final void removeSecondaryEntry(MultiDataObject.Entry fe)
      Remove a secondary entry from the list.
      Parameters:
      fe - the entry to remove
    • registerEntry

      protected final MultiDataObject.Entry registerEntry(org.openide.filesystems.FileObject fo)
      Tests whether this file is between entries and if not, creates a secondary entry for it and adds it into set of secondary entries.

      This method should be used in constructor of MultiDataObject to register all the important files, that could belong to this data object. As example, our XMLDataObject, tries to locate its xmlinfo file and then do register it

      Parameters:
      fo - the file to register (can be null, then the action is ignored)
      Returns:
      the entry associated to this file object (returns primary entry if the fo is null)
    • getPrimaryEntry

      public final MultiDataObject.Entry getPrimaryEntry()
      Get the primary entry.
      Returns:
      the entry
    • secondaryEntries

      public final Set<MultiDataObject.Entry> secondaryEntries()
      Get secondary entries.
      Returns:
      immutable set of entries
    • findSecondaryEntry

      public final MultiDataObject.Entry findSecondaryEntry(org.openide.filesystems.FileObject fo)
      For a given file, find the associated secondary entry.
      Parameters:
      fo - file object
      Returns:
      the entry associated with the file object, or null if there is no such entry
    • takePrimaryFileLock

      protected org.openide.filesystems.FileLock takePrimaryFileLock() throws IOException
      Description copied from class: DataObject
      Obtains lock for primary file.
      Overrides:
      takePrimaryFileLock in class DataObject
      Returns:
      the lock
      Throws:
      IOException - if taking the lock fails
    • handleCopy

      protected DataObject handleCopy(DataFolder df) throws IOException
      Copies primary and secondary files to new folder. May ask for user confirmation before overwriting.
      Specified by:
      handleCopy in class DataObject
      Parameters:
      df - the new folder
      Returns:
      data object for the new primary
      Throws:
      IOException - if there was a problem copying
      org.openide.util.UserCancelException - if the user cancelled the copy
    • handleDelete

      protected void handleDelete() throws IOException
      Description copied from class: DataObject
      Delete this object (implemented by subclasses).
      Specified by:
      handleDelete in class DataObject
      Throws:
      IOException - if an error occures
    • handleRename

      protected org.openide.filesystems.FileObject handleRename(String name) throws IOException
      Description copied from class: DataObject
      Rename this object (implemented in subclasses).
      Specified by:
      handleRename in class DataObject
      Parameters:
      name - name to rename the object to
      Returns:
      new primary file of the object
      Throws:
      IOException - if an error occures
    • handleMove

      protected org.openide.filesystems.FileObject handleMove(DataFolder df) throws IOException
      Moves primary and secondary files to a new folder. May ask for user confirmation before overwriting.
      Specified by:
      handleMove in class DataObject
      Parameters:
      df - the new folder
      Returns:
      the moved primary file object
      Throws:
      IOException - if there was a problem moving
      org.openide.util.UserCancelException - if the user cancelled the move
    • handleCreateFromTemplate

      protected DataObject handleCreateFromTemplate(DataFolder df, String name) throws IOException
      Description copied from class: DataObject
      Create a new data object from template (implemented in subclasses). This method should copy the content of the template to the destination folder and assign a new name to the new object.
      Specified by:
      handleCreateFromTemplate in class DataObject
      Parameters:
      df - data folder to create object in
      name - name to give to the new object (or null if the name should be chosen according to the template)
      Returns:
      the new data object
      Throws:
      IOException - if an error occured
    • handleCopyRename

      protected DataObject handleCopyRename(DataFolder df, String name, String ext) throws IOException
      Description copied from class: DataObject
      Copy and rename this object to a folder (implemented by subclasses).
      Overrides:
      handleCopyRename in class DataObject
      Parameters:
      df - target folder
      name - new file name
      ext - new file extension
      Returns:
      the new data object
      Throws:
      IOException - if an error occures or the file cannot be copied/renamed
    • setCookieSet

      @Deprecated protected final void setCookieSet(org.openide.nodes.CookieSet s)
      Deprecated.
      just use getCookieSet().add(...) instead
      Set the set of cookies. To the provided cookie set a listener is attached, and any change to the set is propagated by firing a change on DataObject.PROP_COOKIE.
      Parameters:
      s - the cookie set to use
    • getCookieSet

      protected final org.openide.nodes.CookieSet getCookieSet()
      Get the set of cookies. If the set had been previously set by setCookieSet(org.openide.nodes.CookieSet), that set is returned. Otherwise an empty set is returned.
      Returns:
      the cookie set (never null)
    • getCookie

      public <T extends org.openide.nodes.Node.Cookie> T getCookie(Class<T> type)
      Look for a cookie in the current cookie set matching the requested class.
      Overrides:
      getCookie in class DataObject
      Parameters:
      type - the class to look for
      Returns:
      an instance of that class, or null if this class of cookie is not supported
    • getLookup

      public org.openide.util.Lookup getLookup()
      Description copied from class: DataObject
      Represents a context of the data object. This method is a more general replacement for DataObject.getCookie(java.lang.Class<T>) and should preferably be used instead of the old method. The default implementation inside a data object returns the getNodeDelegate().getLookup() - which is the most compatible behaviour with previous versions. However this code has significant potential to deadlocks. That is why the preferred advice is to override the method to:
       class MyDataObject extends MultiDataObject {
         public @Override Lookup getLookup() {
           return getCookieSet().getLookup();
         }
       }
       

      Warning: the DataObject.getCookie(java.lang.Class<T>) method and DataObject.getLookup() method are ment to be interchangable - e.g. if you override one of them be sure to override also the other and try as much as possible to keep the same content in each of them. The default implementation tries to do that as much as possible.

      Specified by:
      getLookup in interface org.openide.util.Lookup.Provider
      Overrides:
      getLookup in class DataObject
      Returns:
      lookup representing this data object and its content
    • associateLookup

      protected int associateLookup()
      Influences behavior of getLookup() method. Depending on the returned integer, one can get different, better and more modern content of the Lookup:
      • version 0 - delegates to getNodeDelegate().getLookup().
      • version 1 - delegates to getCookieSet().getLookup() and makes sure FileObject, this and Node are in the lookup. The Node is created lazily by calling DataObject.getNodeDelegate().
      General suggestion is to always return the highest supported version when creating new objects and to stick with certain version when backward compatibility is requested.
      Returns:
      version identifying content of the lookup (currently 0 or 1)
      Since:
      7.27
    • registerEditor

      protected final void registerEditor(String mimeType, boolean useMultiview)
      Utility method to register editor for this DataObject. Call it from constructor with appropriate mimeType. The system will make sure that appropriate cookies (Openable, Editable, CloseCookie, EditorCookie, SaveAsCapable, LineCookie are registered into getCookieSet().

      The selected editor is MultiView component, if requested (this requires presence of the MultiView API in the system. Otherwise it is plain CloneableEditor.

      Parameters:
      mimeType - mime type to associate with
      useMultiview - should the used component be multiview?
      Since:
      7.27