Skip to content

Commit ba838ad

Browse files
committed
expand child nodes after refreshing the node
1 parent 37ce485 commit ba838ad

File tree

4 files changed

+42
-1
lines changed

4 files changed

+42
-1
lines changed

PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/intellij/components/ServerExplorerToolWindowFactory.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,10 @@ else if (e.getKeyCode() == KeyEvent.VK_CONTEXT_MENU) {
143143
// add the tree to the window
144144
toolWindow.getComponent().add(new JBScrollPane(tree));
145145

146+
// set tree and tree path to expand the node later
147+
azureModule.setTree(tree);
148+
azureModule.setTreePath(tree.getPathForRow(0));
149+
146150
// setup toolbar icons
147151
addToolbarItems(toolWindow, azureModule);
148152

@@ -170,6 +174,10 @@ private void treeMousePressed(MouseEvent e, JTree tree) {
170174
SortableTreeNode treeNode = (SortableTreeNode) treePath.getLastPathComponent();
171175
Node node = (Node) treeNode.getUserObject();
172176

177+
// set tree and tree path to expand the node later
178+
node.setTree(tree);
179+
node.setTreePath(treePath);
180+
173181
// delegate click to the node's click action if this is a left button click
174182
if (SwingUtilities.isLeftMouseButton(e)) {
175183
// if the node in question is in a "loading" state then we

Utils/azure-explorer-common/src/com/microsoft/tooling/msservices/serviceexplorer/Node.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
import com.microsoft.tooling.msservices.helpers.Name;
3131
import com.microsoft.tooling.msservices.helpers.collections.ObservableList;
3232

33+
import javax.swing.*;
34+
import javax.swing.tree.TreePath;
3335
import java.beans.PropertyChangeListener;
3436
import java.beans.PropertyChangeSupport;
3537
import java.lang.reflect.Constructor;
@@ -51,7 +53,9 @@ public class Node implements MvpView {
5153
protected Object viewData;
5254
protected NodeAction clickAction = new NodeAction(this, CLICK_ACTION);
5355
protected List<NodeAction> nodeActions = new ArrayList<NodeAction>();
54-
56+
protected JTree tree;
57+
protected TreePath treePath;
58+
5559
// marks this node as being in a "loading" state; when this field is true
5660
// the following consequences apply:
5761
// [1] all actions associated with this node get disabled
@@ -83,6 +87,22 @@ public String getId() {
8387
return id;
8488
}
8589

90+
public JTree getTree() {
91+
return tree;
92+
}
93+
94+
public void setTree(JTree tree) {
95+
this.tree = tree;
96+
}
97+
98+
public TreePath getTreePath() {
99+
return treePath;
100+
}
101+
102+
public void setTreePath(TreePath treePath) {
103+
this.treePath = treePath;
104+
}
105+
86106
public String getName() {
87107
return name;
88108
}

Utils/azure-explorer-common/src/com/microsoft/tooling/msservices/serviceexplorer/RefreshableNode.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
import com.microsoft.azuretools.azurecommons.helpers.AzureCmdException;
3030
import com.microsoft.azuretools.core.mvp.ui.base.NodeContent;
3131

32+
import javax.swing.*;
33+
import javax.swing.tree.TreePath;
3234
import java.util.ArrayList;
3335
import java.util.HashMap;
3436
import java.util.List;
@@ -70,6 +72,8 @@ public List<NodeAction> getNodeActions() {
7072
protected void onNodeClick(NodeActionEvent e) {
7173
if (!initialized) {
7274
this.load(false);
75+
} else {
76+
expandNodeAfterLoading();
7377
}
7478
}
7579

@@ -106,6 +110,12 @@ protected void refreshFromAzure() throws Exception {
106110
protected void updateNodeNameAfterLoading() {
107111
}
108112

113+
protected void expandNodeAfterLoading() {
114+
if (tree != null && treePath != null) {
115+
tree.expandPath(treePath);
116+
}
117+
}
118+
109119
public ListenableFuture<List<Node>> load(boolean forceRefresh) {
110120
initialized = true;
111121
final RefreshableNode node = this;
@@ -125,12 +135,14 @@ public void run() {
125135
public void onSuccess(List<Node> nodes) {
126136
updateName(nodeName, null);
127137
updateNodeNameAfterLoading();
138+
expandNodeAfterLoading();
128139
}
129140

130141
@Override
131142
public void onFailure(Throwable throwable) {
132143
updateName(nodeName, throwable);
133144
updateNodeNameAfterLoading();
145+
expandNodeAfterLoading();
134146
}
135147
});
136148
node.refreshItems(future, forceRefresh);

Utils/azure-explorer-common/src/com/microsoft/tooling/msservices/serviceexplorer/azure/AzureModule.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ protected void refreshItems() throws AzureCmdException {
165165

166166
@Override
167167
protected void onNodeClick(NodeActionEvent e) {
168+
super.onNodeClick(e);
168169
}
169170

170171
@Override

0 commit comments

Comments
 (0)