[hg] main-silver: #223295: SQL History dialog lists connections ...

  • From: Jaroslav Havlin < >
  • To:
  • Subject: [hg] main-silver: #223295: SQL History dialog lists connections ...
  • Date: Fri, 07 Dec 2012 04:16:56 -0800

changeset 6b7add3c7c42 in main-silver ((none))
details: http://hg.netbeans.org/main-silver/rev/6b7add3c7c42
description:
        #223295: SQL History dialog lists connections as URL, not their 
display names

diffstat:

 db.core/src/org/netbeans/modules/db/sql/execute/ui/SQLHistoryPanel.form |   
2 +-
 db.core/src/org/netbeans/modules/db/sql/execute/ui/SQLHistoryPanel.java |  
89 ++++++++-
 2 files changed, 79 insertions(+), 12 deletions(-)

diffs (150 lines):

diff --git 
a/db.core/src/org/netbeans/modules/db/sql/execute/ui/SQLHistoryPanel.form 
b/db.core/src/org/netbeans/modules/db/sql/execute/ui/SQLHistoryPanel.form
--- a/db.core/src/org/netbeans/modules/db/sql/execute/ui/SQLHistoryPanel.form
+++ b/db.core/src/org/netbeans/modules/db/sql/execute/ui/SQLHistoryPanel.form
@@ -1,4 +1,4 @@
-<?xml version="1.1" encoding="UTF-8" ?>
+<?xml version="1.0" encoding="UTF-8" ?>
 
 <Form version="1.6" maxVersion="1.6" 
type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
   <AuxValues>
diff --git 
a/db.core/src/org/netbeans/modules/db/sql/execute/ui/SQLHistoryPanel.java 
b/db.core/src/org/netbeans/modules/db/sql/execute/ui/SQLHistoryPanel.java
--- a/db.core/src/org/netbeans/modules/db/sql/execute/ui/SQLHistoryPanel.java
+++ b/db.core/src/org/netbeans/modules/db/sql/execute/ui/SQLHistoryPanel.java
@@ -42,6 +42,7 @@
 package org.netbeans.modules.db.sql.execute.ui;
 
 import java.awt.Component;
+import java.awt.EventQueue;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
 import java.awt.event.MouseAdapter;
@@ -60,6 +61,8 @@
 import javax.swing.text.BadLocationException;
 import javax.swing.text.Caret;
 import javax.swing.text.Document;
+import org.netbeans.api.db.explorer.ConnectionManager;
+import org.netbeans.api.db.explorer.DatabaseConnection;
 import org.netbeans.api.editor.EditorRegistry;
 import org.netbeans.modules.db.sql.history.SQLHistory;
 import org.netbeans.modules.db.sql.history.SQLHistoryEntry;
@@ -71,6 +74,7 @@
 import org.openide.util.Exceptions;
 import org.openide.util.NbBundle;
 import org.openide.util.NotImplementedException;
+import org.openide.util.RequestProcessor;
 
 /**
  *
@@ -78,6 +82,8 @@
  */
 public class SQLHistoryPanel extends javax.swing.JPanel {
 
+    private static final RequestProcessor RP =
+            new RequestProcessor(SQLHistoryPanel.class);
     private TableRowSorter<HistoryTableModel> rowSorter;
     private HistoryTableModel htm = new HistoryTableModel();
     public static final String SAVE_STATEMENTS_CLEARED = ""; // NOI18N  
@@ -168,9 +174,10 @@
     private void updateFilter() {
         List<RowFilter<HistoryTableModel, Integer>> rowFilter = new 
ArrayList<RowFilter<HistoryTableModel, Integer>>();
 
-        String url = (String) connectionUrlComboBox.getSelectedItem();
-
-        if (url != null && 
!url.equals(NbBundle.getMessage(SQLHistoryPanel.class, 
"LBL_URLComboBoxAllConnectionsItem"))) {
+        ConnectionHistoryItem connectionItem =
+                (ConnectionHistoryItem) 
connectionUrlComboBox.getSelectedItem();
+        String url = connectionItem.getUrl();
+        if (url != null && !url.equals(ConnectionHistoryItem.ALL_URLS)) {
             rowFilter.add(new EqualsFilter(url, 0));
     }
 
@@ -186,16 +193,41 @@
             }
 
     private void updateURLList() {
-        List<String> urls = new ArrayList<String>(htm.getJdbcURLs());
-        urls.add(0, NbBundle.getMessage(SQLHistoryPanel.class, 
"LBL_URLComboBoxAllConnectionsItem"));
-        Object selected = connectionUrlComboBox.getSelectedItem();
-        connectionUrlComboBox.setModel(new 
DefaultComboBoxModel(urls.toArray()));
-        if(selected != null && urls.contains((String) selected)) {
-            connectionUrlComboBox.setSelectedItem(selected);
-        } else {
-            connectionUrlComboBox.setSelectedIndex(0);
+        ConnectionHistoryItem selectedItem =
+                (ConnectionHistoryItem) 
connectionUrlComboBox.getSelectedItem();
+        final String selectedUrl = selectedItem == null
+                ? null : selectedItem.getUrl();
+        final List<String> urls = new ArrayList<String>(htm.getJdbcURLs());
+        urls.add(0, ConnectionHistoryItem.ALL_URLS);
+        RP.post(new Runnable() {
+            @Override
+            public void run() {
+                int selectedIndex = 0;
+                int w = urls.size();
+                final ConnectionHistoryItem[] comboItems =
+                        new ConnectionHistoryItem[w];
+                for (int i = 0; i < w; i++) {
+                    comboItems[i] = new ConnectionHistoryItem(urls.get(i));
+                    if (urls.get(i) != null && 
urls.get(i).equals(selectedUrl)) {
+                        selectedIndex = i;
         }
     }
+                final int selectedIndexFinal = selectedIndex;
+                EventQueue.invokeLater(new Runnable() {
+                    @Override
+                    public void run() {
+                        updateComboBox(comboItems, selectedIndexFinal);
+                    }
+                });
+            }
+
+            private void updateComboBox(ConnectionHistoryItem[] items,
+                    int selectedIndex) {
+                connectionUrlComboBox.setModel(new 
DefaultComboBoxModel(items));
+                connectionUrlComboBox.setSelectedIndex(selectedIndex);
+            }
+        });
+    }
 
     /** This method is called from within the constructor to
      * initialize the form.
@@ -651,4 +683,39 @@
             return ((String) 
entry.getModel().getValueAt(entry.getIdentifier(), 
referenzColumn)).toLowerCase().contains(referenz);
         }
     };
+
+    private static class ConnectionHistoryItem {
+
+        private static final String ALL_URLS = "*";                     
//NOI18N
+        private String url;
+        private String name;
+
+        public ConnectionHistoryItem(String url) {
+            this.url = url == null ? ALL_URLS : url;
+            if (ALL_URLS.equals(url)) {
+                name = NbBundle.getMessage(SQLHistoryPanel.class,
+                        "LBL_URLComboBoxAllConnectionsItem");           
//NOI18N
+            } else {
+                for (DatabaseConnection dc
+                        : ConnectionManager.getDefault().getConnections()) {
+                    if (dc.getDatabaseURL().equals(url)) {
+                        name = dc.getDisplayName();
+                        break;
 }
+                }
+                if (name == null) {
+                    name = url;
+                }
+            }
+        }
+
+        public String getUrl() {
+            return url;
+        }
+
+        @Override
+        public String toString() {
+            return name;
+        }
+    }
+}

[hg] main-silver: #223295: SQL History dialog lists connections ...

Jaroslav Havlin 12/07/2012

Project Features

About this Project

DB was started in November 2009, is owned by Antonin Nebuzelsky, and has 113 members.
By use of this website, you agree to the NetBeans Policies and Terms of Use (revision 20131025.e7cbc9d). © 2013, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo
 
 
Close
loading
Please Confirm
Close