Class ScriptItem

java.lang.Object
org.omegat.gui.scripting.ScriptItem
All Implemented Interfaces:
Comparable<ScriptItem>

public class ScriptItem extends Object implements Comparable<ScriptItem>
A script file in the script list is represented as ScriptListFile to allow for localization, description and reordering.
  • Constructor Details

    • ScriptItem

      public ScriptItem(@NotNull @NotNull String scriptSource)
      Creates a new ScriptItem with the specified script source.
      Parameters:
      scriptSource - the source code of the script. This must not be null.
    • ScriptItem

      public ScriptItem(@NotNull @NotNull File scriptFile)
      Constructs a new ScriptItem based on the provided script file. This constructor initializes the ScriptItem with a reference to the script file and prepares any associated resources, such as a ResourceBundle for localization.
      Parameters:
      scriptFile - the script file to be associated with this ScriptItem. This file must not be null and should represent the source of the script.
  • Method Details

    • getResourceBundle

      @NotNull public @NotNull ResourceBundle getResourceBundle()
      When the properties file is provided, it returns a resource bundle for the script item. Otherwise, it returns an empty resource bundle, which raises MissingResourceException when the resource is requested.
      Returns:
      the resource bundle for this script item
    • getScriptName

      public String getScriptName()
      The name of the script when it is created from a file. If the script provides a resource bundle for localization, it returns the name from the bundle. Otherwise, it returns the name of the file.
      Returns:
      the name of the script
    • getFileName

      @NotNull public @NotNull String getFileName()
      The name of the file containing the script when the item was created from the file. Otherwise, it is the name of the editor script.
      Returns:
      the name of the file containing the script
    • getFile

      @Nullable public @Nullable File getFile()
    • getDescription

      public String getDescription()
    • getToolTip

      public String getToolTip()
      Generates a tooltip text for the script item by combining its script name and description. If the description is empty, only the script name is returned.
      Returns:
      the tooltip text representing the script item, combining its name and description, or just the name if the description is empty
    • getText

      public String getText() throws IOException
      Throws:
      IOException
    • setText

      public void setText(@NotNull @NotNull String text) throws IOException
      Updates the text content of the script associated with this ScriptItem. If the source file exists, the provided text is processed for line breaks and optionally includes a BOM before being written to the file. If the source file is null, an exception is thrown.
      Parameters:
      text - the new text content to be written to the script's source file. This parameter must not be null.
      Throws:
      IOException - if the source file does not exist or an error occurs while writing to the file.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • compareTo

      public int compareTo(ScriptItem o)
      Specified by:
      compareTo in interface Comparable<ScriptItem>