Search in sources :

Example 1 with FileChooserController

use of delta.games.lotro.utils.gui.filechooser.FileChooserController in project lotro-companion by dmorcellet.

the class CharacterFileWindowController method exportCharacterData.

private void exportCharacterData() {
    GenericTableController<CharacterData> controller = _toonsTable.getTableController();
    CharacterData data = controller.getSelectedItem();
    if (data != null) {
        FileChooserController ctrl = new FileChooserController("export", "Export character...");
        File toFile = ctrl.chooseFile(getWindow(), "Export");
        if (toFile != null) {
            boolean doIt = true;
            if (!toFile.getName().toLowerCase().endsWith(".xml")) {
                toFile = new File(toFile.getParentFile(), toFile.getName() + ".xml");
            }
            if (toFile.exists()) {
                doIt = false;
                int result = GuiFactory.showQuestionDialog(getFrame(), "Do you really want to overwrite the selected file?", "Overwrite?", JOptionPane.YES_NO_OPTION);
                if (result == JOptionPane.OK_OPTION) {
                    doIt = true;
                }
            }
            if (doIt) {
                File sourceFile = data.getFile();
                boolean ok = FileCopy.copy(sourceFile, toFile);
                Window window = getWindow();
                if (ok) {
                    GuiFactory.showInformationDialog(window, "Export OK!", "OK!");
                } else {
                    GuiFactory.showErrorDialog(window, "Export failed!", "Error!");
                }
            }
        }
    }
}
Also used : Window(java.awt.Window) CharacterData(delta.games.lotro.character.CharacterData) FileChooserController(delta.games.lotro.utils.gui.filechooser.FileChooserController) CharacterFile(delta.games.lotro.character.CharacterFile) File(java.io.File)

Example 2 with FileChooserController

use of delta.games.lotro.utils.gui.filechooser.FileChooserController in project lotro-companion by dmorcellet.

the class ToonsManagementController method importToon.

private void importToon() {
    FileChooserController ctrl = new FileChooserController("import", "Import character...");
    Window window = _parentController.getWindow();
    File fromFile = ctrl.chooseFile(window, "Import");
    if (fromFile != null) {
        CharacterXMLParser parser = new CharacterXMLParser();
        CharacterData data = new CharacterData();
        boolean ok = parser.parseXML(fromFile, data);
        if (ok) {
            CharactersManager manager = CharactersManager.getInstance();
            CharacterFile toon = manager.getToonById(data.getServer(), data.getName());
            if (toon != null) {
                CharacterInfosManager infos = toon.getInfosManager();
                ok = infos.writeNewCharacterData(data);
                if (ok) {
                    CharacterEvent event = new CharacterEvent(CharacterEventType.CHARACTER_DATA_ADDED, toon, data);
                    EventsManager.invokeEvent(event);
                }
            } else {
                CharacterFile newFile = manager.addToon(data);
                ok = (newFile != null);
            }
            if (ok) {
                GuiFactory.showInformationDialog(window, "Import OK!", "OK!");
            } else {
                GuiFactory.showErrorDialog(window, "Import failed!", "Error!");
            }
        } else {
            GuiFactory.showErrorDialog(window, "Import failed (bad XML file)!", "Error!");
        }
    }
}
Also used : Window(java.awt.Window) CharactersManager(delta.games.lotro.character.CharactersManager) CharacterEvent(delta.games.lotro.character.events.CharacterEvent) CharacterData(delta.games.lotro.character.CharacterData) FileChooserController(delta.games.lotro.utils.gui.filechooser.FileChooserController) CharacterXMLParser(delta.games.lotro.character.io.xml.CharacterXMLParser) CharacterInfosManager(delta.games.lotro.character.CharacterInfosManager) CharacterFile(delta.games.lotro.character.CharacterFile) File(java.io.File) CharacterFile(delta.games.lotro.character.CharacterFile)

Aggregations

CharacterData (delta.games.lotro.character.CharacterData)2 CharacterFile (delta.games.lotro.character.CharacterFile)2 FileChooserController (delta.games.lotro.utils.gui.filechooser.FileChooserController)2 Window (java.awt.Window)2 File (java.io.File)2 CharacterInfosManager (delta.games.lotro.character.CharacterInfosManager)1 CharactersManager (delta.games.lotro.character.CharactersManager)1 CharacterEvent (delta.games.lotro.character.events.CharacterEvent)1 CharacterXMLParser (delta.games.lotro.character.io.xml.CharacterXMLParser)1