public Builder(ShortcutCategoryDTO categoryDTO) { this.withId(categoryDTO.getId()).withName(categoryDTO.getName()) .withDescription(categoryDTO.getDescription()).withShortcuts(categoryDTO.getShortcuts()) .withIcon(categoryDTO.getIcon()); }
public ShortcutDTO build() { return new ShortcutDTO(this); } }
public ShortcutCategoryDTO build() { return new ShortcutCategoryDTO(this); } }
/** * 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); } } }
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 ShortcutDTO fetchShortcutsFromName(String name) { for (ShortcutCategoryDTO shortcutCategoryDTO : fetchShortcuts()) { for (ShortcutDTO shortcutDTO : shortcutCategoryDTO.getShortcuts()) { if (name.equals(shortcutDTO.getInfo().getName())) { return shortcutDTO; } } } return null; }
public static ListWidgetElement<ShortcutDTO> create(ShortcutDTO shortcut) { return new ListWidgetElement<>(shortcut, Optional.ofNullable(shortcut.getMiniature()), DEFAULT_MINIATURE, shortcut.getInfo().getName(), Collections.emptyList(), Collections.emptyList()); }
/** * {@inheritDoc} */ @Override protected ToggleButton convertToToggleButton(ShortcutCategoryDTO category) { final ToggleButton categoryButton = createSidebarToggleButton(category.getName()); categoryButton.setId(String.format("%sButton", category.getId().toLowerCase())); categoryButton.setOnMouseClicked(event -> getControl().setSelectedElement(category)); return categoryButton; } }
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(); }
/** * Filters a given shortcut category * * @param shortcutCategory The to be filtered shortcut category * @return True if the shortcut category should be shown, false otherwise */ public boolean filter(ShortcutCategoryDTO shortcutCategory) { return Optional.ofNullable(searchTerm.getValueSafe()) .map(searchTerm -> shortcutCategory.getShortcuts().stream().anyMatch(this::filter)) .orElse(true); }
private ShortcutInfoDTO unSerializeShortcutInfo(File jsonFile) { try { return this.objectMapper.readValue(jsonFile, ShortcutInfoDTO.class); } catch (IOException e) { LOGGER.debug("JSON file not found"); return new ShortcutInfoDTO.Builder().build(); } } }
public ShortcutInfoDTO build() { return new ShortcutInfoDTO(this); }
public ShortcutCreationDTO build() { return new ShortcutCreationDTO(this); }
/** * 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); } } }
/** * 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 void deleteShortcut(ShortcutDTO shortcutDTO) { final String baseName = shortcutDTO.getId(); final File shortcutDirectory = new File(this.shortcutDirectory); final File infoFile = new File(shortcutDirectory, baseName + ".info"); final File scriptFile = new File(shortcutDirectory, baseName + ".shortcut"); final File iconFile = new File(shortcutDirectory, baseName + ".icon"); final File miniatureFile = new File(shortcutDirectory, baseName + ".miniature"); if (infoFile.exists()) { infoFile.delete(); } if (scriptFile.exists()) { scriptFile.delete(); } if (iconFile.exists()) { iconFile.delete(); } if (miniatureFile.exists()) { miniatureFile.delete(); } if (this.desktopShortcutDirectory != null) { final File desktopShortcutDirectoryFile = new File(this.desktopShortcutDirectory); final File desktopShortcutFile = new File(desktopShortcutDirectoryFile, baseName + ".desktop"); if (desktopShortcutFile.exists()) { desktopShortcutFile.delete(); } } libraryManager.refresh(); }