0

基本上我一直在使用 Vaadin Designer 来设计我的 UI。我的一个用例要求我上传 iCalendar 文件,我使用语法 (ANTLR) 从中获取我需要的内容。在看到 Vaadin Upload 文档并在运行它时将其应用于我的用例后,我遇到了我的问题,什么都不会发生,也不会引发异常。经过一番研究和调试,我相信这是由于上传的线程由于某种原因被关闭。

这是我的代码,有帮助吗?

private void uploadLogic() {

    class IcalendarUploader implements Upload.Receiver, Upload.SucceededListener, Upload.FinishedListener, Upload.FailedListener {

        @Override
        public OutputStream receiveUpload(String filename, String mimeType) {

            try {
                //We'll store the uploadad file as temporary file.
                tempFile = File.createTempFile("temp", ".ics");
                fos =  new FileOutputStream(tempFile);
            } catch (IOException e) {
                Notification.show(e.getMessage(), Notification.Type.WARNING_MESSAGE);
                return null;
            }


        }

        @Override
        public void uploadFinished(Upload.FinishedEvent event) {

            try {
                controller.importIcalendar(tempFile);
                tempFile.delete();

                Notification.show("Uploaded iCalendar file with :\n" + controller.iCalendarDetails(),
                        Notification.Type.HUMANIZED_MESSAGE);

            } catch (IOException e) {

                Notification.show(e.getMessage(), Notification.Type.WARNING_MESSAGE);
            }

        }

        @Override
        public void uploadSucceeded(Upload.SucceededEvent event) {

            try {
                if(controller.saveTimeSlot()){
                    Notification.show("Uploaded iCalendar file with :\n" + controller.iCalendarDetails()
                                    +"\nSaved time slot with success",
                            Notification.Type.HUMANIZED_MESSAGE);
                }else {
                    Notification.show("Uploaded iCalendar file with :\n" + controller.iCalendarDetails()
                                    + "\nTime slot has an overlapp!",
                            Notification.Type.WARNING_MESSAGE);
                }
            } catch (DataConcurrencyException e) {
                Notification.show(e.getMessage(), Notification.Type.WARNING_MESSAGE);
            } catch (DataIntegrityViolationException e) {
                Notification.show(e.getMessage(), Notification.Type.WARNING_MESSAGE);
            }


        }

        @Override
        public void uploadFailed(Upload.FailedEvent event) {

            Notification.show("Upload failed", Notification.Type.ERROR_MESSAGE);
        }
    }

    IcalendarUploader receiver = new IcalendarUploader();
    upload.setReceiver(receiver);
}
4

0 回答 0