Search in sources :

Example 1 with TabbedPreferencesAction

use of apps.gui3.TabbedPreferencesAction in project JMRI by JMRI.

the class JmriConfigurationManager method load.

@Override
public boolean load(URL file, boolean registerDeferred) throws JmriException {
    log.debug("loading {} ...", file);
    try {
        if (file == null || //NOI18N
        (new File(file.toURI())).getName().equals("ProfileConfig.xml") || (new File(file.toURI())).getName().equals(Profile.CONFIG)) {
            Profile profile = ProfileManager.getDefault().getActiveProfile();
            List<PreferencesManager> providers = new ArrayList<>(InstanceManager.getList(PreferencesManager.class));
            providers.stream().forEach((provider) -> {
                this.initializeProvider(provider, profile);
            });
            if (!this.initializationExceptions.isEmpty()) {
                if (!GraphicsEnvironment.isHeadless()) {
                    ArrayList<String> errors = new ArrayList<>();
                    this.initialized.forEach((provider) -> {
                        List<Exception> exceptions = provider.getInitializationExceptions(profile);
                        if (!exceptions.isEmpty()) {
                            exceptions.forEach((exception) -> {
                                errors.add(exception.getLocalizedMessage());
                            });
                        } else if (this.initializationExceptions.get(provider) != null) {
                            errors.add(this.initializationExceptions.get(provider).getLocalizedMessage());
                        }
                    });
                    Object list;
                    if (errors.size() == 1) {
                        list = errors.get(0);
                    } else {
                        list = new JList<>(errors.toArray(new String[errors.size()]));
                    }
                    JOptionPane.showMessageDialog(null, new Object[] { (list instanceof JList) ? Bundle.getMessage("InitExMessageListHeader") : null, list, // Add a visual break between list of errors and notes // NOI18N
                    "<html><br></html>", // NOI18N
                    Bundle.getMessage("InitExMessageLogs"), // NOI18N
                    Bundle.getMessage("InitExMessagePrefs") }, // NOI18N
                    Bundle.getMessage("InitExMessageTitle", Application.getApplicationName()), JOptionPane.ERROR_MESSAGE);
                    (new TabbedPreferencesAction()).actionPerformed();
                }
            }
            if (file != null && (new File(file.toURI())).getName().equals("ProfileConfig.xml")) {
                // NOI18N
                log.debug("Loading legacy configuration...");
                return this.legacy.load(file, registerDeferred);
            }
            return this.initializationExceptions.isEmpty();
        }
    } catch (URISyntaxException ex) {
        log.error("Unable to get File for {}", file);
        throw new JmriException(ex.getMessage(), ex);
    }
    return this.legacy.load(file, registerDeferred);
// return true; // always return true once legacy support is dropped
}
Also used : TabbedPreferencesAction(apps.gui3.TabbedPreferencesAction) ArrayList(java.util.ArrayList) JmriException(jmri.JmriException) URISyntaxException(java.net.URISyntaxException) PreferencesManager(jmri.spi.PreferencesManager) Profile(jmri.profile.Profile) URISyntaxException(java.net.URISyntaxException) InitializationException(jmri.util.prefs.InitializationException) JmriException(jmri.JmriException) File(java.io.File) XmlFile(jmri.jmrit.XmlFile) JList(javax.swing.JList)

Aggregations

TabbedPreferencesAction (apps.gui3.TabbedPreferencesAction)1 File (java.io.File)1 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 JList (javax.swing.JList)1 JmriException (jmri.JmriException)1 XmlFile (jmri.jmrit.XmlFile)1 Profile (jmri.profile.Profile)1 PreferencesManager (jmri.spi.PreferencesManager)1 InitializationException (jmri.util.prefs.InitializationException)1