Search in sources :

Example 1 with ParcelableNode

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

the class NodePropertiesActivity 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 {
                        ParcelableNode node = database.getNodeById(nodeId);
                        node.setProperty(key, value);
                        database.updateNode(node);
                        database.txSuccess();
                    } finally {
                        database.txFinish();
                    }
                } catch (Exception e) {
                    Ln.e(e, "failed to update new property with key '" + key + "' and value '" + value + "' on node with id '" + nodeId + "'.");
                    showErrorDialog();
                }
            } else {
                showPropertyKeyValueEmptyError(key, value);
            }
            updateNodePropertiesList();
        }
    });
    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) ParcelableNode(org.neo4j.android.common.ParcelableNode) ContentView(roboguice.inject.ContentView) View(android.view.View) InjectView(roboguice.inject.InjectView) TextView(android.widget.TextView) TextView(android.widget.TextView)

Example 2 with ParcelableNode

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

the class NodePropertiesActivity method updateNodePropertiesList.

private void updateNodePropertiesList() {
    try {
        nodePropertiesListLayout.removeAllViews();
        GraphDatabase database = dbManager.getCurrentNeo4jDatabase();
        database.beginTx();
        try {
            ParcelableNode node = database.getNodeById(nodeId);
            for (String key : node.getPropertyKeys()) {
                Object value = node.getProperty(key);
                addNodePropertiesListItem(key, value);
            }
        } finally {
            database.txFinish();
        }
    } catch (Exception e) {
        Ln.e(e, "database exception. node id '" + nodeId + "'");
        showErrorDialog();
    }
}
Also used : GraphDatabase(org.neo4j.android.client.GraphDatabase) ParcelableNode(org.neo4j.android.common.ParcelableNode)

Example 3 with ParcelableNode

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

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

the class NodePropertiesActivity method confirmDeletionOfProperty.

private void confirmDeletionOfProperty(final String key, final Object value) {
    AlertDialog dialog = new AlertDialog.Builder(this).create();
    dialog.setTitle(R.string.property_delete_title);
    Formatter formatter = new Formatter();
    formatter.format(getResources().getString(R.string.property_delete_from_node_question), key, value, nodeId);
    dialog.setMessage(formatter.toString());
    dialog.setButton(getResources().getString(android.R.string.ok), new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            try {
                GraphDatabase database = dbManager.getCurrentNeo4jDatabase();
                database.beginTx();
                try {
                    ParcelableNode node = database.getNodeById(nodeId);
                    node.removeProperty(key);
                    database.updateNode(node);
                    database.txSuccess();
                } finally {
                    database.txFinish();
                }
            } catch (Exception e) {
                Ln.e(e, "failed to delete property with key '" + key + "' and value '" + value + "' from node with id '" + nodeId + "'.");
                showErrorDialog();
            }
        }
    });
    dialog.setButton2(getResources().getString(android.R.string.cancel), 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) ParcelableNode(org.neo4j.android.common.ParcelableNode)

Example 5 with ParcelableNode

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

the class DbWrapper method createNode.

@Override
public long createNode(ParcelableNode node, ParcelableError err) throws RemoteException {
    try {
        checkCallerHasWritePermission();
        resumeTrx();
        try {
            Node newNode = mDb.createNode();
            for (String key : node.getPropertyKeys()) {
                newNode.setProperty(key, node.getProperty(key));
            }
            return newNode.getId();
        } finally {
            suspendCurrentTrx("createNode");
        }
    } catch (Exception e) {
        Log.e(TAG, "Error creating node", e);
        err.setError(Errors.TRANSACTION, e.getMessage());
        // we need to return something, caller checks error
        return -1;
    // object
    }
}
Also used : ParcelableNode(org.neo4j.android.common.ParcelableNode) Node(org.neo4j.graphdb.Node) RemoteException(android.os.RemoteException) InvalidTransactionException(org.neo4j.javax.transaction.InvalidTransactionException) SystemException(org.neo4j.javax.transaction.SystemException)

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