forked from Coded/SIPRP
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
237 lines
5.5 KiB
237 lines
5.5 KiB
/*
|
|
* Importer.java
|
|
*
|
|
* Created on 7 de Abril de 2004, 10:56
|
|
*/
|
|
|
|
package siprp.importer;
|
|
|
|
import com.evolute.utils.arrays.*;
|
|
import com.evolute.utils.tables.*;
|
|
import com.evolute.utils.ui.*;
|
|
|
|
import java.awt.*;
|
|
import java.awt.event.*;
|
|
import java.io.*;
|
|
import java.util.*;
|
|
import javax.swing.*;
|
|
import javax.swing.table.*;
|
|
|
|
import jxl.*;
|
|
|
|
/**
|
|
*
|
|
* @author psantos
|
|
*/
|
|
public class Importer extends CustomJDialog
|
|
{
|
|
public String NOME = "Nome do Funcion\u00e1rio";
|
|
public String SEXO = "Sexo";
|
|
public String NACIONALIDADE = "Nacionalidade";
|
|
public String DATA_NASCIMENTO = "Data Nascimento";
|
|
public String NUMERO_MECANOGRAFICO = "N\u00famero Mecanogr\u00e1fico";
|
|
public String DATA_ADMISSAO = "Data Admiss\u00e3o";
|
|
public String CATEGORIA = "Categoria";
|
|
public String LOCAL_TRABALHO = "Local Trabalho";
|
|
public String FUNCAO = "Fun\u00e7\u00e3o";
|
|
public String DATA_ADMISSAO_FUNCAO = "Data Admiss\u00e3o na Fun\u00e7\u00e3o";
|
|
|
|
private JPanel panel;
|
|
private BaseTable table;
|
|
private Excel2DArray e2da;
|
|
private boolean canceled = false;
|
|
private DataChooserWindow dcw;
|
|
private String vals[];
|
|
|
|
private final String names[] = new String[]{
|
|
NOME,
|
|
SEXO,
|
|
NACIONALIDADE,
|
|
DATA_NASCIMENTO,
|
|
NUMERO_MECANOGRAFICO,
|
|
DATA_ADMISSAO,
|
|
CATEGORIA,
|
|
LOCAL_TRABALHO,
|
|
FUNCAO,
|
|
DATA_ADMISSAO_FUNCAO
|
|
};
|
|
/** Creates a new instance of Importer */
|
|
public Importer( JFrame modalFrame, String filename )
|
|
throws Exception
|
|
{
|
|
super( modalFrame, true );
|
|
|
|
setupComponents( filename );
|
|
|
|
if( modalFrame == null )
|
|
{
|
|
center();
|
|
}
|
|
else
|
|
{
|
|
centerSuper();
|
|
}
|
|
|
|
show();
|
|
}
|
|
|
|
private void setupComponents( String filename )
|
|
{
|
|
setSize( 600, 500 );
|
|
|
|
GridBagLayout gblGridBag = new GridBagLayout();
|
|
GridBagConstraints gbcConstraints = new GridBagConstraints();
|
|
|
|
panel = ( JPanel ) getContentPane();
|
|
|
|
panel.setLayout( gblGridBag );
|
|
|
|
e2da = new Excel2DArray( filename );
|
|
|
|
String colNames[] = new String[ e2da.rowLength() ];
|
|
for( int i = 0; i < colNames.length; i++ )
|
|
{
|
|
colNames[ i ] = " ";
|
|
}
|
|
Virtual2DTableModel tm = new Virtual2DTableModel( colNames, null );
|
|
tm.setValues( e2da );
|
|
table = new BaseTable( tm );
|
|
table.getTableHeader().setResizingAllowed( true );
|
|
table.getTableHeader().setReorderingAllowed( false );
|
|
// table.setAutoResizeMode( JTable.AUTO_RESIZE_OFF );
|
|
|
|
for( int i = 0; i < e2da.rowLength(); i++ )
|
|
{
|
|
table.getColumn( i ).setMinWidth( 50 );
|
|
//table.getColumn( i ).setResizable( true );
|
|
}
|
|
|
|
JScrollPane sp = new JScrollPane( table, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
|
|
|
|
gbcConstraints.anchor = GridBagConstraints.CENTER;
|
|
gbcConstraints.fill = GridBagConstraints.BOTH;
|
|
gbcConstraints.insets = new Insets(5, 5, 5, 5);
|
|
gbcConstraints.gridwidth = 3;
|
|
gbcConstraints.gridheight = 3;
|
|
gbcConstraints.weighty = 3;
|
|
gbcConstraints.gridx = 0;
|
|
gbcConstraints.gridy = 3;
|
|
gblGridBag.setConstraints( sp, gbcConstraints );
|
|
|
|
panel.add( sp );
|
|
|
|
JPanel jpButtons = new JPanel();
|
|
final JButton jbOK = new JButton( "Escolher" );
|
|
jbOK.setEnabled( false );
|
|
jpButtons.add( jbOK );
|
|
JButton jbCancel = new JButton( "Cancelar" );
|
|
jpButtons.add( jbCancel );
|
|
|
|
gbcConstraints.gridheight = 1;
|
|
gbcConstraints.weightx = 1;
|
|
gbcConstraints.weighty = 0;
|
|
gbcConstraints.anchor = GridBagConstraints.SOUTH;
|
|
gbcConstraints.fill = GridBagConstraints.BOTH;
|
|
gbcConstraints.insets = new Insets( 2, 2, 2, 2 );
|
|
gbcConstraints.gridwidth = 3;
|
|
gbcConstraints.gridx = 0;
|
|
gbcConstraints.gridy = 6;
|
|
gblGridBag.setConstraints( jpButtons, gbcConstraints );
|
|
panel.add( jpButtons );
|
|
|
|
table.addMouseListener( new MouseAdapter() {
|
|
public void mouseClicked( MouseEvent e ) {
|
|
jbOK.setEnabled( true );
|
|
if( e.getButton() == MouseEvent.BUTTON1
|
|
&& e.getClickCount() == 2
|
|
&& table.columnAtPoint( e.getPoint() ) != -1
|
|
&& table.rowAtPoint( e.getPoint() ) != -1 )
|
|
{
|
|
acceptResult();
|
|
}
|
|
}
|
|
public void mousePressed( MouseEvent e ) {
|
|
jbOK.setEnabled( true );
|
|
}
|
|
});
|
|
|
|
jbOK.addActionListener( new ActionListener() {
|
|
public void actionPerformed( ActionEvent a ) {
|
|
acceptResult();
|
|
}
|
|
});
|
|
|
|
jbCancel.addActionListener( new ActionListener() {
|
|
public void actionPerformed( ActionEvent a ) {
|
|
setVisible( false );
|
|
dispose();
|
|
canceled = true;
|
|
}
|
|
});
|
|
|
|
}
|
|
|
|
private void acceptResult()
|
|
{
|
|
Vector v = new Vector( Arrays.asList( e2da.getRow( table.getSelectedRow() ) ) );
|
|
v.add( "" );
|
|
vals = (String[]) v.toArray( new String[]{} );
|
|
|
|
/*
|
|
System.out.println( "row: " + table.getSelectedRow() );
|
|
System.out.print( "vals: " );
|
|
for( int i = 0; i < vals.length; i++ )
|
|
{
|
|
System.out.print( "[" + vals[ i ] + "]" );
|
|
}
|
|
System.out.println();
|
|
*/
|
|
setVisible( false );
|
|
dispose();
|
|
|
|
}
|
|
|
|
public Hashtable getData()
|
|
{
|
|
dcw = new DataChooserWindow( null, names, vals );
|
|
|
|
if( canceled || ( dcw == null ) )
|
|
{
|
|
return null;
|
|
}
|
|
|
|
return dcw.getData();
|
|
}
|
|
|
|
public static void main( String args[] )
|
|
{
|
|
Importer im = null;
|
|
try
|
|
{
|
|
im = new Importer( null,
|
|
// "E:\\test.xls"
|
|
"C:\\Documents and Settings\\psantos\\My Documents\\Devel\\teste.xls"
|
|
// "C:\\Documents and Settings\\psantos\\My Documents\\Devel\\Docs\\jexcelapi\\jxlrwtest.xls"
|
|
);
|
|
|
|
System.out.println( "Escolhido: " + im.getData() );
|
|
|
|
}
|
|
catch( Exception e )
|
|
{
|
|
e.printStackTrace();
|
|
}
|
|
|
|
// String[][] all = (String[][]) e.getObjects();
|
|
//
|
|
// for( int j = 0; j < e.rowLength(); j++ )
|
|
// {
|
|
// String[] r = e.getRow( j );
|
|
// for( int i = 0; i < r.length; i++ )
|
|
// {
|
|
// System.out.print( "[" + r[ i ] + "]" );
|
|
// }
|
|
// System.out.println();
|
|
// }
|
|
}
|
|
} |