11
11
import com .neueda .jetbrains .plugin .graphdb .jetbrains .component .datasource .state .DataSourceApi ;
12
12
import com .neueda .jetbrains .plugin .graphdb .jetbrains .ui .datasource .DataSourcesView ;
13
13
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 ;
14
16
import com .neueda .jetbrains .plugin .graphdb .jetbrains .util .FileUtil ;
15
17
import com .neueda .jetbrains .plugin .graphdb .jetbrains .util .Notifier ;
16
18
@@ -57,10 +59,10 @@ private void initAddAction() {
57
59
private void initRemoveAction () {
58
60
decorator .setRemoveAction (anActionButton -> {
59
61
DefaultMutableTreeNode [] selectedNodes = dataSourceTree .getSelectedNodes (DefaultMutableTreeNode .class ,
60
- ( node ) -> node . getUserObject () instanceof DataSourceApi );
62
+ this :: isDataSource );
61
63
62
64
List <DataSourceApi > dataSourcesForRemoval = Arrays .stream (selectedNodes )
63
- .map (( node ) -> ( DataSourceApi ) node . getUserObject () )
65
+ .map (this :: getDataSourceApi )
64
66
.collect (Collectors .toList ());
65
67
66
68
if (dataSourcesForRemoval .size () > 0 ) {
@@ -69,7 +71,7 @@ private void initRemoveAction() {
69
71
});
70
72
decorator .setRemoveActionUpdater (e -> {
71
73
DefaultMutableTreeNode [] selectedNodes = dataSourceTree .getSelectedNodes (DefaultMutableTreeNode .class ,
72
- ( node ) -> node . getUserObject () instanceof DataSourceApi );
74
+ this :: isDataSource );
73
75
74
76
return selectedNodes .length > 0 ;
75
77
});
@@ -78,18 +80,18 @@ private void initRemoveAction() {
78
80
private void initEditAction () {
79
81
decorator .setEditActionUpdater (e -> {
80
82
DefaultMutableTreeNode [] selectedNodes = dataSourceTree .getSelectedNodes (DefaultMutableTreeNode .class ,
81
- ( node ) -> node . getUserObject () instanceof DataSourceApi );
83
+ this :: isDataSource );
82
84
83
85
return selectedNodes .length == 1 ;
84
86
});
85
87
decorator .setEditAction (anActionButton -> {
86
88
PatchedDefaultMutableTreeNode [] selectedNodes = dataSourceTree .getSelectedNodes (PatchedDefaultMutableTreeNode .class ,
87
- (node ) -> node .getUserObject () instanceof DataSourceApi );
89
+ (node ) -> node .getUserObject () instanceof TreeNodeModelApi );
88
90
89
91
if (selectedNodes .length == 1 ) {
90
92
PatchedDefaultMutableTreeNode treeNode = selectedNodes [0 ];
91
93
92
- DataSourceApi dataSourceToEdit = ( DataSourceApi ) treeNode . getUserObject ( );
94
+ DataSourceApi dataSourceToEdit = getDataSourceApi ( treeNode );
93
95
94
96
DataSourceDialog dialog = null ;
95
97
if (dataSourceToEdit .getDataSourceType ().equals (DataSourceType .NEO4J_BOLT )) {
@@ -112,13 +114,13 @@ public void mouseClicked(MouseEvent e) {
112
114
int clickCount = e .getClickCount ();
113
115
if (clickCount == 2 ) {
114
116
DefaultMutableTreeNode [] selectedNodes = dataSourceTree .getSelectedNodes (DefaultMutableTreeNode .class ,
115
- ( node ) -> node . getUserObject () instanceof DataSourceApi );
117
+ DataSourceInteractions . this :: isDataSource );
116
118
117
119
if (selectedNodes .length != 1 ) {
118
120
return ;
119
121
}
120
122
121
- DataSourceApi dataSource = ( DataSourceApi ) selectedNodes [0 ]. getUserObject ( );
123
+ DataSourceApi dataSource = getDataSourceApi ( selectedNodes [0 ]);
122
124
Analytics .event (dataSource , "openEditor" );
123
125
124
126
try {
@@ -131,4 +133,13 @@ public void mouseClicked(MouseEvent e) {
131
133
};
132
134
dataSourceTree .addMouseListener (mouseAdapter );
133
135
}
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
+ }
134
145
}
0 commit comments