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