use of de.catma.ui.module.main.ErrorHandler in project catma by forTEXT.
the class AnalyzeResourcePanel method initData.
private void initData() {
documentData = new TreeData<>();
try {
Collection<SourceDocument> documents = project.getSourceDocuments();
documentData.addRootItems(documents.stream().map(document -> new DocumentDataItem(document)));
for (DocumentTreeItem documentDataItem : documentData.getRootItems()) {
for (AnnotationCollectionReference umcRef : ((DocumentDataItem) documentDataItem).getDocument().getUserMarkupCollectionRefs()) {
documentData.addItem(documentDataItem, new CollectionDataItem(umcRef, project.hasPermission(project.getRoleForCollection(umcRef.getId()), RBACPermission.COLLECTION_WRITE)));
}
}
documentTree.setDataProvider(new TreeDataProvider<>(documentData));
Collection<SourceDocument> selectedDocuments = corpus.getSourceDocuments();
Collection<AnnotationCollectionReference> selectedCollections = corpus.getUserMarkupCollectionRefs();
documentData.getRootItems().stream().filter(documentItem -> selectedDocuments.contains(((DocumentDataItem) documentItem).getDocument())).forEach(documentTree::select);
for (DocumentTreeItem documentDataItem : documentData.getRootItems()) {
List<DocumentTreeItem> collectionItems = documentData.getChildren(documentDataItem);
for (DocumentTreeItem oneCollection : collectionItems) {
if (selectedCollections.contains(((CollectionDataItem) oneCollection).getCollectionRef())) {
documentTree.getSelectionModel().select(oneCollection);
}
}
}
documentTree.expand(documentData.getRootItems());
} catch (Exception e) {
((ErrorHandler) UI.getCurrent()).showAndLogError("error loading Project data", e);
}
}
use of de.catma.ui.module.main.ErrorHandler in project catma by forTEXT.
the class InspectContentStep method enter.
@Override
public void enter(boolean back) {
if (back) {
return;
}
@SuppressWarnings("unchecked") Collection<UploadFile> fileList = (Collection<UploadFile>) wizardContext.get(DocumentWizard.WizardContextKey.UPLOAD_FILE_LIST);
contentPanel.setEnabled(false);
progressBar.setVisible(true);
progressBar.setIndeterminate(true);
final ArrayList<UploadFile> files = new ArrayList<UploadFile>(fileList);
BackgroundServiceProvider backgroundServiceProvider = (BackgroundServiceProvider) UI.getCurrent();
backgroundServiceProvider.submit("inspecting-files", new DefaultProgressCallable<List<UploadFile>>() {
@Override
public List<UploadFile> call() throws Exception {
Tika tika = new Tika();
LanguageDetector languageDetector = LanguageDetector.getDefaultLanguageDetector();
try {
languageDetector.loadModels();
} catch (IOException e) {
((ErrorHandler) UI.getCurrent()).showAndLogError("Error loading language detection models!", e);
}
for (UploadFile uploadFile : files) {
if (uploadFile.getMimetype().equals(FileType.XML2.getMimeType())) {
XML2ContentHandler contentHandler = new XML2ContentHandler();
SourceDocumentInfo sourceDocumentInfo = new SourceDocumentInfo();
TechInfoSet techInfoSet = new TechInfoSet(uploadFile.getOriginalFilename(), uploadFile.getMimetype(), uploadFile.getTempFilename());
sourceDocumentInfo.setTechInfoSet(techInfoSet);
contentHandler.setSourceDocumentInfo(sourceDocumentInfo);
contentHandler.load();
String content = contentHandler.getContent();
LanguageResult languageResult = languageDetector.detect(content);
if (languageResult.isReasonablyCertain() && languageResult.getLanguage() != null) {
uploadFile.setLanguage(new LanguageItem(new Locale(languageResult.getLanguage())));
}
} else {
Metadata metadata = new Metadata();
try {
try (FileInputStream fis = new FileInputStream(new File(uploadFile.getTempFilename()))) {
String content = tika.parseToString(fis, metadata);
String contentType = metadata.get(Metadata.CONTENT_TYPE);
MediaType mediaType = MediaType.parse(contentType);
String charset = mediaType.getParameters().get("charset");
if (charset != null) {
uploadFile.setCharset(Charset.forName(charset));
}
LanguageResult languageResult = languageDetector.detect(content);
if (languageResult.isReasonablyCertain() && languageResult.getLanguage() != null) {
uploadFile.setLanguage(new LanguageItem(new Locale(languageResult.getLanguage())));
}
}
} catch (Exception e) {
Logger.getLogger(InspectContentStep.class.getName()).log(Level.SEVERE, String.format("Error inspecting %1$s", uploadFile.getOriginalFilename()), e);
String errorMsg = e.getMessage();
if ((errorMsg == null) || (errorMsg.trim().isEmpty())) {
errorMsg = "";
}
Notification.show("Error", String.format("Error inspecting content of %1$s! " + "Adding this file to your Project might fail!\n The underlying error message was:\n%2$s", uploadFile.getOriginalFilename(), errorMsg), Type.ERROR_MESSAGE);
}
}
}
return files;
}
}, new ExecutionListener<List<UploadFile>>() {
@Override
public void done(List<UploadFile> result) {
contentPanel.setEnabled(true);
progressBar.setVisible(false);
progressBar.setIndeterminate(false);
fileList.clear();
fileList.addAll(result);
fileDataProvider.refreshAll();
if (!fileList.isEmpty()) {
fileList.stream().findFirst().ifPresent(uploadFile -> {
fileGrid.select(uploadFile);
updatePreview(uploadFile);
});
}
if (stepChangeListener != null) {
stepChangeListener.stepChanged(InspectContentStep.this);
}
}
@Override
public void error(Throwable t) {
Logger.getLogger(InspectContentStep.class.getName()).log(Level.SEVERE, "Error inspecting files", t);
String errorMsg = t.getMessage();
if ((errorMsg == null) || (errorMsg.trim().isEmpty())) {
errorMsg = "";
}
Notification.show("Error", String.format("Error inspecting the contents! " + "\n The underlying error message was:\n%1$s", errorMsg), Type.ERROR_MESSAGE);
}
});
}
use of de.catma.ui.module.main.ErrorHandler in project catma by forTEXT.
the class ForkHandler method fork.
public void fork() {
BackgroundServiceProvider backgroundServiceProvider = (BackgroundServiceProvider) ui;
BackgroundService backgroundService = backgroundServiceProvider.accuireBackgroundService();
backgroundService.submit(new DefaultProgressCallable<Void>() {
@Override
public Void call() throws Exception {
final AtomicBoolean cancel = new AtomicBoolean(false);
for (TagsetDefinition tagset : tagsets) {
getProgressListener().setProgress("Forking Tagset %1$s into Project %2$s", tagset.getName(), targetProject.getName());
ui.accessSynchronously(() -> {
try {
ForkStatus forkStatus = projectManager.forkTagset(tagset, projectId, targetProject);
if (forkStatus.isResourceAlreadyExists()) {
Notification.show("Info", String.format("The Tagset %1$s is already present in the target Project and cannot be forked!", tagset.getName()), Type.ERROR_MESSAGE);
} else if (forkStatus.isTargetHasConflicts()) {
Notification.show("Info", String.format("The target Project %1$s has conflicts, please open the Project and resolve the conflicts first!", targetProject.getName()), Type.ERROR_MESSAGE);
cancel.set(true);
} else if (forkStatus.isTargetNotClean()) {
Notification.show("Info", String.format("The target Project %1$s has uncommited changes, please open the Project and commit all changes first!", targetProject.getName()), Type.ERROR_MESSAGE);
cancel.set(true);
}
} catch (Exception e) {
((ErrorHandler) UI.getCurrent()).showAndLogError("Error forking Tagsets", e);
cancel.set(true);
}
});
if (cancel.get()) {
return null;
}
}
return null;
}
}, executionListener, progressListener);
}
use of de.catma.ui.module.main.ErrorHandler in project catma by forTEXT.
the class AnalyzeView method executeSearch.
private void executeSearch(String searchInput, Consumer<QueryResultPanel> addToLayoutFunction) {
QueryOptions queryOptions = new QueryOptions(new QueryId(searchInput), currentCorpus.getDocumentIds(), currentCorpus.getCollectionIds(), indexInfoSet.getUnseparableCharacterSequences(), indexInfoSet.getUserDefinedSeparatingCharacters(), indexInfoSet.getLocale(), project);
QueryJob job = new QueryJob(searchInput, queryOptions);
showProgress(true);
((BackgroundServiceProvider) UI.getCurrent()).submit("Searching...", job, new ExecutionListener<QueryResult>() {
public void done(QueryResult result) {
try {
QueryResultPanel queryResultPanel = new QueryResultPanel(project, result, new QueryId(searchInput.toString()), kwicProviderCache, closingPanel -> handleRemoveQueryResultPanel(closingPanel));
addToLayoutFunction.accept(queryResultPanel);
addQueryResultPanelSetting(queryResultPanel.getQueryResultPanelSetting());
} finally {
showProgress(false);
}
}
public void error(Throwable t) {
showProgress(false);
if (t instanceof QueryException) {
QueryJob.QueryException qe = (QueryJob.QueryException) t;
String input = qe.getInput();
int idx = ((RecognitionException) qe.getCause()).charPositionInLine;
if ((idx >= 0) && (input.length() > idx)) {
char character = input.charAt(idx);
String message = MessageFormat.format("<html><p>There is something wrong with your query <b>{0}</b> approximately at positon {1} character <b>{2}</b>.</p> <p>If you are unsure about how to construct a query try the Query Builder!</p></html>", input, idx + 1, character);
HTMLNotification.show("Info", message, Type.TRAY_NOTIFICATION);
} else {
String message = MessageFormat.format("<html><p>There is something wrong with your query <b>{0}</b>.</p> <p>If you are unsure about how to construct a query try the Query Builder!</p></html>", input);
HTMLNotification.show("Info", message, Type.TRAY_NOTIFICATION);
}
} else {
((ErrorHandler) UI.getCurrent()).showAndLogError("Error during search!", t);
}
}
});
}
use of de.catma.ui.module.main.ErrorHandler 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);
}
Aggregations