use of org.openlca.app.navigation.elements.CategoryElement 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.app.navigation.elements.CategoryElement in project olca-app by GreenDelta.
the class DeleteModelAction method run.
@Override
public void run() {
boolean canceled = false;
boolean dontAsk = false;
showInUseMessage = true;
for (ModelElement element : models) {
var descriptor = element.getContent();
if (descriptor == null)
continue;
String name = Labels.name(descriptor);
int answer = dontAsk ? IDialogConstants.YES_ID : askDelete(name);
if (answer == IDialogConstants.CANCEL_ID) {
canceled = true;
break;
}
if (answer == IDialogConstants.NO_TO_ALL_ID)
break;
if (answer == IDialogConstants.NO_ID)
continue;
if (answer == IDialogConstants.YES_TO_ALL_ID)
dontAsk = true;
if (isUsed(descriptor))
continue;
App.close(descriptor);
delete(descriptor);
Navigator.refresh(element.getParent());
}
models.clear();
if (canceled) {
categories.clear();
return;
}
boolean dontAskEmpty = false;
for (CategoryElement element : categories) {
Category category = element.getContent();
if (category == null)
continue;
boolean empty = element.getChildren().isEmpty();
int answer;
if (!empty) {
answer = dontAskEmpty ? IDialogConstants.YES_ID : askNotEmptyDelete(category.name);
} else {
answer = dontAsk ? IDialogConstants.YES_ID : askDelete(category.name);
}
if (answer == IDialogConstants.NO_TO_ALL_ID)
break;
if (answer == IDialogConstants.CANCEL_ID)
break;
if (answer == IDialogConstants.NO_ID)
continue;
if (answer == IDialogConstants.YES_TO_ALL_ID) {
if (empty) {
dontAskEmpty = true;
} else {
dontAsk = true;
}
}
if (delete(element)) {
INavigationElement<?> typeElement = Navigator.findElement(category.modelType);
Navigator.refresh(typeElement);
}
}
categories.clear();
}
use of org.openlca.app.navigation.elements.CategoryElement in project olca-app by GreenDelta.
the class DeleteModelAction method delete.
private boolean delete(CategoryElement element) {
boolean canBeDeleted = true;
for (INavigationElement<?> child : element.getChildren()) {
if (child instanceof CategoryElement) {
boolean deleted = delete((CategoryElement) child);
if (!deleted) {
canBeDeleted = false;
}
} else if (child instanceof ModelElement) {
var descriptor = ((ModelElement) child).getContent();
if (isUsed(descriptor)) {
canBeDeleted = false;
continue;
}
App.close(descriptor);
delete(descriptor);
}
}
if (!canBeDeleted) {
Navigator.refresh(element);
return false;
}
Category category = element.getContent();
try {
CategoryDao dao = new CategoryDao(Database.get());
Category parent = category.category;
if (parent != null) {
parent.childCategories.remove(category);
category.category = null;
dao.update(parent);
}
dao.delete(category);
Cache.evict(Descriptor.of(category));
return true;
} catch (Exception e) {
ErrorReporter.on("failed to delete category " + category, e);
return false;
}
}
use of org.openlca.app.navigation.elements.CategoryElement in project olca-app by GreenDelta.
the class CategoryDialog method createTreeViewer.
private void createTreeViewer(Composite composite) {
TreeViewer viewer = NavigationTree.forSingleSelection(composite, modelType);
viewer.setFilters(new ViewerFilter[] { new Filter() });
UI.gridData(viewer.getTree(), true, true);
viewer.addSelectionChangedListener(e -> {
INavigationElement<?> element = Selections.firstOf(e);
if (element instanceof CategoryElement) {
category = (Category) element.getContent();
} else {
category = null;
}
});
}
use of org.openlca.app.navigation.elements.CategoryElement in project olca-app by GreenDelta.
the class FlowTypeFilter method select.
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
boolean select = true;
TreeViewer treeViewer = (TreeViewer) viewer;
if (element instanceof ModelElement) {
select = !matchType((ModelElement) element);
} else if (element instanceof CategoryElement) {
if (filterEmptyCategories(treeViewer)) {
CategoryElement catElem = (CategoryElement) element;
Category category = catElem.getContent();
if (category.modelType == ModelType.FLOW)
select = containsOtherTypes(catElem);
}
}
return select;
}
Aggregations