Update of /cvsroot/squirrel-sql/sql12/app/src/net/sourceforge/squirrel_sql/client/gui/db/aliasproperties
In directory sfp-cvsdas-3.v30.ch3.sourceforge.com:/tmp/cvs-serv1839/app/src/net/sourceforge/squirrel_sql/client/gui/db/aliasproperties
Modified Files:
I18NStrings.properties AliasPropertiesController.java
ColorPropertiesController.java
Added Files:
ConnectionPropertiesController.java
ConnectionPropertiesPanel.java
Log Message:
Aliases now have the ability to setup keep-alive SQL statement and sleep time (in seconds) to prevent a connection from being disconnected while appearing to be idle.
Index: AliasPropertiesController.java
===================================================================
RCS file: /cvsroot/squirrel-sql/sql12/app/src/net/sourceforge/squirrel_sql/client/gui/db/aliasproperties/AliasPropertiesController.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** AliasPropertiesController.java 28 Nov 2009 20:14:51 -0000 1.7
--- AliasPropertiesController.java 19 Dec 2009 21:33:51 -0000 1.8
***************
*** 96,99 ****
--- 96,100 ----
_iAliasPropertiesPanelControllers.add(new DriverPropertiesController(_alias, _app));
_iAliasPropertiesPanelControllers.add(new ColorPropertiesController(_alias, _app));
+ _iAliasPropertiesPanelControllers.add(new ConnectionPropertiesController(_alias, _app));
IAliasPropertiesPanelController[] pluginAliasPropertiesPanelControllers =
--- NEW FILE: ConnectionPropertiesController.java ---
package net.sourceforge.squirrel_sql.client.gui.db.aliasproperties;
/*
* Copyright (C) 2009 Rob Manning
* man...@us...
*
* Based on initial work from Colin Bell
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
import java.awt.Component;
import net.sourceforge.squirrel_sql.client.IApplication;
import net.sourceforge.squirrel_sql.client.gui.db.ISQLAliasExt;
import net.sourceforge.squirrel_sql.fw.util.StringManager;
import net.sourceforge.squirrel_sql.fw.util.StringManagerFactory;
/**
* This dialog allows the user to review and maintain connection properties for an alias.
*/
public class ConnectionPropertiesController implements IAliasPropertiesPanelController
{
/**
* Internationalized strings for this class.
*/
private static final StringManager s_stringMgr =
StringManagerFactory.getStringManager(ConnectionPropertiesController.class);
private ConnectionPropertiesPanel _propsPnl;
private ISQLAliasExt _alias;
public static interface i18n {
// i18n[ConnectionPropertiesController.title=Connection]
String TITLE = s_stringMgr.getString("ConnectionPropertiesController.title");
// i18n[ConnectionPropertiesController.hint=Set session connection properties for this Alias]
String HINT = s_stringMgr.getString("ConnectionPropertiesController.hint");
}
public ConnectionPropertiesController(ISQLAliasExt alias, IApplication app)
{
_alias = alias;
_propsPnl = new ConnectionPropertiesPanel(alias.getConnectionProperties());
}
public Component getPanelComponent()
{
return _propsPnl;
}
public void applyChanges()
{
_alias.setConnectionProperties(_propsPnl.getSQLAliasConnectionProperties());
}
public String getTitle()
{
return i18n.TITLE;
}
public String getHint()
{
return i18n.HINT;
}
}
Index: I18NStrings.properties
===================================================================
RCS file: /cvsroot/squirrel-sql/sql12/app/src/net/sourceforge/squirrel_sql/client/gui/db/aliasproperties/I18NStrings.properties,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -d -r1.11 -r1.12
*** I18NStrings.properties 28 Nov 2009 21:38:59 -0000 1.11
--- I18NStrings.properties 19 Dec 2009 21:33:51 -0000 1.12
***************
*** 11,15 ****
ColorPropertiesController.hint=Set session colors for this Alias
! ColorPropertiesController.title=Color Properties
--- 11,15 ----
ColorPropertiesController.hint=Set session colors for this Alias
! ColorPropertiesController.title=Color
***************
*** 27,30 ****
--- 27,41 ----
ColorPropertiesPanel.toolbarBackgroundColorChooserDialogTitle=Select Background Color for Toolbar
+ ConnectionPropertiesController.title=Connection
+ ConnectionPropertiesController.hint=Set session connection properties for this Alias
+
+ ConnectionPropertiesPanel.enableKeepAliveMsg=Enable Keep-Alive
+ ConnectionPropertiesPanel.instructions=These settings control whether or not to enable a sort of keep-alive \
+ scheme for database connections created by this alias. When enabled, after creating a new session to the \
+ database, this will cause the SQL statement specified below to be executed in the background. This will \
+ continue, pausing for the specified sleep time below, as long as the session remains connected.
+ ConnectionPropertiesPanel.secondsLabel=seconds
+ ConnectionPropertiesPanel.executeLabel=Execute the following SQL statement:
+ ConnectionPropertiesPanel.sleepForLabel=Sleep for
DriverPropertiesController.noDriverSelected=No driver available in this Alias.\nCan not load driver properties tab.
Index: ColorPropertiesController.java
===================================================================
RCS file: /cvsroot/squirrel-sql/sql12/app/src/net/sourceforge/squirrel_sql/client/gui/db/aliasproperties/ColorPropertiesController.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** ColorPropertiesController.java 28 Nov 2009 21:38:59 -0000 1.2
--- ColorPropertiesController.java 19 Dec 2009 21:33:51 -0000 1.3
***************
*** 45,49 ****
public static interface i18n {
! // i18n[ColorPropertiesController.title=Color Properties]
String TITLE = s_stringMgr.getString("ColorPropertiesController.title");
--- 45,49 ----
public static interface i18n {
! // i18n[ColorPropertiesController.title=Color]
String TITLE = s_stringMgr.getString("ColorPropertiesController.title");
--- NEW FILE: ConnectionPropertiesPanel.java ---
package net.sourceforge.squirrel_sql.client.gui.db.aliasproperties;
/*
* Copyright (C) 2009 Rob Manning
* man...@us...
*
* Based on initial work from Colin Bell
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BorderFactory;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSpinner;
import javax.swing.JTextArea;
import javax.swing.SpinnerNumberModel;
import net.sourceforge.squirrel_sql.client.gui.db.SQLAliasConnectionProperties;
import net.sourceforge.squirrel_sql.fw.gui.MultipleLineLabel;
import net.sourceforge.squirrel_sql.fw.util.StringManager;
import net.sourceforge.squirrel_sql.fw.util.StringManagerFactory;
import net.sourceforge.squirrel_sql.fw.util.Utilities;
/**
* This panel allows the user to configure Session connection keep-alive properties
*/
public class ConnectionPropertiesPanel extends JPanel
{
private static final long serialVersionUID = 1L;
/** Internationalized strings for this class. */
private static final StringManager s_stringMgr =
StringManagerFactory.getStringManager(ConnectionPropertiesPanel.class);
private JCheckBox enableConnectionKeepAliveChk = null;
private JLabel sleepForLabel = null;
private JSpinner sleepTime = null;
private JLabel secondsLabel = null;
private JLabel executeLabel = null;
private JTextArea sqlTextArea = new JTextArea();
public interface i18n
{
// i18n[ConnectionPropertiesPanel.enableKeepAliveMsg=Enable Keep-Alive]
String ENABLE_KEEP_ALIVE_MSG = s_stringMgr.getString("ConnectionPropertiesPanel.enableKeepAliveMsg");
// i18n[ConnectionPropertiesPanel.instructions=These settings control whether or not...]
String INSTRUCTIONS = s_stringMgr.getString("ConnectionPropertiesPanel.instructions");
// i18n[ConnectionPropertiesPanel.secondsLabel=seconds]
String SECONDS_LABEL = s_stringMgr.getString("ConnectionPropertiesPanel.secondsLabel");
// i18n[ConnectionPropertiesPanel.executeLabel=Execute the following SQL statement:]
String EXECUTE_LABEL = s_stringMgr.getString("ConnectionPropertiesPanel.executeLabel");
// i18n[ConnectionPropertiesPanel.sleepForLabel=Sleep for]
String SLEEP_FOR_LABEL = s_stringMgr.getString("ConnectionPropertiesPanel.sleepForLabel");
}
private SQLAliasConnectionProperties _props = null;
public ConnectionPropertiesPanel(SQLAliasConnectionProperties props)
{
Utilities.checkNull("ConnectionPropertiesPanel.init", "props", props);
this._props = props;
createUserInterface();
setSQLAliasConnectionProperties(props);
}
/**
* Retrieve the database properties.
*
* @return the database properties.
*/
public SQLAliasConnectionProperties getSQLAliasConnectionProperties()
{
if (enableConnectionKeepAliveChk.isSelected())
{
_props.setEnableConnectionKeepAlive(true);
int sleepTimeInt = (Integer)sleepTime.getValue();
_props.setKeepAliveSleepTimeSeconds(sleepTimeInt);
_props.setKeepAliveSqlStatement(sqlTextArea.getText());
}
else
{
_props.setEnableConnectionKeepAlive(false);
}
return _props;
}
public void setSQLAliasConnectionProperties(SQLAliasConnectionProperties props) {
this._props = props;
enableConnectionKeepAliveChk.setSelected(_props.isEnableConnectionKeepAlive());
sleepForLabel.setEnabled(_props.isEnableConnectionKeepAlive());
sleepTime.setEnabled(_props.isEnableConnectionKeepAlive());
sleepTime.setValue(props.getKeepAliveSleepTimeSeconds());
secondsLabel.setEnabled(_props.isEnableConnectionKeepAlive());
executeLabel.setEnabled(_props.isEnableConnectionKeepAlive());
sqlTextArea.setEnabled(_props.isEnableConnectionKeepAlive());
sqlTextArea.setText(props.getKeepAliveSqlStatement());
}
private void createUserInterface()
{
setLayout(new GridBagLayout());
final GridBagConstraints gbc = new GridBagConstraints();
setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
gbc.anchor = GridBagConstraints.WEST;
gbc.insets = new Insets(5, 5, 5, 5);
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.gridx = 0;
gbc.gridy = 0;
gbc.weightx = .75;
gbc.weighty = .3;
addInfoPanel(gbc);
prepareNewRow(gbc);
addMiddle(gbc);
prepareNewRow(gbc);
addExecuteLabel(gbc);
prepareNewRow(gbc);
addSqlTextAreaPanel(gbc);
}
private void addExecuteLabel(GridBagConstraints gbc)
{
executeLabel = new JLabel(i18n.EXECUTE_LABEL);
// We want the text to line up with the text of the enable checkbox to give a hint that the
// the checkbox controls enabling this component.
Insets orig = gbc.insets;
gbc.insets = new Insets(0, 25, 0, 0);
add(executeLabel, gbc);
gbc.insets = orig;
}
private void addInfoPanel(final GridBagConstraints gbc)
{
gbc.weighty = 0;
gbc.fill = GridBagConstraints.BOTH;
MultipleLineLabel label = new MultipleLineLabel(i18n.INSTRUCTIONS);
// Instructions
final JPanel pnl = new JPanel();
pnl.add(new MultipleLineLabel(i18n.INSTRUCTIONS));
add(label, gbc);
}
private void addMiddle(final GridBagConstraints gbc)
{
JPanel middlePanel = new JPanel();
middlePanel.setLayout(new GridLayout(2, 1));
setupEnabledCheckbox();
middlePanel.add(enableConnectionKeepAliveChk);
middlePanel.add(getSleepTimePanel());
gbc.weightx = 1;
gbc.gridwidth = 1;
gbc.gridheight = 1;
gbc.weighty = 0;
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.anchor = GridBagConstraints.WEST;
add(middlePanel, gbc);
}
private JPanel getSleepTimePanel()
{
JPanel sleepTimePanel = new JPanel();
sleepTimePanel.setLayout(new GridBagLayout());
SpinnerNumberModel spinnerNumberModel =
new SpinnerNumberModel(_props.getKeepAliveSleepTimeSeconds(), 10, Integer.MAX_VALUE, 10);
sleepTime = new JSpinner(spinnerNumberModel);
sleepTime.setPreferredSize(new Dimension(75, 25));
sleepForLabel = new JLabel(i18n.SLEEP_FOR_LABEL);
GridBagConstraints gbc = new GridBagConstraints();
gbc.anchor = GridBagConstraints.EAST;
gbc.gridx = 0;
gbc.gridy = 0;
gbc.weightx = .05;
gbc.insets = new Insets(0, 5, 0, 0);
sleepTimePanel.add(sleepForLabel, gbc);
gbc.anchor = GridBagConstraints.CENTER;
gbc.gridx++;
gbc.weightx = .05;
sleepTimePanel.add(sleepTime, gbc);
secondsLabel = new JLabel(i18n.SECONDS_LABEL);
gbc.anchor = GridBagConstraints.WEST;
gbc.gridx++;
gbc.weightx = .9;
sleepTimePanel.add(secondsLabel, gbc);
return sleepTimePanel;
}
private void addSqlTextAreaPanel(final GridBagConstraints gbc)
{
gbc.weighty = .7;
gbc.fill = GridBagConstraints.BOTH;
gbc.insets = new Insets(10, 25, 10, 10);
JPanel textPanel = new JPanel();
textPanel.setLayout(new BorderLayout());
textPanel.add(sqlTextArea, BorderLayout.CENTER);
add(textPanel, gbc);
}
private void prepareNewRow(final GridBagConstraints gbc)
{
gbc.gridx = 0;
++gbc.gridy;
gbc.anchor = GridBagConstraints.WEST;
gbc.gridwidth = 1;
gbc.weighty = 0;
}
private void setupEnabledCheckbox()
{
enableConnectionKeepAliveChk = new JCheckBox(i18n.ENABLE_KEEP_ALIVE_MSG);
enableConnectionKeepAliveChk.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
{
sleepForLabel.setEnabled(enableConnectionKeepAliveChk.isSelected());
sleepTime.setEnabled(enableConnectionKeepAliveChk.isSelected());
secondsLabel.setEnabled(enableConnectionKeepAliveChk.isSelected());
executeLabel.setEnabled(enableConnectionKeepAliveChk.isSelected());
sqlTextArea.setEnabled(enableConnectionKeepAliveChk.isSelected());
}
});
}
}
|