Class BrowserController
- java.lang.Object
-
- org.opends.guitools.controlpanel.browser.BrowserController
-
- All Implemented Interfaces:
EventListener,TreeExpansionListener,ReferralAuthenticationListener
public class BrowserController extends Object implements TreeExpansionListener, ReferralAuthenticationListener
This is the main class of the LDAP entry browser. It is in charge of updating a tree that is passed as parameter. Every instance of BrowserController is associated with a unique JTree. The different visualization options are passed to BrowserController using some setter and getter methods (the user can specify for instance whether the entries must be sorted or not).
-
-
Field Summary
Fields Modifier and Type Field Description static FilterALL_OBJECTS_FILTERThe filter used to retrieve all the entries.
-
Constructor Summary
Constructors Constructor Description BrowserController(JTree tree, LDAPConnectionPool cpool, IconPool ipool)Constructor of the BrowserController.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddBrowserEventListener(BrowserEventListener l)Add a BrowserEventListener to this controller.TreePathaddNodeUnderRoot(DN nodeDn)Add an LDAP suffix to this controller.TreePathaddSuffix(DN suffixDn, DN parentSuffixDn)Add an LDAP suffix to this controller.voidexpandNode(BasicNode node)Expands node.static intfindChildNode(BasicNode parent, DN childDn)Find a child node matching a given DN.ConnectionWithControlsfindConnectionForDisplayedEntry(BasicNode node)Return the LDAP connection to search the displayed entry (which can be the local or remote entry).ConnectionWithControlsgetConfigurationConnection()Return the connection for accessing the directory configuration.LDAPConnectionPoolgetConnectionPool()Return the connection pool used by this controller.String[]getContainerClasses()Return the array of container classes for this controller.StringgetDisplayAttribute()Returns the attribute used to display the entry.intgetDisplayFlags()Return the display flags.FiltergetFilter()Returns the filter that is being used to search the entries.static booleangetHasSubOrdinates(Entry entry)Returns whether the entry has subordinates or not.IconPoolgetIconPool()Return the icon pool used by this controller.intgetMaxChildren()Return the maximum number of children to display.BrowserNodeInfogetNodeInfoFromPath(TreePath path)Find the BrowserNodeInfo associated to a TreePath and returns the describing IBrowserNodeInfo.NumSubordinateHackergetNumSubordinateHacker()NUMSUBORDINATE HACK Make the hacker public so that RefreshTask can use it.intgetQueueSize()Returns the size of the queue containing the different tasks.static String[]getReferral(SearchResultEntry entry)Returns the value of the 'ref' attribute.JTreegetTree()Return the JTree controlled by this controller.DefaultTreeModelgetTreeModel()The tree model created by the controller and assigned to the JTree.ConnectionWithControlsgetUserDataConnection()Return the connection for accessing the directory user data.booleanhasSuffix(DN suffixDn)Tells whether the given suffix is in the tree or not.booleanisAttributeNameShown()Says whether we are showing the attribute name or not.booleanisAutomaticExpand()Returns whether we are in automatic expand mode.booleanisConfigurationNode(BasicNode node)Returns whether a given node is a configuration node or not.booleanisFollowReferrals()Return true if this controller follows referrals.booleanisShowContainerOnly()Return true if only container entries are displayed.booleanisSorted()Return true if entries are displayed sorted.booleannodeIsExpanded(BasicNode node)Returns true if the node is expanded.voidnotifyAuthDataChanged()Notify this controller that authentication data have changed in the connection pool.TreePathnotifyEntryAdded(BrowserNodeInfo parentInfo, DN newEntryDn)Notify this controller that an entry has been added.voidnotifyEntryChanged(BrowserNodeInfo nodeInfo)Notify this controller that an entry has changed.TreePathnotifyEntryDeleted(BrowserNodeInfo nodeInfo)Notify this controller that a entry has been deleted.TreePathremoveAllUnderRoot()Remove all the suffixes.voidsetAutomaticExpand(boolean automaticExpand)Sets the automatic expand mode.voidsetConnections(ServerDescriptor server, ConnectionWrapper connConfiguration, ConnectionWrapper connUserData)Set the connection for accessing the directory.voidsetContainerClasses(String[] containerClasses)Set the list of container classes and calls startRefresh().voidsetDisplayAttribute(String displayAttribute)Set the display attribute (the attribute that will be used to retrieve the string that will appear in the tree when rendering the node).voidsetDisplayFlags(int flags)Set the display flags and call startRefresh().voidsetFilter(Filter filter)Sets the filter that must be used by the browser controller to retrieve entries.voidsetFollowReferrals(boolean followReferrals)Enable/display the following of referrals.voidsetInspectedNode(BrowserNodeInfo node)Sets which is the inspected node.voidsetMaxChildren(int maxChildren)Sets the maximum number of children to display for a node. 0 if there is no limitvoidsetNumSubordinateHacker(NumSubordinateHacker h)NUMSUBORDINATE HACK Set the hacker.voidsetShowContainerOnly(boolean showContainerOnly)Enable or disable container display and call startRefresh().voidsetSorted(boolean sorted)Enable/disable entry sort.voidstartRefresh(BrowserNodeInfo nodeInfo)Start a refresh from the specified node.voidtreeCollapsed(TreeExpansionEvent event)For BrowserController private use.voidtreeExpanded(TreeExpansionEvent event)For BrowserController private use.
-
-
-
Field Detail
-
ALL_OBJECTS_FILTER
public static final Filter ALL_OBJECTS_FILTER
The filter used to retrieve all the entries.
-
-
Constructor Detail
-
BrowserController
public BrowserController(JTree tree, LDAPConnectionPool cpool, IconPool ipool)
Constructor of the BrowserController.- Parameters:
tree- the tree that must be updated.cpool- the connection pool object that will provide the connections to be used.ipool- the icon pool to be used to retrieve the icons that will be used to render the nodes in the tree.
-
-
Method Detail
-
setConnections
public void setConnections(ServerDescriptor server, ConnectionWrapper connConfiguration, ConnectionWrapper connUserData)
Set the connection for accessing the directory. Since we must use different controls when searching the configuration and the user data, two connections must be provided (this is done to avoid synchronization issues). We also pass the server descriptor corresponding to the connections to have a proper rendering of the root node.- Parameters:
server- the server descriptor.connConfiguration- the connection to be used to retrieve the data in the configuration base DNs.connUserData- the connection to be used to retrieve the data in the user base DNs.
-
getConfigurationConnection
public ConnectionWithControls getConfigurationConnection()
Return the connection for accessing the directory configuration.- Returns:
- the connection for accessing the directory configuration.
-
getUserDataConnection
public ConnectionWithControls getUserDataConnection()
Return the connection for accessing the directory user data.- Returns:
- the connection for accessing the directory user data.
-
getTree
public JTree getTree()
Return the JTree controlled by this controller.- Returns:
- the JTree controlled by this controller.
-
getConnectionPool
public LDAPConnectionPool getConnectionPool()
Return the connection pool used by this controller. If a client class adds authentication to the connection pool, it must inform the controller by calling notifyAuthDataChanged().- Returns:
- the connection pool used by this controller.
-
getIconPool
public IconPool getIconPool()
Return the icon pool used by this controller.- Returns:
- the icon pool used by this controller.
-
hasSuffix
public boolean hasSuffix(DN suffixDn) throws IllegalArgumentException
Tells whether the given suffix is in the tree or not.- Parameters:
suffixDn- the DN of the suffix to be analyzed.- Returns:
trueif the provided String is the DN of a suffix andfalseotherwise.- Throws:
IllegalArgumentException- if a node with the given dn exists but is not a suffix node.
-
addSuffix
public TreePath addSuffix(DN suffixDn, DN parentSuffixDn) throws IllegalArgumentException
Add an LDAP suffix to this controller. A new node is added in the JTree and a refresh is started.- Parameters:
suffixDn- the DN of the suffix.parentSuffixDn- the DN of the parent suffix (ornullif there is no parent DN).- Returns:
- the TreePath of the new node.
- Throws:
IllegalArgumentException- if a node with the given dn exists.
-
addNodeUnderRoot
public TreePath addNodeUnderRoot(DN nodeDn)
Add an LDAP suffix to this controller. A new node is added in the JTree and a refresh is started.- Parameters:
nodeDn- the DN of the node to be added.- Returns:
- the TreePath of the new node.
-
removeAllUnderRoot
public TreePath removeAllUnderRoot()
Remove all the suffixes. The controller removes all the nodes from the JTree except the root.- Returns:
- the TreePath of the root node.
-
getDisplayFlags
public int getDisplayFlags()
Return the display flags.- Returns:
- the display flags.
-
setDisplayFlags
public void setDisplayFlags(int flags)
Set the display flags and call startRefresh().- Parameters:
flags- the display flags to be set.
-
setDisplayAttribute
public void setDisplayAttribute(String displayAttribute)
Set the display attribute (the attribute that will be used to retrieve the string that will appear in the tree when rendering the node). This routine collapses the JTree and invokes startRefresh().- Parameters:
displayAttribute- the display attribute to be used.
-
getDisplayAttribute
public String getDisplayAttribute()
Returns the attribute used to display the entry. RDN_ATTRIBUTE is the rdn is used.- Returns:
- the attribute used to display the entry.
-
isAttributeNameShown
public boolean isAttributeNameShown()
Says whether we are showing the attribute name or not.- Returns:
trueif we are showing the attribute name andfalseotherwise.
-
setMaxChildren
public void setMaxChildren(int maxChildren)
Sets the maximum number of children to display for a node. 0 if there is no limit- Parameters:
maxChildren- the maximum number of children to display for a node.
-
getMaxChildren
public int getMaxChildren()
Return the maximum number of children to display.- Returns:
- the maximum number of children to display.
-
isFollowReferrals
public boolean isFollowReferrals()
Return true if this controller follows referrals.- Returns:
trueif this controller follows referrals,falseotherwise.
-
setFollowReferrals
public void setFollowReferrals(boolean followReferrals)
Enable/display the following of referrals. This routine starts a refresh on each referral node.- Parameters:
followReferrals- whether to follow referrals or not.
-
isSorted
public boolean isSorted()
Return true if entries are displayed sorted.- Returns:
trueif entries are displayed sorted,falseotherwise.
-
setSorted
public void setSorted(boolean sorted)
Enable/disable entry sort. This routine collapses the JTree and invokes startRefresh().- Parameters:
sorted- whether to sort the entries or not.
-
isShowContainerOnly
public boolean isShowContainerOnly()
Return true if only container entries are displayed. An entry is a container if: - it has some children - or its class is one of the container classes specified with setContainerClasses().- Returns:
trueif only container entries are displayed andfalseotherwise.
-
setShowContainerOnly
public void setShowContainerOnly(boolean showContainerOnly)
Enable or disable container display and call startRefresh().- Parameters:
showContainerOnly- whether to display only containers or all the entries.
-
getNodeInfoFromPath
public BrowserNodeInfo getNodeInfoFromPath(TreePath path)
Find the BrowserNodeInfo associated to a TreePath and returns the describing IBrowserNodeInfo.- Parameters:
path- the TreePath associated with the node we are searching.- Returns:
- the BrowserNodeInfo associated to the TreePath.
-
getContainerClasses
public String[] getContainerClasses()
Return the array of container classes for this controller. Warning: the returned array is not cloned.- Returns:
- the array of container classes for this controller.
-
setContainerClasses
public void setContainerClasses(String[] containerClasses)
Set the list of container classes and calls startRefresh(). Warning: the array is not cloned.- Parameters:
containerClasses- the lis of container classes.
-
getNumSubordinateHacker
public NumSubordinateHacker getNumSubordinateHacker()
NUMSUBORDINATE HACK Make the hacker public so that RefreshTask can use it.- Returns:
- the NumSubordinateHacker object used by the controller.
-
setNumSubordinateHacker
public void setNumSubordinateHacker(NumSubordinateHacker h)
NUMSUBORDINATE HACK Set the hacker. Note this method does not trigger any refresh. The caller is supposed to do it afterward.- Parameters:
h- the NumSubordinateHacker.
-
addBrowserEventListener
public void addBrowserEventListener(BrowserEventListener l)
Add a BrowserEventListener to this controller.- Parameters:
l- the listener to be added.
-
notifyEntryAdded
public TreePath notifyEntryAdded(BrowserNodeInfo parentInfo, DN newEntryDn)
Notify this controller that an entry has been added. The controller adds a new node in the JTree and starts refreshing this new node. This routine returns the tree path about the new entry.- Parameters:
parentInfo- the parent node of the entry added.newEntryDn- the dn of the entry to be added.- Returns:
- the tree path associated with the new entry.
-
notifyEntryDeleted
public TreePath notifyEntryDeleted(BrowserNodeInfo nodeInfo)
Notify this controller that a entry has been deleted. The controller removes the corresponding node from the JTree and returns the TreePath of the parent node.- Parameters:
nodeInfo- the node to be deleted.- Returns:
- the tree path associated with the parent of the deleted node.
-
notifyEntryChanged
public void notifyEntryChanged(BrowserNodeInfo nodeInfo)
Notify this controller that an entry has changed. The controller starts refreshing the corresponding node. Child nodes are not refreshed.- Parameters:
nodeInfo- the node that changed.
-
notifyAuthDataChanged
public void notifyAuthDataChanged()
Notify this controller that authentication data have changed in the connection pool.- Specified by:
notifyAuthDataChangedin interfaceReferralAuthenticationListener
-
startRefresh
public void startRefresh(BrowserNodeInfo nodeInfo)
Start a refresh from the specified node. If some refresh are on-going on descendant nodes, they are stopped. If nodeInfo is null, refresh is started from the root.- Parameters:
nodeInfo- the node to be refreshed.
-
treeExpanded
public void treeExpanded(TreeExpansionEvent event)
For BrowserController private use. When a node is expanded, refresh it if it needs it (to search the children for instance).- Specified by:
treeExpandedin interfaceTreeExpansionListener- Parameters:
event- the tree expansion event.
-
treeCollapsed
public void treeCollapsed(TreeExpansionEvent event)
For BrowserController private use. When a node is collapsed the refresh tasks on it are canceled.- Specified by:
treeCollapsedin interfaceTreeExpansionListener- Parameters:
event- the tree collapse event.
-
setInspectedNode
public void setInspectedNode(BrowserNodeInfo node)
Sets which is the inspected node. This method simply marks the selected node in the tree so that it can have a different rendering. This is useful for instance when the right panel has a list of entries to which the menu action apply, to make a difference between the selected node in the tree (to which the action in the main menu will not apply) and the selected nodes in the right pane.- Parameters:
node- the selected node.
-
getTreeModel
public DefaultTreeModel getTreeModel()
The tree model created by the controller and assigned to the JTree.- Returns:
- the tree model.
-
setFilter
public void setFilter(Filter filter)
Sets the filter that must be used by the browser controller to retrieve entries.- Parameters:
filter- the LDAP filter.
-
getFilter
public Filter getFilter()
Returns the filter that is being used to search the entries.- Returns:
- the filter that is being used to search the entries.
-
isConfigurationNode
public boolean isConfigurationNode(BasicNode node)
Returns whether a given node is a configuration node or not.- Parameters:
node- the node to analyze.- Returns:
trueif the node is a configuration node,falseotherwise.
-
findConnectionForDisplayedEntry
public ConnectionWithControls findConnectionForDisplayedEntry(BasicNode node) throws LdapException
Return the LDAP connection to search the displayed entry (which can be the local or remote entry).- Parameters:
node- the node for which we want toe LDAP connection.- Returns:
- the LDAP connection to search the displayed entry.
- Throws:
LdapException- if there is an error retrieving the connection.
-
findChildNode
public static int findChildNode(BasicNode parent, DN childDn)
Find a child node matching a given DN. result >= 0 result is the index of the node matching childDn. result < 0 -(result + 1) is the index at which the new node must be inserted.- Parameters:
parent- the parent node of the node that is being searched.childDn- the DN of the entry that is being searched.- Returns:
- the index of the node matching childDn.
-
getQueueSize
public int getQueueSize()
Returns the size of the queue containing the different tasks. It can be used to know if there are search operations ongoing.- Returns:
- the number of RefreshTask operations ongoing (or waiting to start).
-
getHasSubOrdinates
public static boolean getHasSubOrdinates(Entry entry)
Returns whether the entry has subordinates or not. It uses an algorithm based in hasSubordinates and numSubordinates attributes.- Parameters:
entry- the entry to analyze.- Returns:
trueif the entry has subordinates according to the values of hasSubordinates and numSubordinates, returnsfalseif none of the attributes could be found.
-
getReferral
public static String[] getReferral(SearchResultEntry entry)
Returns the value of the 'ref' attribute.nullif the attribute is not present.- Parameters:
entry- the entry to analyze.- Returns:
- the value of the ref attribute.
nullif the attribute could not be found.
-
nodeIsExpanded
public boolean nodeIsExpanded(BasicNode node)
Returns true if the node is expanded.- Parameters:
node- the node to analyze.- Returns:
trueif the node is expanded andfalseotherwise.
-
expandNode
public void expandNode(BasicNode node)
Expands node. Must be run from the event thread. This is called when the node is automatically expanded.- Parameters:
node- the node to expand.
-
isAutomaticExpand
public boolean isAutomaticExpand()
Returns whether we are in automatic expand mode. This mode is used when the user specifies a filter and all the nodes are automatically expanded.- Returns:
trueif we are in automatic expand mode andfalseotherwise.
-
setAutomaticExpand
public void setAutomaticExpand(boolean automaticExpand)
Sets the automatic expand mode.- Parameters:
automaticExpand- whether to expand automatically the nodes or not.
-
-