Search in sources :

Example 6 with TagsetDefinition

use of de.catma.tag.TagsetDefinition in project catma by forTEXT.

the class ProjectView method handleTagsetClick.

private void handleTagsetClick(ItemClick<TagsetDefinition> itemClickEvent) {
    if (itemClickEvent.getMouseEventDetails().isDoubleClick()) {
        TagsetDefinition tagset = itemClickEvent.getItem();
        eventBus.post(new RouteToTagsEvent(project, tagset));
    }
}
Also used : TagsetDefinition(de.catma.tag.TagsetDefinition) RouteToTagsEvent(de.catma.ui.events.routing.RouteToTagsEvent)

Example 7 with TagsetDefinition

use of de.catma.tag.TagsetDefinition 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);
    }
}
Also used : SelectionListener(com.vaadin.event.selection.SelectionListener) VerticalLayout(com.vaadin.ui.VerticalLayout) SelectionEvent(com.vaadin.event.selection.SelectionEvent) UI(com.vaadin.ui.UI) ActionGridComponent(de.catma.ui.component.actiongrid.ActionGridComponent) SearchFilterProvider(de.catma.ui.component.actiongrid.SearchFilterProvider) 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) 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) SaveCancelListener(de.catma.ui.dialog.SaveCancelListener) PropertyChangeEvent(java.beans.PropertyChangeEvent) TreeData(com.vaadin.data.TreeData) Project(de.catma.project.Project) Collection(java.util.Collection) 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) PropertyChangeListener(java.beans.PropertyChangeListener) 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) SelectionMode(com.vaadin.ui.Grid.SelectionMode) RBACPermission(de.catma.rbac.RBACPermission) TagDefinition(de.catma.tag.TagDefinition) TagsetDefinition(de.catma.tag.TagsetDefinition)

Example 8 with TagsetDefinition

use of de.catma.tag.TagsetDefinition in project catma by forTEXT.

the class TagsView method initListeners.

private void initListeners() {
    tagChangedListener = new PropertyChangeListener() {

        @SuppressWarnings("unchecked")
        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            Object newValue = evt.getNewValue();
            Object oldValue = evt.getOldValue();
            if (oldValue == null) {
                // created
                Pair<TagsetDefinition, TagDefinition> value = (Pair<TagsetDefinition, TagDefinition>) newValue;
                TagsetDefinition tagset = value.getFirst();
                TagDefinition tag = value.getSecond();
                if (tag.getParentUuid().isEmpty()) {
                    tagsetData.getRootItems().stream().map(tagsetTreeItem -> (TagsetDataItem) tagsetTreeItem).filter(tagsetDataItem -> tagsetDataItem.getTagset().getUuid().equals(tagset.getUuid())).findFirst().ifPresent(tagsetDataItem -> {
                        TagDataItem tagDataItem = new TagDataItem(tag, tagsetDataItem.isEditable());
                        if (!tagsetData.contains(tagDataItem)) {
                            tagsetData.addItem(tagsetDataItem, tagDataItem);
                            tagsetDataProvider.refreshAll();
                            tagsetGrid.expand(tagsetDataItem);
                        }
                    });
                } else {
                    tagsetData.getRootItems().stream().map(tagsetTreeItem -> (TagsetDataItem) tagsetTreeItem).filter(tagsetDataItem -> tagsetDataItem.getTagset().getUuid().equals(tagset.getUuid())).findFirst().ifPresent(tagsetDataItem -> {
                        TagDataItem tagDataItem = new TagDataItem(tag, tagsetDataItem.isEditable());
                        if (!tagsetData.contains(tagDataItem)) {
                            TagDefinition parentTag = project.getTagManager().getTagLibrary().getTagDefinition(tag.getParentUuid());
                            TagsetTreeItem parentTagItem = new TagDataItem(parentTag, tagsetDataItem.isEditable());
                            tagsetData.addItem(parentTagItem, tagDataItem);
                            tagsetDataProvider.refreshAll();
                            tagsetGrid.expand(parentTagItem);
                        }
                    });
                }
            } else if (newValue == null) {
                // removed
                Pair<TagsetDefinition, TagDefinition> deleted = (Pair<TagsetDefinition, TagDefinition>) oldValue;
                TagDefinition deletedTag = deleted.getSecond();
                tagsetData.removeItem(new TagDataItem(deletedTag, true));
                tagsetDataProvider.refreshAll();
                tagsetGrid.deselectAll();
            } else {
                // update
                TagDefinition tag = (TagDefinition) newValue;
                TagsetDefinition tagset = (TagsetDefinition) oldValue;
                tagsetData.getRootItems().stream().map(tagsetTreeItem -> (TagsetDataItem) tagsetTreeItem).filter(tagsetDataItem -> tagsetDataItem.getTagset().getUuid().equals(tagset.getUuid())).findFirst().ifPresent(tagsetDataItem -> {
                    TagDataItem oldItem = new TagDataItem(tag, tagsetDataItem.isEditable());
                    String parentTagId = tag.getParentUuid();
                    TagsetTreeItem parent = tagsetDataItem;
                    if (!parentTagId.isEmpty()) {
                        parent = new TagDataItem(tagset.getTagDefinition(parentTagId), tagsetDataItem.isEditable());
                    }
                    tagsetData.removeItem(oldItem);
                    TagDataItem tagDataItem = new TagDataItem(tag, tagsetDataItem.isEditable());
                    tagDataItem.setPropertiesExpanded(true);
                    tagsetData.addItem(parent, tagDataItem);
                    addTagSubTree(tagset, tag, tagDataItem);
                    // TODO: sort
                    tagsetDataProvider.refreshAll();
                    showExpandedProperties(tagDataItem);
                });
            }
        }
    };
    project.getTagManager().addPropertyChangeListener(TagManagerEvent.tagDefinitionChanged, tagChangedListener);
    propertyDefinitionChangedListener = new PropertyChangeListener() {

        @SuppressWarnings("unchecked")
        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            Object newValue = evt.getNewValue();
            Object oldValue = evt.getOldValue();
            TagDefinition tag = null;
            if (oldValue == null) {
                // created
                Pair<PropertyDefinition, TagDefinition> newData = (Pair<PropertyDefinition, TagDefinition>) newValue;
                tag = newData.getSecond();
            } else if (newValue == null) {
                // removed
                Pair<PropertyDefinition, Pair<TagDefinition, TagsetDefinition>> oldData = (Pair<PropertyDefinition, Pair<TagDefinition, TagsetDefinition>>) oldValue;
                tag = oldData.getSecond().getFirst();
            } else {
                // update
                tag = (TagDefinition) oldValue;
            }
            TagsetTreeItem parentItem = null;
            if (tag.getParentUuid().isEmpty()) {
                parentItem = new TagsetDataItem(project.getTagManager().getTagLibrary().getTagsetDefinition(tag.getTagsetDefinitionUuid()));
            } else {
                parentItem = new TagDataItem(project.getTagManager().getTagLibrary().getTagDefinition(tag.getParentUuid()));
            }
            final String tagId = tag.getUuid();
            tagsetData.getChildren(parentItem).stream().map(tagsetTreeItem -> (TagDataItem) tagsetTreeItem).filter(tagDataItem -> tagDataItem.getTag().getUuid().equals(tagId)).findFirst().ifPresent(tagDataItem -> {
                tagDataItem.setPropertiesExpanded(false);
                hideExpandedProperties(tagDataItem);
                tagDataItem.setPropertiesExpanded(true);
                showExpandedProperties(tagDataItem);
            });
            tagsetDataProvider.refreshAll();
            tagsetGrid.deselectAll();
        }
    };
    project.getTagManager().addPropertyChangeListener(TagManagerEvent.userPropertyDefinitionChanged, propertyDefinitionChangedListener);
}
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) PropertyChangeEvent(java.beans.PropertyChangeEvent) PropertyChangeListener(java.beans.PropertyChangeListener) PropertyDefinition(de.catma.tag.PropertyDefinition) TagsetDefinition(de.catma.tag.TagsetDefinition) Pair(de.catma.util.Pair)

Example 9 with TagsetDefinition

use of de.catma.tag.TagsetDefinition in project catma by forTEXT.

the class TagsView method deleteTags.

void deleteTags(List<TagDefinition> targetTags) {
    String msg = String.format("Are you sure you want to delete the following Tags: %1$s?", targetTags.stream().map(TagDefinition::getName).collect(Collectors.joining(",")));
    ConfirmDialog.show(UI.getCurrent(), "Warning", msg, "Delete", "Cancel", dlg -> {
        if (dlg.isConfirmed()) {
            for (TagDefinition tag : targetTags) {
                TagsetDefinition tagset = project.getTagManager().getTagLibrary().getTagsetDefinition(tag);
                project.getTagManager().removeTagDefinition(tagset, tag);
            }
        }
    });
}
Also used : TagDefinition(de.catma.tag.TagDefinition) TagsetDefinition(de.catma.tag.TagsetDefinition)

Example 10 with TagsetDefinition

use of de.catma.tag.TagsetDefinition 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);
    }
}
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)

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