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;
}
}
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);
}
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);
}
}
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;
}
}
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;
}
}
Aggregations