Ver código fonte

Return useful value rather than null whern finding node.

Fixes issue 4321

Change-Id: Ic064c6c610b934f4b2b67a143becfa5db3cd0a03
Reviewed-on: http://gerrit.dmdirc.com/1435
Automatic-Compile: DMDirc Local Commits <dmdirc@googlemail.com>
Reviewed-by: Chris Smith <chris@dmdirc.com>
tags/0.6.4
Greg Holmes 14 anos atrás
pai
commit
61f06d27e9

+ 8
- 5
src/com/dmdirc/addons/ui_swing/dialogs/serverlist/Tree.java Ver arquivo

31
 import java.awt.event.ActionEvent;
31
 import java.awt.event.ActionEvent;
32
 import java.awt.event.ActionListener;
32
 import java.awt.event.ActionListener;
33
 import java.util.Enumeration;
33
 import java.util.Enumeration;
34
-import javax.swing.JButton;
35
 
34
 
35
+import javax.swing.JButton;
36
 import javax.swing.JComponent;
36
 import javax.swing.JComponent;
37
 import javax.swing.JPanel;
37
 import javax.swing.JPanel;
38
 import javax.swing.JScrollPane;
38
 import javax.swing.JScrollPane;
74
      * Instantiates a new tree of server groups.
74
      * Instantiates a new tree of server groups.
75
      *
75
      *
76
      * @param model Model backing this tree
76
      * @param model Model backing this tree
77
+     * @param parentWindow Dialog's parent window
77
      */
78
      */
78
     public Tree(final ServerListModel model, final Window parentWindow) {
79
     public Tree(final ServerListModel model, final Window parentWindow) {
79
         super();
80
         super();
106
         items.putClientProperty("JTree.lineStyle", "Angled");
107
         items.putClientProperty("JTree.lineStyle", "Angled");
107
         items.getInputMap().setParent(null);
108
         items.getInputMap().setParent(null);
108
         items.getInputMap(JComponent.WHEN_FOCUSED).clear();
109
         items.getInputMap(JComponent.WHEN_FOCUSED).clear();
109
-        items.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).clear();
110
+        items.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)
111
+                .clear();
110
         items.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).clear();
112
         items.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).clear();
111
         items.getSelectionModel().setSelectionMode(
113
         items.getSelectionModel().setSelectionMode(
112
                 TreeSelectionModel.SINGLE_TREE_SELECTION);
114
                 TreeSelectionModel.SINGLE_TREE_SELECTION);
195
     }
197
     }
196
 
198
 
197
     /**
199
     /**
198
-     * Find the node for a specified server group item, will return null if the
199
-     * group is not found.
200
+     * Find the node for a specified server group item, will return root node
201
+     * if the group isn't found.
200
      *
202
      *
201
      * @param item Item to search for in the tree
203
      * @param item Item to search for in the tree
202
      *
204
      *
203
      * @return Node for group, or null if not found
205
      * @return Node for group, or null if not found
204
      */
206
      */
205
     private DefaultMutableTreeNode getNodeForGroup(final ServerGroupItem item) {
207
     private DefaultMutableTreeNode getNodeForGroup(final ServerGroupItem item) {
206
-        DefaultMutableTreeNode node = null;
208
+        DefaultMutableTreeNode node = (DefaultMutableTreeNode) items.getModel()
209
+                .getRoot();
207
         final Enumeration enumeration = ((DefaultMutableTreeNode) items
210
         final Enumeration enumeration = ((DefaultMutableTreeNode) items
208
                 .getModel().getRoot()).breadthFirstEnumeration();
211
                 .getModel().getRoot()).breadthFirstEnumeration();
209
         while (enumeration.hasMoreElements()) {
212
         while (enumeration.hasMoreElements()) {

Carregando…
Cancelar
Salvar