Search in sources :

Example 6 with Currency

use of org.openlca.core.model.Currency in project olca-modules by GreenDelta.

the class CostHandler method getReferenceCurrencyCode.

private String getReferenceCurrencyCode() {
    CurrencyDao dao = new CurrencyDao(db);
    Currency c = dao.getReferenceCurrency();
    if (c != null && c.code != null)
        return c.code;
    return "?";
}
Also used : CurrencyDao(org.openlca.core.database.CurrencyDao) Currency(org.openlca.core.model.Currency)

Example 7 with Currency

use of org.openlca.core.model.Currency in project olca-app by GreenDelta.

the class CurrencyTable method create.

void create(Composite body, FormToolkit tk) {
    Composite comp = UI.formSection(body, tk, "Other currencies", 1);
    table = Tables.createViewer(comp, "Name", "Code", "Exchange rate");
    Tables.bindColumnWidths(table, 0.4, 0.2, 0.4);
    table.setLabelProvider(new Label());
    table.setInput(getOthers());
    Tables.onDoubleClick(table, e -> {
        Currency c = Viewers.getFirstSelected(table);
        if (c != null)
            App.open(c);
    });
}
Also used : Composite(org.eclipse.swt.widgets.Composite) Currency(org.openlca.core.model.Currency)

Example 8 with Currency

use of org.openlca.core.model.Currency in project olca-app by GreenDelta.

the class CurrencyTable method getOthers.

private List<Currency> getOthers() {
    CurrencyDao dao = new CurrencyDao(Database.get());
    List<Currency> others = new ArrayList<>();
    for (Currency c : dao.getAll()) {
        if (Objects.equals(c, currency))
            continue;
        if (!Objects.equals(c.referenceCurrency, currency.referenceCurrency))
            continue;
        others.add(c);
    }
    Collections.sort(others, (c1, c2) -> {
        return Strings.compare(c1.name, c2.name);
    });
    return others;
}
Also used : CurrencyDao(org.openlca.core.database.CurrencyDao) Currency(org.openlca.core.model.Currency) ArrayList(java.util.ArrayList)

Example 9 with Currency

use of org.openlca.core.model.Currency in project olca-modules by GreenDelta.

the class CurrencyImport method map.

@Override
Currency map(JsonObject json, long id) {
    if (json == null)
        return null;
    Currency c = new Currency();
    In.mapAtts(json, c, id, conf);
    c.code = Json.getString(json, "code");
    c.conversionFactor = Json.getDouble(json, "conversionFactor", 1.0);
    String refCurrencyId = Json.getRefId(json, "referenceCurrency");
    if (Objects.equals(refCurrencyId, refId))
        c.referenceCurrency = c;
    else
        c.referenceCurrency = CurrencyImport.run(refCurrencyId, conf);
    return conf.db.put(c);
}
Also used : Currency(org.openlca.core.model.Currency)

Example 10 with Currency

use of org.openlca.core.model.Currency in project olca-modules by GreenDelta.

the class TestData method currency.

public static Currency currency(String name) {
    String currencyId = KeyGen.get("currency", name);
    CurrencyDao dao = new CurrencyDao(Tests.getDb());
    Currency currency = dao.getForRefId(currencyId);
    if (currency != null)
        return currency;
    currency = new Currency();
    currency.refId = currencyId;
    currency.name = name;
    currency.conversionFactor = 1;
    Currency ref = dao.getReferenceCurrency();
    if (ref != null)
        currency.referenceCurrency = ref;
    else
        currency.referenceCurrency = currency;
    return dao.insert(currency);
}
Also used : CurrencyDao(org.openlca.core.database.CurrencyDao) Currency(org.openlca.core.model.Currency)

Aggregations

Currency (org.openlca.core.model.Currency)20 CurrencyDao (org.openlca.core.database.CurrencyDao)9 Test (org.junit.Test)3 Category (org.openlca.core.model.Category)2 Process (org.openlca.core.model.Process)2 AbstractZipTest (org.openlca.jsonld.AbstractZipTest)2 JsonImport (org.openlca.jsonld.input.JsonImport)2 ArrayList (java.util.ArrayList)1 ComboViewer (org.eclipse.jface.viewers.ComboViewer)1 LabelProvider (org.eclipse.jface.viewers.LabelProvider)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1 Combo (org.eclipse.swt.widgets.Combo)1 Composite (org.eclipse.swt.widgets.Composite)1 Actor (org.openlca.core.model.Actor)1 DQSystem (org.openlca.core.model.DQSystem)1 Flow (org.openlca.core.model.Flow)1 FlowProperty (org.openlca.core.model.FlowProperty)1 ImpactCategory (org.openlca.core.model.ImpactCategory)1 ImpactMethod (org.openlca.core.model.ImpactMethod)1 Location (org.openlca.core.model.Location)1