/** * 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; }
public List<ShortcutCategoryDTO> fetchShortcuts() { final File shortcutDirectoryFile = new File(this.shortcutDirectory); if (!shortcutDirectoryFile.exists()) { shortcutDirectoryFile.mkdirs(); return Collections.emptyList(); } final File[] directoryContent = shortcutDirectoryFile.listFiles(); if (directoryContent == null) { return Collections.emptyList(); } HashMap<String, List<ShortcutDTO>> categoryMap = new HashMap<>(); for (File file : directoryContent) { if ("shortcut".equals(FilenameUtils.getExtension(file.getName()))) { ShortcutDTO shortcut = fetchShortcutDTO(shortcutDirectoryFile, file); String categoryId = shortcut.getInfo().getCategory(); if (!categoryMap.containsKey(categoryId)) { categoryMap.put(categoryId, new ArrayList<>()); } categoryMap.get(categoryId).add(shortcut); } } List<ShortcutCategoryDTO> shortcuts = new ArrayList<>(); for (Map.Entry<String, List<ShortcutDTO>> entry : categoryMap.entrySet()) { entry.getValue().sort(ShortcutDTO.nameComparator()); ShortcutCategoryDTO category = new ShortcutCategoryDTO.Builder().withId(entry.getKey()) .withName(entry.getKey()).withShortcuts(entry.getValue()).build(); shortcuts.add(tr(category)); } return shortcuts; }
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()); }
public void createShortcut(ShortcutDTO shortcutDTO) { final ShortcutInfoDTO shortcutInfo = shortcutDTO.getInfo();
/** * 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(); }