msg.append("Changed selection: ");
HTMLCollection col = selectElem.getOptions();
int len = col.getLength();
for(int i = 0; i < len; i++)
{
HTMLOptionElement option = (HTMLOptionElement)col.item(i);
msg.append( option.getText() + " (" + option.getSelected() + ") " );
}
log(msg.toString());
}
else if (currentTarget == removeElem)
{
HTMLCollection col = selectElem.getOptions();
int len = col.getLength();
HTMLOptionElement[] toRemove = new HTMLOptionElement[len];
for(int i = 0; i < len; i++)
{
HTMLOptionElement option = (HTMLOptionElement)col.item(i);
if (option.getSelected())
toRemove[i] = option;
}
for(int i = 0; i < len; i++)
{
HTMLOptionElement option = toRemove[i];
if (option != null)
selectElem.removeChild(toRemove[i]);
}
}
else if ((currentTarget == updateElem) ||
(currentTarget == insertElem))
{
Document doc = getItsNatDocument().getDocument();
String newItem = itemElem.getValue();
try
{
int pos = Integer.parseInt(posElem.getValue());
if (currentTarget == updateElem)
{
HTMLOptionElement option = getOptionElement(pos);
if (option != null)
ItsNatDOMUtil.setTextContent(option,newItem);
else
getItsNatDocument().addCodeToSend("alert('Bad Position');");
}
else
{
HTMLOptionElement before = (HTMLOptionElement)getOptionElement(pos);
HTMLOptionElement added = (HTMLOptionElement)doc.createElement("option");
added.appendChild(doc.createTextNode(newItem));
selectElem.add(added, before);
selectElem.setSelectedIndex(pos);
}
}
catch(NumberFormatException ex)