This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 154383 - DatabaseExplorerUIs.connect feature problems
Summary: DatabaseExplorerUIs.connect feature problems
Status: RESOLVED FIXED
Alias: None
Product: db
Classification: Unclassified
Component: MySQL (show other bugs)
Version: 6.x
Hardware: All All
: P3 blocker (vote)
Assignee: Jaroslav Havlin
URL:
Keywords: NETFIX
Depends on:
Blocks:
 
Reported: 2008-12-02 17:07 UTC by ndev69
Modified: 2012-10-25 10:50 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
proposed patch v1 (10.47 KB, patch)
2012-10-07 18:34 UTC, matthias42
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description ndev69 2008-12-02 17:07:04 UTC
After connecting a combobox using DatabaseExplorerUIs.connect it does not properly handle the removal of Database
connections on its own. Since it creates a non-mutable model this poses a problem for a user to handle it externally as
well. Issue #135003 was fixed very well but this new problem still impedes the API.
Comment 1 ndev69 2008-12-02 17:19:27 UTC
  This is the routine I am using to connect the combobox. When connections are removed the combo box is not updated.
Below is the fix I am using to accomplish this task.
  public void populateForm() {
        ConnectionManager manager = ConnectionManager.getDefault();
        DatabaseExplorerUIs.connect(connectionsCombo, manager);

        DatabaseConnection current = SQLConnectionManager.getDefault().getActiveConnection();
        if (current != null) {
            connectionsCombo.setSelectedItem(current);
        }
    }


    private void removeActiveConnection(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
        Object selItem = connectionsCombo.getSelectedItem();
        if (selItem instanceof DatabaseConnection) {
             SQLConnectionManager.getDefault().setActiveConnection(null);
            try {
**** issue# 135003 fixed this call it now works.. however the combo is not updated.
                ConnectionManager.getDefault().removeConnection((DatabaseConnection) selItem);
            } catch (DatabaseException ex) {
                ex.printStackTrace(IOProvider.getDefault().getStdOut());
            }
***** This is needed to get the call to re-register the combo box model without generating a class cast exception. I am
assuming that the DatabaseExplorerUIs.connect method adds a property change listener and listens for model changes and
removes itself. If not may want to either fix by adding the remove support or add a DatabaseExplorerUIs.remove method to
handle this type of work around. Personally I think the DatabaseExplorerUIs.connect method should handle adding and
removing items properly as connections become available and are lost.
            connectionsCombo.setModel(new DefaultComboBoxModel());
            populateForm();
        }
    }

Comment 2 Jiri Rechtacek 2009-10-16 14:07:17 UTC
Reassigned to new owner.
Comment 3 matthias42 2012-10-07 18:34:24 UTC
Created attachment 125545 [details]
proposed patch v1

Fixed by useing a connection listener to directly tie the comboboxmodel to the connection list.

A weaklistener is constructed to prevent a memoryleak, unittest is attached.
Comment 4 ndev69 2012-10-08 05:00:01 UTC
It has been 4 years since I initially reported this bug. In the beginnig there were several exchanges to even convince whoever is at the other end of this system that this problem even existed. I have long since given up on this product and moved to .NET. Cudos to your persiverance, but 4 years, and this is just a proposed patch. I know it is a free product but I assume you actually want people to use it.
Comment 5 Jaroslav Havlin 2012-10-22 15:28:53 UTC
Integrated as http://hg.netbeans.org/core-main/rev/3e8d6e8df597
Thank you, Matthias!
Comment 6 Quality Engineering 2012-10-25 10:50:44 UTC
Integrated into 'main-golden', will be available in build *201210250921* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main-golden/rev/3e8d6e8df597
User: Jaroslav Havlin <jhavlin@netbeans.org>
Log: #154383: DatabaseExplorerUIs.connect feature problems