@Override public void duringSave(Void model) { List<EntityExportSource<? extends AbstractPersistentObject>> entityExportSources = PersistentWork.read( em -> { @SuppressWarnings("unchecked") List<Class<? extends AbstractPersistentObject>> entityClasses = em.getEntityManagerFactory() .getMetamodel() .getEntities() .stream() .map(e -> (Class<? extends AbstractPersistentObject>) e.getJavaType()) .collect(Collectors.toList()); List<EntityExportSource<? extends AbstractPersistentObject>> exportSources = entityClasses .stream() .map(c -> new EntityExportSource<>(PersistentWork.idsFrom(c), c)) .collect(Collectors.toList()); return exportSources; }); XlsxExporter exporter = new XlsxExporter(controller.getExecutorService()); File file = exportFile.get(); try { if (file.exists()) { log.info("Deleting existing file {}", file); file.delete(); } Files.createDirectories(file.toPath()); file.createNewFile(); } catch (IOException e) { log.error("Could not create file {}", file, e); } List<EntityExportSource<?>> bla = entityExportSources; exporter.export(file, bla); controller .getJavaFXExecutor() .submit( () -> { Dialogs.create() .message(Localized.get("export.successfully", file)) .showInformation(); if (openAfterExport.isSelected()) { controller .getExecutorService() .submit( () -> { try { desktop.edit(file); } catch (IOException e) { log.error("Could not open {}", file, e); } }); } }); }
// deschide fereastra editorului pentru fisierul openPhilePath public void edit(String entry) throws PhileNotOpenException { try { String targetPath = currentPath + "\\" + entry; File file = new File(targetPath); if (!file.exists()) { System.out.println("Fisierul nu exista"); return; } Desktop dk = Desktop.getDesktop(); // Open a file dk.edit(file); } catch (Exception e) { } finally { takePath(); } }
@DefaultCommand public void run( @Option(description = "The files to edit", defaultValue = ".") final Resource<?>[] dirs) throws IOException { for (Resource<?> resource : dirs) { if (resource instanceof FileResource<?>) { Desktop dt = Desktop.getDesktop(); try { dt.edit((File) resource.getUnderlyingResourceObject()); } catch (UnsupportedOperationException e) { if (OSUtils.isLinux()) { NativeSystemCall.exec(true, "gedit", resource.getFullyQualifiedName()); } else throw e; } } } }