JPanel parent = this;
int errorIndex = 0;
while(it.hasNext()) {
Component comp = null;
KnockModelListener knockModel = null;
UserInput userInput = it.next();
errors.add(null);
if(userInput instanceof UserInputEditable) {
//еденичное значение
UserInputEditable uie = (UserInputEditable) userInput;
if(uie.getValue() instanceof Boolean) {
//булевое
JCheckBox check = new JCheckBox("Да", (Boolean)uie.getValue());
comp = check;
CheckBoxActionListener model = new CheckBoxActionListener(uie, errorIndex);
knockModel = model;
check.addActionListener(model);
} else if(uie.getValue() instanceof Date) {
JDateChooser dc = new JDateChooser((Date)uie.getValue());
comp = dc;
DateListener model = new DateListener(uie, errorIndex);
knockModel = model;
dc.getDateEditor().addPropertyChangeListener(model);
} else {
//не булевое - целое, вещественное, строка
JTextArea ta = new JTextArea(uie.getValue().toString());
comp = ta;
TxtFieldDocumentListener model = new TxtFieldDocumentListener(uie, errorIndex);
knockModel = model;
ta.getDocument().addDocumentListener(model);
}
} else if(userInput instanceof UserInputSelect) {
//выбор из множества
UserInputSelect uis = (UserInputSelect) userInput;
ArrayList<Integer> selectedRows = uis.getSelected();
if(uis.getActiveRows().isSingle()) {
//единичный выбор
JComboBox combo = new JComboBox(uis.getOptions().toArray());
if(selectedRows == null
|| selectedRows.size() != 1) {
combo.setSelectedIndex(-1);
uis.setSelected(null);
} else {
combo.setSelectedIndex(selectedRows.get(0));
}
comp = combo;
ComboItemListener model = new ComboItemListener(uis, errorIndex);
knockModel = model;
combo.addItemListener(model);
} else {
//множественный выбор
JList list = new JList(uis.getOptions().toArray());
if(selectedRows == null
|| selectedRows.size() == 0) {
list.setSelectedIndex(-1);
uis.setSelected(null);
} else {
for(Integer row: selectedRows) {
list.getSelectionModel().addSelectionInterval(row, row);
}
}
comp = list;
ListBoxSelectionListener model = new ListBoxSelectionListener(uis, errorIndex);
knockModel = model;
list.addListSelectionListener(model);
}
} else {
JLabel label = new JLabel("Unknown value");
label.setBorder(BorderFactory.createEtchedBorder());
comp = label;
}
JPanel titlePane = new JPanel(new BorderLayout(5, 5));
JLabel title = new JLabel(userInput.getTitle());
titlePane.add(title, BorderLayout.CENTER);
JCheckBox enableCheck = new JCheckBox("");
if(!userInput.isCanBeOmitted()) {
enableCheck.setEnabled(false);
enableCheck.setSelected(true);
} else {
enableCheck.setSelected(false);
enableCheck.addActionListener(new CheckBoxListener(comp, userInput,
errorIndex, knockModel));
comp.setEnabled(false);
userInput.clearSelection();
}
titlePane.add(enableCheck, BorderLayout.WEST);
JPanel head = new JPanel(new BorderLayout(5, 5));
head.add(titlePane, BorderLayout.NORTH);