Skip to content

Commit fa50293

Browse files
committed
Added interface for TreeNode userObject
1 parent 52cf391 commit fa50293

File tree

14 files changed

+290
-125
lines changed

14 files changed

+290
-125
lines changed

ui/jetbrains/src/main/java/com/neueda/jetbrains/plugin/graphdb/jetbrains/ui/console/graph/GraphPanel.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,11 @@
2929
import java.awt.event.MouseEvent;
3030
import java.util.Enumeration;
3131

32-
import static com.neueda.jetbrains.plugin.graphdb.visualization.util.DisplayUtil.*;
32+
import static com.neueda.jetbrains.plugin.graphdb.visualization.util.DisplayUtil.getTooltipText;
33+
import static com.neueda.jetbrains.plugin.graphdb.visualization.util.DisplayUtil.getTooltipTitle;
3334

3435
public class GraphPanel {
3536

36-
private static final int TYPES_DEPTH = 2;
37-
private static final int PROPERTY_DEPTH = 3;
38-
3937
private PrefuseVisualization visualization;
4038
private LookAndFeelService lookAndFeelService;
4139
private BalloonBuilder balloonPopupBuilder;

ui/jetbrains/src/main/java/com/neueda/jetbrains/plugin/graphdb/jetbrains/ui/console/graph/GraphPanelInteractions.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
import com.neueda.jetbrains.plugin.graphdb.visualization.VisualizationApi;
1313
import com.neueda.jetbrains.plugin.graphdb.visualization.events.EventType;
1414

15-
import java.util.Optional;
16-
1715
public class GraphPanelInteractions {
1816

1917
private final GraphConsoleView graphConsoleView;

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

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818
import com.neueda.jetbrains.plugin.graphdb.jetbrains.ui.datasource.actions.RefreshDataSourcesAction;
1919
import com.neueda.jetbrains.plugin.graphdb.jetbrains.ui.datasource.interactions.DataSourceInteractions;
2020
import com.neueda.jetbrains.plugin.graphdb.jetbrains.ui.datasource.metadata.DataSourceMetadataUi;
21-
import com.neueda.jetbrains.plugin.graphdb.jetbrains.ui.datasource.tree.GraphColoredTreeCellRenderer;
22-
import com.neueda.jetbrains.plugin.graphdb.jetbrains.ui.datasource.tree.DataSourcesTreeMouseAdapter;
21+
import com.neueda.jetbrains.plugin.graphdb.jetbrains.ui.datasource.tree.*;
2322
import com.neueda.jetbrains.plugin.graphdb.jetbrains.util.FileUtil;
2423
import com.neueda.jetbrains.plugin.graphdb.language.cypher.completion.metadata.CypherMetadataProviderService;
2524

@@ -31,9 +30,12 @@
3130
import java.io.IOException;
3231
import java.util.Enumeration;
3332
import java.util.List;
33+
import java.util.Objects;
3434

3535
public class DataSourcesView implements Disposable {
3636

37+
public static final String ROOT_NAME = "treeRoot";
38+
3739
private boolean initialized;
3840

3941
private DataSourcesComponent component;
@@ -63,7 +65,7 @@ public void initToolWindow(Project project, ToolWindow toolWindow) {
6365
componentMetadata = project.getComponent(DataSourcesComponentMetadata.class);
6466
cypherMetadataProviderService = ServiceManager.getService(project, CypherMetadataProviderService.class);
6567
dataSourceMetadataUi = new DataSourceMetadataUi(componentMetadata);
66-
treeRoot = new PatchedDefaultMutableTreeNode("treeRoot");
68+
treeRoot = new PatchedDefaultMutableTreeNode(new TreeNodeModel(Neo4jTreeNodeType.ROOT, ROOT_NAME));
6769
treeModel = new DefaultTreeModel(treeRoot, false);
6870
decorator = ToolbarDecorator.createDecorator(dataSourceTree);
6971
decorator.addExtraAction(new RefreshDataSourcesAction(this));
@@ -126,7 +128,7 @@ private void replaceTreeWithDecorated() {
126128

127129
private void showDataSources() {
128130
component.getDataSourceContainer().getDataSources()
129-
.forEach((dataSource) -> treeRoot.add(new PatchedDefaultMutableTreeNode(dataSource)));
131+
.forEach((dataSource) -> treeRoot.add(new PatchedDefaultMutableTreeNode(new TreeNodeModel(Neo4jTreeNodeType.DATASOURCE, dataSource))));
130132
treeModel.reload();
131133
}
132134

@@ -145,15 +147,17 @@ public void refreshDataSourcesMetadata() {
145147
}
146148

147149
public boolean refreshDataSourceMetadata(PatchedDefaultMutableTreeNode treeNode) {
148-
DataSourceApi nodeDataSource = (DataSourceApi) treeNode.getUserObject();
150+
TreeNodeModelApi userObject = (TreeNodeModelApi) treeNode.getUserObject();
151+
DataSourceApi nodeDataSource = userObject.getDataSourceApi();
149152
Analytics.event(nodeDataSource, "refreshMetadata");
150153
return dataSourceMetadataUi.updateDataSourceMetadataUi(treeNode, nodeDataSource);
151154
}
152155

153156
public void createDataSource(DataSourceApi dataSource) {
154157
Analytics.event(dataSource, "create");
155158
component.getDataSourceContainer().addDataSource(dataSource);
156-
PatchedDefaultMutableTreeNode treeNode = new PatchedDefaultMutableTreeNode(dataSource);
159+
TreeNodeModel model = new TreeNodeModel(Neo4jTreeNodeType.DATASOURCE, dataSource);
160+
PatchedDefaultMutableTreeNode treeNode = new PatchedDefaultMutableTreeNode(model);
157161
treeRoot.add(treeNode);
158162
refreshDataSourceMetadata(treeNode);
159163
treeModel.reload();
@@ -162,7 +166,7 @@ public void createDataSource(DataSourceApi dataSource) {
162166
public void updateDataSource(PatchedDefaultMutableTreeNode treeNode, DataSourceApi oldDataSource, DataSourceApi newDataSource) {
163167
Analytics.event(newDataSource, "update");
164168
component.getDataSourceContainer().updateDataSource(oldDataSource, newDataSource);
165-
treeNode.setUserObject(newDataSource);
169+
treeNode.setUserObject(new TreeNodeModel(Neo4jTreeNodeType.DATASOURCE, newDataSource));
166170
refreshDataSourceMetadata(treeNode);
167171
treeModel.reload();
168172
}
@@ -186,14 +190,15 @@ public void removeDataSources(Project project, List<DataSourceApi> dataSourcesFo
186190
Enumeration enumeration = treeRoot.children();
187191
while (enumeration.hasMoreElements()) {
188192
DefaultMutableTreeNode element = (DefaultMutableTreeNode) enumeration.nextElement();
189-
DataSourceApi dataSource = (DataSourceApi) element.getUserObject();
193+
TreeNodeModelApi userObject = (TreeNodeModelApi) element.getUserObject();
194+
DataSourceApi dataSource = userObject.getDataSourceApi();
190195
if (dataSource.getName().equals(name)) {
191196
return element;
192197
}
193198
}
194199
return null;
195200
})
196-
.filter(ds -> ds != null)
201+
.filter(Objects::nonNull)
197202
.forEach(treeRoot::remove);
198203

199204
treeModel.reload();
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
11
package com.neueda.jetbrains.plugin.graphdb.jetbrains.ui.datasource.metadata;
22

33
import com.intellij.ui.treeStructure.PatchedDefaultMutableTreeNode;
4-
import com.neueda.jetbrains.plugin.graphdb.jetbrains.component.datasource.metadata.*;
4+
import com.neueda.jetbrains.plugin.graphdb.jetbrains.component.datasource.metadata.DataSourceMetadata;
5+
import com.neueda.jetbrains.plugin.graphdb.jetbrains.component.datasource.metadata.DataSourcesComponentMetadata;
6+
import com.neueda.jetbrains.plugin.graphdb.jetbrains.component.datasource.metadata.Neo4jBoltCypherDataSourceMetadata;
57
import com.neueda.jetbrains.plugin.graphdb.jetbrains.component.datasource.state.DataSourceApi;
6-
import com.neueda.jetbrains.plugin.graphdb.jetbrains.ui.datasource.tree.dto.ValueWithIcon;
7-
import com.neueda.jetbrains.plugin.graphdb.platform.GraphIcons;
8+
import com.neueda.jetbrains.plugin.graphdb.jetbrains.ui.datasource.tree.TreeNodeModel;
9+
import com.neueda.jetbrains.plugin.graphdb.jetbrains.ui.datasource.tree.TreeNodeModelApi;
10+
11+
import static com.neueda.jetbrains.plugin.graphdb.jetbrains.ui.datasource.tree.Neo4jTreeNodeType.*;
812

913
public class DataSourceMetadataUi {
1014

11-
public static final String RELATIONSHIP_TYPES_TITLE = "relationship types";
12-
public static final String PROPERTY_KEYS_TITLE = "property keys";
13-
public static final String LABELS_TITLE = "labels";
14-
public static final String STORED_PROCEDURES_TITLE = "stored procedures";
15-
public static final String USER_FUNCTIONS_TITLE = "user functions";
15+
private static final String RELATIONSHIP_TYPES_TITLE = "relationship types";
16+
private static final String PROPERTY_KEYS_TITLE = "property keys";
17+
private static final String LABELS_TITLE = "labels";
18+
private static final String STORED_PROCEDURES_TITLE = "stored procedures";
19+
private static final String USER_FUNCTIONS_TITLE = "user functions";
1620

1721
private final DataSourcesComponentMetadata dataSourcesComponent;
1822

@@ -36,39 +40,41 @@ boolean updateNeo4jBoltCypherMetadataUi(PatchedDefaultMutableTreeNode dataSource
3640
DataSourceMetadata dataSourceMetadata) {
3741
// Remove existing metadata from ui
3842
dataSourceRootTreeNode.removeAllChildren();
43+
TreeNodeModelApi model = (TreeNodeModelApi) dataSourceRootTreeNode.getUserObject();
44+
DataSourceApi dataSourceApi = model.getDataSourceApi();
3945

4046
// Labels
4147
PatchedDefaultMutableTreeNode labelsTreeNode = new PatchedDefaultMutableTreeNode(
42-
new ValueWithIcon(GraphIcons.Nodes.LABEL, LABELS_TITLE));
48+
new TreeNodeModel(LABELS, dataSourceApi, LABELS_TITLE));
4349
dataSourceMetadata
4450
.getMetadata(Neo4jBoltCypherDataSourceMetadata.LABELS)
45-
.forEach((row) -> labelsTreeNode.add(new PatchedDefaultMutableTreeNode(row.get("label"))));
51+
.forEach((row) -> labelsTreeNode.add(of(new TreeNodeModel(LABEL, dataSourceApi, row.get("label")))));
4652
dataSourceRootTreeNode.add(labelsTreeNode);
4753

4854
// RelTypes
4955
PatchedDefaultMutableTreeNode relationshipTypesTreeNode = new PatchedDefaultMutableTreeNode(
50-
new ValueWithIcon(GraphIcons.Nodes.RELATIONSHIP_TYPE, RELATIONSHIP_TYPES_TITLE));
56+
new TreeNodeModel(RELATIONSHIPS, dataSourceApi, RELATIONSHIP_TYPES_TITLE));
5157
dataSourceMetadata
5258
.getMetadata(Neo4jBoltCypherDataSourceMetadata.RELATIONSHIP_TYPES)
53-
.forEach((row) -> relationshipTypesTreeNode.add(new PatchedDefaultMutableTreeNode(row.get("relationshipType"))));
59+
.forEach((row) -> relationshipTypesTreeNode.add(of(new TreeNodeModel(RELATIONSHIP, dataSourceApi, row.get("relationshipType")))));
5460
dataSourceRootTreeNode.add(relationshipTypesTreeNode);
5561

5662
// Property Keys
5763
PatchedDefaultMutableTreeNode propertyKeysTreeNode = new PatchedDefaultMutableTreeNode(
58-
new ValueWithIcon(GraphIcons.Nodes.PROPERTY_KEY, PROPERTY_KEYS_TITLE));
64+
new TreeNodeModel(PROPERTY_KEYS, dataSourceApi, PROPERTY_KEYS_TITLE));
5965
dataSourceMetadata
6066
.getMetadata(Neo4jBoltCypherDataSourceMetadata.PROPERTY_KEYS)
61-
.forEach((row) -> propertyKeysTreeNode.add(new PatchedDefaultMutableTreeNode(row.get("propertyKey"))));
67+
.forEach((row) -> propertyKeysTreeNode.add(of(new TreeNodeModel(PROPERTY_KEY, dataSourceApi, row.get("propertyKey")))));
6268
dataSourceRootTreeNode.add(propertyKeysTreeNode);
6369

6470
// Stored procedures
6571
PatchedDefaultMutableTreeNode storedProceduresTreeNode = new PatchedDefaultMutableTreeNode(
66-
new ValueWithIcon(GraphIcons.Nodes.STORED_PROCEDURE, STORED_PROCEDURES_TITLE));
72+
new TreeNodeModel(STORED_PROCEDURES, dataSourceApi, STORED_PROCEDURES_TITLE));
6773
dataSourceMetadata
6874
.getMetadata(Neo4jBoltCypherDataSourceMetadata.STORED_PROCEDURES)
6975
.forEach((row) -> {
70-
PatchedDefaultMutableTreeNode nameNode = new PatchedDefaultMutableTreeNode(row.get("name"));
71-
PatchedDefaultMutableTreeNode descriptionNode = new PatchedDefaultMutableTreeNode(row.get("signature"));
76+
PatchedDefaultMutableTreeNode nameNode = of(new TreeNodeModel(STORED_PROCEDURE, dataSourceApi, row.get("name")));
77+
PatchedDefaultMutableTreeNode descriptionNode = of(new TreeNodeModel(STORED_PROCEDURE, dataSourceApi, row.get("signature")));
7278
nameNode.add(descriptionNode);
7379
storedProceduresTreeNode.add(nameNode);
7480
});
@@ -77,13 +83,13 @@ boolean updateNeo4jBoltCypherMetadataUi(PatchedDefaultMutableTreeNode dataSource
7783
// User Functions
7884
if (dataSourceMetadata.isMetadataExists(Neo4jBoltCypherDataSourceMetadata.USER_FUNCTIONS)) {
7985
PatchedDefaultMutableTreeNode userFunctionTreeNode = new PatchedDefaultMutableTreeNode(
80-
new ValueWithIcon(GraphIcons.Nodes.USER_FUNCTION, USER_FUNCTIONS_TITLE));
86+
new TreeNodeModel(USER_FUNCTIONS, dataSourceApi, USER_FUNCTIONS_TITLE));
8187

8288
dataSourceMetadata
8389
.getMetadata(Neo4jBoltCypherDataSourceMetadata.USER_FUNCTIONS)
8490
.forEach((row) -> {
85-
PatchedDefaultMutableTreeNode nameNode = new PatchedDefaultMutableTreeNode(row.get("name"));
86-
PatchedDefaultMutableTreeNode descriptionNode = new PatchedDefaultMutableTreeNode(row.get("signature"));
91+
PatchedDefaultMutableTreeNode nameNode = of(new TreeNodeModel(LABEL, dataSourceApi, row.get("name")));
92+
PatchedDefaultMutableTreeNode descriptionNode = of(new TreeNodeModel(LABEL, dataSourceApi, row.get("signature")));
8793
nameNode.add(descriptionNode);
8894
userFunctionTreeNode.add(nameNode);
8995
});
@@ -93,4 +99,8 @@ boolean updateNeo4jBoltCypherMetadataUi(PatchedDefaultMutableTreeNode dataSource
9399

94100
return true;
95101
}
102+
103+
private PatchedDefaultMutableTreeNode of(TreeNodeModel model) {
104+
return new PatchedDefaultMutableTreeNode(model);
105+
}
96106
}

ui/jetbrains/src/main/java/com/neueda/jetbrains/plugin/graphdb/jetbrains/ui/datasource/metadata/actions/MetadataActionGroup.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,20 @@
33
import com.intellij.openapi.actionSystem.ActionGroup;
44
import com.intellij.openapi.actionSystem.AnAction;
55
import com.intellij.openapi.actionSystem.AnActionEvent;
6+
import com.neueda.jetbrains.plugin.graphdb.jetbrains.ui.datasource.tree.Neo4jTreeNodeType;
7+
import com.neueda.jetbrains.plugin.graphdb.jetbrains.ui.datasource.tree.NodeType;
68
import org.jetbrains.annotations.NotNull;
79
import org.jetbrains.annotations.Nullable;
810

9-
import static com.neueda.jetbrains.plugin.graphdb.jetbrains.component.datasource.metadata.Neo4jBoltCypherDataSourceMetadata.*;
1011
import static com.neueda.jetbrains.plugin.graphdb.platform.GraphIcons.Database.NEO4J;
1112

1213
public class MetadataActionGroup extends ActionGroup {
1314

14-
private final String type;
15+
private final NodeType type;
1516
private final String data;
1617
private final String dataSourceUuid;
1718

18-
public MetadataActionGroup(String type, String data, String dataSourceUuid) {
19+
public MetadataActionGroup(NodeType type, String data, String dataSourceUuid) {
1920
this.type = type;
2021
this.data = data;
2122
this.dataSourceUuid = dataSourceUuid;
@@ -24,15 +25,14 @@ public MetadataActionGroup(String type, String data, String dataSourceUuid) {
2425
@NotNull
2526
@Override
2627
public AnAction[] getChildren(@Nullable AnActionEvent e) {
27-
switch (type) {
28-
case RELATIONSHIP_TYPES:
29-
return new AnAction[]{new MetadataRelationshipAction(data, dataSourceUuid, "Query this relationship", "", NEO4J)};
30-
case LABELS:
31-
return new AnAction[]{new MetadataLabelAction(data, dataSourceUuid, "Query this label", "", NEO4J)};
32-
case PROPERTY_KEYS:
33-
return new AnAction[]{new MetadataPropertyKeyAction(data, dataSourceUuid, "Query this property", "", NEO4J)};
34-
default:
35-
return new AnAction[]{};
28+
if (type == Neo4jTreeNodeType.RELATIONSHIP) {
29+
return new AnAction[]{new MetadataRelationshipAction(data, dataSourceUuid, "Query this relationship", "", NEO4J)};
30+
} else if (type == Neo4jTreeNodeType.LABEL) {
31+
return new AnAction[]{new MetadataLabelAction(data, dataSourceUuid, "Query this label", "", NEO4J)};
32+
} else if (type == Neo4jTreeNodeType.PROPERTY_KEY) {
33+
return new AnAction[]{new MetadataPropertyKeyAction(data, dataSourceUuid, "Query this property", "", NEO4J)};
34+
} else {
35+
return new AnAction[]{};
3636
}
3737
}
3838
}

ui/jetbrains/src/main/java/com/neueda/jetbrains/plugin/graphdb/jetbrains/ui/datasource/metadata/dto/ContextMenu.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
package com.neueda.jetbrains.plugin.graphdb.jetbrains.ui.datasource.metadata.dto;
22

3+
import com.neueda.jetbrains.plugin.graphdb.jetbrains.ui.datasource.tree.NodeType;
4+
35
public class ContextMenu {
46

5-
private String metadataType;
7+
private NodeType metadataType;
68
private String datasourceUuid;
79
private String data;
810

9-
public ContextMenu(String metadataType, String datasourceUuid, String data) {
11+
public ContextMenu(NodeType metadataType, String datasourceUuid, String data) {
1012
this.metadataType = metadataType;
1113
this.datasourceUuid = datasourceUuid;
1214
this.data = data;
1315
}
1416

15-
public String getMetadataType() {
17+
public NodeType getMetadataType() {
1618
return metadataType;
1719
}
1820

0 commit comments

Comments
 (0)