Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added procedure and function grouping in metadata view. #78

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ RelationshipDetail ::= "[" Variable? "?"? RelationshipTypes? MaybeVariableLength
RelationshipTypes ::= ":" RelTypeName ("|" ":"? RelTypeName)* {pin=1}
MaybeVariableLength ::= ("*" RangeLiteral?)

NodePattern ::= "(" Variable? NodeLabels? Properties? ")"
NodePattern ::= "(" Variable? NodeLabels? Properties? ")" {pin=1}

RelationshipsPattern ::= NodePattern PatternElementChain+ {
implements="com.neueda.jetbrains.plugin.graphdb.language.cypher.references.types.CypherPathYielding"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
import com.neueda.jetbrains.plugin.graphdb.jetbrains.component.datasource.metadata.DataSourcesComponentMetadata;
import com.neueda.jetbrains.plugin.graphdb.jetbrains.component.datasource.metadata.Neo4jBoltCypherDataSourceMetadata;
import com.neueda.jetbrains.plugin.graphdb.jetbrains.component.datasource.state.DataSourceApi;
import com.neueda.jetbrains.plugin.graphdb.jetbrains.ui.datasource.tree.LabelTreeNodeModel;
import com.neueda.jetbrains.plugin.graphdb.jetbrains.ui.datasource.tree.MetadataTreeNodeModel;
import com.neueda.jetbrains.plugin.graphdb.jetbrains.ui.datasource.tree.RelationshipTypeTreeNodeModel;
import com.neueda.jetbrains.plugin.graphdb.jetbrains.ui.datasource.tree.TreeNodeModelApi;
import com.neueda.jetbrains.plugin.graphdb.jetbrains.ui.datasource.metadata.tree.MutableTreeNodeProducers;
import com.neueda.jetbrains.plugin.graphdb.jetbrains.ui.datasource.metadata.tree.Root;
import com.neueda.jetbrains.plugin.graphdb.jetbrains.ui.datasource.metadata.tree.TreeNodeDirectory;
import com.neueda.jetbrains.plugin.graphdb.jetbrains.ui.datasource.tree.*;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't use imports with '*'. Use only imports what you need

import com.neueda.jetbrains.plugin.graphdb.platform.GraphIcons;

import javax.swing.tree.MutableTreeNode;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -87,37 +88,61 @@ boolean updateNeo4jBoltCypherMetadataUi(PatchedDefaultMutableTreeNode dataSource

// Stored procedures
PatchedDefaultMutableTreeNode storedProceduresTreeNode = new PatchedDefaultMutableTreeNode(
new MetadataTreeNodeModel(STORED_PROCEDURES, dataSourceApi, STORED_PROCEDURES_TITLE, GraphIcons.Nodes.STORED_PROCEDURE));
dataSourceMetadata
.getMetadata(Neo4jBoltCypherDataSourceMetadata.STORED_PROCEDURES)
.forEach((row) -> {
PatchedDefaultMutableTreeNode nameNode = of(new MetadataTreeNodeModel(STORED_PROCEDURE, dataSourceApi, row.get("name")));
PatchedDefaultMutableTreeNode descriptionNode = of(new MetadataTreeNodeModel(STORED_PROCEDURE, dataSourceApi, row.get("signature")));
nameNode.add(descriptionNode);
storedProceduresTreeNode.add(nameNode);
});
new MetadataTreeNodeModel(STORED_PROCEDURES, dataSourceApi, STORED_PROCEDURES_TITLE, GraphIcons.Nodes.STORED_PROCEDURE));

List<Map<String, String>> storedProcedures = dataSourceMetadata
.getMetadata(Neo4jBoltCypherDataSourceMetadata.STORED_PROCEDURES);

createTreeFromMetadata(storedProcedures, storedProceduresTreeNode, STORED_PROCEDURE, dataSourceApi);

dataSourceRootTreeNode.add(storedProceduresTreeNode);

// User Functions
if (dataSourceMetadata.isMetadataExists(Neo4jBoltCypherDataSourceMetadata.USER_FUNCTIONS)) {
PatchedDefaultMutableTreeNode userFunctionTreeNode = new PatchedDefaultMutableTreeNode(
new MetadataTreeNodeModel(USER_FUNCTIONS, dataSourceApi, USER_FUNCTIONS_TITLE, GraphIcons.Nodes.USER_FUNCTION));

dataSourceMetadata
.getMetadata(Neo4jBoltCypherDataSourceMetadata.USER_FUNCTIONS)
.forEach((row) -> {
PatchedDefaultMutableTreeNode nameNode = of(new MetadataTreeNodeModel(USER_FUNCTION, dataSourceApi, row.get("name")));
PatchedDefaultMutableTreeNode descriptionNode = of(new MetadataTreeNodeModel(USER_FUNCTION, dataSourceApi, row.get("signature")));
nameNode.add(descriptionNode);
userFunctionTreeNode.add(nameNode);
});
List<Map<String, String>> storedFunctions = dataSourceMetadata
.getMetadata(Neo4jBoltCypherDataSourceMetadata.USER_FUNCTIONS);

createTreeFromMetadata(storedFunctions, userFunctionTreeNode, USER_FUNCTION, dataSourceApi);

dataSourceRootTreeNode.add(userFunctionTreeNode);
}

return true;
}

private void createTreeFromMetadata(List<Map<String, String>> metadata,
PatchedDefaultMutableTreeNode treeRoot,
Neo4jTreeNodeType type,
DataSourceApi dataSourceApi) {
TreeNodeDirectory treeNodeRoot = new Root(
treeRoot,
MutableTreeNodeProducers.directory(type, dataSourceApi),
MutableTreeNodeProducers.function(type, dataSourceApi)
);

metadata.forEach(data -> {
String[] nameParts = data.getOrDefault("name", "").split("\\.");
nameParts[nameParts.length - 1] = data.get("signature");
createBranch(treeNodeRoot, Arrays.asList(nameParts));
});

treeNodeRoot.getMutableTreeNode();
}

private void createBranch(TreeNodeDirectory directory, List<String> names) {
TreeNodeDirectory currentDirectory = directory;
for (int i = 0; i < names.size(); i++) {
if (i < names.size() - 1) {
currentDirectory = currentDirectory.getDirectory(names.get(i));
} else {
currentDirectory.addLeaf(names.get(i));
}
}
}

private MutableTreeNode createIndexesNode(DataSourceMetadata dataSourceMetadata, DataSourceApi dataSourceApi) {
List<Map<String, String>> indexesMetadata =
dataSourceMetadata.getMetadata(Neo4jBoltCypherDataSourceMetadata.INDEXES);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package com.neueda.jetbrains.plugin.graphdb.jetbrains.ui.datasource.metadata.tree;

import javax.swing.tree.DefaultMutableTreeNode;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;

class Directory implements TreeNode, TreeNodeDirectory {
private final Map<String, Directory> directories;
private final List<Leaf> functions;
private final String name;
private final Function<TreeNode, DefaultMutableTreeNode> directoryProducer;
private final Function<TreeNode, DefaultMutableTreeNode> functionProducer;

public Directory(
String name,
Function<TreeNode, DefaultMutableTreeNode> directoryProducer,
Function<TreeNode, DefaultMutableTreeNode> functionProducer
) {
this.name = name;
this.directoryProducer = directoryProducer;
this.functionProducer = functionProducer;
this.directories = new LinkedHashMap<>();
this.functions = new ArrayList<>();
}

@Override
public Directory getDirectory(String name) {
return directories.computeIfAbsent(
name,
(k) -> new Directory(k, directoryProducer, functionProducer)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is 'k'?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'k' stands for key, however I changed it to 'newName' for more understanding

);
}

@Override
public void addLeaf(String name) {
functions.add(new Leaf(name, functionProducer));
}

@Override
public String getName() {
return name;
}

@Override
public DefaultMutableTreeNode getMutableTreeNode() {
DefaultMutableTreeNode root = directoryProducer.apply(this);

directories.values().forEach((directory) -> root.add(directory.getMutableTreeNode()));
functions.forEach((function) -> root.add(function.getMutableTreeNode()));

return root;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.neueda.jetbrains.plugin.graphdb.jetbrains.ui.datasource.metadata.tree;

import javax.swing.tree.DefaultMutableTreeNode;
import java.util.function.Function;

class Leaf implements TreeNode {
private final String name;
private Function<TreeNode, DefaultMutableTreeNode> mutableTreeNodeProducer;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mutableTreeNodeProducer should be final

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed


public Leaf(String name, Function<TreeNode, DefaultMutableTreeNode> mutableTreeNodeProducer) {
this.name = name;
this.mutableTreeNodeProducer = mutableTreeNodeProducer;
}

@Override
public String getName() {
return name;
}

@Override
public DefaultMutableTreeNode getMutableTreeNode() {
return mutableTreeNodeProducer.apply(this);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.neueda.jetbrains.plugin.graphdb.jetbrains.ui.datasource.metadata.tree;

import com.intellij.icons.AllIcons;
import com.intellij.ui.treeStructure.PatchedDefaultMutableTreeNode;
import com.neueda.jetbrains.plugin.graphdb.jetbrains.component.datasource.state.DataSourceApi;
import com.neueda.jetbrains.plugin.graphdb.jetbrains.ui.datasource.tree.MetadataTreeNodeModel;
import com.neueda.jetbrains.plugin.graphdb.jetbrains.ui.datasource.tree.Neo4jTreeNodeType;

import javax.swing.tree.DefaultMutableTreeNode;
import java.util.function.Function;

public final class MutableTreeNodeProducers {

public static Function<TreeNode, DefaultMutableTreeNode> function(Neo4jTreeNodeType type, DataSourceApi dataSourceApi) {
return treeNode -> new PatchedDefaultMutableTreeNode(
new MetadataTreeNodeModel(type, dataSourceApi, treeNode.getName(), AllIcons.Nodes.Function)
);
}

public static Function<TreeNode, DefaultMutableTreeNode> directory(Neo4jTreeNodeType type, DataSourceApi dataSourceApi) {
return treeNode -> new PatchedDefaultMutableTreeNode(
new MetadataTreeNodeModel(type, dataSourceApi, treeNode.getName(), AllIcons.Nodes.Package)
);
}

private MutableTreeNodeProducers() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Constructor should be in the top of the class

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.neueda.jetbrains.plugin.graphdb.jetbrains.ui.datasource.metadata.tree;

import javax.swing.tree.DefaultMutableTreeNode;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;

public class Root implements TreeNode, TreeNodeDirectory {

private final DefaultMutableTreeNode root;
private final Map<String, Directory> directories;
private final List<Leaf> functions;
private final Function<TreeNode, DefaultMutableTreeNode> directoryProducer;
private final Function<TreeNode, DefaultMutableTreeNode> functionProducer;

public Root(
DefaultMutableTreeNode root,
Function<TreeNode, DefaultMutableTreeNode> directoryProducer,
Function<TreeNode, DefaultMutableTreeNode> functionProducer
) {
this.root = root;
this.directoryProducer = directoryProducer;
this.functionProducer = functionProducer;
this.directories = new LinkedHashMap<>();
this.functions = new ArrayList<>();
}

@Override
public Directory getDirectory(String name) {
return directories.computeIfAbsent(
name,
(k) -> new Directory(k, directoryProducer, functionProducer)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't understand what is 'k'. Please use full names for the variables

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'k' stands for key, however I changed it to 'newName' for more understanding

);
}

@Override
public void addLeaf(String name) {
functions.add(new Leaf(name, functionProducer));
}

@Override
public String getName() {
return "root";
}

@Override
public DefaultMutableTreeNode getMutableTreeNode() {
directories.values().forEach((directory) -> root.add(directory.getMutableTreeNode()));
functions.forEach((function) -> root.add(function.getMutableTreeNode()));

return root;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.neueda.jetbrains.plugin.graphdb.jetbrains.ui.datasource.metadata.tree;

import javax.swing.tree.DefaultMutableTreeNode;

public interface TreeNode {

public String getName();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Access modifier is 'public' is redudant here. In interfaces access modifier by default is public

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed


public DefaultMutableTreeNode getMutableTreeNode();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Access modifier is 'public' is redudant here. In interfaces access modifier by default is public

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.neueda.jetbrains.plugin.graphdb.jetbrains.ui.datasource.metadata.tree;

public interface TreeNodeDirectory extends TreeNode {

public void addLeaf(String name);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Access modifier is 'public' is redudant here. In interfaces access modifier by default is public

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed


public TreeNodeDirectory getDirectory(String name);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Access modifier is 'public' is redudant here. In interfaces access modifier by default is public

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed


}