]> source.dussan.org Git - gitblit.git/commitdiff
Refinements to search dialog and null checks in cell renderers
authorJames Moger <james.moger@gitblit.com>
Sat, 5 Nov 2011 03:00:19 +0000 (23:00 -0400)
committerJames Moger <james.moger@gitblit.com>
Sat, 5 Nov 2011 03:00:19 +0000 (23:00 -0400)
src/com/gitblit/client/BranchRenderer.java
src/com/gitblit/client/MessageRenderer.java
src/com/gitblit/client/NameRenderer.java
src/com/gitblit/client/SearchDialog.java

index 586d0500c99d9b1c9be7911750d532fd912bf8e0..9a303c388a769b83bcec11cd63796914d8e45b08 100644 (file)
@@ -41,10 +41,7 @@ public class BranchRenderer extends DefaultTableCellRenderer implements ListCell
        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,\r
                        boolean hasFocus, int row, int column) {\r
                super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);\r
-               if (value == null) {\r
-                       return this;\r
-               }\r
-               setText(value.toString());\r
+               setText(value == null ? "" : value.toString());\r
                if (isSelected) {\r
                        setForeground(table.getSelectionForeground());\r
                }\r
@@ -54,7 +51,7 @@ public class BranchRenderer extends DefaultTableCellRenderer implements ListCell
        @Override\r
        public Component getListCellRendererComponent(JList list, Object value, int index,\r
                        boolean isSelected, boolean cellHasFocus) {\r
-               setText(value.toString());\r
+               setText(value == null ? "" : value.toString());\r
                if (isSelected) {\r
                        setBackground(list.getSelectionBackground());\r
                        setForeground(list.getSelectionForeground());\r
index 2ff352794024352be00a6553afd587e3ca322e47..3629e21d2b1aef857cdd2fc1a2ca75b73061018a 100644 (file)
@@ -78,6 +78,9 @@ public class MessageRenderer extends JPanel implements TableCellRenderer, Serial
                        setBackground(table.getBackground());\r
                messageLabel.setForeground(isSelected ? table.getSelectionForeground() : table\r
                                .getForeground());\r
+               if (value == null) {\r
+                       return this;\r
+               }\r
                SyndicatedEntryModel entry = (SyndicatedEntryModel) value;\r
 \r
                if (gitblit == null) {\r
index 8ba2e00a77f41c1b10ffc3e30023f16af659cb3e..4cbb5906b87f7f3c25d981a11844dda6c266242b 100644 (file)
@@ -59,14 +59,14 @@ public class NameRenderer extends DefaultTableCellRenderer implements ListCellRe
        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,\r
                        boolean hasFocus, int row, int column) {\r
                super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);\r
-               setValue(value, isSelected);\r
+               setValue(value == null ? "" : value, isSelected);\r
                return this;\r
        }\r
 \r
        @Override\r
        public Component getListCellRendererComponent(JList list, Object value, int index,\r
                        boolean isSelected, boolean cellHasFocus) {\r
-               setValue(value, isSelected);\r
+               setValue(value == null ? "" : value, isSelected);\r
                if (isSelected) {\r
                        setBackground(list.getSelectionBackground());\r
                        setForeground(list.getSelectionForeground());\r
index 5dbea7892fa9ea17151e01b564118d53eacf7cf1..448aaef802bb7777e123d71e032e6d4168e42bf7 100644 (file)
@@ -203,9 +203,16 @@ public class SearchDialog extends JFrame {
                                        selectedBranch = branchSelector.getSelectedItem().toString();\r
                                }\r
                                updateBranches();\r
-                               if (selectedBranch != null) {\r
+                               if (StringUtils.isEmpty(selectedBranch)) {\r
+                                       // do not select branch\r
+                                       branchSelector.setSelectedIndex(-1);\r
+                               } else {\r
                                        if (branchChoices.getIndexOf(selectedBranch) > -1) {\r
+                                               // select branch\r
                                                branchChoices.setSelectedItem(selectedBranch);\r
+                                       } else {\r
+                                               // branch does not exist, do not select branch\r
+                                               branchSelector.setSelectedIndex(-1);\r
                                        }\r
                                }\r
                        }\r
@@ -213,7 +220,7 @@ public class SearchDialog extends JFrame {
 \r
                branchChoices = new DefaultComboBoxModel();\r
                branchSelector = new JComboBox(branchChoices);\r
-               branchSelector.setRenderer(new BranchRenderer());\r
+               branchSelector.setRenderer(new BranchRenderer());               \r
 \r
                searchTypeSelector = new JComboBox(Constants.SearchType.values());\r
                searchTypeSelector.setSelectedItem(Constants.SearchType.COMMIT);\r
@@ -228,19 +235,26 @@ public class SearchDialog extends JFrame {
                        }\r
                });\r
 \r
-               JPanel northControls = new JPanel(new FlowLayout(FlowLayout.LEFT, Utils.MARGIN, 0));\r
-               northControls.add(new JLabel(Translation.get("gb.repository")));\r
-               northControls.add(repositorySelector);\r
-               northControls.add(new JLabel(Translation.get("gb.branch")));\r
-               northControls.add(branchSelector);\r
-               northControls.add(new JLabel(Translation.get("gb.type")));\r
-               northControls.add(searchTypeSelector);\r
-               northControls.add(new JLabel(Translation.get("gb.maxHits")));\r
-               northControls.add(maxHitsSelector);\r
-               northControls.add(searchFragment);\r
-               northControls.add(search);\r
-               northControls.add(prev);\r
-               northControls.add(next);\r
+               JPanel queryPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, Utils.MARGIN, 0));\r
+               queryPanel.add(new JLabel(Translation.get("gb.repository")));\r
+               queryPanel.add(repositorySelector);\r
+               queryPanel.add(new JLabel(Translation.get("gb.branch")));\r
+               queryPanel.add(branchSelector);\r
+               queryPanel.add(new JLabel(Translation.get("gb.type")));\r
+               queryPanel.add(searchTypeSelector);\r
+               queryPanel.add(new JLabel(Translation.get("gb.maxHits")));\r
+               queryPanel.add(maxHitsSelector);\r
+\r
+               JPanel actionsPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, Utils.MARGIN, 0));\r
+               actionsPanel.add(search);\r
+               actionsPanel.add(prev);\r
+               actionsPanel.add(next);\r
+\r
+               JPanel northControls = new JPanel(new BorderLayout(Utils.MARGIN, Utils.MARGIN));\r
+               northControls.add(queryPanel, BorderLayout.WEST);\r
+               northControls.add(searchFragment, BorderLayout.CENTER);\r
+               northControls.add(actionsPanel, BorderLayout.EAST);\r
+               \r
 \r
                JPanel northPanel = new JPanel(new BorderLayout(0, Utils.MARGIN));\r
                northPanel.add(header, BorderLayout.NORTH);\r