use of com.cubrid.cubridmanager.ui.host.dialog.MultiHostEditDialog in project cubrid-manager by CUBRID.
the class EditHostAction method doRun.
/**
* Perform do run
*
* @param obj
*/
public void doRun(CubridServer[] servers, boolean actionIsConnect) {
//multi edit
if (servers.length > 1) {
MultiHostEditDialog dialog = new MultiHostEditDialog(getShell(), Arrays.asList(servers));
if (dialog.open() != MultiHostEditDialog.SAVE_ID) {
return;
}
BrokerIntervalSettingManager brokerManager = BrokerIntervalSettingManager.getInstance();
//new server infolist
List<CubridServer> newServerInfoList = dialog.getNewServerList();
for (int i = 0; i < servers.length; i++) {
CubridServer newServer = newServerInfoList.get(i);
CubridServer server = servers[i];
if (server == null) {
continue;
}
// if the server is not changed, ignore it.
if (!checkServerChanges(newServer, server)) {
continue;
}
ServerInfo oldServerInfo = server.getServerInfo();
if (oldServerInfo == null) {
LOGGER.error("oldServerInfo is null.");
continue;
}
ServerInfo newServerInfo = newServer.getServerInfo();
if (newServerInfo == null) {
LOGGER.error("newServerInfo is null.");
continue;
}
if (!newServerInfo.getServerName().equals(server.getLabel())) {
QueryOptions.removePref(server.getServerInfo());
brokerManager.removeAllBrokerIntervalSettingInServer(server.getLabel());
}
if (oldServerInfo.isConnected()) {
HostUtils.processHostDisconnected(server);
}
server.setAutoSavePassword(newServer.isAutoSavePassword());
server.getServerInfo().setServerName(newServerInfo.getServerName());
server.getServerInfo().setHostAddress(newServerInfo.getHostAddress());
server.getServerInfo().setHostMonPort(newServerInfo.getHostMonPort());
server.getServerInfo().setJdbcDriverVersion(newServerInfo.getJdbcDriverVersion());
server.getServerInfo().setUserName(newServerInfo.getUserName());
if (newServer.isAutoSavePassword()) {
server.getServerInfo().setUserPassword(newServerInfo.getUserPassword());
} else {
server.getServerInfo().setUserPassword(null);
}
server.setId(newServerInfo.getServerName());
server.setLabel(newServerInfo.getServerName());
CMHostNodePersistManager.getInstance().addServer(newServerInfo.getHostAddress(), newServerInfo.getHostMonPort(), newServerInfo.getUserName(), newServerInfo);
CMGroupNodePersistManager.getInstance().saveAllGroupNode();
CMHostNodePersistManager.getInstance().saveServers();
if (server.getLoader() != null) {
server.getLoader().setLoaded(false);
}
CubridWorkbenchContrItem.closeAllEditorAndViewInServer(server, false);
CubridNavigatorView navigatorView = CubridNavigatorView.getNavigatorView(CubridHostNavigatorView.ID);
if (navigatorView != null) {
navigatorView.getViewer().refresh(server, true);
}
CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent(server, CubridNodeChangedEventType.SERVER_DISCONNECTED));
}
return;
}
// single edit
HostDialog dialog = new HostDialog(getShell(), false, actionIsConnect);
CubridServer server = null;
try {
server = servers[0];
//read it from hostgroup preference first
if (server.getParent() == null) {
CMGroupNodePersistManager.getInstance();
}
} catch (ClassCastException cce) {
CubridGroupNode node = (CubridGroupNode) getSelectedObj()[0];
for (ICubridNode icNode : node.getChildren()) {
if (icNode instanceof CubridServer) {
if (!((CubridServer) icNode).isConnected())
server = (CubridServer) icNode;
}
}
}
ServerInfo oldServerInfo = server.getServerInfo();
if (oldServerInfo == null) {
LOGGER.error("oldServerInfo is null.");
return;
}
dialog.setServer(server);
int returnCode = dialog.open();
if (returnCode != HostDialog.SAVE_ID && returnCode != HostDialog.CONNECT_ID) {
return;
}
// Save the server info
ServerInfo serverInfo = dialog.getServerInfo();
if (serverInfo == null) {
LOGGER.error("serverInfo is null.");
return;
}
if (!serverInfo.getServerName().equals(server.getLabel())) {
QueryOptions.removePref(server.getServerInfo());
BrokerIntervalSettingManager.getInstance().removeAllBrokerIntervalSettingInServer(server.getLabel());
}
if (oldServerInfo.isConnected() && !oldServerInfo.equals(serverInfo)) {
HostUtils.processHostDisconnected(server);
}
server.setId(serverInfo.getServerName());
server.setLabel(serverInfo.getServerName());
server.setServerInfo(serverInfo);
server.setAutoSavePassword(dialog.isSavePassword());
CMHostNodePersistManager.getInstance().addServer(serverInfo.getHostAddress(), serverInfo.getHostMonPort(), serverInfo.getUserName(), serverInfo);
// Refresh the tree node
if (returnCode == HostDialog.CONNECT_ID) {
ISelectionProvider provider = getSelectionProvider();
if (provider instanceof TreeViewer) {
server.removeAllChild();
if (server.getLoader() != null) {
server.getLoader().setLoaded(false);
}
TreeViewer treeViewer = (TreeViewer) provider;
treeViewer.refresh(server, true);
treeViewer.expandToLevel(server, 1);
treeViewer.setSelection(null, true);
treeViewer.setSelection(new StructuredSelection(server), true);
setEnabled(false);
}
}
CMGroupNodePersistManager.getInstance().saveAllGroupNode();
CMHostNodePersistManager.getInstance().saveServers();
ActionManager.getInstance().fireSelectionChanged(getSelection());
LayoutManager.getInstance().fireSelectionChanged(getSelection());
CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent(server, CubridNodeChangedEventType.SERVER_CONNECTED));
}
Aggregations