use of org.openlca.core.model.descriptors.ImpactMethodDescriptor in project olca-app by GreenDelta.
the class ImpactPage method createFormContent.
@Override
protected void createFormContent(IManagedForm mform) {
ScrolledForm form = UI.formHeader(this);
FormToolkit tk = mform.getToolkit();
Composite body = UI.formBody(form, tk);
Composite comp = tk.createComposite(body);
UI.gridLayout(comp, 4);
UI.formLabel(comp, tk, M.ImpactAssessmentMethod);
combo = new ImpactMethodViewer(comp);
List<ImpactMethodDescriptor> list = new ImpactMethodDao(Database.get()).getDescriptors().stream().sorted((m1, m2) -> Strings.compare(m1.name, m2.name)).collect(Collectors.toList());
combo.setInput(list);
combo.addSelectionChangedListener(this::setTreeInput);
zeroCheck = tk.createButton(comp, M.ExcludeZeroValues, SWT.CHECK);
zeroCheck.setSelection(true);
Controls.onSelect(zeroCheck, e -> setTreeInput(combo.getSelected()));
Button reload = tk.createButton(comp, M.Reload, SWT.NONE);
reload.setImage(Icon.REFRESH.get());
Controls.onSelect(reload, _e -> {
result = null;
setTreeInput(combo.getSelected());
});
tree = Trees.createViewer(body, M.Name, M.Category, M.Amount, M.Result);
UI.gridData(tree.getControl(), true, true);
tree.setContentProvider(new Content());
tree.setLabelProvider(new Label());
Trees.bindColumnWidths(tree.getTree(), 0.35, 0.35, 0.15, 0.15);
tree.getTree().getColumns()[2].setAlignment(SWT.RIGHT);
tree.getTree().getColumns()[3].setAlignment(SWT.RIGHT);
Action onOpen = Actions.onOpen(() -> {
Contribution<?> c = Viewers.getFirstSelected(tree);
if (c == null)
return;
if (c.item instanceof EnviFlow) {
App.open(((EnviFlow) c.item).flow());
}
if (c.item instanceof ImpactDescriptor) {
App.open((ImpactDescriptor) c.item);
}
});
Actions.bind(tree, onOpen);
Trees.onDoubleClick(tree, e -> onOpen.run());
if (!list.isEmpty()) {
ImpactMethodDescriptor m = list.get(0);
combo.select(m);
setTreeInput(m);
}
form.reflow(true);
}
use of org.openlca.core.model.descriptors.ImpactMethodDescriptor in project olca-modules by GreenDelta.
the class RefSwitcher method getDestImpactMethodId.
Long getDestImpactMethodId(Long srcMethodId) {
if (srcMethodId == null)
return null;
ImpactMethodDao srcDao = new ImpactMethodDao(source);
ImpactMethodDescriptor srcDescriptor = srcDao.getDescriptor(srcMethodId);
if (srcDescriptor == null)
return null;
return seq.get(seq.IMPACT_METHOD, srcDescriptor.refId);
}
use of org.openlca.core.model.descriptors.ImpactMethodDescriptor in project olca-modules by GreenDelta.
the class ImpactMethodExport method doIt.
@Override
protected void doIt(CSVPrinter printer, IDatabase db) throws IOException {
log.trace("write impact methods");
ImpactMethodDao dao = new ImpactMethodDao(db);
CategoryDao categoryDao = new CategoryDao(db);
List<ImpactMethodDescriptor> methods = dao.getDescriptors();
for (ImpactMethodDescriptor method : methods) {
Object[] line = createLine(method, categoryDao);
printer.printRecord(line);
}
log.trace("{} impact methods written", methods.size());
}
use of org.openlca.core.model.descriptors.ImpactMethodDescriptor in project olca-app by GreenDelta.
the class ImpactPage method setTreeInput.
private void setTreeInput(ImpactMethodDescriptor method) {
if (tree == null)
return;
if (method == null) {
tree.setInput(Collections.emptyList());
return;
}
if (result == null) {
App.runInUI("Compute LCIA results ...", () -> {
result = compute();
setTreeInput(method);
});
return;
}
if (!result.hasEnviFlows() || !result.hasImpacts()) {
tree.setInput(Collections.emptyList());
return;
}
List<Contribution<?>> cons = new ImpactMethodDao(Database.get()).getCategoryDescriptors(method.id).stream().sorted((d1, d2) -> Strings.compare(d1.name, d2.name)).map(d -> {
var c = Contribution.of(d, result.getTotalImpactResult(d));
c.unit = d.referenceUnit;
return c;
}).collect(Collectors.toList());
tree.setInput(cons);
}
Aggregations