Editing a row fail after a scroll has been done

Hi,

I have extended the Table and added many different kind of features so I know this might not be to easy to answer but has anyone else had a problem with not being able to edit a single row after the table has scrolled down like 40 rows?

So what iv got is a table that implements an ChangeEventListener that set different context menus depending on if there are more then one row selected or not. If “edit” is selected from the context menu the rows selected will become editable. But as I said if I first scroll 40 rows down then try to edit the rows the table acts strange. Its almost as if its got Focus on some other rows or something? Its not a latency problem because it dosnt help to wait longer or anything like that.

This is part of my code, most of the code comes from the samples. [code]

class ExtendedValueChangeListener implements Property.ValueChangeListener
{
private static final long serialVersionUID = 1L;

	@Override
	public void valueChange(com.vaadin.data.Property.ValueChangeEvent event) {
		if(isEditable()){
			setEditable(false);
		}
		selectedRows = (Set<Object>) event.getProperty().getValue();

		if(selectedRows == null || selectedRows.size() == 0){
			extActionHandler.setCurrentAction(ACTIONS_EDIT);		
		}else if(selectedRows.size() == 1){
			extActionHandler.setCurrentAction(ACTIONS_EDIT);		
			requestRepaint();
		}else{
			if(extActionHandler.getCurrentAction() != ACTIONS_EDIT_ALL)
			{
				extActionHandler.setCurrentAction(ACTIONS_EDIT_ALL);
				requestRepaint();
			}
		}
	}		
}


/**
 * The action handler is the context menu in the table.
 * We have a handler that takes the appropriate action on events.
 */
class ExtendedActionHandler implements Action.Handler{
	private static final long serialVersionUID = 1L;
	private Action[] currentAction = null;

	@Override
	public Action[] getActions(Object target, Object sender) {			
		return currentAction;
	}

	@Override
	public void handleAction(Action action, Object sender, Object target) {
		if(action == ACTION_EDIT_ALL_MODAL){
			if (subwindow != null && subwindow.getParent() != null) {
				subwindow.bringToFront();					
			} else {	      
				subwindow = new Window("Edit contacts");
				subwindow.setModal(true);

				VerticalLayout layout = (VerticalLayout) subwindow.getContent();
				layout.setMargin(true);
				layout.setSpacing(true);

				Object data = (Object)selectedRows.iterator().next();
				try {
					if(getContainerDataSource() instanceof JPAContainer){
						data = ((JPAContainer) getContainerDataSource()).getItem(data).getEntity();
					}
					T dataEmpty = (T) data.getClass().newInstance();						
					modalForm.setItemDataSource(new BeanItem<T>(dataEmpty));
					modalForm.setVisibleItemProperties(editableColumns);
					modalForm.setData(dataEmpty);
				} catch (InstantiationException e) {
					getParent().getWindow().showNotification("An error has occured: Cannot create new class instance.\nPlease contact support.", Notification.TYPE_ERROR_MESSAGE);
					e.printStackTrace();
				} catch (IllegalAccessException e) {
					getParent().getWindow().showNotification("An error has occured: Illegalaccess exception occured.\nPlease contact support.", Notification.TYPE_ERROR_MESSAGE);
					e.printStackTrace();
				}

				subwindow.addComponent(modalForm);
				subwindow.setWidth("720px");
				subwindow.center();					
				getParent().getWindow().addWindow(subwindow);

			}
		}else{
			setEditable(true);
		}	    

	}		
	public Action[] getCurrentAction() {
		return currentAction;
	}

	public void setCurrentAction(Action[] currentAction) {
		this.currentAction = currentAction;

	}
}

class ExtendedTableFieldFactory implements TableFieldFactory{
	private static final long serialVersionUID = 1L;

	public Field createField(Container container, Object itemId, Object propertyId, Component uiContext){
		
		if(GetSelectedRows() != null){
			//if we haven't specified what columns to edit then we edit all.
			if(getEditableColumns() != null){
				if(getEditableColumns().contains(propertyId) && GetSelectedRows().contains(itemId)){
					if(specialFields.get(propertyId) != null){
						try {
							Field f =  specialFields.get(propertyId).getClass().newInstance();
							if(f instanceof ComboBox){
								// super ugly fix, need to rework this.
								((ComboBox) f).setContainerDataSource(((ComboBox)specialFields.get(propertyId)).getContainerDataSource());
								f.setWidth(specialFields.get(propertyId).getWidth()+"");
							}
							return f;
						} catch (InstantiationException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						} catch (IllegalAccessException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
					}
					return new com.vaadin.ui.TextField();
				}
			}else{
				if(GetSelectedRows().contains(itemId)){
					if(specialFields.get(propertyId) != null){
						return specialFields.get(propertyId);
					}
					return new com.vaadin.ui.TextField();
				}
			}
			
		}
		return null;
	}
}

/**
 * Adds special fields to to form in the table.
 * @param field The kind of field. This could be a combobox
 * @param name The name is should have in the Map
 * @param myClass The class
 * @param myEnum The enum that holds the possible values
 */
public void addSpecialFields(Field field, String name, Class myClass, EnumSet myEnum){
	
	if(field instanceof ComboBox){
		ComboBox c = (ComboBox)field;
		c.setContainerDataSource(new BeanItemContainer(myClass, myEnum));
		c.setWidth(CalculateDropdownListWidth(myEnum));
		c.setCaption(name);
		specialFields.put(name, c);
	}
	
	setTableFieldFactory(new ExtendedTableFieldFactory());
}

[/code]
Thx for any help!

Hi,

It’s hard to say what could be wrong, but the repaints and the field factory get me rather worried. What you are attempting to do is a bit unusual, so I wouldn’t be surprised if there are some problems. I’ve also had some focusing problems with one
test application
, but haven’t had time to examine further.

Remember that the field factory is called when you scroll the table and new items come into view. Actually, a number of items above and below the visible view are cached, so that may be the reason why you are experiencing the problem when scrolling down a bit.

You could try debugging the problem by seeing how the factory and the value change listener are called when you focus a field and when you scroll down the table.

I solved the problem, the problem occured thanks to a repaint in the ChangeEventListener.
Thx for helping out!

/Marthin