Search in sources :

Example 1 with LSLibrary

use of net.parostroj.timetable.model.ls.LSLibrary in project grafikon by jub77.

the class LoadLibraryUrlModelAction method backgroundAction.

@Override
protected void backgroundAction() {
    url = (String) getActionContext().getAttribute("libraryUrl");
    if (url == null) {
        // skip
        return;
    }
    setWaitMessage(ResourceLoader.getString("wait.message.loadlibrary"));
    setWaitDialogVisible(true);
    long time = System.currentTimeMillis();
    try {
        try (ZipInputStream is = new ZipInputStream(new URL(url).openStream())) {
            LSLibrary ls = LSLibraryFactory.getInstance().createForLoad(is);
            context.setAttribute("library", ls.load(is));
        } catch (LSException e) {
            log.warn("Error loading model.", e);
            if (e.getCause() instanceof FileNotFoundException) {
                errorMessage = ResourceLoader.getString("dialog.error.filenotfound");
            } else {
                errorMessage = ResourceLoader.getString("dialog.error.loading");
            }
        } catch (Exception e) {
            log.warn("Error loading model.", e);
            errorMessage = ResourceLoader.getString("dialog.error.loading");
        }
    } finally {
        log.debug("Library loaded in {}ms", System.currentTimeMillis() - time);
        setWaitDialogVisible(false);
    }
}
Also used : ZipInputStream(java.util.zip.ZipInputStream) LSLibrary(net.parostroj.timetable.model.ls.LSLibrary) FileNotFoundException(java.io.FileNotFoundException) URL(java.net.URL) LSException(net.parostroj.timetable.model.ls.LSException) LSException(net.parostroj.timetable.model.ls.LSException) FileNotFoundException(java.io.FileNotFoundException)

Example 2 with LSLibrary

use of net.parostroj.timetable.model.ls.LSLibrary in project grafikon by jub77.

the class LoadLibraryModelAction method backgroundAction.

@Override
protected void backgroundAction() {
    selectedFile = (File) getActionContext().getAttribute("libraryFile");
    if (selectedFile == null) {
        // skip
        return;
    }
    setWaitMessage(ResourceLoader.getString("wait.message.loadlibrary"));
    setWaitDialogVisible(true);
    long time = System.currentTimeMillis();
    try {
        try {
            LSLibrary ls = LSLibraryFactory.getInstance().createForLoad(selectedFile);
            try (ZipInputStream stream = new ZipInputStream(new FileInputStream(selectedFile))) {
                context.setAttribute("library", ls.load(stream));
            }
        } catch (LSException e) {
            log.warn("Error loading model.", e);
            if (e.getCause() instanceof FileNotFoundException) {
                errorMessage = ResourceLoader.getString("dialog.error.filenotfound");
            } else {
                errorMessage = ResourceLoader.getString("dialog.error.loading");
            }
        } catch (Exception e) {
            log.warn("Error loading model.", e);
            errorMessage = ResourceLoader.getString("dialog.error.loading");
        }
    } finally {
        log.debug("Library loaded in {}ms", System.currentTimeMillis() - time);
        setWaitDialogVisible(false);
    }
}
Also used : ZipInputStream(java.util.zip.ZipInputStream) LSLibrary(net.parostroj.timetable.model.ls.LSLibrary) FileNotFoundException(java.io.FileNotFoundException) FileInputStream(java.io.FileInputStream) LSException(net.parostroj.timetable.model.ls.LSException) FileNotFoundException(java.io.FileNotFoundException) LSException(net.parostroj.timetable.model.ls.LSException)

Example 3 with LSLibrary

use of net.parostroj.timetable.model.ls.LSLibrary in project grafikon by jub77.

the class ModelUtils method saveLibraryData.

public static void saveLibraryData(final Library library, File file) throws LSException, IOException {
    LSLibrary ls = LSLibraryFactory.getInstance().createForSave();
    try (ZipOutputStream os = new ZipOutputStream(new FileOutputStream(file))) {
        boolean originalSkip = library.getAttributes().isSkipListeners();
        library.getAttributes().setSkipListeners(true);
        log.info("Saving: {}", file);
        ls.save(library, os);
        library.getAttributes().setSkipListeners(originalSkip);
    }
}
Also used : ZipOutputStream(java.util.zip.ZipOutputStream) LSLibrary(net.parostroj.timetable.model.ls.LSLibrary) FileOutputStream(java.io.FileOutputStream)

Aggregations

LSLibrary (net.parostroj.timetable.model.ls.LSLibrary)3 FileNotFoundException (java.io.FileNotFoundException)2 ZipInputStream (java.util.zip.ZipInputStream)2 LSException (net.parostroj.timetable.model.ls.LSException)2 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 URL (java.net.URL)1 ZipOutputStream (java.util.zip.ZipOutputStream)1