Search in sources :

Example 1 with M

use of org.openlca.app.M 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 M

use of org.openlca.app.M in project olca-app by GreenDelta.

the class JsonImportDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    Composite root = (Composite) super.createDialogArea(parent);
    UI.gridLayout(root, 1, 10, 10);
    Composite comp = new Composite(root, SWT.NONE);
    UI.gridLayout(comp, 2, 10, 0);
    UI.formLabel(comp, M.File);
    String fileText = Strings.cut(provider.file().getParent(), 50) + File.separator + Strings.cut(provider.file().getName(), 50);
    Label label = UI.formLabel(comp, fileText);
    label.setForeground(Colors.linkBlue());
    Button openCheck = new Button(root, SWT.RADIO);
    openCheck.setText("Open mapping definition");
    Combo combo = new Combo(root, SWT.READ_ONLY);
    Controls.onSelect(combo, e -> {
        selectedMap = flowMaps.get(combo.getSelectionIndex());
    });
    UI.gridData(combo, true, false);
    Controls.onSelect(openCheck, e -> {
        selectedMap = flowMaps.get(combo.getSelectionIndex());
        combo.setEnabled(true);
    });
    Button genCheck = new Button(root, SWT.RADIO);
    genCheck.setText("Generate mapping based on flow attributes");
    Controls.onSelect(genCheck, e -> {
        selectedMap = null;
        combo.setEnabled(false);
    });
    if (flowMaps.isEmpty()) {
        genCheck.setSelection(true);
        openCheck.setSelection(false);
        combo.setEnabled(false);
        openCheck.setEnabled(false);
    } else {
        openCheck.setSelection(true);
        genCheck.setSelection(false);
        String[] items = this.flowMaps.stream().map(m -> m.name).toArray(len -> new String[len]);
        combo.setItems(items);
        combo.select(0);
        selectedMap = flowMaps.get(0);
    }
    return root;
}
Also used : M(org.openlca.app.M) Combo(org.eclipse.swt.widgets.Combo) Shell(org.eclipse.swt.widgets.Shell) Logger(org.slf4j.Logger) Button(org.eclipse.swt.widgets.Button) App(org.openlca.app.App) Colors(org.openlca.app.util.Colors) Controls(org.openlca.app.util.Controls) LoggerFactory(org.slf4j.LoggerFactory) MsgBox(org.openlca.app.util.MsgBox) File(java.io.File) List(java.util.List) JsonProvider(org.openlca.app.tools.mapping.model.JsonProvider) Strings(org.openlca.util.Strings) UI(org.openlca.app.util.UI) Dialog(org.eclipse.jface.dialogs.Dialog) Composite(org.eclipse.swt.widgets.Composite) SWT(org.eclipse.swt.SWT) FlowMap(org.openlca.io.maps.FlowMap) Collections(java.util.Collections) Label(org.eclipse.swt.widgets.Label) Control(org.eclipse.swt.widgets.Control) Composite(org.eclipse.swt.widgets.Composite) Button(org.eclipse.swt.widgets.Button) Label(org.eclipse.swt.widgets.Label) Combo(org.eclipse.swt.widgets.Combo)

Aggregations

Collections (java.util.Collections)2 List (java.util.List)2 SWT (org.eclipse.swt.SWT)2 Button (org.eclipse.swt.widgets.Button)2 Composite (org.eclipse.swt.widgets.Composite)2 App (org.openlca.app.App)2 M (org.openlca.app.M)2 Controls (org.openlca.app.util.Controls)2 UI (org.openlca.app.util.UI)2 File (java.io.File)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Collectors (java.util.stream.Collectors)1 Action (org.eclipse.jface.action.Action)1 Dialog (org.eclipse.jface.dialogs.Dialog)1 ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)1 ColumnLabelProvider (org.eclipse.jface.viewers.ColumnLabelProvider)1 ITableLabelProvider (org.eclipse.jface.viewers.ITableLabelProvider)1 ITreeContentProvider (org.eclipse.jface.viewers.ITreeContentProvider)1 TreeViewer (org.eclipse.jface.viewers.TreeViewer)1