Class New.NewAction
- java.lang.Object
-
- ca.cgjennings.apps.arkham.project.TaskAction
-
- ca.cgjennings.apps.arkham.project.New.NewAction
-
- All Implemented Interfaces:
IconProvider
- Direct Known Subclasses:
DocumentTask.DocumentType
- Enclosing class:
- New
public static class New.NewAction extends TaskAction
A useful class for adding actions toNew. It is not required: you can use anyTaskAction.
-
-
Constructor Summary
Constructors Constructor Description NewAction(java.lang.String label, java.lang.String defaultFileName, java.lang.String extension, java.lang.String resourceFile, javax.swing.Icon icon)Create a new action that will create a new empty file by copying a template file from a resource.NewAction(java.lang.String label, java.lang.String defaultFileName, java.lang.String extension, java.lang.String resourceFile, javax.swing.Icon icon, java.lang.String taskType)Create a new action that will create a new empty file by copying a template file from a resource.NewAction(java.lang.String label, java.lang.String defaultFileName, javax.swing.Icon icon)Create a new action that you will supply your own file creation logic for.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanappliesTo(Project project, Task task, Member member)Returnstrueif the target is any kind of folder (including a project or task) and the task type restrictions (if any) are met.booleanappliesToSelection(Member[] members)Returnstrueif this action is applicable to any of the specifiedMembers.voidcreateFile(java.io.File file)Creates a file of the type represented by this action.java.lang.StringgetActionName()Returns a unique internal name for this action.java.lang.StringgetFileExtension()Returns the file extension of the files created by this action.ThemedIcongetIcon()Returns an icon for this action, ornullif the action should not be associated with an icon.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.protected voidrenameFile(Member parent, java.io.File f)Called after creating the file to give the user a chance to rename it.-
Methods inherited from class ca.cgjennings.apps.arkham.project.TaskAction
applyToChildren, getDescription, performOnSelection, resolveTarget, toString
-
-
-
-
Constructor Detail
-
NewAction
public NewAction(java.lang.String label, java.lang.String defaultFileName, javax.swing.Icon icon)Create a new action that you will supply your own file creation logic for. You must overridecreateFile(java.io.File)in order to create the new project file; otherwise the default behaviour is to create a folder.- Parameters:
label- the name of the actiondefaultFileName- the default name used to create a new fileicon- the icon to display as the file type icon
-
NewAction
public NewAction(java.lang.String label, java.lang.String defaultFileName, java.lang.String extension, java.lang.String resourceFile, javax.swing.Icon icon)Create a new action that will create a new empty file by copying a template file from a resource.- Parameters:
label- the name of the actiondefaultFileName- the default base name (no extension) used to create a new fileextension- the file name extension to use for the new fileresourceFile- the resource that will be copied to create an empty new file, ornullicon- the icon to display as the file type icon
-
NewAction
public NewAction(java.lang.String label, java.lang.String defaultFileName, java.lang.String extension, java.lang.String resourceFile, javax.swing.Icon icon, java.lang.String taskType)Create a new action that will create a new empty file by copying a template file from a resource. The action will only apply within task folders of the specified type.- Parameters:
label- the name of the actiondefaultFileName- the default base name (no extension) used to create a new fileextension- the file name extension to use for the new fileresourceFile- the resource that will be copied to create an empty new file, ornullicon- the icon to display as the file type icontaskType- the code for the task type that this action is restricted to, or a comma separated list of such task types;nullto allow the action to apply anywhere
-
-
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
-
getIcon
public ThemedIcon getIcon()
Description copied from class:TaskActionReturns an icon for this action, ornullif the action should not be associated with an icon.- Specified by:
getIconin interfaceIconProvider- Overrides:
getIconin classTaskAction- Returns:
- an icon that represents the action
-
getActionName
public java.lang.String getActionName()
Description copied from class:TaskActionReturns a unique internal name for this action. Actions can be looked up by this name. The default implementation returns the class name, converted to lowercase.- Overrides:
getActionNamein classTaskAction- Returns:
- the internal name of this action
-
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
-
renameFile
protected void renameFile(Member parent, java.io.File f) throws java.io.IOException
Called after creating the file to give the user a chance to rename it. Override to change rename behaviour. The base class selects the file in the project view, then looks up and applies the "rename" task action.- Parameters:
parent- the project member that is a parent of the new filef- the newly created file- Throws:
java.io.IOException- if an error occurs while renaming
-
createFile
public void createFile(java.io.File file) throws java.io.IOExceptionCreates a file of the type represented by this action. The base class copies the specified resource file to the destination. (If the resource file isnull, it creates a folder.)- Parameters:
file- the file to be created- Throws:
java.io.IOException- if an error occurs while creating the file (if the method throws this, an error message will be displayed)
-
getFileExtension
public java.lang.String getFileExtension()
Returns the file extension of the files created by this action.- Returns:
- the file extension
-
appliesTo
public boolean appliesTo(Project project, Task task, Member member)
Returnstrueif the target is any kind of folder (including a project or task) and the task type restrictions (if any) are met. Returnstrueif 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
-
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
-
-