wiki:PLUGIN_SUPPORT_LIB_CONFIGURING_R1

Version 4 (modified by mitex, 16 years ago) (diff)

--

Error: Macro BackLinksMenu(None) failed
compressed data is corrupt

Error: Macro TicketQuery(summary=PLUGIN_SUPPORT_LIB_CONFIGURING_R1, format=table, col=summary|owner|status|type|component|priority|effort|importance, rows=description|analysis_owners|analysis_reviewers|analysis_score|design_owners|design_reviewers|design_score|implementation_owners|implementation_reviewers|implementation_score|test_owners|test_reviewers|test_score|) failed
current transaction is aborted, commands ignored until end of transaction block

Analysis

Overview

The goal of this task is to provide ability to load and save configuration settings that are not defined by skins. For example, bug reporting requires user's e-mail address to be persisted.

Task requirements

  • Configuration settings are stored as pairs (key, value).
  • Loading and saving configuration settings should be easy and made in uniform way:
    • get : key -> value - reads the value from configuration file.
    • set : key, value - updates the value so any part of Sophie that depends on it is updated.
  • Convention for configuration files:
    • Configuration files can be stored in distrib/conf/ directory of the corresponding plugin.
    • Their names should be unique for the application.
      • Use the name of the corresponding Sophie module, for example:
        • distrib/conf/org.sophie2.main.layout.mydoggy.conf
        • distrib/conf/org.sophie2.main.layout.mydoggy/some_name
    • Configuration files are saved in XML format.
    • Keys should be unique in a given configuration file, but there's no need to be globally unique, since the file names are unique.
  • Make at least one of the following settings to be persisted in configuration files:
    • User's e-mail address in the bug report form.
    • Main window's size, location and state (maximized/normal).
    • Current skin - default or alternative.

Task result

  • Source code.

Implementation idea

  • This functionality has much in common with skins, but cannot be implemented as skins. So create a new module.
  • Create a singleton class ConfigurationManager (or something else) that has the described get and set methods.
  • Create a class Configuration that represents a single configuration file.
    • Use list of ListEntrys that stores all key-value pairs in that file.

  • Create a generic class ConfigKey that encapsulates all of the information about a key:
    • key name
    • configuration file
    • default value (if the key is not present in the file)
    • schema (for the persistence)
  • ConfigKeys should be defined as constants in the code, for example:
    • public static final ConfigKey USER_EMAIL = ...;
    • email = ConfigurationManager.get().get(USER_EMAIL);

How to demo

  • Open Sophie.
  • Maximize the main window.
  • Open the bug report form (in Help menu) and enter a valid e-mail address.
  • Close the form.
  • Restart Sophie.
  • Show that the main window is maximized.
  • Open the bug report and show the saved e-mail address.

Design

  • Package org.sophie2.base.config.
  • Immutable generic class ConfigKey<T> that encapsulates all of the information about a key:
    • name (of the key) - String
    • configuration file - File
    • default value (if the key is not present in the file) - T
    • schema (for the persistence) - String, for example "imm:int|storage|decimal"
  • Class ConfigEntry that extends ListEntry
    • This class represents a key-value pair in a configuration file.
    • Override getKey to return a ConfigKey.
  • Class Configuration - represents a single configuration file.
    • configuration file - File
    • list property of ConfigEntrys that stores all key-value pairs in that file.
    • T getValue(ConfigKey<T> key) - searches the list for a given entry and returns the corresponding value or the default value for the key.
    • void setValue(ConfigKey<T> key, T value) - sets the value in the list and saves the configuration using the persister (see below).
    • When a Configuration for a given file is constructed, all entries are read from that file and stored in the list.
  • Class ConfigurationPersister that loads/saves configuration files.
    • Use the following structure for the storage, where "value" is the storage for the value of the configuration key, created with the according persister:
      • configuration
        • entry
          • key
          • value
        • entry
          • key
          • value
    • Register the persister as an extension.
  • Singleton class ConfigurationManager.
    • list of entries (String, Configuration), which maps Configuration objects to configuration file names.
    • T getValue(ConfigKey<T> key)
      • Given the file name in the key, finds the corresponding Configuration and then returns the result of Configuration.getValue.
    • setValue(ConfigKey<T> key, T value)
      • Given the file name in the key, finds the corresponding Configuration and sets the new value for that key.
  • Implement at least one of the following:
    • In BugReportLogic
      • Remove the file "distrib/email" and create a new one "distrib/conf/org.sophie2.main.func.help.conf".
      • Create a ConfigKey userEmail.
      • Remove the method readEmail and use getValue in ConfigurationManager.
      • In SAVE_EMAIL use setValue in ConfigurationManager.
    • In MDMainWindow
      • Create a ConfigKey windowSize of type ImmSize and set its default value to (1200, 900).
      • Remove the constants WINDOW_WIDTH, WINDOW_HEIGHT.
      • In globalContainer set the JFrame's size according to the value of the configuration key.

Implementation

(Describe and link the implementation results here (from the wiki or the repository).)

Testing

(Place the testing results here.)

Comments

(Write comments for this or later revisions here.)