From 149df264fb7c9c37e6439d00cc33613f57448ac1 Mon Sep 17 00:00:00 2001
From: Jean-Noël Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Wed, 03 Aug 2016 09:43:06 +0000
Subject: [PATCH] code cleanups
---
opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/browser/BrowserController.java | 314 ++++++++++++++++++++--------------------------------
1 files changed, 120 insertions(+), 194 deletions(-)
diff --git a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/browser/BrowserController.java b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/browser/BrowserController.java
index afa6800..64597f9 100644
--- a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/browser/BrowserController.java
+++ b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/browser/BrowserController.java
@@ -165,7 +165,6 @@
numSubordinateHacker = new NumSubordinateHacker();
}
-
/**
* Set the connection for accessing the directory. Since we must use
* different controls when searching the configuration and the user data,
@@ -200,7 +199,6 @@
startRefresh(null);
}
-
/**
* Return the connection for accessing the directory configuration.
* @return the connection for accessing the directory configuration.
@@ -217,7 +215,6 @@
return connUserData;
}
-
/**
* Return the JTree controlled by this controller.
* @return the JTree controlled by this controller.
@@ -226,7 +223,6 @@
return tree;
}
-
/**
* Return the connection pool used by this controller.
* If a client class adds authentication to the connection
@@ -248,8 +244,8 @@
/**
* Tells whether the given suffix is in the tree or not.
* @param suffixDn the DN of the suffix to be analyzed.
- * @return <CODE>true</CODE> if the provided String is the DN of a suffix
- * and <CODE>false</CODE> otherwise.
+ * @return {@code true} if the provided String is the DN of a suffix
+ * and {@code false} otherwise.
* @throws IllegalArgumentException if a node with the given dn exists but
* is not a suffix node.
*/
@@ -262,7 +258,7 @@
* Add an LDAP suffix to this controller.
* A new node is added in the JTree and a refresh is started.
* @param suffixDn the DN of the suffix.
- * @param parentSuffixDn the DN of the parent suffix (or <CODE>null</CODE> if
+ * @param parentSuffixDn the DN of the parent suffix (or {@code null} if
* there is no parent DN).
* @return the TreePath of the new node.
* @throws IllegalArgumentException if a node with the given dn exists.
@@ -313,7 +309,6 @@
return new TreePath(treeModel.getPathToRoot(newNode));
}
-
/**
* Remove all the suffixes.
* The controller removes all the nodes from the JTree except the root.
@@ -325,7 +320,6 @@
return new TreePath(treeModel.getPathToRoot(rootNode));
}
-
/**
* Return the display flags.
* @return the display flags.
@@ -334,7 +328,6 @@
return displayFlags;
}
-
/**
* Set the display flags and call startRefresh().
* @param flags the display flags to be set.
@@ -368,8 +361,8 @@
/**
* Says whether we are showing the attribute name or not.
- * @return <CODE>true</CODE> if we are showing the attribute name and
- * <CODE>false</CODE> otherwise.
+ * @return {@code true} if we are showing the attribute name and
+ * {@code false} otherwise.
*/
public boolean isAttributeNameShown() {
return showAttributeName;
@@ -394,14 +387,13 @@
/**
* Return true if this controller follows referrals.
- * @return <CODE>true</CODE> if this controller follows referrals and
- * <CODE>false</CODE> otherwise.
+ * @return {@code true} if this controller follows referrals and
+ * {@code false} otherwise.
*/
public boolean getFollowReferrals() {
return followReferrals;
}
-
/**
* Enable/display the following of referrals.
* This routine starts a refresh on each referral node.
@@ -420,17 +412,15 @@
startRefresh(null);
}
-
/**
* Return true if entries are displayed sorted.
- * @return <CODE>true</CODE> if entries are displayed sorted and
- * <CODE>false</CODE> otherwise.
+ * @return {@code true} if entries are displayed sorted and
+ * {@code false} otherwise.
*/
public boolean isSorted() {
return sorted;
}
-
/**
* Enable/disable entry sort.
* This routine collapses the JTree and invokes startRefresh().
@@ -448,21 +438,19 @@
startRefresh(null);
}
-
/**
* 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().
- * @return <CODE>true</CODE> if only container entries are displayed and
- * <CODE>false</CODE> otherwise.
+ * @return {@code true} if only container entries are displayed and
+ * {@code false} otherwise.
*/
public boolean isShowContainerOnly() {
return showContainerOnly;
}
-
/**
* Enable or disable container display and call startRefresh().
* @param showContainerOnly whether to display only containers or all the
@@ -473,7 +461,6 @@
startRefresh(null);
}
-
/**
* Find the BrowserNodeInfo associated to a TreePath and returns
* the describing IBrowserNodeInfo.
@@ -485,7 +472,6 @@
return new BrowserNodeInfoImpl(node);
}
-
/**
* Return the array of container classes for this controller.
* Warning: the returned array is not cloned.
@@ -495,7 +481,6 @@
return containerClasses;
}
-
/**
* Set the list of container classes and calls startRefresh().
* Warning: the array is not cloned.
@@ -506,7 +491,6 @@
startRefresh(null);
}
-
/**
* NUMSUBORDINATE HACK
* Make the hacker public so that RefreshTask can use it.
@@ -516,7 +500,6 @@
return numSubordinateHacker;
}
-
/**
* NUMSUBORDINATE HACK
* Set the hacker. Note this method does not trigger any
@@ -568,7 +551,6 @@
return new TreePath(treeModel.getPathToRoot(childNode));
}
-
/**
* Notify this controller that a entry has been deleted.
* The controller removes the corresponding node from the JTree and returns
@@ -591,7 +573,6 @@
return null;
}
-
/**
* Notify this controller that an entry has changed.
* The controller starts refreshing the corresponding node.
@@ -625,7 +606,6 @@
startRefreshReferralNodes(rootNode);
}
-
/**
* Start a refresh from the specified node.
* If some refresh are on-going on descendant nodes, they are stopped.
@@ -633,13 +613,7 @@
* @param nodeInfo the node to be refreshed.
*/
public void startRefresh(BrowserNodeInfo nodeInfo) {
- BasicNode node;
- if (nodeInfo == null) {
- node = rootNode;
- }
- else {
- node = nodeInfo.getNode();
- }
+ BasicNode node = nodeInfo != null ? nodeInfo.getNode() : rootNode;
stopRefreshNode(node);
startRefreshNode(node, null, true);
}
@@ -690,9 +664,6 @@
}
}
-
-
-
/**
* Stop refreshing below this node.
* TODO: this method is very costly when applied to something else than the
@@ -713,8 +684,6 @@
}
}
-
-
/**
* Call startRefreshNode() on each referral node accessible from parentNode.
* @param parentNode the parent node.
@@ -732,8 +701,6 @@
}
}
-
-
/**
* Remove all the children below parentNode *without changing the leaf state*.
* If specified, it keeps the SuffixNode and recurses on them. Inform the tree
@@ -774,7 +741,6 @@
}
}
-
/**
* For BrowserController private use. When a node is collapsed the refresh
* tasks on it are canceled.
@@ -808,15 +774,10 @@
* @param node the selected node.
*/
public void setInspectedNode(BrowserNodeInfo node) {
- BrowserCellRenderer renderer = (BrowserCellRenderer)tree.getCellRenderer();
- if (node == null) {
- renderer.setInspectedNode(null);
- } else {
- renderer.setInspectedNode(node.getNode());
- }
+ BrowserCellRenderer renderer = (BrowserCellRenderer) tree.getCellRenderer();
+ renderer.setInspectedNode(node != null ? node.getNode() : null);
}
-
/**
* Routines for the task classes
* =============================
@@ -826,7 +787,6 @@
* called by task threads without synchronize clauses.
*/
-
/**
* The tree model created by the controller and assigned
* to the JTree.
@@ -864,7 +824,6 @@
return ALL_OBJECTS_FILTER;
}
-
/**
* Return the LDAP search filter to use for searching child entries.
* If showContainerOnly is true, the filter will select only the
@@ -910,9 +869,6 @@
return result;
}
-
-
-
/**
* Return the LDAP connection to reading the base entry of a node.
* @param node the node for which we want the LDAP connection.
@@ -949,8 +905,8 @@
/**
* Returns whether a given node is a configuration node or not.
* @param node the node to analyze.
- * @return <CODE>true</CODE> if the node is a configuration node and
- * <CODE>false</CODE> otherwise.
+ * @return {@code true} if the node is a configuration node and
+ * {@code false} otherwise.
*/
public boolean isConfigurationNode(BasicNode node)
{
@@ -989,7 +945,6 @@
return findConnectionForDisplayedEntry(node, isConfigurationNode(node));
}
-
/**
* Return the LDAP connection to search the displayed entry (which can be the
* local or remote entry).
@@ -1007,8 +962,6 @@
return findConnectionForLocalEntry(node, isConfigurationNode);
}
-
-
/**
* Release a connection returned by selectConnectionForChildEntries() or
* selectConnectionForBaseEntry().
@@ -1022,7 +975,6 @@
}
}
-
/**
* Returns the local entry URL for a given node.
* @param node the node.
@@ -1041,7 +993,6 @@
return LDAPConnectionPool.makeLDAPUrl(connConfig.getHostPort(), node.getDN(), connConfig.isLdaps());
}
-
/**
* Returns the displayed entry URL for a given node.
* @param node the node.
@@ -1055,7 +1006,6 @@
return findUrlForLocalEntry(node);
}
-
/**
* Returns the DN to use for searching children of a given node.
* In most cases, it's node.getDN(). However if node has referral data
@@ -1072,13 +1022,11 @@
return node.getDN();
}
-
-
/**
* Tells whether a node is displaying a remote entry.
* @param node the node.
- * @return <CODE>true</CODE> if the node displays a remote entry and
- * <CODE>false</CODE> otherwise.
+ * @return {@code true} if the node displays a remote entry and
+ * {@code false} otherwise.
*/
private boolean isDisplayedEntryRemote(BasicNode node) {
if (followReferrals) {
@@ -1096,7 +1044,6 @@
return false;
}
-
/**
* Returns the list of attributes for the red search.
* @return the list of attributes for the red search.
@@ -1200,7 +1147,6 @@
return getRequestControls();
}
-
/**
* Callbacks invoked by task classes
* =================================
@@ -1278,14 +1224,12 @@
}
else if (newState == NodeRefresher.State.CANCELLED ||
newState == NodeRefresher.State.INTERRUPTED) {
-
// Let's collapse task.getNode()
tree.collapsePath(new TreePath(treeModel.getPathToRoot(node)));
// TODO: should we reflect this situation visually ?
}
else {
-
if (oldState != NodeRefresher.State.SEARCHING_CHILDREN
&& newState == NodeRefresher.State.SEARCHING_CHILDREN) {
// The children search is going to start
@@ -1326,7 +1270,6 @@
}
}
else if (oldState == NodeRefresher.State.SEARCHING_CHILDREN) {
-
updateChildNodes(task);
if (newState == NodeRefresher.State.FINISHED) {
// The children search is finished
@@ -1359,7 +1302,6 @@
}
}
-
if (nodeChanged) {
treeModel.nodeChanged(task.getNode());
}
@@ -1369,7 +1311,6 @@
}
}
-
/**
* Commodity method that calls the method refreshTaskDidProgress in the event
* thread.
@@ -1427,19 +1368,16 @@
// Walk through the entries
for (SearchResultEntry entry : task.getChildEntries())
{
- BasicNode child;
-
// Search a child node matching the DN of the entry
int index;
if (differential) {
-// System.out.println("Differential mode -> starting to search");
index = findChildNode(parent, entry.getName().toString());
-// System.out.println("Differential mode -> ending to search");
}
else {
index = - (parent.getChildCount() + 1);
}
+ BasicNode child;
// If no node matches, we create a new node
if (index < 0) {
// -(index + 1) is the location where to insert the new node
@@ -1448,7 +1386,6 @@
parent.insert(child, index);
updateNodeRendering(child, entry);
insertIndex.add(index);
-// System.out.println("Inserted " + child.getDN() + " at " + index);
}
else { // Else we update the existing one
child = (BasicNode)parent.getChildAt(index);
@@ -1473,25 +1410,19 @@
hasNoSubOrdinates = !child.hasSubOrdinates();
}
-
-
// Propagate the refresh
// Note: logically we should unconditionally call:
// startRefreshNode(child, false, true);
//
- // However doing that saturates refreshQueue
- // with many nodes. And, by design, RefreshTask
- // won't do anything on a node if:
+ // However doing that saturates refreshQueue with many nodes.
+ // And, by design, RefreshTask won't do anything on a node if:
// - this node has no subordinates
// - *and* this node has no referral data
- // So we test these conditions here and
- // skip the call to startRefreshNode() if
- // possible.
+ // So we test these conditions here
+ // and skip the call to startRefreshNode() if possible.
//
- // The exception to this is the case where the
- // node had children (in the tree). In this case
- // we force the refresh. See bug 5015115
- //
+ // The exception to this is the case where the node had children
+ // (in the tree). In this case we force the refresh. See bug 5015115
if (!hasNoSubOrdinates
|| child.getReferral() != null
|| child.getChildCount() > 0) {
@@ -1499,7 +1430,6 @@
}
}
-
// Inform the tree model that we have created some new nodes
if (insertIndex.size() >= 1) {
treeModel.nodesWereInserted(parent, intArrayFromCollection(insertIndex));
@@ -1509,26 +1439,24 @@
}
}
-
-
/**
* Tells whether a differential update can be made in the provided task.
* @param task the task.
- * @return <CODE>true</CODE> if a differential update can be made and
- * <CODE>false</CODE> otherwise.
+ * @return {@code true} if a differential update can be made and
+ * {@code false} otherwise.
*/
private boolean canDoDifferentialUpdate(NodeRefresher task) {
return task.getNode().getChildCount() >= 1
&& task.getNode().getNumSubOrdinates() <= 100;
}
-
/**
* Recompute the rendering props of a node (text, style, icon) depending on.
* - the state of this node
* - the LDAPEntry displayed by this node
* @param node the node to be rendered.
* @param entry the search result for the entry that the node represents.
+ * @return whether the node display changed
*/
private boolean updateNodeRendering(BasicNode node, SearchResultEntry entry)
throws NamingException {
@@ -1545,58 +1473,7 @@
Icon newIcon = getNewIcon(node, entry);
// Construct the icon text according the dn, the aci count...
- StringBuilder sb2 = new StringBuilder();
- if (aciCount >= 1) {
- sb2.append(aciCount);
- sb2.append(" aci");
- if (aciCount != 1) {
- sb2.append("s");
- }
- }
-
- StringBuilder sb1 = new StringBuilder();
- if (node instanceof SuffixNode) {
- if (entry != null) {
- sb1.append(entry.getName());
- }
- } else {
- boolean useRdn = true;
- if (!RDN_ATTRIBUTE.equals(displayAttribute) && entry != null) {
- String value = firstValueAsString(entry, displayAttribute);
- if (value != null) {
- if (showAttributeName) {
- value = displayAttribute+"="+value;
- }
- sb1.append(value);
- useRdn = false;
- }
- }
-
- if (useRdn) {
- String rdn;
- if (followReferrals && node.getRemoteUrl() != null) {
- if (showAttributeName) {
- rdn = node.getRemoteRDNWithAttributeName();
- } else {
- rdn = node.getRemoteRDN();
- }
- }
- else {
- if (showAttributeName) {
- rdn = node.getRDNWithAttributeName();
- } else {
- rdn = node.getRDN();
- }
- }
- sb1.append(rdn);
- }
- }
- if (sb2.length() >= 1) {
- sb1.append(" (");
- sb1.append(sb2);
- sb1.append(")");
- }
- String newDisplayName = sb1.toString();
+ String newDisplayName = newDisplayName(node, entry, aciCount);
// Select the font style according referral
int newStyle = 0;
@@ -1613,8 +1490,79 @@
node.setIcon(newIcon);
node.setDisplayName(newDisplayName);
node.setFontStyle(newStyle);
+ return true;
}
- return changed;
+ return false;
+ }
+
+ private String newDisplayName(BasicNode node, SearchResultEntry entry, int aciCount)
+ {
+ StringBuilder result = new StringBuilder();
+ if (node instanceof SuffixNode)
+ {
+ if (entry != null)
+ {
+ result.append(entry.getName());
+ }
+ }
+ else
+ {
+ boolean useRdn = true;
+ if (!RDN_ATTRIBUTE.equals(displayAttribute) && entry != null)
+ {
+ String value = firstValueAsString(entry, displayAttribute);
+ if (value != null)
+ {
+ if (showAttributeName)
+ {
+ value = displayAttribute + "=" + value;
+ }
+ result.append(value);
+ useRdn = false;
+ }
+ }
+
+ if (useRdn)
+ {
+ result.append(getRDN(node));
+ }
+ }
+
+ StringBuilder acis = new StringBuilder();
+ if (aciCount >= 1)
+ {
+ acis.append(aciCount);
+ acis.append(" aci");
+ if (aciCount != 1)
+ {
+ acis.append("s");
+ }
+ }
+ if (acis.length() >= 1)
+ {
+ result.append(" (");
+ result.append(acis);
+ result.append(")");
+ }
+ return result.toString();
+ }
+
+ private String getRDN(BasicNode node)
+ {
+ if (followReferrals && node.getRemoteUrl() != null) {
+ if (showAttributeName) {
+ return node.getRemoteRDNWithAttributeName();
+ } else {
+ return node.getRemoteRDN();
+ }
+ }
+ else {
+ if (showAttributeName) {
+ return node.getRDNWithAttributeName();
+ } else {
+ return node.getRDN();
+ }
+ }
}
private int getAciCount(SearchResultEntry entry) throws NamingException
@@ -1625,7 +1573,6 @@
return 0;
}
-
private Icon getNewIcon(BasicNode node, SearchResultEntry entry)
{
// Select the icon according the objectClass,...
@@ -1690,7 +1637,6 @@
treeModel.removeNodeFromParent(node);
}
-
/**
* BrowserEvent management
* =======================
@@ -1730,7 +1676,6 @@
return refreshQueue.size();
}
-
/**
* Fires a BrowserEvent.
* @param type the type of the event.
@@ -1754,7 +1699,7 @@
* Find a SuffixNode in the tree model.
* @param suffixDn the dn of the suffix node.
* @param suffixNode the node from which we start searching.
- * @return the SuffixNode associated with the provided DN. <CODE>null</CODE>
+ * @return the SuffixNode associated with the provided DN. {@code null}
* if nothing is found.
* @throws IllegalArgumentException if a node with the given dn exists but
* is not a suffix node.
@@ -1799,20 +1744,14 @@
throw new IllegalArgumentException(suffixDn + " is not a suffix node");
}
-
-
/**
- * Return <CODE>true</CODE> if x is a non <code>null</code>
- * NameNotFoundException.
- * @return <CODE>true</CODE> if x is a non <code>null</code>
- * NameNotFoundException.
+ * Return {@code true} if x is a non {@code null} NameNotFoundException.
+ * @return {@code true} if x is a non {@code null} NameNotFoundException.
*/
private boolean isNameNotFoundException(Object x) {
return x instanceof NameNotFoundException;
}
-
-
/**
* Get the value of the numSubordinates attribute.
* If numSubordinates is not present, returns 0.
@@ -1863,7 +1802,6 @@
return toInt(v);
}
-
private static int toInt(String v)
{
if (v == null)
@@ -1903,13 +1841,12 @@
return getNumSubOrdinates(entry) > 0;
}
-
/**
* Returns the value of the 'ref' attribute.
- * <CODE>null</CODE> if the attribute is not present.
+ * {@code null} if the attribute is not present.
* @param entry the entry to analyze.
* @throws NamingException if an error occurs.
- * @return the value of the ref attribute. <CODE>null</CODE> if the attribute
+ * @return the value of the ref attribute. {@code null} if the attribute
* could not be found.
*/
public static String[] getReferral(SearchResultEntry entry) throws NamingException
@@ -1926,12 +1863,10 @@
return null;
}
-
/**
* Returns true if the node is expanded.
* @param node the node to analyze.
- * @return <CODE>true</CODE> if the node is expanded and <CODE>false</CODE>
- * otherwise.
+ * @return {@code true} if the node is expanded and {@code false} otherwise.
*/
public boolean nodeIsExpanded(BasicNode node) {
TreePath tp = new TreePath(treeModel.getPathToRoot(node));
@@ -1951,8 +1886,6 @@
automaticallyExpandedNode = false;
}
-
-
/** Collection utilities. */
/**
* Returns an array of integer from a Collection of Integer objects.
@@ -1970,7 +1903,6 @@
return result;
}
-
/**
* For debugging purpose: allows to switch easily
* between invokeLater() and invokeAndWait() for
@@ -1991,7 +1923,6 @@
}
}
-
/** The default implementation of the BrowserNodeInfo interface. */
private class BrowserNodeInfoImpl implements BrowserNodeInfo
{
@@ -2071,8 +2002,7 @@
/**
* Tells whether this is a root node or not.
- * @return <CODE>true</CODE> if this is a root node and <CODE>false</CODE>
- * otherwise.
+ * @return {@code true} if this is a root node and {@code false} otherwise.
*/
@Override
public boolean isRootNode() {
@@ -2081,8 +2011,7 @@
/**
* Tells whether this is a suffix node or not.
- * @return <CODE>true</CODE> if this is a suffix node and <CODE>false</CODE>
- * otherwise.
+ * @return {@code true} if this is a suffix node and {@code false} otherwise.
*/
@Override
public boolean isSuffix() {
@@ -2091,8 +2020,7 @@
/**
* Tells whether this is a remote node or not.
- * @return <CODE>true</CODE> if this is a remote node and <CODE>false</CODE>
- * otherwise.
+ * @return {@code true} if this is a remote node and {@code false} otherwise.
*/
@Override
public boolean isRemote() {
@@ -2131,9 +2059,9 @@
/**
* Returns the error type associated we got when refreshing the node.
- * <CODE>null</CODE> if no error was found.
+ * {@code null} if no error was found.
* @return the error type associated we got when refreshing the node.
- * <CODE>null</CODE> if no error was found.
+ * {@code null} if no error was found.
*/
@Override
public int getErrorType() {
@@ -2142,9 +2070,9 @@
/**
* Returns the exception associated we got when refreshing the node.
- * <CODE>null</CODE> if no exception was found.
+ * {@code null} if no exception was found.
* @return the exception associated we got when refreshing the node.
- * <CODE>null</CODE> if no exception was found.
+ * {@code null} if no exception was found.
*/
@Override
public Exception getErrorException() {
@@ -2153,9 +2081,9 @@
/**
* Returns the error argument associated we got when refreshing the node.
- * <CODE>null</CODE> if no error argument was found.
+ * {@code null} if no error argument was found.
* @return the error argument associated we got when refreshing the node.
- * <CODE>null</CODE> if no error argument was found.
+ * {@code null} if no error argument was found.
*/
@Override
public Object getErrorArg() {
@@ -2192,8 +2120,8 @@
/**
* Compares the provide node with this object.
* @param node the node.
- * @return <CODE>true</CODE> if the node info represents the same node as
- * this and <CODE>false</CODE> otherwise.
+ * @return {@code true} if the node info represents the same node as
+ * this and {@code false} otherwise.
*/
@Override
public boolean representsSameNode(BrowserNodeInfo node) {
@@ -2201,19 +2129,17 @@
}
}
-
/**
* 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.
- * @return <CODE>true</CODE> if we are in automatic expand mode and
- * <CODE>false</CODE> otherwise.
+ * @return {@code true} if we are in automatic expand mode and
+ * {@code false} otherwise.
*/
public boolean isAutomaticExpand()
{
return automaticExpand;
}
-
/**
* Sets the automatic expand mode.
* @param automaticExpand whether to expand automatically the nodes or not.
--
Gitblit v1.10.0