DefaultDocumentView Class
- public abstract class DefaultDocumentView
extends Object
implements IDocumentView
Default implementation of the IDocumentView interface. This implementation prvoides
most of the simple property, cookie and driver support. Most of the direct IDocumentView
methods need to be implemented.
Derived classes may use addDriver to store drivers on the DefaultDocumentView and it will
take care of returning them on calls to getDriver().
-
Hierarchy
-
Object
DefaultDocumentView
-
All Implemented Interfaces
-
ICookieSupport
, IDocumentView
, IDriverSupport
, IPropertySupport
public Object |
-
addCookie (Object key, Object cookie)
- Adds the cookie object to this object with the given key.
|
protected void |
-
addDriver (Class oClass, Object driver)
- Derived classes should use this method to store drivers on the class.
|
public void |
-
addPropertyChangeListener (String sProp, PropertyChangeListener pcl)
- Adds the given listener to the object for the given property.
|
public void |
-
addPropertyChangeListener (PropertyChangeListener pcl)
- Adds the given listener to the object.
|
protected void |
-
addSelectionRemovalListener ()
- Adds a listener to the document that will call documentSelectionRemoved()
if the selected element is removed from the parse tree.
|
protected void |
-
checkElementRemoval (IDocumentElement elem)
- Check if the removed element contains the active element, and call
DefaultDocumentView.documentSelectionRemoved() if so.
|
protected PropertyChangeListener |
-
createEditableListener ()
- Creates the default editable listener for the view.
|
protected void |
-
documentSelectionRemoved ()
- Called when the document structure changes and the active document element
is no longer part of the parse tree.
|
protected void |
-
editableChanged (boolean editable)
- This method is called when the underlying document's editability changes.
|
public Object |
-
getCookie (Object key)
- Returns the cookie object for the corresponding key.
|
public IDocument |
-
getDocument ()
- Simply returns the document passed in during construction.
|
public IElement |
-
getDocumentElement (IElement el)
- Given an IElement from this view, map it to an appropriate IElement from the element tree of a document.
This implementation simply returns the element if it is an IDocumentElement, else, it returns
null .
|
public Object |
-
getDriver (Class oClass)
- Returns the driver object associated with the given class.
|
public INavigationPoint |
-
getNavigationPoint ()
- Gets a navigation point indicating the current position in the view.
This implementation returns a simple
DefaultDocumentViewNavigationPoint .
|
public Object |
-
getProperty (String sProp)
- Gets the value of a property on the object.
|
public void |
-
onClose ()
- Called to indicate to the view that the user is no longer interested in this view so it should go away.
This implementation removes the listeners added in the constructor.
|
public Object |
-
removeCookie (Object key)
- Removes an association between the specified key and its cookie.
|
public void |
-
removePropertyChangeListener (String sProp, PropertyChangeListener pcl)
- Removes the given listener from the object for the given property.
|
public void |
-
removePropertyChangeListener (PropertyChangeListener pcl)
- Removes the given listener from the object for the given property.
|
protected void |
-
removeSelectionRemovalListener ()
- Removes the listener added in addSelectionRemovalListener().
|
public boolean |
-
setCurrentPoint (INavigationPoint np)
- This method updates the document view so that its state matches the
state specified by the navigation point.
This implementation does nothing, since there is no position information stored in the default
navigation point.
|
public void |
-
setProperty (String sProp, Object oValue)
- Sets a property on the object to the given value.
|
public String |
-
toMemString ()
- Special method that's used by internal Workshop profiling to display information about this object.
|
Methods from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
DefaultDocumentView
public DefaultDocumentView(IDocument
document)
- Constructor initializes property support, watches for editability changes on the document
addCookie(Object, Object) Method
public Object
addCookie(Object
key,
Object
cookie)
Description copied from ICookieSupport.addCookie(Object, Object)
Adds the cookie object to this object with the given key. getCookie may be used to retrieve
the cookie object by passing in the same key. Two keys that compare equal using Object.equals
method will be considered the same key.
Parameters
-
key
- Key value to associate the cookie with.
-
cookie
- Object value to store and associate with the key.
Returns
- If key previously had some cookie associated with it, that value is returned; otherwise
null
is returned. It is possible that the key was explicitly associated with the null object
and this case cannot be distinguished from the case where the key had no previous association.
addDriver(Class, Object) Method
protected void addDriver(Class
oClass,
Object
driver)
Derived classes should use this method to store drivers on the class. It will then return them when
getDriver is called.
Parameters
-
oClass
- class of the driver
-
driver
- object implementing the driver class
addPropertyChangeListener(String, PropertyChangeListener) Method
public void addPropertyChangeListener(String
sProp,
PropertyChangeListener
pcl)
Description copied from IPropertySupport.addPropertyChangeListener(String, PropertyChangeListener)
Adds the given listener to the object for the given property. Whenever the given property
changes the listener will receive a PropertyChangeEvent
.
Parameters
-
sProp
- property to watch for changes
-
pcl
- listener to notify when a change occurs
addPropertyChangeListener(PropertyChangeListener) Method
public void addPropertyChangeListener(PropertyChangeListener
pcl)
Description copied from IPropertySupport.addPropertyChangeListener(PropertyChangeListener)
Adds the given listener to the object. Whenever any property of the object changes
the listener will receive a PropertyChangeEvent
.
Parameters
-
pcl
- listener to notify when a change occurs
addSelectionRemovalListener() Method
protected void addSelectionRemovalListener()
Adds a listener to the document that will call documentSelectionRemoved()
if the selected element is removed from the parse tree. This is
called from the constructor.
checkElementRemoval(IDocumentElement) Method
protected void checkElementRemoval(IDocumentElement
elem)
Check if the removed element contains the active element, and call
DefaultDocumentView.documentSelectionRemoved()
if so. This is called by the default listener
added by addSelectionRemovalListener.
Parameters
-
elem
- the element that was removed and may be a parent of the
currently selected element.
createEditableListener() Method
protected PropertyChangeListener
createEditableListener()
Creates the default editable listener for the view. This listener simply calls the
editableChanged method with the new value of the property
Returns
- default editable listener
documentSelectionRemoved() Method
protected void documentSelectionRemoved()
Called when the document structure changes and the active document element
is no longer part of the parse tree. Default action is to set the active
document element to null, but other implementations are encouraged to
be smarter.
editableChanged(boolean) Method
protected void editableChanged(boolean editable)
This method is called when the underlying document's editability changes. The default
implementation does nothing.
Parameters
-
editable
- the new editable state of the document
getCookie(Object) Method
public Object
getCookie(Object
key)
Description copied from ICookieSupport.getCookie(Object)
Returns the cookie object for the corresponding key. Associations are made using the addCookie
method. Two keys that compare equal using Object.equals method will be considered the same key.
Parameters
-
key
- Key value to use for cookie lookup.
Returns
- The cookie value associated with the key for this document;
null
if there is no association
for the key. It is possible that the key was explicitly associated with the null object
and this case cannot be distinguished from the case where the key has no association.
getDocument() Method
public IDocument
getDocument()
Simply returns the document passed in during construction. Note: there is no way to
change the document dynamically. You must create a new IDocumentView.
Returns
- Document object over which this view is running
getDocumentElement(IElement) Method
public IElement
getDocumentElement(IElement
el)
Given an IElement from this view, map it to an appropriate IElement from the element tree of a document. If
it is already an element from a document, the element may simply be returned. If this element has no
corresponding element in the document tree, the implementation may return null
. The returned element is not
required to be from the document this view was created from. It may be from any document that is represented
in the view. This method is used to provide a mapping for views that use some other type of element as their
PROP_SelectedElement property.
This implementation simply returns the element if it is an IDocumentElement, else, it returns null
.
Returns
- An IElement in the document's tree that the given element represents;
null
if there is no such element
getDriver(Class) Method
public Object
getDriver(Class
oClass)
Description copied from IDriverSupport.getDriver(Class)
Returns the driver object associated with the given class. Drivers are typically used to customize
the behavior of shared services and implementations. Typically, the driver will be represented
by some interface. When that interface is passed to getDriver, the object implementing the interface
for this document should be returned. The method may return null to indicate that the requested
driver does not have an implementation for this document.
Parameters
-
oClass
- The class object representing the class of the driver that is being requested.
Returns
- An object implementing the given class or null if no driver is not implemented.
getNavigationPoint() Method
public INavigationPoint
getNavigationPoint()
Gets a navigation point indicating the current position in the view.
This implementation returns a simple DefaultDocumentViewNavigationPoint
. This
type of navigation point includes no position information. Derived classes are encouraged
to override this method and provide navigation points that can return the user to the exact
state of the editor at the time the method was called.
getProperty(String) Method
public Object
getProperty(String
sProp)
Description copied from IPropertySupport.getProperty(String)
Gets the value of a property on the object.
Parameters
-
sProp
- Name of the property to get
Returns
- The value of the specified property or null if the property has not been set. It is not
possible to distinguish between a property that has not been set and one whose value has been set
explicitly to null.
onClose() Method
public void onClose()
Called to indicate to the view that the user is no longer interested in this view so it should go away. The view
will never be called again. In addition, it is guaranteed that IDocumentView.onDeactivate()
will always be called before
this method.
This implementation removes the listeners added in the constructor.
removeCookie(Object) Method
public Object
removeCookie(Object
key)
Description copied from ICookieSupport.removeCookie(Object)
Removes an association between the specified key and its cookie. If the key had no association
this method does nothing.
Returns
- The cookie this key was previously associated with;
null
if there was no association.
It is possible that the key was explicitly associated with the null object
and this case cannot be distinguished from the case where the key had no previous association.
removePropertyChangeListener(String, PropertyChangeListener) Method
public void removePropertyChangeListener(String
sProp,
PropertyChangeListener
pcl)
Description copied from IPropertySupport.removePropertyChangeListener(String, PropertyChangeListener)
Removes the given listener from the object for the given property. The listener must
have been added using IPropertySupport.addPropertyChangeListener(String, PropertyChangeListener)
.
This method will not remove listeners added using IPropertySupport.addPropertyChangeListener(PropertyChangeListener)
.
Parameters
-
sProp
- property to watch for changes
-
pcl
- listener to notify when a change occurs
removePropertyChangeListener(PropertyChangeListener) Method
public void removePropertyChangeListener(PropertyChangeListener
pcl)
Description copied from IPropertySupport.removePropertyChangeListener(PropertyChangeListener)
Removes the given listener from the object for the given property. The listener must
have been added using IPropertySupport.addPropertyChangeListener(PropertyChangeListener)
.
This method will not remove listeners added using
IPropertySupport.addPropertyChangeListener(String, PropertyChangeListener)
.
Parameters
-
pcl
- listener to notify when a change occurs
removeSelectionRemovalListener() Method
protected void removeSelectionRemovalListener()
Removes the listener added in addSelectionRemovalListener().
setCurrentPoint(INavigationPoint) Method
public boolean setCurrentPoint(INavigationPoint
np)
This method updates the document view so that its state matches the
state specified by the navigation point. The document view should be in
the active state (that is, its onActivate() method must have been called more
recently than its onDeactivate() method).
This implementation does nothing, since there is no position information stored in the default
navigation point. Derived classes are encouraged to override this method and examine the navigation
point to reset state.
Returns
true
if the document view was successfully updated to be consistent with
this navigation point; false
otherwise
setProperty(String, Object) Method
public void setProperty(String
sProp,
Object
oValue)
Description copied from IPropertySupport.setProperty(String, Object)
Sets a property on the object to the given value. This will notify all property change
listeners that the value of the property has changed. Only the listeners for the specified
property and listeners that did not specify a property will be notified.
Parameters
-
sProp
- Name of the property to set
-
oValue
- New value of the property
toMemString() Method
public String
toMemString()
Special method that's used by internal Workshop profiling to display information about this object.