Skip to content

Commit

Permalink
fixing logic for updating server after Server Edit dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
dzmipt committed Mar 15, 2024
1 parent ef4d49b commit ddf77b9
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
25 changes: 25 additions & 0 deletions src/studio/kdb/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,31 @@ public void removeServer(Server server) {
saveAllServers();
}

public void replaceServer(Server oldServer, Server newServer) {
ServerTreeNode oldFolder = serverTree.findPath(oldServer.getFolderPath(), false);
if (oldFolder == null) {
// ?? Is it possible
return;
}
ServerTreeNode newFolder = serverTree.findPath(newServer.getFolderPath(), true);

String name = oldServer.getFullName();
serverNames.remove(name);
servers.remove(name);
int index = oldFolder.remove(oldServer);
if (index == -1 || oldFolder!=newFolder) {
index = newFolder.getChildCount();
}

try {
addServerInternal(newServer);
newFolder.add(index, newServer);
} catch (IllegalArgumentException e) {
log.error("Failed to add server", e);
addServer(oldServer);
}
}

private void purgeAll() {
servers.clear();
serverNames.clear();
Expand Down
6 changes: 3 additions & 3 deletions src/studio/kdb/ServerTreeNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public ServerTreeNode add(int index, String folder) {
}

// Remove direct child
public boolean remove(Server server) {
public int remove(Server server) {
if (!isFolder()) {
throw new IllegalArgumentException("This is not folder");
}
Expand All @@ -89,10 +89,10 @@ public boolean remove(Server server) {
if (treeNode.isFolder()) continue;
if (treeNode.getServer().equals(server)) {
remove(index);
return true;
return index;
}
}
return false;
return -1;
}

public ServerTreeNode getChild(String folder) {
Expand Down
4 changes: 1 addition & 3 deletions src/studio/ui/StudioWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -556,10 +556,8 @@ private void initActions() {
if (stopAction.isEnabled())
stopAction.actionPerformed(e);

CONFIG.removeServer(editor.getServer());

Server newServer = f.getServer();
CONFIG.addServer(newServer);
CONFIG.replaceServer(editor.getServer(), newServer);
setServer(newServer);
refreshAll();
}
Expand Down

0 comments on commit ddf77b9

Please sign in to comment.