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 boolean
appliesTo(Project project, Task task, Member member)
Returnstrue
if the target is any kind of folder (including a project or task) and the task type restrictions (if any) are met.boolean
appliesToSelection(Member[] members)
Returnstrue
if this action is applicable to any of the specifiedMember
s.void
createFile(java.io.File file)
Creates a file of the type represented by this action.java.lang.String
getActionName()
Returns a unique internal name for this action.java.lang.String
getFileExtension()
Returns the file extension of the files created by this action.ThemedIcon
getIcon()
Returns an icon for this action, ornull
if the action should not be associated with an icon.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.protected void
renameFile(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, ornull
icon
- 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, ornull
icon
- 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;null
to allow the action to apply anywhere
-
-
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
-
getIcon
public ThemedIcon getIcon()
Description copied from class:TaskAction
Returns an icon for this action, ornull
if the action should not be associated with an icon.- Specified by:
getIcon
in interfaceIconProvider
- Overrides:
getIcon
in classTaskAction
- Returns:
- an icon that represents the action
-
getActionName
public java.lang.String getActionName()
Description copied from class:TaskAction
Returns 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:
getActionName
in classTaskAction
- Returns:
- the internal name of this action
-
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
-
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.IOException
Creates 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)
Returnstrue
if the target is any kind of folder (including a project or task) and the task type restrictions (if any) are met. 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
-
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
-
-