Skip to content

Commit

Permalink
Multiple catalogs choice (GitHub issue 17) finished:
Browse files Browse the repository at this point in the history
#17
   For databases that support catalogs SQuirreL now allows to specify additional catalogs to load.
   See the new toolbar button with the three dots icon next to the
   catalogs combo box at the upper left of a Session panel.
  • Loading branch information
gerdwagner committed Aug 27, 2023
1 parent b162f23 commit 9e30e77
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 7 deletions.
7 changes: 6 additions & 1 deletion sql12/core/doc/changes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ Not yet released, available in our GIT repository, snapshots and future releases

Enhancements:

https://github.com/squirrel-sql-client/squirrel-sql-code/issues/17
For databases that support catalogs SQuirreL now allows to specify additional catalogs to load.
See the new toolbar button with the three dots icon next to the
catalogs combo box at the upper left of a Session panel.

Hibernate Plugin: Now supports Hibernate 6 and Jakarta Persistence.

Query connection pool:
Expand Down Expand Up @@ -459,7 +464,7 @@ https://github.com/squirrel-sql-client/squirrel-sql-code/issues/1
For Oracle databases right mouse click on table in Object tree --> Scripts --> Create Table Script
scripted columns of type number as decimal.

#1508 MS SQL Server: When the catalog was switched by SQuirreL's catalogs combobox
#1508 MS SQL Server: When the catalog was switched by SQuirreL's catalogs combo box
the subsequent Object tree reload didn't work.
The reason is a bug of the MSSQL JDBC driver (https://github.com/microsoft/mssql-jdbc).
The logged message of the bug is:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
import java.awt.event.MouseEvent;
import java.sql.SQLException;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

public class AdditionalCatalogsController
{
Expand All @@ -31,7 +29,10 @@ public AdditionalCatalogsController(ISession session)
AliasCatalogLoadModelJsonBean bean = Main.getApplication().getCatalogLoadModelManager().getAliasCatalogLoadModelJsonBean(session.getAlias());

DefaultListModel<CatalogChecked> listModel = new DefaultListModel<>();
listModel.addAll(List.of(catalogs).stream().map(c -> createCatalogChecked(c, bean)).collect(Collectors.toList()));
for (String catalog : catalogs)
{
listModel.addElement(createCatalogChecked(catalog, bean));
}

_dlg.chkLstCatalogs.setModel(listModel);

Expand All @@ -47,6 +48,9 @@ public void mouseClicked(MouseEvent event)
}
});


_dlg.btnSelectAll.addActionListener(e -> onSelectAll());
_dlg.btnInvertSelection.addActionListener(e -> onInvertSelection());
_dlg.btnOk.addActionListener(e -> onOk(session));

GUIUtils.initLocation(_dlg, 400, 600);
Expand All @@ -62,10 +66,31 @@ public void mouseClicked(MouseEvent event)
}
}

private void onInvertSelection()
{
for (int i = 0; i < _dlg.chkLstCatalogs.getModel().getSize(); i++)
{
CatalogChecked catalogChecked = _dlg.chkLstCatalogs.getModel().getElementAt(i);
catalogChecked.setChecked(!catalogChecked.isChecked());
}
_dlg.chkLstCatalogs.repaint();
}

private void onSelectAll()
{
for (int i = 0; i < _dlg.chkLstCatalogs.getModel().getSize(); i++)
{
_dlg.chkLstCatalogs.getModel().getElementAt(i).setChecked(true);
}
_dlg.chkLstCatalogs.repaint();
}

private void onMouseClicked(MouseEvent event)
{
int index = _dlg.chkLstCatalogs.locationToIndex(event.getPoint());
if (index >= 0 && index < _dlg.chkLstCatalogs.getModel().getSize())
if ( index >= 0
&& index < _dlg.chkLstCatalogs.getModel().getSize()
&& _dlg.chkLstCatalogs.getCellBounds(index, index).contains(event.getPoint()))
{
CatalogChecked catalogChecked = _dlg.chkLstCatalogs.getModel().getElementAt(index);
catalogChecked.setChecked(!catalogChecked.isChecked());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public class AdditionalCatalogsDlg extends JDialog

final JList<CatalogChecked> chkLstCatalogs;
final JButton btnOk;
JButton btnSelectAll;
JButton btnInvertSelection;

public AdditionalCatalogsDlg(Window owner)
{
Expand All @@ -31,8 +33,28 @@ public AdditionalCatalogsDlg(Window owner)
chkLstCatalogs = new JList<>();
getContentPane().add(new JScrollPane(chkLstCatalogs), gbc);

gbc = new GridBagConstraints(0,2,1,1,0,0,GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(5,5,5,5),0,0 );
gbc = new GridBagConstraints(0,2,1,1,0,0,GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(3,5,5,5),0,0 );
getContentPane().add(createListControlButtonsPanel(), gbc);

gbc = new GridBagConstraints(0,3,1,1,0,0,GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(10,5,5,5),0,0 );
btnOk = new JButton(s_stringMgr.getString("AdditionalCatalogsDlg.ok"));
getContentPane().add(btnOk, gbc);
}

private JPanel createListControlButtonsPanel()
{
JPanel ret = new JPanel(new GridBagLayout());

GridBagConstraints gbc;

gbc = new GridBagConstraints(0,0,1,1,0,0,GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(0,0,0,0),0,0 );
btnSelectAll = new JButton(s_stringMgr.getString("AdditionalCatalogsDlg.selectAll"));
ret.add(btnSelectAll, gbc);

gbc = new GridBagConstraints(1,0,1,1,0,0,GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(0,5,0,0),0,0 );
btnInvertSelection = new JButton(s_stringMgr.getString("AdditionalCatalogsDlg.invertSelection"));
ret.add(btnInvertSelection, gbc);

return ret;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,15 @@ public void initSizeAndBackgroundAfterCatalogsComboFilled()
GUIUtils.inheritBackground(this);
}

public void setHasAdditionalCatalogs(boolean hasAdditionalCatalogs)
{
if(hasAdditionalCatalogs)
{
btnConfiCatalogLoading.setIcon(Main.getApplication().getResources().getIcon(SquirrelResources.IImageNames.THREE_DOTS_CHECKED));
}
else
{
btnConfiCatalogLoading.setIcon(Main.getApplication().getResources().getIcon(SquirrelResources.IImageNames.THREE_DOTS));
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.sourceforge.squirrel_sql.client.gui.session.catalogspanel;

import net.sourceforge.squirrel_sql.client.Main;
import net.sourceforge.squirrel_sql.client.session.IObjectTreeAPI;
import net.sourceforge.squirrel_sql.client.session.ISession;
import net.sourceforge.squirrel_sql.client.session.mainpanel.objecttree.ObjectTreeNode;
Expand Down Expand Up @@ -43,13 +44,21 @@ public CatalogsPanelController(ISession session, JComponent parentComponent)
_session = session;
_parentComponent = parentComponent;
_catalogsPanel = new CatalogsPanel();
updateAdditionalCatalogsIcon();


_catalogsComboListener = e -> onCatalogSelected();
_connectionPropetryListener = evt -> GUIUtils.processOnSwingEventThread(() -> onConnectionPropertyChanged(evt));

init();
}

private void updateAdditionalCatalogsIcon()
{
boolean hasAdditionalCatalogs = !Main.getApplication().getCatalogLoadModelManager().getAliasCatalogLoadModelJsonBean(_session.getAlias()).getAdditionalUserChosenCatalogs().isEmpty();
_catalogsPanel.setHasAdditionalCatalogs(hasAdditionalCatalogs);
}

private void init()
{
try
Expand Down Expand Up @@ -95,6 +104,7 @@ private void onConfigureCatalogLoading()
{
if(new AdditionalCatalogsController(_session).isOk())
{
updateAdditionalCatalogsIcon();
refreshSchemaAndTree();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@ AdditionalCatalogsDlg.explain=By default, SQuirreL does not specify catalogs whe
(The current catalog can be switched by the catalogs drop down). \
Here users can choose catalogs that should be loaded additionally to SQuirreL's default schema data loading.

AdditionalCatalogsDlg.ok=Ok
AdditionalCatalogsDlg.ok=Ok

AdditionalCatalogsDlg.selectAll=Select all
AdditionalCatalogsDlg.invertSelection=Invert selection
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ public interface IImageNames
String EDIT_RED_DOT = "editRedDot";

String THREE_DOTS = "threedots";
String THREE_DOTS_CHECKED = "threedots_checked";

String DELETE = "delete";

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ edit.image=edit.png
editRedDot.image=editRedDot.png

threedots.image=threedots.png
threedots_checked.image=threedots_checked.png

delete.image=delete.png

Expand Down

0 comments on commit 9e30e77

Please sign in to comment.