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);
}
}
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);
}
}
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);
}
}
Aggregations