Example usage for javax.swing JFileChooser setSelectedFile

List of usage examples for javax.swing JFileChooser setSelectedFile

Introduction

In this page you can find the example usage for javax.swing JFileChooser setSelectedFile.

Prototype

@BeanProperty(preferred = true)
public void setSelectedFile(File file) 

Source Link

Document

Sets the selected file.

Usage

From source file:org.pgptool.gui.ui.encryptone.EncryptOnePm.java

public SaveFileChooserDialog getTargetFileChooser() {
    if (targetFileChooser == null) {
        targetFileChooser = new SaveFileChooserDialog(findRegisteredWindowIfAny(), "action.chooseTargetFile",
                "action.choose", appProps, "EncryptionTargetChooser") {
            @Override/*from w  ww.  ja v  a  2 s.c  o  m*/
            protected String onDialogClosed(String filePathName, JFileChooser ofd) {
                String ret = super.onDialogClosed(filePathName, ofd);
                if (ret != null) {
                    targetFile.setValueByOwner(ret);
                }
                return ret;
            }

            @Override
            protected void onFileChooserPostConstrct(JFileChooser ofd) {
                ofd.setAcceptAllFileFilterUsed(false);
                ofd.addChoosableFileFilter(new FileNameExtensionFilter("GPG Files (.pgp)", "pgp"));
                // NOTE: Should we support other extensions?....
                ofd.addChoosableFileFilter(ofd.getAcceptAllFileFilter());
                ofd.setFileFilter(ofd.getChoosableFileFilters()[0]);
            }

            @Override
            protected void suggestTarget(JFileChooser ofd) {
                String sourceFileStr = sourceFile.getValue();
                if (StringUtils.hasText(targetFile.getValue())) {
                    use(ofd, targetFile.getValue());
                } else if (encryptionDialogParameters != null
                        && encryptionDialogParameters.getTargetFile() != null) {
                    if (encryptionDialogParameters.getSourceFile().equals(sourceFile.getValue())) {
                        use(ofd, encryptionDialogParameters.getTargetFile());
                    } else {
                        use(ofd, madeUpTargetFileName(sourceFile.getValue(), FilenameUtils
                                .getFullPathNoEndSeparator(encryptionDialogParameters.getTargetFile())));
                    }
                } else if (StringUtils.hasText(sourceFileStr) && new File(sourceFileStr).exists()) {
                    String basePath = FilenameUtils.getFullPathNoEndSeparator(sourceFileStr);
                    ofd.setCurrentDirectory(new File(basePath));
                    ofd.setSelectedFile(new File(madeUpTargetFileName(sourceFileStr, basePath)));
                }
            }

            private void use(JFileChooser ofd, String filePathName) {
                ofd.setCurrentDirectory(new File(FilenameUtils.getFullPathNoEndSeparator(filePathName)));
                ofd.setSelectedFile(new File(filePathName));
            }
        };
    }
    return targetFileChooser;
}

From source file:neg.JRViewerFactura.java

void btnSaveActionPerformed(java.awt.event.ActionEvent evt, String nombre) {
    // Add your handling code here:

    JFileChooser fileChooser = new JFileChooser();
    fileChooser.setLocale(this.getLocale());
    fileChooser.updateUI();//w ww  .j av a 2s.  c  o  m
    String archivo = nombre;
    File f = new File(archivo);
    fileChooser.setSelectedFile(f);

    for (int i = 0; i < saveContributors.size(); i++) {
        fileChooser.addChoosableFileFilter((JRSaveContributor) saveContributors.get(i));
    }

    if (saveContributors.contains(lastSaveContributor)) {
        fileChooser.setFileFilter(lastSaveContributor);
    } else if (saveContributors.size() > 0) {
        fileChooser.setFileFilter((JRSaveContributor) saveContributors.get(0));
    }

    if (lastFolder != null) {
        //fileChooser.setCurrentDirectory(lastFolder);
        fileChooser.setCurrentDirectory(lastFolder);
    }

    int retValue = fileChooser.showSaveDialog(this);
    if (retValue == JFileChooser.APPROVE_OPTION) {
        javax.swing.filechooser.FileFilter fileFilter = fileChooser.getFileFilter();
        File file = fileChooser.getSelectedFile();

        lastFolder = file.getParentFile();

        JRSaveContributor contributor = null;

        if (fileFilter instanceof JRSaveContributor) {
            contributor = (JRSaveContributor) fileFilter;
        } else {
            int i = 0;
            while (contributor == null && i < saveContributors.size()) {
                contributor = (JRSaveContributor) saveContributors.get(i++);
                if (!contributor.accept(file)) {
                    contributor = null;
                }
            }

            if (contributor == null) {
                contributor = new JRPrintSaveContributor(getLocale(), this.resourceBundle);
            }
        }

        lastSaveContributor = contributor;

        try {
            contributor.save(jasperPrint, file);
        } catch (JRException e) {
            if (log.isErrorEnabled())
                log.error("Save error.", e);

            JOptionPane.showMessageDialog(this, getBundleString("error.saving"));
        }
    }
}

From source file:neg.JRViewerFactura.java

void btnSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSaveActionPerformed
    // Add your handling code here:

    JFileChooser fileChooser = new JFileChooser();
    fileChooser.setLocale(this.getLocale());
    fileChooser.updateUI();//from  www.  ja  va 2 s.  c  o m
    String archivo = "Pepe.txt";
    File f = new File(archivo);
    fileChooser.setSelectedFile(f);

    for (int i = 0; i < saveContributors.size(); i++) {
        fileChooser.addChoosableFileFilter((JRSaveContributor) saveContributors.get(i));
    }

    if (saveContributors.contains(lastSaveContributor)) {
        fileChooser.setFileFilter(lastSaveContributor);
    } else if (saveContributors.size() > 0) {
        fileChooser.setFileFilter((JRSaveContributor) saveContributors.get(0));
    }

    if (lastFolder != null) {
        fileChooser.setCurrentDirectory(lastFolder);
    }

    int retValue = fileChooser.showSaveDialog(this);
    if (retValue == JFileChooser.APPROVE_OPTION) {
        javax.swing.filechooser.FileFilter fileFilter = fileChooser.getFileFilter();
        File file = fileChooser.getSelectedFile();

        lastFolder = file.getParentFile();

        JRSaveContributor contributor = null;

        if (fileFilter instanceof JRSaveContributor) {
            contributor = (JRSaveContributor) fileFilter;
        } else {
            int i = 0;
            while (contributor == null && i < saveContributors.size()) {
                contributor = (JRSaveContributor) saveContributors.get(i++);
                if (!contributor.accept(file)) {
                    contributor = null;
                }
            }

            if (contributor == null) {
                contributor = new JRPrintSaveContributor(getLocale(), this.resourceBundle);
            }
        }

        lastSaveContributor = contributor;

        try {
            contributor.save(jasperPrint, file);
        } catch (JRException e) {
            if (log.isErrorEnabled())
                log.error("Save error.", e);

            JOptionPane.showMessageDialog(this, getBundleString("error.saving"));
        }
    }
}

From source file:ffx.ui.MainPanel.java

/**
 * <p>//www . jav  a  2s.co m
 * createKeyFile</p>
 *
 * @param system a {@link ffx.ui.FFXSystem} object.
 * @return a boolean.
 */
public boolean createKeyFile(FFXSystem system) {
    String message = new String("Please select a parameter file " + "and a TINKER Key file will be created.");
    String params = (String) JOptionPane.showInputDialog(this, message, "Parameter File",
            JOptionPane.QUESTION_MESSAGE, null, keywordPanel.getParamFiles(), null);
    if (params != null) {
        if (params.equalsIgnoreCase("Use an existing TINKER Key file")) {
            JFileChooser fc = resetFileChooser();
            fc.setDialogTitle("Choose a KEY File");
            fc.setCurrentDirectory(pwd);
            fc.setSelectedFile(null);
            fc.setFileFilter(keyFileFilter);
            int result = fc.showOpenDialog(this);
            if (result == JFileChooser.APPROVE_OPTION) {
                File keyfile = fc.getSelectedFile();
                if (keyfile.exists()) {
                    Hashtable<String, Keyword> keywordHash = KeyFilter.open(keyfile);
                    if (keywordHash != null) {
                        system.setKeywords(keywordHash);
                    } else {
                        return false;
                    }
                    system.setKeyFile(keyfile);
                    system.setForceField(null);
                    return true;
                }
            }
        } else {
            File tempFile = system.getFile();
            if (tempFile.getParentFile().canWrite()) {
                String path = system.getFile().getParent() + File.separatorChar;
                String keyFileName = system.getName() + ".key";
                File keyfile = new File(path + keyFileName);
                try {
                    FileWriter fw = new FileWriter(keyfile);
                    BufferedWriter bw = new BufferedWriter(fw);
                    bw.write("\n");
                    bw.write("# Force Field Selection\n");
                    String tempParm = keywordPanel.getParamPath(params);
                    if (tempParm.indexOf(" ") > 0) {
                        tempParm = "\"" + keywordPanel.getParamPath(params) + "\"";
                    }
                    bw.write("PARAMETERS        " + tempParm + "\n");
                    bw.close();
                    fw.close();
                    Hashtable<String, Keyword> keywordHash = KeyFilter.open(keyfile);
                    if (keywordHash != null) {
                        system.setKeywords(keywordHash);
                    } else {
                        return false;
                    }
                    system.setKeyFile(keyfile);
                    system.setForceField(null);
                    return true;
                } catch (Exception e) {
                    logger.warning("" + e);
                    message = new String("There was an error creating " + keyfile.getAbsolutePath());
                    JOptionPane.showMessageDialog(this, message);
                }
            } else {
                message = new String(
                        "Could not create a Key file because " + pwd.getAbsolutePath() + " is not writable");
                JOptionPane.showMessageDialog(this, message);
            }
        }
    }
    return false;
}

From source file:fi.hoski.remote.ui.Admin.java

private File saveFile(String lastDir, String nameCandidate, String suffix, String description) {
    JFileChooser fc = new JFileChooser();
    fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
    fc.setAcceptAllFileFilterUsed(false);
    FileFilter ff = new SuffixFileFilter(suffix, description);
    fc.setFileFilter(ff);//from   w ww . j  a  va 2s.  com
    fc.setSelectedFile(new File(nameCandidate));
    File currentDirectory = LastInput.getDirectory(lastDir);
    if (currentDirectory != null) {
        fc.setCurrentDirectory(currentDirectory);
    }
    if (fc.showSaveDialog(frame) == JFileChooser.APPROVE_OPTION) {
        File file = fc.getSelectedFile();
        if (file != null) {
            if (!file.getName().endsWith(suffix)) {
                file = new File(file.getPath() + suffix);
            }
            LastInput.set(lastDir, file);
        }
        return file;
    }
    return null;
}

From source file:org.jets3t.apps.cockpit.Cockpit.java

/**
 * Downloads the objects currently selected in the objects table. The user is
 * prompted/*  w ww.j a v  a  2s.c  om*/
 * Prepares to perform a download of objects from S3 by prompting the user for a directory
 * to store the files in, then performing the download.
 *
 * @throws IOException
 */
private void downloadSelectedObjects() {
    // Prompt user to choose directory location for downloaded files (or cancel download altogether)
    JFileChooser fileChooser = new JFileChooser();
    fileChooser.setDialogTitle("Choose directory to save S3 files in");
    fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    fileChooser.setMultiSelectionEnabled(false);
    fileChooser.setSelectedFile(downloadDirectory);

    int returnVal = fileChooser.showDialog(ownerFrame, "Choose Directory");
    if (returnVal != JFileChooser.APPROVE_OPTION) {
        return;
    }

    downloadDirectory = fileChooser.getSelectedFile();

    boolean storeEmptyDirectories = Jets3tProperties.getInstance(Constants.JETS3T_PROPERTIES_FILENAME)
            .getBoolProperty("uploads.storeEmptyDirectories", true);
    final Map<String, String> objectKeyToFilepathMap = FileComparer.getInstance()
            .buildObjectKeyToFilepathMap(downloadDirectory.listFiles(), "", storeEmptyDirectories);

    // Build map of S3 Objects being downloaded.
    final Map s3DownloadObjectsMap = FileComparer.getInstance().populateObjectMap("", getSelectedObjects());

    final HyperlinkActivatedListener hyperlinkListener = this;

    runInBackgroundThread(new Runnable() {
        public void run() {
            // Retrieve details of objects for download
            if (!retrieveObjectsDetails(getSelectedObjects())) {
                return;
            }

            try {
                final FileComparerResults comparisonResults = compareRemoteAndLocalFiles(objectKeyToFilepathMap,
                        s3DownloadObjectsMap);

                DownloadPackage[] downloadPackages = buildDownloadPackageList(comparisonResults,
                        s3DownloadObjectsMap);
                if (downloadPackages == null) {
                    return;
                }

                s3ServiceMulti.downloadObjects(currentSelectedBucket, downloadPackages);

            } catch (final Exception e) {
                runInDispatcherThreadImmediately(new Runnable() {
                    public void run() {
                        String message = "Unable to download objects";
                        log.error(message, e);
                        ErrorDialog.showDialog(ownerFrame, hyperlinkListener, message, e);
                    }
                });
            }
        }
    });
}

From source file:edu.ku.brc.specify.tasks.WorkbenchTask.java

/**
 * Asks for the type of export and the file name.
 * @param props the properties object to be filled in.
 * @return true if everything was asked for and received.
 *//*from ww w . j a  v a2  s  .c  om*/
public static boolean getExportInfo(final Properties props, final String defaultFileName) {
    String extension = "";
    //String fileTypeCaption = "";
    if (true) {
        for (ExportFileConfigurationFactory.ExportableType type : ExportFileConfigurationFactory
                .getExportList()) {
            if (type.getMimeType() == ExportFileConfigurationFactory.XLS_MIME_TYPE) {
                props.setProperty("mimetype", type.getMimeType());
                extension = type.getExtension();
                //fileTypeCaption = type.getCaption();
                break;
            }
        }

    } else {
        ChooseFromListDlg<ExportFileConfigurationFactory.ExportableType> dlg = new ChooseFromListDlg<ExportFileConfigurationFactory.ExportableType>(
                (Frame) UIRegistry.get(UIRegistry.FRAME), getResourceString("WB_FILE_FORMAT"), null,
                ChooseFromListDlg.OKCANCELHELP, ExportFileConfigurationFactory.getExportList(),
                "WorkbenchImportCvs");
        dlg.setModal(true);
        UIHelper.centerAndShow(dlg);

        if (!dlg.isCancelled()) {
            props.setProperty("mimetype", dlg.getSelectedObject().getMimeType());

        } else {
            return false;
        }
        extension = dlg.getSelectedObject().getExtension();
        dlg.dispose();
    }

    //        FileDialog fileDialog = new FileDialog((Frame) UIRegistry.get(UIRegistry.FRAME),
    //                                               String.format(getResourceString("CHOOSE_WORKBENCH_EXPORT_FILE"), fileTypeCaption), FileDialog.SAVE);
    //        fileDialog.setDirectory(getDefaultDirPath(EXPORT_FILE_PATH));
    //        UIHelper.centerAndShow(fileDialog);
    //        fileDialog.dispose();

    JFileChooser chooser = new JFileChooser(getDefaultDirPath(EXPORT_FILE_PATH));
    chooser.setDialogTitle(getResourceString("CHOOSE_WORKBENCH_EXPORT_FILE"));
    chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    chooser.setMultiSelectionEnabled(false);
    chooser.setFileFilter(new UIFileFilter("xls", getResourceString("WB_EXCELFILES")));
    if (defaultFileName != null) {
        chooser.setSelectedFile(
                new File(chooser.getCurrentDirectory().getPath() + File.separator + defaultFileName + ".xls"));
    }

    if (chooser.showSaveDialog(UIRegistry.get(UIRegistry.FRAME)) != JFileChooser.APPROVE_OPTION) {
        UIRegistry.getStatusBar().setText("");
        return false;
    }

    File file = chooser.getSelectedFile();
    if (file == null) {
        UIRegistry.getStatusBar().setText(getResourceString("WB_EXPORT_NOFILENAME"));
        return false;
    }

    String path = chooser.getCurrentDirectory().getPath();
    //String path = FilenameUtils.getPath(file.getPath());
    if (StringUtils.isNotEmpty(path)) {
        AppPreferences localPrefs = AppPreferences.getLocalPrefs();
        localPrefs.put(EXPORT_FILE_PATH, path);
    }

    //        String fileName = fileDialog.getFile();
    String fileName = file.getName();
    //        if (StringUtils.isEmpty(fileName))
    //        {
    //            UIRegistry.getStatusBar().setText(getResourceString("WB_EXPORT_NOFILENAME"));
    //            return false;
    //        }

    if (StringUtils.isEmpty(FilenameUtils.getExtension(fileName))) {
        fileName += (fileName.endsWith(".") ? "" : ".") + extension;
    }

    if (StringUtils.isEmpty(fileName)) {
        return false;
    }

    if (file.exists()) {
        PanelBuilder builder = new PanelBuilder(new FormLayout("p:g", "c:p:g"));
        CellConstraints cc = new CellConstraints();

        String msg = String.format("<html><p>%s<br><br>%s<br></p></html>", getResourceString("WB_FILE_EXISTS"),
                getResourceString("WB_OK_TO_OVERWRITE"));
        builder.add(createLabel(msg), cc.xy(1, 1));
        builder.setDefaultDialogBorder();

        CustomDialog confirmer = new CustomDialog((Frame) UIRegistry.get(UIRegistry.FRAME),
                getResourceString("WB_FILE_EXISTS_TITLE"), true, CustomDialog.OKCANCEL, builder.getPanel(),
                CustomDialog.CANCEL_BTN);
        UIHelper.centerAndShow(confirmer);
        confirmer.dispose();
        if (confirmer.isCancelled()) {
            return false;
        }
    }
    props.setProperty("fileName", path + File.separator + fileName);
    return true;
}

From source file:simMPLS.ui.simulator.JVentanaHija.java

/**
 * Este mtodo se encarga de controlar que todo ocurre como debe con respecto al
 * escenario, cuando se pulsa en el men principal la opcin de "Guardar como..."
 * @since 1.0/*from ww  w.j  a v  a2 s  .  c om*/
 */
public void gestionarGuardarComo() {
    anotarDatosDeEscenario();
    JFileChooser dialogoGuardar = new JFileChooser();
    dialogoGuardar.setFileFilter(new JOSMFilter());
    dialogoGuardar.setDialogType(JFileChooser.CUSTOM_DIALOG);
    dialogoGuardar.setApproveButtonMnemonic('A');
    dialogoGuardar.setApproveButtonText(java.util.ResourceBundle.getBundle("simMPLS/lenguajes/lenguajes")
            .getString("JVentanaHija.DialogoGuardar.OK"));
    dialogoGuardar.setDialogTitle(java.util.ResourceBundle.getBundle("simMPLS/lenguajes/lenguajes")
            .getString("JVentanaHija.DialogoGuardar.Almacenar") + this.getTitle()
            + java.util.ResourceBundle.getBundle("simMPLS/lenguajes/lenguajes").getString("-"));
    dialogoGuardar.setAcceptAllFileFilterUsed(false);
    dialogoGuardar.setSelectedFile(new File(this.getTitle()));
    dialogoGuardar.setFileSelectionMode(JFileChooser.FILES_ONLY);
    int resultado = dialogoGuardar.showSaveDialog(VentanaPadre);
    if (resultado == JFileChooser.APPROVE_OPTION) {
        String ext = null;
        String nombreFich = dialogoGuardar.getSelectedFile().getPath();
        int i = nombreFich.lastIndexOf('.');
        if (i > 0 && i < nombreFich.length() - 1) {
            ext = nombreFich.substring(i + 1).toLowerCase();
        }
        if (ext == null) {
            nombreFich += java.util.ResourceBundle.getBundle("simMPLS/lenguajes/lenguajes").getString(".osm");
        } else {
            if (!ext.equals(
                    java.util.ResourceBundle.getBundle("simMPLS/lenguajes/lenguajes").getString("osm"))) {
                nombreFich += java.util.ResourceBundle.getBundle("simMPLS/lenguajes/lenguajes")
                        .getString(".osm");
            }
        }
        dialogoGuardar.setSelectedFile(new File(nombreFich));
        escenario.setFile(dialogoGuardar.getSelectedFile());
        this.escenario.setSaved(true);
        this.setTitle(this.escenario.obtenerFichero().getName());
        TOSMSaver almacenador = new TOSMSaver(escenario);
        //            JVentanaBooleana vb = new JVentanaBooleana(this.VentanaPadre, true, this.dispensadorDeImagenes);
        //            vb.mostrarPregunta(java.util.ResourceBundle.getBundle("simMPLS/lenguajes/lenguajes").getString("JVentanaHija.PreguntaEmpotrarCRC"));
        //            vb.show();
        //            boolean conCRC = vb.obtenerRespuesta();
        //            boolean correcto = almacenador.save(escenario.obtenerFichero(), conCRC);
        JVentanaBooleana vb = new JVentanaBooleana(this.VentanaPadre, true, this.dispensadorDeImagenes);
        vb.mostrarPregunta("Do you want to save the routing tables ?");
        vb.show();
        boolean saveTables = vb.obtenerRespuesta();
        boolean correcto = almacenador.save(escenario.obtenerFichero(), false, saveTables);
        if (correcto) {
            this.escenario.setModified(false);
            this.escenario.setSaved(true);
        }
    }
}

From source file:eu.crisis_economics.abm.dashboard.Page_Parameters.java

private void chooseFile() {
    final JFileChooser fileDialog = new JFileChooser(
            !"".equals(fileTextField.getToolTipText()) ? fileTextField.getToolTipText() : currentDirectory);
    if (!"".equals(fileTextField.getToolTipText()))
        fileDialog.setSelectedFile(new File(fileTextField.getToolTipText()));
    int dialogResult = fileDialog.showOpenDialog(dashboard);
    if (dialogResult == JFileChooser.APPROVE_OPTION) {
        final File selectedFile = fileDialog.getSelectedFile();
        if (selectedFile != null) {
            currentDirectory = selectedFile.getAbsoluteFile().getParent();
            fileTextField.setText(selectedFile.getName());
            fileTextField.setToolTipText(selectedFile.getAbsolutePath());
        }//from ww  w .ja v  a 2  s  . co  m
    }
}

From source file:de.tor.tribes.ui.windows.DSWorkbenchMainFrame.java

private void fireExportEvent(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fireExportEvent
    if (evt.getSource() == jExportButton) {
        //do export
        logger.debug("Building export data");

        List<String> plansToExport = new LinkedList<>();
        for (int i = 0; i < jAttackExportTable.getRowCount(); i++) {
            String plan = (String) jAttackExportTable.getValueAt(i, 0);
            Boolean export = (Boolean) jAttackExportTable.getValueAt(i, 1);
            if (export) {
                logger.debug("Selecting attack plan '" + plan + "' to export list");
                plansToExport.add(plan);
            }// ww w . j ava  2 s.com

        }

        List<String> setsToExport = new LinkedList<>();
        for (int i = 0; i < jMarkerSetExportTable.getRowCount(); i++) {
            String set = (String) jMarkerSetExportTable.getValueAt(i, 0);
            Boolean export = (Boolean) jMarkerSetExportTable.getValueAt(i, 1);
            if (export) {
                logger.debug("Selecting marker set '" + set + "' to export list");
                setsToExport.add(set);
            }

        }
        List<String> reportsToExport = new LinkedList<>();
        for (int i = 0; i < jReportSetExportTable.getRowCount(); i++) {
            String set = (String) jReportSetExportTable.getValueAt(i, 0);
            Boolean export = (Boolean) jReportSetExportTable.getValueAt(i, 1);
            if (export) {
                logger.debug("Selecting report set '" + set + "' to export list");
                reportsToExport.add(set);
            }
        }

        List<String> troopSetsToExport = new LinkedList<>();
        for (int i = 0; i < jTroopSetExportTable.getRowCount(); i++) {
            String set = (String) jTroopSetExportTable.getValueAt(i, 0);
            Boolean export = (Boolean) jTroopSetExportTable.getValueAt(i, 1);
            if (export) {
                logger.debug("Selecting troop set '" + set + "' to export list");
                troopSetsToExport.add(set);
            }
        }
        List<String> noteSetsToExport = new LinkedList<>();
        for (int i = 0; i < jNoteSetExportTable.getRowCount(); i++) {
            String set = (String) jNoteSetExportTable.getValueAt(i, 0);
            Boolean export = (Boolean) jNoteSetExportTable.getValueAt(i, 1);
            if (export) {
                logger.debug("Selecting note set '" + set + "' to export list");
                noteSetsToExport.add(set);
            }
        }
        boolean needExport = false;
        needExport = !plansToExport.isEmpty();
        needExport |= !setsToExport.isEmpty();
        needExport |= !reportsToExport.isEmpty();
        needExport |= jExportTags.isSelected();
        needExport |= !troopSetsToExport.isEmpty();
        needExport |= jExportForms.isSelected();
        needExport |= !noteSetsToExport.isEmpty();
        needExport |= jExportVillageInformation.isSelected();
        needExport |= jExportFarminfos.isSelected();
        needExport |= jExportSOS.isSelected();
        needExport |= jExportSplits.isSelected();
        needExport |= jExportStdAttacks.isSelected();

        if (!needExport) {
            JOptionPaneHelper.showWarningBox(jExportDialog, "Keine Daten fr den Export gewhlt", "Export");
            return;

        }
        String dir = GlobalOptions.getProperty("screen.dir");
        if (dir == null) {
            dir = ".";
        }

        JFileChooser chooser;
        try {
            chooser = new JFileChooser(dir);
        } catch (Exception e) {
            JOptionPaneHelper.showErrorBox(this,
                    "Konnte Dateiauswahldialog nicht ffnen.\nMglicherweise verwendest du Windows Vista. Ist dies der Fall, beende DS Workbench, klicke mit der rechten Maustaste auf DSWorkbench.exe,\n"
                            + "whle 'Eigenschaften' und deaktiviere dort unter 'Kompatibilitt' den Windows XP Kompatibilittsmodus.",
                    "Fehler");
            return;
        }
        chooser.setDialogTitle("Datei auswhlen");
        chooser.setSelectedFile(new File("export.xml"));
        chooser.setFileFilter(new javax.swing.filechooser.FileFilter() {

            @Override
            public boolean accept(File f) {
                return (f != null) && (f.isDirectory() || f.getName().endsWith(".xml"));

            }

            @Override
            public String getDescription() {
                return "*.xml";
            }
        });
        int ret = chooser.showSaveDialog(jExportDialog);
        if (ret == JFileChooser.APPROVE_OPTION) {
            try {
                File f = chooser.getSelectedFile();
                String file = f.getCanonicalPath();
                if (!file.endsWith(".xml")) {
                    file += ".xml";
                }

                File target = new File(file);
                if (target.exists()) {
                    if (JOptionPaneHelper.showQuestionConfirmBox(jExportDialog,
                            "Bestehende Datei berschreiben?", "Export", "Nein",
                            "Ja") == JOptionPane.NO_OPTION) {
                        return;
                    }
                }

                Document doc = JDomUtils.createDocument();
                Element backup = doc.getRootElement();
                if (!plansToExport.isEmpty()) {
                    backup.addContent(AttackManager.getSingleton().getExportData(plansToExport));
                }
                if (!setsToExport.isEmpty()) {
                    backup.addContent(MarkerManager.getSingleton().getExportData(setsToExport));
                }
                if (!reportsToExport.isEmpty()) {
                    backup.addContent(ReportManager.getSingleton().getExportData(reportsToExport));
                }
                if (jExportTags.isSelected()) {
                    backup.addContent(TagManager.getSingleton().getExportData(null));
                }

                if (!troopSetsToExport.isEmpty()) {
                    backup.addContent(TroopsManager.getSingleton().getExportData(troopSetsToExport));
                }

                if (jExportForms.isSelected()) {
                    backup.addContent(FormManager.getSingleton().getExportData(null));
                }

                if (!noteSetsToExport.isEmpty()) {
                    backup.addContent(NoteManager.getSingleton().getExportData(noteSetsToExport));
                }

                if (jExportVillageInformation.isSelected()) {
                    backup.addContent(KnownVillageManager.getSingleton().getExportData(null));
                }

                if (jExportFarminfos.isSelected()) {
                    backup.addContent(FarmManager.getSingleton().getExportData(null));
                }

                if (jExportSOS.isSelected()) {
                    backup.addContent(SOSManager.getSingleton().getExportData(null));
                }

                if (jExportSplits.isSelected()) {
                    backup.addContent(SplitSetHelper.getExportData());
                }

                if (jExportStdAttacks.isSelected()) {
                    backup.addContent(StandardAttackManager.getSingleton().getExportData(null));
                }

                logger.debug("Writing data to disk");
                JDomUtils.saveDocument(doc, file);
                logger.debug("Export finished successfully");
                JOptionPaneHelper.showInformationBox(jExportDialog, "Export erfolgreich beendet.", "Export");
            } catch (Exception e) {
                logger.error("Failed to export data", e);
                JOptionPaneHelper.showErrorBox(this, "Export fehlgeschlagen.", "Export");
            }

        } else {
            //cancel pressed
            return;
        }

    }
    jExportDialog.setAlwaysOnTop(false);
    jExportDialog.setVisible(false);
}