Class Rename
- java.lang.Object
-
- ca.cgjennings.apps.arkham.project.TaskAction
-
- ca.cgjennings.apps.arkham.project.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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceRename.RenameListenerA listener for file rename events.
-
Constructor Summary
Constructors Constructor Description Rename()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static voidaddRenameListener(Rename.RenameListener listener)Adds a new listener for file rename events.booleanappliesTo(Project project, Task task, Member member)Returnstrueif this action can be performed on the specified member of a project, project or a task.booleanappliesToSelection(Member[] members)Returnstrueif this action is applicable to any of the specifiedMembers.java.lang.StringgetLabel()Returns the human-readable name of this action.booleanperform(Project project, Task task, Member member)Perform this action on a member of a project, a project or a task.static voidremoveRenameListener(Rename.RenameListener listener)Removes a rename event listener.static java.io.Filerename(Member member, java.io.File newFile, java.lang.String subfolders)Rename a file in the project as if using this action, but without displaying a dialog.static java.io.Filerename(Member member, java.lang.String newFileName)Deprecated.Replaced byMember.renameFile(java.lang.String).-
Methods inherited from class ca.cgjennings.apps.arkham.project.TaskAction
applyToChildren, getActionName, getDescription, getIcon, performOnSelection, resolveTarget, toString
-
-
-
-
Method Detail
-
getLabel
public java.lang.String getLabel()
Description copied from class:TaskActionReturns the human-readable name of this action.- Specified by:
getLabelin classTaskAction- Returns:
- the name used to create menu items for this action, localized if possible
-
appliesToSelection
public boolean appliesToSelection(Member[] members)
Description copied from class:TaskActionReturnstrueif this action is applicable to any of the specifiedMembers. 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 ofmembersand returningfalseif it is not 1, and otherwise calling the super implementation.- Overrides:
appliesToSelectionin classTaskAction- Parameters:
members- a list of zero or more members- Returns:
trueis the action can be applied to at least one member
-
appliesTo
public boolean appliesTo(Project project, Task task, Member member)
Description copied from class:TaskActionReturnstrueif this action can be performed on the specified member of a project, project or a task. If the project itself is the target,taskandmemberwill benull. If a task is the target, thenmemberwill be null. If an error occurs while executing the task, then it is the action's responsibility to inform the user. This method can returnfalseto indicate that if the action is being applied to multiple members, it should stop immediately rather than continue to the next member.- Specified by:
appliesToin classTaskAction- Parameters:
project- the project that is being acted upontask- the task within the project that is being acted upon;nullif acting on a projectmember- the specific member within the task to act upon;nullif this is a project or task
-
perform
public boolean perform(Project project, Task task, Member member)
Description copied from class:TaskActionPerform this action on a member of a project, a project or a task. If the project itself is the target,taskandmemberwill benull. If a task is the target, thenmemberwill be null. If an error occurs while executing the task, then it is the action's responsibility to inform the user. This method can returnfalseto indicate that if the action is being applied to multiple members, it should stop immediately rather than continue to the next member.- Specified by:
performin classTaskAction- Parameters:
project- the project that is being acted upontask- the task within the project that is being acted upon;nullif acting on a projectmember- the specific member within the task to act upon;nullif this is a project or task
-
rename
@Deprecated public static java.io.File rename(Member member, java.lang.String newFileName)
Deprecated.Replaced byMember.renameFile(java.lang.String).Renames a member.- Parameters:
member- the member to renamenewFileName- 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 renamenewFile- the file object that specifies the new file namesubfolders- 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 nulljava.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
-
-