use of org.openlca.core.database.CurrencyDao in project olca-app by GreenDelta.
the class CostDialog method setCurrencyContent.
private void setCurrencyContent(ComboViewer combo) {
combo.setContentProvider(ArrayContentProvider.getInstance());
CurrencyDao dao = new CurrencyDao(Database.get());
List<Currency> all = dao.getAll();
Collections.sort(all, (c1, c2) -> Strings.compare(c1.name, c2.name));
combo.setInput(all);
currency = exchange.currency;
if (currency == null)
currency = dao.getReferenceCurrency();
if (currency != null) {
combo.setSelection(new StructuredSelection(currency));
exchange.currency = currency;
}
}
use of org.openlca.core.database.CurrencyDao in project olca-app by GreenDelta.
the class RefCurrencyUpdate method run.
@Override
public void run() {
try {
CurrencyDao dao = new CurrencyDao(Database.get());
c.lastChange = Calendar.getInstance().getTimeInMillis();
Version.incUpdate(c);
c = dao.update(c);
double f = c.conversionFactor;
for (Currency o : dao.getAll()) {
o.referenceCurrency = c;
o.lastChange = Calendar.getInstance().getTimeInMillis();
Version.incUpdate(o);
if (Objects.equals(c, o)) {
o.conversionFactor = 1.0;
c = dao.update(o);
} else {
o.conversionFactor = o.conversionFactor / f;
dao.update(o);
}
}
} catch (Exception e) {
Logger log = LoggerFactory.getLogger(getClass());
log.error("failed to update reference currency", e);
}
}
Aggregations