Skip to content

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

Merged
merged 10 commits into from
Jan 12, 2017
Merged

Conversation

Vorago
Copy link
Contributor

@Vorago Vorago commented Jan 10, 2017

No description provided.

@Vorago Vorago requested a review from FylmTM January 10, 2017 13:45
DataSourcesComponent dataSourcesComponent = project.getComponent(DataSourcesComponent.class);
Optional<DataSourceApi> dataSource = dataSourcesComponent.getDataSourceContainer().findDataSource(dataSourceUuid);

executeQueryEvent.executeQuery(dataSource.get(), payload);
Copy link
Contributor

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[]{};
}
}

Copy link
Contributor

@FylmTM FylmTM Jan 10, 2017

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)};
Copy link
Contributor

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)};
Copy link
Contributor

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();
Copy link
Contributor

Choose a reason for hiding this comment

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

Use interface DataSourceApi

Copy link
Contributor

@FylmTM FylmTM left a 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() {
Copy link
Contributor

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 {
Copy link
Contributor

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) {
Copy link
Contributor

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
Copy link
Contributor

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());
Copy link
Contributor

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));
Copy link
Contributor

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) {
Copy link
Contributor

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) {
Copy link
Contributor

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 {
Copy link
Contributor

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 {
Copy link
Contributor

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.

Copy link
Contributor

@FylmTM FylmTM left a 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
@FylmTM FylmTM merged commit b4d9f11 into master Jan 12, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants