Search in sources :

Example 1 with ResourceSelectionListener

use of de.catma.ui.module.annotate.resourcepanel.ResourceSelectionListener in project catma by forTEXT.

the class TaggerView method initActions.

private void initActions() {
    btClearSearchHighlights.addClickListener(new ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            tagger.removeHighlights();
        }
    });
    cbTraceSelection.addClickListener(clickEvent -> {
        boolean traceSelection = (boolean) cbTraceSelection.getData();
        traceSelection = !traceSelection;
        cbTraceSelection.setData(traceSelection);
        tagger.setTraceSelection(traceSelection);
        if (traceSelection) {
            cbTraceSelection.addStyleName("tagger-trace-checkbox-selected");
        } else {
            cbTraceSelection.removeStyleName("tagger-trace-checkbox-selected");
        }
    });
    cbAutoShowComments.addClickListener(clickEvent -> {
        boolean autoShowComments = (boolean) cbAutoShowComments.getData();
        autoShowComments = !autoShowComments;
        cbAutoShowComments.setData(autoShowComments);
        if (autoShowComments) {
            cbAutoShowComments.setIcon(VaadinIcons.COMMENT);
            try {
                TaggerView.this.comments.clear();
                TaggerView.this.comments.addAll(TaggerView.this.project.getComments(sourceDocument.getUuid()));
                tagger.updateComments(comments);
            } catch (IOException e) {
                logger.log(Level.SEVERE, "unable to reload comments", e);
            }
        } else {
            cbAutoShowComments.setIcon(VaadinIcons.COMMENT_O);
        }
    });
    btAnalyze.addClickListener(new ClickListener() {

        public void buttonClick(ClickEvent event) {
            analyzeDocument();
        }
    });
    linesPerPageSlider.addValueChangeListener(new ValueChangeListener<Double>() {

        public void valueChange(ValueChangeEvent<Double> event) {
            Double perCentValue = (Double) linesPerPageSlider.getValue();
            int lines = (int) ((totalLineCount / 100.0) * perCentValue);
            List<ClientTagInstance> absoluteTagInstances = pager.getAbsoluteTagInstances();
            Page currentPage = null;
            if (pager.hasPages()) {
                currentPage = pager.getCurrentPage();
            }
            pager.setMaxPageLengthInLines(lines);
            if (pager.hasPages()) {
                // recalculate pages
                try {
                    pager.setText(sourceDocument.getContent(), comments);
                    int previousPageNumber = pager.getPageNumberFor(currentPage.getPageStart());
                    tagger.setPage(previousPageNumber);
                    tagger.setTagInstancesVisible(absoluteTagInstances, true);
                    pagerComponent.setPage(previousPageNumber);
                } catch (IOException e) {
                    errorHandler.showAndLogError("Error showing the Document!", e);
                }
            }
        }
    });
    resourcePanel.setSelectionListener(new ResourceSelectionListener() {

        @Override
        public void resourcesChanged() {
            AnnotationCollection selectedEditableCollection = annotationPanel.getSelectedEditableCollection();
            List<AnnotationCollectionReference> selectedAnnotationCollectionRefs = resourcePanel.getSelectedAnnotationCollectionReferences();
            for (AnnotationCollection collection : userMarkupCollectionManager.getUserMarkupCollections()) {
                userMarkupCollectionManager.remove(collection.getId());
                annotationPanel.removeCollection(collection.getId());
                tagger.setVisible(collection.getTagReferences(), false);
            }
            userMarkupCollectionManager.clear();
            for (AnnotationCollectionReference collectionReference : selectedAnnotationCollectionRefs) {
                try {
                    AnnotationCollection collection = project.getUserMarkupCollection(collectionReference);
                    setAnnotationCollectionSelected(new AnnotationCollectionReference(collection), true);
                } catch (IOException e) {
                    ((ErrorHandler) UI.getCurrent()).showAndLogError("error refreshing Annotation Collection!", e);
                }
            }
            if ((selectedEditableCollection != null) && (userMarkupCollectionManager.contains(selectedEditableCollection.getId()))) {
                annotationPanel.setSelectedEditableCollection(userMarkupCollectionManager.getUserMarkupCollection(selectedEditableCollection.getId()));
            }
            annotationPanel.clearTagsets();
            tagsetsSelected(resourcePanel.getSelectedTagsets());
        }

        @Override
        public void documentSelected(SourceDocument sourceDocument) {
            setSourceDocument(sourceDocument, null);
        }

        @Override
        public void annotationCollectionSelected(AnnotationCollectionReference collectionReference, boolean selected) {
            setAnnotationCollectionSelected(collectionReference, selected);
        }

        @Override
        public void tagsetsSelected(Collection<TagsetDefinition> tagsets) {
            try {
                annotationPanel.setTagsets(tagsets);
                if (taggerContextMenu != null) {
                    taggerContextMenu.setTagsets(tagsets);
                }
                for (AnnotationCollection collection : userMarkupCollectionManager.getUserMarkupCollections()) {
                    tagger.setVisible(collection.getTagReferences(), false);
                    List<TagReference> visibleRefs = annotationPanel.getVisibleTagReferences(collection.getTagReferences());
                    if (!visibleRefs.isEmpty()) {
                        tagger.setVisible(visibleRefs, true);
                    }
                }
            } catch (Exception e) {
                errorHandler.showAndLogError("Error handling Tagset!", e);
            }
        }
    });
    annotationPanel.setTagReferenceSelectionChangeListener((tagReferences, selected) -> {
        if (!tagReferences.isEmpty()) {
            tagger.setVisible(tagReferences, selected);
        }
    });
    kwicPanel.setExpansionListener(new ExpansionListener() {

        @Override
        public void expand() {
            // we hide on expand and on compress since both is considered a "close"
            hideKwicPanel();
        }

        @Override
        public void compress() {
            // we hide on expand and on compress since both is considered a "close"
            hideKwicPanel();
        }
    });
    kwicPanel.addItemClickListener(itemClick -> {
        if (itemClick.getMouseEventDetails().isDoubleClick()) {
            show(itemClick.getItem().getRange());
        }
    });
}
Also used : ErrorHandler(de.catma.ui.module.main.ErrorHandler) AnnotationCollection(de.catma.document.annotation.AnnotationCollection) ClickEvent(com.vaadin.ui.Button.ClickEvent) SourceDocument(de.catma.document.source.SourceDocument) AnnotationCollectionReference(de.catma.document.annotation.AnnotationCollectionReference) Page(de.catma.ui.module.annotate.pager.Page) IOException(java.io.IOException) ValueOutOfBoundsException(com.vaadin.ui.Slider.ValueOutOfBoundsException) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) TagsetDefinition(de.catma.tag.TagsetDefinition) ResourceSelectionListener(de.catma.ui.module.annotate.resourcepanel.ResourceSelectionListener) ArrayList(java.util.ArrayList) List(java.util.List) ExpansionListener(de.catma.ui.module.analyze.visualization.ExpansionListener) ClickListener(com.vaadin.ui.Button.ClickListener)

Aggregations

ClickEvent (com.vaadin.ui.Button.ClickEvent)1 ClickListener (com.vaadin.ui.Button.ClickListener)1 ValueOutOfBoundsException (com.vaadin.ui.Slider.ValueOutOfBoundsException)1 AnnotationCollection (de.catma.document.annotation.AnnotationCollection)1 AnnotationCollectionReference (de.catma.document.annotation.AnnotationCollectionReference)1 SourceDocument (de.catma.document.source.SourceDocument)1 TagsetDefinition (de.catma.tag.TagsetDefinition)1 ExpansionListener (de.catma.ui.module.analyze.visualization.ExpansionListener)1 Page (de.catma.ui.module.annotate.pager.Page)1 ResourceSelectionListener (de.catma.ui.module.annotate.resourcepanel.ResourceSelectionListener)1 ErrorHandler (de.catma.ui.module.main.ErrorHandler)1 IOException (java.io.IOException)1 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1