de.qfs.apps.qflog.logview
Class LogLevelTreeModel

java.lang.Object
  |
  +--de.qfs.apps.qflog.logview.LogLevelTreeModel

public class LogLevelTreeModel
extends java.lang.Object
implements javax.swing.tree.TreeModel, de.qfs.lib.config.Configurable, java.util.Observer, de.qfs.lib.log.LogLevelListener

TreeModel for the display of log levels for the Loggers used in an application.

Version:
$Revision: 1.20 $
Author:
Gregor Schmid

Inner Class Summary
static class LogLevelTreeModel.UnitTest
          Test cases for the LogLevelTreeModel class.
 
Constructor Summary
LogLevelTreeModel()
          Create a new LogLevelTreeModel.
 
Method Summary
 void addTreeModelListener(javax.swing.event.TreeModelListener listener)
          Add a TreeModelListener to the LogLevelTreeModel.
 void classAdded(de.qfs.lib.log.LogLevelEvent event)
          Notify the listener that a Logger for a formerly unknown class has requested its log level, adding the class to the log level tree.
 void cleanup()
          Try to remove everything that might prevent garbage collection.
 void finalize()
          Finalize the LogLevelTreeModel.
 void fireNodesChanged(java.lang.Object[] path)
          Tell the TreeModelListeners that a node was modified.
 void fireNodesInserted(java.lang.Object[] path, int index)
          Tell the TreeModelListeners that a node was inserted.
 void fireNodeStructureChanged(java.lang.Object[] path)
          Tell the TreeModelListeners that the structure changed.
 java.lang.Object getChild(java.lang.Object parent, int index)
          Get a child of a node from the tree.
 int getChildCount(java.lang.Object parent)
          Get number of children of a node.
 java.lang.String getClazz(java.lang.Object node)
          Get the class/package of a node.
 java.lang.String getConfigurableName()
          Get the Configurable's name.
 java.util.Properties getConfigurableState()
          Get the Configurable's state.
 int getIndexOfChild(java.lang.Object parent, java.lang.Object child)
          Get the index of node's child.
 java.lang.Integer getLevel(java.lang.Object node)
          Get the level of a node.
 de.qfs.lib.option.OptionSet getOptions()
          Get the options of the LogLevelTreeModel.
 java.lang.Object[] getPath(java.lang.String clazz)
          Get the path for a node representing a package or class.
 java.lang.Object getRoot()
          Get the root node of the tree.
 java.lang.String getRootName()
          Get the name for the root node.
 boolean isLeaf(java.lang.Object node)
          Determine, whether a node is a leaf.
 void levelChanged(de.qfs.lib.log.LogLevelEvent event)
          Notify the listener that a log level has been changed.
 void levelChangedImpl(java.lang.String name, int level)
          Notify the listener that a log level has been changed.
 void levelRemoved(de.qfs.lib.log.LogLevelEvent event)
          Notify the listener that a log level has been unset.
 void levelRemovedImpl(java.lang.String name)
          Notify the listener that a log level has been unset.
 void registrationChanged(de.qfs.lib.config.Configuration config, java.lang.String name, boolean registered, boolean valuesKept)
          This callback is used to notify the Configurable whenever it is registered with or unregistered from the Configuration, so it can decide whether to notify the Configuration when its state changes.
 void removeLogLevel(javax.swing.tree.TreePath path, boolean recurse)
          Remove the log level for a node in the tree.
 void removeTreeModelListener(javax.swing.event.TreeModelListener listener)
          Remove a TreeModelListener from the LogLevelTreeModel.
 void setConfigurableName(java.lang.String name)
          Set the Configurable's name.
 void setConfigurableState(java.util.Properties state)
          Set the Configurable's state.
 void setLoggingEnabled(boolean enable)
          Enable or disable logging output caused directly or indirectly by LogLevelTreeModel methods.
 void setLogLevel(javax.swing.tree.TreePath path, int level)
          Set the log level for a node in the tree.
 void setLogLevelCallback(de.qfs.lib.log.LogLevelCallback callback)
          Sets the LogLevelCallback for the LogLevelListener.
 void setRootName(java.lang.String name)
          Set the name for the root node.
 void update(java.util.Observable obj, java.lang.Object arg)
          Notify the LogLevelTreeModel that one of its Observables has changed.
 void valueForPathChanged(javax.swing.tree.TreePath path, java.lang.Object newValue)
          Update a node.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LogLevelTreeModel

public LogLevelTreeModel()
Create a new LogLevelTreeModel.
Method Detail

cleanup

public void cleanup()
Try to remove everything that might prevent garbage collection.

finalize

public void finalize()
Finalize the LogLevelTreeModel.
Overrides:
finalize in class java.lang.Object

getRootName

public final java.lang.String getRootName()
Get the name for the root node.
Returns:
The root node's name.

setRootName

public final void setRootName(java.lang.String name)
Set the name for the root node.
Parameters:
name - The root node's new name.

setLoggingEnabled

public final void setLoggingEnabled(boolean enable)
Enable or disable logging output caused directly or indirectly by LogLevelTreeModel methods. If logging is disabled, all calls to methods that might create log messages will be protected with de.qfs.lib.log.Log.excludeThread. This is necessary, if the LogFilterTreeModel is used inside the application whose logs it is supposed to filter.

The default value is false.

Parameters:
enable - True to enable logging, false to disable it.

getPath

public java.lang.Object[] getPath(java.lang.String clazz)
Get the path for a node representing a package or class.
Parameters:
clazz - The package/class name.
Returns:
The path for the node or null.

getOptions

public final de.qfs.lib.option.OptionSet getOptions()
Get the options of the LogLevelTreeModel.
Returns:
The LogLevelTreeModel's options.

setLogLevel

public void setLogLevel(javax.swing.tree.TreePath path,
                        int level)
Set the log level for a node in the tree. If the LogLevelCallback has been set, the level will be propagated to it.

This method is not thread safe and must be called from the AWT event loop. The update of the LogLevelCallback is delegated to a background task and will not block the event loop.

Parameters:
path - The TreePath defining the node.
level - The new log level to set.

removeLogLevel

public void removeLogLevel(javax.swing.tree.TreePath path,
                           boolean recurse)
Remove the log level for a node in the tree. If the LogLevelCallback has been set, the modification will be propagated to it.

This method is not thread safe and must be called from the AWT event loop. The update of the LogLevelCallback is delegated to a background task and will not block the event loop.

Parameters:
path - The TreePath defining the node.
recurse - Whether to remove the level on all subnodes.

classAdded

public void classAdded(de.qfs.lib.log.LogLevelEvent event)
Notify the listener that a Logger for a formerly unknown class has requested its log level, adding the class to the log level tree.
Specified by:
classAdded in interface de.qfs.lib.log.LogLevelListener
Parameters:
event - The LogLevelEvent holding the details.

levelChanged

public void levelChanged(de.qfs.lib.log.LogLevelEvent event)
Notify the listener that a log level has been changed.
Specified by:
levelChanged in interface de.qfs.lib.log.LogLevelListener
Parameters:
event - The LogLevelEvent holding the details.

levelChangedImpl

public void levelChangedImpl(java.lang.String name,
                             int level)
Notify the listener that a log level has been changed.
Parameters:
name - The name of the affected class or package.
level - The new log level.

levelRemoved

public void levelRemoved(de.qfs.lib.log.LogLevelEvent event)
Notify the listener that a log level has been unset.
Specified by:
levelRemoved in interface de.qfs.lib.log.LogLevelListener
Parameters:
event - The LogLevelEvent holding the details.

levelRemovedImpl

public void levelRemovedImpl(java.lang.String name)
Notify the listener that a log level has been unset.
Parameters:
name - The name of the affected class or package.

setLogLevelCallback

public void setLogLevelCallback(de.qfs.lib.log.LogLevelCallback callback)
Sets the LogLevelCallback for the LogLevelListener. The callback will immediately be queried for its state and be updated to reflect the current settings of the LogLevelTreeModel.
Specified by:
setLogLevelCallback in interface de.qfs.lib.log.LogLevelListener
Parameters:
callback - The LogLevelCallback to use to change the log levels.

getConfigurableName

public java.lang.String getConfigurableName()
Get the Configurable's name.
Specified by:
getConfigurableName in interface de.qfs.lib.config.Configurable
Returns:
The Configurable's name.

setConfigurableName

public void setConfigurableName(java.lang.String name)
Set the Configurable's name.
Specified by:
setConfigurableName in interface de.qfs.lib.config.Configurable
Parameters:
name - The name to set.

getConfigurableState

public java.util.Properties getConfigurableState()
Get the Configurable's state.
Specified by:
getConfigurableState in interface de.qfs.lib.config.Configurable
Returns:
A Properties object with one property per node with a non-null level.

setConfigurableState

public void setConfigurableState(java.util.Properties state)
Set the Configurable's state.
Specified by:
setConfigurableState in interface de.qfs.lib.config.Configurable
Parameters:
state - The state to set.

registrationChanged

public void registrationChanged(de.qfs.lib.config.Configuration config,
                                java.lang.String name,
                                boolean registered,
                                boolean valuesKept)
This callback is used to notify the Configurable whenever it is registered with or unregistered from the Configuration, so it can decide whether to notify the Configuration when its state changes. This implementation does nothing.
Specified by:
registrationChanged in interface de.qfs.lib.config.Configurable
Parameters:
config - The affected Configuration.
name - The registration name of the Configurable which may be different from the Configurable's name.
registered - True if the Configurable was just registered, false if it was unregistered.
valuesKept - Whether the Configurable's values were kept, if it was just unregistered.

addTreeModelListener

public void addTreeModelListener(javax.swing.event.TreeModelListener listener)
Add a TreeModelListener to the LogLevelTreeModel.
Specified by:
addTreeModelListener in interface javax.swing.tree.TreeModel
Parameters:
listener - The listener to add.

removeTreeModelListener

public void removeTreeModelListener(javax.swing.event.TreeModelListener listener)
Remove a TreeModelListener from the LogLevelTreeModel.
Specified by:
removeTreeModelListener in interface javax.swing.tree.TreeModel
Parameters:
listener - The listener to remove.

getChild

public java.lang.Object getChild(java.lang.Object parent,
                                 int index)
Get a child of a node from the tree.
Specified by:
getChild in interface javax.swing.tree.TreeModel
Parameters:
parent - The parent node.
index - The index of the child in the parent.
Returns:
The child node.

getChildCount

public int getChildCount(java.lang.Object parent)
Get number of children of a node.
Specified by:
getChildCount in interface javax.swing.tree.TreeModel
Parameters:
parent - The parent node.
Returns:
The number of children of the parent node.

getIndexOfChild

public int getIndexOfChild(java.lang.Object parent,
                           java.lang.Object child)
Get the index of node's child.
Specified by:
getIndexOfChild in interface javax.swing.tree.TreeModel
Parameters:
parent - The parent node.
child - The child node.
Returns:
The index of the child node in the param node.

getRoot

public java.lang.Object getRoot()
Get the root node of the tree.
Specified by:
getRoot in interface javax.swing.tree.TreeModel
Returns:
The root node.

isLeaf

public boolean isLeaf(java.lang.Object node)
Determine, whether a node is a leaf.
Specified by:
isLeaf in interface javax.swing.tree.TreeModel
Parameters:
node - The Node to check.
Returns:
True for class nodes, false for package nodes.

valueForPathChanged

public void valueForPathChanged(javax.swing.tree.TreePath path,
                                java.lang.Object newValue)
Update a node. This is a noop, since the tree is not editable.
Specified by:
valueForPathChanged in interface javax.swing.tree.TreeModel
Parameters:
path - The path of the changed node.
newValue - The new value of the node.

fireNodesInserted

public void fireNodesInserted(java.lang.Object[] path,
                              int index)
Tell the TreeModelListeners that a node was inserted.
Parameters:
path - The path of the parent node.
index - The index of the new child.

fireNodesChanged

public void fireNodesChanged(java.lang.Object[] path)
Tell the TreeModelListeners that a node was modified.
Parameters:
path - The path of the modified node.

fireNodeStructureChanged

public void fireNodeStructureChanged(java.lang.Object[] path)
Tell the TreeModelListeners that the structure changed.
Parameters:
path - The path to the root of the structure change.

getClazz

public java.lang.String getClazz(java.lang.Object node)
Get the class/package of a node.
Parameters:
node - The node to query.
Returns:
The clazz/package of the node.

getLevel

public java.lang.Integer getLevel(java.lang.Object node)
Get the level of a node.
Parameters:
node - The node to query.
Returns:
The level of the node.

update

public void update(java.util.Observable obj,
                   java.lang.Object arg)
Notify the LogLevelTreeModel that one of its Observables has changed.
Specified by:
update in interface java.util.Observer
Parameters:
obj - The Observable that changed.
arg - Details about the change.