Package de.timefinder.core.ui.command

Source Code of de.timefinder.core.ui.command.ExportXmlFileCommand

/*
*  Copyright 2009 Peter Karich, peat_hal ‘at’ users ‘dot’ sourceforge ‘dot’ net.
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*       http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*  under the License.
*/
package de.timefinder.core.ui.command;

import de.timefinder.core.io.xml.XmlExport;
import de.timefinder.data.algo.DataPoolSettings;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileWriter;
import javax.swing.JFileChooser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.richclient.application.Application;
import org.springframework.richclient.application.ApplicationWindow;
import org.springframework.richclient.application.statusbar.StatusBar;
import org.springframework.richclient.progress.ProgressMonitor;

/**
* This UI class provides the Export class to the user
*
* @author Peter Karich, peat_hal ‘at’ users ‘dot’ sourceforge ‘dot’ net
*/
public class ExportXmlFileCommand extends ClearDataPoolCommand {

    public static final String ID = "exportXmlFile";
    protected DataPoolSettings settings;

    public ExportXmlFileCommand() {
        super(ID);
    }

    @Autowired
    public void setDataPoolSettings(DataPoolSettings set) {
        this.settings = set;
    }

    /**
     * Starts a new frame and close the active window.
     *
     * @see Application#close()
     */
    @Override
    protected void doOnce() {
        ApplicationWindow aw = getApplicationWindow();
        final StatusBar bar = aw.getStatusBar();
        ProgressMonitor pm = bar.getProgressMonitor();

        JFileChooser fc = new JFileChooser();
        fc.setDialogTitle(tr.get(ID + ".fileDialog"));
        int res = fc.showSaveDialog(aw.getControl());
        if (res != JFileChooser.APPROVE_OPTION) {
            bar.setMessage(tr.get(ID + ".noFileSelected"));
            return;
        }
        final File f = fc.getSelectedFile();

        pm.taskStarted(tr.get(ID + ".startTask"), -1);

        MySwingWorker sw = new MySwingWorker(ID) {

            @Override
            protected void myconstruct() throws Exception {
                bar.getProgressMonitor().worked(10);
                XmlExport exporter = new XmlExport(dataPool,
                        settings, new FileOutputStream(f.getAbsoluteFile()));

                exporter.doWork();
                bar.getProgressMonitor().worked(100);
            }
        };

        sw.execute();
    }
}
TOP

Related Classes of de.timefinder.core.ui.command.ExportXmlFileCommand

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.