/** * 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.util.Arrays; import java.util.Collections; import java.util.List; import org.jdesktop.beansbinding.Binding; import org.jdesktop.beansbinding.Validator; import wsattacker.gui.component.pluginconfiguration.composition.OptionGUI; import static wsattacker.gui.component.pluginconfiguration.composition.OptionGUI.COLOR_ERROR; import static wsattacker.gui.component.pluginconfiguration.composition.OptionGUI.COLOR_OK; import wsattacker.main.composition.plugin.option.AbstractOption; import wsattacker.main.composition.plugin.option.AbstractOptionChoice; import wsattacker.main.plugin.option.OptionSimpleChoice; public class OptionChoiceGUI_NB extends OptionGUI { final private List<String> FALLBACKCHOICES = Arrays.asList( "Currently no Data" ); private AbstractOptionChoice option = new OptionSimpleChoice( "Sample Option", Collections.<String> emptyList(), 0, "Sample Description" ); public static final String PROP_OPTION = "option"; /** * Get the value of optionChoice * * @return the value of optionChoice */ public AbstractOptionChoice getOption() { return option; } /** * Set the value of optionChoice * * @param option new value of optionChoice */ public void setOption( AbstractOptionChoice option ) { AbstractOptionChoice oldOptionChoice = this.option; this.option = option; firePropertyChange( PROP_OPTION, oldOptionChoice, option ); } /** * Creates new form OptionChoiceGUI_NB */ public OptionChoiceGUI_NB() { initComponents(); } public OptionChoiceGUI_NB( AbstractOptionChoice option ) { this.option = option; initComponents(); } /** * 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(); name = new javax.swing.JLabel(); choices = new javax.swing.JComboBox(); description = new javax.swing.JLabel(); 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 ); choices.setModel( new javax.swing.DefaultComboBoxModel( new String[] { "Item 1", "Item 2", "Item 3", "Item 4" } ) ); org.jdesktop.beansbinding.ELProperty eLProperty = org.jdesktop.beansbinding.ELProperty.create( "${option.choices}" ); org.jdesktop.swingbinding.JComboBoxBinding jComboBoxBinding = org.jdesktop.swingbinding.SwingBindings.createJComboBoxBinding( org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ, this, eLProperty, choices ); jComboBoxBinding.setSourceNullValue( FALLBACKCHOICES ); jComboBoxBinding.setSourceUnreadableValue( FALLBACKCHOICES ); bindingGroup.addBinding( jComboBoxBinding ); binding = org.jdesktop.beansbinding.Bindings.createAutoBinding( org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, this, org.jdesktop.beansbinding.ELProperty.create( "${option.selectedAsString}" ), choices, org.jdesktop.beansbinding.BeanProperty.create( "selectedItem" ) ); binding.setValidator( new Validator<String>() { @Override public Validator<String>.Result validate( String value ) { Validator<String>.Result result = null; if ( !getOption().isValid( value ) ) { result = new Validator.Result( 1, "Value invalid" ); setValueBackgroundIfError( true ); } else { setValueBackgroundIfError( false ); } return result; } } ); bindingGroup.addBinding( binding ); description.setFont( new java.awt.Font( "Dialog", 0, 12 ) ); // NOI18N description.setVerticalAlignment( javax.swing.SwingConstants.TOP ); 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 ); 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( javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup().addGroup( layout.createParallelGroup( javax.swing.GroupLayout.Alignment.TRAILING ).addComponent( description, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE ).addComponent( choices, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE ) ).addContainerGap() ).addGroup( layout.createSequentialGroup().addComponent( name, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE ).addGap( 388, 388, 388 ) ) ) ) ); layout.setVerticalGroup( layout.createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING ).addGroup( layout.createSequentialGroup().addContainerGap().addComponent( name ).addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.RELATED ).addComponent( choices, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE ).addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.RELATED ).addComponent( description ).addContainerGap( javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE ) ) ); bindingGroup.bind(); }// </editor-fold>//GEN-END:initComponents // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JComboBox choices; private javax.swing.JLabel description; private javax.swing.JLabel name; private org.jdesktop.beansbinding.BindingGroup bindingGroup; // End of variables declaration//GEN-END:variables private void setValueBackgroundIfError( boolean error ) { if ( error ) { choices.setBackground( COLOR_ERROR ); } else { choices.setBackground( COLOR_OK ); } } @Override public void bindingDoUnbind() { // The following command will throw an exception // bindingGroup.unbind(); List<Binding> bindingList = bindingGroup.getBindings(); for ( int i = bindingList.size() - 1; i >= 0; --i ) { bindingList.get( i ).unbind(); } } @Override public AbstractOption getUsedOption() { return option; } }