From 41cffba4298d61383d0dd99857429960a4ca3d44 Mon Sep 17 00:00:00 2001 From: James Moger Date: Fri, 4 Nov 2011 23:00:19 -0400 Subject: [PATCH] Refinements to search dialog and null checks in cell renderers --- src/com/gitblit/client/BranchRenderer.java | 7 +--- src/com/gitblit/client/MessageRenderer.java | 3 ++ src/com/gitblit/client/NameRenderer.java | 4 +- src/com/gitblit/client/SearchDialog.java | 44 ++++++++++++++------- 4 files changed, 36 insertions(+), 22 deletions(-) diff --git a/src/com/gitblit/client/BranchRenderer.java b/src/com/gitblit/client/BranchRenderer.java index 586d0500..9a303c38 100644 --- a/src/com/gitblit/client/BranchRenderer.java +++ b/src/com/gitblit/client/BranchRenderer.java @@ -41,10 +41,7 @@ public class BranchRenderer extends DefaultTableCellRenderer implements ListCell public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); - if (value == null) { - return this; - } - setText(value.toString()); + setText(value == null ? "" : value.toString()); if (isSelected) { setForeground(table.getSelectionForeground()); } @@ -54,7 +51,7 @@ public class BranchRenderer extends DefaultTableCellRenderer implements ListCell @Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { - setText(value.toString()); + setText(value == null ? "" : value.toString()); if (isSelected) { setBackground(list.getSelectionBackground()); setForeground(list.getSelectionForeground()); diff --git a/src/com/gitblit/client/MessageRenderer.java b/src/com/gitblit/client/MessageRenderer.java index 2ff35279..3629e21d 100644 --- a/src/com/gitblit/client/MessageRenderer.java +++ b/src/com/gitblit/client/MessageRenderer.java @@ -78,6 +78,9 @@ public class MessageRenderer extends JPanel implements TableCellRenderer, Serial setBackground(table.getBackground()); messageLabel.setForeground(isSelected ? table.getSelectionForeground() : table .getForeground()); + if (value == null) { + return this; + } SyndicatedEntryModel entry = (SyndicatedEntryModel) value; if (gitblit == null) { diff --git a/src/com/gitblit/client/NameRenderer.java b/src/com/gitblit/client/NameRenderer.java index 8ba2e00a..4cbb5906 100644 --- a/src/com/gitblit/client/NameRenderer.java +++ b/src/com/gitblit/client/NameRenderer.java @@ -59,14 +59,14 @@ public class NameRenderer extends DefaultTableCellRenderer implements ListCellRe public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); - setValue(value, isSelected); + setValue(value == null ? "" : value, isSelected); return this; } @Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { - setValue(value, isSelected); + setValue(value == null ? "" : value, isSelected); if (isSelected) { setBackground(list.getSelectionBackground()); setForeground(list.getSelectionForeground()); diff --git a/src/com/gitblit/client/SearchDialog.java b/src/com/gitblit/client/SearchDialog.java index 5dbea789..448aaef8 100644 --- a/src/com/gitblit/client/SearchDialog.java +++ b/src/com/gitblit/client/SearchDialog.java @@ -203,9 +203,16 @@ public class SearchDialog extends JFrame { selectedBranch = branchSelector.getSelectedItem().toString(); } updateBranches(); - if (selectedBranch != null) { + if (StringUtils.isEmpty(selectedBranch)) { + // do not select branch + branchSelector.setSelectedIndex(-1); + } else { if (branchChoices.getIndexOf(selectedBranch) > -1) { + // select branch branchChoices.setSelectedItem(selectedBranch); + } else { + // branch does not exist, do not select branch + branchSelector.setSelectedIndex(-1); } } } @@ -213,7 +220,7 @@ public class SearchDialog extends JFrame { branchChoices = new DefaultComboBoxModel(); branchSelector = new JComboBox(branchChoices); - branchSelector.setRenderer(new BranchRenderer()); + branchSelector.setRenderer(new BranchRenderer()); searchTypeSelector = new JComboBox(Constants.SearchType.values()); searchTypeSelector.setSelectedItem(Constants.SearchType.COMMIT); @@ -228,19 +235,26 @@ public class SearchDialog extends JFrame { } }); - JPanel northControls = new JPanel(new FlowLayout(FlowLayout.LEFT, Utils.MARGIN, 0)); - northControls.add(new JLabel(Translation.get("gb.repository"))); - northControls.add(repositorySelector); - northControls.add(new JLabel(Translation.get("gb.branch"))); - northControls.add(branchSelector); - northControls.add(new JLabel(Translation.get("gb.type"))); - northControls.add(searchTypeSelector); - northControls.add(new JLabel(Translation.get("gb.maxHits"))); - northControls.add(maxHitsSelector); - northControls.add(searchFragment); - northControls.add(search); - northControls.add(prev); - northControls.add(next); + JPanel queryPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, Utils.MARGIN, 0)); + queryPanel.add(new JLabel(Translation.get("gb.repository"))); + queryPanel.add(repositorySelector); + queryPanel.add(new JLabel(Translation.get("gb.branch"))); + queryPanel.add(branchSelector); + queryPanel.add(new JLabel(Translation.get("gb.type"))); + queryPanel.add(searchTypeSelector); + queryPanel.add(new JLabel(Translation.get("gb.maxHits"))); + queryPanel.add(maxHitsSelector); + + JPanel actionsPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, Utils.MARGIN, 0)); + actionsPanel.add(search); + actionsPanel.add(prev); + actionsPanel.add(next); + + JPanel northControls = new JPanel(new BorderLayout(Utils.MARGIN, Utils.MARGIN)); + northControls.add(queryPanel, BorderLayout.WEST); + northControls.add(searchFragment, BorderLayout.CENTER); + northControls.add(actionsPanel, BorderLayout.EAST); + JPanel northPanel = new JPanel(new BorderLayout(0, Utils.MARGIN)); northPanel.add(header, BorderLayout.NORTH); -- 2.39.5