Search in sources :

Example 11 with ParcelableRelationship

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

the class RelationshipActivity method createRelationship.

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

Example 12 with ParcelableRelationship

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

the class RelationshipPropertiesActivity method createProperty.

private void createProperty(String key, String value) {
    try {
        GraphDatabase database = dbManager.getCurrentNeo4jDatabase();
        database.beginTx();
        try {
            ParcelableRelationship relationship = database.getRelationshipById(relationshipId);
            if (!relationship.hasProperty(key)) {
                relationship.setProperty(key, value);
                database.updateRelationship(relationship);
                database.txSuccess();
            } else {
                showPropertyAlreadyExistsError(key, value);
            }
        } finally {
            database.txFinish();
        }
    } catch (Exception e) {
        Ln.e(e, "failed to create new property with key '" + key + "' and value '" + value + "' on relationship with id '" + relationshipId + "'.");
        showErrorDialog();
    }
    updateRelationshipPropertiesList();
}
Also used : GraphDatabase(org.neo4j.android.client.GraphDatabase) ParcelableRelationship(org.neo4j.android.common.ParcelableRelationship)

Example 13 with ParcelableRelationship

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

the class RelationshipPropertiesActivity method updateRelationshipPropertiesList.

private void updateRelationshipPropertiesList() {
    try {
        relationshipPropertiesListLayout.removeAllViews();
        GraphDatabase database = dbManager.getCurrentNeo4jDatabase();
        database.beginTx();
        try {
            ParcelableRelationship relationship = database.getRelationshipById(relationshipId);
            for (String key : relationship.getPropertyKeys()) {
                Object value = relationship.getProperty(key);
                addRelationshipPropertiesListItem(key, value);
            }
        } finally {
            database.txFinish();
        }
    } catch (Exception e) {
        Ln.e(e, "database exception. relationship id '" + relationshipId + "'");
        showErrorDialog();
    }
}
Also used : GraphDatabase(org.neo4j.android.client.GraphDatabase) ParcelableRelationship(org.neo4j.android.common.ParcelableRelationship)

Example 14 with ParcelableRelationship

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

the class RelationshipPropertiesActivity method askUpdateProperty.

private void askUpdateProperty(final String key, String value) {
    AlertDialog dialog = new AlertDialog.Builder(this).create();
    dialog.setTitle(R.string.property_update_title);
    View propertyEditView = inflater.inflate(R.layout.property_edit, null);
    final TextView propertyKeyText = (TextView) propertyEditView.findViewById(R.id.propertyKeyText);
    propertyKeyText.setText(key);
    final EditText propertyValueText = (EditText) propertyEditView.findViewById(R.id.propertyValueText);
    propertyValueText.setText(value);
    dialog.setView(propertyEditView);
    dialog.setButton(getResources().getString(android.R.string.ok), new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            String value = propertyValueText.getText().toString();
            if (!value.isEmpty()) {
                try {
                    GraphDatabase database = dbManager.getCurrentNeo4jDatabase();
                    database.beginTx();
                    try {
                        ParcelableRelationship relationship = database.getRelationshipById(relationshipId);
                        relationship.setProperty(key, value);
                        database.updateRelationship(relationship);
                        database.txSuccess();
                    } finally {
                        database.txFinish();
                    }
                } catch (Exception e) {
                    Ln.e(e, "failed to update new property with key '" + key + "' and value '" + value + "' on relationship with id '" + relationshipId + "'.");
                    showErrorDialog();
                }
            } else {
                showPropertyKeyValueEmptyError(key, value);
            }
            updateRelationshipPropertiesList();
        }
    });
    dialog.setButton2(getResources().getString(android.R.string.cancel), new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.cancel();
        }
    });
    dialog.show();
}
Also used : AlertDialog(android.app.AlertDialog) EditText(android.widget.EditText) DialogInterface(android.content.DialogInterface) GraphDatabase(org.neo4j.android.client.GraphDatabase) ContentView(roboguice.inject.ContentView) InjectView(roboguice.inject.InjectView) TextView(android.widget.TextView) View(android.view.View) ParcelableRelationship(org.neo4j.android.common.ParcelableRelationship) TextView(android.widget.TextView)

Example 15 with ParcelableRelationship

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

the class NodeActivity method updateNodesList.

private void updateNodesList() {
    try {
        nodeRelationshipsLayout.removeAllViews();
        GraphDatabase database = dbManager.getCurrentNeo4jDatabase();
        database.beginTx();
        try {
            ParcelableNode centerNode = database.getNodeById(centerNodeId);
            List<ParcelableRelationship> relationships = centerNode.getRelationships();
            final Set<Long> pointingToCenterNodeNodeIds = new TreeSet<Long>();
            Set<ParcelableNode> peerNodes = new TreeSet<ParcelableNode>(new Comparator<ParcelableNode>() {

                @Override
                public int compare(ParcelableNode firstNode, ParcelableNode secondNode) {
                    if (firstNode.getId() < secondNode.getId()) {
                        return -1;
                    } else if (firstNode.getId() > secondNode.getId()) {
                        return 1;
                    } else {
                        return 0;
                    }
                }
            });
            int loopRelationshipsCount = 0;
            String lastLoopRelationshipName = "";
            for (ParcelableRelationship relationship : relationships) {
                if (relationship.getStartNodeId() == relationship.getEndNodeId()) {
                    loopRelationshipsCount++;
                    lastLoopRelationshipName = relationship.getName();
                } else {
                    if (centerNodeId == relationship.getStartNodeId()) {
                        peerNodes.add(database.getNodeById(relationship.getEndNodeId()));
                    } else {
                        pointingToCenterNodeNodeIds.add(relationship.getStartNodeId());
                        peerNodes.add(database.getNodeById(relationship.getStartNodeId()));
                    }
                }
            }
            nodeCenterButton.setText("" + centerNodeId);
            nodeCenterButton.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    if (pointingToCenterNodeNodeIds.isEmpty()) {
                    // do nothing.
                    } else if (pointingToCenterNodeNodeIds.size() == 1) {
                        showNodeActivity(pointingToCenterNodeNodeIds.iterator().next(), true);
                    } else {
                        showRelatedStartNodes(pointingToCenterNodeNodeIds);
                    }
                }
            });
            String text = getResources().getString(R.string.node_relationships_loop_button);
            if (loopRelationshipsCount == 0) {
                nodeLoopRelationshipsButton.setText(text);
            } else if (loopRelationshipsCount == 1) {
                nodeLoopRelationshipsButton.setText(text + "\n" + lastLoopRelationshipName);
            } else {
                nodeLoopRelationshipsButton.setText(text + "\n# " + loopRelationshipsCount);
            }
            nodeLoopRelationshipsButton.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    showRelationshipActivity(centerNodeId, centerNodeId);
                }
            });
            for (ParcelableNode peerNode : peerNodes) {
                addNodeRelationshipsListItem(peerNode);
            }
        } finally {
            database.txFinish();
        }
    } catch (Exception e) {
        Ln.e(e, "database exception");
        showErrorDialog();
    }
}
Also used : GraphDatabase(org.neo4j.android.client.GraphDatabase) ParcelableNode(org.neo4j.android.common.ParcelableNode) ContentView(roboguice.inject.ContentView) View(android.view.View) InjectView(roboguice.inject.InjectView) Neo4jServiceException(org.neo4j.android.client.Neo4jServiceException) RemoteException(android.os.RemoteException) TreeSet(java.util.TreeSet) ParcelableRelationship(org.neo4j.android.common.ParcelableRelationship)

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