Search in sources :

Example 1 with Annotation

use of de.catma.document.annotation.Annotation in project catma by forTEXT.

the class AnnotationDetailsPanel method handleDeleteAnnotationRequest.

private void handleDeleteAnnotationRequest(RendererClickEvent<AnnotationTreeItem> clickEvent) {
    AnnotationDataItem item = (AnnotationDataItem) clickEvent.getItem();
    final Annotation annotation = item.getAnnotation();
    if (project.hasPermission(project.getRoleForCollection(annotation.getUserMarkupCollection().getUuid()), RBACPermission.COLLECTION_WRITE)) {
        if (!isCurrentEditedCollection.apply(annotation.getUserMarkupCollection().getUuid())) {
            changeCollectionListener.accept(annotation.getUserMarkupCollection().getUuid());
            annotationDetailsProvider.refreshAll();
        } else {
            ConfirmDialog.show(UI.getCurrent(), "Info", "Are you sure you want to delete this Annotation?", "Delete", "Cancel", dlg -> {
                if (dlg.isConfirmed()) {
                    collectionManager.removeTagInstance(annotation.getTagInstance().getUuid());
                }
            });
        }
    } else {
        Notification.show("Info", "You do not have the permission to make changes to the Collection of this Annotation, " + "please contact the Project maintainer!", Type.HUMANIZED_MESSAGE);
    }
}
Also used : Annotation(de.catma.document.annotation.Annotation)

Example 2 with Annotation

use of de.catma.document.annotation.Annotation in project catma by forTEXT.

the class TaggerView method tagInstanceAdded.

public void tagInstanceAdded(ClientTagInstance clientTagInstance) {
    AnnotationCollection collection = annotationPanel.getSelectedEditableCollection();
    if (collection == null) {
        // shouldn't happen, but just in case
        Notification.show("Info", "Please make sure you have an editable Collection available " + "and select this Collection as 'currently being edited'! " + "Your Annotation hasn't been saved!", Type.ERROR_MESSAGE);
    } else {
        TagLibrary tagLibrary = collection.getTagLibrary();
        TagDefinition tagDef = tagLibrary.getTagDefinition(clientTagInstance.getTagDefinitionID());
        TagInstance ti = new TagInstance(clientTagInstance.getInstanceID(), tagDef.getUuid(), project.getUser().getIdentifier(), ZonedDateTime.now().format(DateTimeFormatter.ofPattern(Version.DATETIMEPATTERN)), tagDef.getUserDefinedPropertyDefinitions(), tagDef.getTagsetDefinitionUuid());
        List<TagReference> tagReferences = new ArrayList<TagReference>();
        try {
            String userMarkupCollectionUuid = collection.getId();
            for (TextRange tr : clientTagInstance.getRanges()) {
                Range r = new Range(tr.getStartPos(), tr.getEndPos());
                TagReference ref = new TagReference(ti, sourceDocument.getUuid(), r, userMarkupCollectionUuid);
                tagReferences.add(ref);
            }
            final Annotation annotation = new Annotation(ti, tagReferences, collection, tagLibrary.getTagPath(tagDef));
            if (!tagDef.getUserDefinedPropertyDefinitions().isEmpty()) {
                EditAnnotationPropertiesDialog editAnnotationPropertiesDialog = new EditAnnotationPropertiesDialog(project, annotation, new SaveCancelListener<List<Property>>() {

                    @Override
                    public void savePressed(List<Property> notOfInterest) {
                        userMarkupCollectionManager.addTagReferences(tagReferences, collection);
                    }
                });
                editAnnotationPropertiesDialog.show();
            } else {
                userMarkupCollectionManager.addTagReferences(tagReferences, collection);
            }
        } catch (URISyntaxException e) {
            errorHandler.showAndLogError("Error adding Annotations!", e);
        }
    }
}
Also used : TagLibrary(de.catma.tag.TagLibrary) TagDefinition(de.catma.tag.TagDefinition) AnnotationCollection(de.catma.document.annotation.AnnotationCollection) ArrayList(java.util.ArrayList) TextRange(de.catma.ui.client.ui.tagger.shared.TextRange) URISyntaxException(java.net.URISyntaxException) Range(de.catma.document.Range) TextRange(de.catma.ui.client.ui.tagger.shared.TextRange) Annotation(de.catma.document.annotation.Annotation) EditAnnotationPropertiesDialog(de.catma.ui.module.annotate.annotationpanel.EditAnnotationPropertiesDialog) TagInstance(de.catma.tag.TagInstance) ClientTagInstance(de.catma.ui.client.ui.tagger.shared.ClientTagInstance) TagReference(de.catma.document.annotation.TagReference) ArrayList(java.util.ArrayList) List(java.util.List) Property(de.catma.tag.Property)

Example 3 with Annotation

use of de.catma.document.annotation.Annotation in project catma by forTEXT.

the class AnnotationDetailsPanel method initListeners.

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

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            TagInstance tagInstance = (TagInstance) evt.getOldValue();
            findAnnotationDataItem(tagInstance.getUuid()).ifPresent(annotationDataItem -> {
                Annotation annotation = annotationDataItem.getAnnotation();
                annotationDetailData.removeItem(annotationDataItem);
                try {
                    addAnnotation(annotation);
                } catch (Exception e) {
                    ((ErrorHandler) UI.getCurrent()).showAndLogError("error adding Annotation", e);
                }
            });
        }
    };
    project.addPropertyChangeListener(RepositoryChangeEvent.propertyValueChanged, annotationPropertiesChangedListener);
    propertyDefinitionChangedListener = new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            refreshAnnotations();
        }
    };
    project.getTagManager().addPropertyChangeListener(TagManagerEvent.userPropertyDefinitionChanged, propertyDefinitionChangedListener);
    tagChangedListener = new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            if ((evt.getOldValue() != null) && (evt.getNewValue() == null)) {
            }
            refreshAnnotations();
        }
    };
    project.getTagManager().addPropertyChangeListener(TagManagerEvent.tagDefinitionChanged, tagChangedListener);
}
Also used : SelectionEvent(com.vaadin.event.selection.SelectionEvent) Alignment(com.vaadin.ui.Alignment) UI(com.vaadin.ui.UI) ConfirmDialog(org.vaadin.dialogs.ConfirmDialog) KwicProvider(de.catma.indexer.KwicProvider) ErrorHandler(de.catma.ui.module.main.ErrorHandler) TreeDataProvider(com.vaadin.data.provider.TreeDataProvider) VaadinIcons(com.vaadin.icons.VaadinIcons) Objects(com.google.common.base.Objects) IconButton(de.catma.ui.component.IconButton) Collection(java.util.Collection) Set(java.util.Set) TagInstance(de.catma.tag.TagInstance) TreeGrid(com.vaadin.ui.TreeGrid) Collectors(java.util.stream.Collectors) 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) RBACPermission(de.catma.rbac.RBACPermission) PropertyDefinition(de.catma.tag.PropertyDefinition) ClickListener(com.vaadin.ui.Button.ClickListener) DescriptionGenerator(com.vaadin.ui.DescriptionGenerator) VerticalLayout(com.vaadin.ui.VerticalLayout) AnnotationCollectionManager(de.catma.document.annotation.AnnotationCollectionManager) ActionGridComponent(de.catma.ui.component.actiongrid.ActionGridComponent) Function(java.util.function.Function) ArrayList(java.util.ArrayList) Registration(com.vaadin.shared.Registration) Notification(com.vaadin.ui.Notification) Label(com.vaadin.ui.Label) TreeGridFactory(de.catma.ui.component.TreeGridFactory) ButtonRenderer(com.vaadin.ui.renderers.ButtonRenderer) SaveCancelListener(de.catma.ui.dialog.SaveCancelListener) PropertyChangeEvent(java.beans.PropertyChangeEvent) ContentMode(com.vaadin.shared.ui.ContentMode) Property(de.catma.tag.Property) TreeData(com.vaadin.data.TreeData) Project(de.catma.project.Project) RepositoryChangeEvent(de.catma.project.Project.RepositoryChangeEvent) IOException(java.io.IOException) SourceDocument(de.catma.document.source.SourceDocument) Annotation(de.catma.document.annotation.Annotation) Consumer(java.util.function.Consumer) TagManagerEvent(de.catma.tag.TagManager.TagManagerEvent) Button(com.vaadin.ui.Button) HorizontalLayout(com.vaadin.ui.HorizontalLayout) ScrollDestination(com.vaadin.shared.ui.grid.ScrollDestination) HtmlRenderer(com.vaadin.ui.renderers.HtmlRenderer) ErrorHandler(de.catma.ui.module.main.ErrorHandler) PropertyChangeEvent(java.beans.PropertyChangeEvent) PropertyChangeListener(java.beans.PropertyChangeListener) TagInstance(de.catma.tag.TagInstance) Annotation(de.catma.document.annotation.Annotation) IOException(java.io.IOException)

Example 4 with Annotation

use of de.catma.document.annotation.Annotation in project catma by forTEXT.

the class AnnotationDetailsPanel method initComponents.

private void initComponents() {
    setSpacing(true);
    setMargin(false);
    setSizeFull();
    addStyleName("annotation-details-panel");
    HorizontalLayout headerPanel = new HorizontalLayout();
    headerPanel.setWidth("100%");
    addComponent(headerPanel);
    btClearSelected = new IconButton(VaadinIcons.ERASER);
    btClearSelected.setDescription("Clear the list of selected Annotations");
    headerPanel.addComponent(btClearSelected);
    headerPanel.setComponentAlignment(btClearSelected, Alignment.TOP_RIGHT);
    headerPanel.setExpandRatio(btClearSelected, 1.0f);
    btMinimize = new IconButton(VaadinIcons.ANGLE_DOUBLE_DOWN);
    headerPanel.addComponent(btMinimize);
    headerPanel.setComponentAlignment(btMinimize, Alignment.TOP_RIGHT);
    annotationDetailData = new TreeData<>();
    annotationDetailsProvider = new TreeDataProvider<>(annotationDetailData);
    annotationDetailsTree = TreeGridFactory.createDefaultGrid(annotationDetailsProvider);
    annotationDetailsTree.setSizeFull();
    annotationDetailsTree.addStyleNames("annotation-details-panel-annotation-details-grid", "flat-undecorated-icon-buttonrenderer");
    annotationDetailsTree.addColumn(annotationTreeItem -> annotationTreeItem.getDetail(), new HtmlRenderer()).setCaption("Annotation").setWidth(200).setSortable(false);
    annotationDetailsTree.addColumn(annotationTreeItem -> annotationTreeItem.getTag()).setCaption("Tag").setSortable(false).setWidth(80);
    annotationDetailsTree.addColumn(annotationTreeItem -> annotationTreeItem.getAuthor()).setCaption("Author").setSortable(false).setWidth(60);
    annotationDetailsTree.addColumn(annotationTreeItem -> annotationTreeItem.getCollection()).setCaption("Collection").setSortable(false).setWidth(60);
    annotationDetailsTree.addColumn(annotationTreeItem -> annotationTreeItem.getTagset()).setCaption("Tagset").setSortable(false).setWidth(70);
    annotationDetailsTree.addColumn(annotationTreeItem -> annotationTreeItem.getAnnotationId()).setCaption("Annotation ID").setHidable(true).setHidden(true).setSortable(false).setWidth(100);
    ButtonRenderer<AnnotationTreeItem> editAnnotationRenderer = new ButtonRenderer<AnnotationTreeItem>(clickEvent -> handleEditAnnotationRequest(clickEvent));
    editAnnotationRenderer.setHtmlContentAllowed(true);
    annotationDetailsTree.addColumn(annotationTreeItem -> annotationTreeItem.getEditIcon(), editAnnotationRenderer).setWidth(50);
    ButtonRenderer<AnnotationTreeItem> deleteAnnotationRenderer = new ButtonRenderer<AnnotationTreeItem>(clickEvent -> handleDeleteAnnotationRequest(clickEvent));
    deleteAnnotationRenderer.setHtmlContentAllowed(true);
    annotationDetailsTree.addColumn(annotationTreeItem -> annotationTreeItem.getDeleteIcon(), deleteAnnotationRenderer).setExpandRatio(1);
    annotationDetailsTree.setDescriptionGenerator(new DescriptionGenerator<AnnotationTreeItem>() {

        @Override
        public String apply(AnnotationTreeItem annotationTreeItem) {
            return annotationTreeItem.getDescription();
        }
    }, ContentMode.HTML);
    ActionGridComponent<TreeGrid<AnnotationTreeItem>> annotationDetailsGridComponent = new ActionGridComponent<>(new Label("Selected Annotations"), annotationDetailsTree);
    annotationDetailsGridComponent.setMargin(false);
    addComponent(annotationDetailsGridComponent);
    setExpandRatio(annotationDetailsGridComponent, 1.0f);
}
Also used : SelectionEvent(com.vaadin.event.selection.SelectionEvent) Alignment(com.vaadin.ui.Alignment) UI(com.vaadin.ui.UI) ConfirmDialog(org.vaadin.dialogs.ConfirmDialog) KwicProvider(de.catma.indexer.KwicProvider) ErrorHandler(de.catma.ui.module.main.ErrorHandler) TreeDataProvider(com.vaadin.data.provider.TreeDataProvider) VaadinIcons(com.vaadin.icons.VaadinIcons) Objects(com.google.common.base.Objects) IconButton(de.catma.ui.component.IconButton) Collection(java.util.Collection) Set(java.util.Set) TagInstance(de.catma.tag.TagInstance) TreeGrid(com.vaadin.ui.TreeGrid) Collectors(java.util.stream.Collectors) 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) RBACPermission(de.catma.rbac.RBACPermission) PropertyDefinition(de.catma.tag.PropertyDefinition) ClickListener(com.vaadin.ui.Button.ClickListener) DescriptionGenerator(com.vaadin.ui.DescriptionGenerator) VerticalLayout(com.vaadin.ui.VerticalLayout) AnnotationCollectionManager(de.catma.document.annotation.AnnotationCollectionManager) ActionGridComponent(de.catma.ui.component.actiongrid.ActionGridComponent) Function(java.util.function.Function) ArrayList(java.util.ArrayList) Registration(com.vaadin.shared.Registration) Notification(com.vaadin.ui.Notification) Label(com.vaadin.ui.Label) TreeGridFactory(de.catma.ui.component.TreeGridFactory) ButtonRenderer(com.vaadin.ui.renderers.ButtonRenderer) SaveCancelListener(de.catma.ui.dialog.SaveCancelListener) PropertyChangeEvent(java.beans.PropertyChangeEvent) ContentMode(com.vaadin.shared.ui.ContentMode) Property(de.catma.tag.Property) TreeData(com.vaadin.data.TreeData) Project(de.catma.project.Project) RepositoryChangeEvent(de.catma.project.Project.RepositoryChangeEvent) IOException(java.io.IOException) SourceDocument(de.catma.document.source.SourceDocument) Annotation(de.catma.document.annotation.Annotation) Consumer(java.util.function.Consumer) TagManagerEvent(de.catma.tag.TagManager.TagManagerEvent) Button(com.vaadin.ui.Button) HorizontalLayout(com.vaadin.ui.HorizontalLayout) ScrollDestination(com.vaadin.shared.ui.grid.ScrollDestination) HtmlRenderer(com.vaadin.ui.renderers.HtmlRenderer) Label(com.vaadin.ui.Label) HorizontalLayout(com.vaadin.ui.HorizontalLayout) IconButton(de.catma.ui.component.IconButton) TreeGrid(com.vaadin.ui.TreeGrid) HtmlRenderer(com.vaadin.ui.renderers.HtmlRenderer) ActionGridComponent(de.catma.ui.component.actiongrid.ActionGridComponent) ButtonRenderer(com.vaadin.ui.renderers.ButtonRenderer)

Example 5 with Annotation

use of de.catma.document.annotation.Annotation in project catma by forTEXT.

the class AnnotationDetailsPanel method handleEditAnnotationRequest.

private void handleEditAnnotationRequest(RendererClickEvent<AnnotationTreeItem> clickEvent) {
    AnnotationDataItem item = (AnnotationDataItem) clickEvent.getItem();
    final Annotation annotation = item.getAnnotation();
    if (project.hasPermission(project.getRoleForCollection(annotation.getUserMarkupCollection().getUuid()), RBACPermission.COLLECTION_WRITE)) {
        String tagId = annotation.getTagInstance().getTagDefinitionId();
        TagDefinition tag = project.getTagManager().getTagLibrary().getTagDefinition(tagId);
        if (tag.getUserDefinedPropertyDefinitions().isEmpty()) {
            Notification.show("Info", "There are no Properties defined for the Tag of this Annotation!", Type.HUMANIZED_MESSAGE);
        } else {
            EditAnnotationPropertiesDialog editAnnotationPropertiesDialog = new EditAnnotationPropertiesDialog(project, annotation, new SaveCancelListener<List<Property>>() {

                @Override
                public void savePressed(List<Property> result) {
                    try {
                        collectionManager.updateProperty(annotation.getUserMarkupCollection(), annotation.getTagInstance(), result);
                    } catch (IOException e) {
                        ((ErrorHandler) UI.getCurrent()).showAndLogError("error updating Annotation Properties", e);
                    }
                }
            });
            editAnnotationPropertiesDialog.show();
        }
    } else {
        Notification.show("Info", "You do not have the permission to make changes to the Collection of this Annotation, " + "please contact the Project maintainer!", Type.HUMANIZED_MESSAGE);
    }
}
Also used : TagDefinition(de.catma.tag.TagDefinition) ErrorHandler(de.catma.ui.module.main.ErrorHandler) List(java.util.List) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Property(de.catma.tag.Property) Annotation(de.catma.document.annotation.Annotation)

Aggregations

Annotation (de.catma.document.annotation.Annotation)6 TagDefinition (de.catma.tag.TagDefinition)5 ArrayList (java.util.ArrayList)5 List (java.util.List)5 Property (de.catma.tag.Property)4 ErrorHandler (de.catma.ui.module.main.ErrorHandler)4 IOException (java.io.IOException)4 TreeData (com.vaadin.data.TreeData)3 TreeDataProvider (com.vaadin.data.provider.TreeDataProvider)3 VaadinIcons (com.vaadin.icons.VaadinIcons)3 Alignment (com.vaadin.ui.Alignment)3 Button (com.vaadin.ui.Button)3 HorizontalLayout (com.vaadin.ui.HorizontalLayout)3 Label (com.vaadin.ui.Label)3 Notification (com.vaadin.ui.Notification)3 Type (com.vaadin.ui.Notification.Type)3 TreeGrid (com.vaadin.ui.TreeGrid)3 UI (com.vaadin.ui.UI)3 VerticalLayout (com.vaadin.ui.VerticalLayout)3 ButtonRenderer (com.vaadin.ui.renderers.ButtonRenderer)3