From ad85b8dfd8775fa342dcf6d0deaa380be53d080f Mon Sep 17 00:00:00 2001
From: Jean-Noel Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Mon, 20 Apr 2015 09:32:50 +0000
Subject: [PATCH] Code cleanup: Extracted methods, used ternary operator.
---
opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/StatusGenericPanel.java | 58 ++++++++++++++++++++++++++++++++--------------------------
1 files changed, 32 insertions(+), 26 deletions(-)
diff --git a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/StatusGenericPanel.java b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/StatusGenericPanel.java
index 4a5ba6e..cf491c1 100644
--- a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/StatusGenericPanel.java
+++ b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/StatusGenericPanel.java
@@ -59,6 +59,7 @@
import javax.naming.directory.SearchControls;
import javax.naming.directory.SearchResult;
import javax.swing.Box;
+import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JComboBox;
import javax.swing.JComponent;
@@ -792,16 +793,7 @@
{
if (selectedItem == null)
{
- // Look for the first element that is not a category
- for (int i = 0; i < combo.getModel().getSize(); i++)
- {
- Object item = combo.getModel().getElementAt(i);
- if (item instanceof CategorizedComboBoxElement && !isCategory(item))
- {
- selectedItem = item;
- break;
- }
- }
+ selectedItem = firstNonCategoryItem(combo.getModel());
}
if (selectedItem != null)
{
@@ -817,6 +809,19 @@
selectedItem = o;
}
}
+
+ private Object firstNonCategoryItem(ComboBoxModel model)
+ {
+ for (int i = 0; i < model.getSize(); i++)
+ {
+ Object item = model.getElementAt(i);
+ if (item instanceof CategorizedComboBoxElement && !isCategory(item))
+ {
+ return item;
+ }
+ }
+ return null;
+ }
}
/**
@@ -1219,22 +1224,7 @@
private void updatePane(final JEditorPane pane, final LocalizableMessage title, final Font titleFont,
final LocalizableMessage details, final Font detailsFont, final PanelType type)
{
- String text;
- switch (type)
- {
- case ERROR:
- text = Utilities.getFormattedError(title, titleFont, details, detailsFont);
- break;
- case CONFIRMATION:
- text = Utilities.getFormattedConfirmation(title, titleFont, details, detailsFont);
- break;
- case WARNING:
- text = Utilities.getFormattedWarning(title, titleFont, details, detailsFont);
- break;
- default:
- text = Utilities.getFormattedSuccess(title, titleFont, details, detailsFont);
- break;
- }
+ String text = getText(type, title, titleFont, details, detailsFont);
if (!text.equals(lastDisplayedError))
{
LocalizableMessage wrappedTitle = Utilities.wrapHTML(title, 80);
@@ -1274,6 +1264,22 @@
}
}
+ private String getText(
+ PanelType type, LocalizableMessage title, Font titleFont, LocalizableMessage details, Font detailsFont)
+ {
+ switch (type)
+ {
+ case ERROR:
+ return Utilities.getFormattedError(title, titleFont, details, detailsFont);
+ case CONFIRMATION:
+ return Utilities.getFormattedConfirmation(title, titleFont, details, detailsFont);
+ case WARNING:
+ return Utilities.getFormattedWarning(title, titleFont, details, detailsFont);
+ default:
+ return Utilities.getFormattedSuccess(title, titleFont, details, detailsFont);
+ }
+ }
+
/**
* Commodity method used to update the elements of a combo box that contains
* the different user backends. If no backends are found the combo box will be
--
Gitblit v1.10.0