Search in sources :

Example 26 with TagsetDefinition

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

the class GraphWorktreeProject method importTagsets.

@Override
public void importTagsets(List<TagsetDefinitionImportStatus> tagsetDefinitionImportStatusList) throws IOException {
    for (TagsetDefinitionImportStatus tagsetDefinitionImportStatus : tagsetDefinitionImportStatusList) {
        if (tagsetDefinitionImportStatus.isDoImport()) {
            TagsetDefinition tagset = tagsetDefinitionImportStatus.getTagset();
            // new Tagset
            if (!tagsetDefinitionImportStatus.isInProjectHistory()) {
                try {
                    tagManagerListenersEnabled = false;
                    try {
                        addTagsetDefinition(tagset);
                        tagManager.addTagsetDefinition(tagset);
                    } catch (Exception e) {
                        throw new IOException(String.format("Import of Tagset %1$s failed! The import has been aborted.", tagset.getName()), e);
                    }
                } finally {
                    tagManagerListenersEnabled = true;
                }
                for (TagDefinition tag : tagset.getRootTagDefinitions()) {
                    tagManager.addTagDefinition(tagset, tag);
                    importTagHierarchy(tag, tagset, tagset);
                }
            } else // removed, but exists in version history
            if (!tagsetDefinitionImportStatus.isCurrent()) {
                String oldRootRevisionHash = this.rootRevisionHash;
                Pair<TagsetDefinition, String> result = gitProjectHandler.cloneAndAddTagset(tagset.getUuid(), tagset.getName(), String.format("Re-Added Tagset %1$s with ID %2$s", tagset.getName(), tagset.getUuid()));
                TagsetDefinition oldTagset = result.getFirst();
                this.rootRevisionHash = result.getSecond();
                // remove old Tags
                for (TagDefinition tagDefinition : oldTagset.getRootTagDefinitions()) {
                    gitProjectHandler.removeTag(tagDefinition);
                    oldTagset.remove(tagDefinition);
                }
                try {
                    // add empty Tagset
                    graphProjectHandler.addTagset(this.rootRevisionHash, oldTagset, oldRootRevisionHash);
                    try {
                        tagManagerListenersEnabled = false;
                        tagManager.addTagsetDefinition(tagset);
                    } finally {
                        tagManagerListenersEnabled = true;
                    }
                    // add imported Tags
                    for (TagDefinition tag : tagset.getRootTagDefinitions()) {
                        tagManager.addTagDefinition(oldTagset, tag);
                        importTagHierarchy(tag, tagset, oldTagset);
                    }
                    // update meta data
                    oldTagset.setName(tagset.getName());
                    updateTagsetDefinition(oldTagset);
                } catch (Exception e) {
                    throw new IOException(String.format("Import of Tagset %1$s failed! The import has been aborted.", tagset.getName()), e);
                }
            } else // exists already in project
            {
                try {
                    TagsetDefinition existingTagset = getTagManager().getTagLibrary().getTagsetDefinition(tagset.getUuid());
                    for (TagDefinition incomingTag : tagset) {
                        if (existingTagset.hasTagDefinition(incomingTag.getUuid())) {
                            if (tagsetDefinitionImportStatus.passesUpdateFilter(incomingTag.getUuid())) {
                                TagDefinition existingTag = existingTagset.getTagDefinition(incomingTag.getUuid());
                                for (PropertyDefinition incomingPropertyDef : incomingTag.getUserDefinedPropertyDefinitions()) {
                                    PropertyDefinition existingPropertyDef = existingTag.getPropertyDefinitionByUuid(incomingPropertyDef.getUuid());
                                    if (existingPropertyDef != null) {
                                        for (String value : incomingPropertyDef.getPossibleValueList()) {
                                            if (!existingPropertyDef.getPossibleValueList().contains(value)) {
                                                existingPropertyDef.addValue(value);
                                            }
                                        }
                                        existingPropertyDef.setName(incomingPropertyDef.getName());
                                        updatePropertyDefinition(existingPropertyDef, existingTag);
                                    } else {
                                        existingTag.addUserDefinedPropertyDefinition(incomingPropertyDef);
                                    }
                                    existingTag.setName(incomingTag.getName());
                                    existingTag.setColor(incomingTag.getColor());
                                    updateTagDefinition(existingTag, existingTagset);
                                }
                            }
                        } else {
                            getTagManager().addTagDefinition(existingTagset, incomingTag);
                        }
                    }
                    existingTagset.setName(tagset.getName());
                    updateTagsetDefinition(existingTagset);
                } catch (Exception e) {
                    throw new IOException(String.format("Import of Tagset %1$s failed! The import has been aborted.", tagset.getName()), e);
                }
            }
        }
    }
}
Also used : TagsetDefinition(de.catma.tag.TagsetDefinition) TagDefinition(de.catma.tag.TagDefinition) IOException(java.io.IOException) TagsetDefinitionImportStatus(de.catma.serialization.TagsetDefinitionImportStatus) PropertyDefinition(de.catma.tag.PropertyDefinition) IOException(java.io.IOException) Pair(de.catma.util.Pair)

Example 27 with TagsetDefinition

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

the class AnnotateResourcePanel method initComponents.

private void initComponents() {
    addStyleName("annotate-resource-panel");
    Label documentTreeLabel = new Label("Documents & Annotations");
    documentTree = TreeGridFactory.createDefaultTreeGrid();
    documentTree.addStyleNames("resource-grid", "flat-undecorated-icon-buttonrenderer");
    ButtonRenderer<DocumentTreeItem> documentSelectionRenderer = new ButtonRenderer<DocumentTreeItem>(documentSelectionClick -> handleVisibilityClickEvent(documentSelectionClick));
    documentSelectionRenderer.setHtmlContentAllowed(true);
    Column<DocumentTreeItem, String> selectionColumn = documentTree.addColumn(documentTreeItem -> documentTreeItem.getSelectionIcon(), documentSelectionRenderer).setWidth(100);
    documentTree.setHierarchyColumn(selectionColumn);
    documentTree.addColumn(documentTreeItem -> documentTreeItem.getName()).setCaption("Name").setWidth(150);
    documentTree.setHeight("250px");
    documentTree.addColumn(documentTreeItem -> documentTreeItem.getPermissionIcon(), new HtmlRenderer()).setWidth(50);
    documentTree.addColumn(documentTreeItem -> documentTreeItem.getIcon(), new HtmlRenderer()).setExpandRatio(1);
    documentActionGridComponent = new ActionGridComponent<TreeGrid<DocumentTreeItem>>(documentTreeLabel, documentTree);
    documentActionGridComponent.getActionGridBar().setMoreOptionsBtnVisible(false);
    addComponent(documentActionGridComponent);
    Label tagsetLabel = new Label("Tagsets");
    tagsetGrid = new Grid<>();
    tagsetGrid.addStyleNames("resource-grid", "flat-undecorated-icon-buttonrenderer", "no-focused-before-border");
    tagsetGrid.setHeight("250px");
    tagsetGrid.addColumn(tagset -> tagset.getName()).setCaption("Name").setWidth(150);
    tagsetGrid.addColumn(tagset -> project.hasPermission(project.getRoleForTagset(tagset.getUuid()), RBACPermission.TAGSET_WRITE) ? VaadinIcons.UNLOCK.getHtml() : VaadinIcons.LOCK.getHtml(), new HtmlRenderer()).setWidth(50);
    tagsetGrid.addColumn(tagset -> VaadinIcons.TAGS.getHtml(), new HtmlRenderer()).setExpandRatio(1);
    tagsetActionGridComponent = new ActionGridComponent<Grid<TagsetDefinition>>(tagsetLabel, tagsetGrid);
    tagsetActionGridComponent.setSelectionModeFixed(SelectionMode.MULTI);
    tagsetActionGridComponent.getActionGridBar().setMoreOptionsBtnVisible(false);
    tagsetActionGridComponent.getActionGridBar().setMargin(new MarginInfo(false, false, false, true));
    addComponent(tagsetActionGridComponent);
}
Also used : SelectionEvent(com.vaadin.event.selection.SelectionEvent) UI(com.vaadin.ui.UI) SearchFilterProvider(de.catma.ui.component.actiongrid.SearchFilterProvider) ErrorHandler(de.catma.ui.module.main.ErrorHandler) TreeDataProvider(com.vaadin.data.provider.TreeDataProvider) VaadinIcons(com.vaadin.icons.VaadinIcons) DocumentChangeEvent(de.catma.project.event.DocumentChangeEvent) Version(de.catma.tag.Version) Collection(java.util.Collection) Set(java.util.Set) TreeGrid(com.vaadin.ui.TreeGrid) Collectors(java.util.stream.Collectors) MarginInfo(com.vaadin.shared.ui.MarginInfo) List(java.util.List) Type(com.vaadin.ui.Notification.Type) RendererClickEvent(com.vaadin.ui.renderers.ClickableRenderer.RendererClickEvent) PropertyChangeListener(java.beans.PropertyChangeListener) Optional(java.util.Optional) SingleTextInputDialog(de.catma.ui.dialog.SingleTextInputDialog) CollectionChangeEvent(de.catma.project.event.CollectionChangeEvent) SelectionMode(com.vaadin.ui.Grid.SelectionMode) RBACPermission(de.catma.rbac.RBACPermission) Column(com.vaadin.ui.Grid.Column) VerticalLayout(com.vaadin.ui.VerticalLayout) ActionGridComponent(de.catma.ui.component.actiongrid.ActionGridComponent) HashSet(java.util.HashSet) EventBus(com.google.common.eventbus.EventBus) Notification(com.vaadin.ui.Notification) Label(com.vaadin.ui.Label) TagsetDefinition(de.catma.tag.TagsetDefinition) TreeGridFactory(de.catma.ui.component.TreeGridFactory) IDGenerator(de.catma.util.IDGenerator) Subscribe(com.google.common.eventbus.Subscribe) ButtonRenderer(com.vaadin.ui.renderers.ButtonRenderer) SaveCancelListener(de.catma.ui.dialog.SaveCancelListener) PropertyChangeEvent(java.beans.PropertyChangeEvent) ListDataProvider(com.vaadin.data.provider.ListDataProvider) TreeData(com.vaadin.data.TreeData) AnnotationCollectionReference(de.catma.document.annotation.AnnotationCollectionReference) Project(de.catma.project.Project) RepositoryChangeEvent(de.catma.project.Project.RepositoryChangeEvent) SourceDocument(de.catma.document.source.SourceDocument) ProjectReadyEvent(de.catma.project.event.ProjectReadyEvent) TagManagerEvent(de.catma.tag.TagManager.TagManagerEvent) ChangeType(de.catma.project.event.ChangeType) SerializablePredicate(com.vaadin.server.SerializablePredicate) HtmlRenderer(com.vaadin.ui.renderers.HtmlRenderer) Collections(java.util.Collections) Grid(com.vaadin.ui.Grid) TreeGrid(com.vaadin.ui.TreeGrid) Grid(com.vaadin.ui.Grid) Label(com.vaadin.ui.Label) MarginInfo(com.vaadin.shared.ui.MarginInfo) TreeGrid(com.vaadin.ui.TreeGrid) HtmlRenderer(com.vaadin.ui.renderers.HtmlRenderer) ButtonRenderer(com.vaadin.ui.renderers.ButtonRenderer)

Example 28 with TagsetDefinition

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

the class TaggerContextMenu 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();
                Object parent = tagset;
                if (!tag.getParentUuid().isEmpty()) {
                    parent = tagset.getTagDefinition(tag.getParentUuid());
                }
                MenuItem parentItem = entryToMenuItemMap.get(parent);
                if (parentItem != null) {
                    addToMenuItem(parentItem, tagset, tag);
                }
            } else if (newValue == null) {
                // removed
                Pair<TagsetDefinition, TagDefinition> deleted = (Pair<TagsetDefinition, TagDefinition>) oldValue;
                TagDefinition deletedTag = deleted.getSecond();
                MenuItem menuItem = entryToMenuItemMap.get(deletedTag);
                if (menuItem != null) {
                    contextMenu.removeItem(menuItem);
                }
            } else {
                // update
                TagDefinition tag = (TagDefinition) newValue;
                TagsetDefinition tagset = (TagsetDefinition) oldValue;
                MenuItem menuItem = entryToMenuItemMap.get(tag);
                if (menuItem != null) {
                    menuItem.setText(createTagMenuItemCaption(tag));
                }
            }
        }
    };
    tagManager.addPropertyChangeListener(TagManagerEvent.tagDefinitionChanged, tagChangedListener);
}
Also used : TagsetDefinition(de.catma.tag.TagsetDefinition) TagDefinition(de.catma.tag.TagDefinition) PropertyChangeEvent(java.beans.PropertyChangeEvent) PropertyChangeListener(java.beans.PropertyChangeListener) MenuItem(com.vaadin.ui.MenuBar.MenuItem) Pair(de.catma.util.Pair)

Example 29 with TagsetDefinition

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

the class TaggerContextMenu method setTagsets.

public void setTagsets(Collection<TagsetDefinition> tagsets) {
    contextMenu.removeItems();
    entryToMenuItemMap.clear();
    for (TagsetDefinition tagset : tagsets) {
        addTagset(tagset);
    }
}
Also used : TagsetDefinition(de.catma.tag.TagsetDefinition)

Example 30 with TagsetDefinition

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

the class AnnotationPanel method handleSingleEditProperties.

private void handleSingleEditProperties(List<PropertyDefinition> editedPropertyDefs, TagDefinition tag) {
    TagsetDefinition tagset = project.getTagManager().getTagLibrary().getTagsetDefinition(tag);
    for (PropertyDefinition existingPropertyDef : new ArrayList<>(tag.getUserDefinedPropertyDefinitions())) {
        // handle deleted PropertyDefs
        if (!editedPropertyDefs.contains(existingPropertyDef)) {
            project.getTagManager().removeUserDefinedPropertyDefinition(existingPropertyDef, tag, tagset);
        } else // handle updated PropertyDefs
        {
            editedPropertyDefs.stream().filter(possiblyChangedPd -> possiblyChangedPd.getUuid().equals(existingPropertyDef.getUuid())).findFirst().ifPresent(editedPropertyDef -> {
                existingPropertyDef.setName(editedPropertyDef.getName());
                existingPropertyDef.setPossibleValueList(editedPropertyDef.getPossibleValueList());
            });
            project.getTagManager().updateUserDefinedPropertyDefinition(tag, existingPropertyDef);
        }
    }
    // handle created PropertyDefs
    for (PropertyDefinition pd : editedPropertyDefs) {
        if (tag.getPropertyDefinitionByUuid(pd.getUuid()) == null) {
            PropertyDefinition createdPropertyDefinition = new PropertyDefinition(pd);
            pd.setUuid(idGenerator.generate());
            project.getTagManager().addUserDefinedPropertyDefinition(tag, createdPropertyDefinition);
        }
    }
}
Also used : TagsetDefinition(de.catma.tag.TagsetDefinition) ArrayList(java.util.ArrayList) PropertyDefinition(de.catma.tag.PropertyDefinition)

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