Skip to content

Context menus added #33

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 30, 2017
Merged
Show file tree
Hide file tree
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 @@ -172,6 +172,18 @@
<keyboard-shortcut first-keystroke="ctrl ENTER"
keymap="$default"/>
</action>
<action id="GraphDatabaseActionGroup.ExplainQuery"
class="com.neueda.jetbrains.plugin.graphdb.jetbrains.actions.execute.ExplainQueryAction"
text="Explain query"
icon="/general/run.png"
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there any other icons that are more suitable here?

description="Explain query">
</action>
<action id="GraphDatabaseActionGroup.ProfileQuery"
class="com.neueda.jetbrains.plugin.graphdb.jetbrains.actions.execute.ProfileQueryAction"
text="Profile query"
icon="/general/run.png"
description="Profile query">
</action>
<add-to-group group-id="EditorPopupMenu"/>
</group>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,15 @@ public void actionPerformed(AnActionEvent e) {

Caret caret = editor.getCaretModel().getPrimaryCaret();

String content = null;
PsiElement cypherStatement = null;
String query = null;
Map<String, Object> parameters = Collections.emptyMap();
if (caret.hasSelection()) {
content = caret.getSelectedText();
query = caret.getSelectedText();
} else if (psiFile != null) {
if (psiFile.getLanguage().getID().equals(GraphLanguages.CYPHER)) {
cypherStatement = getCypherStatement(psiFile, caret);
PsiElement cypherStatement = getCypherStatement(psiFile, caret);
if (cypherStatement != null) {
content = cypherStatement.getText();
query = cypherStatement.getText();
try { // support parameters for PsiElement only
ParametersService service = ServiceManager.getService(project, ParametersService.class);
parameters = service.getParameters(cypherStatement);
Expand All @@ -91,12 +90,14 @@ public void actionPerformed(AnActionEvent e) {

Analytics.event("query-content", caret.hasSelection() ? "contentFromSelect" : "contentFromCaret");

if (content == null) {
if (query == null) {
Notifier.error("Query execution error", "No query selected");
return;
}

ExecuteQueryPayload executeQueryPayload = new ExecuteQueryPayload(content, parameters, editor);
query = decorateQuery(query);

ExecuteQueryPayload executeQueryPayload = new ExecuteQueryPayload(query, parameters, editor);
ConsoleToolWindow.ensureOpen(project);

if (virtualFile != null) {
Expand Down Expand Up @@ -132,6 +133,10 @@ public void executeQuery(MessageBus messageBus, DataSourceApi dataSource, Execut
executeQueryEvent.executeQuery(dataSource, payload);
}

protected String decorateQuery(String query) {
return query;
}

private PsiElement getCypherStatement(PsiFile psiFile, Caret caret) {
return PsiTraversalUtilities.Cypher.getCypherStatementAtOffset(psiFile, caret.getOffset());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.neueda.jetbrains.plugin.graphdb.jetbrains.actions.execute;

public class ExplainQueryAction extends ExecuteQueryAction {

@Override
protected String decorateQuery(String query) {
return "EXPLAIN " + super.decorateQuery(query);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.neueda.jetbrains.plugin.graphdb.jetbrains.actions.execute;

public class ProfileQueryAction extends ExecuteQueryAction {

@Override
protected String decorateQuery(String query) {
return "PROFILE " + super.decorateQuery(query);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ public DataSourceActionGroup(DataSourceApi dataSourceApi) {
@NotNull
@Override
public AnAction[] getChildren(@Nullable AnActionEvent e) {
return new AnAction[]{new DataSourceAction("Open editor", "", null, dataSourceApi)};
return new AnAction[]{
new DataSourceAction("Open editor", "", null, dataSourceApi),
new DataSourceOpenBrowserAction("Open in browser", "", null, dataSourceApi)
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.neueda.jetbrains.plugin.graphdb.jetbrains.ui.datasource.actions;

import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.neueda.jetbrains.plugin.graphdb.database.neo4j.bolt.Neo4jBoltConfiguration;
import com.neueda.jetbrains.plugin.graphdb.jetbrains.component.datasource.state.DataSourceApi;

import javax.swing.*;
import java.awt.*;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;

public class DataSourceOpenBrowserAction extends AnAction {

private DataSourceApi dataSource;

DataSourceOpenBrowserAction(String title, String description, Icon icon, DataSourceApi dataSource) {
super(title, description, icon);
this.dataSource = dataSource;
}

@Override
public void actionPerformed(AnActionEvent e) {
try {
String host = dataSource.getConfiguration().get(Neo4jBoltConfiguration.HOST);
openWebpage(new URI("http://" + host + ":7474"));
} catch (IOException | URISyntaxException ex) {
ex.printStackTrace();
}
}

private void openWebpage(URI uri) throws IOException {
Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null;
if (desktop != null && desktop.isSupported(Desktop.Action.BROWSE)) {
desktop.browse(uri);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ public AnAction[] getChildren(@Nullable AnActionEvent e) {
if (type == Neo4jTreeNodeType.RELATIONSHIP) {
return new AnAction[]{new MetadataRelationshipAction(data, dataSourceUuid, "Query this relationship", "", NEO4J)};
} else if (type == Neo4jTreeNodeType.LABEL) {
return new AnAction[]{new MetadataLabelAction(data, dataSourceUuid, "Query this label", "", NEO4J)};
return new AnAction[]{
new MetadataLabelAction(data, dataSourceUuid, "Nodes with this label", "", NEO4J),
new MetadataLabelFromAction(data, dataSourceUuid, "Outgoing relationships", "", NEO4J),
new MetadataLabelToAction(data, dataSourceUuid, "Incoming relationships", "", NEO4J)
};
} else if (type == Neo4jTreeNodeType.PROPERTY_KEY) {
return new AnAction[]{new MetadataPropertyKeyAction(data, dataSourceUuid, "Query this property", "", NEO4J)};
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.neueda.jetbrains.plugin.graphdb.jetbrains.ui.datasource.metadata.actions;

import javax.swing.*;

public class MetadataLabelFromAction extends MetadataAction {

private static final String QUERY = "MATCH (n:%s)-[r]->() RETURN type(r), r LIMIT 25";

MetadataLabelFromAction(String data, String dataSourceUuid, String title, String description, Icon icon) {
super(data, dataSourceUuid, title, description, icon);
}

@Override
protected String getQuery(String data) {
return String.format(QUERY, data);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.neueda.jetbrains.plugin.graphdb.jetbrains.ui.datasource.metadata.actions;

import javax.swing.*;

public class MetadataLabelToAction extends MetadataAction {

private static final String QUERY = "MATCH (n:%s)<-[r]-() RETURN type(r), r LIMIT 25";

MetadataLabelToAction(String data, String dataSourceUuid, String title, String description, Icon icon) {
super(data, dataSourceUuid, title, description, icon);
}

@Override
protected String getQuery(String data) {
return String.format(QUERY, data);
}
}