Class Rename

  • All Implemented Interfaces:
    IconProvider

    public class Rename
    extends TaskAction
    Task action for renaming project files. Also allows you to register listeners that will be notified when files are renamed (through the project system).
    Since:
    2.1
    Author:
    Chris Jennings
    • Constructor Detail

      • Rename

        public Rename()
    • Method Detail

      • getLabel

        public java.lang.String getLabel()
        Description copied from class: TaskAction
        Returns the human-readable name of this action.
        Specified by:
        getLabel in class TaskAction
        Returns:
        the name used to create menu items for this action, localized if possible
      • appliesToSelection

        public boolean appliesToSelection​(Member[] members)
        Description copied from class: TaskAction
        Returns true if this action is applicable to any of the specified Members. By overriding this, you can modify whether an action is listed depending on which other members are selected. For example, you could create a command that can only be applied to a singleton selection by checking the length of members and returning false if it is not 1, and otherwise calling the super implementation.
        Overrides:
        appliesToSelection in class TaskAction
        Parameters:
        members - a list of zero or more members
        Returns:
        true is the action can be applied to at least one member
      • appliesTo

        public boolean appliesTo​(Project project,
                                 Task task,
                                 Member member)
        Description copied from class: TaskAction
        Returns true if this action can be performed on the specified member of a project, project or a task. If the project itself is the target, task and member will be null. If a task is the target, then member will be null. If an error occurs while executing the task, then it is the action's responsibility to inform the user. This method can return false to indicate that if the action is being applied to multiple members, it should stop immediately rather than continue to the next member.
        Specified by:
        appliesTo in class TaskAction
        Parameters:
        project - the project that is being acted upon
        task - the task within the project that is being acted upon; null if acting on a project
        member - the specific member within the task to act upon; null if this is a project or task
      • perform

        public boolean perform​(Project project,
                               Task task,
                               Member member)
        Description copied from class: TaskAction
        Perform this action on a member of a project, a project or a task. If the project itself is the target, task and member will be null. If a task is the target, then member will be null. If an error occurs while executing the task, then it is the action's responsibility to inform the user. This method can return false to indicate that if the action is being applied to multiple members, it should stop immediately rather than continue to the next member.
        Specified by:
        perform in class TaskAction
        Parameters:
        project - the project that is being acted upon
        task - the task within the project that is being acted upon; null if acting on a project
        member - the specific member within the task to act upon; null if this is a project or task
      • rename

        @Deprecated
        public static java.io.File rename​(Member member,
                                          java.lang.String newFileName)
        Deprecated.
        Renames a member.
        Parameters:
        member - the member to rename
        newFileName - the new name for the member
        Returns:
        the new file; if the rename failed, this will be the original file
      • rename

        public static java.io.File rename​(Member member,
                                          java.io.File newFile,
                                          java.lang.String subfolders)
                                   throws java.io.IOException
        Rename a file in the project as if using this action, but without displaying a dialog. This is the recommended way to rename a project member, as it handles a number of special cases.

        Note that renaming a file should not be used to move a file to a different folder. In other words, the parent of the new file should be the same as the parent of the original file.

        Parameters:
        member - the member to rename
        newFile - the file object that specifies the new file name
        subfolders - if member is a folder, and this is non-null, then it is a slash-separated list of subfolders to create
        Returns:
        the new file
        Throws:
        java.lang.IllegalArgumentException - if the member is not a folder and subfolders is not null
        java.io.IOException
      • addRenameListener

        public static void addRenameListener​(Rename.RenameListener listener)
        Adds a new listener for file rename events. All instances of the rename action share a common listener list (there is normally only one instance). This makes it easier to register a listener because the rename action does not need to be looked up.
        Parameters:
        listener - the listener to be notified when files are renamed or deleted
      • removeRenameListener

        public static void removeRenameListener​(Rename.RenameListener listener)
        Removes a rename event listener. The listener will no longer receive rename events when a project file is renamed.
        Parameters:
        listener - the previously added listener