Search in sources :

Example 6 with PropertyDefinition

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);
}
Also used : ColorPicker(com.vaadin.ui.ColorPicker) TextArea(com.vaadin.ui.TextArea) Color(com.vaadin.shared.ui.colorpicker.Color) ArrayList(java.util.ArrayList) PropertyDefinition(de.catma.tag.PropertyDefinition) HorizontalLayout(com.vaadin.ui.HorizontalLayout) TagsetDefinition(de.catma.tag.TagsetDefinition) Button(com.vaadin.ui.Button) MarginInfo(com.vaadin.shared.ui.MarginInfo) TextField(com.vaadin.ui.TextField)

Example 7 with PropertyDefinition

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);
    }
}
Also used : PropertyDefinition(de.catma.tag.PropertyDefinition)

Example 8 with 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);
    }
}
Also used : PropertyDefinition(de.catma.tag.PropertyDefinition)

Example 9 with 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);
}
Also used : Button(com.vaadin.ui.Button) TextArea(com.vaadin.ui.TextArea) MarginInfo(com.vaadin.shared.ui.MarginInfo) Label(com.vaadin.ui.Label) ArrayList(java.util.ArrayList) TextField(com.vaadin.ui.TextField) PropertyDefinition(de.catma.tag.PropertyDefinition) HorizontalLayout(com.vaadin.ui.HorizontalLayout)

Example 10 with PropertyDefinition

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;
}
Also used : PropertyDefinition(de.catma.tag.PropertyDefinition) Project(de.catma.project.Project) Collection(java.util.Collection) UI(com.vaadin.ui.UI) FileOutputStream(java.io.FileOutputStream) Set(java.util.Set) FileInputStream(java.io.FileInputStream) Supplier(java.util.function.Supplier) Collectors(java.util.stream.Collectors) File(java.io.File) ArrayList(java.util.ArrayList) ColorConverter(de.catma.util.ColorConverter) CSVFormat(org.apache.commons.csv.CSVFormat) ErrorHandler(de.catma.ui.module.main.ErrorHandler) TagDefinition(de.catma.tag.TagDefinition) TagsetDefinition(de.catma.tag.TagsetDefinition) OutputStreamWriter(java.io.OutputStreamWriter) IDGenerator(de.catma.util.IDGenerator) Collections(java.util.Collections) CSVPrinter(org.apache.commons.csv.CSVPrinter) InputStream(java.io.InputStream) StreamSource(com.vaadin.server.StreamResource.StreamSource) TagDefinition(de.catma.tag.TagDefinition) ArrayList(java.util.ArrayList) PropertyDefinition(de.catma.tag.PropertyDefinition) FileInputStream(java.io.FileInputStream) CSVPrinter(org.apache.commons.csv.CSVPrinter) TagsetDefinition(de.catma.tag.TagsetDefinition) Project(de.catma.project.Project) UI(com.vaadin.ui.UI) FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) File(java.io.File) IDGenerator(de.catma.util.IDGenerator)

Aggregations

PropertyDefinition (de.catma.tag.PropertyDefinition)40 TagDefinition (de.catma.tag.TagDefinition)24 ArrayList (java.util.ArrayList)20 TagsetDefinition (de.catma.tag.TagsetDefinition)18 Pair (de.catma.util.Pair)14 IDGenerator (de.catma.util.IDGenerator)13 UI (com.vaadin.ui.UI)12 Property (de.catma.tag.Property)12 IOException (java.io.IOException)12 Collection (java.util.Collection)12 List (java.util.List)12 ArrayListMultimap (com.google.common.collect.ArrayListMultimap)11 Multimap (com.google.common.collect.Multimap)11 TreeData (com.vaadin.data.TreeData)11 TreeDataProvider (com.vaadin.data.provider.TreeDataProvider)11 Project (de.catma.project.Project)11 ErrorHandler (de.catma.ui.module.main.ErrorHandler)11 PropertyChangeEvent (java.beans.PropertyChangeEvent)11 PropertyChangeListener (java.beans.PropertyChangeListener)11 Set (java.util.Set)11