Search in sources :

Example 6 with ParcelableNode

use of org.neo4j.android.common.ParcelableNode in project neo4j-mobile-android by neo4j-contrib.

the class RelationshipActivity method updateRelationshipsList.

private void updateRelationshipsList() {
    try {
        relationshipsLayout.removeAllViews();
        GraphDatabase database = dbManager.getCurrentNeo4jDatabase();
        database.beginTx();
        try {
            ParcelableNode centerNode = database.getNodeById(centerNodeId);
            List<ParcelableRelationship> relationshipsFromCenterNode = new ArrayList<ParcelableRelationship>();
            List<ParcelableRelationship> relationshipsToCenterNode = new ArrayList<ParcelableRelationship>();
            for (ParcelableRelationship relationship : centerNode.getRelationships()) {
                if ((centerNodeId == relationship.getStartNodeId()) && (peerNodeId == relationship.getEndNodeId())) {
                    relationshipsFromCenterNode.add(relationship);
                }
                if ((centerNodeId != peerNodeId) && (peerNodeId == relationship.getStartNodeId()) && (centerNodeId == relationship.getEndNodeId())) {
                    relationshipsToCenterNode.add(relationship);
                }
            }
            Button nodeCenterButton = (Button) findViewById(R.id.nodeCenterButton);
            nodeCenterButton.setText("" + centerNodeId);
            nodeCenterButton.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    showNodePropertyActivity(centerNodeId);
                }
            });
            Button nodePeerButton = (Button) findViewById(R.id.nodePeerButton);
            if (centerNodeId == peerNodeId) {
                nodePeerButton.setVisibility(View.INVISIBLE);
            } else {
                nodePeerButton.setText("" + peerNodeId);
                nodePeerButton.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        showNodePropertyActivity(peerNodeId);
                    }
                });
            }
            for (ParcelableRelationship relationship : relationshipsFromCenterNode) {
                addRelationshipsListItem(relationship, true);
            }
            for (ParcelableRelationship relationship : relationshipsToCenterNode) {
                addRelationshipsListItem(relationship, false);
            }
        } finally {
            database.txFinish();
        }
    } catch (Exception e) {
        Ln.e(e, "database exception");
        showErrorDialog();
    }
}
Also used : GraphDatabase(org.neo4j.android.client.GraphDatabase) ImageButton(android.widget.ImageButton) Button(android.widget.Button) ArrayList(java.util.ArrayList) ParcelableRelationship(org.neo4j.android.common.ParcelableRelationship) ParcelableNode(org.neo4j.android.common.ParcelableNode) ContentView(roboguice.inject.ContentView) View(android.view.View) InjectView(roboguice.inject.InjectView) TextView(android.widget.TextView) Neo4jServiceException(org.neo4j.android.client.Neo4jServiceException) RemoteException(android.os.RemoteException)

Example 7 with ParcelableNode

use of org.neo4j.android.common.ParcelableNode in project neo4j-mobile-android by neo4j-contrib.

the class NodeActivity method createNode.

private void createNode(boolean createDefaultRelationship) throws RemoteException, Neo4jServiceException {
    GraphDatabase database = dbManager.getCurrentNeo4jDatabase();
    database.beginTx();
    try {
        ParcelableNode node = new ParcelableNode();
        long nodeId = database.createNode(node);
        Ln.i("created node '" + node + "' with id '" + nodeId + "'");
        if (createDefaultRelationship) {
            ParcelableRelationship relationship = new ParcelableRelationship();
            relationship.setStartNodeId(centerNodeId);
            relationship.setEndNodeId(nodeId);
            relationship.setName(defaultRelationshipName);
            long relationshipId = database.createRelationship(relationship);
            Ln.i("created relationship '" + relationship + "' with id '" + relationshipId + "'");
        }
        database.txSuccess();
    } finally {
        database.txFinish();
    }
}
Also used : GraphDatabase(org.neo4j.android.client.GraphDatabase) ParcelableRelationship(org.neo4j.android.common.ParcelableRelationship) ParcelableNode(org.neo4j.android.common.ParcelableNode)

Example 8 with ParcelableNode

use of org.neo4j.android.common.ParcelableNode in project neo4j-mobile-android by neo4j-contrib.

the class NodeIterator method next.

public ParcelableNode next() throws RemoteException, Neo4jServiceException {
    ParcelableError err = new ParcelableError();
    ParcelableNode result = mProxy.next(err);
    Util.throwServiceExceptionIfError(err);
    return result;
}
Also used : ParcelableNode(org.neo4j.android.common.ParcelableNode) ParcelableError(org.neo4j.android.common.ParcelableError)

Example 9 with ParcelableNode

use of org.neo4j.android.common.ParcelableNode in project neo4j-mobile-android by neo4j-contrib.

the class ParcelableFactory method makeParcelableNode.

public static ParcelableNode makeParcelableNode(Node node) {
    ParcelableNode pNode = new ParcelableNode();
    pNode.setId(node.getId());
    // shallow copy of properties
    for (String key : node.getPropertyKeys()) {
        pNode.setProperty(key, node.getProperty(key));
    }
    // shallow copy of relationships
    for (Relationship rel : node.getRelationships()) {
        ParcelableRelationship pRel = makeParcelableRelationship(rel);
        pNode.getRelationships().add(pRel);
    }
    return pNode;
}
Also used : ParcelableRelationship(org.neo4j.android.common.ParcelableRelationship) Relationship(org.neo4j.graphdb.Relationship) ParcelableRelationship(org.neo4j.android.common.ParcelableRelationship) ParcelableNode(org.neo4j.android.common.ParcelableNode)

Example 10 with ParcelableNode

use of org.neo4j.android.common.ParcelableNode in project neo4j-mobile-android by neo4j-contrib.

the class GraphDatabase method getReferenceNode.

public ParcelableNode getReferenceNode() throws RemoteException, Neo4jServiceException {
    ParcelableError err = new ParcelableError();
    ParcelableNode result = mProxy.getReferenceNode(err);
    Util.throwServiceExceptionIfError(err);
    return result;
}
Also used : ParcelableNode(org.neo4j.android.common.ParcelableNode) ParcelableError(org.neo4j.android.common.ParcelableError)

Aggregations

ParcelableNode (org.neo4j.android.common.ParcelableNode)18 GraphDatabase (org.neo4j.android.client.GraphDatabase)12 RemoteException (android.os.RemoteException)6 ParcelableRelationship (org.neo4j.android.common.ParcelableRelationship)6 Neo4jServiceException (org.neo4j.android.client.Neo4jServiceException)4 AlertDialog (android.app.AlertDialog)3 DialogInterface (android.content.DialogInterface)3 View (android.view.View)3 ArrayList (java.util.ArrayList)3 ParcelableError (org.neo4j.android.common.ParcelableError)3 ContentView (roboguice.inject.ContentView)3 InjectView (roboguice.inject.InjectView)3 TextView (android.widget.TextView)2 Formatter (java.util.Formatter)2 NodeIterator (org.neo4j.android.client.NodeIterator)2 Node (org.neo4j.graphdb.Node)2 InvalidTransactionException (org.neo4j.javax.transaction.InvalidTransactionException)2 SystemException (org.neo4j.javax.transaction.SystemException)2 Intent (android.content.Intent)1 Button (android.widget.Button)1