Class DataShadow

All Implemented Interfaces:
Serializable, DataObject.Container, org.openide.nodes.Node.Cookie, org.openide.util.HelpCtx.Provider, org.openide.util.Lookup.Provider

public class DataShadow extends MultiDataObject implements DataObject.Container
Default implementation of a shortcut to another data object. Since 1.13 it extends MultiDataObject.
See Also:
  • Constructor Details

    • DataShadow

      protected DataShadow(org.openide.filesystems.FileObject fo, DataObject original, MultiFileLoader loader) throws DataObjectExistsException
      Constructs new data shadow for given primary file and referenced original. Method to allow subclasses of data shadow.
      Parameters:
      fo - the primary file
      original - original data object
      loader - the loader that created the object
      Throws:
      DataObjectExistsException
    • DataShadow

      @Deprecated protected DataShadow(org.openide.filesystems.FileObject fo, DataObject original, DataLoader loader) throws DataObjectExistsException
      Deprecated.
      Since 1.13 do not use this constructor, it is for backward compatibility only
      Constructs new data shadow for given primary file and referenced original. Method to allow subclasses of data shadow.
      Parameters:
      fo - the primary file
      original - original data object
      loader - the loader that created the object
      Throws:
      DataObjectExistsException
  • Method Details

    • create

      public static DataShadow create(DataFolder folder, DataObject original) throws IOException
      Method that creates new data shadow in a folder. The name chosen is based on the name of the original object.
      Parameters:
      folder - target folder to create data in
      original - original object that should be represented by the shadow
      Throws:
      IOException
    • create

      public static DataShadow create(DataFolder folder, String name, DataObject original) throws IOException
      Method that creates new data shadow in a folder. The default extension is used.
      Parameters:
      folder - target folder to create data in
      name - name to give to the shadow
      original - object that should be represented by the shadow
      Throws:
      IOException
    • create

      public static DataShadow create(DataFolder folder, String name, DataObject original, String ext) throws IOException
      Method that creates new data shadow in a folder. All modifications are done atomically using FileSystem.runAtomicAction(org.openide.filesystems.FileSystem.AtomicAction).
      Parameters:
      folder - target folder to create data in
      name - name to give to the shadow
      original - original object that should be represented by the shadow
      Throws:
      IOException
    • findOriginal

      public static org.openide.filesystems.FileObject findOriginal(org.openide.filesystems.FileObject fileObject) throws IOException
      Tries to locate the original file from a shadow. Looks for file contents as well as the originalFile/originalFileSystem attributes. Attempts to discover locations for migrated files in configuration. Returns null, if the target file could not be found (broken link)
      Parameters:
      fileObject - a data shadow
      Returns:
      the original FileObject referenced by the shadow
      Throws:
      IOException - error during load
      Since:
      7.42
      See Also:
      • Utilities.translate(java.lang.String)
    • deserialize

      protected static DataObject deserialize(org.openide.filesystems.FileObject fileObject) throws IOException
      Tries to load the original file from a shadow. Looks for file contents as well as the originalFile/originalFileSystem attributes. Attempts to discover locations for migrated files in configuration.
      Parameters:
      fileObject - a data shadow
      Returns:
      the original DataObject referenced by the shadow
      Throws:
      IOException - error during load or broken link
      See Also:
      • Utilities.translate(java.lang.String)
    • getOriginal

      public DataObject getOriginal()
      Return the original shadowed object.
      Returns:
      the data object
    • getChildren

      public DataObject[] getChildren()
      Implementation of Container interface.
      Specified by:
      getChildren in interface DataObject.Container
      Returns:
      array of one element, the original
    • createNodeDelegate

      protected org.openide.nodes.Node createNodeDelegate()
      Description copied from class: MultiDataObject
      Provides node that should represent this data object.
      Overrides:
      createNodeDelegate in class MultiDataObject
      Returns:
      the node representation
      See Also:
    • isDeleteAllowed

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

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

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

      public boolean isRenameAllowed()
      Description copied from class: DataObject
      Test whether the object may be renamed.
      Overrides:
      isRenameAllowed in class MultiDataObject
      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
      Overrides:
      getHelpCtx in class MultiDataObject
      Returns:
      the help context
    • handleCreateShadow

      protected DataShadow handleCreateShadow(DataFolder f) throws IOException
      Description copied from class: DataObject
      Creates shadow for this object in specified folder (overridable in subclasses).

      The default implementation creates a reference data shadow and pastes it into the specified folder.

      Overrides:
      handleCreateShadow in class DataObject
      Parameters:
      f - the folder to create a shortcut in
      Returns:
      the shadow
      Throws:
      IOException
    • getCookie

      public <T extends org.openide.nodes.Node.Cookie> T getCookie(Class<T> c)
      Description copied from class: MultiDataObject
      Look for a cookie in the current cookie set matching the requested class.
      Overrides:
      getCookie in class MultiDataObject
      Parameters:
      c - 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 MultiDataObject
      Returns:
      lookup representing this data object and its content
    • refresh

      public void refresh()
    • handleCopy

      protected DataObject handleCopy(DataFolder f) throws IOException
      Description copied from class: MultiDataObject
      Copies primary and secondary files to new folder. May ask for user confirmation before overwriting.
      Overrides:
      handleCopy in class MultiDataObject
      Parameters:
      f - the new folder
      Returns:
      data object for the new primary
      Throws:
      IOException - if there was a problem copying
    • handleMove

      protected org.openide.filesystems.FileObject handleMove(DataFolder f) throws IOException
      Description copied from class: MultiDataObject
      Moves primary and secondary files to a new folder. May ask for user confirmation before overwriting.
      Overrides:
      handleMove in class MultiDataObject
      Parameters:
      f - the new folder
      Returns:
      the moved primary file object
      Throws:
      IOException - if there was a problem moving