Modified:
trunk/objectmanager-swing/src/com/db4o/objectManager/v2/configuration/ConfigurationDialog.java
trunk/objectmanager-swing/src/com/db4o/objectManager/v2/configuration/ConfigurationPanel.java
trunk/objectmanager-swing/src/com/db4o/objectManager/v2/connections/ConnectionForm.java
Log:
Support to save configuration
Modified: trunk/objectmanager-swing/src/com/db4o/objectManager/v2/configuration/ConfigurationDialog.java
==============================================================================
---
trunk/objectmanager-swing/src/com/db4o/objectManager/v2/configuration/ConfigurationDialog.java (original)
+++
trunk/objectmanager-swing/src/com/db4o/objectManager/v2/configuration/ConfigurationDialog.java
Sun Apr 20 18:18:27 2008
@@ -13,11 +13,14 @@
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
+import javax.swing.UIManager;
import com.db4o.config.Configuration;
+import com.db4o.objectManager.v2.MainFrame;
import com.db4o.objectManager.v2.custom.BackgroundPanel;
import com.db4o.objectManager.v2.resources.ResourceManager;
import com.db4o.objectmanager.configuration.ConfigurationFacade;
+import com.jgoodies.looks.Options;
import java.awt.BorderLayout;
import java.awt.Dimension;
@@ -27,22 +30,27 @@
private final String TITLE="Configuration";
private ConfigurationPanel configurationPanel = null;
private BackgroundPanel mainPanel;
-
+ private ConfigurationFacade configuration;
+
/**
* This method initializes
*
*/
- public ConfigurationDialog() {
+ public ConfigurationDialog(ConfigurationFacade configuration) {
super();
+ this.configuration = configuration;
initialize();
this.setModal(true);
}
+
+
/**
* This method initializes this
*
*/
private void initialize() {
+ configureUI();
this.setSize(new Dimension(484, 289));
this.setContentPane(getConfigurationPanel());
this.setIconImage(ResourceManager.createImageIcon(ResourceManager.ICONS_PLAIN_16X16 + "configure.png", "configure").getImage());
@@ -54,6 +62,21 @@
}
});
}
+
+ /**
+ *
+ */
+ private void configureUI() {
+ UIManager.put(Options.USE_SYSTEM_FONTS_APP_KEY, Boolean.TRUE);
+ Options.setDefaultIconSize(new Dimension(18, 18));
+ String lafName = Options.getSystemLookAndFeelClassName();
+ try {
+ UIManager.setLookAndFeel(lafName);
+ } catch (Exception e) {
+ System.err.println("Can't set look & feel:" + e);
+ }
+ }
+
/**
* This method initializes configurationPanel
@@ -63,7 +86,7 @@
private JPanel getConfigurationPanel() {
if (configurationPanel == null) {
mainPanel = new BackgroundPanel();
- configurationPanel = new ConfigurationPanel(this);
+ configurationPanel = new ConfigurationPanel(this,configuration);
mainPanel.add(configurationPanel.buildPanel());
}
return mainPanel;
Modified: trunk/objectmanager-swing/src/com/db4o/objectManager/v2/configuration/ConfigurationPanel.java
==============================================================================
---
trunk/objectmanager-swing/src/com/db4o/objectManager/v2/configuration/ConfigurationPanel.java (original)
+++
trunk/objectmanager-swing/src/com/db4o/objectManager/v2/configuration/ConfigurationPanel.java
Sun Apr 20 18:18:27 2008
@@ -10,10 +10,14 @@
import java.awt.*;
import java.awt.event.*;
import java.io.*;
+
import javax.swing.*;
import javax.swing.filechooser.*;
import com.db4o.Db4o;
import com.db4o.config.Configuration;
+import com.db4o.objectManager.v2.Dashboard;
+import com.db4o.objectManager.v2.uiHelper.OptionPaneHelper;
+import com.db4o.objectmanager.api.helpers.SerializerHelper;
import com.db4o.objectmanager.configuration.*;
import com.jgoodies.forms.builder.*;
import com.jgoodies.forms.layout.*;
@@ -26,6 +30,7 @@
private JCheckBox _unicode;
private JCheckBox _lockDatabase;
private JCheckBox _callConstructors;
+ private JCheckBox _saveConfigurationBox;
private JTextField _encryptionPassword;
private JButton _buildConfiguration;
private ConfigurationFacade _configuration;
@@ -40,7 +45,16 @@
*/
public ConfigurationPanel() {
super();
- initialize();
+ initialize();
+ }
+
+ /**
+ * This method initializes
+ * @param configuration In memory configuration or stored configuration
+ */
+ public ConfigurationPanel(ConfigurationFacade configuration){
+ this();
+ _configuration = configuration;
}
/**
@@ -51,15 +65,41 @@
this();
_container = container;
}
+
+ /**
+ *
+ * @param container The form which contains the panel
+ */
+ public ConfigurationPanel(JDialog container,ConfigurationFacade currentConfiguration){
+ this(container);
+ this.configuration(currentConfiguration);
+ }
/**
* This method initializes this
*
*/
private void initialize() {
+ _configurationProvider = new ConfigurationProvider();
}
/**
+ * Get the configuration object built by the configuration window
+ * @return
+ */
+ public ConfigurationFacade configuration(){
+ return this._configuration;
+ }
+
+ /**
+ * Set the configuration object
+ * @param configurationConfigurationFacade
+ */
+ private void configuration(ConfigurationFacade configuration){
+ this._configuration = configuration;
+ }
+
+ /**
* Create all the UI elements for the configuration panel
*
* @return
@@ -99,9 +139,14 @@
builder.nextLine();
builder.append(buildConfiguration(),cancel());
+
+ builder.nextLine();
+
+ builder.append("",saveConfigurationBox());
panel = builder.getPanel();
panel.setOpaque(false);
+ applyConfiguration();
return panel;
}
@@ -136,6 +181,7 @@
private JCheckBox callConstructors() {
_callConstructors = new JCheckBox();
_callConstructors.setOpaque(false);
+ _callConstructors.setSelected(true);
return _callConstructors;
}
@@ -150,6 +196,18 @@
}
/**
+ * Create the checkbox to set if the configuration will be saved
+ *
+ * @return
+ */
+ private JCheckBox saveConfigurationBox() {
+ _saveConfigurationBox = new JCheckBox();
+ _saveConfigurationBox.setText("Save Configuration");
+ _saveConfigurationBox.setOpaque(false);
+ return _saveConfigurationBox;
+ }
+
+ /**
* Builds a label to append in the pannel
* @param text
* @return
@@ -175,13 +233,8 @@
int dialogResult = jarFileChooser.showDialog(_container, "Ok");
if (dialogResult == JFileChooser.APPROVE_OPTION) {
File file = jarFileChooser.getSelectedFile();
- JarLoader jarLoader = new JarLoader(file.getPath());
- EncryptionProviderComboBoxModel model = new EncryptionProviderComboBoxModel(
- jarLoader.getClasses(file.getPath()));
- _encryptionProvider.setModel(model);
- if(model.getDataSource().size() > 0)
- _encryptionProvider.setSelectedIndex(0);
- _encryptionProvider.setRenderer(new EncryptionProviderComboBoxRenderer());
+ String path = file.getPath();
+ loadEncryptionProvider(path);
}
}
});
@@ -190,6 +243,24 @@
/**
*
+ * @param path
+ */
+ private boolean loadEncryptionProvider(String path) {
+ if(!new File(path).exists())
+ return false;
+ JarLoader jarLoader = new JarLoader(path);
+ EncryptionProviderComboBoxModel model = new EncryptionProviderComboBoxModel(
+ jarLoader.getClasses(path));
+ _encryptionProvider.setModel(model);
+ if(model.getDataSource().size() > 0)
+ _encryptionProvider.setSelectedIndex(0);
+ _encryptionProvider.setRenderer(new EncryptionProviderComboBoxRenderer());
+ _configurationProvider.encryptionProviderPath(path);
+ return true;
+ }
+
+ /**
+ *
* @return
*/
private JButton cancel(){
@@ -239,18 +310,20 @@
_buildConfiguration = new JButton("Ok");
_buildConfiguration.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
- _configurationProvider = new ConfigurationProvider();
+
_configurationProvider.unicodeEnabled(_unicode.isSelected());
_configurationProvider.lockDatabase(_lockDatabase.isSelected());
_configurationProvider.callConstructors(_callConstructors.isSelected());
+ _configurationProvider.encryptionPassword(_encryptionPassword.getText());
try {
_configurationProvider.encryptionProvider(
EncryptionProviderHandler.getEncryptionProvider((Class) _encryptionProvider.getSelectedItem(),
- _encryptionPassword.getText()));
+ _encryptionPassword.getText()));
} catch (Exception ex) {
JOptionPane.showMessageDialog(null, "Can't create an instance of
the Encryption Provider");
}
configuration(_configurationProvider.buildConfiguration());
+ saveConfiguration(configuration());
_container.setVisible(false);
_container.dispose();
}
@@ -260,18 +333,35 @@
}
/**
- * Get the configuration object built by the configuration window
- * @return
+ *
+ * @param configuration
*/
- public ConfigurationFacade configuration(){
- return this._configuration;
+ private void saveConfiguration(ConfigurationFacade configuration){
+ if(!_saveConfigurationBox.isSelected())
+ return;
+ try {
+ SerializerHelper.Serialize(configuration, ConfigurationFacade.CONFIGURATION_FILE_PATH);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
}
-
+
/**
- * Set the configuration object
- * @param configurationConfigurationFacade
+ * Applies the configuration if it exists
*/
- private void configuration(ConfigurationFacade configuration){
- this._configuration = configuration;
+ public void applyConfiguration()
+ {
+ if(_configuration == null)
+ return;
+ _unicode.setSelected(_configuration.unicode());
+ _callConstructors.setSelected(_configuration.callConstructors());
+ _lockDatabase.setSelected(_configuration.lockDatabaseFile());
+ _encryptionPassword.setText(_configuration.encryptionPassword());
+ if(_configuration.encriptionProviderPath() != null &&
_configuration.encriptionProviderPath().trim().length() > 0){
+ if(!loadEncryptionProvider(_configuration.encriptionProviderPath())){
+ OptionPaneHelper.showErrorMessage(_container, "The file " +
_configuration.encriptionProviderPath() + "could not be opened, please
load again your encryption provider.", "Encryption provider not found");
+ }
+ }
}
+
}
Modified: trunk/objectmanager-swing/src/com/db4o/objectManager/v2/connections/ConnectionForm.java
==============================================================================
---
trunk/objectmanager-swing/src/com/db4o/objectManager/v2/connections/ConnectionForm.java (original)
+++
trunk/objectmanager-swing/src/com/db4o/objectManager/v2/connections/ConnectionForm.java
Sun Apr 20 18:18:27 2008
@@ -7,6 +7,7 @@
import com.db4o.objectmanager.model.Db4oConnectionSpec;
import com.db4o.objectmanager.model.Db4oFileConnectionSpec;
import com.db4o.objectmanager.model.Db4oSocketConnectionSpec;
+import com.db4o.objectmanager.api.helpers.SerializerHelper;
import com.db4o.objectmanager.api.prefs.Preferences;
import com.db4o.objectmanager.configuration.ConfigurationFacade;
import com.db4o.ObjectContainer;
@@ -22,6 +23,7 @@
import java.awt.*;
import java.awt.event.*;
import java.io.File;
+import java.io.IOException;
/**
* User: treeder
@@ -102,7 +104,7 @@
configurationButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
//JOptionPane.showMessageDialog(null, "Configure database");
- ConfigurationDialog configurationForm = new ConfigurationDialog();
+ ConfigurationDialog configurationForm = new ConfigurationDialog(configuration);
configurationForm.setAlwaysOnTop(true);
UIHelper.CenterFormInScreen(configurationForm, configurationForm.getToolkit());
configurationForm.setVisible(true);
@@ -110,8 +112,14 @@
}
});
+ JButton clearConfigurationButton = new JButton("Clear");
+ clearConfigurationButton.addActionListener(new ActionListener(){
+ public void actionPerformed(ActionEvent e){
+ configuration = null;
+ }
+ });
- builder.append("",configurationButton);
+ builder.append("",configurationButton,clearConfigurationButton);
builder.nextLine();
@@ -119,7 +127,7 @@
fileTextField = new JTextField();
builder.append("File:", fileTextField);
final JFileChooser fc = new JFileChooser();
- final Button browse = new Button("Browse");
+ final JButton browse = new JButton("Browse");
browse.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
//Handle open button action.
@@ -176,9 +184,22 @@
}
});
builder.append("", connectButton);
-
+ LoadConfiguration();
panel = builder.getPanel();
panel.setOpaque(false);
+ }
+
+ private void LoadConfiguration(){
+ try {
+ Object result = SerializerHelper.Deserialize(ConfigurationFacade.CONFIGURATION_FILE_PATH);
+ if(result != null)
+ configuration = (ConfigurationFacade) result;
+ } catch (IOException e) {
+ e.printStackTrace();
+ //File not found
+ } catch (ClassNotFoundException e) {
+ e.printStackTrace();
+ }
}
public void connectToFile(String dataFile) {