@EventListener(priority = Integer.MIN_VALUE) public void request(TaskExecutionRequestEvent event) { AbstractParameters params = event.getParameters(); try { if (params.getExistingOutputPolicy() != ExistingOutputPolicy.OVERWRITE) { event.getParameters().getOutput().accept(new TaskOutputDispatcher() { @Override public void dispatch(FileOrDirectoryTaskOutput output) { onDirectory(params, output.getDestination()); } @Override public void dispatch(DirectoryTaskOutput output) { onDirectory(params, output.getDestination()); } @Override public void dispatch(FileTaskOutput output) { onFile(params, output.getDestination()); } }); } } catch (TaskOutputVisitException e) { // it should never happen LOG.warn("Unable to show overwrite confirmation dialog", e); } }
public OpenButton(String ownerModule, ModuleInputOutputType outputType) { requireNonNull(outputType); this.outputType = outputType; this.ownerModule = defaultString(ownerModule); setId(ownerModule + ".openButton"); getStyleClass().addAll(Style.BUTTON.css()); getStyleClass().addAll("pdfsam-split-button", "footer-open-button"); setText(DefaultI18nContext.getInstance().i18n("Open")); setMaxHeight(Double.MAX_VALUE); setPrefHeight(Double.MAX_VALUE); setVisible(false); setOnAction(e -> { if (latestOutput.size() != 1 || !openFile(latestOutput.get(0))) { openFile(destination); } }); eventStudio().add(TaskExecutionRequestEvent.class, e -> { if (e.getModuleId().equals(ownerModule)) { latestOutput.clear(); try { if (!isNull(e.getParameters().getOutput())) { e.getParameters().getOutput().accept(this); } } catch (TaskOutputVisitException ex) { LOG.warn("This should never happen", ex); } } }, -10, ReferenceStrength.STRONG); eventStudio().addAnnotatedListeners(this); }
protected void assertOutputFile(TaskOutput output, final Path expected) throws TaskException { output.accept(new TaskOutputDispatcher() { @Override public void dispatch(DirectoryTaskOutput output) { fail("wrong dispached method"); } @Override public void dispatch(FileTaskOutput output) { assertEquals(expected.toAbsolutePath().normalize().toFile(), output.getDestination()); } @Override public void dispatch(FileOrDirectoryTaskOutput output) { assertEquals(expected.toAbsolutePath().normalize().toFile(), output.getDestination()); } }); }
/** * Creates a temp file trying to find the best location based on the task output. * * @param taskOut * @return * @throws TaskIOException */ public static File createTemporaryBuffer(TaskOutput taskOut) throws TaskIOException { TmpBufferLocationFinder bufferLocationFinder = new TmpBufferLocationFinder(); try { taskOut.accept(bufferLocationFinder); File buffer = tmpFile(bufferLocationFinder.bufferLocation).toFile(); buffer.deleteOnExit(); return buffer; } catch (TaskOutputVisitException | IOException e) { throw new TaskIOException("Unable to create temporary buffer", e); } }
/** * Creates a temp file trying to find the best location based on the task output. * * @param taskOut * @return * @throws TaskIOException */ public static File createTemporaryBuffer(TaskOutput taskOut) throws TaskIOException { TmpBufferLocationFinder bufferLocationFinder = new TmpBufferLocationFinder(); try { taskOut.accept(bufferLocationFinder); File buffer = tmpFile(bufferLocationFinder.bufferLocation).toFile(); buffer.deleteOnExit(); return buffer; } catch (TaskOutputVisitException | IOException e) { throw new TaskIOException("Unable to create temporary buffer", e); } }
protected void assertOutputFolder(TaskParameters result, final Path expected) throws TaskException { result.getOutput().accept(new TaskOutputDispatcher() { @Override public void dispatch(DirectoryTaskOutput output) { assertEquals(expected.toAbsolutePath().normalize().toFile(), output.getDestination()); } @Override public void dispatch(FileTaskOutput output) { fail("wrong dispached method"); } @Override public void dispatch(FileOrDirectoryTaskOutput output) { assertEquals(expected.toAbsolutePath().normalize().toFile(), output.getDestination()); } }); }
parameters.getOutput().accept(outputWriter);
parameters.getOutput().accept(outputWriter);