Class Open

  • All Implemented Interfaces:
    IconProvider

    public class Open
    extends TaskAction
    A task action that opens project files. How a file is handled when it is opened depends on the user's settings, which may specify rules for various file extensions. The default rule has Strange Eons first check if it knows how to open the file (either via a registered Open.InternalOpener or else via a built-in default file handling mechanism). If it does not know how to deal with the file itself, and if the platform supports this capability, the Strange Eons will ask the operating system to open the file if it knows how.
    Since:
    2.1
    Author:
    Chris Jennings
    • Field Detail

      • cascade

        protected int cascade
    • Constructor Detail

      • Open

        public Open()
    • 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
      • performOnSelection

        public boolean performOnSelection​(Member[] members)
        Description copied from class: TaskAction
        Applies this action to all of the specified project members. By overriding this, you can modify what happens when the user tries to initiate this action. For example, you could add a verification dialog and call the super implementation only if the user verifies the action.
        Overrides:
        performOnSelection in class TaskAction
        Returns:
        true if and only if the action is successfully applied to all of the members
      • 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
      • tryDesktopOpen

        public boolean tryDesktopOpen​(java.io.File f)
      • tryDesktopEdit

        public boolean tryDesktopEdit​(java.io.File f)
      • tryDesktopPrint

        public boolean tryDesktopPrint​(java.io.File f)
      • tryInternalOpen

        public boolean tryInternalOpen​(Project project,
                                       Member member,
                                       java.io.File f)
                                throws java.io.IOException
        Throws:
        java.io.IOException
      • runCommand

        public static boolean runCommand​(java.io.File f,
                                         java.lang.String commandString)
                                  throws java.io.IOException
        Runs a command as if for the Open.OpenRule.CUSTOM_COMMAND rule. See setRuleCommand(java.lang.String, java.lang.String) for details.
        Parameters:
        f - the file that the command applies to (used to complete %f variables).
        commandString - the command string to use
        Returns:
        true if the command is successfully started
        Throws:
        java.io.IOException - if an exception occurs while executing the command
      • splitCommand

        public static java.lang.String[] splitCommand​(java.lang.String commandString)
        Splits a command string into tokens by splitting on spaces unless those spaces are enclosed in a quote sequence. See setRuleCommand(java.lang.String, java.lang.String) for details.
        Parameters:
        commandString -
        Returns:
        an array of command line tokens
      • appliesTo

        public boolean appliesTo​(Project project,
                                 Task task,
                                 Member member)
        Description copied from class: TaskAction
        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
      • getRuleExtensions

        public static java.lang.String[] getRuleExtensions()
        Returns an array of the extensions for which an Open.OpenRule has been set.
        Returns:
        an array of file name extensions for which an explicit rule exists
      • setOpenRule

        public static void setOpenRule​(java.lang.String extension,
                                       Open.OpenRule rule)
        Sets the rule used to open files with the given extension. The rule will be applied to all files with the given extension unless a SpecializedAction overrides the standard open action. (Note that specializing the open action is not recommended. Instead, if you wish to add custom code to handle opening certain files, you should register an Open.InternalOpener with the standard open action.)
        Parameters:
        extension - the file extension to set the rule for
        rule - the rule to set
      • getOpenRule

        public static Open.OpenRule getOpenRule​(java.lang.String extension)
        Returns the Open.OpenRule that controls handling for files with the given file name extension. If no rule is explicitly set for an extension, the default rule is Open.OpenRule.INTERNAL_OPEN.
        Parameters:
        extension - the file extension to return a rule for
        Returns:
        the rule used when opening files with the given extension
      • deleteOpenRule

        public static void deleteOpenRule​(java.lang.String extension)
        Returns the rule that controls handling files with the given file name extension to its default state.
        Parameters:
        extension - the extension to revert to its default rule
      • setRuleCommand

        public static void setRuleCommand​(java.lang.String extension,
                                          java.lang.String commandString)
        Sets the command to execute when opening files with the given file name extension when they use the open rule Open.OpenRule.CUSTOM_COMMAND.

        The escape sequence %f will be replaced with the complete path to the file. (The sequence %% may be used to insert a plain percent sign.) Command line tokens that contain spaces must be enclosed in double quotes; to include a double quote within such a sequence it must be escaped as \".

        Parameters:
        extension - the file name extension to set the command string for
        commandString - the command string to use when opening such files
      • getRuleCommand

        public static java.lang.String getRuleCommand​(java.lang.String extension)
        Returns the command that is executed when opening files with the given file name extension if it uses the open rule Open.OpenRule.CUSTOM_COMMAND.
        Parameters:
        extension - the file name extension to get the command string for
        Returns:
        the command string used to open matching files