001package jmri.configurexml; 002 003import java.awt.event.ActionEvent; 004 005import javax.swing.JFileChooser; 006 007import jmri.ConfigureManager; 008import jmri.InstanceManager; 009import jmri.util.swing.JmriJOptionPane; 010 011/** 012 * Store the JMRI user-level information as XML. 013 * <P> 014 * Note that this does not store preferences, configuration, or tool information 015 * in the file. This is not a complete store! See {@link jmri.ConfigureManager} 016 * for information on the various types of information stored in configuration 017 * files. 018 * 019 * @author Bob Jacobsen Copyright (C) 2002 020 * @see jmri.jmrit.XmlFile 021 */ 022public class StoreXmlUserAction extends StoreXmlConfigAction { 023 024 public StoreXmlUserAction() { 025 this(Bundle.getMessage("MenuItemStore")); // NOI18N 026 } 027 028 public StoreXmlUserAction(String s) { 029 super(s); 030 } 031 032 @Override 033 public void actionPerformed(ActionEvent e) { 034 JFileChooser userFileChooser = getUserFileChooser(); 035 userFileChooser.setDialogType(javax.swing.JFileChooser.SAVE_DIALOG); 036 userFileChooser.setApproveButtonText(Bundle.getMessage("ButtonSave")); // NOI18N 037 userFileChooser.setDialogTitle(Bundle.getMessage("StoreTitle")); // NOI18N 038 java.io.File file = getFileCustom(userFileChooser); 039 040 if (file == null) { 041 return; 042 } 043 044 // make a backup file 045 ConfigureManager cm = InstanceManager.getNullableDefault(jmri.ConfigureManager.class); 046 if (cm == null) { 047 log.error("Failed to make backup due to unable to get default configure manager"); // NOI18N 048 } else { 049 cm.makeBackup(file); 050 // and finally store 051 boolean results = cm.storeUser(file); 052 log.debug("store {}", results ? "was successful" : "failed"); // NOI18N 053 if (!results) { 054 JmriJOptionPane.showMessageDialog(null, 055 Bundle.getMessage("StoreHasErrors") + "\n" // NOI18N 056 + Bundle.getMessage("StoreIncomplete") + "\n" // NOI18N 057 + Bundle.getMessage("ConsoleWindowHasInfo"), // NOI18N 058 Bundle.getMessage("StoreError"), JmriJOptionPane.ERROR_MESSAGE); // NOI18N 059 } 060 } 061 } 062 063 private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(StoreXmlUserAction.class); 064}