=== modified file 'DBDrivers/src/org/gephi/io/database/drivers/MySQLDriver.java' --- DBDrivers/src/org/gephi/io/database/drivers/MySQLDriver.java 2009-06-22 20:51:20 +0000 +++ DBDrivers/src/org/gephi/io/database/drivers/MySQLDriver.java 2010-05-04 16:26:52 +0000 @@ -43,4 +43,19 @@ public String toString() { return "MySQL"; } + + @Override + public boolean equals(Object obj) { + if (obj instanceof MySQLDriver) { + return ((MySQLDriver) obj).getPrefix().equals(getPrefix()); + } else { + return false; + } + } + + @Override + public int hashCode() { + return getPrefix().hashCode(); + } + } === modified file 'DBDrivers/src/org/gephi/io/database/drivers/SQLDriver.java' --- DBDrivers/src/org/gephi/io/database/drivers/SQLDriver.java 2009-06-22 20:51:20 +0000 +++ DBDrivers/src/org/gephi/io/database/drivers/SQLDriver.java 2010-05-04 15:25:56 +0000 @@ -20,6 +20,7 @@ */ package org.gephi.io.database.drivers; +import java.io.Serializable; import java.sql.Connection; import java.sql.SQLException; @@ -27,7 +28,7 @@ * * @author Mathieu Bastian */ -public interface SQLDriver { +public interface SQLDriver extends Serializable { public String getPrefix(); === modified file 'DBDrivers/src/org/gephi/io/database/drivers/SQLServerDriver.java' --- DBDrivers/src/org/gephi/io/database/drivers/SQLServerDriver.java 2009-06-22 20:51:20 +0000 +++ DBDrivers/src/org/gephi/io/database/drivers/SQLServerDriver.java 2010-05-04 16:27:21 +0000 @@ -44,4 +44,18 @@ public String toString() { return "SQL Server"; } + + @Override + public boolean equals(Object obj) { + if (obj instanceof SQLServerDriver) { + return ((SQLServerDriver) obj).getPrefix().equals(getPrefix()); + } else { + return false; + } + } + + @Override + public int hashCode() { + return getPrefix().hashCode(); + } } === modified file 'DesktopImport/src/org/gephi/desktop/importer/impl/Bundle.properties' --- DesktopImport/src/org/gephi/desktop/importer/impl/Bundle.properties 2010-04-02 15:34:54 +0000 +++ DesktopImport/src/org/gephi/desktop/importer/impl/Bundle.properties 2010-05-07 11:55:19 +0000 @@ -18,3 +18,10 @@ EdgeListPanel.database.text= EdgeListPanel.user\ name.text= EdgeListPanel.password.text= +EdgeListPanel.save.text=Save Configuration +EdgeListPanel.save.toolTipText= +EdgeListPanel.configNameLabel.text=Configuration Name: +EdgeListPanel.host.text= +EdgeListPanel.configName.text= +EdgeListPanel.remove.toolTipText= +EdgeListPanel.remove.text=Remove Configuration === added file 'DesktopImport/src/org/gephi/desktop/importer/impl/EdgeListDatabaseManager.java' --- DesktopImport/src/org/gephi/desktop/importer/impl/EdgeListDatabaseManager.java 1970-01-01 00:00:00 +0000 +++ DesktopImport/src/org/gephi/desktop/importer/impl/EdgeListDatabaseManager.java 2010-05-07 12:23:31 +0000 @@ -0,0 +1,139 @@ +/* +Copyright 2008 WebAtlas +Authors : Mathieu Bastian, Mathieu Jacomy, Julian Bilcke +Website : http://www.gephi.org + +This file is part of Gephi. + +Gephi is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +Gephi 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 General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Gephi. If not, see . + */ +package org.gephi.desktop.importer.impl; + +import java.io.EOFException; +import java.io.IOException; +import java.io.InputStream; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import org.gephi.io.importer.api.Database; +import org.openide.filesystems.FileObject; +import org.openide.util.lookup.ServiceProvider; +import org.gephi.io.importer.api.EdgeListDatabase; +import org.openide.filesystems.FileLock; +import org.openide.filesystems.FileUtil; + +/** + * + * @author Andre Panisson + */ +@ServiceProvider(service = EdgeListDatabaseManager.class) +public class EdgeListDatabaseManager { + + private FileObject databaseConfigurations; + private List edgeListDatabases = new ArrayList(); +// private Map nameToInstance = new HashMap(); + + public EdgeListDatabaseManager() { + load(); + } + + public Collection getEdgeListDatabases() { + return edgeListDatabases; + } + + public List getNames() { + List names = new ArrayList(); + for (Database db: edgeListDatabases) { + names.add(db.getName()); + } + return names; + } + + public void addDatabase(EdgeListDatabase db) { + edgeListDatabases.add(db); + } + + public boolean removeDatabase(EdgeListDatabase db) { + return edgeListDatabases.remove(db); + } + + public void persist() { + doPersist(); + } + + private void load() { + if (databaseConfigurations == null) { + databaseConfigurations = + FileUtil.getConfigFile("EdgeListDatabase"); + } + + if (databaseConfigurations != null) { + InputStream is = null; + + try { + is = databaseConfigurations.getInputStream(); + ObjectInputStream ois = new ObjectInputStream(is); + List unserialized = + (List) ois.readObject(); + if (unserialized!=null) + edgeListDatabases = unserialized; + + } catch (EOFException eofe) { + // Empty configuration: do nothing + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (ClassNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } finally { + if (is != null) + try { + is.close(); + } catch (IOException e) { + } + } + } + } + + private void doPersist() { + FileLock lock = null; + ObjectOutputStream ois = null; + + try { + if (databaseConfigurations != null) + databaseConfigurations.delete(); + + databaseConfigurations = FileUtil.getConfigRoot().createData("EdgeListDatabase"); + lock = databaseConfigurations.lock(); + + ois = new ObjectOutputStream(databaseConfigurations.getOutputStream(lock)); + ois.writeObject(edgeListDatabases); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } finally { + if (ois != null) { + try { + ois.close(); + } catch (IOException e) {} + } + if (lock != null) + lock.releaseLock(); + } + } + +} === modified file 'DesktopImport/src/org/gephi/desktop/importer/impl/EdgeListDatabaseUIImpl.java' --- DesktopImport/src/org/gephi/desktop/importer/impl/EdgeListDatabaseUIImpl.java 2010-01-21 23:57:26 +0000 +++ DesktopImport/src/org/gephi/desktop/importer/impl/EdgeListDatabaseUIImpl.java 2010-05-04 13:08:52 +0000 @@ -62,18 +62,7 @@ } public void unsetup() { - EdgeListDatabase selectedDB = (EdgeListDatabase) panel.getSelectedDatabase(); - selectedDB.setDBName(panel.dbTextField.getText()); - selectedDB.setHost(panel.hostTextField.getText()); - selectedDB.setPasswd(new String(panel.pwdTextField.getPassword())); - selectedDB.setPort(Integer.parseInt(panel.portTextField.getText())); - selectedDB.setUsername(panel.userTextField.getText()); - selectedDB.setSQLDriver(panel.getSelectedSQLDriver()); - selectedDB.setNodeQuery(panel.nodeQueryTextField.getText()); - selectedDB.setEdgeQuery(panel.edgeQueryTextField.getText()); - selectedDB.setNodeAttributesQuery(panel.nodeAttQueryTextField.getText()); - selectedDB.setEdgeAttributesQuery(panel.edgeAttQueryTextField.getText()); - this.database = selectedDB; + this.database = (EdgeListDatabase) panel.getSelectedDatabase(); panel = null; } === modified file 'DesktopImport/src/org/gephi/desktop/importer/impl/EdgeListPanel.form' --- DesktopImport/src/org/gephi/desktop/importer/impl/EdgeListPanel.form 2010-01-21 23:57:26 +0000 +++ DesktopImport/src/org/gephi/desktop/importer/impl/EdgeListPanel.form 2010-05-07 12:24:50 +0000 @@ -18,12 +18,7 @@ - - - - - - + @@ -36,25 +31,33 @@ + + - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + @@ -63,16 +66,20 @@ - + - + + + + + + - @@ -119,7 +126,12 @@ - + + + + + + @@ -131,9 +143,6 @@ - - - @@ -324,5 +333,52 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + === modified file 'DesktopImport/src/org/gephi/desktop/importer/impl/EdgeListPanel.java' --- DesktopImport/src/org/gephi/desktop/importer/impl/EdgeListPanel.java 2010-01-21 23:57:26 +0000 +++ DesktopImport/src/org/gephi/desktop/importer/impl/EdgeListPanel.java 2010-05-07 12:24:50 +0000 @@ -23,9 +23,9 @@ import java.sql.Connection; import java.sql.SQLException; import java.util.Collection; -import javax.swing.ComboBoxModel; + import javax.swing.DefaultComboBoxModel; -import javax.swing.event.ListDataListener; + import org.gephi.io.database.drivers.SQLDriver; import org.gephi.io.database.drivers.SQLUtils; import org.gephi.io.importer.api.Database; @@ -36,7 +36,6 @@ import org.netbeans.validation.api.ui.ValidationPanel; import org.openide.DialogDisplayer; import org.openide.NotifyDescriptor; -import org.openide.util.Lookup; /** * @@ -45,9 +44,13 @@ public class EdgeListPanel extends javax.swing.JPanel { private DatabaseType type; + private EdgeListDatabaseManager databaseManager; + + private static String NEW_CONFIGURATION_NAME = "New Configuration"; /** Creates new form EdgeListPanel */ public EdgeListPanel() { + databaseManager = new EdgeListDatabaseManager(); //Lookup.getDefault().lookup(EdgeListDatabaseManager.class); initComponents(); } @@ -61,6 +64,7 @@ ValidationGroup group = validationPanel.getValidationGroup(); //Validators + group.add(innerPanel.configNameTextField, Validators.REQUIRE_NON_EMPTY_STRING); group.add(innerPanel.hostTextField, Validators.HOST_NAME_OR_IP_ADDRESS); group.add(innerPanel.dbTextField, Validators.REQUIRE_NON_EMPTY_STRING); group.add(innerPanel.portTextField, Validators.REQUIRE_NON_EMPTY_STRING, @@ -72,8 +76,21 @@ } public Database getSelectedDatabase() { - ConfigurationComboModel model = (ConfigurationComboModel) configurationCombo.getModel(); - return model.selectedItem.db; + ConfigurationComboModel model = + (ConfigurationComboModel)configurationCombo.getModel(); + ConfigurationComboItem item = model.getSelectedItem(); + + populateEdgeListDatabase(item.db); + + // save the configuration if user changed the option New Configuration + if (item.equals(model.templateConfiguration) && + !NEW_CONFIGURATION_NAME.equals(item.db.getName())) { + databaseManager.addDatabase(item.db); + } + + databaseManager.persist(); + + return item.db; } public SQLDriver getSelectedSQLDriver() { @@ -89,6 +106,37 @@ this.type = type; configurationCombo.setModel(new EdgeListPanel.ConfigurationComboModel()); } + + private void populateForm(EdgeListDatabase db) { + configNameTextField.setText(db.getName()); + dbTextField.setText(db.getDBName()); + hostTextField.setText(db.getHost()); + portTextField.setText(db.getPort() == 0 ? "" : "" + db.getPort()); + userTextField.setText(db.getUsername()); + pwdTextField.setText(db.getPasswd()); +// driverComboBox.setSelectedItem(db.getSQLDriver()); + driverComboBox.getModel().setSelectedItem(db.getSQLDriver()); + nodeQueryTextField.setText(db.getNodeQuery()); + edgeQueryTextField.setText(db.getEdgeQuery()); + nodeAttQueryTextField.setText(db.getNodeAttributesQuery()); + edgeAttQueryTextField.setText(db.getEdgeAttributesQuery()); + } + + private void populateEdgeListDatabase(EdgeListDatabase db) { + db.setName(this.configNameTextField.getText()); + db.setDBName(this.dbTextField.getText()); + db.setHost(this.hostTextField.getText()); + db.setPasswd(new String(this.pwdTextField.getPassword())); + db.setPort(portTextField.getText() != null + && !"".equals(portTextField.getText()) ? + Integer.parseInt(portTextField.getText()) : 0); + db.setUsername(this.userTextField.getText()); + db.setSQLDriver(this.getSelectedSQLDriver()); + db.setNodeQuery(this.nodeQueryTextField.getText()); + db.setEdgeQuery(this.edgeQueryTextField.getText()); + db.setNodeAttributesQuery(this.nodeAttQueryTextField.getText()); + db.setEdgeAttributesQuery(this.edgeAttQueryTextField.getText()); + } /** This method is called from within the constructor to * initialize the form. @@ -122,13 +170,12 @@ edgeAttQueryTextField = new javax.swing.JTextField(); testConnection = new javax.swing.JButton(); pwdTextField = new javax.swing.JPasswordField(); + save = new javax.swing.JButton(); + configNameTextField = new javax.swing.JTextField(); + configNameLabel = new javax.swing.JLabel(); + remove = new javax.swing.JButton(); configurationCombo.setModel(new EdgeListPanel.ConfigurationComboModel()); - configurationCombo.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - configurationComboActionPerformed(evt); - } - }); configurationLabel.setText(org.openide.util.NbBundle.getMessage(EdgeListPanel.class, "EdgeListPanel.configurationLabel.text")); // NOI18N @@ -182,18 +229,37 @@ pwdTextField.setText(org.openide.util.NbBundle.getMessage(EdgeListPanel.class, "EdgeListPanel.password.text")); // NOI18N pwdTextField.setName("password"); // NOI18N + save.setText(org.openide.util.NbBundle.getMessage(EdgeListPanel.class, "EdgeListPanel.save.text")); // NOI18N + save.setToolTipText(org.openide.util.NbBundle.getMessage(EdgeListPanel.class, "EdgeListPanel.save.toolTipText")); // NOI18N + save.setPreferredSize(new java.awt.Dimension(65, 29)); + save.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + saveActionPerformed(evt); + } + }); + + configNameTextField.setText(org.openide.util.NbBundle.getMessage(EdgeListPanel.class, "EdgeListPanel.configName.text")); // NOI18N + configNameTextField.setName("configName"); // NOI18N + + configNameLabel.setText(org.openide.util.NbBundle.getMessage(EdgeListPanel.class, "EdgeListPanel.configNameLabel.text")); // NOI18N + + remove.setText(org.openide.util.NbBundle.getMessage(EdgeListPanel.class, "EdgeListPanel.remove.text")); // NOI18N + remove.setToolTipText(org.openide.util.NbBundle.getMessage(EdgeListPanel.class, "EdgeListPanel.remove.toolTipText")); // NOI18N + remove.setPreferredSize(new java.awt.Dimension(65, 29)); + remove.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + removeActionPerformed(evt); + } + }); + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addComponent(configurationLabel) - .addGap(67, 67, 67) - .addComponent(configurationCombo, 0, 442, Short.MAX_VALUE)) - .addGroup(layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) + .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(userLabel) .addComponent(pwdLabel) @@ -204,36 +270,47 @@ .addComponent(nodeQueryLabel) .addComponent(edgeQueryLabel) .addComponent(nodeAttQueyLabel) - .addComponent(edgeAttQueryLabel)) + .addComponent(edgeAttQueryLabel) + .addComponent(configNameLabel) + .addComponent(configurationLabel)) .addGap(22, 22, 22) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(edgeAttQueryTextField, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 443, Short.MAX_VALUE) - .addComponent(nodeAttQueryTextField, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 443, Short.MAX_VALUE) - .addComponent(edgeQueryTextField, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 443, Short.MAX_VALUE) - .addComponent(nodeQueryTextField, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 443, Short.MAX_VALUE) - .addComponent(portTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 443, Short.MAX_VALUE) - .addComponent(hostTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 443, Short.MAX_VALUE) - .addComponent(dbTextField, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 443, Short.MAX_VALUE) - .addComponent(userTextField, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 443, Short.MAX_VALUE) - .addGroup(layout.createSequentialGroup() - .addComponent(driverComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 216, Short.MAX_VALUE) - .addComponent(testConnection)) - .addComponent(pwdTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 443, Short.MAX_VALUE)))) + .addComponent(configurationCombo, 0, 448, Short.MAX_VALUE) + .addComponent(configNameTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 448, Short.MAX_VALUE) + .addComponent(edgeAttQueryTextField, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 448, Short.MAX_VALUE) + .addComponent(nodeAttQueryTextField, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 448, Short.MAX_VALUE) + .addComponent(edgeQueryTextField, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 448, Short.MAX_VALUE) + .addComponent(nodeQueryTextField, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 448, Short.MAX_VALUE) + .addComponent(portTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 448, Short.MAX_VALUE) + .addComponent(hostTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 448, Short.MAX_VALUE) + .addComponent(dbTextField, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 448, Short.MAX_VALUE) + .addComponent(userTextField, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 448, Short.MAX_VALUE) + .addComponent(driverComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(pwdTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 448, Short.MAX_VALUE))) + .addGroup(layout.createSequentialGroup() + .addComponent(save, javax.swing.GroupLayout.PREFERRED_SIZE, 142, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(remove, javax.swing.GroupLayout.PREFERRED_SIZE, 158, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(testConnection) + .addGap(5, 5, 5))) .addContainerGap()) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() - .addContainerGap() + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(configurationLabel) .addComponent(configurationCombo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGap(29, 29, 29) + .addGap(22, 22, 22) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(configNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(configNameLabel)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(driverLabel) - .addComponent(driverComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(testConnection)) + .addComponent(driverComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(9, 9, 9) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(hostLabel) @@ -270,7 +347,11 @@ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(edgeAttQueryLabel) .addComponent(edgeAttQueryTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(testConnection) + .addComponent(remove, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(save, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) ); }// //GEN-END:initComponents @@ -298,21 +379,78 @@ } }//GEN-LAST:event_testConnectionActionPerformed - private void configurationComboActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_configurationComboActionPerformed - ConfigurationComboModel model = (ConfigurationComboModel) configurationCombo.getModel(); - EdgeListDatabase selectedDatabase = model.getSelectedItem().db; - dbTextField.setText(selectedDatabase.getDBName()); - hostTextField.setText(selectedDatabase.getHost()); - portTextField.setText("" + selectedDatabase.getPort()); - userTextField.setText(selectedDatabase.getUsername()); - pwdTextField.setText(selectedDatabase.getPasswd()); - driverComboBox.setSelectedItem(selectedDatabase.getSQLDriver()); - nodeQueryTextField.setText(selectedDatabase.getNodeQuery()); - edgeQueryTextField.setText(selectedDatabase.getEdgeQuery()); - nodeAttQueryTextField.setText(selectedDatabase.getNodeAttributesQuery()); - edgeAttQueryTextField.setText(selectedDatabase.getEdgeAttributesQuery()); - }//GEN-LAST:event_configurationComboActionPerformed + private void saveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveActionPerformed + ConfigurationComboModel model = + (ConfigurationComboModel)configurationCombo.getModel(); + ConfigurationComboItem item = model.getSelectedItem(); + + if (item.equals(model.templateConfiguration)) { + + EdgeListDatabase db = (EdgeListDatabase) type.createDatabase(); + populateEdgeListDatabase(db); + + if (NEW_CONFIGURATION_NAME.equals(db.getName())) { + NotifyDescriptor.Message e = new NotifyDescriptor.Message( + "Please change Configuration Name.", + NotifyDescriptor.ERROR_MESSAGE); + DialogDisplayer.getDefault().notifyLater(e); + } else { + + databaseManager.addDatabase(db); + item = new ConfigurationComboItem(db); + // leaves New Configuration option always at end + model.insertElementAt(item, model.getSize()-1); + + databaseManager.persist(); + NotifyDescriptor.Message e = new NotifyDescriptor.Message( + "Configuration "+item.toString()+" successfully added.", + NotifyDescriptor.INFORMATION_MESSAGE); + DialogDisplayer.getDefault().notifyLater(e); + } + + + } else { + populateEdgeListDatabase(item.db); + databaseManager.persist(); + NotifyDescriptor.Message e = new NotifyDescriptor.Message( + "Configuration "+item.toString()+" successfully saved.", + NotifyDescriptor.INFORMATION_MESSAGE); + DialogDisplayer.getDefault().notifyLater(e); + } + // workaround to update combo text when config name changes + model.setSelectedItem(model.templateConfiguration); + model.setSelectedItem(item); + + }//GEN-LAST:event_saveActionPerformed + + private void removeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeActionPerformed + ConfigurationComboModel model = + (ConfigurationComboModel)configurationCombo.getModel(); + ConfigurationComboItem item = model.getSelectedItem(); + + if(databaseManager.removeDatabase(item.db)) { + + model.removeElement(item); + databaseManager.persist(); + NotifyDescriptor.Message e = new NotifyDescriptor.Message( + "Configuration "+item.toString()+" successfully removed.", + NotifyDescriptor.INFORMATION_MESSAGE); + DialogDisplayer.getDefault().notifyLater(e); + model.setSelectedItem(model.getElementAt(0)); + + } else { + + NotifyDescriptor.Message e = new NotifyDescriptor.Message( + "This configuration is not saved.", + NotifyDescriptor.ERROR_MESSAGE); + DialogDisplayer.getDefault().notifyLater(e); + } + + }//GEN-LAST:event_removeActionPerformed + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JLabel configNameLabel; + private javax.swing.JTextField configNameTextField; private javax.swing.JComboBox configurationCombo; private javax.swing.JLabel configurationLabel; private javax.swing.JLabel dbLabel; @@ -333,6 +471,8 @@ protected javax.swing.JTextField portTextField; private javax.swing.JLabel pwdLabel; protected javax.swing.JPasswordField pwdTextField; + private javax.swing.JButton remove; + private javax.swing.JButton save; private javax.swing.JButton testConnection; private javax.swing.JLabel userLabel; protected javax.swing.JTextField userTextField; @@ -341,70 +481,59 @@ public void initEvents() { } - private class ConfigurationComboModel implements ComboBoxModel { + private class ConfigurationComboModel extends DefaultComboBoxModel { - private ConfigurationComboItem[] items; - private ConfigurationComboItem selectedItem; + ConfigurationComboItem templateConfiguration; public ConfigurationComboModel() { + super(); + if (type != null) { - Collection configs = Lookup.getDefault().lookupAll(type.getDatabaseClass()); - items = new ConfigurationComboItem[configs.size() + 1]; - int i = 0; - for (Object db : configs) { - EdgeListDatabase dbe = (EdgeListDatabase) db; - ConfigurationComboItem item = new ConfigurationComboItem(); - item.db = dbe; - items[i] = item; - i++; + + Collection configs = databaseManager.getEdgeListDatabases(); + for (Database db : configs) { + EdgeListDatabase dbe = (EdgeListDatabase)db; + ConfigurationComboItem item = new ConfigurationComboItem(dbe); + this.insertElementAt(item, this.getSize()); } + + // add template configuration option at end EdgeListDatabase db = (EdgeListDatabase) type.createDatabase(); - ConfigurationComboItem item = new ConfigurationComboItem(); - item.db = db; - db.setName("New configuration"); - items[i] = item; - selectedItem = items[items.length - 1]; + populateEdgeListDatabase(db); + db.setName(NEW_CONFIGURATION_NAME); + templateConfiguration = new ConfigurationComboItem(db); + this.insertElementAt(templateConfiguration, this.getSize()); + + this.setSelectedItem(this.getElementAt(0)); } + } + @Override public void setSelectedItem(Object anItem) { - this.selectedItem = (ConfigurationComboItem) anItem; + ConfigurationComboItem item = (ConfigurationComboItem) anItem; + populateForm(item.db); + super.setSelectedItem(anItem); } + @Override public ConfigurationComboItem getSelectedItem() { - return selectedItem; - } - - public int getSize() { - return items.length; - } - - public Object getElementAt(int index) { - return items[index]; - } - - public void addListDataListener(ListDataListener l) { - } - - public void removeListDataListener(ListDataListener l) { + return (ConfigurationComboItem)super.getSelectedItem(); } } private class ConfigurationComboItem { - private EdgeListDatabase db; + private final EdgeListDatabase db; - public ConfigurationComboItem() { + public ConfigurationComboItem(EdgeListDatabase db) { + this.db = db; } public EdgeListDatabase getDb() { return db; } - public void setDb(EdgeListDatabase db) { - this.db = db; - } - @Override public String toString() { String name = db.getName(); === modified file 'DesktopImport/src/org/gephi/desktop/importer/layer.xml' --- DesktopImport/src/org/gephi/desktop/importer/layer.xml 2010-01-21 23:57:26 +0000 +++ DesktopImport/src/org/gephi/desktop/importer/layer.xml 2010-05-03 21:35:34 +0000 @@ -8,4 +8,6 @@ + + === modified file 'ImportAPI/src/org/gephi/io/importer/api/AbstractDatabase.java' --- ImportAPI/src/org/gephi/io/importer/api/AbstractDatabase.java 2010-01-21 23:57:26 +0000 +++ ImportAPI/src/org/gephi/io/importer/api/AbstractDatabase.java 2010-05-04 15:26:30 +0000 @@ -21,7 +21,6 @@ package org.gephi.io.importer.api; import org.gephi.io.database.drivers.SQLDriver; -import org.gephi.io.importer.api.PropertiesAssociations; /** * === modified file 'ImportAPI/src/org/gephi/io/importer/api/Database.java' --- ImportAPI/src/org/gephi/io/importer/api/Database.java 2010-01-21 23:57:26 +0000 +++ ImportAPI/src/org/gephi/io/importer/api/Database.java 2010-05-04 15:26:23 +0000 @@ -20,6 +20,8 @@ */ package org.gephi.io.importer.api; +import java.io.Serializable; + import org.gephi.io.database.drivers.SQLDriver; /** @@ -27,7 +29,7 @@ * * @author Mathieu Bastian */ -public interface Database { +public interface Database extends Serializable { public String getName(); === modified file 'ImportAPI/src/org/gephi/io/importer/api/PropertiesAssociations.java' --- ImportAPI/src/org/gephi/io/importer/api/PropertiesAssociations.java 2010-04-29 20:12:44 +0000 +++ ImportAPI/src/org/gephi/io/importer/api/PropertiesAssociations.java 2010-05-04 15:34:50 +0000 @@ -20,6 +20,7 @@ */ package org.gephi.io.importer.api; +import java.io.Serializable; import java.util.Iterator; import java.util.LinkedList; import java.util.List; @@ -28,7 +29,7 @@ * * @author Mathieu Bastian */ -public final class PropertiesAssociations { +public final class PropertiesAssociations implements Serializable { public enum NodeProperties { === modified file 'ImportAPI/src/org/gephi/io/importer/api/PropertyAssociation.java' --- ImportAPI/src/org/gephi/io/importer/api/PropertyAssociation.java 2010-01-21 23:57:26 +0000 +++ ImportAPI/src/org/gephi/io/importer/api/PropertyAssociation.java 2010-05-04 15:35:11 +0000 @@ -20,11 +20,13 @@ */ package org.gephi.io.importer.api; +import java.io.Serializable; + /** * * @author Mathieu Bastian */ -public final class PropertyAssociation { +public final class PropertyAssociation implements Serializable { private final Property property; private final String title;