Skip to content

Commit b77d462

Browse files
VoragoFylmTM
authored andcommitted
Use TreeNodeModelApi everywhere instead of DataSourceApi (#28)
* Use TreeNodeModelApi everywhere * Filter out datasources
1 parent 1245b64 commit b77d462

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

ui/jetbrains/src/main/java/com/neueda/jetbrains/plugin/graphdb/jetbrains/ui/datasource/interactions/DataSourceInteractions.java

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
import com.neueda.jetbrains.plugin.graphdb.jetbrains.component.datasource.state.DataSourceApi;
1212
import com.neueda.jetbrains.plugin.graphdb.jetbrains.ui.datasource.DataSourcesView;
1313
import com.neueda.jetbrains.plugin.graphdb.jetbrains.ui.datasource.interactions.neo4j.bolt.Neo4jBoltDataSourceDialog;
14+
import com.neueda.jetbrains.plugin.graphdb.jetbrains.ui.datasource.tree.Neo4jTreeNodeType;
15+
import com.neueda.jetbrains.plugin.graphdb.jetbrains.ui.datasource.tree.TreeNodeModelApi;
1416
import com.neueda.jetbrains.plugin.graphdb.jetbrains.util.FileUtil;
1517
import com.neueda.jetbrains.plugin.graphdb.jetbrains.util.Notifier;
1618

@@ -57,10 +59,10 @@ private void initAddAction() {
5759
private void initRemoveAction() {
5860
decorator.setRemoveAction(anActionButton -> {
5961
DefaultMutableTreeNode[] selectedNodes = dataSourceTree.getSelectedNodes(DefaultMutableTreeNode.class,
60-
(node) -> node.getUserObject() instanceof DataSourceApi);
62+
this::isDataSource);
6163

6264
List<DataSourceApi> dataSourcesForRemoval = Arrays.stream(selectedNodes)
63-
.map((node) -> (DataSourceApi) node.getUserObject())
65+
.map(this::getDataSourceApi)
6466
.collect(Collectors.toList());
6567

6668
if (dataSourcesForRemoval.size() > 0) {
@@ -69,7 +71,7 @@ private void initRemoveAction() {
6971
});
7072
decorator.setRemoveActionUpdater(e -> {
7173
DefaultMutableTreeNode[] selectedNodes = dataSourceTree.getSelectedNodes(DefaultMutableTreeNode.class,
72-
(node) -> node.getUserObject() instanceof DataSourceApi);
74+
this::isDataSource);
7375

7476
return selectedNodes.length > 0;
7577
});
@@ -78,18 +80,18 @@ private void initRemoveAction() {
7880
private void initEditAction() {
7981
decorator.setEditActionUpdater(e -> {
8082
DefaultMutableTreeNode[] selectedNodes = dataSourceTree.getSelectedNodes(DefaultMutableTreeNode.class,
81-
(node) -> node.getUserObject() instanceof DataSourceApi);
83+
this::isDataSource);
8284

8385
return selectedNodes.length == 1;
8486
});
8587
decorator.setEditAction(anActionButton -> {
8688
PatchedDefaultMutableTreeNode[] selectedNodes = dataSourceTree.getSelectedNodes(PatchedDefaultMutableTreeNode.class,
87-
(node) -> node.getUserObject() instanceof DataSourceApi);
89+
(node) -> node.getUserObject() instanceof TreeNodeModelApi);
8890

8991
if (selectedNodes.length == 1) {
9092
PatchedDefaultMutableTreeNode treeNode = selectedNodes[0];
9193

92-
DataSourceApi dataSourceToEdit = (DataSourceApi) treeNode.getUserObject();
94+
DataSourceApi dataSourceToEdit = getDataSourceApi(treeNode);
9395

9496
DataSourceDialog dialog = null;
9597
if (dataSourceToEdit.getDataSourceType().equals(DataSourceType.NEO4J_BOLT)) {
@@ -112,13 +114,13 @@ public void mouseClicked(MouseEvent e) {
112114
int clickCount = e.getClickCount();
113115
if (clickCount == 2) {
114116
DefaultMutableTreeNode[] selectedNodes = dataSourceTree.getSelectedNodes(DefaultMutableTreeNode.class,
115-
(node) -> node.getUserObject() instanceof DataSourceApi);
117+
DataSourceInteractions.this::isDataSource);
116118

117119
if (selectedNodes.length != 1) {
118120
return;
119121
}
120122

121-
DataSourceApi dataSource = (DataSourceApi) selectedNodes[0].getUserObject();
123+
DataSourceApi dataSource = getDataSourceApi(selectedNodes[0]);
122124
Analytics.event(dataSource, "openEditor");
123125

124126
try {
@@ -131,4 +133,13 @@ public void mouseClicked(MouseEvent e) {
131133
};
132134
dataSourceTree.addMouseListener(mouseAdapter);
133135
}
136+
137+
private boolean isDataSource(DefaultMutableTreeNode node) {
138+
return node.getUserObject() instanceof TreeNodeModelApi
139+
&& ((TreeNodeModelApi) node.getUserObject()).getType() == Neo4jTreeNodeType.DATASOURCE;
140+
}
141+
142+
private DataSourceApi getDataSourceApi(DefaultMutableTreeNode node) {
143+
return ((TreeNodeModelApi) node.getUserObject()).getDataSourceApi();
144+
}
134145
}

0 commit comments

Comments
 (0)