use of de.catma.ui.module.main.ErrorHandler in project catma by forTEXT.
the class TagsetCSVExportStreamSource method getStream.
@Override
public InputStream getStream() {
final UI ui = UI.getCurrent();
Set<TagsetDefinition> tagsets = tagsetsSupplier.get();
Project project = projectSupplier.get();
if (tagsets != null && !tagsets.isEmpty()) {
try {
File tempFile = File.createTempFile(new IDGenerator().generate() + "_TagLibrary_Export", "xml");
try (OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(tempFile))) {
try (CSVPrinter csvPrinter = new CSVPrinter(writer, CSVFormat.EXCEL.withDelimiter(';'))) {
csvPrinter.print("Tagset");
csvPrinter.print("Tagset ID");
csvPrinter.print("Tag");
csvPrinter.print("Tag ID");
csvPrinter.print("Tag Path");
csvPrinter.print("Tag Parent ID");
csvPrinter.print("Tag Color");
csvPrinter.print("Tag Author");
csvPrinter.print("Project Name");
csvPrinter.print("Project ID");
csvPrinter.print("Tag Properties & Values & Property ID");
csvPrinter.println();
for (TagsetDefinition tagset : tagsets) {
Collection<TagDefinition> sortedTags = tagset.stream().sorted((t1, t2) -> {
if (t1.getName().equals(t2.getName())) {
return t1.getUuid().compareTo(t2.getUuid());
}
return t1.getName().compareTo(t2.getName());
}).collect(Collectors.toList());
for (TagDefinition tag : sortedTags) {
csvPrinter.print(tagset.getName());
csvPrinter.print(tagset.getUuid());
csvPrinter.print(tag.getName());
csvPrinter.print(tag.getUuid());
csvPrinter.print(tagset.getTagPath(tag));
csvPrinter.print(tag.getParentUuid());
csvPrinter.print("#" + ColorConverter.toHex(tag.getColor()));
csvPrinter.print(tag.getAuthor());
csvPrinter.print(project.getName());
csvPrinter.print(project.getProjectId());
ArrayList<PropertyDefinition> sortedProperties = new ArrayList<>(tag.getUserDefinedPropertyDefinitions());
Collections.sort(sortedProperties, (p1, p2) -> {
if (p1.getName().equals(p2.getName())) {
return p1.getUuid().compareTo(p2.getUuid());
}
return p1.getName().compareTo(p2.getName());
});
for (PropertyDefinition propertyDef : sortedProperties) {
csvPrinter.print(propertyDef.getName() + propertyDef.getPossibleValueList().stream().sorted().collect(Collectors.toList()) + " " + propertyDef.getUuid());
}
csvPrinter.println();
}
}
}
}
return new FileInputStream(tempFile);
} catch (Exception e) {
((ErrorHandler) ui).showAndLogError("Error exporting Tagsets to XML!", e);
}
}
return null;
}
use of de.catma.ui.module.main.ErrorHandler in project catma by forTEXT.
the class CollectionXMLExportStreamSource method getStream.
@Override
public InputStream getStream() {
final UI ui = UI.getCurrent();
final Project project = projectSupplier.get();
final Corpus corpus = new Corpus();
final Collection<SourceDocument> documents = documentSupplier.get();
final Collection<AnnotationCollectionReference> collectionReferences = collectionReferenceSupplier.get();
try {
Set<String> documentIds = documents.stream().map(doc -> doc.getUuid()).collect(Collectors.toSet());
collectionReferences.stream().forEach(ref -> documentIds.add(ref.getSourceDocumentId()));
for (String documentId : documentIds) {
corpus.addSourceDocument(project.getSourceDocument(documentId));
}
if (corpus.getSourceDocuments().size() == 0) {
return null;
}
collectionReferences.forEach(ref -> corpus.addUserMarkupCollectionReference(ref));
File tempFile = File.createTempFile(new IDGenerator().generate() + "_AnnotationCollection_Export", "tgz");
try (FileOutputStream fos = new FileOutputStream(tempFile)) {
new CorpusExporter(project, true).export(project.getName(), corpus, fos);
}
return new FileInputStream(tempFile);
} catch (Exception e) {
((ErrorHandler) ui).showAndLogError("Error exporting Documents and Collections!", e);
}
return null;
}
use of de.catma.ui.module.main.ErrorHandler 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());
}
});
}
use of de.catma.ui.module.main.ErrorHandler in project catma by forTEXT.
the class KwicPanel method handleKwicItemClick.
private void handleKwicItemClick(ItemClick<QueryResultRow> clickEvent, EventBus eventBus) {
if (clickEvent.getMouseEventDetails().isDoubleClick()) {
QueryResultRow selectedRow = clickEvent.getItem();
final String documentId = selectedRow.getSourceDocumentId();
List<QueryResultRow> documentRows = kwicDataProvider.getItems().parallelStream().filter(row -> row.getSourceDocumentId().equals(documentId)).collect(Collectors.toList());
try {
if (project.hasDocument(documentId)) {
eventBus.post(new QueryResultRowInAnnotateEvent(documentId, selectedRow, documentRows, project));
} else {
Notification.show("Info", "The corresponding Document is no longer part of the Project!", Type.WARNING_MESSAGE);
}
} catch (Exception e) {
((ErrorHandler) UI.getCurrent()).showAndLogError("error accessing project data", e);
}
}
}
use of de.catma.ui.module.main.ErrorHandler in project catma by forTEXT.
the class KwicPanel method handleAnnotateSelectedRequest.
private void handleAnnotateSelectedRequest(EventBus eventBus) {
final Set<QueryResultRow> selectedRows = kwicGrid.getSelectedItems();
if (selectedRows.isEmpty()) {
Notification.show("Info", "Please select one or more rows to annotate!", Type.HUMANIZED_MESSAGE);
return;
}
Set<String> documentIds = kwicDataProvider.getItems().stream().map(row -> row.getSourceDocumentId()).collect(Collectors.toSet());
WizardContext wizardContext = new WizardContext();
wizardContext.put(AnnotationWizardContextKey.DOCUMENTIDS, documentIds);
AnnotationWizard wizard = new AnnotationWizard(eventBus, project, wizardContext, new SaveCancelListener<WizardContext>() {
@Override
public void savePressed(WizardContext result) {
try {
annotateSelection(selectedRows, result);
} catch (Exception e) {
((ErrorHandler) UI.getCurrent()).showAndLogError("error annotating selected rows", e);
}
}
});
wizard.show();
}
Aggregations