Search in sources :

Example 11 with PropertyDefinition

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

the class TagConflict method createCombinedTagDefinition.

private TagDefinition createCombinedTagDefinition() {
    TagDefinition tagDefinition = new TagDefinition(masterTagDefinition);
    for (PropertyDefinition devPropertyDef : devTagDefinition.getUserDefinedPropertyDefinitions()) {
        PropertyDefinition combinedPropertyDef = tagDefinition.getPropertyDefinitionByUuid(devPropertyDef.getUuid());
        if (combinedPropertyDef == null) {
            combinedPropertyDef = new PropertyDefinition(devPropertyDef);
            tagDefinition.addUserDefinedPropertyDefinition(combinedPropertyDef);
        } else {
            for (String value : devPropertyDef.getPossibleValueList()) {
                if (!combinedPropertyDef.getPossibleValueList().contains(value)) {
                    combinedPropertyDef.addValue(value);
                }
            }
        }
    }
    return tagDefinition;
}
Also used : TagDefinition(de.catma.tag.TagDefinition) PropertyDefinition(de.catma.tag.PropertyDefinition)

Example 12 with PropertyDefinition

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

the class GraphWorktreeProject method initTagManagerListeners.

private void initTagManagerListeners() {
    tagsetDefinitionChangedListener = new PropertyChangeListener() {

        public void propertyChange(final PropertyChangeEvent evt) {
            if (!tagManagerListenersEnabled) {
                return;
            }
            try {
                if (evt.getOldValue() == null) {
                    // insert
                    final TagsetDefinition tagsetDefinition = (TagsetDefinition) evt.getNewValue();
                    addTagsetDefinition(tagsetDefinition);
                } else if (evt.getNewValue() == null) {
                    // delete
                    final TagsetDefinition tagsetDefinition = (TagsetDefinition) evt.getOldValue();
                    removeTagsetDefinition(tagsetDefinition);
                } else {
                    // update
                    final TagsetDefinition tagsetDefinition = (TagsetDefinition) evt.getNewValue();
                    updateTagsetDefinition(tagsetDefinition);
                }
            } catch (Exception e) {
                propertyChangeSupport.firePropertyChange(RepositoryChangeEvent.exceptionOccurred.name(), null, e);
            }
        }
    };
    tagManager.addPropertyChangeListener(TagManagerEvent.tagsetDefinitionChanged, tagsetDefinitionChangedListener);
    tagDefinitionChangedListener = new PropertyChangeListener() {

        public void propertyChange(final PropertyChangeEvent evt) {
            if (!tagManagerListenersEnabled) {
                return;
            }
            try {
                if (evt.getOldValue() == null) {
                    @SuppressWarnings("unchecked") final Pair<TagsetDefinition, TagDefinition> args = (Pair<TagsetDefinition, TagDefinition>) evt.getNewValue();
                    TagsetDefinition tagsetDefinition = args.getFirst();
                    TagDefinition tagDefinition = args.getSecond();
                    addTagDefinition(tagDefinition, tagsetDefinition);
                } else if (evt.getNewValue() == null) {
                    @SuppressWarnings("unchecked") final Pair<TagsetDefinition, TagDefinition> args = (Pair<TagsetDefinition, TagDefinition>) evt.getOldValue();
                    TagsetDefinition tagsetDefinition = args.getFirst();
                    TagDefinition tagDefinition = args.getSecond();
                    removeTagDefinition(tagDefinition, tagsetDefinition);
                } else {
                    TagDefinition tag = (TagDefinition) evt.getNewValue();
                    TagsetDefinition tagset = (TagsetDefinition) evt.getOldValue();
                    updateTagDefinition(tag, tagset);
                }
            } catch (Exception e) {
                propertyChangeSupport.firePropertyChange(RepositoryChangeEvent.exceptionOccurred.name(), null, e);
            }
        }
    };
    tagManager.addPropertyChangeListener(TagManagerEvent.tagDefinitionChanged, tagDefinitionChangedListener);
    userDefinedPropertyChangedListener = new PropertyChangeListener() {

        public void propertyChange(PropertyChangeEvent evt) {
            if (!tagManagerListenersEnabled) {
                return;
            }
            Object oldValue = evt.getOldValue();
            Object newValue = evt.getNewValue();
            try {
                if (oldValue == null) {
                    // insert
                    @SuppressWarnings("unchecked") Pair<PropertyDefinition, TagDefinition> newPair = (Pair<PropertyDefinition, TagDefinition>) newValue;
                    PropertyDefinition propertyDefinition = newPair.getFirst();
                    TagDefinition tagDefinition = newPair.getSecond();
                    addPropertyDefinition(propertyDefinition, tagDefinition);
                } else if (newValue == null) {
                    // delete
                    @SuppressWarnings("unchecked") Pair<PropertyDefinition, Pair<TagDefinition, TagsetDefinition>> oldPair = (Pair<PropertyDefinition, Pair<TagDefinition, TagsetDefinition>>) oldValue;
                    PropertyDefinition propertyDefinition = oldPair.getFirst();
                    TagDefinition tagDefinition = oldPair.getSecond().getFirst();
                    TagsetDefinition tagsetDefinition = oldPair.getSecond().getSecond();
                    removePropertyDefinition(propertyDefinition, tagDefinition, tagsetDefinition);
                } else {
                    // update
                    PropertyDefinition propertyDefinition = (PropertyDefinition) evt.getNewValue();
                    TagDefinition tagDefinition = (TagDefinition) evt.getOldValue();
                    updatePropertyDefinition(propertyDefinition, tagDefinition);
                }
            } catch (Exception e) {
                propertyChangeSupport.firePropertyChange(RepositoryChangeEvent.exceptionOccurred.name(), null, e);
            }
        }
    };
    tagManager.addPropertyChangeListener(TagManagerEvent.userPropertyDefinitionChanged, userDefinedPropertyChangedListener);
}
Also used : TagsetDefinition(de.catma.tag.TagsetDefinition) TagDefinition(de.catma.tag.TagDefinition) PropertyChangeEvent(java.beans.PropertyChangeEvent) PropertyChangeListener(java.beans.PropertyChangeListener) PropertyDefinition(de.catma.tag.PropertyDefinition) IOException(java.io.IOException) Pair(de.catma.util.Pair)

Example 13 with PropertyDefinition

use of de.catma.tag.PropertyDefinition 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 14 with PropertyDefinition

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

the class AnnotationConflictView method createPropertyTreeDataProvider.

private TreeDataProvider<PropertyTreeItem> createPropertyTreeDataProvider(TagInstance tagInstance, TagDefinition tag) {
    TreeData<PropertyTreeItem> propertyTreeData = new TreeData<>();
    for (Property property : tagInstance.getUserDefinedProperties()) {
        PropertyDefinition propertyDef = tag.getPropertyDefinitionByUuid(property.getPropertyDefinitionId());
        PropertyDataItem propertyDataItem = new PropertyDataItem(propertyDef, property);
        propertyTreeData.addItem(null, propertyDataItem);
        for (String value : property.getPropertyValueList()) {
            propertyTreeData.addItem(propertyDataItem, new PropertyValueDataItem(property, value));
        }
    }
    TreeDataProvider<PropertyTreeItem> propertyTreeDataProvider = new TreeDataProvider<>(propertyTreeData);
    return propertyTreeDataProvider;
}
Also used : TreeDataProvider(com.vaadin.data.provider.TreeDataProvider) TreeData(com.vaadin.data.TreeData) Property(de.catma.tag.Property) PropertyDefinition(de.catma.tag.PropertyDefinition)

Example 15 with PropertyDefinition

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

the class AnnotationPanel method showExpandedProperties.

private void showExpandedProperties(TagDataItem tagDataItem) {
    TagDefinition tag = tagDataItem.getTag();
    PropertyDataItem lastPropertyDataItem = null;
    for (PropertyDefinition propertyDefinition : tag.getUserDefinedPropertyDefinitions()) {
        lastPropertyDataItem = new PropertyDataItem(propertyDefinition);
        tagsetGrid.getTreeData().addItem(tagDataItem, lastPropertyDataItem);
    }
    List<TagsetTreeItem> children = tagsetData.getChildren(tagDataItem).stream().filter(tagsetTreeItem -> tagsetTreeItem instanceof TagDataItem).collect(Collectors.toList());
    for (int i = children.size() - 1; i >= 0; i--) {
        tagsetData.moveAfterSibling(children.get(i), lastPropertyDataItem);
    }
    tagsetGrid.expand(tagDataItem);
}
Also used : ArrayListMultimap(com.google.common.collect.ArrayListMultimap) BackgroundServiceProvider(de.catma.backgroundservice.BackgroundServiceProvider) VerticalSplitPanel(com.vaadin.ui.VerticalSplitPanel) Alignment(com.vaadin.ui.Alignment) UI(com.vaadin.ui.UI) XmlMarkupCollectionSerializationHandler(de.catma.serialization.intrinsic.xml.XmlMarkupCollectionSerializationHandler) 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) IconButton(de.catma.ui.component.IconButton) Collection(java.util.Collection) Set(java.util.Set) TreeGrid(com.vaadin.ui.TreeGrid) Collectors(java.util.stream.Collectors) ItemClick(com.vaadin.ui.Grid.ItemClick) TagReference(de.catma.document.annotation.TagReference) Objects(java.util.Objects) List(java.util.List) Type(com.vaadin.ui.Notification.Type) RendererClickEvent(com.vaadin.ui.renderers.ClickableRenderer.RendererClickEvent) PropertyChangeListener(java.beans.PropertyChangeListener) TagDefinition(de.catma.tag.TagDefinition) Optional(java.util.Optional) SingleTextInputDialog(de.catma.ui.dialog.SingleTextInputDialog) CollectionChangeEvent(de.catma.project.event.CollectionChangeEvent) SelectionMode(com.vaadin.ui.Grid.SelectionMode) StyleGenerator(com.vaadin.ui.StyleGenerator) RBACPermission(de.catma.rbac.RBACPermission) PropertyDefinition(de.catma.tag.PropertyDefinition) VerticalLayout(com.vaadin.ui.VerticalLayout) AnnotationCollectionManager(de.catma.document.annotation.AnnotationCollectionManager) ComboBox(com.vaadin.ui.ComboBox) Multimap(com.google.common.collect.Multimap) ActionGridComponent(de.catma.ui.component.actiongrid.ActionGridComponent) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) EventBus(com.google.common.eventbus.EventBus) AddEditPropertyDialog(de.catma.ui.module.tags.AddEditPropertyDialog) MaterialTheme(com.github.appreciated.material.MaterialTheme) EditTagDialog(de.catma.ui.module.tags.EditTagDialog) Notification(com.vaadin.ui.Notification) Label(com.vaadin.ui.Label) TagsetDefinition(de.catma.tag.TagsetDefinition) Pair(de.catma.util.Pair) 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) AddSubtagDialog(de.catma.ui.module.tags.AddSubtagDialog) IOException(java.io.IOException) AddParenttagDialog(de.catma.ui.module.tags.AddParenttagDialog) SourceDocument(de.catma.document.source.SourceDocument) AnnotationCollection(de.catma.document.annotation.AnnotationCollection) Annotation(de.catma.document.annotation.Annotation) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) TagManagerEvent(de.catma.tag.TagManager.TagManagerEvent) ContextMenu(com.vaadin.contextmenu.ContextMenu) Button(com.vaadin.ui.Button) ChangeType(de.catma.project.event.ChangeType) HorizontalLayout(com.vaadin.ui.HorizontalLayout) SerializablePredicate(com.vaadin.server.SerializablePredicate) HtmlRenderer(com.vaadin.ui.renderers.HtmlRenderer) TagDefinition(de.catma.tag.TagDefinition) PropertyDefinition(de.catma.tag.PropertyDefinition)

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