Search in sources :

Example 1 with ImpactMethodDescriptor

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);
}
Also used : ParameterTable(org.openlca.core.matrix.ParameterTable) App(org.openlca.app.App) Controls(org.openlca.app.util.Controls) Images(org.openlca.app.rcp.images.Images) ModelType(org.openlca.core.model.ModelType) Database(org.openlca.app.db.Database) Actions(org.openlca.app.util.Actions) EnviFlow(org.openlca.core.matrix.index.EnviFlow) TechIndex(org.openlca.core.matrix.index.TechIndex) EnviIndex(org.openlca.core.matrix.index.EnviIndex) Composite(org.eclipse.swt.widgets.Composite) ReferenceAmount(org.openlca.core.math.ReferenceAmount) ImpactMethodViewer(org.openlca.app.viewers.combo.ImpactMethodViewer) Icon(org.openlca.app.rcp.images.Icon) ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) FlowType(org.openlca.core.model.FlowType) Descriptor(org.openlca.core.model.descriptors.Descriptor) ITableLabelProvider(org.eclipse.jface.viewers.ITableLabelProvider) Button(org.eclipse.swt.widgets.Button) Process(org.openlca.core.model.Process) ContributionImage(org.openlca.app.components.ContributionImage) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) IManagedForm(org.eclipse.ui.forms.IManagedForm) Collectors(java.util.stream.Collectors) TechFlow(org.openlca.core.matrix.index.TechFlow) List(java.util.List) Strings(org.openlca.util.Strings) UI(org.openlca.app.util.UI) Contribution(org.openlca.core.results.Contribution) SWT(org.eclipse.swt.SWT) TreeViewer(org.eclipse.jface.viewers.TreeViewer) ImpactIndex(org.openlca.core.matrix.index.ImpactIndex) ImpactBuilder(org.openlca.core.matrix.ImpactBuilder) M(org.openlca.app.M) Labels(org.openlca.app.util.Labels) EagerResultProvider(org.openlca.core.results.providers.EagerResultProvider) ModelPage(org.openlca.app.editors.ModelPage) Trees(org.openlca.app.viewers.trees.Trees) Image(org.eclipse.swt.graphics.Image) ImpactMethodDao(org.openlca.core.database.ImpactMethodDao) ArrayList(java.util.ArrayList) Viewers(org.openlca.app.viewers.Viewers) HashSet(java.util.HashSet) MatrixBuilder(org.openlca.core.matrix.format.MatrixBuilder) Exchange(org.openlca.core.model.Exchange) JavaMatrix(org.openlca.core.matrix.format.JavaMatrix) MatrixData(org.openlca.core.matrix.MatrixData) Numbers(org.openlca.app.util.Numbers) FormToolkit(org.eclipse.ui.forms.widgets.FormToolkit) Action(org.eclipse.jface.action.Action) SolverContext(org.openlca.core.results.providers.SolverContext) ScrolledForm(org.eclipse.ui.forms.widgets.ScrolledForm) ContributionResult(org.openlca.core.results.ContributionResult) ImpactDescriptor(org.openlca.core.model.descriptors.ImpactDescriptor) ImpactMethodDescriptor(org.openlca.core.model.descriptors.ImpactMethodDescriptor) Collections(java.util.Collections) Action(org.eclipse.jface.action.Action) FormToolkit(org.eclipse.ui.forms.widgets.FormToolkit) Composite(org.eclipse.swt.widgets.Composite) EnviFlow(org.openlca.core.matrix.index.EnviFlow) ImpactDescriptor(org.openlca.core.model.descriptors.ImpactDescriptor) ImpactMethodViewer(org.openlca.app.viewers.combo.ImpactMethodViewer) Button(org.eclipse.swt.widgets.Button) ScrolledForm(org.eclipse.ui.forms.widgets.ScrolledForm) ImpactMethodDescriptor(org.openlca.core.model.descriptors.ImpactMethodDescriptor) ImpactMethodDao(org.openlca.core.database.ImpactMethodDao)

Example 2 with ImpactMethodDescriptor

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);
}
Also used : ImpactMethodDescriptor(org.openlca.core.model.descriptors.ImpactMethodDescriptor) ImpactMethodDao(org.openlca.core.database.ImpactMethodDao)

Example 3 with ImpactMethodDescriptor

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());
}
Also used : CategoryDao(org.openlca.core.database.CategoryDao) ImpactMethodDescriptor(org.openlca.core.model.descriptors.ImpactMethodDescriptor) ImpactMethodDao(org.openlca.core.database.ImpactMethodDao)

Example 4 with ImpactMethodDescriptor

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);
}
Also used : ParameterTable(org.openlca.core.matrix.ParameterTable) App(org.openlca.app.App) Controls(org.openlca.app.util.Controls) Images(org.openlca.app.rcp.images.Images) ModelType(org.openlca.core.model.ModelType) Database(org.openlca.app.db.Database) Actions(org.openlca.app.util.Actions) EnviFlow(org.openlca.core.matrix.index.EnviFlow) TechIndex(org.openlca.core.matrix.index.TechIndex) EnviIndex(org.openlca.core.matrix.index.EnviIndex) Composite(org.eclipse.swt.widgets.Composite) ReferenceAmount(org.openlca.core.math.ReferenceAmount) ImpactMethodViewer(org.openlca.app.viewers.combo.ImpactMethodViewer) Icon(org.openlca.app.rcp.images.Icon) ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) FlowType(org.openlca.core.model.FlowType) Descriptor(org.openlca.core.model.descriptors.Descriptor) ITableLabelProvider(org.eclipse.jface.viewers.ITableLabelProvider) Button(org.eclipse.swt.widgets.Button) Process(org.openlca.core.model.Process) ContributionImage(org.openlca.app.components.ContributionImage) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) IManagedForm(org.eclipse.ui.forms.IManagedForm) Collectors(java.util.stream.Collectors) TechFlow(org.openlca.core.matrix.index.TechFlow) List(java.util.List) Strings(org.openlca.util.Strings) UI(org.openlca.app.util.UI) Contribution(org.openlca.core.results.Contribution) SWT(org.eclipse.swt.SWT) TreeViewer(org.eclipse.jface.viewers.TreeViewer) ImpactIndex(org.openlca.core.matrix.index.ImpactIndex) ImpactBuilder(org.openlca.core.matrix.ImpactBuilder) M(org.openlca.app.M) Labels(org.openlca.app.util.Labels) EagerResultProvider(org.openlca.core.results.providers.EagerResultProvider) ModelPage(org.openlca.app.editors.ModelPage) Trees(org.openlca.app.viewers.trees.Trees) Image(org.eclipse.swt.graphics.Image) ImpactMethodDao(org.openlca.core.database.ImpactMethodDao) ArrayList(java.util.ArrayList) Viewers(org.openlca.app.viewers.Viewers) HashSet(java.util.HashSet) MatrixBuilder(org.openlca.core.matrix.format.MatrixBuilder) Exchange(org.openlca.core.model.Exchange) JavaMatrix(org.openlca.core.matrix.format.JavaMatrix) MatrixData(org.openlca.core.matrix.MatrixData) Numbers(org.openlca.app.util.Numbers) FormToolkit(org.eclipse.ui.forms.widgets.FormToolkit) Action(org.eclipse.jface.action.Action) SolverContext(org.openlca.core.results.providers.SolverContext) ScrolledForm(org.eclipse.ui.forms.widgets.ScrolledForm) ContributionResult(org.openlca.core.results.ContributionResult) ImpactDescriptor(org.openlca.core.model.descriptors.ImpactDescriptor) ImpactMethodDescriptor(org.openlca.core.model.descriptors.ImpactMethodDescriptor) Collections(java.util.Collections) ImpactMethodDao(org.openlca.core.database.ImpactMethodDao) Contribution(org.openlca.core.results.Contribution)

Aggregations

ImpactMethodDao (org.openlca.core.database.ImpactMethodDao)4 ImpactMethodDescriptor (org.openlca.core.model.descriptors.ImpactMethodDescriptor)4 ArrayList (java.util.ArrayList)2 Collections (java.util.Collections)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 Action (org.eclipse.jface.action.Action)2 ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)2 ColumnLabelProvider (org.eclipse.jface.viewers.ColumnLabelProvider)2 ITableLabelProvider (org.eclipse.jface.viewers.ITableLabelProvider)2 ITreeContentProvider (org.eclipse.jface.viewers.ITreeContentProvider)2 TreeViewer (org.eclipse.jface.viewers.TreeViewer)2 SWT (org.eclipse.swt.SWT)2 Image (org.eclipse.swt.graphics.Image)2 Button (org.eclipse.swt.widgets.Button)2 Composite (org.eclipse.swt.widgets.Composite)2 IManagedForm (org.eclipse.ui.forms.IManagedForm)2 FormToolkit (org.eclipse.ui.forms.widgets.FormToolkit)2 ScrolledForm (org.eclipse.ui.forms.widgets.ScrolledForm)2