Class ReArrangePlayListAction

    • Method Detail

      • reArrangePlayList

        public void reArrangePlayList​(PlayList playList,
                                      long[] selectedSongIds)

        You may override this method to provide a custom implementation for playlist re-arrangement. But instead of overriding, you might want to opt for the much simple approach of providing a custom function via setReArrangeFunction(BiFunction) or the corresponding constructor.

        This method is called by the action as part of its actionPerformed(ActionEvent) method. You are given an existing playlist and the ids of the currently selected songs, if isRequiresSelectedSongs() is true.

        Note that the most efficient way to move stuff around is to create a new order of ids and then simply set those ids using PlayList.setSongIds(java.util.List). Alternatively, load all songs from the playlist, re-arrange them in memory and set them with PlayList.setSongs(List) — this is essentially what happens when using the re-arrangement function.

        You may also modify the playlist object itself, e.g. change the default name programmatically.

        Note that you are not called from either the EDT or the default database thread, but an independent thread. This means, that you may block this thread indefinitely (of course you shouldn't though!). It also means, that from this thread you should invoke UI code using SwingUtilities.invokeAndWait(Runnable).

        The default implementation of this method uses the set reArrangeFunction to create a new order. If no custom function is set, identity is used.

        Parameters:
        playList - existing playlist
        selectedSongIds - selected song ids or an empty array, if isRequiresSelectedSongs() is false
      • isRequiresSelectedSongs

        public boolean isRequiresSelectedSongs()
        Indicates whether beaTunes should provide the ids of the selected songs in reArrangePlayList(PlayList, long[]).
        Returns:
        true (default) or false
      • setRequiresSelectedSongs

        public void setRequiresSelectedSongs​(boolean requiresSelectedSongs)
        Call this from the constructor to determine, whether reArrangePlayList(PlayList, long[]) should be called with the ids of selected songs.
        Parameters:
        requiresSelectedSongs - true or false
      • loadResources

        protected void loadResources()
        Installs enabled/disabled listeners that turn the action on and off, depending on whether the current playlist is editable at all (some lists, like Music are not editable). Override this method, if you desire a different enable/disable behavior.
        Overrides:
        loadResources in class BaseAction
      • actionPerformed

        public void actionPerformed​(ActionEvent e)