use of de.catma.tag.PropertyDefinition 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.PropertyDefinition in project catma by forTEXT.
the class AbstractAddEditTagDialog method handleAddPropertyDefRequest.
private void handleAddPropertyDefRequest(String name) {
if (propertyDefDataProvider.getItems().isEmpty()) {
setPropertyDefinitionsVisible();
}
if ((name != null) && !name.trim().isEmpty()) {
tfPropertyDefName.clear();
PropertyDefinition propertyDefinition = new PropertyDefinition(idGenerator.generate(), name, Collections.emptyList());
propertyDefDataProvider.getItems().add(propertyDefinition);
propertyDefDataProvider.refreshAll();
propertyDefinitionGrid.select(propertyDefinition);
propertyDefinitionAdded(propertyDefinition);
}
}
use of de.catma.tag.PropertyDefinition in project catma by forTEXT.
the class AddEditPropertyDialog method handleAddPropertyDefinition.
private void handleAddPropertyDefinition(String name) {
if ((name != null) && !name.trim().isEmpty()) {
tfPropertyDefName.clear();
PropertyDefinition propertyDefinition = new PropertyDefinition(idGenerator.generate(), name, Collections.emptyList());
propertyDefDataProvider.getItems().add(propertyDefinition);
propertyDefDataProvider.refreshAll();
propertyDefinitionGrid.select(propertyDefinition);
}
}
use of de.catma.tag.PropertyDefinition in project catma by forTEXT.
the class AddEditPropertyDialog method initComponents.
private void initComponents(boolean bulkEdit, List<PropertyDefinition> commonPropertyDefs) {
inputLabel = new Label(bulkEdit ? "Edit the common Properties of the selected Tags" : "Edit the Properties of the selected Tag");
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();
propertyDefinitionGrid = new Grid<PropertyDefinition>("Assigned Properties");
propertyDefinitionGrid.addStyleName("flat-undecorated-icon-buttonrenderer");
TextField propertyNameField = new TextField();
propertyDefinitionGrid.addColumn(propertyDef -> propertyDef.getName()).setEditorComponent(propertyNameField, PropertyDefinition::setName).setEditable(!bulkEdit);
propertyDefinitionGrid.getEditor().setEnabled(!bulkEdit);
propertyDefinitionGrid.setHeaderVisible(false);
propertyDefinitionGrid.setWidth("99%");
propertyDefinitionGrid.setHeight("100%");
propertyDefDataProvider = new ListDataProvider<PropertyDefinition>(new ArrayList<>(commonPropertyDefs));
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.PropertyDefinition 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