Permalink
Browse files

Merge pull request #50 from mattcasters/master

Issue #49
  • Loading branch information...
mattcasters committed Oct 3, 2018
2 parents 3749604 + c4a14b7 commit 95c09c1af0c2f75ddc32d5886c88783b67716360
@@ -4,7 +4,7 @@
<groupId>bi.know.kettle.neo4j.output</groupId>
<artifactId>Neo4JOutput</artifactId>
<version>3.13.0-SNAPSHOT</version>
<version>3.13.2-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Neo4JOutput</name>
@@ -2,6 +2,8 @@
import bi.know.kettle.neo4j.core.MetaStoreUtil;
import bi.know.kettle.neo4j.core.Neo4jDefaults;
import bi.know.kettle.neo4j.model.GraphModel;
import bi.know.kettle.neo4j.model.GraphModelDialog;
import bi.know.kettle.neo4j.shared.NeoConnection;
import bi.know.kettle.neo4j.shared.NeoConnectionUtils;
import org.apache.commons.lang.StringUtils;
@@ -19,6 +21,7 @@
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.MessageBox;
import org.pentaho.di.core.Const;
import org.pentaho.di.core.EngineMetaInterface;
import org.pentaho.di.core.logging.LogChannel;
@@ -88,8 +91,10 @@
protected List<SpoonPerspectiveListener> listeners = new ArrayList<>();
protected MetaStoreFactory<NeoConnection> connectionFactory;
protected MetaStoreFactory<GraphModel> modelsFactory;
private org.eclipse.swt.widgets.List wConnections;
private org.eclipse.swt.widgets.List wGraphModels;
Neo4jPerspective() throws XulException {
KettleXulLoader loader = new KettleXulLoader();
@@ -105,6 +110,7 @@
container.addEventHandler( this );
connectionFactory = new MetaStoreFactory<>( NeoConnection.class, Spoon.getInstance().getMetaStore(), Neo4jDefaults.NAMESPACE );
modelsFactory = new MetaStoreFactory<>( GraphModel.class, Spoon.getInstance().getMetaStore(), Neo4jDefaults.NAMESPACE );
addAdminTab();
@@ -150,8 +156,48 @@ private void addAdminTab() throws Exception {
formLayout.spacing = Const.MARGIN;
parentComposite.setLayout( formLayout );
// Add widgets...
// On the left a list of connections and buttons
// to create, edit, delete connections
//
Button wbDeleteConnection = new Button( parentComposite, SWT.PUSH );
wbDeleteConnection.setText( "Delete Connection" );
props.setLook( wbDeleteConnection );
FormData fdbDeleteConnection = new FormData();
fdbDeleteConnection.left = new FormAttachment( 0, 0 );
fdbDeleteConnection.bottom = new FormAttachment( 100, -Const.MARGIN );
wbDeleteConnection.setLayoutData( fdbDeleteConnection );
wbDeleteConnection.addListener( SWT.Selection, this::deleteConnection );
Button wbNewConnection = new Button( parentComposite, SWT.PUSH );
wbNewConnection.setText( "New Connection" );
props.setLook( wbNewConnection );
FormData fdbNewConnection = new FormData();
fdbNewConnection.left = new FormAttachment( 0, 0 );
fdbNewConnection.bottom = new FormAttachment( wbDeleteConnection, -Const.MARGIN );
fdbNewConnection.right = new FormAttachment( wbDeleteConnection, 0, SWT.RIGHT );
wbNewConnection.setLayoutData( fdbNewConnection );
wbNewConnection.addListener( SWT.Selection, this::newConnection );
Button wbEditConnection = new Button( parentComposite, SWT.PUSH );
wbEditConnection.setText( "Edit Connection" );
props.setLook( wbEditConnection );
FormData fdbEditConnection = new FormData();
fdbEditConnection.left = new FormAttachment( 0, Const.MARGIN );
fdbEditConnection.bottom = new FormAttachment( wbNewConnection, -Const.MARGIN );
fdbEditConnection.right = new FormAttachment( wbDeleteConnection, 0, SWT.RIGHT );
wbEditConnection.setLayoutData( fdbEditConnection );
wbEditConnection.addListener( SWT.Selection, this::editConnection );
Button wbOpenConnection = new Button( parentComposite, SWT.PUSH );
wbOpenConnection.setText( "Open Connection" );
props.setLook( wbOpenConnection );
FormData fdbOpenConnection = new FormData();
fdbOpenConnection.left = new FormAttachment( 0, 0 );
fdbOpenConnection.bottom = new FormAttachment( wbEditConnection, -Const.MARGIN );
fdbOpenConnection.right = new FormAttachment( wbDeleteConnection, 0, SWT.RIGHT );
wbOpenConnection.setLayoutData( fdbOpenConnection );
wbOpenConnection.addListener( SWT.Selection, this::openConnection );
Label wlConnections = new Label( parentComposite, SWT.LEFT | SWT.SINGLE );
wlConnections.setText( "Neo4j Connections" );
props.setLook( wlConnections );
@@ -166,51 +212,62 @@ private void addAdminTab() throws Exception {
FormData fdConnections = new FormData();
fdConnections.left = new FormAttachment( 0, 0 );
fdConnections.top = new FormAttachment( wlConnections, Const.MARGIN );
fdConnections.right = new FormAttachment( props.getMiddlePct(), 0 );
fdConnections.bottom = new FormAttachment( 80, 0 );
fdConnections.right = new FormAttachment( wbDeleteConnection, 0, SWT.RIGHT );
fdConnections.bottom = new FormAttachment( wbOpenConnection, -Const.MARGIN );
wConnections.setLayoutData( fdConnections );
// Add a few buttons to create, edit, delete connections
// On the right a list of graph models and buttons
// to create, edit, delete models
//
Button wbOpen = new Button( parentComposite, SWT.PUSH );
wbOpen.setText( "Open Connection" );
props.setLook( wbOpen );
Button wbNew = new Button( parentComposite, SWT.PUSH );
wbNew.setText( "New Connection" );
props.setLook( wbNew );
Button wbEdit = new Button( parentComposite, SWT.PUSH );
wbEdit.setText( "Edit Connection" );
props.setLook( wbEdit );
Button wbDelete = new Button( parentComposite, SWT.PUSH );
wbDelete.setText( "Delete Connection" );
props.setLook( wbDelete );
FormData fdbOpen = new FormData();
fdbOpen.left = new FormAttachment( props.getMiddlePct(), Const.MARGIN );
fdbOpen.top = new FormAttachment( wlConnections, Const.MARGIN );
fdbOpen.right = new FormAttachment( wbDelete, 0, SWT.RIGHT );
wbOpen.setLayoutData( fdbOpen );
wbOpen.addListener( SWT.Selection, this::openConnection );
FormData fdbNew = new FormData();
fdbNew.left = new FormAttachment( props.getMiddlePct(), Const.MARGIN );
fdbNew.top = new FormAttachment( wbOpen, Const.MARGIN );
fdbNew.right = new FormAttachment( wbDelete, 0, SWT.RIGHT );
wbNew.setLayoutData( fdbNew );
wbNew.addListener( SWT.Selection, this::newConnection );
FormData fdbEdit = new FormData();
fdbEdit.left = new FormAttachment( props.getMiddlePct(), Const.MARGIN );
fdbEdit.top = new FormAttachment( wbNew, Const.MARGIN );
fdbEdit.right = new FormAttachment( wbDelete, 0, SWT.RIGHT );
wbEdit.setLayoutData( fdbEdit );
wbEdit.addListener( SWT.Selection, this::editConnection );
FormData fdbDelete = new FormData();
fdbDelete.left = new FormAttachment( props.getMiddlePct(), Const.MARGIN );
fdbDelete.top = new FormAttachment( wbEdit, Const.MARGIN );
wbDelete.setLayoutData( fdbDelete );
wbDelete.addListener( SWT.Selection, this::deleteConnection );
Button wbDeleteGraphModel = new Button( parentComposite, SWT.PUSH );
wbDeleteGraphModel.setText( "Delete Graph Model" );
props.setLook( wbDeleteGraphModel );
FormData fdbDeleteGraphModel = new FormData();
fdbDeleteGraphModel.left = new FormAttachment( wConnections, 30 );
fdbDeleteGraphModel.bottom = new FormAttachment( 100, -Const.MARGIN );
wbDeleteGraphModel.setLayoutData( fdbDeleteGraphModel );
wbDeleteGraphModel.addListener( SWT.Selection, this::deleteGraphModel );
Button wbNewGraphModel = new Button( parentComposite, SWT.PUSH );
wbNewGraphModel.setText( "New Graph Model" );
props.setLook( wbNewGraphModel );
FormData fdbNewGraphModel = new FormData();
fdbNewGraphModel.left = new FormAttachment( wConnections, 30, 0 );
fdbNewGraphModel.bottom = new FormAttachment( wbDeleteGraphModel, -Const.MARGIN );
fdbNewGraphModel.right = new FormAttachment( wbDeleteGraphModel, 0, SWT.RIGHT );
wbNewGraphModel.setLayoutData( fdbNewGraphModel );
wbNewGraphModel.addListener( SWT.Selection, this::newGraphModel );
Button wbEditGraphModel = new Button( parentComposite, SWT.PUSH );
wbEditGraphModel.setText( "Edit Graph Model" );
props.setLook( wbEditGraphModel );
FormData fdbEditGraphModel = new FormData();
fdbEditGraphModel.left = new FormAttachment( wConnections, 30 );
fdbEditGraphModel.bottom = new FormAttachment( wbNewGraphModel, -Const.MARGIN );
fdbEditGraphModel.right = new FormAttachment( wbDeleteGraphModel, 0, SWT.RIGHT );
wbEditGraphModel.setLayoutData( fdbEditGraphModel );
wbEditGraphModel.addListener( SWT.Selection, this::editGraphModel );
Label wlGraphModels = new Label( parentComposite, SWT.LEFT | SWT.SINGLE );
wlGraphModels.setText( "Neo4j Graph Models" );
props.setLook( wlGraphModels );
FormData fdlGraphModels = new FormData();
fdlGraphModels.left = new FormAttachment( wConnections, 30 );
fdlGraphModels.top = new FormAttachment( 0, 0 );
wlGraphModels.setLayoutData( fdlGraphModels );
wGraphModels = new org.eclipse.swt.widgets.List( parentComposite, SWT.BORDER | SWT.V_SCROLL );
props.setLook( wGraphModels );
updateGraphModelsList();
FormData fdGraphModels = new FormData();
fdGraphModels.left = new FormAttachment( wConnections, 30 );
fdGraphModels.top = new FormAttachment( wlGraphModels, Const.MARGIN );
fdGraphModels.right = new FormAttachment( wbDeleteGraphModel, 0, SWT.RIGHT );
fdGraphModels.bottom = new FormAttachment( wbEditGraphModel, -Const.MARGIN );
wGraphModels.setLayoutData( fdGraphModels );
parentComposite.layout( true );
parentComposite.pack();
@@ -231,6 +288,10 @@ private void updateConnectionsList() throws MetaStoreException {
wConnections.setItems( connectionFactory.getElementNames().toArray( new String[ 0 ] ) );
}
private void updateGraphModelsList() throws MetaStoreException {
wGraphModels.setItems( modelsFactory.getElementNames().toArray( new String[ 0 ] ) );
}
private void openConnection( Event event ) {
String[] selection = wConnections.getSelection();
if ( selection == null || selection.length < 1 ) {
@@ -303,6 +364,76 @@ private void deleteConnection( Event event ) {
}
}
private void newGraphModel( Event event ) {
try {
GraphModel graphModel = new GraphModel();
editGraphModel(graphModel);
} catch ( Exception e ) {
new ErrorDialog( Spoon.getInstance().getShell(), "Error", "Unable to create graph model", e );
}
}
private void editGraphModel( Event event ) {
String[] selection = wGraphModels.getSelection();
if ( selection == null || selection.length < 1 ) {
return;
}
String modelName = selection[ 0 ];
try {
GraphModel graphModel = modelsFactory.loadElement( modelName );
if (graphModel==null) {
throw new Exception("Model '"+modelName+"' doesn't exist");
}
editGraphModel(graphModel);
updateGraphModelsList();
} catch ( Exception e ) {
new ErrorDialog( Spoon.getInstance().getShell(), "Error", "Unable to edit graph model", e );
}
}
private void editGraphModel( GraphModel graphModel ) throws MetaStoreException {
GraphModelDialog dialog = new GraphModelDialog( Spoon.getInstance().getShell(), graphModel );
if (dialog.open()) {
modelsFactory.saveElement( graphModel );
updateGraphModelsList();
}
}
private void deleteGraphModel( Event event ) {
String[] selection = wGraphModels.getSelection();
if ( selection == null || selection.length < 1 ) {
return;
}
String modelName = selection[ 0 ];
try {
MessageBox box = new MessageBox( Spoon.getInstance().getShell(), SWT.YES | SWT.NO | SWT.ICON_QUESTION );
box.setText( BaseMessages.getString( PKG, "Neo4jPerspective.DeleteGraphModelConfirmation.Title" ) );
box.setMessage( BaseMessages.getString( PKG, "Neo4jPerspective.DeleteGraphModelConfirmation.Message", modelName ) );
int answer = box.open();
if ( ( answer & SWT.YES ) != 0 ) {
try {
modelsFactory.deleteElement( modelName);
} catch ( Exception exception ) {
new ErrorDialog( Spoon.getInstance().getShell(),
BaseMessages.getString( PKG, "NeoConnectionUtils.Error.ErrorDeletingConnection.Title" ),
BaseMessages.getString( PKG, "NeoConnectionUtils.Error.ErrorDeletingConnection.Message", modelName ),
exception );
}
}
updateGraphModelsList();
} catch ( Exception e ) {
new ErrorDialog( Spoon.getInstance().getShell(), "Error", "Unable to delete graph model", e );
}
}
/**
* Gets controller
*
@@ -1 +1,6 @@
Neo4j.Perspective.perspectiveName = Neo4j Browser
Neo4jPerspective.DeleteGraphModelConfirmation.Title = Delete graph model?
Neo4jPerspective.DeleteGraphModelConfirmation.Message = Are you sure you want to delete graph model {0}?
NeoConnectionUtils.Error.ErrorDeletingConnection.Title = Error
NeoConnectionUtils.Error.ErrorDeletingConnection.Message = Error deleting graph model {0}

0 comments on commit 95c09c1

Please sign in to comment.