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 "?";
}
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);
});
}
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;
}
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);
}
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);
}
Aggregations