use of de.catma.project.Project in project catma by forTEXT.
the class TagSelectionPanel method handleAddSubtagRequest.
private void handleAddSubtagRequest() {
final List<TagDefinition> parentTags = tagsetGrid.getSelectedItems().stream().filter(tagsetTreeItem -> tagsetTreeItem instanceof TagDataItem).map(tagsetTreeItem -> ((TagDataItem) tagsetTreeItem).getTag()).collect(Collectors.toList());
for (TagDefinition parentTag : parentTags) {
if (!project.hasPermission(project.getRoleForTagset(parentTag.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!", parentTag.getName()), Type.HUMANIZED_MESSAGE);
return;
}
}
if (!parentTags.isEmpty()) {
AddSubtagDialog addTagDialog = new AddSubtagDialog(new SaveCancelListener<TagDefinition>() {
public void savePressed(TagDefinition result) {
for (TagDefinition parent : parentTags) {
TagsetDefinition tagset = project.getTagManager().getTagLibrary().getTagsetDefinition(parent);
TagDefinition tag = new TagDefinition(result);
tag.setUuid(idGenerator.generate());
tag.setParentUuid(parent.getUuid());
tag.setTagsetDefinitionUuid(tagset.getUuid());
project.getTagManager().addTagDefinition(tagset, tag);
}
}
});
addTagDialog.show();
} else {
Notification.show("Info", "Please select at least one parent Tag!", Type.HUMANIZED_MESSAGE);
}
}
use of de.catma.project.Project in project catma by forTEXT.
the class TagsView method handleAddSubtagRequest.
private void handleAddSubtagRequest() {
final List<TagDefinition> parentTags = tagsetGrid.getSelectedItems().stream().filter(tagsetTreeItem -> tagsetTreeItem instanceof TagDataItem).map(tagsetTreeItem -> ((TagDataItem) tagsetTreeItem).getTag()).collect(Collectors.toList());
for (TagDefinition parentTag : parentTags) {
if (!project.hasPermission(project.getRoleForTagset(parentTag.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!", parentTag.getName()), Type.HUMANIZED_MESSAGE);
return;
}
}
if (!parentTags.isEmpty()) {
AddSubtagDialog addTagDialog = new AddSubtagDialog(new SaveCancelListener<TagDefinition>() {
public void savePressed(TagDefinition result) {
for (TagDefinition parent : parentTags) {
TagsetDefinition tagset = project.getTagManager().getTagLibrary().getTagsetDefinition(parent);
TagDefinition tag = new TagDefinition(result);
tag.setUuid(idGenerator.generate());
tag.setParentUuid(parent.getUuid());
tag.setTagsetDefinitionUuid(tagset.getUuid());
project.getTagManager().addTagDefinition(tagset, tag);
}
}
});
addTagDialog.show();
} else {
Notification.show("Info", "Please select at least one parent Tag!", Type.HUMANIZED_MESSAGE);
}
}
use of de.catma.project.Project in project catma by forTEXT.
the class TagsView 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();
}
}
use of de.catma.project.Project in project catma by forTEXT.
the class TagsView method handleEditTagsetRequest.
private void handleEditTagsetRequest() {
if (project.isAuthorizedOnProject(RBACPermission.TAGSET_DELETE_OR_EDIT)) {
Collection<TagsetDefinition> selectedTagsets = tagsetGrid.getSelectedItems().stream().filter(tagsetTreeItem -> tagsetTreeItem instanceof TagsetDataItem).map(tagsetDataItem -> ((TagsetDataItem) tagsetDataItem).getTagset()).collect(Collectors.toList());
if (!selectedTagsets.isEmpty()) {
final TagsetDefinition tagset = selectedTagsets.iterator().next();
SingleTextInputDialog tagsetNameDlg = new SingleTextInputDialog("Edit Tagset", "Please enter the new Tagset name:", tagset.getName(), new SaveCancelListener<String>() {
@Override
public void savePressed(String result) {
project.getTagManager().setTagsetDefinitionName(tagset, result);
}
});
tagsetNameDlg.show();
} else {
Notification.show("Info", "Please select a Tagset first!", Type.HUMANIZED_MESSAGE);
}
} else {
Notification.show("Info", "You do not have the permission to edit Tagsets! " + "Please contact the Project maintainer for changes!", Type.HUMANIZED_MESSAGE);
}
}
use of de.catma.project.Project in project catma by forTEXT.
the class TagsetCSVExportStreamSource method getStream.
@Override
public InputStream getStream() {
final UI ui = UI.getCurrent();
Set<TagsetDefinition> tagsets = tagsetsSupplier.get();
Project project = projectSupplier.get();
if (tagsets != null && !tagsets.isEmpty()) {
try {
File tempFile = File.createTempFile(new IDGenerator().generate() + "_TagLibrary_Export", "xml");
try (OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(tempFile))) {
try (CSVPrinter csvPrinter = new CSVPrinter(writer, CSVFormat.EXCEL.withDelimiter(';'))) {
csvPrinter.print("Tagset");
csvPrinter.print("Tagset ID");
csvPrinter.print("Tag");
csvPrinter.print("Tag ID");
csvPrinter.print("Tag Path");
csvPrinter.print("Tag Parent ID");
csvPrinter.print("Tag Color");
csvPrinter.print("Tag Author");
csvPrinter.print("Project Name");
csvPrinter.print("Project ID");
csvPrinter.print("Tag Properties & Values & Property ID");
csvPrinter.println();
for (TagsetDefinition tagset : tagsets) {
Collection<TagDefinition> sortedTags = tagset.stream().sorted((t1, t2) -> {
if (t1.getName().equals(t2.getName())) {
return t1.getUuid().compareTo(t2.getUuid());
}
return t1.getName().compareTo(t2.getName());
}).collect(Collectors.toList());
for (TagDefinition tag : sortedTags) {
csvPrinter.print(tagset.getName());
csvPrinter.print(tagset.getUuid());
csvPrinter.print(tag.getName());
csvPrinter.print(tag.getUuid());
csvPrinter.print(tagset.getTagPath(tag));
csvPrinter.print(tag.getParentUuid());
csvPrinter.print("#" + ColorConverter.toHex(tag.getColor()));
csvPrinter.print(tag.getAuthor());
csvPrinter.print(project.getName());
csvPrinter.print(project.getProjectId());
ArrayList<PropertyDefinition> sortedProperties = new ArrayList<>(tag.getUserDefinedPropertyDefinitions());
Collections.sort(sortedProperties, (p1, p2) -> {
if (p1.getName().equals(p2.getName())) {
return p1.getUuid().compareTo(p2.getUuid());
}
return p1.getName().compareTo(p2.getName());
});
for (PropertyDefinition propertyDef : sortedProperties) {
csvPrinter.print(propertyDef.getName() + propertyDef.getPossibleValueList().stream().sorted().collect(Collectors.toList()) + " " + propertyDef.getUuid());
}
csvPrinter.println();
}
}
}
}
return new FileInputStream(tempFile);
} catch (Exception e) {
((ErrorHandler) ui).showAndLogError("Error exporting Tagsets to XML!", e);
}
}
return null;
}
Aggregations