Search in sources :

Example 1 with PlaylistMenuItem

use of se.light.assembly64.model.PlaylistMenuItem in project assembly64fx by freabemania.

the class SearchViewFilesController method handleMouseClicked.

private void handleMouseClicked(MouseEvent event) {
    if (event.getButton() == MouseButton.SECONDARY || event.isControlDown()) {
        final ContextMenu contextMenu = new ContextMenu();
        List<ContentEntry> selectedItems = table.getSelectionModel().getSelectedItems();
        // do not show downloadbuttons if we're coming from treeview
        if (fromSearch) {
            MenuItem view = new MenuItem("Download to installbase");
            view.setOnAction((ActionEvent event2) -> {
                if (userService.getPrimaryInstallation().exists()) {
                    downloadFilesAsync(selectedItems, UserService.getInstance().resolveDownloadFolderAsString());
                } else {
                    GenericMessageDialogController.withErrorProps("Ooops..", "No valid downloadlocation is present").showAndWait();
                }
            });
            if (userService.isLocationSelectedAndExisting()) {
                contextMenu.getItems().add(view);
            }
            MenuItem downloadTo = new MenuItem("Download to...");
            downloadTo.setOnAction((ActionEvent event2) -> {
                File tmp = new DirectoryChooser().showDialog(getStage());
                Analytics.sendEvent("search", "installfilecustompath");
                if (tmp != null) {
                    downloadFilesAsync(selectedItems, Support.getAndfixPathAsString(tmp));
                }
            });
            contextMenu.getItems().add(downloadTo);
        }
        MenuItem openBrowser = new MenuItem("Open browser");
        openBrowser.setOnAction((ActionEvent event2) -> {
            openFile(true);
        });
        contextMenu.getItems().add(openBrowser);
        MenuItem loadStar = new MenuItem("LOAD \"*\",8,1");
        loadStar.setOnAction((ActionEvent event2) -> {
            openFile(false, true);
        });
        contextMenu.getItems().add(loadStar);
        if (selectedItems.size() == 1) {
            MenuItem browseAction = new MenuItem("Browse image");
            browseAction.setOnAction((ActionEvent event2) -> {
                openFile(true);
            });
            if (selectedItems.size() == 1) {
                ContentEntry selectedItem = selectedItems.get(0);
                if (selectedItem.getName().toLowerCase().endsWith(".sid")) {
                    Menu addToPlaylist = new Menu("Add to playlist");
                    for (PlaylistInfo plist : playlistService.getPlaylistInfo()) {
                        PlaylistMenuItem mItem = new PlaylistMenuItem(plist);
                        mItem.setOnAction((ActionEvent event2) -> {
                            PlaylistMenuItem item = (PlaylistMenuItem) event2.getSource();
                            PlaylistEntry song = new PlaylistEntry(searchedItem.getId(), searchedItem.getCategory(), selectedItem.getId(), selectedItem.getName());
                            selectedItem.setFullPlaylistInfo(song);
                            playlistService.addSong(item.getPlaylist(), selectedItem);
                        });
                        addToPlaylist.getItems().add(mItem);
                    }
                    contextMenu.getItems().add(addToPlaylist);
                }
            }
            contextMenu.getItems().add(browseAction);
        }
        table.setContextMenu(contextMenu);
        Analytics.sendEvent("search", "installfile");
    } else if (event.getClickCount() == 2) {
        openFile(false);
    }
}
Also used : PlaylistMenuItem(se.light.assembly64.model.PlaylistMenuItem) ContentEntry(se.light.assembly64.model.ContentEntry) ActionEvent(javafx.event.ActionEvent) ContextMenu(javafx.scene.control.ContextMenu) MenuItem(javafx.scene.control.MenuItem) PlaylistMenuItem(se.light.assembly64.model.PlaylistMenuItem) ContextMenu(javafx.scene.control.ContextMenu) Menu(javafx.scene.control.Menu) PlaylistInfo(se.light.assembly64.model.PlaylistInfo) PlaylistEntry(se.light.assembly64.model.PlaylistEntry) File(java.io.File) DirectoryChooser(javafx.stage.DirectoryChooser)

Example 2 with PlaylistMenuItem

use of se.light.assembly64.model.PlaylistMenuItem in project assembly64fx by freabemania.

the class SidifyChooseMultipleSongsController method init.

public void init(List<ContentEntry> contentEntries) {
    Analytics.sendEvent("sidify", "choose_multi");
    name.setCellValueFactory(new PropertyValueFactory<ContentEntry, String>("name"));
    playListService = PlaylistService.getInstance();
    sidPlayService = SIDPlayerService.getInstance();
    downloadService = DownloadArtifactsService.getInstance();
    pathService = PathService.getInstance();
    songs.clear();
    contentEntries.stream().forEach(songs::add);
    songlist.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
    songlist.setItems(songs);
    songlist.setOnMousePressed(event -> {
        List<ContentEntry> selectedItems = songlist.getSelectionModel().getSelectedItems();
        if (event.getButton() == MouseButton.SECONDARY || event.isControlDown()) {
            final ContextMenu contextMenu = new ContextMenu();
            Menu addToPlaylist = new Menu("Add to playlist");
            for (PlaylistInfo plist : playListService.getPlaylistInfo()) {
                PlaylistMenuItem mItem = new PlaylistMenuItem(plist);
                mItem.setOnAction((ActionEvent event2) -> {
                    playListService.addSongs(plist, selectedItems.stream().map(item -> item.getFullPlaylistInfo()).collect(Collectors.toList()), selectedItems.stream().map(item -> Collections.singletonList(item)).collect(toList()));
                    songlist.getSelectionModel().clearSelection();
                });
                addToPlaylist.getItems().add(mItem);
            }
            MenuItem mItem = new MenuItem("Add to new playlist");
            mItem.setOnAction((ActionEvent event2) -> {
                SidifyCreatePlaylistController controller = GuiUtils.showDialog("sidifyCreateNewPlaylist.fxml", Boolean.TRUE, "Create new playlist", getStage(), new Object[] { null, true });
                PlaylistInfo newPlaylist = controller.getNewlyCreatedPlayList();
                if (newPlaylist != null) {
                    playListService.addSongs(newPlaylist, selectedItems.stream().map(item -> item.getFullPlaylistInfo()).collect(Collectors.toList()), selectedItems.stream().map(item -> Collections.singletonList(item)).collect(toList()));
                    songlist.getSelectionModel().clearSelection();
                }
            });
            addToPlaylist.getItems().add(mItem);
            contextMenu.getItems().add(addToPlaylist);
            songlist.setContextMenu(contextMenu);
        } else if (event.getClickCount() == 2) {
            playSong(new PlaylistEntry(selectedItems.get(0).getFullPlaylistInfo().getId(), selectedItems.get(0).getFullPlaylistInfo().getCategory(), selectedItems.get(0).getId(), selectedItems.get(0).getName()));
        }
    });
}
Also used : ActionEvent(javafx.event.ActionEvent) ContextMenu(javafx.scene.control.ContextMenu) MenuItem(javafx.scene.control.MenuItem) PlaylistMenuItem(se.light.assembly64.model.PlaylistMenuItem) PlaylistMenuItem(se.light.assembly64.model.PlaylistMenuItem) ContentEntry(se.light.assembly64.model.ContentEntry) ContextMenu(javafx.scene.control.ContextMenu) Menu(javafx.scene.control.Menu) PlaylistInfo(se.light.assembly64.model.PlaylistInfo) PlaylistEntry(se.light.assembly64.model.PlaylistEntry)

Example 3 with PlaylistMenuItem

use of se.light.assembly64.model.PlaylistMenuItem in project assembly64fx by freabemania.

the class SidifyViewPublicPlaylistsController method init.

public void init(Runnable updateCallback) {
    publicLists.setPlaceholder(new Label("No more public lists to follow"));
    name.setCellValueFactory(new PropertyValueFactory<PlaylistInfo, String>("name"));
    ownerAlias.setCellValueFactory(new PropertyValueFactory<PlaylistInfo, String>("ownerAlias"));
    playListService = PlaylistService.getInstance();
    populateList();
    publicLists.setOnMousePressed(event -> {
        PlaylistInfo selectedItem = publicLists.getSelectionModel().getSelectedItem();
        if (event.getButton() == MouseButton.SECONDARY || event.isControlDown()) {
            final ContextMenu contextMenu = new ContextMenu();
            MenuItem infoItem = new MenuItem("Playlistinfo");
            infoItem.setOnAction((ActionEvent event2) -> {
                GuiUtils.showDialog("sidifyViewPublicPlaylistInfo.fxml", Boolean.TRUE, "Playlistinfo", getStage(), new Object[] { selectedItem });
            });
            MenuItem mItem = new MenuItem("Subscribe to list");
            mItem.setOnAction((ActionEvent event2) -> {
                Analytics.sendEvent("sidify", "subscribe_playlist");
                playListService.subscribeToPlaylist(selectedItem.getId());
                playListService.resetAndGetPublicPlaylists();
                populateList();
                updateCallback.run();
            });
            MenuItem mItem2 = new MenuItem("Copy & add to new playlist");
            mItem2.setOnAction((ActionEvent event2) -> {
                Analytics.sendEvent("sidify", "copyadd_playlist");
                SidifyCreatePlaylistController controller = GuiUtils.showDialog("sidifyCreateNewPlaylist.fxml", Boolean.TRUE, "Create new playlist", getStage(), new Object[] { null, true });
                playListService.copyPlaylist(selectedItem.getId(), controller.getNewlyCreatedPlayList().getId());
                updateCallback.run();
            });
            Menu mItem3 = new Menu("Copy & add to existing playlist");
            for (PlaylistInfo plist : playListService.getPlaylistInfo()) {
                Analytics.sendEvent("sidify", "add_to_existing_playlist");
                PlaylistMenuItem menuItemPl = new PlaylistMenuItem(plist);
                menuItemPl.setOnAction((ActionEvent event2) -> {
                    playListService.copyPlaylist(selectedItem.getId(), menuItemPl.getPlaylist().getId());
                });
                mItem3.getItems().add(menuItemPl);
            }
            contextMenu.getItems().add(infoItem);
            contextMenu.getItems().add(mItem);
            contextMenu.getItems().add(mItem2);
            contextMenu.getItems().add(mItem3);
            publicLists.setContextMenu(contextMenu);
        } else if (event.getClickCount() == 2) {
            GuiUtils.showDialog("sidifyViewPublicPlaylist.fxml", Boolean.TRUE, "Contents of playlist", getStage(), new Object[] { playListService.getSongsForPlaylist(selectedItem) });
        }
    });
}
Also used : PlaylistMenuItem(se.light.assembly64.model.PlaylistMenuItem) ActionEvent(javafx.event.ActionEvent) Label(javafx.scene.control.Label) ContextMenu(javafx.scene.control.ContextMenu) MenuItem(javafx.scene.control.MenuItem) PlaylistMenuItem(se.light.assembly64.model.PlaylistMenuItem) PlaylistInfo(se.light.assembly64.model.PlaylistInfo) Menu(javafx.scene.control.Menu) ContextMenu(javafx.scene.control.ContextMenu)

Example 4 with PlaylistMenuItem

use of se.light.assembly64.model.PlaylistMenuItem in project assembly64fx by freabemania.

the class SidifyMainContoller method init.

public void init(Boolean showBackButton) {
    if (!playerWindowActive.compareAndSet(false, true)) {
        setCancelShow(true);
        return;
    }
    imageCache = CachedImageService.getInstance();
    playListService = PlaylistService.getInstance();
    downloadService = DownloadArtifactsService.getInstance();
    pathService = PathService.getInstance();
    sidPlayService = SIDPlayerService.getInstance();
    volume.setMin(-50L);
    volume.setMax(12);
    volume.setValue(sidPlayService.getVolume());
    volume.valueProperty().addListener(new ChangeListener<Number>() {

        public void changed(ObservableValue<? extends Number> ov, Number oldVal, Number newVal) {
            sidPlayService.setVolume(newVal.intValue());
        }
    });
    volume.valueChangingProperty().addListener(new ChangeListener<Boolean>() {

        @Override
        public void changed(ObservableValue<? extends Boolean> observableValue, Boolean wasChanging, Boolean changing) {
            if (!changing) {
                sidPlayService.storeVolume();
            }
        }
    });
    if (isOffline()) {
        enableSearchImage.setVisible(false);
    }
    performSearchImage.setVisible(false);
    searchField.setVisible(false);
    setIconPlaying(false);
    name.setCellValueFactory(new PropertyValueFactory<PlaylistEntry, String>("nameMasked"));
    group.setCellValueFactory(new PropertyValueFactory<PlaylistEntry, String>("groupMasked"));
    year.setCellValueFactory(new PropertyValueFactory<PlaylistEntry, String>("year"));
    downloaded.setCellValueFactory(new PropertyValueFactory<PlaylistEntry, ImageView>("downloaded"));
    status.setCellValueFactory(new PropertyValueFactory<PlaylistEntry, ImageView>("status"));
    progressSlider.setMin(0);
    progressSlider.setMax(SLIDERMAX);
    progressSlider.disableProperty().setValue(Boolean.TRUE);
    progressUpdater = new ProgressUpdater(played, remaining, progressSlider, prevSub, nextSub);
    status.setMaxWidth(40);
    status.setMinWidth(40);
    status.setSortable(false);
    name.setSortable(false);
    group.setSortable(false);
    year.setSortable(false);
    // songLength.setSortable(false);
    downloaded.setSortable(false);
    songlist.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
    songlist.setPlaceholder(new Label(""));
    songlist.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
    searchPeriod.setItems(FXCollections.observableArrayList(SEARCH_PERIOD.ALL, SEARCH_PERIOD.ONE_DAY, SEARCH_PERIOD.TWO_DAYS, SEARCH_PERIOD.FOUR_DAYS, SEARCH_PERIOD.ONE_WEEK, SEARCH_PERIOD.TWO_WEEKS, SEARCH_PERIOD.THREE_WEEKS, SEARCH_PERIOD.ONE_MONTH, SEARCH_PERIOD.TWO_MONTHS));
    searchPeriod.getSelectionModel().select(0);
    searchPeriod.setVisible(false);
    if (openedMain || !showBackButton) {
        openedMain = true;
        backToAssemblyImage.setVisible(false);
    }
    getStage().getScene().heightProperty().addListener(new ChangeListener<Number>() {

        @Override
        public void changed(ObservableValue<? extends Number> observableValue, Number oldSceneHeight, Number newSceneHeight) {
            resizeComponentsHeight();
            delayedResize();
        }
    });
    getStage().getScene().widthProperty().addListener(new ChangeListener<Number>() {

        @Override
        public void changed(ObservableValue<? extends Number> observableValue, Number oldSceneHeight, Number newSceneWidth) {
            resizeComponentsWidth();
            delayedResize();
        }
    });
    songlist.setRowFactory(tv -> {
        TableRow<PlaylistEntry> row = new TableRow<>();
        row.setOnDragDetected(event -> {
            if (!row.isEmpty() && isPlaylistMine(activePlaylist)) {
                Integer index = row.getIndex();
                Dragboard db = row.startDragAndDrop(TransferMode.MOVE);
                db.setDragView(row.snapshot(null, null));
                ClipboardContent cc = new ClipboardContent();
                cc.put(SERIALIZED_MIME_TYPE, index);
                db.setContent(cc);
                event.consume();
            }
        });
        row.setOnDragOver(event -> {
            if (!isSearchActive() && isPlaylistMine(activePlaylist)) {
                Dragboard db = event.getDragboard();
                if (db.hasContent(SERIALIZED_MIME_TYPE)) {
                    if (row.getIndex() != ((Integer) db.getContent(SERIALIZED_MIME_TYPE)).intValue()) {
                        event.acceptTransferModes(TransferMode.COPY_OR_MOVE);
                        event.consume();
                    }
                }
            }
        });
        row.setOnDragDropped(event -> {
            if (!isSearchActive() && isPlaylistMine(activePlaylist)) {
                Dragboard db = event.getDragboard();
                if (db.hasContent(SERIALIZED_MIME_TYPE)) {
                    int draggedIndex = (Integer) db.getContent(SERIALIZED_MIME_TYPE);
                    PlaylistEntry draggedPerson = songlist.getItems().remove(draggedIndex);
                    int dropIndex;
                    if (row.isEmpty()) {
                        dropIndex = songlist.getItems().size();
                    } else {
                        dropIndex = row.getIndex();
                    }
                    songlist.getItems().add(dropIndex, draggedPerson);
                    event.setDropCompleted(true);
                    clearAndSelect(dropIndex);
                    Analytics.sendEvent("sidify", "dragndrop_song");
                    playListService.moveSongInList(playListService.getPlaylistForSong(draggedPerson), draggedIndex, dropIndex);
                    event.consume();
                    populateLeftList();
                }
            }
        });
        return row;
    });
    getStage().setOnCloseRequest(new EventHandler<WindowEvent>() {

        public void handle(WindowEvent we) {
            if (GlobalRepoService.getInstance().contains("overridebacktoassembly")) {
                closeAndcleanup(true);
            } else {
                closeAndcleanup(!LocalDBService.getInstance().getSidifyAsDefault());
            }
        }
    });
    populateLeftList();
    leftlist.setCellFactory(callback -> new ListCell<PlayerItem>() {

        @Override
        protected void updateItem(PlayerItem t, boolean bln) {
            super.updateItem(t, bln);
            if (t != null) {
                setText(t.getName());
            }
        }
    });
    leftlist.setOnMousePressed(new EventHandler<MouseEvent>() {

        @Override
        public void handle(MouseEvent event) {
            disableSearch(true, false);
            PlayerItem clickedItem = leftlist.getSelectionModel().getSelectedItem();
            if (clickedItem.getType() == MENU_TYPE.NONCLICKABLE) {
                leftlist.getSelectionModel().clearSelection();
            } else if (clickedItem.getType() == MENU_TYPE.PLAYLIST || clickedItem.getType() == MENU_TYPE.PUBLICLIST) {
                PlaylistInfo playlist = clickedItem.getPlaylist();
                // activePlaylist = playlist;
                if ((event.getButton() == MouseButton.SECONDARY || event.isControlDown()) && !isOffline()) {
                    final ContextMenu contextMenu = new ContextMenu();
                    if (clickedItem.getType() == MENU_TYPE.PLAYLIST) {
                        MenuItem tmp = new MenuItem("Delete");
                        tmp.setOnAction((ActionEvent event2) -> {
                            playListService.deletePlaylist(playlist);
                            populateLeftList();
                            clearSongList();
                        });
                        MenuItem rename = new MenuItem("Edit");
                        rename.setOnAction((ActionEvent event2) -> {
                            GuiUtils.showDialog("sidifyCreateNewPlaylist.fxml", Boolean.TRUE, "Yada", getStage(), new Object[] { playlist, false });
                            populateLeftList();
                        });
                        contextMenu.getItems().add(tmp);
                        contextMenu.getItems().add(rename);
                        leftlist.setContextMenu(contextMenu);
                    } else {
                        MenuItem tmp = new MenuItem("Unfollow");
                        tmp.setOnAction((ActionEvent event2) -> {
                            playListService.deletePlaylist(playlist);
                            playListService.resetAndGetPublicPlaylists();
                            populateLeftList();
                        });
                        contextMenu.getItems().add(tmp);
                    }
                    MenuItem offline = new MenuItem("Download to offline");
                    offline.setOnAction((ActionEvent event2) -> {
                        Analytics.sendEvent("sidify", "download_playlist");
                        workQueue.offer(playlist);
                    });
                    MenuItem info = new MenuItem("Playlistinfo");
                    info.setOnAction((ActionEvent event2) -> {
                        GuiUtils.showDialog("sidifyViewPublicPlaylistInfo.fxml", Boolean.TRUE, "Playlistinfo", getStage(), new Object[] { playlist });
                    });
                    MenuItem exportLists = new MenuItem("Export playlist");
                    exportLists.setOnAction((ActionEvent event2) -> {
                        GuiUtils.showDialog("sidifyExportPlaylist.fxml", Boolean.TRUE, "Playlistinfo", getStage(), new Object[] { playlist });
                    });
                    contextMenu.getItems().add(offline);
                    contextMenu.getItems().add(info);
                    contextMenu.getItems().add(exportLists);
                    leftlist.setContextMenu(contextMenu);
                } else {
                    refreshCurrentSongList(playlist);
                }
                if (event.getClickCount() == 2) {
                    activePlaylist = playlist;
                    if (activePlaylist != null) {
                        List<PlaylistEntry> songsForPlaylist = playListService.getSongsForPlaylist(activePlaylist);
                        if (songsForPlaylist.size() > 0) {
                            if (randomSongs.get() == false) {
                                clearAndSelect(0);
                                setActiveSongInList(0);
                            } else {
                                randomize();
                                clearAndSelect(getActiveSongInList());
                            }
                            startSwitchSongLoopFromScratch();
                        }
                    }
                    songlist.requestFocus();
                }
                scrollToTop();
                populateLeftList();
            }
        }
    });
    songlist.setOnKeyTyped(event -> {
        if (!isSearchActive()) {
            if (event.getCharacter().length() > 0 && event.getCharacter().charAt(0) == Support.ENTER_KEY) {
                setBackgroundplaylistState();
                setNewSongPlayingState(false);
                startSwitchSongLoopFromScratch();
            }
        }
    });
    songlist.setOnMousePressed(event -> {
        songlist.setContextMenu(null);
        List<PlaylistEntry> selectedItems = songlist.getSelectionModel().getSelectedItems();
        if (selectedItems == null) {
            return;
        }
        if (isSearchActive()) {
            List<List<ContentEntry>> contentEntries = new ArrayList<>();
            for (PlaylistEntry playlistEntry : selectedItems) {
                ContentEntryInfo entryInfo = SearchService.getInstance().getSearchItems(playlistEntry.getId(), playlistEntry.getCategory());
                List<ContentEntry> entries = entryInfo.getContentEntry().stream().filter(item -> item.getName().toLowerCase().endsWith(".sid")).collect(Collectors.toList());
                List<ContentEntry> tmp = new ArrayList<>();
                tmp.addAll(entries);
                contentEntries.add(tmp);
            }
            boolean addable = !contentEntries.stream().filter(item -> item.size() > 1).findFirst().isPresent();
            if (event.getButton() == MouseButton.SECONDARY || event.isControlDown()) {
                if (addable) {
                    final ContextMenu contextMenu = new ContextMenu();
                    Menu addToPlaylist = new Menu("Add to playlist");
                    for (PlaylistInfo plist : playListService.getPlaylistInfo()) {
                        PlaylistMenuItem mItem = new PlaylistMenuItem(plist);
                        mItem.setOnAction((ActionEvent event2) -> {
                            PlaylistMenuItem item = (PlaylistMenuItem) event2.getSource();
                            if (Support.isPlaylistMine(item.getPlaylist())) {
                                playListService.addSongs(item.getPlaylist(), selectedItems, contentEntries);
                                songlist.getSelectionModel().clearSelection();
                            } else {
                                GenericMessageDialogController.withErrorProps("Sidify", "You can not add song to public lists!").showAndWait();
                            }
                        });
                        addToPlaylist.getItems().add(mItem);
                    }
                    MenuItem mItem = new MenuItem("Add to new playlist");
                    mItem.setOnAction((ActionEvent event2) -> {
                        SidifyCreatePlaylistController controller = GuiUtils.showDialog("sidifyCreateNewPlaylist.fxml", Boolean.TRUE, "Create new playlist", getStage(), new Object[] { null, false });
                        PlaylistInfo newPlaylist = controller.getNewlyCreatedPlayList();
                        if (newPlaylist != null) {
                            playListService.addSongs(newPlaylist, selectedItems, contentEntries);
                            songlist.getSelectionModel().clearSelection();
                            populateLeftList();
                        }
                    });
                    addToPlaylist.getItems().add(mItem);
                    contextMenu.getItems().add(addToPlaylist);
                    songlist.setContextMenu(contextMenu);
                } else {
                    // If we have more than one entry and
                    // want to add all
                    final ContextMenu contextMenu = new ContextMenu();
                    long nofSids = contentEntries.stream().collect(Collectors.summarizingInt(item -> item.size())).getSum();
                    Menu addToPlaylist = new Menu("Add all (" + nofSids + ") songs to playlist");
                    for (PlaylistInfo plist : playListService.getPlaylistInfo()) {
                        ContentEntryInfoMenuItem mItem = new ContentEntryInfoMenuItem(plist.getName(), contentEntries);
                        mItem.setOnAction((ActionEvent event2) -> {
                            ContentEntryInfoMenuItem item = (ContentEntryInfoMenuItem) event2.getSource();
                            playListService.addSongs(plist, selectedItems, item.getContentEntries());
                            songlist.getSelectionModel().clearSelection();
                            populateLeftList();
                        });
                        addToPlaylist.getItems().add(mItem);
                    }
                    contextMenu.getItems().add(addToPlaylist);
                    MenuItem mItem = new MenuItem("Add to new playlist");
                    mItem.setOnAction((ActionEvent event2) -> {
                        SidifyCreatePlaylistController controller = GuiUtils.showDialog("sidifyCreateNewPlaylist.fxml", Boolean.TRUE, "Create new playlist", getStage(), new Object[] { null, false });
                        PlaylistInfo newPlaylist = controller.getNewlyCreatedPlayList();
                        ContentEntryInfoMenuItem cmItem = new ContentEntryInfoMenuItem(newPlaylist.getName(), contentEntries);
                        if (newPlaylist != null) {
                            playListService.addSongs(newPlaylist, selectedItems, cmItem.getContentEntries());
                            songlist.getSelectionModel().clearSelection();
                            populateLeftList();
                        }
                    });
                    addToPlaylist.getItems().add(mItem);
                    songlist.setContextMenu(contextMenu);
                }
            } else {
                if (event.getClickCount() == 2) {
                    setBackgroundplaylistState();
                    try {
                        if (contentEntries.size() == 1 && contentEntries.get(0).size() == 1) {
                            setNewSongPlayingState(false);
                            selectedItems.get(0).setFileId(contentEntries.get(0).get(0).getId());
                            startSwitchSongLoopFromScratch();
                        } else {
                            GuiUtils.showDialog("sidifyViewMultipeSongs.fxml", Boolean.TRUE, "Choose", getStage(), new Object[] { Support.flattenAndEnrichEntries(selectedItems, contentEntries) });
                            refreshPlaylistIfNeeded(playListService.getPlaylistForSong(selectedItems.get(0)));
                            populateLeftList();
                        }
                    } catch (Exception e) {
                        LOGGER.error("Unable to play item", e);
                    }
                }
            }
        } else {
            List<List<ContentEntry>> contentEntries = new ArrayList<>();
            for (PlaylistEntry playlistEntry : selectedItems) {
                List<ContentEntry> tmp = new ArrayList<>();
                ContentEntry entry = new ContentEntry();
                entry.setFullPlaylistInfo(playlistEntry);
                entry.setId(playlistEntry.getFileId());
                entry.setName(playlistEntry.getName());
                tmp.add(entry);
                contentEntries.add(tmp);
            }
            setBackgroundplaylistState();
            if ((event.getButton() == MouseButton.SECONDARY || event.isControlDown()) && !isOffline()) {
                final ContextMenu contextMenu = new ContextMenu();
                Menu addToPlaylist = new Menu("Add to playlist");
                for (PlaylistInfo plist : playListService.getPlaylistInfo()) {
                    PlaylistMenuItem mItem = new PlaylistMenuItem(plist);
                    mItem.setOnAction((ActionEvent event2) -> {
                        PlaylistMenuItem item = (PlaylistMenuItem) event2.getSource();
                        if (Support.isPlaylistMine(item.getPlaylist())) {
                            playListService.addSongs(item.getPlaylist(), selectedItems, contentEntries);
                            PlaylistInfo currentPlaylist = playListService.getPlaylistForSong(selectedItems.get(0));
                            refreshPlaylistIfNeeded(currentPlaylist);
                            songlist.getSelectionModel().clearSelection();
                        } else {
                            GenericMessageDialogController.withErrorProps("Sidify", "You can not add song to public lists!").showAndWait();
                        }
                    });
                    addToPlaylist.getItems().add(mItem);
                }
                contextMenu.getItems().add(addToPlaylist);
                MenuItem mItem = new MenuItem("Add to new playlist");
                mItem.setOnAction((ActionEvent event2) -> {
                    SidifyCreatePlaylistController controller = GuiUtils.showDialog("sidifyCreateNewPlaylist.fxml", Boolean.TRUE, "Create new playlist", getStage(), new Object[] { null, false });
                    PlaylistInfo newPlaylist = controller.getNewlyCreatedPlayList();
                    ContentEntryInfoMenuItem cmItem = new ContentEntryInfoMenuItem(newPlaylist.getName(), contentEntries);
                    if (newPlaylist != null) {
                        playListService.addSongs(newPlaylist, selectedItems, cmItem.getContentEntries());
                        songlist.getSelectionModel().clearSelection();
                        populateLeftList();
                    }
                });
                addToPlaylist.getItems().add(mItem);
                if (isPlaylistMine(playListService.getPlaylistForSong(selectedItems.get(0)))) {
                    PlaylistEntryMenuItem deleteItem = new PlaylistEntryMenuItem("Delete", selectedItems);
                    deleteItem.setOnAction((ActionEvent event2) -> {
                        PlaylistEntryMenuItem item = (PlaylistEntryMenuItem) event2.getSource();
                        PlaylistInfo currentPlaylist = playListService.getPlaylistForSong(item.getPlaylistEntry());
                        playListService.deleteSongs(currentPlaylist, item.getPlaylistEntries());
                        songlist.getSelectionModel().clearSelection();
                        populateLeftList();
                        refreshPlaylistIfNeeded(currentPlaylist);
                    });
                    contextMenu.getItems().add(deleteItem);
                }
                songlist.setContextMenu(contextMenu);
            } else if (event.getClickCount() == 2) {
                setNewSongPlayingState(false);
                startSwitchSongLoopFromScratch();
                populateLeftList();
            }
        }
    });
    searchField.setOnKeyReleased((event) -> {
        if (event.getCode() == KeyCode.ENTER) {
            doSearch(searchField.getText());
        }
    });
    try {
        searchPeriod.getSelectionModel().selectedItemProperty().addListener((ObservableValue<? extends SEARCH_PERIOD> observable, SEARCH_PERIOD oldValue, SEARCH_PERIOD newValue) -> doSearch(searchField.getText()));
    } catch (Exception e) {
        LOGGER.info("Unable to add listener", e);
    }
    disableSearch();
    workQueue = new ArrayBlockingQueue<>(1000);
    Executors.newSingleThreadExecutor().execute(() -> {
        while (true) {
            try {
                Object queueItem = workQueue.take();
                if (queueItem instanceof PoisonPill) {
                    break;
                } else if (queueItem instanceof PlaylistInfo) {
                    downloadPlaylistOffline((PlaylistInfo) queueItem, true);
                } else if (queueItem instanceof String && ((String) queueItem).equals("checklists")) {
                    for (PlaylistInfo pInfo : playListService.getPlaylistInfo()) {
                        if (pInfo.isAvailableOffline()) {
                            downloadPlaylistOffline(pInfo, false);
                        }
                    }
                }
            } catch (Exception e) {
            }
        }
    });
    if (!isOffline()) {
        checkOfflineScheduler = Executors.newScheduledThreadPool(1);
        checkOfflineScheduler.scheduleAtFixedRate(() -> {
            workQueue.offer("checklists");
        }, 5, 10, TimeUnit.SECONDS);
    }
}
Also used : EventHandler(javafx.event.EventHandler) Support.isOffline(se.light.assembly64.Support.isOffline) ListCell(javafx.scene.control.ListCell) LoggerFactory(org.slf4j.LoggerFactory) Random(java.util.Random) PathService(se.light.assembly64.service.PathService) StringUtils(org.apache.commons.lang3.StringUtils) ContentEntryInfo(se.light.assembly64.model.ContentEntryInfo) CachedImageService(se.light.assembly64.service.CachedImageService) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ContextMenu(javafx.scene.control.ContextMenu) WindowEvent(javafx.stage.WindowEvent) TableView(javafx.scene.control.TableView) ContentEntry(se.light.assembly64.model.ContentEntry) Pane(javafx.scene.layout.Pane) TextField(javafx.scene.control.TextField) PlaylistEntryMenuItem(se.light.assembly64.model.PlaylistEntryMenuItem) MenuItem(javafx.scene.control.MenuItem) PropertyValueFactory(javafx.scene.control.cell.PropertyValueFactory) SidTune(libsidplay.sidtune.SidTune) SidFileInfo(se.light.assembly64.model.SidFileInfo) Set(java.util.Set) BlockingQueue(java.util.concurrent.BlockingQueue) SearchException(se.light.assembly64.model.SearchException) Collectors(java.util.stream.Collectors) Executors(java.util.concurrent.Executors) Platform(javafx.application.Platform) FXML(javafx.fxml.FXML) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) List(java.util.List) DataFormat(javafx.scene.input.DataFormat) PlaylistMenuItem(se.light.assembly64.model.PlaylistMenuItem) AnchorPane(javafx.scene.layout.AnchorPane) ObservableList(javafx.collections.ObservableList) ClipboardContent(javafx.scene.input.ClipboardContent) ReturningTask(se.light.assembly64.model.ReturningTask) MouseButton(javafx.scene.input.MouseButton) ListView(javafx.scene.control.ListView) PlaylistEntry(se.light.assembly64.model.PlaylistEntry) MouseEvent(javafx.scene.input.MouseEvent) SearchService(se.light.assembly64.service.SearchService) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) FXCollections(javafx.collections.FXCollections) PoisonPill(se.light.assembly64.model.PoisonPill) PlaylistInfo(se.light.assembly64.model.PlaylistInfo) GlobalRepoService(se.light.assembly64.service.GlobalRepoService) TransferMode(javafx.scene.input.TransferMode) ArrayList(java.util.ArrayList) TableColumn(javafx.scene.control.TableColumn) Support.isSearchActive(se.light.assembly64.Support.isSearchActive) Dragboard(javafx.scene.input.Dragboard) Slider(javafx.scene.control.Slider) GuiUtils(se.light.assembly64.util.GuiUtils) Support(se.light.assembly64.Support) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) MetadataService(se.light.assembly64.fx.mdresolve.MetadataService) DownloadArtifactsService(se.light.assembly64.service.DownloadArtifactsService) PlaylistService(se.light.assembly64.service.PlaylistService) BaseGuiController(se.light.assembly64.model.BaseGuiController) Analytics(se.light.assembly64.Analytics) KeyCode(javafx.scene.input.KeyCode) Logger(org.slf4j.Logger) Label(javafx.scene.control.Label) ExecutorUtil(se.light.assembly64.util.ExecutorUtil) TargetAndPath(se.light.assembly64.model.TargetAndPath) TableRow(javafx.scene.control.TableRow) ContentEntryInfoMenuItem(se.light.assembly64.model.ContentEntryInfoMenuItem) Support.resolveFilename(se.light.assembly64.Support.resolveFilename) Support.setSearchActive(se.light.assembly64.Support.setSearchActive) SongNotAvailableException(se.light.assembly64.model.SongNotAvailableException) Support.isPlaylistMine(se.light.assembly64.Support.isPlaylistMine) File(java.io.File) ChoiceBox(javafx.scene.control.ChoiceBox) Menu(javafx.scene.control.Menu) SIDPlayerService(se.light.assembly64.service.SIDPlayerService) TimeUnit(java.util.concurrent.TimeUnit) ActionEvent(javafx.event.ActionEvent) SpecifyFileIdException(se.light.assembly64.model.SpecifyFileIdException) SelectionMode(javafx.scene.control.SelectionMode) Stage(javafx.stage.Stage) ImageView(javafx.scene.image.ImageView) LocalDBService(se.light.assembly64.service.LocalDBService) ObservableValue(javafx.beans.value.ObservableValue) SEARCH_PERIOD(se.light.assembly64.Support.SEARCH_PERIOD) Comparator(java.util.Comparator) ChangeListener(javafx.beans.value.ChangeListener) Collections(java.util.Collections) Image(javafx.scene.image.Image) PlaylistEntryMenuItem(se.light.assembly64.model.PlaylistEntryMenuItem) PoisonPill(se.light.assembly64.model.PoisonPill) ActionEvent(javafx.event.ActionEvent) Label(javafx.scene.control.Label) ArrayList(java.util.ArrayList) ObservableValue(javafx.beans.value.ObservableValue) PlaylistMenuItem(se.light.assembly64.model.PlaylistMenuItem) List(java.util.List) ObservableList(javafx.collections.ObservableList) ArrayList(java.util.ArrayList) ImageView(javafx.scene.image.ImageView) PlaylistInfo(se.light.assembly64.model.PlaylistInfo) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Dragboard(javafx.scene.input.Dragboard) ContentEntryInfo(se.light.assembly64.model.ContentEntryInfo) SEARCH_PERIOD(se.light.assembly64.Support.SEARCH_PERIOD) TableRow(javafx.scene.control.TableRow) ContentEntryInfoMenuItem(se.light.assembly64.model.ContentEntryInfoMenuItem) ClipboardContent(javafx.scene.input.ClipboardContent) ContextMenu(javafx.scene.control.ContextMenu) ContextMenu(javafx.scene.control.ContextMenu) Menu(javafx.scene.control.Menu) MouseEvent(javafx.scene.input.MouseEvent) PlaylistEntryMenuItem(se.light.assembly64.model.PlaylistEntryMenuItem) MenuItem(javafx.scene.control.MenuItem) PlaylistMenuItem(se.light.assembly64.model.PlaylistMenuItem) ContentEntryInfoMenuItem(se.light.assembly64.model.ContentEntryInfoMenuItem) SearchException(se.light.assembly64.model.SearchException) SongNotAvailableException(se.light.assembly64.model.SongNotAvailableException) SpecifyFileIdException(se.light.assembly64.model.SpecifyFileIdException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ContentEntry(se.light.assembly64.model.ContentEntry) WindowEvent(javafx.stage.WindowEvent) PlaylistEntry(se.light.assembly64.model.PlaylistEntry)

Aggregations

ActionEvent (javafx.event.ActionEvent)4 ContextMenu (javafx.scene.control.ContextMenu)4 Menu (javafx.scene.control.Menu)4 MenuItem (javafx.scene.control.MenuItem)4 PlaylistInfo (se.light.assembly64.model.PlaylistInfo)3 PlaylistMenuItem (se.light.assembly64.model.PlaylistMenuItem)3 File (java.io.File)2 Label (javafx.scene.control.Label)2 ContentEntry (se.light.assembly64.model.ContentEntry)2 PlaylistEntry (se.light.assembly64.model.PlaylistEntry)2 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1 List (java.util.List)1 Random (java.util.Random)1 Set (java.util.Set)1 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)1 BlockingQueue (java.util.concurrent.BlockingQueue)1 Executors (java.util.concurrent.Executors)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1