Search in sources :

Example 1 with RootEntity

use of org.openlca.core.model.RootEntity in project olca-app by GreenDelta.

the class Widgets method link.

public static ImageHyperlink link(Composite parent, String label, String property, ModelEditor<?> editor, FormToolkit toolkit) {
    new Label(parent, SWT.NONE).setText(label);
    ImageHyperlink link = new ImageHyperlink(parent, SWT.TOP);
    link.setForeground(Colors.linkBlue());
    try {
        Object value = Bean.getValue(editor.getModel(), property);
        if (value == null) {
            link.setText("-");
            return link;
        }
        if (!(value instanceof RootEntity)) {
            link.setText(value.toString());
            return link;
        }
        var entity = (RootEntity) value;
        link.setText(Labels.name(entity));
        link.setImage(Images.get(entity));
        link.addHyperlinkListener(new ModelLinkClickedListener(entity));
        new CommentControl(parent, toolkit, property, editor.getComments());
        return link;
    } catch (Exception e) {
        log.error("Could not get value " + property + " of " + editor.getModel(), e);
        return link;
    }
}
Also used : ImageHyperlink(org.eclipse.ui.forms.widgets.ImageHyperlink) CommentControl(org.openlca.app.editors.comments.CommentControl) CLabel(org.eclipse.swt.custom.CLabel) Label(org.eclipse.swt.widgets.Label) RootEntity(org.openlca.core.model.RootEntity)

Example 2 with RootEntity

use of org.openlca.core.model.RootEntity in project olca-app by GreenDelta.

the class LocationPage method createTree.

private void createTree(Composite body, FormToolkit tk) {
    Section section = UI.section(body, tk, M.ContributionTreeLocations);
    UI.gridData(section, true, true);
    Composite comp = UI.sectionClient(section, tk);
    UI.gridLayout(comp, 1);
    label = new TreeLabel();
    String[] labels = { M.Location, M.Amount, M.Unit };
    tree = Trees.createViewer(comp, labels, label);
    tree.setContentProvider(new TreeContentProvider(this));
    Trees.bindColumnWidths(tree.getTree(), 0.4, 0.3, 0.3);
    // tree actions
    Action onOpen = Actions.onOpen(() -> {
        Object obj = Viewers.getFirstSelected(tree);
        if (obj == null)
            return;
        if (obj instanceof Contribution) {
            Contribution<?> c = (Contribution<?>) obj;
            if (c.item instanceof RootDescriptor) {
                App.open((RootDescriptor) c.item);
            } else if (c.item instanceof RootEntity) {
                App.open((RootEntity) c.item);
            }
        }
    });
    Actions.bind(tree, onOpen, TreeClipboard.onCopy(tree));
    Trees.onDoubleClick(tree, e -> onOpen.run());
    tree.getTree().getColumns()[1].setAlignment(SWT.RIGHT);
}
Also used : Action(org.eclipse.jface.action.Action) Composite(org.eclipse.swt.widgets.Composite) RootDescriptor(org.openlca.core.model.descriptors.RootDescriptor) Section(org.eclipse.ui.forms.widgets.Section) Contribution(org.openlca.core.results.Contribution) RootEntity(org.openlca.core.model.RootEntity)

Example 3 with RootEntity

use of org.openlca.core.model.RootEntity in project olca-app by GreenDelta.

the class ChartLegend method element.

private void element(String text, Object model, int colorIndex) {
    if (model instanceof RootDescriptor || model instanceof RootEntity) {
        ImageHyperlink link = new ImageHyperlink(composite, SWT.TOP);
        link.setText(text);
        link.setImage(getImage(colorIndex));
        Controls.onClick(link, (e) -> {
            if (model instanceof RootDescriptor) {
                App.open((RootDescriptor) model);
            } else if (model instanceof RootEntity) {
                App.open((RootEntity) model);
            }
        });
        createdLinks.push(link);
    } else {
        CLabel label = new CLabel(composite, SWT.TOP);
        label.setImage(getImage(colorIndex));
        label.setText(text);
        createdLinks.push(label);
    }
}
Also used : CLabel(org.eclipse.swt.custom.CLabel) ImageHyperlink(org.eclipse.ui.forms.widgets.ImageHyperlink) RootDescriptor(org.openlca.core.model.descriptors.RootDescriptor) RootEntity(org.openlca.core.model.RootEntity)

Example 4 with RootEntity

use of org.openlca.core.model.RootEntity in project olca-app by GreenDelta.

the class CopyPaste method copy.

private static void copy(CategoryElement element, INavigationElement<?> category) {
    Category parent = getCategory(category);
    Queue<CategoryElement> elements = new LinkedList<>();
    elements.add(element);
    while (!elements.isEmpty()) {
        CategoryElement current = elements.poll();
        Category copy = current.getContent().copy();
        copy.childCategories.clear();
        copy.category = parent;
        if (parent == null)
            copy = new CategoryDao(Database.get()).insert(copy);
        else {
            parent.childCategories.add(copy);
            copy = new CategoryDao(Database.get()).update(parent);
        }
        for (INavigationElement<?> child : current.getChildren()) if (child instanceof CategoryElement)
            elements.add((CategoryElement) child);
        else {
            RootEntity modelCopy = copy((ModelElement) child);
            modelCopy.category = copy;
            insert(modelCopy);
        }
        parent = copy;
    }
}
Also used : ModelElement(org.openlca.app.navigation.elements.ModelElement) Category(org.openlca.core.model.Category) CategoryElement(org.openlca.app.navigation.elements.CategoryElement) CategoryDao(org.openlca.core.database.CategoryDao) LinkedList(java.util.LinkedList) RootEntity(org.openlca.core.model.RootEntity)

Example 5 with RootEntity

use of org.openlca.core.model.RootEntity in project olca-app by GreenDelta.

the class CopyPaste method cloneIt.

private static RootEntity cloneIt(RootEntity entity) {
    try {
        RootEntity clone = (RootEntity) entity.copy();
        DatabaseDir.copyDir(entity, clone);
        return clone;
    } catch (Exception e) {
        Logger log = LoggerFactory.getLogger(CopyPaste.class);
        log.error("failed to clone " + entity, e);
        return null;
    }
}
Also used : Logger(org.slf4j.Logger) RootEntity(org.openlca.core.model.RootEntity)

Aggregations

RootEntity (org.openlca.core.model.RootEntity)9 ImageHyperlink (org.eclipse.ui.forms.widgets.ImageHyperlink)3 RootDescriptor (org.openlca.core.model.descriptors.RootDescriptor)3 CLabel (org.eclipse.swt.custom.CLabel)2 Composite (org.eclipse.swt.widgets.Composite)2 Label (org.eclipse.swt.widgets.Label)2 LinkedList (java.util.LinkedList)1 Action (org.eclipse.jface.action.Action)1 SWT (org.eclipse.swt.SWT)1 Button (org.eclipse.swt.widgets.Button)1 Text (org.eclipse.swt.widgets.Text)1 FormToolkit (org.eclipse.ui.forms.widgets.FormToolkit)1 Section (org.eclipse.ui.forms.widgets.Section)1 After (org.junit.After)1 Test (org.junit.Test)1 App (org.openlca.app.App)1 M (org.openlca.app.M)1 Editors (org.openlca.app.editors.Editors)1 CommentControl (org.openlca.app.editors.comments.CommentControl)1 CategoryElement (org.openlca.app.navigation.elements.CategoryElement)1