-
Notifications
You must be signed in to change notification settings - Fork 56
Provide query example for metadata using context menu #19
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
Conversation
DataSourcesComponent dataSourcesComponent = project.getComponent(DataSourcesComponent.class); | ||
Optional<DataSourceApi> dataSource = dataSourcesComponent.getDataSourceContainer().findDataSource(dataSourceUuid); | ||
|
||
executeQueryEvent.executeQuery(dataSource.get(), payload); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's not blindly use .get(), but actually check for a data source and do nothing if data source is not present (for some wierd reason).
return new AnAction[]{}; | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's common practice for all of you to put empty line before closing class bracket? I should put some checkstyle rule for that :)
public AnAction[] getChildren(@Nullable AnActionEvent e) { | ||
switch (type) { | ||
case RELATIONSHIP_TYPES: | ||
return new AnAction[]{new MetadataRelationshipAction(label, dataSourceUuid, "Query this relationship", "", NEO4J)}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
label
-> relationshipType
case LABELS: | ||
return new AnAction[]{new MetadataLabelAction(label, dataSourceUuid, "Query this label", "", NEO4J)}; | ||
case PROPERTY_KEYS: | ||
return new AnAction[]{new MetadataPropertyKeyAction(label, dataSourceUuid, "Query this property", "", NEO4J)}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
label
-> propertyKey
|
||
private String extractUuid(Object dsUserObject) { | ||
if (dsUserObject instanceof DataSourceV1) { | ||
return ((DataSourceV1) dsUserObject).getUUID(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use interface DataSourceApi
- Tests implemented - Refactoring needed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed - while it's working, we can do better by changing approach.
return dataSourceApi; | ||
} | ||
|
||
public String getData() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is possibility that data will be null. Either mark with annotation @Nullable
(from intellij platform) or add Optional
.
import javax.swing.tree.TreePath; | ||
import java.util.Optional; | ||
|
||
public class ContextMenuService { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would question about coupling this service to data sources.
But let's leave it as it is for now.
} | ||
} | ||
|
||
private TreeNodeModelApi extractUserObject(TreeNode node) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optional?
|
||
private void popup(ContextMenu dto, Tree tree) { | ||
DataContext dataContext = DataManager.getInstance().getDataContext(tree); | ||
if (dto.getMetadataType() == Neo4jTreeNodeType.LABEL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that switch
will be better here instead of ifs (because we are using enums)
|| type == Neo4jTreeNodeType.PROPERTY_KEY)) { | ||
return new ContextMenu(type, model.getDataSourceApi(), model.getText().get()); | ||
} else if (type == Neo4jTreeNodeType.DATASOURCE) { | ||
return new ContextMenu(type, model.getDataSourceApi()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are creating data source context menu here.
|
||
@Override | ||
public Optional<ContextMenu> getContextMenu() { | ||
return Optional.of(new ContextMenu(getType(), dataSourceApi)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And also data source context menu here. Why in 2 places?
return Optional.ofNullable(contextMenu); | ||
} | ||
|
||
public void setContextMenu(ContextMenu contextMenu) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that this setter is not used?
this.value = value; | ||
} | ||
|
||
public TreeNodeModel(Neo4jTreeNodeType type, DataSourceApi dataSourceApi, String value) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Constructors should be organized into a tree, with prepareContextMenu()
only in one of them (most general one).
import javax.swing.*; | ||
import java.util.Optional; | ||
|
||
public class TreeNodeModel implements TreeNodeModelApi { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's move metadata specific logic to a "MetadataTreeNodeModel" (similar to how DataSourceTreeNodeModel works).
It's looks a bit odd when you extend from TreeNodeModel and already have some built-in logic that you override by doing method overrides.
I would even consider to create "RootTreeNodeModel" for tree root specifically.
import static java.util.Collections.singletonList; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class DataSourceMetadataUiTest { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this test. Using swing objects, but just not rendering them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bunch of comments, but most important one is about why we have context menu creation in multiple places.
- Changed arg order: key first, then value
No description provided.