Example usage for com.google.gwt.gdata.client.finance TransactionData setType

List of usage examples for com.google.gwt.gdata.client.finance TransactionData setType

Introduction

In this page you can find the example usage for com.google.gwt.gdata.client.finance TransactionData setType.

Prototype

public final native void setType(String type) ;

Source Link

Document

Sets the type for the transaction (can be "Buy", "Sell", "Buy to Cover" or "Sell Short").

Usage

From source file:com.google.gwt.gdata.sample.hellogdata.client.FinanceCreateTransactionDemo.java

License:Apache License

/**
 * Create a transaction by inserting a transaction entry into
 * a transaction feed./*from www .j av  a 2s.co m*/
 * Set the transaction's notes to an arbitrary string. Here
 * we prefix the notes field with 'GWT-Finance-Client' so that
 * we can identify which transactions were created by this demo.
 * The new transaction is created with a set of transaction data
 * specifying the type and shares.
 * The transaction is inserted into the transactions feed for
 * the symbol "NASDAQ:GOOG". If no position exists for this symbol
 * the insert request will fail.
 * On success and failure, display a status message.
 * 
 * @param portfolioEditUri The uri of the portfolio entry into which
 * to insert the transaction entry
 */
private void createTransaction(String portfolioEditUri) {
    showStatus("Creating transaction...", false);
    TransactionEntry entry = TransactionEntry.newInstance();
    TransactionData data = TransactionData.newInstance();
    data.setType("Buy");
    data.setShares(141.42);
    data.setNotes("GWT-Finance-Client - inserted transaction");
    entry.setTransactionData(data);
    String ticker = "NASDAQ:GOOG";
    String transactionPostUri = portfolioEditUri + "/positions/" + ticker + "/transactions";
    service.insertEntry(transactionPostUri, entry, new TransactionEntryCallback() {
        public void onFailure(CallErrorException caught) {
            showStatus("An error occurred while creating a transaction: " + caught.getMessage(), true);
        }

        public void onSuccess(TransactionEntry result) {
            showStatus("Created a transaction.", false);
        }
    });
}