public void updateLibrary() { final List<ShortcutCategoryDTO> categories = libraryManager.fetchShortcuts(); Platform.runLater(() -> this.libraryView.populate(categories)); }
@Bean public LibraryManager libraryManager() { return new LibraryManager(shortcutDirectory, phoenicisGlobalConfiguration.objectMapper()); }
public void run(String shortcutName, List<String> arguments, Consumer<Exception> errorCallback) { run(libraryManager.fetchShortcutsFromName(shortcutName), arguments, errorCallback); }
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(); }
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; }
final ShortcutInfoDTO shortcutInfoDTOFromJsonFile = unSerializeShortcutInfo(infoFile); shortcutInfoDTOBuilder = new ShortcutInfoDTO.Builder(shortcutInfoDTOFromJsonFile);
public LibraryController(LibraryView libraryView, ConsoleController consoleController, LibraryManager libraryManager, RepositoryManager repositoryManager) { super(); this.libraryView = libraryView; this.libraryManager = libraryManager; this.repositoryManager = repositoryManager; this.libraryManager.setOnUpdate(this::updateLibrary); this.libraryView.setOnOpenConsole(() -> libraryView.createNewTab(consoleController.createConsole())); this.libraryView.setOnSelectionChanged(event -> { if (this.libraryView.isSelected() && this.firstViewSelection) { this.repositoryManager.addCallbacks(this::updateLibrary, e -> { }); this.repositoryManager.triggerCallbacks(); this.firstViewSelection = false; } }); }
LOGGER.warn("Error while creating shortcut", e); } finally { libraryManager.refresh();
public ShortcutDTO fetchShortcutsFromName(String name) { for (ShortcutCategoryDTO shortcutCategoryDTO : fetchShortcuts()) { for (ShortcutDTO shortcutDTO : shortcutCategoryDTO.getShortcuts()) { if (name.equals(shortcutDTO.getInfo().getName())) { return shortcutDTO; } } } return null; }
List<ShortcutDTO> shortcutDTOS = libraryManager.fetchShortcuts().stream() .flatMap(shortcutCategory -> shortcutCategory.getShortcuts().stream()).filter(shortcut -> { boolean toAdd = false;
List<ShortcutCategoryDTO> categories = this.libraryManager.fetchShortcuts(); categories.stream().flatMap(shortcutCategoryDTO -> shortcutCategoryDTO.getShortcuts().stream()) .forEach(shortcutDTO -> {