use of de.catma.ui.CatmaApplication in project catma by forTEXT.
the class ProjectView method importCollection.
private void importCollection() {
Set<SourceDocument> selectedDocuments = getSelectedDocuments();
if (selectedDocuments.size() != 1) {
Notification.show("Info", "Please select the corresponding Document first!", Type.HUMANIZED_MESSAGE);
} else {
final SourceDocument document = selectedDocuments.iterator().next();
GenericUploadDialog uploadDialog = new GenericUploadDialog(String.format("Upload a Collection for %1$s:", document.toString()), new SaveCancelListener<byte[]>() {
public void savePressed(byte[] result) {
InputStream is = new ByteArrayInputStream(result);
try {
if (BOMFilterInputStream.hasBOM(result)) {
is = new BOMFilterInputStream(is, // $NON-NLS-1$
Charset.forName("UTF-8"));
}
Pair<AnnotationCollection, List<TagsetDefinitionImportStatus>> loadResult = project.loadAnnotationCollection(is, document);
List<TagsetDefinitionImportStatus> tagsetDefinitionImportStatusList = loadResult.getSecond();
final AnnotationCollection annotationCollection = loadResult.getFirst();
CollectionImportDialog tagsetImportDialog = new CollectionImportDialog(tagsetDefinitionImportStatusList, new SaveCancelListener<List<TagsetDefinitionImportStatus>>() {
@Override
public void savePressed(List<TagsetDefinitionImportStatus> result) {
try {
project.importCollection(result, annotationCollection);
} catch (IOException e) {
((CatmaApplication) UI.getCurrent()).showAndLogError("Error importing Tagsets", e);
}
}
});
tagsetImportDialog.show();
} catch (IOException e) {
((CatmaApplication) UI.getCurrent()).showAndLogError("Error loading external Tagsets", e);
} finally {
CloseSafe.close(is);
}
}
});
uploadDialog.show();
}
}
use of de.catma.ui.CatmaApplication in project catma by forTEXT.
the class ProjectView method importCorpus.
private void importCorpus(final File corpusFile, final List<CorpusImportDocumentMetadata> documentMetadataList) {
setEnabled(false);
setProgressBarVisible(true);
try {
final String tempDir = ((CatmaApplication) UI.getCurrent()).accquirePersonalTempFolder();
final UI ui = UI.getCurrent();
BackgroundServiceProvider backgroundServiceProvider = (BackgroundServiceProvider) UI.getCurrent();
BackgroundService backgroundService = backgroundServiceProvider.accuireBackgroundService();
backgroundService.submit(new DefaultProgressCallable<Void>() {
@Override
public Void call() throws Exception {
return new CorpusImporter().importCorpus(getProgressListener(), corpusFile, documentMetadataList, tempDir, ui, project);
}
}, new ExecutionListener<Void>() {
@Override
public void done(Void result) {
setProgressBarVisible(false);
setEnabled(true);
}
@Override
public void error(Throwable t) {
setProgressBarVisible(false);
setEnabled(true);
Logger.getLogger(ProjectView.class.getName()).log(Level.SEVERE, "Error importing the CATMA 5 Corpus!", t);
String errorMsg = t.getMessage();
if ((errorMsg == null) || (errorMsg.trim().isEmpty())) {
errorMsg = "";
}
Notification.show("Error", String.format("Error importing the CATMA 5 Corpus! " + "This import will be aborted!\n The underlying error message was:\n%1$s", errorMsg), Type.ERROR_MESSAGE);
}
}, progressListener);
} catch (Exception e) {
setProgressBarVisible(false);
setEnabled(true);
Logger.getLogger(ProjectView.class.getName()).log(Level.SEVERE, "Error importing the CATMA 5 Corpus!", e);
String errorMsg = e.getMessage();
if ((errorMsg == null) || (errorMsg.trim().isEmpty())) {
errorMsg = "";
}
Notification.show("Error", String.format("Error importing the CATMA 5 Corpus! " + "This import will be aborted!\n The underlying error message was:\n%1$s", errorMsg), Type.ERROR_MESSAGE);
}
}
use of de.catma.ui.CatmaApplication in project catma by forTEXT.
the class UploadStep method initComponents.
private void initComponents() {
HorizontalLayout uploadPanel = new HorizontalLayout();
uploadPanel.setWidth("100%");
uploadPanel.setSpacing(true);
uploadPanel.setMargin(false);
addComponent(uploadPanel);
UploadStateWindow uploadStateWindow = new UploadStateWindow();
uploadStateWindow.setModal(true);
uploadStateWindow.setWindowPosition(WindowPosition.CENTER);
upload = new MultiFileUpload(new UploadFinishedHandler() {
@Override
public void handleFile(InputStream stream, String fileName, String mimeType, long length, int filesLeftInQueue) {
try {
String tempDir = ((CatmaApplication) UI.getCurrent()).accquirePersonalTempFolder();
final String fileId = idGenerator.generateDocumentId();
File tempFile = new File(new File(tempDir), fileId);
if (tempFile.exists()) {
tempFile.delete();
}
try (FileOutputStream fos = new FileOutputStream(tempFile)) {
IOUtils.copy(stream, fos);
}
try (FileInputStream fis = new FileInputStream(tempFile)) {
String type = tika.detect(fis, fileName);
UploadFile uploadFile = new UploadFile(fileId, tempFile.toURI(), fileName, type, length);
if (type.toLowerCase().trim().equals(FileType.ZIP.getMimeType())) {
handleZipFile(uploadFile);
} else {
fileList.add(uploadFile);
fileDataProvider.refreshAll();
stepChangeListener.stepChanged(UploadStep.this);
}
}
} catch (Exception e) {
String errorMsg = e.getMessage();
if ((errorMsg == null) || (errorMsg.trim().isEmpty())) {
errorMsg = "";
}
Notification.show("Error", String.format("Error uploading %1$s, file will be skipped!\n%2$s", fileName, errorMsg), Type.ERROR_MESSAGE);
}
}
}, uploadStateWindow) {
@Override
protected UploadStatePanel createStatePanel(UploadStateWindow uploadStateWindow) {
return new MyUploadStatePanel(uploadStateWindow);
}
};
uploadPanel.addComponent(upload);
// 100 MB
int maxFileSize = 104857600;
upload.setMaxFileSize(maxFileSize);
String errorMsgPattern = "File is too big (max = {0}): {2} ({1})";
upload.setSizeErrorMsgPattern(errorMsgPattern);
upload.setCaption("Upload files from your local computer");
upload.setPanelCaption("Uploading file");
upload.setMaxFileCount(300);
upload.getSmartUpload().setUploadButtonCaptions("", "");
upload.getSmartUpload().setUploadButtonIcon(VaadinIcons.UPLOAD);
urlInputField = new TextField("or add a URL");
urlInputField.setValueChangeMode(ValueChangeMode.BLUR);
urlInputField.setWidth("100%");
uploadPanel.addComponent(urlInputField);
btFetch = new Button(VaadinIcons.CLOUD_DOWNLOAD);
uploadPanel.addComponent(btFetch);
uploadPanel.setComponentAlignment(btFetch, Alignment.BOTTOM_LEFT);
progressBar = new ProgressBar();
progressBar.setVisible(false);
uploadPanel.addComponent(progressBar);
fileGrid = new Grid<UploadFile>("or drag and drop some files to the list", fileDataProvider);
fileGrid.setSizeFull();
fileGrid.addColumn(UploadFile::getOriginalFilename).setCaption("File");
fileGrid.addColumn(UploadFile::getMimetype).setCaption("Type");
addComponent(fileGrid);
setExpandRatio(fileGrid, 1.0f);
}
use of de.catma.ui.CatmaApplication in project catma by forTEXT.
the class TaggerView method addCommentMessageListener.
private void addCommentMessageListener() {
try {
removeCommentMessageListener();
if (this.sourceDocument != null) {
HazelCastService hazelcastService = ((CatmaApplication) UI.getCurrent()).getHazelCastService();
this.commentTopic = hazelcastService.getHazelcastClient().getTopic(HazelcastConfiguration.TopicName.COMMENT + "_" + this.sourceDocument.getUuid());
this.commentMessageListenerRegId = this.commentTopic.addMessageListener(this.commentMessageListener);
}
} catch (Exception e) {
logger.log(Level.WARNING, "error registering for comment messages", e);
}
}
Aggregations