Skip to content

Use TreeNodeModelApi everywhere instead of DataSourceApi #28

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 2 commits into from
Jan 19, 2017
Merged
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import com.neueda.jetbrains.plugin.graphdb.jetbrains.component.datasource.state.DataSourceApi;
import com.neueda.jetbrains.plugin.graphdb.jetbrains.ui.datasource.DataSourcesView;
import com.neueda.jetbrains.plugin.graphdb.jetbrains.ui.datasource.interactions.neo4j.bolt.Neo4jBoltDataSourceDialog;
import com.neueda.jetbrains.plugin.graphdb.jetbrains.ui.datasource.tree.Neo4jTreeNodeType;
import com.neueda.jetbrains.plugin.graphdb.jetbrains.ui.datasource.tree.TreeNodeModelApi;
import com.neueda.jetbrains.plugin.graphdb.jetbrains.util.FileUtil;
import com.neueda.jetbrains.plugin.graphdb.jetbrains.util.Notifier;

Expand Down Expand Up @@ -57,10 +59,10 @@ private void initAddAction() {
private void initRemoveAction() {
decorator.setRemoveAction(anActionButton -> {
DefaultMutableTreeNode[] selectedNodes = dataSourceTree.getSelectedNodes(DefaultMutableTreeNode.class,
(node) -> node.getUserObject() instanceof DataSourceApi);
this::isDataSource);

List<DataSourceApi> dataSourcesForRemoval = Arrays.stream(selectedNodes)
.map((node) -> (DataSourceApi) node.getUserObject())
.map(this::getDataSourceApi)
.collect(Collectors.toList());

if (dataSourcesForRemoval.size() > 0) {
Expand All @@ -69,7 +71,7 @@ private void initRemoveAction() {
});
decorator.setRemoveActionUpdater(e -> {
DefaultMutableTreeNode[] selectedNodes = dataSourceTree.getSelectedNodes(DefaultMutableTreeNode.class,
(node) -> node.getUserObject() instanceof DataSourceApi);
this::isDataSource);

return selectedNodes.length > 0;
});
Expand All @@ -78,18 +80,18 @@ private void initRemoveAction() {
private void initEditAction() {
decorator.setEditActionUpdater(e -> {
DefaultMutableTreeNode[] selectedNodes = dataSourceTree.getSelectedNodes(DefaultMutableTreeNode.class,
(node) -> node.getUserObject() instanceof DataSourceApi);
this::isDataSource);

return selectedNodes.length == 1;
});
decorator.setEditAction(anActionButton -> {
PatchedDefaultMutableTreeNode[] selectedNodes = dataSourceTree.getSelectedNodes(PatchedDefaultMutableTreeNode.class,
(node) -> node.getUserObject() instanceof DataSourceApi);
(node) -> node.getUserObject() instanceof TreeNodeModelApi);

if (selectedNodes.length == 1) {
PatchedDefaultMutableTreeNode treeNode = selectedNodes[0];

DataSourceApi dataSourceToEdit = (DataSourceApi) treeNode.getUserObject();
DataSourceApi dataSourceToEdit = getDataSourceApi(treeNode);

DataSourceDialog dialog = null;
if (dataSourceToEdit.getDataSourceType().equals(DataSourceType.NEO4J_BOLT)) {
Expand All @@ -112,13 +114,13 @@ public void mouseClicked(MouseEvent e) {
int clickCount = e.getClickCount();
if (clickCount == 2) {
DefaultMutableTreeNode[] selectedNodes = dataSourceTree.getSelectedNodes(DefaultMutableTreeNode.class,
(node) -> node.getUserObject() instanceof DataSourceApi);
DataSourceInteractions.this::isDataSource);

if (selectedNodes.length != 1) {
return;
}

DataSourceApi dataSource = (DataSourceApi) selectedNodes[0].getUserObject();
DataSourceApi dataSource = getDataSourceApi(selectedNodes[0]);
Analytics.event(dataSource, "openEditor");

try {
Expand All @@ -131,4 +133,13 @@ public void mouseClicked(MouseEvent e) {
};
dataSourceTree.addMouseListener(mouseAdapter);
}

private boolean isDataSource(DefaultMutableTreeNode node) {
return node.getUserObject() instanceof TreeNodeModelApi
&& ((TreeNodeModelApi) node.getUserObject()).getType() == Neo4jTreeNodeType.DATASOURCE;
}

private DataSourceApi getDataSourceApi(DefaultMutableTreeNode node) {
return ((TreeNodeModelApi) node.getUserObject()).getDataSourceApi();
}
}