Skip to content

Commit 1ef53c1

Browse files
committed
Starting to build UI
1 parent 968baa3 commit 1ef53c1

16 files changed

Lines changed: 582 additions & 107 deletions

modules/Neo4jPlugin/README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
## Neo4J plugin
1+
## Neo4j plugin
22

3-
This README supports Markdown, see [syntax](https://help.github.com/articles/markdown-basics/)
3+
This plugin allows you to import a network from Neo4j database 4.X.
4+
5+
Three modes are available :
6+
7+
- Import the full database
8+
- Import just a set of node labels and relationship types
9+
- Import by specifying a query for nodes and edges
410

modules/Neo4jPlugin/src/main/java/org/gephi/plugins/neo4j/importer/Neo4jDatabaseImporter.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,34 @@ public class Neo4jDatabaseImporter implements WizardImporter, LongTask {
8686
private String edgeQuery;
8787

8888
/**
89-
* Neo4J driver instance.
89+
* Neo4j driver instance.
9090
*/
9191
private Driver driver;
9292

93+
94+
public static void checkConnection(String url, String username, String password, String dbName) {
95+
Driver driver = GraphDatabase.driver(url, password != null ? AuthTokens.basic(username, password) : AuthTokens.none());
96+
try {
97+
driver.verifyConnectivity();
98+
driver.session(dbName != null ? SessionConfig.forDatabase(dbName) : SessionConfig.defaultConfig()).run("RETURN 1");
99+
} catch (Exception e) {
100+
throw e;
101+
} finally {
102+
driver.close();
103+
}
104+
}
105+
106+
public static void checkQuery(String url, String username, String password, String dbName, String query) {
107+
Driver driver = GraphDatabase.driver(url, password != null ? AuthTokens.basic(username, password) : AuthTokens.none(), Config.builder().withFetchSize(5).build());
108+
try {
109+
driver.session(dbName != null ? SessionConfig.forDatabase(dbName) : SessionConfig.defaultConfig()).run(query);
110+
} catch (Exception e) {
111+
throw e;
112+
} finally {
113+
driver.close();
114+
}
115+
}
116+
93117
@Override
94118
public boolean execute(ContainerLoader containerLoader) {
95119
this.container = containerLoader;
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="org.gephi.plugins.neo4j.importer.ui.Neo4jDatabaseImporterConnectionPanel">
3+
<grid id="27dc6" layout-manager="GridLayoutManager" row-count="7" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
4+
<margin top="20" left="20" bottom="20" right="20"/>
5+
<constraints>
6+
<xy x="20" y="20" width="500" height="400"/>
7+
</constraints>
8+
<properties/>
9+
<border type="none"/>
10+
<children>
11+
<component id="8ebfa" class="javax.swing.JTextField" binding="dbUrl">
12+
<constraints>
13+
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
14+
<preferred-size width="150" height="-1"/>
15+
</grid>
16+
</constraints>
17+
<properties>
18+
<text value="neo4j://localhost"/>
19+
</properties>
20+
</component>
21+
<component id="ae5ba" class="javax.swing.JLabel" binding="dbUrlLabel">
22+
<constraints>
23+
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="4" fill="0" indent="0" use-parent-layout="false"/>
24+
</constraints>
25+
<properties>
26+
<labelFor value="8ebfa"/>
27+
<text value="URL"/>
28+
</properties>
29+
</component>
30+
<component id="7485a" class="javax.swing.JTextField" binding="dbUsername">
31+
<constraints>
32+
<grid row="4" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
33+
<preferred-size width="150" height="-1"/>
34+
</grid>
35+
</constraints>
36+
<properties>
37+
<text value="neo4j"/>
38+
</properties>
39+
</component>
40+
<component id="85717" class="javax.swing.JPasswordField" binding="dbPassword">
41+
<constraints>
42+
<grid row="5" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
43+
<preferred-size width="150" height="-1"/>
44+
</grid>
45+
</constraints>
46+
<properties/>
47+
</component>
48+
<component id="d769d" class="javax.swing.JLabel" binding="dbUsernameLabel">
49+
<constraints>
50+
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="4" fill="0" indent="0" use-parent-layout="false"/>
51+
</constraints>
52+
<properties>
53+
<labelFor value="7485a"/>
54+
<text value="Username"/>
55+
</properties>
56+
</component>
57+
<component id="4b830" class="javax.swing.JLabel" binding="dbPasswordLabel">
58+
<constraints>
59+
<grid row="5" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="4" fill="0" indent="0" use-parent-layout="false"/>
60+
</constraints>
61+
<properties>
62+
<labelFor value="85717"/>
63+
<text value="Password"/>
64+
</properties>
65+
</component>
66+
<component id="8ed5c" class="javax.swing.JButton" binding="checkConnectivity">
67+
<constraints>
68+
<grid row="6" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
69+
</constraints>
70+
<properties>
71+
<enabled value="true"/>
72+
<text value="Check connectivity"/>
73+
</properties>
74+
</component>
75+
<component id="56259" class="javax.swing.JLabel" binding="dbNameLabel">
76+
<constraints>
77+
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
78+
</constraints>
79+
<properties>
80+
<labelFor value="397ee"/>
81+
<text value="Database"/>
82+
</properties>
83+
</component>
84+
<component id="397ee" class="javax.swing.JTextField" binding="dbName">
85+
<constraints>
86+
<grid row="3" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
87+
<preferred-size width="150" height="-1"/>
88+
</grid>
89+
</constraints>
90+
<properties>
91+
<text value="neo4j"/>
92+
</properties>
93+
</component>
94+
<component id="e0a53" class="javax.swing.JLabel" binding="error">
95+
<constraints>
96+
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
97+
</constraints>
98+
<properties>
99+
<enabled value="true"/>
100+
<foreground color="-65536"/>
101+
<text value="Label"/>
102+
<visible value="false"/>
103+
</properties>
104+
</component>
105+
<component id="b8544" class="javax.swing.JLabel" binding="success">
106+
<constraints>
107+
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
108+
</constraints>
109+
<properties>
110+
<foreground color="-16711936"/>
111+
<text value="Connection successful"/>
112+
<visible value="false"/>
113+
</properties>
114+
</component>
115+
</children>
116+
</grid>
117+
</form>
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package org.gephi.plugins.neo4j.importer.ui;
2+
3+
import org.gephi.plugins.neo4j.importer.Neo4jDatabaseImporter;
4+
5+
import javax.swing.*;
6+
import java.awt.event.ActionEvent;
7+
import java.awt.event.ActionListener;
8+
9+
public class Neo4jDatabaseImporterConnectionPanel extends javax.swing.JPanel {
10+
11+
private JTextField dbUrl;
12+
private JLabel dbUrlLabel;
13+
private JTextField dbUsername;
14+
private JPasswordField dbPassword;
15+
private JLabel dbUsernameLabel;
16+
private JLabel dbPasswordLabel;
17+
private JButton checkConnectivity;
18+
private JTextField dbName;
19+
private JLabel dbNameLabel;
20+
private JLabel error;
21+
private JLabel success;
22+
23+
24+
public Neo4jDatabaseImporterConnectionPanel() {
25+
26+
checkConnectivity.addActionListener(new ActionListener() {
27+
@Override
28+
public void actionPerformed(ActionEvent event) {
29+
checkConnectivity.setEnabled(false);
30+
dbUsername.setEnabled(false);
31+
dbPassword.setEnabled(false);
32+
dbUrl.setEnabled(false);
33+
dbName.setEnabled(false);
34+
try {
35+
error.setVisible(false);
36+
success.setVisible(false);
37+
// TODO: need to check inputs
38+
Neo4jDatabaseImporter.checkConnection(dbUrl.getText(), dbUsername.getText(), dbPassword.getText(), dbName.getText());
39+
success.setVisible(true);
40+
} catch (Exception e) {
41+
error.setVisible(true);
42+
error.setText(e.getMessage());
43+
}
44+
finally {
45+
checkConnectivity.setEnabled(true);
46+
dbUsername.setEnabled(true);
47+
dbPassword.setEnabled(true);
48+
dbUrl.setEnabled(true);
49+
dbName.setEnabled(true);
50+
}
51+
}
52+
});
53+
}
54+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package org.gephi.plugins.neo4j.importer.ui;
2+
3+
import org.openide.WizardDescriptor;
4+
import org.openide.util.HelpCtx;
5+
6+
import javax.swing.event.ChangeListener;
7+
import java.awt.*;
8+
import java.beans.PropertyChangeEvent;
9+
import java.beans.PropertyChangeListener;
10+
11+
public class Neo4jDatabaseImporterConnectionWizard implements WizardDescriptor.Panel<WizardDescriptor>, PropertyChangeListener {
12+
13+
private Neo4jDatabaseImporterConnectionPanel component = new Neo4jDatabaseImporterConnectionPanel();
14+
15+
@Override
16+
public void propertyChange(PropertyChangeEvent evt) {
17+
18+
}
19+
20+
@Override
21+
public Component getComponent() {
22+
return this.component;
23+
}
24+
25+
@Override
26+
public HelpCtx getHelp() {
27+
return null;
28+
}
29+
30+
@Override
31+
public void readSettings(WizardDescriptor settings) {
32+
33+
}
34+
35+
@Override
36+
public void storeSettings(WizardDescriptor settings) {
37+
}
38+
39+
@Override
40+
public boolean isValid() {
41+
return false;
42+
}
43+
44+
@Override
45+
public void addChangeListener(ChangeListener l) {
46+
47+
}
48+
49+
@Override
50+
public void removeChangeListener(ChangeListener l) {
51+
52+
}
53+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="org.gephi.plugins.neo4j.importer.ui.Neo4jDatabaseImporterQueriesPanel">
3+
<grid id="27dc6" layout-manager="GridLayoutManager" row-count="4" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
4+
<margin top="0" left="0" bottom="0" right="0"/>
5+
<constraints>
6+
<xy x="20" y="20" width="470" height="400"/>
7+
</constraints>
8+
<properties/>
9+
<border type="none"/>
10+
<children>
11+
<component id="3631c" class="javax.swing.JLabel" binding="nodeQueryLabel">
12+
<constraints>
13+
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="9" fill="0" indent="0" use-parent-layout="false"/>
14+
</constraints>
15+
<properties>
16+
<labelFor value="f2b76"/>
17+
<text value="Node query"/>
18+
<toolTipText value="Query MUST returns an `id` column "/>
19+
</properties>
20+
</component>
21+
<component id="39dc4" class="javax.swing.JButton" binding="checkNodeQUeryButton">
22+
<constraints>
23+
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="4" fill="0" indent="0" use-parent-layout="false"/>
24+
</constraints>
25+
<properties>
26+
<text value="Check"/>
27+
</properties>
28+
</component>
29+
<component id="c6de5" class="javax.swing.JLabel" binding="edgeQueryLabel">
30+
<constraints>
31+
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="9" fill="0" indent="0" use-parent-layout="false"/>
32+
</constraints>
33+
<properties>
34+
<labelFor value="ca361"/>
35+
<text value="Edge query"/>
36+
</properties>
37+
</component>
38+
<component id="f2b76" class="javax.swing.JTextArea" binding="nodeQuery">
39+
<constraints>
40+
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="6" hsize-policy="6" anchor="0" fill="3" indent="0" use-parent-layout="false">
41+
<preferred-size width="150" height="50"/>
42+
</grid>
43+
</constraints>
44+
<properties/>
45+
</component>
46+
<component id="ca361" class="javax.swing.JTextArea" binding="edgeQuery">
47+
<constraints>
48+
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="6" hsize-policy="6" anchor="0" fill="3" indent="0" use-parent-layout="false">
49+
<preferred-size width="150" height="50"/>
50+
</grid>
51+
</constraints>
52+
<properties/>
53+
</component>
54+
<component id="59801" class="javax.swing.JButton" binding="checkEdgeQueryButton">
55+
<constraints>
56+
<grid row="3" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="4" fill="0" indent="0" use-parent-layout="false"/>
57+
</constraints>
58+
<properties>
59+
<text value="Check"/>
60+
</properties>
61+
</component>
62+
</children>
63+
</grid>
64+
</form>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package org.gephi.plugins.neo4j.importer.ui;
2+
3+
import javax.swing.*;
4+
import java.awt.event.ActionEvent;
5+
import java.awt.event.ActionListener;
6+
7+
public class Neo4jDatabaseImporterQueriesPanel extends javax.swing.JPanel {
8+
private JLabel nodeQueryLabel;
9+
private JButton checkNodeQUeryButton;
10+
private JLabel edgeQueryLabel;
11+
private JTextArea nodeQuery;
12+
private JTextArea edgeQuery;
13+
private JButton checkEdgeQueryButton;
14+
15+
public Neo4jDatabaseImporterQueriesPanel() {
16+
checkNodeQUeryButton.addActionListener(new ActionListener() {
17+
@Override
18+
public void actionPerformed(ActionEvent e) {
19+
20+
}
21+
});
22+
checkEdgeQueryButton.addActionListener(new ActionListener() {
23+
@Override
24+
public void actionPerformed(ActionEvent e) {
25+
26+
}
27+
});
28+
}
29+
}

0 commit comments

Comments
 (0)