Search in sources :

Example 11 with TagsetDefinition

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);
    }
}
Also used : ArrayListMultimap(com.google.common.collect.ArrayListMultimap) PropertyDefinition(de.catma.tag.PropertyDefinition) UI(com.vaadin.ui.UI) ConfirmDialog(org.vaadin.dialogs.ConfirmDialog) Multimap(com.google.common.collect.Multimap) ActionGridComponent(de.catma.ui.component.actiongrid.ActionGridComponent) SearchFilterProvider(de.catma.ui.component.actiongrid.SearchFilterProvider) ArrayList(java.util.ArrayList) EventBus(com.google.common.eventbus.EventBus) MaterialTheme(com.github.appreciated.material.MaterialTheme) Notification(com.vaadin.ui.Notification) ErrorHandler(de.catma.ui.module.main.ErrorHandler) Label(com.vaadin.ui.Label) TagsetDefinition(de.catma.tag.TagsetDefinition) SliderPanel(org.vaadin.sliderpanel.SliderPanel) TreeDataProvider(com.vaadin.data.provider.TreeDataProvider) Pair(de.catma.util.Pair) Version(de.catma.tag.Version) TreeGridFactory(de.catma.ui.component.TreeGridFactory) IDGenerator(de.catma.util.IDGenerator) ButtonRenderer(com.vaadin.ui.renderers.ButtonRenderer) SaveCancelListener(de.catma.ui.dialog.SaveCancelListener) PropertyChangeEvent(java.beans.PropertyChangeEvent) TreeData(com.vaadin.data.TreeData) Project(de.catma.project.Project) Collection(java.util.Collection) Set(java.util.Set) IOException(java.io.IOException) TreeGrid(com.vaadin.ui.TreeGrid) Collectors(java.util.stream.Collectors) TagManagerEvent(de.catma.tag.TagManager.TagManagerEvent) ContextMenu(com.vaadin.contextmenu.ContextMenu) List(java.util.List) Type(com.vaadin.ui.Notification.Type) RendererClickEvent(com.vaadin.ui.renderers.ClickableRenderer.RendererClickEvent) PropertyChangeListener(java.beans.PropertyChangeListener) HorizontalLayout(com.vaadin.ui.HorizontalLayout) TagDefinition(de.catma.tag.TagDefinition) SerializablePredicate(com.vaadin.server.SerializablePredicate) Optional(java.util.Optional) HtmlRenderer(com.vaadin.ui.renderers.HtmlRenderer) SingleTextInputDialog(de.catma.ui.dialog.SingleTextInputDialog) SliderPanelBuilder(org.vaadin.sliderpanel.SliderPanelBuilder) SelectionMode(com.vaadin.ui.Grid.SelectionMode) StyleGenerator(com.vaadin.ui.StyleGenerator) RBACPermission(de.catma.rbac.RBACPermission) SliderMode(org.vaadin.sliderpanel.client.SliderMode) HugeCard(de.catma.ui.component.hugecard.HugeCard) TagsetDefinition(de.catma.tag.TagsetDefinition) SingleTextInputDialog(de.catma.ui.dialog.SingleTextInputDialog)

Example 12 with TagsetDefinition

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);
            }
        }
    }
}
Also used : ArrayListMultimap(com.google.common.collect.ArrayListMultimap) PropertyDefinition(de.catma.tag.PropertyDefinition) UI(com.vaadin.ui.UI) ConfirmDialog(org.vaadin.dialogs.ConfirmDialog) Multimap(com.google.common.collect.Multimap) ActionGridComponent(de.catma.ui.component.actiongrid.ActionGridComponent) SearchFilterProvider(de.catma.ui.component.actiongrid.SearchFilterProvider) ArrayList(java.util.ArrayList) EventBus(com.google.common.eventbus.EventBus) MaterialTheme(com.github.appreciated.material.MaterialTheme) Notification(com.vaadin.ui.Notification) ErrorHandler(de.catma.ui.module.main.ErrorHandler) Label(com.vaadin.ui.Label) TagsetDefinition(de.catma.tag.TagsetDefinition) SliderPanel(org.vaadin.sliderpanel.SliderPanel) TreeDataProvider(com.vaadin.data.provider.TreeDataProvider) Pair(de.catma.util.Pair) Version(de.catma.tag.Version) TreeGridFactory(de.catma.ui.component.TreeGridFactory) IDGenerator(de.catma.util.IDGenerator) ButtonRenderer(com.vaadin.ui.renderers.ButtonRenderer) SaveCancelListener(de.catma.ui.dialog.SaveCancelListener) PropertyChangeEvent(java.beans.PropertyChangeEvent) TreeData(com.vaadin.data.TreeData) Project(de.catma.project.Project) Collection(java.util.Collection) Set(java.util.Set) IOException(java.io.IOException) TreeGrid(com.vaadin.ui.TreeGrid) Collectors(java.util.stream.Collectors) TagManagerEvent(de.catma.tag.TagManager.TagManagerEvent) ContextMenu(com.vaadin.contextmenu.ContextMenu) List(java.util.List) Type(com.vaadin.ui.Notification.Type) RendererClickEvent(com.vaadin.ui.renderers.ClickableRenderer.RendererClickEvent) PropertyChangeListener(java.beans.PropertyChangeListener) HorizontalLayout(com.vaadin.ui.HorizontalLayout) TagDefinition(de.catma.tag.TagDefinition) SerializablePredicate(com.vaadin.server.SerializablePredicate) Optional(java.util.Optional) HtmlRenderer(com.vaadin.ui.renderers.HtmlRenderer) SingleTextInputDialog(de.catma.ui.dialog.SingleTextInputDialog) SliderPanelBuilder(org.vaadin.sliderpanel.SliderPanelBuilder) SelectionMode(com.vaadin.ui.Grid.SelectionMode) StyleGenerator(com.vaadin.ui.StyleGenerator) RBACPermission(de.catma.rbac.RBACPermission) SliderMode(org.vaadin.sliderpanel.client.SliderMode) HugeCard(de.catma.ui.component.hugecard.HugeCard) TagDefinition(de.catma.tag.TagDefinition) TagsetDefinition(de.catma.tag.TagsetDefinition) ArrayList(java.util.ArrayList) PropertyDefinition(de.catma.tag.PropertyDefinition)

Example 13 with TagsetDefinition

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);
}
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 14 with TagsetDefinition

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);
    }
}
Also used : Column(com.vaadin.ui.Grid.Column) Alignment(com.vaadin.ui.Alignment) ComboBox(com.vaadin.ui.ComboBox) UI(com.vaadin.ui.UI) HashBasedTable(com.google.common.collect.HashBasedTable) Window(com.vaadin.ui.Window) RBACRole(de.catma.rbac.RBACRole) ActionGridComponent(de.catma.ui.component.actiongrid.ActionGridComponent) SearchFilterProvider(de.catma.ui.component.actiongrid.SearchFilterProvider) Binding(com.vaadin.data.Binder.Binding) HashSet(java.util.HashSet) Member(de.catma.user.Member) ErrorHandler(de.catma.ui.module.main.ErrorHandler) Label(com.vaadin.ui.Label) TagsetDefinition(de.catma.tag.TagsetDefinition) TreeDataProvider(com.vaadin.data.provider.TreeDataProvider) TreeGridFactory(de.catma.ui.component.TreeGridFactory) TreeData(com.vaadin.data.TreeData) Project(de.catma.project.Project) Collection(java.util.Collection) Set(java.util.Set) IOException(java.io.IOException) StatusChangeListener(com.vaadin.data.StatusChangeListener) TreeGrid(com.vaadin.ui.TreeGrid) Binder(com.vaadin.data.Binder) MarginInfo(com.vaadin.shared.ui.MarginInfo) StatusChangeEvent(com.vaadin.data.StatusChangeEvent) List(java.util.List) Button(com.vaadin.ui.Button) HorizontalLayout(com.vaadin.ui.HorizontalLayout) SerializablePredicate(com.vaadin.server.SerializablePredicate) HelpWindow(de.catma.ui.dialog.HelpWindow) HtmlRenderer(com.vaadin.ui.renderers.HtmlRenderer) SelectionMode(com.vaadin.ui.Grid.SelectionMode) Table(com.google.common.collect.Table) IOException(java.io.IOException) TagsetDefinition(de.catma.tag.TagsetDefinition) RBACRole(de.catma.rbac.RBACRole) HtmlRenderer(com.vaadin.ui.renderers.HtmlRenderer) TreeData(com.vaadin.data.TreeData) Member(de.catma.user.Member)

Example 15 with TagsetDefinition

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;
}
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

TagsetDefinition (de.catma.tag.TagsetDefinition)61 IDGenerator (de.catma.util.IDGenerator)31 TagDefinition (de.catma.tag.TagDefinition)27 ArrayList (java.util.ArrayList)27 List (java.util.List)24 UI (com.vaadin.ui.UI)23 ErrorHandler (de.catma.ui.module.main.ErrorHandler)23 Pair (de.catma.util.Pair)23 IOException (java.io.IOException)23 Collection (java.util.Collection)23 Project (de.catma.project.Project)22 PropertyDefinition (de.catma.tag.PropertyDefinition)22 PropertyChangeEvent (java.beans.PropertyChangeEvent)22 PropertyChangeListener (java.beans.PropertyChangeListener)22 Version (de.catma.tag.Version)21 SingleTextInputDialog (de.catma.ui.dialog.SingleTextInputDialog)21 AnnotationCollection (de.catma.document.annotation.AnnotationCollection)20 Collectors (java.util.stream.Collectors)20 TagManagerEvent (de.catma.tag.TagManager.TagManagerEvent)19 Set (java.util.Set)19