package org.pasif.gui;
import org.pasif.utils.ImportData;
import java.awt.Component;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.ActionMap;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.WindowConstants;
import org.jdesktop.application.Action;
import org.jdesktop.application.Application;
import org.jdesktop.application.ResourceMap;
import org.jdesktop.application.Task;
import org.jdesktop.layout.GroupLayout;
import org.jdesktop.layout.LayoutStyle;
import org.pas.database.DbHelper;
public class ImportView extends javax.swing.JDialog {
private ImportData importData;
private String index;
public ImportView(java.awt.Frame parent, boolean modal, String importFolder, DbHelper dbHelper, String index) {
super(parent, modal);
initComponents();
importData = new ImportData(dbHelper, importFolder, currentFileName);
this.index = index;
this.setTitle("导入数据");
jButton1.setVisible(false);
exportData().execute();
addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
if (exportData().isStarted()) {
exportData().cancel(true);
}
}
});
}
@Action
public void exit() {
dispose();
}
@Action
public Task exportData() {
if (exportDataTask == null) {
return new ExportDataTask(org.jdesktop.application.Application.getInstance(org.pasif.gui.Server.class));
} else {
return exportDataTask;
}
}
private class ExportDataTask extends org.jdesktop.application.Task<Object, Void> {
ExportDataTask(org.jdesktop.application.Application app) {
super(app);
}
@Override
protected Object doInBackground() {
try {
importData.parseIndex(index);
} catch (Exception ex) {
ex.printStackTrace();
}
return null;
}
@Override
protected void succeeded(Object result) {
jButton1.setVisible(true);
}
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
currentFileName = new JLabel();
jButton1 = new JButton();
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
setName("Form"); // NOI18N
ResourceMap resourceMap = Application.getInstance(Server.class).getContext().getResourceMap(ImportView.class);
currentFileName.setText(resourceMap.getString("currentFileName.text")); // NOI18N
currentFileName.setName("currentFileName"); // NOI18N
ActionMap actionMap = Application.getInstance(Server.class).getContext().getActionMap(ImportView.class, this);
jButton1.setAction(actionMap.get("exit")); // NOI18N
jButton1.setText(resourceMap.getString("jButton1.text")); // NOI18N
jButton1.setName("jButton1"); // NOI18N
GroupLayout layout = new GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(layout.createParallelGroup(GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.addContainerGap()
.add(currentFileName, GroupLayout.DEFAULT_SIZE, 329, Short.MAX_VALUE))
.add(layout.createSequentialGroup()
.add(133, 133, 133)
.add(jButton1, GroupLayout.PREFERRED_SIZE, 80, GroupLayout.PREFERRED_SIZE)))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.addContainerGap()
.add(currentFileName, GroupLayout.PREFERRED_SIZE, 32, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(LayoutStyle.RELATED)
.add(jButton1)
.addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
pack();
}// </editor-fold>//GEN-END:initComponents
// Variables declaration - do not modify//GEN-BEGIN:variables
private JLabel currentFileName;
private JButton jButton1;
// End of variables declaration//GEN-END:variables
private Task exportDataTask;
}