public class IlvDocumentTemplate extends Object implements ActionHandler, IlvPropertyManager
SETTINGS_TYPE
and initializes
a new document template for each selected settings element. It is
possible to extend the IlvDocumentTemplate
or
IlvFileDocumentTemplate
classes and to add corresponding instances
to the application using its IlvApplication.addDocumentTemplate(ilog.views.appframe.docview.IlvDocumentTemplate)
method.
The entry point for creating documents is the application with
methods like IlvApplication.newDocument()
or IlvApplication.openDocument()
. But, the
application involves its document templates in all the steps of the
creation of documents.
Creation of documents
First, the document template is asked to provide a new IlvDocument
instance. If the document template is MDI (see isMDI()
) or if no
documents have yet been created by the document template, the method
createDocument()
is called to create a new document instance. Otherwise,
the open document created by the document template has its modifications
saved and is eventually cleaned.
Once a new document is created, the document template is asked to create
document views to associate with this document, with its method
createDocumentViews(ilog.views.appframe.docview.IlvMainWindow, ilog.views.appframe.docview.IlvDocument)
. The creation of views is parameterized by
IlvDocumentViewConfiguration
instances that are initialized by the document template from its
settings. (See getViewConfiguration(java.lang.String)
for more details.)
For each view configuration that has the auto create mode, the document
template creates a view container.
Finally, the document template activates one of the newly created view
containers. This container is determined as follows:
SELECTED_CONFIGURATION_PROPERTY
has been initialized
from the settings or by using the setProperty(java.lang.String, java.lang.Object)
method, the container
with the view configuration that is specified by this property will be activated.Creation/closing of document view
After a document has been created with its views, it is possible to
create new document views or to close existing ones.
Document views are created dynamically with the methods
newViewContainer(IlvDocument, String, boolean)
or
newViewContainer(IlvDocument, IlvContainerTemplate, String)
, whereas
views are closed with the methods closeDocumentViews(ilog.views.appframe.docview.IlvDocument)
or closeViewContainer(IlvMDIViewContainer)
. It is also possible
to ensure that a view for a document has been created with the method
ensureDocumentViewExists(ilog.views.appframe.docview.IlvDocument, java.lang.String, boolean)
.
You can find documentation and examples of using document templates in the Rogue Wave JViews Application Framework User's Manual, in the chapter on Applying the Document/View Architecture.
Modifier and Type | Field and Description |
---|---|
static String |
DATA_CLASS_PROPERTY
Bound property name for the class of data the documents created by
the template embed.
|
static String |
DEFAULT_DOCUMENT_NAME_PROPERTY
Bound property name for the default name of the document
created by the document template.
|
static String |
DESCRIPTION_PROPERTY
Bound property name for the description of the document template.
|
static String |
DOCUMENT_CLASS_PROPERTY
Bound property name for the class of documents that this document template
creates.
|
static String |
ICON_PROPERTY
Bound property name for the icon of the document template.
|
static String |
NAME_PROPERTY
Bound property name for the name of the document template.
|
static String |
SELECTED_CONFIGURATION_PROPERTY
Bound property name for the name of the configuration
whose new container must be activated when creating views
on a document.
|
static String |
SETTINGS_TYPE
The type of settings elements providing the settings for document templates.
|
static String |
SHORT_NAME_PROPERTY
Bound property name for the short name of the document template.
|
static String |
UNDO_LIMIT_PROPERTY
Bound property name for the undo limit of the documents of
this document template.
|
Constructor and Description |
---|
IlvDocumentTemplate()
Constructs a new
IlvDocumentTemplate instance. |
IlvDocumentTemplate(String name)
Constructs a new
IlvDocumentTemplate instance with the
specified name . |
Modifier and Type | Method and Description |
---|---|
void |
actionPerformed(ActionEvent e)
Invoked when an action occurs.
|
void |
activateDocumentView(IlvDocument document)
Activates the specified
document by activating the view
containers of the document. |
void |
activateDocumentView(IlvDocumentView view)
Activates the specified
view . |
void |
addPropertyChangeListener(PropertyChangeListener listener)
Adds a listener that listens for changes to the properties of this
document template.
|
boolean |
alwaysShowMenu()
Determines whether the document template completes the main menu and toolbar
of the application main window when the application is initializing or
after a document associated with this document template is activated.
|
boolean |
canCloseViewContainer(IlvViewContainer container)
Determines whether the specified view container can be closed.
|
boolean |
closeDocument(IlvDocument document,
boolean force)
Tries to close the specified document.
|
boolean |
closeDocumentView(IlvDocument document,
String viewConfiguration)
Closes the document view associated with the specified
document and created for the specified
viewConfiguration . |
void |
closeDocumentViews(IlvDocument document)
Closes all the views of the specified
document that are
not static. |
boolean |
closeViewContainer(IlvMDIViewContainer container)
Closes the specified view container.
|
boolean |
closeViewContainer(IlvMDIViewContainer container,
boolean closeDocument)
Closes the specified view container.
|
void |
connectMainWindow(IlvMainWindow mainWindow)
Associates this document template with a main window.
|
IlvDocument |
createDocument()
Factory method for creating documents associated with this document template.
|
boolean |
createDocumentViews(IlvMainWindow mainWindow,
IlvDocument document)
Creates the view containers of a document.
|
void |
documentActivated(IlvDocument document,
boolean activated)
Invoked after a view of the specified
document has been
activated or deactivated, depending on the value of the specified
activated parameter. |
IlvDocumentView |
documentViewExists(IlvDocument document,
String viewConfiguration)
Determines whether a document view associated with the specified
document has been created for the specified
viewConfiguration . |
IlvDocumentView |
ensureDocumentViewExists(IlvDocument document,
String viewConfiguration,
boolean activate)
Ensures that a document view is created for the specified
document and viewConfiguration . |
IlvApplication |
getApplication()
Returns the application of this document template.
|
Class<?> |
getDataClass()
Returns the class of the data that the documents created by this template
embed.
|
String |
getDefaultDocumentName()
Returns the default name to be given to the document created by this
document template.
|
String |
getDescription()
Returns the description of the document template.
|
Class<?> |
getDocumentClass()
Returns the class of the documents created by this document template.
|
IlvViewContainer[] |
getDocumentContainers(IlvDocument document)
Returns all the view containers that contain views of the specified
document . |
Icon |
getIcon()
Returns the icon associated with this document template.
|
Icon |
getIcon(String configurationName)
Returns the icon for the specified view configuration with the
specified name.
|
IlvMenuCompletion |
getMenuCompletion(IlvMainWindow mainWindow)
Returns the menu completion instance that is responsible for
completing/removing items from the main menu and toolbars of the
specified main window.
|
String |
getName()
Returns the name of the document template.
|
Object |
getProperty(String key)
Returns the property of this object with the specified key.
|
String |
getRecentFileListCommand()
Returns the command key of the action that stores the list
of Most Recently Used files for this document template.
|
IlvSettings |
getSettings()
Returns the settings of the document template.
|
IlvSettingsElement |
getSettingsElement()
Returns the settings element that provides the settings for this document
template.
|
String |
getShortName()
Returns a short name for the document template.
|
IlvDocumentViewConfiguration |
getViewConfiguration(int index)
Returns the view configuration at the specified storage
index . |
IlvDocumentViewConfiguration |
getViewConfiguration(String configName)
Returns the view configuration with the specified
name . |
int |
getViewConfigurationCount()
Returns the number of view configurations of the document template.
|
boolean |
hasOwnRecentFileList()
Determines whether the documents opened by this document template are
referenced in a list of Most Recently Used files specific to this document
template.
|
void |
initializeDocumentViews(IlvDocument document)
Initializes all the views of the specified
document . |
void |
insertBars(IlvMainWindow mainWindow)
Completes the menu and toolbars of the specified
mainWindow
and inserts additional toolbars as specified in the settings of the
document template. |
boolean |
isMDI()
Determines whether more than one document can be created by the
document template at the same time.
|
boolean |
isProcessingAction(String command)
Determines whether the document template is able to perform the action
with the specified
command key. |
int |
matchData(Object data)
Provides the matching level of the document template with a data object.
|
IlvMDIViewContainer |
newMDIViewContainer(IlvDocument document,
IlvMDIContainerTemplate containerTemplate,
String configurationName)
Creates a new MDI view container for the specified document and MDI
container template.
|
IlvViewContainer |
newViewContainer(IlvDocument document,
IlvContainerTemplate containerTemplate,
String configurationName)
Creates a new view container for the specified document and container
template.
|
IlvViewContainer |
newViewContainer(IlvDocument document,
String configurationName,
boolean activate)
Creates a new view container for the specified
document
and the specified configuration. |
boolean |
readSettings(IlvSettingsElement element,
IlvApplication application)
Reads the settings of the document template from the specified
settings element.
|
boolean |
readSettings(IlvSettings settings,
IlvApplication application)
Reads the settings of the document template.
|
void |
removeBars(IlvMainWindow mainWindow)
Removes all the toolbars and the menu completion that were added by
this document template to the specified
mainWindow . |
void |
removePropertyChangeListener(PropertyChangeListener listener)
Removes the specified listener from the list of
PropertyChange
listeners managed by this document template. |
boolean |
saveDocumentModifications(IlvDocument document)
Saves the specified
document if it was modified. |
void |
setApplication(IlvApplication application)
Sets the application of this document template.
|
void |
setDefaultDocumentName(String defaultName)
Sets the default name to set to the document created by this
document template.
|
void |
setDescription(String description)
Sets the description of the document template.
|
void |
setDocumentClass(Class<?> documentClass)
Sets the class of document that this document template creates.
|
void |
setMDI(boolean mdi)
Sets the document template as MDI or not, depending on the value of the
mdi parameter. |
void |
setName(String name)
Sets the name of the document template.
|
Object |
setProperty(String key,
Object value)
Changes the value of one of the properties of this document template.
|
void |
setSettings(IlvSettings settings)
Sets the settings that initialize the document template.
|
void |
setShortName(String shortName)
Sets a short name to the document template.
|
boolean |
updateAction(Action action)
Invoked by the application for updating the state of the specified
action . |
void |
updateViewContainerTitles(IlvDocument document)
Updates the title of all the view containers containing document views
of the specified
document . |
public static final String SETTINGS_TYPE
public static final String NAME_PROPERTY
getName()
,
setName(java.lang.String)
,
Constant Field Valuespublic static final String ICON_PROPERTY
getIcon()
,
Constant Field Valuespublic static final String DESCRIPTION_PROPERTY
public static final String SHORT_NAME_PROPERTY
public static final String DEFAULT_DOCUMENT_NAME_PROPERTY
getDefaultDocumentName()
,
Constant Field Valuespublic static final String SELECTED_CONFIGURATION_PROPERTY
public static final String DATA_CLASS_PROPERTY
dataJavaClass
attribute of the settings element defining
the document template.matchData(java.lang.Object)
,
Constant Field Valuespublic static final String UNDO_LIMIT_PROPERTY
public static final String DOCUMENT_CLASS_PROPERTY
public IlvDocumentTemplate()
IlvDocumentTemplate
instance.public IlvDocumentTemplate(String name)
IlvDocumentTemplate
instance with the
specified name
. This constructor is invoked when the
application is creating its document templates from the settings.
The specified name is the value of the name
attribute
of the settings element that defines the document template.name
- The name of the document template.getName()
,
setName(java.lang.String)
public boolean createDocumentViews(IlvMainWindow mainWindow, IlvDocument document)
Containers are created for all the document view configurations of this template that are in autocreate mode.
mainWindow
- The main window in which the view containers are created.document
- The document for which the view container is created.true
if view containers have been successfully created;
false
otherwise.IlvDocumentViewConfiguration.isAutoCreate()
,
IlvDocumentViewConfiguration
public int matchData(Object data)
This method is called by the application when it looks for a document
template that could create a document that embeds the specified data.
By default, the class accessible with the property DATA_CLASS_PROPERTY
of the document template is compared with the class
of the specified data.
null
, -1
will be returned.0
will be returned.1
will be returned and so on.data
- The data to match the class with the data class property stored
in this document template.DATA_CLASS_PROPERTY
,
getDataClass()
public void closeDocumentViews(IlvDocument document)
document
that are
not static.
All the view containers of the document that are not static - that
implement the IlvMDIViewContainer
interface - are closed with
their views. All the views of the document that are static,
registered with the main window of the application through the
method IlvMainWindow.registerStaticView(java.lang.String, ilog.views.appframe.docview.IlvDocumentView)
are detached from this document and initialized with a
null
document.
document
- The document that has its views closed.public IlvViewContainer[] getDocumentContainers(IlvDocument document)
document
.document
- The document from which view containers are retrieved.public IlvViewContainer newViewContainer(IlvDocument document, String configurationName, boolean activate)
document
and the specified configuration.document
- The document from which a view container is created.configurationName
- The name of the IlvDocumentViewConfiguration
that is used for creating the new view container.activate
- If true
, the new container is
activated and the active view of the container receives action events
of the application. Otherwise, the new view container is not
activated, even though its creation may lead to its activation.null
will be returned.public IlvViewContainer newViewContainer(IlvDocument document, IlvContainerTemplate containerTemplate, String configurationName)
document
- The document from which a view container is created.containerTemplate
- The container template used to create the new
view container.configurationName
- This parameter is used only if the
specified container template is an IlvMDIContainerTemplate
instance. It is the name of the window configuration used
to create the views in the container created by the container template.IlvSingleContainerTemplate
instance,
the container provided with its IlvSingleContainerTemplate.getViewContainer()
method is returned.newViewContainer(IlvDocument, IlvContainerTemplate, String)
public IlvMDIViewContainer newMDIViewContainer(IlvDocument document, IlvMDIContainerTemplate containerTemplate, String configurationName)
document
- The document from which a view container is created.containerTemplate
- The MDI container template used to create the new
view container.configurationName
- The name of the view configuration used
to create the views in the container created by the container template.newViewContainer(IlvDocument, IlvContainerTemplate, String)
public void activateDocumentView(IlvDocumentView view)
view
.
The container of the view is activated previously and the view is set
as the active view of the container.view
- The view to activate.IlvViewContainer.ACTIVE_VIEW_PROPERTY
public void activateDocumentView(IlvDocument document)
document
by activating the view
containers of the document.
If no view containers have been created earlier for the document, they will be created.document
- The document of which a view is activated.public void documentActivated(IlvDocument document, boolean activated)
document
has been
activated or deactivated, depending on the value of the specified
activated
parameter.document
- The document that has been activated or deactivated.activated
- If true
, the document has been activated;
otherwise, the document has been deactivated.public IlvDocumentView documentViewExists(IlvDocument document, String viewConfiguration)
document
has been created for the specified
viewConfiguration
.document
- The document from which a view is retrieved.viewConfiguration
- The name of the view configuration
from which a document view is retrieved.null
if no document view
was found.ensureDocumentViewExists(ilog.views.appframe.docview.IlvDocument, java.lang.String, boolean)
,
getViewConfiguration(java.lang.String)
public IlvDocumentView ensureDocumentViewExists(IlvDocument document, String viewConfiguration, boolean activate)
document
and viewConfiguration
.
If a document view is not found for the specified view configuration,
it will be created.document
- The document for which you want to ensure that a view exists.viewConfiguration
- The name of the view configuration
from which a document view is retrieved or created.activate
- If true
, the new document view that has been
retrieved or created is activated; if false
, the activation
state of the view will remain unchanged.null
if no document view
was found or could be created.documentViewExists(ilog.views.appframe.docview.IlvDocument, java.lang.String)
,
getViewConfiguration(java.lang.String)
public boolean closeDocumentView(IlvDocument document, String viewConfiguration)
document
and created for the specified
viewConfiguration
. The view container containing the
document view is closed.document
- The document that has its views closed.viewConfiguration
- The name of the view configuration
from which the document views to close were created originally.true
if document views could be found and closed;
false
otherwise.closeViewContainer(ilog.views.appframe.docview.IlvMDIViewContainer)
public void initializeDocumentViews(IlvDocument document)
document
.
IlvDocumentView.initializeView(ilog.views.appframe.docview.IlvDocument)
and fires
a corresponding
ApplicationEvent.DOCUMENT_VIEW_INITIALIZED
event.document
- The document which views are being initialized.public void updateViewContainerTitles(IlvDocument document)
document
.document
- The document with the view containers that have their title updated.public IlvDocument createDocument()
getDocumentClass()
method. This method can be overridden to create
specific documents.public boolean alwaysShowMenu()
true
if the document template completes the main menu
and toolbars when the application is initialized;
false
if the the main menu and toolbars are completed only
if a document of this document template has been activated. In this case,
the added items and toolbars are removed when the document becomes inactive.public void insertBars(IlvMainWindow mainWindow)
mainWindow
and inserts additional toolbars as specified in the settings of the
document template.
mainWindow
- The main window that has its menu and toolbars completed.removeBars(ilog.views.appframe.docview.IlvMainWindow)
,
ApplicationEvent.DOCUMENT_TEMPLATE_ACTIVATED
public void removeBars(IlvMainWindow mainWindow)
mainWindow
.
mainWindow
- The main window from which bar insertions are removed.insertBars(ilog.views.appframe.docview.IlvMainWindow)
,
ApplicationEvent.DOCUMENT_TEMPLATE_DEACTIVATED
public String getName()
setName(java.lang.String)
public void setName(String name)
name
- The new name of the document template.getName()
public IlvApplication getApplication()
public void setApplication(IlvApplication application)
application
- The new application of the document template.getApplication()
public IlvSettings getSettings()
public void setSettings(IlvSettings settings)
setApplication(ilog.views.appframe.IlvApplication)
.settings
- The new settings of the document template.getSettings()
,
setApplication(ilog.views.appframe.IlvApplication)
public Class<?> getDocumentClass()
documentJavaClass
attribute of the settings element that defines this document template.public void setDocumentClass(Class<?> documentClass)
documentClass
- The new document class.getDocumentClass()
,
DOCUMENT_CLASS_PROPERTY
,
createDocument()
public Class<?> getDataClass()
matchData(java.lang.Object)
,
DATA_CLASS_PROPERTY
public String getShortName()
public void setShortName(String shortName)
shortName
- The new short name of the document template.getShortName()
,
SHORT_NAME_PROPERTY
public String getDescription()
description
attribute
of the settings element defining the document template.public void setDescription(String description)
description
- The new description of the document template.getDescription()
,
DESCRIPTION_PROPERTY
public String getDefaultDocumentName()
IlvApplication.newDocument(IlvDocumentTemplate, boolean, Object)
or IlvApplication.newDocument()
or IlvApplication.newDocumentOnLastTemplate()
.
It is initialized with the defaultDocumentName
attribute of the settings element defining the document template.setDefaultDocumentName(java.lang.String)
public void setDefaultDocumentName(String defaultName)
defaultName
- The new default name of the documents of this
document template.getDefaultDocumentName()
public boolean isMDI()
The MDI property of the document template is initialized from the
isMDI
attribute of the settings element defining the
document template. If this attribute is not specified, the document
template is considered to be MDI by default.
true
if more than one document can be open
at the same time; false
otherwise.setMDI(boolean)
public void setMDI(boolean mdi)
mdi
parameter.mdi
- If true
, the document template is set to
MDI; if false
, the parameter is not MDI.isMDI()
public boolean hasOwnRecentFileList()
true
if the documents of this document template
are referenced in a list of Most Recently Used files specific to this
document template; false
if the documents are referenced
in the global list of Most Recently Used files of the application.getRecentFileListCommand()
public String getRecentFileListCommand()
hasOwnRecentFileList()
returns
true
.hasOwnRecentFileList()
public void connectMainWindow(IlvMainWindow mainWindow)
mainWindow
- The main window to which this document template is connected.IlvMainWindow.getContainerTemplate(java.lang.String)
public IlvMenuCompletion getMenuCompletion(IlvMainWindow mainWindow)
<menuCompletion>
child element
of the settings element defining this document template. If no such
element is specified, this method returns null
.mainWindow
- The main window with the menus and toolbars that will be
modified by the menu completion of this document template.null
.public boolean readSettings(IlvSettings settings, IlvApplication application)
documentTemplate
type and whose name
attribute is equal to the name of the document template, given by
the method getName()
.settings
- The settings from which to initialize the document template.application
- The application to which this document template will be added.
It can be used for localizing strings or resolving URLs.true
if the document template could be initialized
from the specified settings; false
otherwise.readSettings(IlvSettingsElement, IlvApplication)
public boolean readSettings(IlvSettingsElement element, IlvApplication application)
element
- The settings element from which the settings are read.application
- The application of the document template. It can be used
for localizing strings or resolving URLs.true
if the settings of the document template could
be read; false
otherwise.public IlvSettingsElement getSettingsElement()
public void actionPerformed(ActionEvent e)
isProcessingAction(java.lang.String)
method
returns true
with the e.getActionCommand()
value as the parameter.actionPerformed
in interface ActionListener
e
- The action event.isProcessingAction(java.lang.String)
public boolean isProcessingAction(String command)
command
key.
A document template can handle actions only if a document of this
document template is active in the application.
isProcessingAction
in interface ActionHandler
command
- The command key of the action.true
if the document template can process the specified
action; false
otherwise.actionPerformed(java.awt.event.ActionEvent)
public boolean updateAction(Action action)
action
.
false
.updateAction
in interface ActionHandler
action
- The action to update.true
if the document template has updated the state
of the action; false
otherwise.public Icon getIcon()
ICON_PROPERTY
,
getIcon(java.lang.String)
public Icon getIcon(String configurationName)
getIcon()
.configurationName
- The name of the
IlvDocumentViewConfiguration
to return the icon for.getIcon()
public boolean closeDocument(IlvDocument document, boolean force)
force
parameter is false
, the application user is prompted for
saving the document if it is modified. If the document can be closed,
all the document views associated with this document that are not static
are closed.document
- The document to close.force
- If true
, the document will be closed whenever
it has been modified, without the application user being asked for confirmation.
If false
, the user will be asked to saved the document if it has been
modified and can cancel the operation.true
if the document was closed;
false
otherwise.public boolean saveDocumentModifications(IlvDocument document)
document
if it was modified.
If the document is a file document and does not yet have a
specified file name, a file chooser is displayed to ask for it.true
if the document was not modified or if
the document was saved. Otherwise, the method returns false
.public boolean closeViewContainer(IlvMDIViewContainer container)
closeViewContainer(IlvMDIViewContainer, boolean)
with true
as the closeDocument
parameter.container
- The view container to close.true
if the container could be closed;
false
otherwise.closeViewContainer(IlvMDIViewContainer, boolean)
public boolean closeViewContainer(IlvMDIViewContainer container, boolean closeDocument)
container
- The view container to close.closeDocument
- If true
, the document associated with
the container and all the views of the document are closed; Otherwise,
the document is not closed even though the document remains with no
associated views.true
if the container could be closed;
false
otherwise.closeViewContainer(IlvMDIViewContainer)
public boolean canCloseViewContainer(IlvViewContainer container)
true
if the view container view can be closed;
false
otherwise.public Object setProperty(String key, Object value)
PropertyChangeEvent
is sent to
property change listeners.setProperty
in interface IlvPropertyManager
key
- The non-null
property key.value
- An Object
value. If it is equal to
null
, the property with the specified key will be removed.getProperty(java.lang.String)
public Object getProperty(String key)
getProperty
in interface IlvPropertyManager
key
- The non-null
property key.null
if the specified property was not found.setProperty(java.lang.String, java.lang.Object)
public void addPropertyChangeListener(PropertyChangeListener listener)
addPropertyChangeListener
in interface IlvPropertyManager
listener
- The listener to add.removePropertyChangeListener(java.beans.PropertyChangeListener)
public void removePropertyChangeListener(PropertyChangeListener listener)
PropertyChange
listeners managed by this document template.removePropertyChangeListener
in interface IlvPropertyManager
listener
- The listener to remove.addPropertyChangeListener(java.beans.PropertyChangeListener)
public IlvDocumentViewConfiguration getViewConfiguration(String configName)
name
.
<containerTemplate>
settings elements, children of the <containerTemplates>
child element of the settings element defining this document template.configName
- The name of the view configuration to return.null
if no view configuration could be found with this name.getViewConfiguration(int)
public IlvDocumentViewConfiguration getViewConfiguration(int index)
index
.index
- The storage index of the view configuration to return.index
.getViewConfigurationCount()
public int getViewConfigurationCount()
index
.getViewConfiguration(int)
© Copyright Rogue Wave Software, Inc. 1997, 2018. All Rights Reserved.