List of usage examples for java.util.function Supplier get
T get();
From source file:org.opensingular.form.type.basic.AtrBasic.java
public AtrBasic dependsOn(Supplier<Collection<SType<?>>> value) { Supplier<Collection<SType<?>>> previous = ObjectUtils .defaultIfNull(getAttributeValue(SPackageBasic.ATR_DEPENDS_ON_FUNCTION), Collections::emptySet); setAttributeValue(SPackageBasic.ATR_DEPENDS_ON_FUNCTION, () -> { Set<SType<?>> union = new LinkedHashSet<>(previous.get()); union.addAll(value.get());/*from w w w . ja v a2 s. c o m*/ return union; }); return this; }
From source file:org.pentaho.di.core.listeners.impl.EntryCurrentDirectoryChangedListener.java
public EntryCurrentDirectoryChangedListener(Supplier<ObjectLocationSpecificationMethod> specMethodGetter, Supplier<String> pathGetter, Consumer<String> pathSetter) { this(new PathReference() { @Override//w w w. ja va 2 s .co m public ObjectLocationSpecificationMethod getSpecification() { return specMethodGetter.get(); } @Override public String getPath() { return pathGetter.get(); } @Override public void setPath(String path) { pathSetter.accept(path); } }); }
From source file:org.pentaho.osgi.platform.plugin.deployer.impl.PluginZipFileProcessor.java
public void process(Supplier<ZipInputStream> zipInputStreamProvider, ZipOutputStream zipOutputStream) throws IOException { File dir = Files.createTempDir(); PluginMetadata pluginMetadata = null; try {//w w w.j av a 2s . co m pluginMetadata = new PluginMetadataImpl(dir); } catch (ParserConfigurationException e) { throw new IOException(e); } Manifest manifest = null; ZipInputStream zipInputStream = zipInputStreamProvider.get(); try { logger.debug("Processing plugin - Name: {} SymbolicName: {} Version: {}", this.name, this.symbolicName, this.version); ZipEntry zipEntry; byte[] pluginSpringXmlBytes = null; String pluginSpringXmlName = null; while ((zipEntry = zipInputStream.getNextEntry()) != null) { String name = zipEntry.getName(); byte[] bytes = getEntryBytes(zipInputStream); // [BACKLOG-14815] // Ensures the plugin.xml file is read before plugin.spring.xml. This is needed so // {@link org.pentaho.osgi.platform.plugin.deployer.impl.handlers.SpringFileHandler#handle()} // can get the proper bundleName and set the service entry point. if (pluginSpringXmlBytes == null && name != null && name.endsWith(PLUGIN_SPRING_XML_FILENAME)) { pluginSpringXmlBytes = bytes; // Store plugin.spring.xml for processing after plugin.xml pluginSpringXmlName = name; } else { processEntry(zipOutputStream, pluginMetadata, zipEntry.isDirectory(), name, bytes); } } if (pluginSpringXmlBytes != null) { processEntry(zipOutputStream, pluginMetadata, false, pluginSpringXmlName, pluginSpringXmlBytes); } } finally { IOUtils.closeQuietly(zipInputStream); } // Write blueprint to disk, picked up with others later int tries = 100; File blueprintDir = new File( dir.getAbsolutePath() + "/" + BLUEPRINT.substring(0, BLUEPRINT.lastIndexOf('/'))); while (!blueprintDir.exists() && tries-- > 0) { blueprintDir.mkdirs(); } FileOutputStream blueprintOutputStream = null; try { blueprintOutputStream = new FileOutputStream(dir.getAbsolutePath() + "/" + BLUEPRINT); pluginMetadata.writeBlueprint(name, blueprintOutputStream); } finally { if (blueprintOutputStream != null) { blueprintOutputStream.close(); } } Set<String> createdEntries = new HashSet<String>(); // 1. Write Manifest Directory String manifestFolder = JarFile.MANIFEST_NAME.split("/")[0] + "/"; ZipEntry manifestFolderEntry = new ZipEntry(manifestFolder); zipOutputStream.putNextEntry(manifestFolderEntry); zipOutputStream.closeEntry(); createdEntries.add(manifestFolder); // 2. Write Manifest ZipEntry manifestEntry = new ZipEntry(JarFile.MANIFEST_NAME); zipOutputStream.putNextEntry(manifestEntry); pluginMetadata.getManifestUpdater().write(manifest, zipOutputStream, name, symbolicName, version); zipOutputStream.closeEntry(); createdEntries.add(JarFile.MANIFEST_NAME); // Handlers may have written files to disk which need to be added. Stack<File> dirStack = new Stack<File>(); dirStack.push(dir); int len = 0; byte[] buffer = new byte[1024]; try { while (dirStack.size() > 0) { File currentDir = dirStack.pop(); String dirName = currentDir.getAbsolutePath().substring(dir.getAbsolutePath().length()) + "/"; if (dirName.startsWith("/") || dirName.startsWith("\\")) { dirName = dirName.substring(1); } if (dirName.length() > 0 && !createdEntries.contains(dirName)) { ZipEntry zipEntry = new ZipEntry(dirName.replaceAll(Pattern.quote("\\"), "/")); zipOutputStream.putNextEntry(zipEntry); zipOutputStream.closeEntry(); } File[] dirFiles = currentDir.listFiles(); if (dirFiles != null) { for (File childFile : dirFiles) { if (childFile.isDirectory()) { dirStack.push(childFile); } else { String fileName = childFile.getAbsolutePath() .substring(dir.getAbsolutePath().length() + 1); FileInputStream fileInputStream = null; try { fileInputStream = new FileInputStream(childFile); ZipEntry childZipEntry = new ZipEntry( fileName.replaceAll(Pattern.quote("\\"), "/")); zipOutputStream.putNextEntry(childZipEntry); while ((len = fileInputStream.read(buffer)) != -1) { zipOutputStream.write(buffer, 0, len); } zipOutputStream.closeEntry(); } finally { if (fileInputStream != null) { fileInputStream.close(); } } } } } } } finally { IOUtils.closeQuietly(zipOutputStream); recursiveDelete(dir); } }
From source file:org.phoenicis.javafx.UiMessageSenderJavaFXImplementation.java
@Override public <R> R run(Supplier<R> function) { // runBackground synchronously on JavaFX thread if (Platform.isFxApplicationThread()) { return function.get(); }// w ww . j ava2s. c om // queue on JavaFX thread and wait for completion final CountDownLatch doneLatch = new CountDownLatch(1); final MutableObject result = new MutableObject(); Platform.runLater(() -> { try { result.setValue(function.get()); } finally { doneLatch.countDown(); } }); try { doneLatch.await(); } catch (InterruptedException e) { // ignore exception } return (R) result.getValue(); }
From source file:org.polymap.p4.data.importer.prompts.CharsetPrompt.java
public CharsetPrompt(final ImporterSite site, final String summary, final String description, Supplier<Charset> charsetSupplier, Supplier<List<String>> potentialEncodingProblemsSupplier) { selection = charsetSupplier.get(); if (selection == null) { selection = DEFAULT;//www . j a v a 2s. co m } initCharsets(); site.newPrompt("charset").summary.put(summary).description.put(description).value .put(selection.name()).severity.put(Severity.VERIFY).extendedUI .put(new FilteredListPromptUIBuilder() { @Override public void submit(ImporterPrompt prompt) { prompt.ok.set(true); prompt.value.put(selection.displayName(Polymap.getSessionLocale())); } @Override protected Set<String> listItems() { return displayNames; } @Override protected String initiallySelectedItem() { return selection.displayName(Polymap.getSessionLocale()); } @Override protected void handleSelection(String selectedDisplayname) { selection = charsets.get(selectedDisplayname); assert selection != null; } @Override public void createContents(ImporterPrompt prompt, Composite parent, IPanelToolkit tk) { super.createContents(prompt, parent, tk); if (potentialEncodingProblemsSupplier != null) { List<String> potentialEncodingProblems = potentialEncodingProblemsSupplier .get(); if (potentialEncodingProblems != null && !potentialEncodingProblems.isEmpty()) { Label desc = FormDataFactory.on(tk.createLabel(parent, i18n.get("encodingSamplesDescription"), SWT.WRAP)).top(list, 25) .left(0).width(350).control(); TableViewer viewer = new TableViewer(parent, SWT.H_SCROLL | SWT.V_SCROLL); // create preview table ColumnViewerToolTipSupport.enableFor(viewer); TableLayout layout = new TableLayout(); viewer.getTable().setLayout(layout); viewer.getTable().setHeaderVisible(true); viewer.getTable().setLinesVisible(true); layout.addColumnData(new ColumnPixelData(350)); TableViewerColumn viewerColumn = new TableViewerColumn(viewer, SWT.H_SCROLL); viewerColumn.getColumn().setText(i18n.get("encodingSamples")); viewerColumn.setLabelProvider(new ColumnLabelProvider() { @Override public String getToolTipText(Object element) { return super.getText(element); } }); viewer.setContentProvider(ArrayContentProvider.getInstance()); viewer.setInput(potentialEncodingProblems); FormDataFactory.on(viewer.getTable()).left(1).top(desc, 15).width(350) .height(200).bottom(100); // parent.pack(); } } } @Override protected String description() { return i18nPrompt.get("filterDescription"); } @Override protected String summary() { return i18nPrompt.get("filterSummary"); } }); }
From source file:org.polymap.wbv.ui.StartPanel.java
protected void createMainContents(Composite parent) { site().title.set(i18n.get("title", "--")); Composite body = parent;//from w ww . java 2 s .c o m body.setLayout(FormLayoutFactory.defaults().spacing(5).margins(0, 10).create()); final WaldbesitzerTableViewer viewer = new WaldbesitzerTableViewer(uow, body, Collections.EMPTY_LIST, SWT.BORDER); getContext().propagate(viewer); // waldbesitzer ffnen viewer.addSelectionChangedListener(new ISelectionChangedListener() { @Override public void selectionChanged(SelectionChangedEvent ev) { if (!viewer.getSelected().isEmpty()) { selected.set(viewer.getSelected().get(0)); getContext().openPanel(getSite().getPath(), WaldbesitzerPanel.ID); } } }); // waldbesitzer anlegen Button createBtn = tk().createButton(body, "Neu", SWT.PUSH); createBtn.setToolTipText("Einen neuen Waldbesitzer anlegen"); createBtn.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent ev) { selected.set(null); getContext().openPanel(getSite().getPath(), WaldbesitzerPanel.ID); } }); // exit app Button exitBtn = tk().createButton(body, null, SWT.PUSH); exitBtn.setImage(BatikPlugin.images().svgImage("close.svg", SvgImageRegistryHelper.WHITE24)); exitBtn.setToolTipText("Anwendung verlassen und neu anmelden"); exitBtn.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent ev) { RWT.getClient().getService(JavaScriptExecutor.class).execute("window.location.reload(true);"); } }); // reports final Combo reports = new Combo(body, SWT.BORDER | SWT.READ_ONLY); reports.add("Auswertung whlen..."); for (Supplier<WbvReport> factory : WbvReport.factories) { reports.add(factory.get().getName()); } reports.setVisibleItemCount(8); reports.select(0); reports.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent ev) { try { if (reports.getSelectionIndex() > 0) { WbvReport report = WbvReport.factories.get(reports.getSelectionIndex() - 1).get(); report.setOutputType(OutputType.PDF); report.setViewerEntities(viewer.getInput()); String url = DownloadService.registerContent(report); UrlLauncher launcher = RWT.getClient().getService(UrlLauncher.class); launcher.openURL(url); //ExternalBrowser.open( "download_window", url, ExternalBrowser.NAVIGATION_BAR | ExternalBrowser.STATUS ); reports.select(0); } } catch (Exception e) { throw new RuntimeException(e); } } }); // searchField FulltextIndex fulltext = WbvRepository.fulltextIndex(); EntitySearchField search = new EntitySearchField<Waldbesitzer>(body, fulltext, uow, Waldbesitzer.class) { @Override protected void doSearch(String _queryString) throws Exception { super.doSearch(_queryString); queryString.set(_queryString); } @Override protected void doRefresh() { // nach revier filtern revier.ifPresent(r -> query.andWhere(r.waldbesitzerFilter.get())); // SelectionEvent nach refresh() verhindern viewer.clearSelection(); ResultSet<Waldbesitzer> results = query.execute(); viewer.setInput(results); site().title.set(i18n.get("title", results.size())); } }; if ("falko".equals(System.getProperty("user.name"))) { search.searchOnEnter.set(false); search.getText().setText("gemarkung:Holzhau*"); } search.searchOnEnter.set(true); search.getText().setFocus(); search.getControl().moveAbove(null); new FulltextProposal(fulltext, search.getText()).activationDelayMillis.put(250); // layout int displayHeight = UIUtils.sessionDisplay().getBounds().height; int tableHeight = (displayHeight - (2 * 50) - 75 - 70); // margins, searchbar, toolbar+banner exitBtn.setLayoutData(FormDataFactory.filled().clearRight().clearBottom().height(28).width(30).create()); createBtn.setLayoutData(FormDataFactory.defaults().left(exitBtn).create()); reports.setLayoutData(FormDataFactory.filled().left(createBtn).noBottom().height(26).right(50).create()); search.getControl().setLayoutData( FormDataFactory.filled().height(27).bottom(viewer.getTable()).left(reports).create()); viewer.getTable() .setLayoutData(FormDataFactory.filled().top(createBtn).height(tableHeight).width(300).create()); // // map // IPanelSection karte = tk.createPanelSection( parent, null ); // karte.addConstraint( new PriorityConstraint( 5 ) ); // karte.getBody().setLayout( ColumnLayoutFactory.defaults().columns( 1, 1 ).create() ); // // try { // map = new WbvMapViewer( getSite() ); // map.createContents( karte.getBody() ) // .setLayoutData( new ColumnLayoutData( SWT.DEFAULT, tableHeight + 35 ) ); // //.setLayoutData( FormDataFactory.filled().height( tableHeight + 35 ).create() ); // } // catch (Exception e) { // throw new RuntimeException( e ); // } // // // context menu // map.getContextMenu().addProvider( new WaldflaechenMenu() ); // map.getContextMenu().addProvider( new IContextMenuProvider() { // @Override // public IContextMenuContribution createContribution() { // return new FindFeaturesMenuContribution() { // @Override // protected void onMenuOpen( FeatureStore fs, Feature feature, ILayer layer ) { // log.info( "Feature: " + feature ); // } // }; // } // }); }
From source file:org.rakam.client.builder.document.SlateDocumentGenerator.java
private String generateContent(String key) { Supplier<String> supplier = contentSuppliers.get(key); if (supplier == null) { System.out.println("template key " + key + " not supported!"); return ""; }// www .ja v a2s .c o m return supplier.get(); }
From source file:org.sejda.impl.sambox.util.FontUtils.java
/** * check the label can be written with the selected font, use the fallback otherwise * /* w w w . j a va 2 s. c om*/ * @param text * @param font * @param fallbackSupplier * @return */ public static PDFont fontOrFallback(String text, PDFont font, Supplier<PDFont> fallbackSupplier) { if (nonNull(fallbackSupplier) && !canDisplay(text, font)) { LOG.info("Text cannot be written with font {}, using fallback", font.getName()); return fallbackSupplier.get(); } return font; }
From source file:org.semanticweb.owlapi6.rdf.rdfxml.parser.OWLRDFConsumer.java
protected <T> void consume(Supplier<T> next, Consumer<T> use) { for (T t = next.get(); t != null; t = next.get()) { use.accept(t);// ww w.j a va 2 s. c o m } }
From source file:org.silverpeas.components.kmelia.export.KmeliaPublicationExporter.java
/** * Only the first publication is taken in charge by this exporter. * @param descriptor the descriptor providing enough information about the export to perform * (document name, user for which the export is, the language in which the export has to be done, * ...)// w w w . j a v a2 s . c o m * @param supplier a supplier of the publication to export. If several publications are passed as * parameter, only the first one is taken. * @throws ExportException if an error occurs while exporting the publication. */ @Override public void exports(ExportDescriptor descriptor, Supplier<KmeliaPublication> supplier) throws ExportException { OutputStream output = descriptor.getOutputStream(); UserDetail user = descriptor.getParameter(EXPORT_FOR_USER); String language = descriptor.getParameter(EXPORT_LANGUAGE); String folderId = descriptor.getParameter(EXPORT_TOPIC); DocumentFormat targetFormat = DocumentFormat.inFormat(descriptor.getMimeType()); KmeliaPublication publication = supplier.get(); String documentPath = getTemporaryExportFilePathFor(publication); File odtDocument = null, exportFile = null; try { ODTDocumentBuilder builder = ODTDocumentBuilder.anODTDocumentBuilder().forUser(user) .inLanguage(language).inTopic(folderId); odtDocument = builder.buildFrom(publication, ODTDocumentBuilder.anODTAt(documentPath)); if (targetFormat != odt) { ODTConverter converter = DocumentFormatConverterProvider.getODTConverter(); exportFile = converter.convert(odtDocument, inFormat(targetFormat)); } else { exportFile = odtDocument; } output.write(FileUtils.readFileToByteArray(exportFile)); output.flush(); output.close(); } catch (IOException ex) { throw new ExportException(ex.getMessage(), ex); } finally { if (odtDocument != null && odtDocument.exists()) { odtDocument.delete(); } if (exportFile != null && exportFile.exists()) { exportFile.delete(); } } }