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