|
|
@ -1,11 +1,11 @@ |
|
|
|
package com.fr.design.data.datapane.connect; |
|
|
|
package com.fr.design.data.datapane.connect; |
|
|
|
|
|
|
|
|
|
|
|
import com.fr.base.Env; |
|
|
|
|
|
|
|
import com.fr.base.FRContext; |
|
|
|
import com.fr.base.FRContext; |
|
|
|
import com.fr.data.impl.AbstractDatabaseConnection; |
|
|
|
import com.fr.data.impl.AbstractDatabaseConnection; |
|
|
|
import com.fr.data.impl.Connection; |
|
|
|
import com.fr.data.impl.Connection; |
|
|
|
import com.fr.data.impl.NameDatabaseConnection; |
|
|
|
import com.fr.data.impl.NameDatabaseConnection; |
|
|
|
import com.fr.design.DesignerEnvManager; |
|
|
|
import com.fr.design.DesignerEnvManager; |
|
|
|
|
|
|
|
import com.fr.design.actions.server.ConnectionListAction; |
|
|
|
import com.fr.design.dialog.BasicDialog; |
|
|
|
import com.fr.design.dialog.BasicDialog; |
|
|
|
import com.fr.design.dialog.DialogActionAdapter; |
|
|
|
import com.fr.design.dialog.DialogActionAdapter; |
|
|
|
import com.fr.file.DatasourceManager; |
|
|
|
import com.fr.file.DatasourceManager; |
|
|
@ -17,6 +17,7 @@ import javax.swing.*; |
|
|
|
import java.awt.event.ItemEvent; |
|
|
|
import java.awt.event.ItemEvent; |
|
|
|
import java.awt.event.ItemListener; |
|
|
|
import java.awt.event.ItemListener; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.ArrayList; |
|
|
|
|
|
|
|
import java.util.Iterator; |
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -31,7 +32,7 @@ public class ConnectionComboBoxPanel extends ItemEditableComboBoxPanel { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private static final long serialVersionUID = 1L; |
|
|
|
private static final long serialVersionUID = 1L; |
|
|
|
private Class<? extends Connection> cls; // 所取的Connection都是cls及其子类
|
|
|
|
private Class<? extends Connection> cls; // 所取的Connection都是cls及其子类
|
|
|
|
private java.util.List<String> nameList = new ArrayList<String>(); |
|
|
|
private List<String> nameList = new ArrayList<String>(); |
|
|
|
|
|
|
|
|
|
|
|
public ConnectionComboBoxPanel(Class<? extends Connection> cls) { |
|
|
|
public ConnectionComboBoxPanel(Class<? extends Connection> cls) { |
|
|
|
super(); |
|
|
|
super(); |
|
|
@ -53,11 +54,11 @@ public class ConnectionComboBoxPanel extends ItemEditableComboBoxPanel { |
|
|
|
/* |
|
|
|
/* |
|
|
|
* 刷新ComboBox.items |
|
|
|
* 刷新ComboBox.items |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
protected java.util.Iterator<String> items() { |
|
|
|
protected Iterator<String> items() { |
|
|
|
nameList = new ArrayList<String>(); |
|
|
|
nameList = new ArrayList<String>(); |
|
|
|
|
|
|
|
|
|
|
|
DatasourceManagerProvider mgr = DatasourceManager.getProviderInstance(); |
|
|
|
DatasourceManagerProvider mgr = DatasourceManager.getProviderInstance(); |
|
|
|
java.util.Iterator<String> nameIt = mgr.getConnectionNameIterator(); |
|
|
|
Iterator<String> nameIt = mgr.getConnectionNameIterator(); |
|
|
|
while (nameIt.hasNext()) { |
|
|
|
while (nameIt.hasNext()) { |
|
|
|
String conName = nameIt.next(); |
|
|
|
String conName = nameIt.next(); |
|
|
|
Connection connection = mgr.getConnection(conName); |
|
|
|
Connection connection = mgr.getConnection(conName); |
|
|
@ -71,7 +72,6 @@ public class ConnectionComboBoxPanel extends ItemEditableComboBoxPanel { |
|
|
|
connection.addConnection(nameList, conName, new Class[]{AbstractDatabaseConnection.class}); |
|
|
|
connection.addConnection(nameList, conName, new Class[]{AbstractDatabaseConnection.class}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public int getConnectionSize() { |
|
|
|
public int getConnectionSize() { |
|
|
|
return nameList.size(); |
|
|
|
return nameList.size(); |
|
|
|
} |
|
|
|
} |
|
|
@ -86,25 +86,37 @@ public class ConnectionComboBoxPanel extends ItemEditableComboBoxPanel { |
|
|
|
protected void editItems() { |
|
|
|
protected void editItems() { |
|
|
|
final ConnectionListPane connectionListPane = new ConnectionListPane(); |
|
|
|
final ConnectionListPane connectionListPane = new ConnectionListPane(); |
|
|
|
final DatasourceManagerProvider datasourceManager = DatasourceManager.getProviderInstance(); |
|
|
|
final DatasourceManagerProvider datasourceManager = DatasourceManager.getProviderInstance(); |
|
|
|
|
|
|
|
final DatasourceManager backupManager = datasourceManager.getBackUpManager(); |
|
|
|
connectionListPane.populate(datasourceManager); |
|
|
|
connectionListPane.populate(datasourceManager); |
|
|
|
BasicDialog connectionListDialog = connectionListPane.showLargeWindow( |
|
|
|
final BasicDialog connectionListDialog = connectionListPane.showLargeWindow( |
|
|
|
SwingUtilities.getWindowAncestor(ConnectionComboBoxPanel.this), new DialogActionAdapter() { |
|
|
|
SwingUtilities.getWindowAncestor(ConnectionComboBoxPanel.this), null); |
|
|
|
|
|
|
|
connectionListDialog.addDialogActionListener(new DialogActionAdapter() { |
|
|
|
public void doOk() { |
|
|
|
public void doOk() { |
|
|
|
connectionListPane.update(datasourceManager); |
|
|
|
if (!connectionListPane.isNamePermitted()) { |
|
|
|
|
|
|
|
connectionListDialog.setDoOKSucceed(false); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (!ConnectionListAction.doWithDatasourceManager(datasourceManager, backupManager, connectionListPane, |
|
|
|
|
|
|
|
connectionListDialog)) { |
|
|
|
|
|
|
|
//如果更新失败,则不关闭对话框,也不写xml文件,并且将对话框定位在请重命名的那个对象页面
|
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
// marks:保存数据
|
|
|
|
// marks:保存数据
|
|
|
|
Env currentEnv = FRContext.getCurrentEnv(); |
|
|
|
ConnectionListAction.writeFile(datasourceManager); |
|
|
|
try { |
|
|
|
|
|
|
|
currentEnv.writeResource(datasourceManager); |
|
|
|
|
|
|
|
} catch (Exception ex) { |
|
|
|
|
|
|
|
FRContext.getLogger().error(ex.getMessage(), ex); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void doCancel() { |
|
|
|
|
|
|
|
datasourceManager.synchronizedWithServer(); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
connectionListDialog.setVisible(true); |
|
|
|
connectionListDialog.setVisible(true); |
|
|
|
refreshItems(); |
|
|
|
refreshItems(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void populate(com.fr.data.impl.Connection connection) { |
|
|
|
/** |
|
|
|
|
|
|
|
* @param connection 数据库链接 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public void populate(Connection connection) { |
|
|
|
editButton.setEnabled(FRContext.getCurrentEnv().isRoot()); |
|
|
|
editButton.setEnabled(FRContext.getCurrentEnv().isRoot()); |
|
|
|
if (connection instanceof NameDatabaseConnection) { |
|
|
|
if (connection instanceof NameDatabaseConnection) { |
|
|
|
this.setSelectedItem(((NameDatabaseConnection) connection).getName()); |
|
|
|
this.setSelectedItem(((NameDatabaseConnection) connection).getName()); |
|
|
|