use of org.openlca.core.model.descriptors.FlowDescriptor in project olca-app by GreenDelta.
the class JsonRefCollector method buildFlows.
private List<FlowRef> buildFlows(ZipFile zip) {
List<FlowRef> flowRefs = new ArrayList<>();
for (ZipEntry e : flowEntries) {
JsonObject obj = unpack(e, zip);
if (obj == null)
continue;
String id = Json.getString(obj, "@id");
if (id == null)
continue;
FlowRef ref = new FlowRef();
ref.flow = new FlowDescriptor();
ref.flow.refId = id;
ref.flow.name = Json.getString(obj, "name");
ref.flow.flowType = Json.getEnum(obj, "flowType", FlowType.class);
// the category
String catID = Json.getRefId(obj, "category");
ref.flowCategory = categoryPaths.get(catID);
// find the reference flow property
String propID = null;
JsonArray props = Json.getArray(obj, "flowProperties");
if (props != null) {
for (JsonElement elem : props) {
if (!elem.isJsonObject())
continue;
JsonObject prop = elem.getAsJsonObject();
boolean isRef = Json.getBool(prop, "referenceFlowProperty", false);
if (!isRef)
continue;
propID = Json.getRefId(prop, "flowProperty");
break;
}
}
if (propID != null) {
ref.property = new FlowPropertyDescriptor();
ref.property.refId = propID;
ref.property.name = propertyNames.get(propID);
String unitID = propertyUnits.get(propID);
if (unitID != null) {
ref.unit = new UnitDescriptor();
ref.unit.refId = unitID;
ref.unit.name = unitNames.get(unitID);
}
}
flowRefs.add(ref);
}
return flowRefs;
}
use of org.openlca.core.model.descriptors.FlowDescriptor in project olca-app by GreenDelta.
the class LocationPage method onSelected.
private void onSelected(Object obj) {
label.update(obj);
if (obj instanceof FlowDescriptor) {
FlowDescriptor f = (FlowDescriptor) obj;
update(locations.getContributions(f));
return;
}
if (obj instanceof ImpactDescriptor) {
var i = (ImpactDescriptor) obj;
update(locations.getContributions(i));
return;
}
if (obj instanceof CostResultDescriptor) {
var c = (CostResultDescriptor) obj;
if (c.forAddedValue) {
update(locations.getAddedValueContributions());
} else {
update(locations.getNetCostsContributions());
}
}
}
use of org.openlca.core.model.descriptors.FlowDescriptor in project olca-app by GreenDelta.
the class LabelProvider method getText.
@Override
public String getText(Object obj, int col) {
if (!(obj instanceof Item))
return null;
Item item = (Item) obj;
FlowDescriptor flow = flowOf(item);
switch(col) {
case 0:
return item.name();
// flow name
case 1:
return !item.isProvider() || flow == null ? null : Labels.name(flow);
// amount
case 2:
if (item.isProvider()) {
return Numbers.format(item.asProvider().amount);
}
if (item.isChild()) {
return Numbers.format(item.asChild().amount);
}
return null;
// unit
case 3:
return flow == null ? null : Labels.refUnit(flow);
// cost values
case 4:
if (!item.isProvider())
return null;
var val = item.asProvider().costValue;
return Numbers.decimalFormat(val, 2) + " " + currency;
default:
return null;
}
}
use of org.openlca.core.model.descriptors.FlowDescriptor in project olca-app by GreenDelta.
the class ReplaceFlowsDialog method getUsed.
private List<FlowDescriptor> getUsed() {
FlowDao dao = new FlowDao(Database.get());
Set<Long> ids = dao.getUsed();
List<FlowDescriptor> result = new ArrayList<>();
result.add(new FlowDescriptor());
result.addAll(dao.getDescriptors(ids));
return result;
}
use of org.openlca.core.model.descriptors.FlowDescriptor in project olca-app by GreenDelta.
the class ReplaceFlowsDialog method okPressed.
@Override
protected void okPressed() {
FlowDescriptor oldFlow = selectionViewer.getSelected();
FlowDescriptor newFlow = replacementViewer.getSelected();
FlowDao dao = new FlowDao(Database.get());
boolean replaceFlows = replaceBothButton.getSelection() || replaceFlowsButton.getSelection();
boolean replaceImpacts = replaceBothButton.getSelection() || replaceImpactsButton.getSelection();
if (replaceFlows) {
if (excludeWithProviders.getSelection()) {
dao.replaceExchangeFlowsWithoutProviders(oldFlow.id, newFlow.id);
} else {
dao.replaceExchangeFlows(oldFlow.id, newFlow.id);
}
}
if (replaceImpacts) {
dao.replaceImpactFlows(oldFlow.id, newFlow.id);
}
Database.get().getEntityFactory().getCache().evictAll();
super.okPressed();
}
Aggregations