Class DataObject
- All Implemented Interfaces:
Serializable, org.openide.nodes.Node.Cookie, org.openide.util.HelpCtx.Provider, org.openide.util.Lookup.Provider
- Direct Known Subclasses:
MultiDataObject
getLookup() lookup pattern. Since version 6.0
this class implements Lookup.Provider.- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceInterface for objects that can contain other data objects.static interfaceFactory interface for converting file object to data objects.static @interfaceRegisters new file type into the system.static @interfaceMay be used to allow multipleDataObject.Registrationat one place.static final classRegistry of modified data objects. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringName of the property used during notification of changes in the set of cookies attached to this object.static final StringName of files property.static final StringName of the help context property.static final StringName of the modified property.static final StringName of the name property.static final StringName of primary file property.static final StringName of the template property.static final StringName of valid property. -
Constructor Summary
ConstructorsConstructorDescriptionDataObject(org.openide.filesystems.FileObject pf, DataLoader loader) Create a new data object. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdd a property change listener.voidAdd a listener to vetoable changes.final DataObjectcopy(DataFolder f) Copy this object to a folder.final DataObjectCreate a new object from template (with a name depending on the template).final DataObjectcreateFromTemplate(DataFolder f, String name) Create a new object from template.final DataObjectcreateFromTemplate(DataFolder f, String name, Map<String, ? extends Object> parameters) More generic way how to instantiate aDataObject.protected org.openide.nodes.NodeProvides node that should represent this data object.final DataShadowCreates shadow for this object in specified folder.final voiddelete()Delete this object.protected voiddispose()Allows subclasses to discard the object.Set<org.openide.filesystems.FileObject> files()Get all contained files.static DataObjectfind(org.openide.filesystems.FileObject fo) Finds the data object for a specified file object.protected final voidfirePropertyChange(String name, Object oldValue, Object newValue) Fires property change notification to all listeners registered viaaddPropertyChangeListener(PropertyChangeListener).protected final voidfireVetoableChange(String name, Object oldValue, Object newValue) Fires vetoable change notification.<T extends org.openide.nodes.Node.Cookie>
TObtain a cookie from the data object.protected <T extends org.openide.nodes.Node.Cookie>
TgetCookie(DataShadow shadow, Class<T> clazz) When a request for a cookie is done on a DataShadow of this DataObject this methods gets called (by default) so the DataObject knows which DataShadow is asking and extract some information from the shadow itself.final DataFolderGet the folder this data object is stored in.abstract org.openide.util.HelpCtxGet help context for this object.final DataLoaderGet the loader that created this data object.org.openide.util.LookupRepresents a context of the data object.getName()Get the name of the data object.final org.openide.nodes.NodeGet the node delegate.final org.openide.filesystems.FileObjectGet the primary file for this data object.static DataObject.RegistryGet the registry containing all modified objects.protected abstract DataObjectCopy this object to a folder (implemented by subclasses).protected DataObjecthandleCopyRename(DataFolder f, String name, String ext) Copy and rename this object to a folder (implemented by subclasses).protected abstract DataObjecthandleCreateFromTemplate(DataFolder df, String name) Create a new data object from template (implemented in subclasses).protected DataShadowCreates shadow for this object in specified folder (overridable in subclasses).protected abstract voidDelete this object (implemented by subclasses).protected abstract org.openide.filesystems.FileObjecthandleMove(DataFolder df) Move this object to another folder (implemented in subclasses).protected abstract org.openide.filesystems.FileObjecthandleRename(String name) Rename this object (implemented in subclasses).abstract booleanTest whether the object may be copied.abstract booleanTest whether the object may be deleted.booleanTest whether the object is modified.abstract booleanTest whether the object may be moved.abstract booleanTest whether the object may be renamed.booleanTest whether the object may create shadows.final booleanGet the template status of this data object.final booleanisValid()Test whether the data object is still valid and usable.protected final voidMark all contained files as belonging to this loader.final voidmove(DataFolder df) Move this object to another folder.voidRemove a property change listener.voidAdd a listener to vetoable changes.final voidRename this object.voidsetModified(boolean modif) Set whether the object is considered modified.final voidsetTemplate(boolean newTempl) Set the template status of this data object.voidsetValid(boolean valid) Setter that allows to destroy this data object.protected org.openide.filesystems.FileLockObtains lock for primary file.toString()The Serialization replacement for this object stores the primary file instead.
-
Field Details
-
PROP_TEMPLATE
-
PROP_NAME
-
PROP_HELP
-
PROP_MODIFIED
-
PROP_COOKIE
Name of the property used during notification of changes in the set of cookies attached to this object.- See Also:
-
PROP_VALID
Name of valid property. Allows listening to deletion or disposal of the data object.- See Also:
-
PROP_PRIMARY_FILE
Name of primary file property. Primary file is changed when the object is moved- See Also:
-
PROP_FILES
Name of files property. Allows listening to set of files handled by this object.- See Also:
-
-
Constructor Details
-
DataObject
public DataObject(org.openide.filesystems.FileObject pf, DataLoader loader) throws DataObjectExistsException Create a new data object.- Parameters:
pf- primary file object for this data objectloader- loader that created the data object- Throws:
DataObjectExistsException- if there is already a data object for this primary file
-
-
Method Details
-
dispose
protected void dispose()Allows subclasses to discard the object. When an object is discarded, it is released from the list of objects registered in the system. Then the contents of the parent folder (if it still exists) are rescanned, which may result in the creation of a new data object for the primary file.The normal use of this method is to change the type of a data object. Because this would usually only be invoked from the original data object, it is protected.
-
setValid
Setter that allows to destroy this data object. Because such operation can be dangerous and not always possible (if the data object is opened in editor) it can be vetoed. Either by this data object or by any vetoable listener attached to this object (like editor support)- Parameters:
valid- should be false- Throws:
PropertyVetoException- if the invalidation has been vetoed
-
isValid
public final boolean isValid()Test whether the data object is still valid and usable.The object can become invalid when it is deleted, its files are deleted, or
dispose()is called.When the validity of the object changes a property change event is fired, so anyone can listen and be notified when the object is deleted/disposed.
-
getLoader
Get the loader that created this data object.- Returns:
- the data loader
-
markFiles
Mark all contained files as belonging to this loader. If the files are rescanned (e.g. after a disposal), the current data loader will be given preference.- Throws:
IOException
-
files
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.
- Returns:
- set of files
-
getNodeDelegate
public final org.openide.nodes.Node getNodeDelegate()Get the node delegate. Eithercreates it(if it does not already exist) or returns a previously created instance of it.- Returns:
- the node delegate (without parent) for this data object
- See Also:
-
createNodeDelegate
protected org.openide.nodes.Node createNodeDelegate()Provides node that should represent this data object.The default implementation creates an instance of
DataNode. Most subclasses will override this method to provide aDataNode(usually subclassed).This method is called only once per data object.
It is strongly recommended that the resulting node will, when asked for the cookie
DataObject.class, return this same data object.It is also recommended that the node:
- Base its name on
getName(). - Base its display name additionally on
DataNode.getShowFileExtensions().
- Returns:
- the node delegate (without parent) for this data object
- See Also:
- Base its name on
-
takePrimaryFileLock
Obtains lock for primary file.- Returns:
- the lock
- Throws:
IOException- if taking the lock fails
-
setTemplate
Set the template status of this data object.- Parameters:
newTempl-trueif the object should be a template- Throws:
IOException- if setting the template state fails
-
isTemplate
public final boolean isTemplate()Get the template status of this data object.- Returns:
trueif it is a template
-
isDeleteAllowed
public abstract boolean isDeleteAllowed()Test whether the object may be deleted.- Returns:
trueif it may
-
isCopyAllowed
public abstract boolean isCopyAllowed()Test whether the object may be copied.- Returns:
trueif it may
-
isMoveAllowed
public abstract boolean isMoveAllowed()Test whether the object may be moved.- Returns:
trueif it may
-
isShadowAllowed
public boolean isShadowAllowed()Test whether the object may create shadows.The default implementation returns
true.- Returns:
trueif it may
-
isRenameAllowed
public abstract boolean isRenameAllowed()Test whether the object may be renamed.- Returns:
trueif it may
-
isModified
public boolean isModified()Test whether the object is modified.- Returns:
trueif it is modified
-
setModified
public void setModified(boolean modif) Set whether the object is considered modified. Also fires a change event. If the new value istrue, the data object is added into aregistryof opened data objects. If the new value isfalse, the data object is removed from the registry. -
getHelpCtx
public abstract org.openide.util.HelpCtx getHelpCtx()Get help context for this object.- Specified by:
getHelpCtxin interfaceorg.openide.util.HelpCtx.Provider- Returns:
- the help context
-
getPrimaryFile
public final org.openide.filesystems.FileObject getPrimaryFile()Get the primary file for this data object. For example, Java source uses*.javaand*.classfiles but the primary one is always*.java. Please note that two data objects areequivalentif they use the same primary file.Warning: do not call
Node.getHandle()orDefaultHandle.createHandle(Node)in this method.- Returns:
- the primary file
-
find
public static DataObject find(org.openide.filesystems.FileObject fo) throws DataObjectNotFoundException Finds the data object for a specified file object.- Parameters:
fo- file object- Returns:
- the data object for that file
- Throws:
DataObjectNotFoundException- if the file does not have a data object
-
getRegistry
Get the registry containing all modified objects.- Returns:
- the registry
-
getName
Get the name of the data object.The default implementation uses the name of the primary file.
- Returns:
- the name
-
toString
-
getFolder
Get the folder this data object is stored in.- Returns:
- the folder;
nullif the primary file is therootof its filesystem
-
copy
Copy this object to a folder. The copy of the object is required to be deletable and movable.An event is fired, and atomicity is implemented.
- Parameters:
f- the folder to copy the object to- Returns:
- the new object
- Throws:
IOException- if something went wrong
-
handleCopy
Copy this object to a folder (implemented by subclasses).- Parameters:
f- target folder- Returns:
- the new data object
- Throws:
IOException- if an error occures
-
handleCopyRename
Copy and rename this object to a folder (implemented by subclasses).- Parameters:
f- 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- Since:
- 6.3
-
delete
Delete this object.Events are fired and atomicity is implemented.
- Throws:
IOException- if an error occures
-
handleDelete
Delete this object (implemented by subclasses).- Throws:
IOException- if an error occures
-
rename
Rename this object.Events are fired and atomicity is implemented.
- Parameters:
name- the new name- Throws:
IOException- if an error occurs
-
handleRename
Rename this object (implemented in subclasses).- Parameters:
name- name to rename the object to- Returns:
- new primary file of the object
- Throws:
IOException- if an error occures
-
move
Move this object to another folder.An event is fired and atomicity is implemented.
- Parameters:
df- folder to move object to- Throws:
IOException- if an error occurs
-
handleMove
Move this object to another folder (implemented in subclasses).- Parameters:
df- target data folder- Returns:
- new primary file of the object
- Throws:
IOException- if an error occures
-
handleCreateShadow
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.
- Parameters:
f- the folder to create a shortcut in- Returns:
- the shadow
- Throws:
IOException
-
createShadow
Creates shadow for this object in specified folder.An event is fired and atomicity is implemented.
- Parameters:
f- the folder to create shortcut in- Returns:
- the shadow
- Throws:
IOException
-
createFromTemplate
Create a new object from template (with a name depending on the template).- Parameters:
f- folder to create object in- Returns:
- new data object based on this one
- Throws:
IOException- if an error occured- See Also:
-
createFromTemplate
Create a new object from template. AskshandleCreateFromTemplate(DataFolder, String).- Parameters:
f- folder to create object inname- name of object that should be created, ornullif the name should be same as that of the template (or otherwise mechanically generated)- Returns:
- the new data object
- Throws:
IOException- if an error occured
-
createFromTemplate
public final DataObject createFromTemplate(DataFolder f, String name, Map<String, ? extends Object> parameters) throws IOException More generic way how to instantiate aDataObject. One can not only specify its name, but also pass a map of parameters that can influence the copying of the stream.- Parameters:
f- folder to create object inname- name of object that should be created, ornullif the name should be same as that of the template (or otherwise mechanically generated)parameters- map of named objects that are going to be used when creating the new object- Returns:
- the new data object
- Throws:
IOException- if an error occured- Since:
- 6.1
-
handleCreateFromTemplate
protected abstract DataObject handleCreateFromTemplate(DataFolder df, String name) throws IOException 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.- Parameters:
df- data folder to create object inname- name to give to the new object (ornullif the name should be chosen according to the template)- Returns:
- the new data object
- Throws:
IOException- if an error occured
-
addPropertyChangeListener
Add a property change listener.- Parameters:
l- the listener to add
-
removePropertyChangeListener
Remove a property change listener.- Parameters:
l- the listener to remove
-
firePropertyChange
Fires property change notification to all listeners registered viaaddPropertyChangeListener(PropertyChangeListener).- Parameters:
name- of propertyoldValue- old valuenewValue- new value
-
addVetoableChangeListener
Add a listener to vetoable changes.- Parameters:
l- the listener to add- See Also:
-
removeVetoableChangeListener
Add a listener to vetoable changes.- Parameters:
l- the listener to remove- See Also:
-
fireVetoableChange
protected final void fireVetoableChange(String name, Object oldValue, Object newValue) throws PropertyVetoException Fires vetoable change notification.- Parameters:
name- of propertyoldValue- old valuenewValue- new value- Throws:
PropertyVetoException- if the change has been vetoed
-
getCookie
Obtain a cookie from the data object. May be overridden by subclasses to extend the behaviour of data objects.The default implementation tests if this object is of the requested class and if so, returns it.
Warning: the
getCookie(Class)method andgetLookup()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.- Parameters:
c- class of requested cookie- Returns:
- a cookie or
nullif such cookies are not supported
-
getLookup
public org.openide.util.Lookup getLookup()Represents a context of the data object. This method is a more general replacement forgetCookie(Class)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
getCookie(Class)method andgetLookup()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:
getLookupin interfaceorg.openide.util.Lookup.Provider- Returns:
- lookup representing this data object and its content
- Since:
- 6.0
-
getCookie
When a request for a cookie is done on a DataShadow of this DataObject this methods gets called (by default) so the DataObject knows which DataShadow is asking and extract some information from the shadow itself.Subclasses can override this method with better logic, but the default implementation just delegates to
getCookie (Class).- Parameters:
shadow- the shadow for which is askingclazz- class to search for- Returns:
- the cookie or
null - Since:
- 1.16
-
writeReplace
The Serialization replacement for this object stores the primary file instead.- Returns:
- a replacement
-