use of de.catma.project.Project in project catma by forTEXT.
the class AnnotationPanel method handleAddPropertyRequest.
private void handleAddPropertyRequest() {
final List<TagDefinition> targetTags = new ArrayList<>();
if (tagsetGrid.getSelectedItems().size() == 1) {
TagsetTreeItem selectedItem = tagsetGrid.getSelectedItems().iterator().next();
while (!(selectedItem instanceof TagDataItem) && (selectedItem != null)) {
selectedItem = tagsetData.getParent(selectedItem);
}
if (selectedItem != null) {
targetTags.add(((TagDataItem) selectedItem).getTag());
}
} else {
targetTags.addAll(tagsetGrid.getSelectedItems().stream().filter(tagsetTreeItem -> tagsetTreeItem instanceof TagDataItem).map(tagsetTreeItem -> ((TagDataItem) tagsetTreeItem).getTag()).collect(Collectors.toList()));
}
if (targetTags.isEmpty()) {
Notification.show("Info", "Please select one ore more Tags first!", Type.TRAY_NOTIFICATION);
} else {
for (TagDefinition targetTag : targetTags) {
if (!project.hasPermission(project.getRoleForTagset(targetTag.getTagsetDefinitionUuid()), RBACPermission.TAGSET_WRITE)) {
Notification.show("Info", String.format("You do not have the permission to make changes to the Tagset of Tag %1$s, " + "Please contact the Project maintainer!", targetTag.getName()), Type.HUMANIZED_MESSAGE);
return;
}
}
Multimap<String, PropertyDefinition> propertiesByName = ArrayListMultimap.create();
for (TagDefinition tag : targetTags) {
for (PropertyDefinition propertyDef : tag.getUserDefinedPropertyDefinitions()) {
if (!propertiesByName.containsKey(propertyDef.getName()) || propertiesByName.get(propertyDef.getName()).iterator().next().getPossibleValueList().equals(propertyDef.getPossibleValueList())) {
propertiesByName.put(propertyDef.getName(), propertyDef);
}
}
}
List<PropertyDefinition> commonProperties = propertiesByName.asMap().entrySet().stream().filter(entry -> entry.getValue().size() == targetTags.size()).map(entry -> new PropertyDefinition(entry.getValue().iterator().next())).collect(Collectors.toList());
// just a single tag's properties or is it a bulk(>1) edit?
final boolean bulkEdit = targetTags.size() > 1;
AddEditPropertyDialog addPropertyDialog = new AddEditPropertyDialog(bulkEdit, commonProperties, new SaveCancelListener<List<PropertyDefinition>>() {
@Override
public void savePressed(List<PropertyDefinition> result) {
if (bulkEdit) {
handleBulkEditProperties(result, commonProperties, targetTags);
} else {
handleSingleEditProperties(result, targetTags.iterator().next());
}
}
});
addPropertyDialog.show();
}
}
Aggregations