|
|
|
|
@ -41,7 +41,7 @@ public class Importer extends CustomJDialog
|
|
|
|
|
private Excel2DArray e2da;
|
|
|
|
|
private boolean canceled = false;
|
|
|
|
|
private DataChooserWindow dcw;
|
|
|
|
|
private String vals[];
|
|
|
|
|
private String vals[][];
|
|
|
|
|
private final int[] DEFAULT_SELECTION = new int[]{ 0, 2, 3, 1, -1, 4, 5, 7, 6, -1 };
|
|
|
|
|
|
|
|
|
|
private final String names[] = new String[]{
|
|
|
|
|
@ -56,14 +56,21 @@ public class Importer extends CustomJDialog
|
|
|
|
|
FUNCAO,
|
|
|
|
|
DATA_ADMISSAO_FUNCAO
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
private final boolean multipleSelection;
|
|
|
|
|
/** Creates a new instance of Importer */
|
|
|
|
|
public Importer( JFrame modalFrame, String filename )
|
|
|
|
|
throws Exception
|
|
|
|
|
{
|
|
|
|
|
super( modalFrame, true );
|
|
|
|
|
this( modalFrame, filename, false );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Importer( JFrame modalFrame, String filename, boolean multiple )
|
|
|
|
|
throws Exception
|
|
|
|
|
{
|
|
|
|
|
super( modalFrame, true );
|
|
|
|
|
multipleSelection = multiple;
|
|
|
|
|
setupComponents( filename );
|
|
|
|
|
|
|
|
|
|
if( modalFrame == null )
|
|
|
|
|
{
|
|
|
|
|
center();
|
|
|
|
|
@ -72,7 +79,6 @@ public class Importer extends CustomJDialog
|
|
|
|
|
{
|
|
|
|
|
centerSuper();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
show();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -97,6 +103,14 @@ public class Importer extends CustomJDialog
|
|
|
|
|
Virtual2DTableModel tm = new Virtual2DTableModel( colNames, null );
|
|
|
|
|
tm.setValues( e2da );
|
|
|
|
|
table = new BaseTable( tm );
|
|
|
|
|
if( !multipleSelection )
|
|
|
|
|
{
|
|
|
|
|
table.getSelectionModel().setSelectionMode( ListSelectionModel.SINGLE_SELECTION );
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
table.getSelectionModel().setSelectionMode( ListSelectionModel.SINGLE_INTERVAL_SELECTION );
|
|
|
|
|
}
|
|
|
|
|
table.getTableHeader().setResizingAllowed( true );
|
|
|
|
|
table.getTableHeader().setReorderingAllowed( false );
|
|
|
|
|
// table.setAutoResizeMode( JTable.AUTO_RESIZE_OFF );
|
|
|
|
|
@ -174,9 +188,23 @@ public class Importer extends CustomJDialog
|
|
|
|
|
|
|
|
|
|
private void acceptResult()
|
|
|
|
|
{
|
|
|
|
|
Vector v = new Vector( Arrays.asList( e2da.getRow( table.getSelectedRow() ) ) );
|
|
|
|
|
v.add( "" );
|
|
|
|
|
vals = (String[]) v.toArray( new String[]{} );
|
|
|
|
|
if( multipleSelection )
|
|
|
|
|
{
|
|
|
|
|
int rows[] = table.getSelectedRows();
|
|
|
|
|
vals = new String[ rows.length ][];
|
|
|
|
|
for( int i = 0; i < rows.length; ++i )
|
|
|
|
|
{
|
|
|
|
|
Vector v = new Vector( Arrays.asList( e2da.getRow( rows[ i ] ) ) );
|
|
|
|
|
v.add( "" );
|
|
|
|
|
vals[ i ] = (String[]) v.toArray( new String[ v.size() ] );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Vector v = new Vector( Arrays.asList( e2da.getRow( table.getSelectedRow() ) ) );
|
|
|
|
|
v.add( "" );
|
|
|
|
|
vals = new String[][] { ( String[] )v.toArray( new String[ v.size() ] ) };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
System.out.println( "row: " + table.getSelectedRow() );
|
|
|
|
|
@ -194,6 +222,10 @@ public class Importer extends CustomJDialog
|
|
|
|
|
|
|
|
|
|
public Hashtable getData()
|
|
|
|
|
{
|
|
|
|
|
if( names == null || vals == null )
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
dcw = new DataChooserWindow( null, names, vals, DEFAULT_SELECTION );
|
|
|
|
|
|
|
|
|
|
if( canceled || ( dcw == null ) )
|
|
|
|
|
@ -201,27 +233,56 @@ public class Importer extends CustomJDialog
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return dcw.getData();
|
|
|
|
|
return dcw.getData( multipleSelection );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void main( String args[] )
|
|
|
|
|
{
|
|
|
|
|
Importer im = null;
|
|
|
|
|
try
|
|
|
|
|
// FileDialog fd = new FileDialog( null, "Escolha um ficheiro Excel:", FileDialog.LOAD );
|
|
|
|
|
// fd.setDirectory( System.getProperty( "user.home" ) );
|
|
|
|
|
// fd.setFilenameFilter( new FilenameFilter() {
|
|
|
|
|
// public boolean accept( File dir, String name )
|
|
|
|
|
// {
|
|
|
|
|
// return (name!=null) && (name.indexOf( ".xls" ) != -1);
|
|
|
|
|
// }
|
|
|
|
|
// } );
|
|
|
|
|
// fd.show();
|
|
|
|
|
String filename = "c:\\teste_com_dados.xls";
|
|
|
|
|
//String filename = fd.getFile();
|
|
|
|
|
if( filename != null )
|
|
|
|
|
{
|
|
|
|
|
im = new Importer( null,
|
|
|
|
|
//filename = fd.getDirectory() + File.separator + filename;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
Importer importer = new Importer( null, filename, true );
|
|
|
|
|
Hashtable hash = importer.getData();
|
|
|
|
|
if( hash != null )
|
|
|
|
|
{
|
|
|
|
|
System.out.println( "Data: " + hash );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch( Exception ex )
|
|
|
|
|
{
|
|
|
|
|
ex.printStackTrace();
|
|
|
|
|
JOptionPane.showMessageDialog( null, "Erro a importar", "Erro...", JOptionPane.ERROR_MESSAGE );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 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\\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();
|
|
|
|
|
}
|
|
|
|
|
// );
|
|
|
|
|
//
|
|
|
|
|
//System.out.println( "Escolhido: " + im.getData() );
|
|
|
|
|
//
|
|
|
|
|
// }
|
|
|
|
|
// catch( Exception e )
|
|
|
|
|
// {
|
|
|
|
|
// e.printStackTrace();
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// String[][] all = (String[][]) e.getObjects();
|
|
|
|
|
//
|
|
|
|
|
|