org.openide.cookies.InstanceCookie, org.openide.cookies.InstanceCookie.Of, org.openide.nodes.Node.Cookiepublic class InstanceDataObject extends MultiDataObject implements org.openide.cookies.InstanceCookie.Of
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:
Object (e.g. created by
methodvalue at XML filesystem)
String that is tokenized at ':', ',', ';' and
whitespace boundaries. Resulting tokens represent class names that created
instance is instanceof. Utilizing it may improve performance.
DataObject.Container, DataObject.Factory, DataObject.Registration, DataObject.Registrations, DataObject.Registryorg.openide.cookies.InstanceCookie.OfMultiDataObject.Entry| Modifier and Type | Field | Description |
|---|---|---|
static java.lang.String |
INSTANCE |
File extension for instance data objects.
|
PROP_COOKIE, PROP_FILES, PROP_HELP, PROP_MODIFIED, PROP_NAME, PROP_PRIMARY_FILE, PROP_TEMPLATE, PROP_VALID| Constructor | Description |
|---|---|
InstanceDataObject(org.openide.filesystems.FileObject pf,
MultiFileLoader loader) |
Create a new instance.
|
| Modifier and Type | Method | Description |
|---|---|---|
static InstanceDataObject |
create(DataFolder folder,
java.lang.String name,
java.lang.Class<?> clazz) |
Create a new
InstanceDataObject in a given folder. |
static InstanceDataObject |
create(DataFolder folder,
java.lang.String name,
java.lang.Object instance,
org.openide.modules.ModuleInfo info) |
Create a new
InstanceDataObject containing settings
in a given folder. |
static InstanceDataObject |
create(DataFolder folder,
java.lang.String name,
java.lang.Object instance,
org.openide.modules.ModuleInfo info,
boolean create) |
Create a new
InstanceDataObject containing settings
in a given folder. |
static InstanceDataObject |
create(DataFolder folder,
java.lang.String name,
java.lang.String className) |
Create a new
InstanceDataObject in a given folder. |
protected org.openide.nodes.Node |
createNodeDelegate() |
Provides node that should represent this data object.
|
protected void |
dispose() |
Allows subclasses to discard the object.
|
static InstanceDataObject |
find(DataFolder folder,
java.lang.String name,
java.lang.Class<?> clazz) |
Finds instance of specified name in a given folder.
|
static InstanceDataObject |
find(DataFolder folder,
java.lang.String name,
java.lang.String className) |
Finds instance of specified name in a given folder.
|
<T extends org.openide.nodes.Node.Cookie> |
getCookie(java.lang.Class<T> clazz) |
Look for a cookie in the current cookie set matching the requested class.
|
org.openide.util.HelpCtx |
getHelpCtx() |
Get help context for this object.
|
org.openide.util.Lookup |
getLookup() |
Represents a context of the data object.
|
java.lang.String |
getName() |
Get the name of the data object.
|
protected DataObject |
handleCopy(DataFolder df) |
Copies primary and secondary files to new folder.
|
protected DataObject |
handleCreateFromTemplate(DataFolder df,
java.lang.String name) |
Create a new data object from template (implemented in subclasses).
|
protected void |
handleDelete() |
Delete this object (implemented by subclasses).
|
protected org.openide.filesystems.FileObject |
handleRename(java.lang.String name) |
Rename this object (implemented in subclasses).
|
java.lang.Class<?> |
instanceClass() |
|
java.lang.Object |
instanceCreate() |
|
java.lang.String |
instanceName() |
|
boolean |
instanceOf(java.lang.Class<?> type) |
Query if this instance can create object of given type.
|
static boolean |
remove(DataFolder folder,
java.lang.String name,
java.lang.Class<?> clazz) |
Remove an existing instance data object.
|
static boolean |
remove(DataFolder folder,
java.lang.String name,
java.lang.String className) |
Remove an existing instance data object.
|
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, writeReplaceaddSecondaryEntry, associateLookup, files, findSecondaryEntry, getCookieSet, getMultiFileLoader, getPrimaryEntry, handleCopyRename, handleMove, isCopyAllowed, isDeleteAllowed, isMoveAllowed, isRenameAllowed, registerEditor, registerEntry, removeSecondaryEntry, secondaryEntries, setCookieSet, takePrimaryFileLockpublic static final java.lang.String INSTANCE
public InstanceDataObject(org.openide.filesystems.FileObject pf,
MultiFileLoader loader)
throws DataObjectExistsException
create(org.openide.loaders.DataFolder, java.lang.String, java.lang.String).pf - primary file object for this data objectloader - the loaderDataObjectExistsException - if it already existspublic static InstanceDataObject find(DataFolder folder, java.lang.String name, java.lang.String className)
folder - the folder to create the instance data object inname - the name to give to the object (can be null if no special name besides the class name is needed)className - the name of the class the new object should provide an instance ofpublic static InstanceDataObject find(DataFolder folder, java.lang.String name, java.lang.Class<?> clazz)
folder - the folder to create the instance data object inname - the name to give to the object (can be null if no special name besides the class name is needed)clazz - the class to create instance for (see class header for details)public static InstanceDataObject create(DataFolder folder, java.lang.String name, java.lang.String className) throws java.io.IOException
InstanceDataObject 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.
folder - the folder to create the instance data object inname - the name to give to the object (can be null 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)java.io.IOException - if the file cannot be createdpublic static InstanceDataObject create(DataFolder folder, java.lang.String name, java.lang.Class<?> clazz) throws java.io.IOException
InstanceDataObject 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.
folder - the folder to create the instance data object inname - the name to give to the object (can be null if no special name besides the class name is needed)clazz - the class to create instance for (see class header for details)java.io.IOException - if the file cannot be createdpublic static InstanceDataObject create(DataFolder folder, java.lang.String name, java.lang.Object instance, org.openide.modules.ModuleInfo info) throws java.io.IOException
InstanceDataObject containing settings
in a given folder. If object with specified name already exists, it is returned.
If the module info is null 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.
folder - the folder to create the instance data object inname - the name to give to the object (can be null 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 be null)java.io.IOException - if the file cannot be createdpublic static InstanceDataObject create(DataFolder folder, java.lang.String name, java.lang.Object instance, org.openide.modules.ModuleInfo info, boolean create) throws java.io.IOException
InstanceDataObject containing settings
in a given folder.
If the module info is null 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.
folder - the folder to create the instance data object inname - the name to give to the object (can be null 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 be null)create - true - always create new file; false
- store to existing file if existjava.io.IOException - if the file cannot be createdpublic static boolean remove(DataFolder folder, java.lang.String name, java.lang.String className)
DataObject.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.
folder - the folder to remove the file fromname - the name of the instance (can be null)className - the name of class the object referred to (see class header for details)true if the instance was succesfully removed, false if notpublic static boolean remove(DataFolder folder, java.lang.String name, java.lang.Class<?> clazz)
DataObject.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.
folder - the folder to remove the file fromname - the name of the instance (can be null)clazz - the class the object referred to (see class header for details)true if the instance was succesfully removed, false if notpublic org.openide.util.HelpCtx getHelpCtx()
DataObjectgetHelpCtx in class MultiDataObjectprotected org.openide.nodes.Node createNodeDelegate()
MultiDataObjectcreateNodeDelegate in class MultiDataObjectDataNodepublic <T extends org.openide.nodes.Node.Cookie> T getCookie(java.lang.Class<T> clazz)
MultiDataObjectgetCookie in class MultiDataObjectclazz - the class to look fornull if this class of cookie
is not supportedpublic org.openide.util.Lookup getLookup()
DataObjectDataObject.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 class MultiDataObjectpublic java.lang.String instanceName()
instanceName in interface org.openide.cookies.InstanceCookiepublic java.lang.Class<?> instanceClass()
throws java.io.IOException,
java.lang.ClassNotFoundException
instanceClass in interface org.openide.cookies.InstanceCookiejava.io.IOExceptionjava.lang.ClassNotFoundExceptionpublic boolean instanceOf(java.lang.Class<?> type)
instanceOf in interface org.openide.cookies.InstanceCookie.Oftype - the type to createpublic java.lang.Object instanceCreate()
throws java.io.IOException,
java.lang.ClassNotFoundException
instanceCreate in interface org.openide.cookies.InstanceCookiejava.io.IOExceptionjava.lang.ClassNotFoundExceptionpublic java.lang.String getName()
DataObjectThe default implementation uses the name of the primary file.
getName in class DataObjectprotected org.openide.filesystems.FileObject handleRename(java.lang.String name)
throws java.io.IOException
DataObjecthandleRename in class MultiDataObjectname - name to rename the object tojava.io.IOException - if an error occuresprotected DataObject handleCreateFromTemplate(DataFolder df, java.lang.String name) throws java.io.IOException
DataObjecthandleCreateFromTemplate in class MultiDataObjectdf - 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)java.io.IOException - if an error occuredprotected DataObject handleCopy(DataFolder df) throws java.io.IOException
MultiDataObjecthandleCopy in class MultiDataObjectdf - the new folderjava.io.IOException - if there was a problem copyingorg.openide.util.UserCancelException - if the user cancelled the copyprotected void dispose()
DataObjectThe 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.
dispose in class DataObjectprotected void handleDelete()
throws java.io.IOException
DataObjecthandleDelete in class MultiDataObjectjava.io.IOException - if an error occuresBuilt on April 24 2018. | Portions Copyright 1997-2018 Oracle. All rights reserved.