Java Client Api for SettingsManager


    • How to use API
    • To generate or apply a settings file, read or write attributes will be done.
      The number and the response time of attributes is unknown and can be a quiet long.
      For this reason, the generate/apply calls will be executed and returned after a while.
      The generate/apply action will be done with a long TIMEOUT value.
        The default value is 5 seconds but it could be changed using:
      • SETTINGS_TIMEOUT VM property
      • SETTINGS_TIMEOUT environment variable
      The JAVA client API provides a listener (SettingsManagedListener) called after execution, giving an event (SettingsManagedEvent) containing execution information.

      
          import org.tango.settingsmanager.client.SettingsManagerClient;
          import org.tango.settingsmanager.client.SettingsManagedListener;
          import org.tango.settingsmanager.client.SettingsManagedEvent;
      
              - - - - -
               private SettingsManagerClient settingsClient;
              - - - - -
              //  Create a settings manager client and add a listener 
              settingsClient = new SettingsManagerClient(settingsProjectName);
              settingsClient.addSettingsAppliedListener(new SettingsManagedListener() {
                  @Override
                  public void settingsManaged(SettingsManagedEvent event) {
                      settingsAppliedPerformed(event);
                  }
              });
              - - - - -
                          


      Then to apply settings, the SettingsManagerClient object will call with apply method.
      This method will propose a file chooser to select a file to apply.
      This method will return the selected file name. If no selection, the file name will be null.
      If the file name is not null, after a while, the specified listener will be called.
      The SettingsManagedEvent event propose methods to get execution information.
      See following example:
      
          private void applySettingsItemActionPerformed(ActionEvent evt) {
              try {
                  //  Apply settings
                  settingsClient.setApproveButtonText("Apply");
                  String fileName = settingsClient.applySettings(this);
                  if (fileName!=null) {
                      System.out.println("Applying " + fileName);
                  }
              }
              catch (DevFailed e) {
                  ErrorPane.showErrorMessage(this, null, e);
              }
          }
          - - - - - -
          private void settingsAppliedPerformed(SettingsManagedEvent event) {
              String fileName = event.getFileName();
              switch (event.getAction()) {
                  case SettingsManagerClient.APPLIED:
                      //  Display applied results
                      if (event.hasFailed()) {
                          ErrorPane.showErrorMessage(new JFrame(),
                              "Applying file " + fileName, event.getDevFailed());
                      } else {
                          JOptionPane.showMessageDialog(new JFrame(),
                              "Settings loaded from  " + event.getFileName());
                      }
                      break;
                  case SettingsManagerClient.GENERATED:
                      //  Display generated results
                      if (event.hasFailed()) {
                          ErrorPane.showErrorMessage(new JFrame(),
                              "Generated file " + fileName, event.getDevFailed());
                      } else {
                          JOptionPane.showMessageDialog(new JFrame(),
                              "Settings saved in  " + event.getFileName());
                      }
                      break;
              }
          }