use of org.openlca.app.navigation.elements.ModelElement 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.ModelElement 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.ModelElement 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.ModelElement in project olca-app by GreenDelta.
the class EmptyCategoryFilter method hasContent.
/**
* A category element is selected when there are model components in it
* which make it through all filters.
*/
private boolean hasContent(Viewer viewer, CategoryElement element) {
List<ModelElement> content = new ArrayList<>();
collectContent(element, content);
if (content.size() == 0)
return false;
ViewerFilter[] filters = getFilters(viewer);
if (filters.length == 0)
return true;
for (ModelElement model : content) if (passesFilters(viewer, filters, model))
return true;
return false;
}
use of org.openlca.app.navigation.elements.ModelElement 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