Search in sources :

Example 1 with ParcelableRelationship

use of org.neo4j.android.common.ParcelableRelationship 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 2 with ParcelableRelationship

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

the class NodeActivity method addNodeRelationshipsListItem.

private void addNodeRelationshipsListItem(ParcelableNode peerNode) {
    final long peerNodeId = peerNode.getId();
    List<ParcelableRelationship> relationships = peerNode.getRelationships();
    boolean foundBackwardRelationship = false;
    boolean foundForwardRelationship = false;
    long lastRelationshipId = 0;
    String lastRelationshipName = "";
    int relationshipCount = 0;
    for (ParcelableRelationship relationship : relationships) {
        if (relationship.getStartNodeId() == centerNodeId) {
            foundForwardRelationship = true;
            relationshipCount++;
            lastRelationshipId = relationship.getId();
            lastRelationshipName = relationship.getName();
        }
        if (relationship.getEndNodeId() == centerNodeId) {
            foundBackwardRelationship = true;
            relationshipCount++;
            lastRelationshipId = relationship.getId();
            lastRelationshipName = relationship.getName();
        }
    }
    View nodeRelationshipsListItem = inflater.inflate(R.layout.node_activity_listitem, null);
    Button relationshipsButton = (Button) nodeRelationshipsListItem.findViewById(R.id.nodeItemRelationshipButton);
    String text;
    if (foundForwardRelationship && foundBackwardRelationship) {
        text = getResources().getString(R.string.node_relationships_both_button);
    } else if (foundForwardRelationship) {
        text = getResources().getString(R.string.node_relationships_forward_button);
    } else if (foundBackwardRelationship) {
        text = getResources().getString(R.string.node_relationships_backward_button);
    } else {
        text = getResources().getString(R.string.node_relationships_unknown_button);
    }
    if (relationshipCount == 1) {
        relationshipsButton.setText(text + "\n" + lastRelationshipId + "\n" + lastRelationshipName);
    } else {
        relationshipsButton.setText(text + "\n# " + relationshipCount);
    }
    relationshipsButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            showRelationshipActivity(centerNodeId, peerNodeId);
        }
    });
    Button nodeButton = (Button) nodeRelationshipsListItem.findViewById(R.id.nodeItemNodeButton);
    nodeButton.setText("" + peerNode.getId());
    nodeButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            showNodeActivity(peerNodeId, false);
        }
    });
    nodeRelationshipsLayout.addView(nodeRelationshipsListItem);
}
Also used : ImageButton(android.widget.ImageButton) Button(android.widget.Button) ParcelableRelationship(org.neo4j.android.common.ParcelableRelationship) ContentView(roboguice.inject.ContentView) View(android.view.View) InjectView(roboguice.inject.InjectView)

Example 3 with ParcelableRelationship

use of org.neo4j.android.common.ParcelableRelationship 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 4 with ParcelableRelationship

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

the class NodePropertiesActivity method confirmDeletionOfNode.

private void confirmDeletionOfNode() {
    AlertDialog dialog = new AlertDialog.Builder(this).create();
    dialog.setTitle(R.string.node_delete_title);
    Formatter formatter = new Formatter();
    formatter.format(getResources().getString(R.string.node_delete_question), nodeId);
    dialog.setMessage(formatter.toString());
    dialog.setButton(getResources().getString(android.R.string.yes), new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            try {
                GraphDatabase database = dbManager.getCurrentNeo4jDatabase();
                database.beginTx();
                try {
                    ParcelableNode node = database.getNodeById(nodeId);
                    ParcelableNode referenceNode = database.getReferenceNode();
                    if (nodeId != referenceNode.getId()) {
                        List<ParcelableRelationship> relationships = node.getRelationships();
                        for (ParcelableRelationship relationship : relationships) {
                            database.deleteRelationship(relationship.getId());
                        }
                        database.deleteNode(nodeId);
                        database.txSuccess();
                    } else {
                        showCannotDeleteReferenceNodeError();
                    }
                } finally {
                    database.txFinish();
                }
                Intent data = new Intent();
                data.putExtra(DBInspectorConstants.INTENTEXTRA_NODE_DELETED, true);
                setResult(RESULT_OK, data);
                finish();
            } catch (Exception e) {
                Ln.e(e, "failed to delete node with id '" + nodeId + "'.");
                showErrorDialog();
            }
        }
    });
    dialog.setButton2(getResources().getString(android.R.string.no), new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.cancel();
        }
    });
    dialog.show();
    formatter.close();
}
Also used : AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) GraphDatabase(org.neo4j.android.client.GraphDatabase) Formatter(java.util.Formatter) Intent(android.content.Intent) ParcelableNode(org.neo4j.android.common.ParcelableNode) ParcelableRelationship(org.neo4j.android.common.ParcelableRelationship) List(java.util.List)

Example 5 with ParcelableRelationship

use of org.neo4j.android.common.ParcelableRelationship 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)

Aggregations

ParcelableRelationship (org.neo4j.android.common.ParcelableRelationship)17 GraphDatabase (org.neo4j.android.client.GraphDatabase)11 ParcelableNode (org.neo4j.android.common.ParcelableNode)7 AlertDialog (android.app.AlertDialog)4 DialogInterface (android.content.DialogInterface)4 RemoteException (android.os.RemoteException)4 View (android.view.View)4 ContentView (roboguice.inject.ContentView)4 InjectView (roboguice.inject.InjectView)4 Formatter (java.util.Formatter)3 Relationship (org.neo4j.graphdb.Relationship)3 Intent (android.content.Intent)2 Button (android.widget.Button)2 ImageButton (android.widget.ImageButton)2 TextView (android.widget.TextView)2 Neo4jServiceException (org.neo4j.android.client.Neo4jServiceException)2 InvalidTransactionException (org.neo4j.javax.transaction.InvalidTransactionException)2 SystemException (org.neo4j.javax.transaction.SystemException)2 EditText (android.widget.EditText)1 ArrayList (java.util.ArrayList)1