public class MultiDataObject extends DataObject
MultiDataObject.Entry
. Each handler
has one primary
entry and zero or more secondary entries.Modifier and Type | Class and Description |
---|---|
class |
MultiDataObject.Entry
Represents one file in a
group data object . |
DataObject.Container, DataObject.Factory, DataObject.Registration, DataObject.Registrations, DataObject.Registry
PROP_COOKIE, PROP_FILES, PROP_HELP, PROP_MODIFIED, PROP_NAME, PROP_PRIMARY_FILE, PROP_TEMPLATE, PROP_VALID
Constructor and Description |
---|
MultiDataObject(FileObject fo,
MultiFileLoader loader)
Create a MultiFileObject.
|
Modifier and Type | Method and Description |
---|---|
protected void |
addSecondaryEntry(MultiDataObject.Entry fe)
Add a new secondary entry to the list.
|
protected int |
associateLookup()
Influences behavior of
MultiDataObject.getLookup() method. |
protected Node |
createNodeDelegate()
Provides node that should represent this data object.
|
Set<FileObject> |
files()
Get all contained files.
|
MultiDataObject.Entry |
findSecondaryEntry(FileObject fo)
For a given file, find the associated secondary entry.
|
<T extends Node.Cookie> |
getCookie(Class<T> type)
Look for a cookie in the current cookie set matching the requested class.
|
protected CookieSet |
getCookieSet()
Get the set of cookies.
|
HelpCtx |
getHelpCtx()
Get help context for this object.
|
Lookup |
getLookup()
Represents a context of the data object.
|
MultiFileLoader |
getMultiFileLoader()
Getter for the multi file loader that created this
object.
|
MultiDataObject.Entry |
getPrimaryEntry()
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 |
handleDelete()
Delete this object (implemented by subclasses).
|
protected FileObject |
handleMove(DataFolder df)
Moves primary and secondary files to a new folder.
|
protected FileObject |
handleRename(String name)
Rename this object (implemented in subclasses).
|
boolean |
isCopyAllowed()
Test whether the object may be copied.
|
boolean |
isDeleteAllowed()
Test whether the object may be deleted.
|
boolean |
isMoveAllowed()
Test whether the object may be moved.
|
boolean |
isRenameAllowed()
Test whether the object may be renamed.
|
protected void |
registerEditor(String mimeType,
boolean useMultiview)
Utility method to register editor for this
DataObject . |
protected MultiDataObject.Entry |
registerEntry(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 void |
removeSecondaryEntry(MultiDataObject.Entry fe)
Remove a secondary entry from the list.
|
Set<MultiDataObject.Entry> |
secondaryEntries()
Get secondary entries.
|
protected void |
setCookieSet(CookieSet s)
Deprecated.
just use getCookieSet().add(...) instead
|
protected FileLock |
takePrimaryFileLock()
Obtains lock for primary file.
|
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
public MultiDataObject(FileObject fo, MultiFileLoader loader) throws DataObjectExistsException
fo
- the primary file objectloader
- loader of this data objectDataObjectExistsException
DataObject.DataObject(org.openide.filesystems.FileObject,org.openide.loaders.DataLoader)
public final MultiFileLoader getMultiFileLoader()
public Set<FileObject> files()
DataObject
The default implementation returns a set consisting only of the primary file.
files
in class DataObject
public boolean isDeleteAllowed()
DataObject
isDeleteAllowed
in class DataObject
true
if it maypublic boolean isCopyAllowed()
DataObject
isCopyAllowed
in class DataObject
true
if it maypublic boolean isMoveAllowed()
DataObject
isMoveAllowed
in class DataObject
true
if it maypublic boolean isRenameAllowed()
DataObject
isRenameAllowed
in class DataObject
true
if it maypublic HelpCtx getHelpCtx()
DataObject
getHelpCtx
in interface HelpCtx.Provider
getHelpCtx
in class DataObject
protected Node createNodeDelegate()
createNodeDelegate
in class DataObject
DataNode
protected final void addSecondaryEntry(MultiDataObject.Entry fe)
fe
- the entry to addprotected final void removeSecondaryEntry(MultiDataObject.Entry fe)
fe
- the entry to removeprotected final MultiDataObject.Entry registerEntry(FileObject fo)
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
fo
- the file to register (can be null, then the action is ignored)public final MultiDataObject.Entry getPrimaryEntry()
public final Set<MultiDataObject.Entry> secondaryEntries()
public final MultiDataObject.Entry findSecondaryEntry(FileObject fo)
fo
- file objectnull
if there is no
such entryprotected FileLock takePrimaryFileLock() throws IOException
DataObject
takePrimaryFileLock
in class DataObject
IOException
- if taking the lock failsprotected DataObject handleCopy(DataFolder df) throws IOException
handleCopy
in class DataObject
df
- the new folderIOException
- if there was a problem copyingUserCancelException
- if the user cancelled the copyprotected void handleDelete() throws IOException
DataObject
handleDelete
in class DataObject
IOException
- if an error occuresprotected FileObject handleRename(String name) throws IOException
DataObject
handleRename
in class DataObject
name
- name to rename the object toIOException
- if an error occuresprotected FileObject handleMove(DataFolder df) throws IOException
handleMove
in class DataObject
df
- the new folderIOException
- if there was a problem movingUserCancelException
- if the user cancelled the moveprotected DataObject handleCreateFromTemplate(DataFolder df, String name) throws IOException
DataObject
handleCreateFromTemplate
in class DataObject
df
- data folder to create object inname
- name to give to the new object (or null
if the name should be chosen according to the template)IOException
- if an error occuredprotected DataObject handleCopyRename(DataFolder df, String name, String ext) throws IOException
DataObject
handleCopyRename
in class DataObject
df
- target foldername
- new file nameext
- new file extensionIOException
- if an error occures or the file cannot be copied/renamed@Deprecated protected final void setCookieSet(CookieSet s)
DataObject.PROP_COOKIE
.s
- the cookie set to useprotected final CookieSet getCookieSet()
MultiDataObject.setCookieSet(org.openide.nodes.CookieSet)
, that set
is returned. Otherwise an empty set is
returned.null
)public <T extends Node.Cookie> T getCookie(Class<T> type)
getCookie
in class DataObject
type
- the class to look fornull
if this class of cookie
is not supportedpublic Lookup getLookup()
DataObject
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.
getLookup
in interface Lookup.Provider
getLookup
in class DataObject
protected int associateLookup()
MultiDataObject.getLookup()
method. Depending on the
returned integer, one can get different, better and more modern content
of the Lookup
:
getNodeDelegate().getLookup()
.getCookieSet().getLookup()
and makes sure FileObject
, this
and
Node
are in the lookup. The Node
is created lazily
by calling DataObject.getNodeDelegate()
.
protected final void registerEditor(String mimeType, boolean useMultiview)
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 MultiDataObject.getCookieSet()
.
The selected editor is
MultiView component, if requested (this requires presence of
the MultiView API
in the system. Otherwise it is plain CloneableEditor
.
mimeType
- mime type to associate withuseMultiview
- should the used component be multiview?