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 boolean results = cm.makeBackup(file); 054 if (!results) { 055 JmriJOptionPane.showMessageDialog(null, 056 Bundle.getMessage("BackupError", file.getPath()) 057 + System.lineSeparator() + Bundle.getMessage("ConsoleWindowHasInfo"), 058 Bundle.getMessage("BackupError", ""), 059 JmriJOptionPane.ERROR_MESSAGE); 060 } 061 // and finally store 062 results = cm.storeUser(file); 063 log.debug("store {}", results ? "was successful" : "failed"); // NOI18N 064 if (!results) { 065 JmriJOptionPane.showMessageDialog(null, 066 Bundle.getMessage("StoreHasErrors") + "\n" // NOI18N 067 + Bundle.getMessage("StoreIncomplete") + "\n" // NOI18N 068 + Bundle.getMessage("ConsoleWindowHasInfo"), // NOI18N 069 Bundle.getMessage("StoreError"), JmriJOptionPane.ERROR_MESSAGE); // NOI18N 070 } 071 } 072 } 073 074 private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(StoreXmlUserAction.class); 075}