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 interface
Rename.RenameListener
A 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 void
addRenameListener(Rename.RenameListener listener)
Adds a new listener for file rename events.boolean
appliesTo(Project project, Task task, Member member)
Returnstrue
if this action can be performed on the specified member of a project, project or a task.boolean
appliesToSelection(Member[] members)
Returnstrue
if this action is applicable to any of the specifiedMember
s.java.lang.String
getLabel()
Returns the human-readable name of this action.boolean
perform(Project project, Task task, Member member)
Perform this action on a member of a project, a project or a task.static void
removeRenameListener(Rename.RenameListener listener)
Removes a rename event listener.static java.io.File
rename(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.File
rename(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:TaskAction
Returns the human-readable name of this action.- Specified by:
getLabel
in 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:TaskAction
Returnstrue
if this action is applicable to any of the specifiedMember
s. 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 ofmembers
and returningfalse
if it is not 1, and otherwise calling the super implementation.- Overrides:
appliesToSelection
in classTaskAction
- 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
Returnstrue
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
andmember
will benull
. If a task is the target, thenmember
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 returnfalse
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 classTaskAction
- Parameters:
project
- the project that is being acted upontask
- the task within the project that is being acted upon;null
if acting on a projectmember
- 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
andmember
will benull
. If a task is the target, thenmember
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 returnfalse
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 classTaskAction
- Parameters:
project
- the project that is being acted upontask
- the task within the project that is being acted upon;null
if acting on a projectmember
- 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.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
-
-