Package de.timefinder.core.io.winqd

Source Code of de.timefinder.core.io.winqd.ImportWinQDCommand

/*
*  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.io.winqd;

import de.timefinder.data.algo.DataPoolSettings;
import de.timefinder.core.ui.command.AbstractImportCommand;
import de.timefinder.core.ui.command.TimeFinderCommand.MySwingWorker;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
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 Import class to the user
*
* @author Peter Karich, peat_hal ‘at’ users ‘dot’ sourceforge ‘dot’ net
*/
public class ImportWinQDCommand extends AbstractImportCommand {

    public static final String ID = "importWinQDFile";
    private DataPoolSettings settings;

    public ImportWinQDCommand() {
        super(ID);
    }

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

    /**
     * Starts a new frame and close the active window.
     *
     * @see Application#close()
     */
    @Override
    protected void doOnce() {
        checkIfDataIsAlreadyAvailable();
        closeAllViews();

        ApplicationWindow aw = getApplicationWindow();
        final StatusBar bar = aw.getStatusBar();
        final ProgressMonitor pm = bar.getProgressMonitor();

        JFileChooser fc = new JFileChooser();
        fc.setDialogTitle(tr.get(ID + ".fileDialog"));
        fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        int res = fc.showOpenDialog(aw.getControl());
        if (res != JFileChooser.APPROVE_OPTION) {
            bar.setMessage(tr.get(ID + ".noFileSelected"));
            return;
        }
        file = fc.getSelectedFile();
        if (!file.isDirectory()) {
            int resultOP = JOptionPane.showConfirmDialog(null, tr.get(ID + ".confirmation.message"),
                    tr.get(ID + ".confirmation.title"), JOptionPane.OK_CANCEL_OPTION);
            if (resultOP != JOptionPane.OK_OPTION) {
                return;
            }
        }
        pm.taskStarted(tr.get(ID + ".startTask"), 100);

        MySwingWorker sw = new MySwingWorker(ID) {

            @Override
            protected void myconstruct() throws Exception {
                bar.getProgressMonitor().worked(10);
                ImportWinQD importer = new ImportWinQD(dataPool, settings, file);

                bar.getProgressMonitor().worked(20);
                importer.doWork();
                bar.getProgressMonitor().worked(80);
            }

            @Override
            protected void done() {
                bar.getProgressMonitor().worked(90);
                openAllViews();
                bar.getProgressMonitor().worked(100);
                super.done();
            }
        };

        sw.execute();
    }
}
TOP

Related Classes of de.timefinder.core.io.winqd.ImportWinQDCommand

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.