use of de.catma.tag.TagsetDefinition 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.tag.TagsetDefinition in project catma by forTEXT.
the class TagsView method handleBulkEditProperties.
private void handleBulkEditProperties(List<PropertyDefinition> editedProperties, List<PropertyDefinition> commonProperties, List<TagDefinition> targetTags) {
final Set<String> availableCommonPropertyNames = editedProperties.stream().map(propertyDef -> propertyDef.getName()).collect(Collectors.toSet());
final Set<String> deletedCommonProperyNames = commonProperties.stream().map(propertyDef -> propertyDef.getName()).filter(name -> !availableCommonPropertyNames.contains(name)).collect(Collectors.toSet());
for (TagDefinition tag : targetTags) {
TagsetDefinition tagset = project.getTagManager().getTagLibrary().getTagsetDefinition(tag);
for (PropertyDefinition existingPropertyDef : new ArrayList<>(tag.getUserDefinedPropertyDefinitions())) {
// handle deleted PropertyDefs
if (deletedCommonProperyNames.contains(existingPropertyDef.getName())) {
project.getTagManager().removeUserDefinedPropertyDefinition(existingPropertyDef, tag, tagset);
} else // handle updated PropertyDefs
if (availableCommonPropertyNames.contains(existingPropertyDef.getName())) {
editedProperties.stream().filter(possiblyChangedPd -> possiblyChangedPd.getName().equals(existingPropertyDef.getName())).findFirst().ifPresent(possiblyChangedPd -> existingPropertyDef.setPossibleValueList(possiblyChangedPd.getPossibleValueList()));
project.getTagManager().updateUserDefinedPropertyDefinition(tag, existingPropertyDef);
}
}
// handle created PropertyDefs
for (PropertyDefinition pd : editedProperties) {
if (tag.getPropertyDefinition(pd.getName()) == null) {
PropertyDefinition createdPropertyDefinition = new PropertyDefinition(pd);
pd.setUuid(idGenerator.generate());
project.getTagManager().addUserDefinedPropertyDefinition(tag, createdPropertyDefinition);
}
}
}
}
use of de.catma.tag.TagsetDefinition in project catma by forTEXT.
the class AbstractAddEditTagDialog method initComponents.
protected void initComponents(Collection<TagsetDefinition> availableTagsets, Optional<TagsetDefinition> preSelectedTagset, boolean allowPropertyDefEditing) {
if (isWithTagsetSelection()) {
cbTagsets = new ComboBox<TagsetDefinition>("Tagset", availableTagsets);
cbTagsets.setItemCaptionGenerator(tagset -> tagset.getName());
cbTagsets.setWidth("100%");
cbTagsets.setDescription("The Tagset that will be the container of the new Tag.");
cbTagsets.setEmptySelectionAllowed(false);
preSelectedTagset.ifPresent(tagset -> cbTagsets.setValue(tagset));
}
tagPanel = new HorizontalLayout();
tagPanel.setSpacing(true);
tagPanel.setWidth("100%");
tagPanel.setMargin(new MarginInfo(false, true));
tfName = new TextField();
tfName.setPlaceholder("Tag Name");
tagPanel.addComponent(tfName);
int[] randomRGBColor = ColorConverter.getRandomColor();
colorPicker = new ColorPicker("Tag color", new Color(randomRGBColor[0], randomRGBColor[1], randomRGBColor[2]));
colorPicker.addStyleName(MaterialTheme.BUTTON_FLAT);
colorPicker.addStyleName("inputfield-color-picker");
colorPicker.setModal(true);
tagPanel.addComponent(colorPicker);
propertyDefNamePanel = new HorizontalLayout();
propertyDefNamePanel.setSpacing(true);
propertyDefNamePanel.setMargin(new MarginInfo(true, true, false, true));
tfPropertyDefName = new TextField("Add Properties");
tfPropertyDefName.setPlaceholder("Enter a Property name");
tfPropertyDefName.setWidth("250px");
propertyDefNamePanel.addComponent(tfPropertyDefName);
btAddProperty = new Button("Add Property");
btAddProperty.addStyleName(MaterialTheme.BUTTON_FLAT);
btAddProperty.addStyleName(MaterialTheme.BUTTON_PRIMARY);
propertyDefNamePanel.addComponent(btAddProperty);
propertyDefNamePanel.setComponentAlignment(btAddProperty, Alignment.BOTTOM_LEFT);
propertyDefPanel = new HorizontalLayout();
propertyDefPanel.setMargin(new MarginInfo(false, true));
propertyDefPanel.setSpacing(true);
propertyDefPanel.setSizeFull();
propertyDefPanel.setVisible(false);
TextField propertyNameField = new TextField();
propertyDefinitionGrid = new Grid<PropertyDefinition>("Assigned Properties");
propertyDefinitionGrid.addStyleName("flat-undecorated-icon-buttonrenderer");
propertyDefinitionGrid.addColumn(propertyDef -> propertyDef.getName()).setEditorComponent(propertyNameField, PropertyDefinition::setName).setEditable(allowPropertyDefEditing);
propertyDefinitionGrid.getEditor().setEnabled(allowPropertyDefEditing);
propertyDefinitionGrid.setHeaderVisible(false);
propertyDefinitionGrid.setWidth("99%");
propertyDefinitionGrid.setHeight("100%");
propertyDefDataProvider = new ListDataProvider<PropertyDefinition>(new ArrayList<>());
propertyDefinitionGrid.setDataProvider(propertyDefDataProvider);
propertyDefPanel.addComponent(propertyDefinitionGrid);
possibleValuesArea = new TextArea("Proposed Values");
possibleValuesArea.setPlaceholder("You can add multiple comma separated values: value1, value2, ...");
possibleValuesArea.setSizeFull();
propertyDefPanel.addComponent(possibleValuesArea);
}
use of de.catma.tag.TagsetDefinition in project catma by forTEXT.
the class ResourcePermissionView method initData.
private void initData(TreeData<Resource> resourceData, Collection<TagsetDefinition> tagsets) {
try {
permissionGrid.removeAllColumns();
permissionGrid.addColumn(resource -> resource.getIcon(), new HtmlRenderer()).setWidth(70);
permissionGrid.addColumn(resource -> resource.getName()).setWidth(250).setCaption("Resource");
TreeData<Resource> items = new TreeData<Resource>();
for (Resource documentResource : resourceData.getRootItems()) {
Set<Member> documentMembers = project.getResourceMembers(documentResource.getResourceId());
documentMembers.forEach(member -> permissionMatrix.put(documentResource, member, member.getRole()));
items.addItem(null, documentResource);
Collection<Resource> collectionResources = resourceData.getChildren(documentResource);
for (Resource collectionResource : collectionResources) {
Set<Member> collectionMembers = project.getResourceMembers(collectionResource.getResourceId());
collectionMembers.forEach(member -> permissionMatrix.put(collectionResource, member, member.getRole()));
items.addItem(documentResource, collectionResource);
}
}
for (TagsetDefinition tagset : tagsets) {
Set<Member> tagsetMembers = project.getResourceMembers(tagset.getUuid());
TagsetResource tagsetResource = new TagsetResource(tagset, project.getProjectId());
tagsetMembers.forEach(member -> permissionMatrix.put(tagsetResource, member, member.getRole()));
items.addItem(null, tagsetResource);
}
for (Member member : permissionMatrix.columnKeySet()) {
Column<Resource, String> memberColumn = permissionGrid.addColumn(resource -> {
RBACRole role = permissionMatrix.get(resource, member);
return role == null ? "" : role.getRoleName();
}).setWidth(120).setCaption(member.getName()).setDescriptionGenerator(resource -> member.preciseName());
// only reporter and lower can be upgraded for specific resources
if (member.getRole().getAccessLevel() <= RBACRole.REPORTER.getAccessLevel()) {
memberColumn.setEditorBinding(createRoleEditor(member));
} else {
memberColumn.setHidable(true);
memberColumn.setHidden(true);
}
}
permissionDataProvider = new TreeDataProvider<>(items);
permissionGrid.setDataProvider(permissionDataProvider);
permissionGrid.expand(resourceData.getRootItems());
} catch (IOException e) {
errorHandler.showAndLogError("Failed to fetch permissions", e);
}
}
use of de.catma.tag.TagsetDefinition 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