/**
* WS-Attacker - A Modular Web Services Penetration Testing Framework Copyright
* (C) 2010 Christian Mainka
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc., 51
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package wsattacker.gui.component.pluginconfiguration.option;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JList;
import javax.swing.filechooser.FileFilter;
import wsattacker.gui.component.pluginconfiguration.composition.OptionGUI;
import wsattacker.main.composition.plugin.option.AbstractOption;
import wsattacker.main.composition.plugin.option.AbstractOptionMultiFiles;
import wsattacker.main.plugin.option.OptionSimpleMultiFiles;
public class OptionMultiFileGUI_NB
extends OptionGUI
{
private AbstractOptionMultiFiles option = new OptionSimpleMultiFiles( "Sample File Option",
"Sample File Description" );
public static final String PROP_OPTION = "option";
/**
* Get the value of option
*
* @return the value of option
*/
public AbstractOptionMultiFiles getOption()
{
return option;
}
/**
* Set the value of option
*
* @param option new value of option
*/
public void setOption( AbstractOptionMultiFiles option )
{
AbstractOptionMultiFiles oldOption = this.option;
this.option = option;
firePropertyChange( PROP_OPTION, oldOption, option );
}
/**
* Creates new form OptionVarcharGUI_NB
*/
public OptionMultiFileGUI_NB()
{
initComponents();
}
public OptionMultiFileGUI_NB( AbstractOptionMultiFiles option )
{
this.option = option;
initComponents();
}
private void setValueBackgroundIfError( boolean error )
{
if ( error )
{
fileButton.setBackground( COLOR_ERROR );
}
else
{
fileButton.setBackground( COLOR_OK );
}
}
/**
* This method is called from within the constructor to initialize the form. WARNING: Do NOT modify this code. The
* content of this method is always regenerated by the Form Editor.
*/
@SuppressWarnings( "unchecked" )
// <editor-fold defaultstate="collapsed"
// desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents()
{
bindingGroup = new org.jdesktop.beansbinding.BindingGroup();
fileChooser = new javax.swing.JFileChooser();
name = new javax.swing.JLabel();
description = new javax.swing.JLabel();
currentFileLabel = new javax.swing.JLabel();
typeLabel = new javax.swing.JLabel();
typeValue = new javax.swing.JLabel();
fileButton = new javax.swing.JButton();
fileListScrollPane = new javax.swing.JScrollPane();
fileList = new javax.swing.JList();
removeButton = new javax.swing.JButton();
fileChooser.setDialogTitle( "Select the Files" );
fileChooser.setFileFilter( new FileFilter()
{
@Override
public String getDescription()
{
return getOption().getDescription();
}
@Override
public boolean accept( File f )
{
// always show directories
if ( f.isDirectory() )
{
return true;
}
return getOption().isValid( f );
}
} );
fileChooser.setMultiSelectionEnabled( true );
name.setFont( new java.awt.Font( "Dialog", 1, 18 ) ); // NOI18N
org.jdesktop.beansbinding.Binding binding =
org.jdesktop.beansbinding.Bindings.createAutoBinding( org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ,
this,
org.jdesktop.beansbinding.ELProperty.create( "${option.name}" ),
name,
org.jdesktop.beansbinding.BeanProperty.create( "text" ) );
binding.setSourceNullValue( "Option Name" );
binding.setSourceUnreadableValue( "Option Name" );
bindingGroup.addBinding( binding );
description.setFont( new java.awt.Font( "Dialog", 0, 12 ) ); // NOI18N
binding =
org.jdesktop.beansbinding.Bindings.createAutoBinding( org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ,
this,
org.jdesktop.beansbinding.ELProperty.create( "${option.description}" ),
description,
org.jdesktop.beansbinding.BeanProperty.create( "text" ) );
binding.setSourceNullValue( "Option Description" );
binding.setSourceUnreadableValue( "Option Description" );
bindingGroup.addBinding( binding );
currentFileLabel.setFont( new java.awt.Font( "Dialog", 0, 12 ) ); // NOI18N
currentFileLabel.setText( "Current Files:" );
typeLabel.setFont( new java.awt.Font( "Dialog", 0, 12 ) ); // NOI18N
typeLabel.setText( "Type:" );
typeValue.setText( "multiple File" );
fileButton.setText( "Select Files" );
fileButton.addActionListener( new java.awt.event.ActionListener()
{
public void actionPerformed( java.awt.event.ActionEvent evt )
{
fileButtonActionPerformed( evt );
}
} );
fileList.setModel( new javax.swing.AbstractListModel()
{
String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
public int getSize()
{
return strings.length;
}
public Object getElementAt( int i )
{
return strings[i];
}
} );
fileList.setLayoutOrientation( javax.swing.JList.HORIZONTAL_WRAP );
org.jdesktop.beansbinding.ELProperty eLProperty =
org.jdesktop.beansbinding.ELProperty.create( "${option.files}" );
org.jdesktop.swingbinding.JListBinding jListBinding =
org.jdesktop.swingbinding.SwingBindings.createJListBinding( org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ,
this, eLProperty, fileList );
jListBinding.setDetailBinding( org.jdesktop.beansbinding.ELProperty.create( "${name}" ) );
bindingGroup.addBinding( jListBinding );
fileListScrollPane.setViewportView( fileList );
removeButton.setText( "Remove Selected" );
removeButton.addActionListener( new java.awt.event.ActionListener()
{
public void actionPerformed( java.awt.event.ActionEvent evt )
{
removeButtonActionPerformed( evt );
}
} );
javax.swing.GroupLayout layout = new javax.swing.GroupLayout( this );
this.setLayout( layout );
layout.setHorizontalGroup( layout.createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING ).addGroup( layout.createSequentialGroup().addContainerGap().addGroup( layout.createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING ).addGroup( layout.createSequentialGroup().addGroup( layout.createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING ).addGroup( layout.createSequentialGroup().addComponent( typeLabel ).addGap( 15,
15,
15 ).addComponent( typeValue ).addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.RELATED ).addComponent( currentFileLabel ).addGap( 0,
0,
Short.MAX_VALUE ) ).addComponent( fileListScrollPane ) ).addContainerGap() ).addGroup( layout.createSequentialGroup().addGroup( layout.createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING ).addComponent( name ).addGroup( layout.createSequentialGroup().addComponent( fileButton ).addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.RELATED ).addComponent( removeButton ) ).addComponent( description ) ).addContainerGap( javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE ) ) ) ) );
layout.linkSize( javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] { fileButton, removeButton } );
layout.setVerticalGroup( layout.createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING ).addGroup( layout.createSequentialGroup().addContainerGap().addComponent( name ).addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.RELATED ).addGroup( layout.createParallelGroup( javax.swing.GroupLayout.Alignment.BASELINE ).addComponent( fileButton ).addComponent( removeButton ) ).addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.RELATED ).addGroup( layout.createParallelGroup( javax.swing.GroupLayout.Alignment.BASELINE ).addComponent( currentFileLabel ).addComponent( typeLabel ).addComponent( typeValue ) ).addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.RELATED ).addComponent( fileListScrollPane,
javax.swing.GroupLayout.PREFERRED_SIZE,
94,
javax.swing.GroupLayout.PREFERRED_SIZE ).addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.RELATED,
javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE ).addComponent( description ) ) );
bindingGroup.bind();
}// </editor-fold>//GEN-END:initComponents
private void fileButtonActionPerformed( java.awt.event.ActionEvent evt )
{// GEN-FIRST:event_fileButtonActionPerformed
int returnVal = fileChooser.showOpenDialog( this );
if ( returnVal == JFileChooser.APPROVE_OPTION )
{
File[] files = fileChooser.getSelectedFiles();
boolean valid = option.isValid( files );
setValueBackgroundIfError( !valid );
if ( valid )
{
option.setFilesAsArray( files );
}
}
}// GEN-LAST:event_fileButtonActionPerformed
private void removeButtonActionPerformed( java.awt.event.ActionEvent evt )
{// GEN-FIRST:event_removeButtonActionPerformed
int[] selected = fileList.getSelectedIndices();
Arrays.sort( selected );
List<File> currentFileList = new ArrayList<File>( option.getFiles() );
for ( int i = selected.length - 1; i >= 0; --i )
{
currentFileList.remove( selected[i] );
}
option.setFiles( currentFileList );
}// GEN-LAST:event_removeButtonActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JLabel currentFileLabel;
private javax.swing.JLabel description;
private javax.swing.JButton fileButton;
private javax.swing.JFileChooser fileChooser;
private javax.swing.JList fileList;
private javax.swing.JScrollPane fileListScrollPane;
private javax.swing.JLabel name;
private javax.swing.JButton removeButton;
private javax.swing.JLabel typeLabel;
private javax.swing.JLabel typeValue;
private org.jdesktop.beansbinding.BindingGroup bindingGroup;
// End of variables declaration//GEN-END:variables
@Override
public void bindingDoUnbind()
{
bindingGroup.unbind();
}
public JList getFileList()
{
return fileList;
}
public JButton getRemoveButton()
{
return removeButton;
}
@Override
public AbstractOption getUsedOption()
{
return option;
}
}