diff --git a/src/main/java/de/marhali/easyi18n/InstanceManager.java b/src/main/java/de/marhali/easyi18n/InstanceManager.java index 41ec935..129f1be 100644 --- a/src/main/java/de/marhali/easyi18n/InstanceManager.java +++ b/src/main/java/de/marhali/easyi18n/InstanceManager.java @@ -65,8 +65,10 @@ public class InstanceManager { if(success) { this.bus.propagate().onUpdateData(this.store.getData()); - if(!update.isDeletion()) { // TODO: maybe focus parent if key was deleted + if(!update.isDeletion()) { this.bus.propagate().onFocusKey(update.getChange().getKey()); + } else { + this.bus.propagate().onFocusKey(update.getOrigin().getKey()); } } }); diff --git a/src/main/java/de/marhali/easyi18n/tabs/TreeView.java b/src/main/java/de/marhali/easyi18n/tabs/TreeView.java index 55bce06..aeda7c1 100644 --- a/src/main/java/de/marhali/easyi18n/tabs/TreeView.java +++ b/src/main/java/de/marhali/easyi18n/tabs/TreeView.java @@ -87,7 +87,12 @@ public class TreeView implements BusListener { @Override public void onFocusKey(@Nullable String key) { if(key != null && currentMapper != null) { - this.tree.scrollPathToVisible(currentMapper.findTreePath(key)); + TreePath path = currentMapper.findTreePath(key); + this.tree.scrollPathToVisible(path); + + if(this.tree.isCollapsed(path)) { + this.tree.expandPath(path); + } } } diff --git a/src/main/java/de/marhali/easyi18n/tabs/mapper/TreeModelMapper.java b/src/main/java/de/marhali/easyi18n/tabs/mapper/TreeModelMapper.java index d1e4670..c841799 100644 --- a/src/main/java/de/marhali/easyi18n/tabs/mapper/TreeModelMapper.java +++ b/src/main/java/de/marhali/easyi18n/tabs/mapper/TreeModelMapper.java @@ -14,6 +14,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import javax.swing.tree.*; +import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -111,19 +112,22 @@ public class TreeModelMapper extends DefaultTreeModel implements SearchQueryList public @NotNull TreePath findTreePath(@NotNull String fullPath) { List sections = new PathUtil(this.state.isNestedKeys()).split(fullPath); - Object[] nodes = new Object[sections.size() + 1]; + List nodes = new ArrayList<>(); - int pos = 0; TreeNode currentNode = (TreeNode) this.getRoot(); - nodes[pos] = currentNode; + nodes.add(currentNode); for(String section : sections) { - pos++; currentNode = this.findNode(currentNode, section); - nodes[pos] = currentNode; + + if(currentNode == null) { + break; + } + + nodes.add(currentNode); } - return new TreePath(nodes); + return new TreePath(nodes.toArray()); } public @Nullable DefaultMutableTreeNode findNode(@NotNull TreeNode parent, @NotNull String key) { @@ -144,6 +148,6 @@ public class TreeModelMapper extends DefaultTreeModel implements SearchQueryList } } - throw new NullPointerException("Cannot find node by key: " + key); + return null; } } \ No newline at end of file