ilog.views.appframe.docview
Class IlvAbstractDocument

java.lang.Object
  extended by ilog.views.appframe.docview.IlvAbstractDocument
All Implemented Interfaces:
IlvDocument, ActionHandler, MessageListener, IlvPropertyManager, ActionListener, EventListener
Direct Known Subclasses:
IlvAbstractFileDocument, IlvDataDocument

public abstract class IlvAbstractDocument
extends Object
implements IlvDocument

An implementation of the IlvDocument interface to serve as a basis for implementing various kinds of documents.


Field Summary
static String REDO_CMD
          Action command key for the Redo action.
static String UNDO_CMD
          Action command key for the Undo action.
 
Fields inherited from interface ilog.views.appframe.docview.IlvDocument
APPLICATION_PROPERTY, ATTACHED_DOCUMENTS_PROPERTY, DOCUMENT_OWNER_PROPERTY, DOCUMENT_TEMPLATE_PROPERTY, EDITABLE_PROPERTY, MODIFIED_PROPERTY, SAVEABLE_PROPERTY, TITLE_PROPERTY
 
Constructor Summary
IlvAbstractDocument()
          Constructs a new IlvAbstractDocument.
 
Method Summary
 void actionPerformed(ActionEvent event)
          Processes the specified action event.
 void activated(boolean active)
          Invoked when the document has been activated or deactivated.
 void addActionHandler(ActionHandler actionHandler)
          Adds the specified actionHandler to the list of action handlers of the document.
 void addEdit(UndoableEdit edit)
          Adds the specified undoable edit to the undo manager owned by the document.
 void addPropertyChangeListener(PropertyChangeListener listener)
          Adds a listener that listens for changes to the document properties.
 void addView(IlvDocumentView view)
          Adds the specified instance of IlvDocumentView to the list of views of the document.
 void attachDocument(IlvDocument document, boolean attach)
          Attaches or detaches the specified document from this document, depending on the value of the attach parameter.
 boolean canRedo()
          Returns true if a redo operation can be performed by the document; false otherwise.
 boolean canUndo()
          Returns true if an undo operation can be performed by the document; false otherwise.
 void clean()
          Cleans up the document.
 void documentClosed()
          Invoked after the document was closed.
 void documentClosing()
          Invoked before the document closes.
 IlvDocumentView getActiveView()
          Returns the view currently active for the document, namely the last view of the document that became active to the application.
 IlvApplication getApplication()
          Returns the application of the document.
 IlvDocumentTemplate getDocumentTemplate()
          Returns the document template that has created the document.
 Object getProperty(String name)
          Returns the value of the document property with the specified key.
 String getTitle()
          Returns the title of the document.
 UndoManager getUndoManager()
          Returns the undo manager that stores undoable edits added to the document.
 IlvDocumentView getView(int index)
          Returns the view of the document at the specified position in the list of document views.
 int getViewCount()
          Returns the number of views associated with this document.
 IlvDocumentView[] getViews()
          Returns all the document views associated with the document.
 boolean initializeDocument(Object userData)
          Initializes a new document.
 boolean isModified()
          Returns the modification state of the document.
 boolean isProcessingAction(String command)
          Determines whether the document is able to perform the action with the specified command key in its actionPerformed(java.awt.event.ActionEvent) method.
protected  void notifyViews(String name, IlvDocumentView except, Object[] params)
          Notifies the views associated with this document of an event.
 void receiveMessage(MessageEvent event)
          Invoked when the specified message event is received.
 void redo()
          Redoes the last undoable edit undone by the document.
protected  void registerMappings(IlvMessageMapper msgMapper)
          This method is called to register the mappings between action events and document methods.
 boolean removeActionHandler(ActionHandler actionHandler)
          Removes the specified actionHandler from the list of action handlers managed by this document.
 void removePropertyChangeListener(PropertyChangeListener listener)
          Removes the specified listener from the document listener list.
 boolean removeView(IlvDocumentView view)
          Removes the specified view from the list of views of the document.
 void removeViews()
          Removes all the views owned by the document.
 void setApplication(IlvApplication application)
          Sets the application of the document.
 void setModified(boolean modified)
          Marks this document as modified.
 Object setProperty(String name, Object value)
          Sets one of the properties of this document using the associated key.
 void setTitle(String title)
          Sets a new title to the document.
 void undo()
          Undoes the last undoable edit added to the document.
 boolean updateAction(Action action)
          Invoked by the application for updating the state of the specified action.
protected  void updateModificationState()
          Updates the modification state of the document.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

UNDO_CMD

public static final String UNDO_CMD
Action command key for the Undo action.

See Also:
Constant Field Values

REDO_CMD

public static final String REDO_CMD
Action command key for the Redo action.

See Also:
Constant Field Values
Constructor Detail

IlvAbstractDocument

public IlvAbstractDocument()
Constructs a new IlvAbstractDocument. Initialization of the empty document should be performed in the initializeDocument(java.lang.Object) method.

See Also:
initializeDocument(java.lang.Object)
Method Detail

initializeDocument

public boolean initializeDocument(Object userData)
Initializes a new document. By default, this method registers action handlers associated with the document and returns true.

Specified by:
initializeDocument in interface IlvDocument
Parameters:
userData - The user data to initialize the document with - can be null. This parameter is not used by default.
Returns:
true. Overridden methods return true if the document was successfully initialized, or false otherwise.
See Also:
IlvApplication.newDocument(java.lang.Object, boolean), IlvApplication.newDocument(), IlvApplication.newDocument(IlvDocumentTemplate, boolean, Object)

documentClosing

public void documentClosing()
Invoked before the document closes. The default implementation is empty.

Specified by:
documentClosing in interface IlvDocument
See Also:
documentClosed()

documentClosed

public void documentClosed()
Invoked after the document was closed. The default implementation is empty.

Specified by:
documentClosed in interface IlvDocument
See Also:
documentClosing()

clean

public void clean()
Cleans up the document. All the undoable edits added to the document are discarded.

Specified by:
clean in interface IlvDocument

activated

public void activated(boolean active)
Invoked when the document has been activated or deactivated. A document is activated after one of its view becomes the active view of the application. It is deactivated when this view is deactivated.

Specified by:
activated in interface IlvDocument
Parameters:
active - If this parameter is true, the document has been activated. If it is false, the document has been deactivated.

getViewCount

public int getViewCount()
Returns the number of views associated with this document.

Specified by:
getViewCount in interface IlvDocument

removeView

public boolean removeView(IlvDocumentView view)
Removes the specified view from the list of views of the document.

Specified by:
removeView in interface IlvDocument
Returns:
true if the specified view has been removed from the list of views of the document; false if the view has not been added to the document.
See Also:
addView(ilog.views.appframe.docview.IlvDocumentView)

removeViews

public void removeViews()
Removes all the views owned by the document.

Specified by:
removeViews in interface IlvDocument

addView

public void addView(IlvDocumentView view)
Adds the specified instance of IlvDocumentView to the list of views of the document.

Specified by:
addView in interface IlvDocument
Parameters:
view - The view to add to the list of views of the document.
See Also:
getViewCount(), removeView(ilog.views.appframe.docview.IlvDocumentView), removeViews()

getView

public IlvDocumentView getView(int index)
Returns the view of the document at the specified position in the list of document views.

Specified by:
getView in interface IlvDocument
Parameters:
index - The storage index of the view to return.
Returns:
The document view at the specified index.
See Also:
getView(int)

getViews

public IlvDocumentView[] getViews()
Returns all the document views associated with the document.

Returns:
An array of document views.

getActiveView

public IlvDocumentView getActiveView()
Returns the view currently active for the document, namely the last view of the document that became active to the application.

Returns:
The active view.

isModified

public boolean isModified()
Returns the modification state of the document.

Specified by:
isModified in interface IlvDocument
Returns:
true if the document is modified; false otherwise.
See Also:
setModified(boolean)

setModified

public void setModified(boolean modified)
Marks this document as modified. This method should not be used. Rather, you should modify the document by adding undoable edits. When you do so, the modification state of the document is automatically calculated according to the stack of undoable edits managed by the document. Moreover, this approach allows actions that have modified the document to be undone.

Specified by:
setModified in interface IlvDocument
Parameters:
modified - The new modification state of the document. If true, the document is marked as modified. If false, the document is marked as unmodified.
See Also:
isModified(), addEdit(javax.swing.undo.UndoableEdit)

getTitle

public String getTitle()
Returns the title of the document. The value of the TITLE_PROPERTY is returned.

Specified by:
getTitle in interface IlvDocument
Returns:
The title of the document.
See Also:
setTitle(java.lang.String)

setTitle

public void setTitle(String title)
Sets a new title to the document.

Specified by:
setTitle in interface IlvDocument
Parameters:
title - The new title of the document.
See Also:
getTitle()

getDocumentTemplate

public IlvDocumentTemplate getDocumentTemplate()
Returns the document template that has created the document.

Specified by:
getDocumentTemplate in interface IlvDocument
Returns:
The value of the IlvDocument.DOCUMENT_TEMPLATE_PROPERTY that is automatically set by the document template of the document.

updateAction

public boolean updateAction(Action action)
Invoked by the application for updating the state of the specified action. For example, the implementation of this method can enable or disable the action. By default, the document processes the state of actions with the following command names:

Specified by:
updateAction in interface ActionHandler
Parameters:
action - The action to update.
Returns:
true if the action handler has updated the state of the action; false otherwise.

actionPerformed

public void actionPerformed(ActionEvent event)
Processes the specified action event. This method is called only when isProcessingAction(java.lang.String) returns true for the action command corresponding to this event as the parameter. By default, the document processes the actions with the following command keys:

Specified by:
actionPerformed in interface ActionListener

isProcessingAction

public boolean isProcessingAction(String command)
Determines whether the document is able to perform the action with the specified command key in its actionPerformed(java.awt.event.ActionEvent) method. By default, the document processes the actions with the following command names:

Specified by:
isProcessingAction in interface ActionHandler
Parameters:
command - The command key of the action.
Returns:
true if the document can handle the specified action; false otherwise.
See Also:
actionPerformed(java.awt.event.ActionEvent)

registerMappings

protected void registerMappings(IlvMessageMapper msgMapper)
This method is called to register the mappings between action events and document methods.

Parameters:
msgMapper - The message mapper to register mappings to.
See Also:
IlvMessageMapper.registerActionMethod(java.lang.String, java.lang.String), IlvMessageMapper.registerActionStateMethod(java.lang.String, java.lang.String)

addActionHandler

public void addActionHandler(ActionHandler actionHandler)
Adds the specified actionHandler to the list of action handlers of the document.

Parameters:
actionHandler - The new action handler to add.
See Also:
removeActionHandler(ilog.views.appframe.event.ActionHandler)

removeActionHandler

public boolean removeActionHandler(ActionHandler actionHandler)
Removes the specified actionHandler from the list of action handlers managed by this document.

Returns:
true if the action handler has been previously added; false otherwise.
See Also:
addActionHandler(ilog.views.appframe.event.ActionHandler)

receiveMessage

public void receiveMessage(MessageEvent event)
Invoked when the specified message event is received.

Specified by:
receiveMessage in interface MessageListener
Parameters:
event - The message event.
See Also:
MessageEvent

getUndoManager

public UndoManager getUndoManager()
Returns the undo manager that stores undoable edits added to the document.

Returns:
The undo manager.
See Also:
addEdit(javax.swing.undo.UndoableEdit), undo(), canUndo(), redo(), canRedo()

canUndo

public boolean canUndo()
Returns true if an undo operation can be performed by the document; false otherwise.

See Also:
undo()

undo

public void undo()
Undoes the last undoable edit added to the document.

See Also:
canUndo(), addEdit(javax.swing.undo.UndoableEdit)

canRedo

public boolean canRedo()
Returns true if a redo operation can be performed by the document; false otherwise.

See Also:
redo()

redo

public void redo()
Redoes the last undoable edit undone by the document.

See Also:
canRedo()

addEdit

public void addEdit(UndoableEdit edit)
Adds the specified undoable edit to the undo manager owned by the document. It updates the Undo/Redo actions and the modification state of the document.

Parameters:
edit - the undoable edit to add.

updateModificationState

protected void updateModificationState()
Updates the modification state of the document. The default implementation of this method determines the state of the document according to the state of the undo manager of the document.

See Also:
getUndoManager()

notifyViews

protected void notifyViews(String name,
                           IlvDocumentView except,
                           Object[] params)
Notifies the views associated with this document of an event. Sends an event with the specified name and list of parameters to the associated document views.

Parameters:
name - The name of the message to send.
except - Specifies a particular view that must not receive this message. Can be null for notifying all the views of the document.
params - The parameters of the message.

setProperty

public Object setProperty(String name,
                          Object value)
Sets one of the properties of this document using the associated key. If the value has changed, a PropertyChangeEvent is sent to property change listeners.

Specified by:
setProperty in interface IlvPropertyManager
Parameters:
name - The non-null property name
value - An Object value. If it is equal to null, the property with the specified key is removed.
Returns:
The previous value of the property.
See Also:
getProperty(java.lang.String)

getProperty

public Object getProperty(String name)
Returns the value of the document property with the specified key.

Specified by:
getProperty in interface IlvPropertyManager
Parameters:
name - The name of the document property whose value is retrieved.
Returns:
The property value.
See Also:
IlvPropertyManager.setProperty(java.lang.String, java.lang.Object)

getApplication

public IlvApplication getApplication()
Returns the application of the document.

Specified by:
getApplication in interface IlvDocument
Returns:
The value of the APPLICATION_PROPERTY that is automatically set by the document template of the document.
See Also:
setApplication(ilog.views.appframe.IlvApplication)

setApplication

public void setApplication(IlvApplication application)
Sets the application of the document.

Parameters:
application - The application of the document.

addPropertyChangeListener

public void addPropertyChangeListener(PropertyChangeListener listener)
Adds a listener that listens for changes to the document properties.

Specified by:
addPropertyChangeListener in interface IlvPropertyManager
Parameters:
listener - The listener to add.
See Also:
removePropertyChangeListener(java.beans.PropertyChangeListener)

removePropertyChangeListener

public void removePropertyChangeListener(PropertyChangeListener listener)
Removes the specified listener from the document listener list.

Specified by:
removePropertyChangeListener in interface IlvPropertyManager
Parameters:
listener - The listener to remove.
See Also:
addPropertyChangeListener(java.beans.PropertyChangeListener)

attachDocument

public void attachDocument(IlvDocument document,
                           boolean attach)
Attaches or detaches the specified document from this document, depending on the value of the attach parameter. Attached documents are automatically closed when the document they are attached to is closed.

Parameters:
document - The document to attach to this document.
attach - If true, the specified document is attached to this document; if false, the document is detached from this document.


Copyright © 1996-2007 ILOG S.A. All rights reserved.   Documentation homepage.