Search in sources :

Example 16 with GraphDatabase

use of org.neo4j.android.client.GraphDatabase 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 17 with GraphDatabase

use of org.neo4j.android.client.GraphDatabase 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 18 with GraphDatabase

use of org.neo4j.android.client.GraphDatabase 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)

Aggregations

GraphDatabase (org.neo4j.android.client.GraphDatabase)18 ParcelableNode (org.neo4j.android.common.ParcelableNode)12 ParcelableRelationship (org.neo4j.android.common.ParcelableRelationship)11 AlertDialog (android.app.AlertDialog)6 DialogInterface (android.content.DialogInterface)6 RemoteException (android.os.RemoteException)4 View (android.view.View)4 Formatter (java.util.Formatter)4 Neo4jServiceException (org.neo4j.android.client.Neo4jServiceException)4 ContentView (roboguice.inject.ContentView)4 InjectView (roboguice.inject.InjectView)4 TextView (android.widget.TextView)3 ArrayList (java.util.ArrayList)3 Intent (android.content.Intent)2 EditText (android.widget.EditText)2 NodeIterator (org.neo4j.android.client.NodeIterator)2 Button (android.widget.Button)1 ImageButton (android.widget.ImageButton)1 List (java.util.List)1 TreeSet (java.util.TreeSet)1