/** * Filters a given shortcut * * @param shortcut The to be filtered shortcut * @return True if the shortcut should be shown, false otherwise */ public boolean filter(ShortcutDTO shortcut) { final boolean searchTermConstraint = Optional.ofNullable(searchTerm.getValueSafe()) .map(searchTerm -> shortcut.getInfo().getName().toLowerCase().contains(searchTerm.toLowerCase())) .orElse(true); final boolean selectedShortcutCategoryConstraint = Optional.ofNullable(selectedShortcutCategory.getValue()) .map(selectedShortcutCategory -> selectedShortcutCategory.getShortcuts().contains(shortcut)) .orElse(true); return searchTermConstraint && selectedShortcutCategoryConstraint; }
public static ListWidgetElement<ShortcutDTO> create(ShortcutDTO shortcut) { return new ListWidgetElement<>(shortcut, Optional.ofNullable(shortcut.getMiniature()), DEFAULT_MINIATURE, shortcut.getInfo().getName(), Collections.emptyList(), Collections.emptyList()); }
public ShortcutDTO fetchShortcutsFromName(String name) { for (ShortcutCategoryDTO shortcutCategoryDTO : fetchShortcuts()) { for (ShortcutDTO shortcutDTO : shortcutCategoryDTO.getShortcuts()) { if (name.equals(shortcutDTO.getInfo().getName())) { return shortcutDTO; } } } return null; }
final File desktopShortcutFile = new File(desktopShortcutDirectoryFile, baseName + ".desktop"); try { final String content = "[Desktop Entry]\n" + "Name=" + shortcutInfo.getName() + "\n" + "Type=Application\n" + "Icon=" + miniatureFile.getAbsolutePath() + "\n" + "Exec=phoenicis-cli -run \"" + shortcutInfo.getName() + "\""; FileUtils.writeStringToFile(desktopShortcutFile, content, ENCODING); } catch (IOException e) {
public static ListWidgetElement<ContainerDTO> create(ContainerDTO container) { final List<BufferedImage> miniatures = new ArrayList<>(); // do not use too many segments (cannot recognize the miniature if the segment is too small) final int maxSegments = 4; int currentSegment = 0; for (ShortcutDTO shortcutDTO : container.getInstalledShortcuts()) { if (currentSegment >= maxSegments) { break; } try { miniatures.add(ImageIO.read(shortcutDTO.getMiniature().toURL())); currentSegment++; } catch (IOException e) { LOGGER.warn( String.format("Could not read miniature for shortcut \"%s\"", shortcutDTO.getInfo().getName()), e); } } final BufferedImage segmentedMiniature = createSegmentedMiniature(miniatures); final Optional<URI> shortcutMiniature = saveBufferedImage(segmentedMiniature, container.getName()); return new ListWidgetElement<>(container, shortcutMiniature, CONTAINER_MINIATURE, container.getName(), Collections.emptyList(), Collections.emptyList()); }
/** * Updates the shortcut of this {@link LibraryDetailsPanelSkin} instance */ private void updateShortcut() { final ShortcutDTO shortcut = getControl().getShortcut(); if (shortcut != null) { title.setValue(shortcut.getInfo().getName()); description.setValue(shortcut.getInfo().getDescription()); try { final Map<String, Object> shortcutProperties = getControl().getObjectMapper() .readValue(shortcut.getScript(), new TypeReference<Map<String, Object>>() { // nothing }); this.shortcutProperties.clear(); this.shortcutProperties.putAll(shortcutProperties); } catch (IOException e) { LOGGER.error("An error occurred during a shortcut update", e); } } }
/** * Updates the shortcut of this {@link LibraryDetailsPanelSkin} instance */ private void updateShortcut() { final ShortcutDTO shortcut = getControl().getShortcut(); if (shortcut != null) { title.setValue(shortcut.getInfo().getName()); description.setValue(shortcut.getInfo().getDescription()); try { final Map<String, Object> shortcutProperties = getControl().getObjectMapper() .readValue(shortcut.getScript(), new TypeReference<Map<String, Object>>() { // nothing }); this.shortcutProperties.clear(); this.shortcutProperties.putAll(shortcutProperties); } catch (IOException e) { LOGGER.error("An error occurred during a shortcut update", e); } } }
.map(shortcutDTO -> shortcutDTO.getInfo().getName()).collect(Collectors.joining("; "))); installedShortcuts.setWrapText(true); informationContentPane.add(installedShortcuts, 1, 2);
.sorted(Comparator.comparing(shortcut -> shortcut.getInfo().getName()));
private void uninstallShortcut(ShortcutDTO shortcut) { final String shortcutName = shortcut.getInfo().getName(); final ConfirmDialog confirmMessage = ConfirmDialog.builder() .withTitle(tr("Uninstall {0}", shortcutName)) .withMessage(tr("Are you sure you want to uninstall {0}?", shortcutName)) .withOwner(content.getScene().getWindow()) .withResizable(true) .withYesCallback(() -> shortcutManager.uninstallFromShortcut(shortcut, e -> { final ErrorDialog errorDialog = ErrorDialog.builder() .withMessage(tr("Error while uninstalling {0}", shortcutName)) .withException(e) .withOwner(content.getScene().getWindow()) .build(); errorDialog.showAndWait(); })) .build(); confirmMessage.showAndCallback(); }