Class InstanceDataObject
- All Implemented Interfaces:
Serializable
,org.openide.cookies.InstanceCookie
,org.openide.cookies.InstanceCookie.Of
,org.openide.nodes.Node.Cookie
,org.openide.util.HelpCtx.Provider
,org.openide.util.Lookup.Provider
InstanceCookie
.
The instances are created by default instantiation; the name of the class
to instantiate is stored on disk, typically right in the file name.
This data object is generally used to configure menus and toolbars,
though it could be used in any situation requiring instances to be present in
a folder; for example, anything using FolderInstance
.
Typical instance classes are subclasses of SystemAction
to make
menu items or toolbar buttons; JSeparator
for a menu
separator; or JToolBar.Separator
for a toolbar
separator.
Use create(org.openide.loaders.DataFolder, java.lang.String, java.lang.String)
and remove(org.openide.loaders.DataFolder, java.lang.String, java.lang.String)
to make the objects.
Better yet, use an XML filesystem to install them declaratively.
Instance data object by default recognizes all files with .instance
suffix. Such file can have associated optional file attributes:
instanceCreate
- instantionalized
Object
(e.g. created bymethodvalue
at XML filesystem) instanceOf
String
that is tokenized at ':', ',', ';' and whitespace boundaries. Resulting tokens represent class names that created instance isinstanceof
. Utilizing it may improve performance.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class org.openide.loaders.MultiDataObject
MultiDataObject.Entry
Nested classes/interfaces inherited from class org.openide.loaders.DataObject
DataObject.Container, DataObject.Factory, DataObject.Registration, DataObject.Registrations, DataObject.Registry
Nested classes/interfaces inherited from interface org.openide.cookies.InstanceCookie
org.openide.cookies.InstanceCookie.Of
-
Field Summary
FieldsFields 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
ConstructorsConstructorDescriptionInstanceDataObject
(org.openide.filesystems.FileObject pf, MultiFileLoader loader) Create a new instance. -
Method Summary
Modifier and TypeMethodDescriptionstatic InstanceDataObject
create
(DataFolder folder, String name, Class<?> clazz) Create a newInstanceDataObject
in a given folder.static InstanceDataObject
create
(DataFolder folder, String name, Object instance, org.openide.modules.ModuleInfo info) Create a newInstanceDataObject
containing settings in a given folder.static InstanceDataObject
create
(DataFolder folder, String name, Object instance, org.openide.modules.ModuleInfo info, boolean create) Create a newInstanceDataObject
containing settings in a given folder.static InstanceDataObject
create
(DataFolder folder, String name, String className) Create a newInstanceDataObject
in a given folder.protected org.openide.nodes.Node
Provides node that should represent this data object.protected void
dispose()
Allows subclasses to discard the object.static InstanceDataObject
find
(DataFolder folder, String name, Class<?> clazz) Finds instance of specified name in a given folder.static InstanceDataObject
find
(DataFolder folder, String name, String className) Finds instance of specified name in a given folder.<T extends org.openide.nodes.Node.Cookie>
TLook for a cookie in the current cookie set matching the requested class.org.openide.util.HelpCtx
Get help context for this object.org.openide.util.Lookup
Represents a context of the data object.getName()
Get the name of the data object.protected DataObject
handleCopy
(DataFolder df) Copy a service sanely.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
handleRename
(String name) Rename this object (implemented in subclasses).Class
<?> boolean
instanceOf
(Class<?> type) Query if this instance can create object of given type.static boolean
remove
(DataFolder folder, String name, Class<?> clazz) Remove an existing instance data object.static boolean
remove
(DataFolder folder, String name, String className) Remove an existing instance data object.Methods inherited from class org.openide.loaders.MultiDataObject
addSecondaryEntry, associateLookup, files, findSecondaryEntry, getCookieSet, getMultiFileLoader, getPrimaryEntry, handleCopyRename, handleMove, isCopyAllowed, isDeleteAllowed, isMoveAllowed, isRenameAllowed, registerEditor, registerEntry, removeSecondaryEntry, secondaryEntries, setCookieSet, takePrimaryFileLock
Methods inherited from class org.openide.loaders.DataObject
addPropertyChangeListener, addVetoableChangeListener, copy, createFromTemplate, createFromTemplate, createFromTemplate, createShadow, delete, find, firePropertyChange, fireVetoableChange, getCookie, getFolder, getLoader, getNodeDelegate, getPrimaryFile, getRegistry, handleCreateShadow, isModified, isShadowAllowed, isTemplate, isValid, markFiles, move, removePropertyChangeListener, removeVetoableChangeListener, rename, setModified, setTemplate, setValid, toString, writeReplace
-
Field Details
-
INSTANCE
-
-
Constructor Details
-
InstanceDataObject
public InstanceDataObject(org.openide.filesystems.FileObject pf, MultiFileLoader loader) throws DataObjectExistsException Create a new instance. Do not use this to make instances; usecreate(org.openide.loaders.DataFolder, java.lang.String, java.lang.String)
.- Parameters:
pf
- primary file object for this data objectloader
- the loader- Throws:
DataObjectExistsException
- if it already exists
-
-
Method Details
-
find
Finds instance of specified name in a given folder.- Parameters:
folder
- the folder to create the instance data object inname
- the name to give to the object (can benull
if no special name besides the class name is needed)className
- the name of the class the new object should provide an instance of- Returns:
- the found instance data object or null if it does not exist
-
find
Finds instance of specified name in a given folder.- Parameters:
folder
- the folder to create the instance data object inname
- the name to give to the object (can benull
if no special name besides the class name is needed)clazz
- the class to create instance for (see class header for details)- Returns:
- the found instance data object or null if it does not exist
-
create
public static InstanceDataObject create(DataFolder folder, String name, String className) throws IOException Create a newInstanceDataObject
in a given folder. If object with specified name already exists, it is returned. You should specify the name if there is a chance another file of the same instance class already exists in the folder; or just to provide a more descriptive name, which will appear in the Explorer for example.Note: use of XML layers to install instances is generally preferred.
- Parameters:
folder
- the folder to create the instance data object inname
- the name to give to the object (can benull
if no special name besides the class name is needed) but name cannot be emptyclassName
- the name of the class the new object should provide an instance of (see class header for details)- Returns:
- the newly created or existing instance data object
- Throws:
IOException
- if the file cannot be created
-
create
public static InstanceDataObject create(DataFolder folder, String name, Class<?> clazz) throws IOException Create a newInstanceDataObject
in a given folder. If object with specified name already exists, it is returned. You should specify the name if there is a chance another file of the same instance class already exists in the folder; or just to provide a more descriptive name, which will appear in the Explorer for example.Note: use of XML layers to install instances is generally preferred.
- Parameters:
folder
- the folder to create the instance data object inname
- the name to give to the object (can benull
if no special name besides the class name is needed)clazz
- the class to create instance for (see class header for details)- Returns:
- the newly created or existing instance data object
- Throws:
IOException
- if the file cannot be created
-
create
public static InstanceDataObject create(DataFolder folder, String name, Object instance, org.openide.modules.ModuleInfo info) throws IOException Create a newInstanceDataObject
containing settings in a given folder. If object with specified name already exists, it is returned. If the module info isnull
then the origin module info of an instance class is tried to find out.Note: use of XML layers to install instances is generally preferred.
- Parameters:
folder
- the folder to create the instance data object inname
- the name to give to the object (can benull
if no special name besides the class name is needed) but name cannot be emptyinstance
- the serializable instanceinfo
- the module info describing the settings provenance (can benull
)- Returns:
- the newly created or existing instance data object
- Throws:
IOException
- if the file cannot be created- Since:
- 1.28
-
create
public static InstanceDataObject create(DataFolder folder, String name, Object instance, org.openide.modules.ModuleInfo info, boolean create) throws IOException Create a newInstanceDataObject
containing settings in a given folder. If the module info isnull
then the origin module info of an instance class is tried to find out.Note: use of XML layers to install instances is generally preferred.
- Parameters:
folder
- the folder to create the instance data object inname
- the name to give to the object (can benull
if no special name besides the class name is needed) but name cannot be emptyinstance
- the serializable instanceinfo
- the module info describing the settings provenance (can benull
)create
-true
- always create new file;false
- store to existing file if exist- Returns:
- the newly created or existing instance data object
- Throws:
IOException
- if the file cannot be created- Since:
- 2.9
-
remove
Remove an existing instance data object. If you have the exact file name, just callDataObject.delete()
; this method lets you delete an instance you do not have an exact record of the file name for, based on the same information used to create it.Note: use of XML layers to install instances is generally preferred.
- Parameters:
folder
- the folder to remove the file fromname
- the name of the instance (can benull
)className
- the name of class the object referred to (see class header for details)- Returns:
true
if the instance was succesfully removed,false
if not
-
remove
Remove an existing instance data object. If you have the exact file name, just callDataObject.delete()
; this method lets you delete an instance you do not have an exact record of the file name for, based on the same information used to create it.Note: use of XML layers to install instances is generally preferred.
- Parameters:
folder
- the folder to remove the file fromname
- the name of the instance (can benull
)clazz
- the class the object referred to (see class header for details)- Returns:
true
if the instance was succesfully removed,false
if not
-
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
- Overrides:
getHelpCtx
in classMultiDataObject
- Returns:
- the help context
-
createNodeDelegate
protected org.openide.nodes.Node createNodeDelegate()Description copied from class:MultiDataObject
Provides node that should represent this data object.- Overrides:
createNodeDelegate
in classMultiDataObject
- Returns:
- the node representation
- See Also:
-
getCookie
Description copied from class:MultiDataObject
Look for a cookie in the current cookie set matching the requested class.- Overrides:
getCookie
in classMultiDataObject
- Parameters:
clazz
- 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 classMultiDataObject
- Returns:
- lookup representing this data object and its content
-
instanceName
- Specified by:
instanceName
in interfaceorg.openide.cookies.InstanceCookie
-
instanceClass
- Specified by:
instanceClass
in interfaceorg.openide.cookies.InstanceCookie
- Throws:
IOException
ClassNotFoundException
-
instanceOf
Query if this instance can create object of given type.- Specified by:
instanceOf
in interfaceorg.openide.cookies.InstanceCookie.Of
- Parameters:
type
- the type to create- Returns:
- true or false
-
instanceCreate
- Specified by:
instanceCreate
in interfaceorg.openide.cookies.InstanceCookie
- Throws:
IOException
ClassNotFoundException
-
getName
Description copied from class:DataObject
Get the name of the data object.The default implementation uses the name of the primary file.
- Overrides:
getName
in classDataObject
- Returns:
- the name
-
handleRename
Description copied from class:DataObject
Rename this object (implemented in subclasses).- Overrides:
handleRename
in classMultiDataObject
- Parameters:
name
- name to rename the object to- Returns:
- new primary file of the object
- Throws:
IOException
- if an error occures
-
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.- Overrides:
handleCreateFromTemplate
in classMultiDataObject
- 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
-
handleCopy
Copy a service sanely. For settings and serializable beans, special methods are used to write out the resulting files, and the name to use is taken from the *display name* of the current file, as this is what the user is accustomed to seeing (for ServiceType's especially).- Overrides:
handleCopy
in classMultiDataObject
- Parameters:
df
- the new folder- Returns:
- data object for the new primary
- Throws:
IOException
- if there was a problem copying- See Also:
-
dispose
protected void dispose()Description copied from class:DataObject
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.
- Overrides:
dispose
in classDataObject
-
handleDelete
Description copied from class:DataObject
Delete this object (implemented by subclasses).- Overrides:
handleDelete
in classMultiDataObject
- Throws:
IOException
- if an error occures
-