Class New.NewAction

    • 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)
      Returns true 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)
      Returns true if this action is applicable to any of the specified Members.
      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, or null 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 java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • 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 override createFile(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 action
        defaultFileName - the default name used to create a new file
        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)
        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 action
        defaultFileName - the default base name (no extension) used to create a new file
        extension - the file name extension to use for the new file
        resourceFile - the resource that will be copied to create an empty new file, or null
        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 action
        defaultFileName - the default base name (no extension) used to create a new file
        extension - the file name extension to use for the new file
        resourceFile - the resource that will be copied to create an empty new file, or null
        icon - the icon to display as the file type icon
        taskType - 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 class TaskAction
        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, or null if the action should not be associated with an icon.
        Specified by:
        getIcon in interface IconProvider
        Overrides:
        getIcon in class TaskAction
        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 class TaskAction
        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 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
      • 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 file
        f - 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 is null, 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)
        Returns true if the target is any kind of folder (including a project or task) and the task type restrictions (if any) are met. 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
      • 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