Class 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
MultiDataObject.Entry
. Each handler
has one primary
entry and zero or more secondary entries.- See Also:
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from class org.openide.loaders.DataObject
DataObject.Container, DataObject.Factory, DataObject.Registration, DataObject.Registrations, DataObject.Registry
-
Field Summary
Fields inherited from class org.openide.loaders.DataObject
PROP_COOKIE, PROP_FILES, PROP_HELP, PROP_MODIFIED, PROP_NAME, PROP_PRIMARY_FILE, PROP_TEMPLATE, PROP_VALID
-
Constructor Summary
ConstructorsConstructorDescriptionMultiDataObject
(org.openide.filesystems.FileObject fo, MultiFileLoader loader) Create a MultiFileObject. -
Method Summary
Modifier and TypeMethodDescriptionprotected final void
Add a new secondary entry to the list.protected int
Influences behavior ofgetLookup()
method.protected org.openide.nodes.Node
Provides node that should represent this data object.Set
<org.openide.filesystems.FileObject> files()
Get all contained files.final MultiDataObject.Entry
findSecondaryEntry
(org.openide.filesystems.FileObject fo) For a given file, find the associated secondary entry.<T extends org.openide.nodes.Node.Cookie>
TLook for a cookie in the current cookie set matching the requested class.protected final org.openide.nodes.CookieSet
Get the set of cookies.org.openide.util.HelpCtx
Get help context for this object.org.openide.util.Lookup
Represents a context of the data object.final MultiFileLoader
Getter for the multi file loader that created this object.final MultiDataObject.Entry
Get the primary entry.protected DataObject
handleCopy
(DataFolder df) Copies primary and secondary files to new folder.protected DataObject
handleCopyRename
(DataFolder df, String name, String ext) Copy and rename this object to a folder (implemented by subclasses).protected DataObject
handleCreateFromTemplate
(DataFolder df, String name) Create a new data object from template (implemented in subclasses).protected void
Delete this object (implemented by subclasses).protected org.openide.filesystems.FileObject
handleMove
(DataFolder df) Moves primary and secondary files to a new folder.protected org.openide.filesystems.FileObject
handleRename
(String name) Rename this object (implemented in subclasses).boolean
Test whether the object may be copied.boolean
Test whether the object may be deleted.boolean
Test whether the object may be moved.boolean
Test whether the object may be renamed.protected final void
registerEditor
(String mimeType, boolean useMultiview) Utility method to register editor for thisDataObject
.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.protected final void
Remove a secondary entry from the list.final Set
<MultiDataObject.Entry> Get secondary entries.protected final void
setCookieSet
(org.openide.nodes.CookieSet s) Deprecated.just use getCookieSet().add(...) insteadprotected org.openide.filesystems.FileLock
Obtains lock for primary file.Methods inherited from class org.openide.loaders.DataObject
addPropertyChangeListener, addVetoableChangeListener, copy, createFromTemplate, createFromTemplate, createFromTemplate, createShadow, delete, dispose, find, firePropertyChange, fireVetoableChange, getCookie, getFolder, getLoader, getName, getNodeDelegate, getPrimaryFile, getRegistry, handleCreateShadow, isModified, isShadowAllowed, isTemplate, isValid, markFiles, move, removePropertyChangeListener, removeVetoableChangeListener, rename, setModified, setTemplate, setValid, toString, writeReplace
-
Constructor Details
-
MultiDataObject
public MultiDataObject(org.openide.filesystems.FileObject fo, MultiFileLoader loader) throws DataObjectExistsException Create a MultiFileObject.- Parameters:
fo
- the primary file objectloader
- loader of this data object- Throws:
DataObjectExistsException
- See Also:
-
-
Method Details
-
getMultiFileLoader
Getter for the multi file loader that created this object.- Returns:
- the multi loader for the object
-
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 classDataObject
- Returns:
- set of files
-
isDeleteAllowed
public boolean isDeleteAllowed()Description copied from class:DataObject
Test whether the object may be deleted.- Specified by:
isDeleteAllowed
in classDataObject
- 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 classDataObject
- 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 classDataObject
- 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 classDataObject
- 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 interfaceorg.openide.util.HelpCtx.Provider
- Specified by:
getHelpCtx
in classDataObject
- Returns:
- the help context
-
createNodeDelegate
protected org.openide.nodes.Node createNodeDelegate()Provides node that should represent this data object.- Overrides:
createNodeDelegate
in classDataObject
- Returns:
- the node representation
- See Also:
-
addSecondaryEntry
Add a new secondary entry to the list.- Parameters:
fe
- the entry to add
-
removeSecondaryEntry
Remove a secondary entry from the list.- Parameters:
fe
- the entry to remove
-
registerEntry
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
-
secondaryEntries
Get secondary entries.- Returns:
- immutable set of entries
-
findSecondaryEntry
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
Description copied from class:DataObject
Obtains lock for primary file.- Overrides:
takePrimaryFileLock
in classDataObject
- Returns:
- the lock
- Throws:
IOException
- if taking the lock fails
-
handleCopy
Copies primary and secondary files to new folder. May ask for user confirmation before overwriting.- Specified by:
handleCopy
in classDataObject
- Parameters:
df
- the new folder- Returns:
- data object for the new primary
- Throws:
IOException
- if there was a problem copyingorg.openide.util.UserCancelException
- if the user cancelled the copy
-
handleDelete
Description copied from class:DataObject
Delete this object (implemented by subclasses).- Specified by:
handleDelete
in classDataObject
- Throws:
IOException
- if an error occures
-
handleRename
Description copied from class:DataObject
Rename this object (implemented in subclasses).- Specified by:
handleRename
in classDataObject
- Parameters:
name
- name to rename the object to- Returns:
- new primary file of the object
- Throws:
IOException
- if an error occures
-
handleMove
Moves primary and secondary files to a new folder. May ask for user confirmation before overwriting.- Specified by:
handleMove
in classDataObject
- Parameters:
df
- the new folder- Returns:
- the moved primary file object
- Throws:
IOException
- if there was a problem movingorg.openide.util.UserCancelException
- if the user cancelled the move
-
handleCreateFromTemplate
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 classDataObject
- Parameters:
df
- data folder to create object inname
- name to give to the new object (ornull
if the name should be chosen according to the template)- Returns:
- the new data object
- Throws:
IOException
- if an error occured
-
handleCopyRename
Description copied from class:DataObject
Copy and rename this object to a folder (implemented by subclasses).- Overrides:
handleCopyRename
in classDataObject
- Parameters:
df
- target foldername
- new file nameext
- new file extension- Returns:
- the new data object
- Throws:
IOException
- if an error occures or the file cannot be copied/renamed
-
setCookieSet
Deprecated.just use getCookieSet().add(...) insteadSet 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 onDataObject.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 bysetCookieSet(org.openide.nodes.CookieSet)
, that set is returned. Otherwise an empty set is returned.- Returns:
- the cookie set (never
null
)
-
getCookie
Look for a cookie in the current cookie set matching the requested class.- Overrides:
getCookie
in classDataObject
- 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 forDataObject.getCookie(java.lang.Class<T>)
and should preferably be used instead of the old method. The default implementation inside a data object returns thegetNodeDelegate().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 andDataObject.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 interfaceorg.openide.util.Lookup.Provider
- Overrides:
getLookup
in classDataObject
- Returns:
- lookup representing this data object and its content
-
associateLookup
protected int associateLookup()Influences behavior ofgetLookup()
method. Depending on the returned integer, one can get different, better and more modern content of theLookup
:- version 0 - delegates to
getNodeDelegate().getLookup()
. - version 1 - delegates to
getCookieSet().getLookup()
and makes sureFileObject
,this
andNode
are in the lookup. TheNode
is created lazily by callingDataObject.getNodeDelegate()
.
- Returns:
- version identifying content of the lookup (currently 0 or 1)
- Since:
- 7.27
- version 0 - delegates to
-
registerEditor
Utility method to register editor for thisDataObject
. Call it from constructor with appropriate mimeType. The system will make sure that appropriate cookies (Openable
,Editable
,CloseCookie
,EditorCookie
,SaveAsCapable
,LineCookie
are registered intogetCookieSet()
.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 withuseMultiview
- should the used component be multiview?- Since:
- 7.27
-