Table : setColumnCollapsed

Hi folks,

I have two questions about setColumnCollapsed method on table component.

  • If I try to collapse some columns on table (via a button clicklistener). Result : columns are not displayed but column’s headers still displayed on my table and the drop down menu (top right of table) said that column are not collapsed.
  • If I use an Handler to set actions and call method in order to collapse columns, nothing happens.

I’m not sure what I’m doing wrong. Maybe it’s normal or if it’s a bug. Note that I use Vaadin v6.1.2 to do my test.
To explain what I said exactly you can find my class bellow.

Thanks in advance for your help.


public class TableTesting extends Application implements Handler, ClickListener {
	/**
	 * 
	 */
	private Window mainWindow;
	private Table table = new Table();
	private Action hideColumn = new Action("Hide");
	private Action unHideColumn = new Action("UnHide");
	private Action[] actions = new Action[]
 { hideColumn, unHideColumn };
	private Random random = new Random();
	private String[] columns = new String[]
 { "Column1", "Column2", "Column3", "Column4" };
	private Button btHide = new Button("Hide Columns");
	private Button btUnHide = new Button("UnHide Columns");

	@Override
	public void init() {
		mainWindow = new Window("Collapsed Columns");
		setMainWindow(mainWindow);
		table.setColumnCollapsingAllowed(true);
		table.addActionHandler(this);
		btHide.addListener(this);
		btUnHide.addListener(this);
		loadTable(random.nextInt(10));

		mainWindow.addComponent(table);
		mainWindow.addComponent(btHide);
		mainWindow.addComponent(btUnHide);
	}

	/**
	 * @param itemNumber
	 */
	private void loadTable(int itemNumber) {
		HierarchicalContainer container = createContainer();
		for (int j = 0; j < itemNumber; j++) {
			Item rowItem = container.addItem(j);
			if (rowItem != null) {
				for (int i = 0; i < columns.length; i++) {
					rowItem.getItemProperty(columns[i]
).setValue("Value" + j);
				}
			}
		}
		table.setContainerDataSource(container);
	}

	/**
	 * @return
	 */
	private HierarchicalContainer createContainer() {
		final HierarchicalContainer c = new HierarchicalContainer();
		for (int i = 0; i < columns.length; i++) {
			c.addContainerProperty(columns[i]
, String.class, null);
		}
		return c;
	}

	/**
	 * @param visibility
	 */
	private void setColumnVisibility(Boolean visibility) {
		Iterator it = table.getContainerPropertyIds().iterator();
		while (it.hasNext()) {
			String propertyId = it.next().toString();
			try {
				table.setColumnCollapsed(propertyId, visibility);
			} catch (IllegalAccessException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}

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

	@Override
	public void handleAction(Action action, Object sender, Object target) {
		if (action == hideColumn) {
			setColumnVisibility(true);
		} else if (action == unHideColumn)
			setColumnVisibility(false);
	}

	@Override
	public void buttonClick(ClickEvent event) {
		if (event.getButton().equals(btHide)) {
			setColumnVisibility(true);
		} else if (event.getButton().equals(btUnHide)) {
			setColumnVisibility(false);
		}

	}
}

I just gave your code a run and it seems to be correct, but not working. It only works after you force a browser refresh (F5). RequestRepaint() and RequestRepaintAll() did not do any good. Changing the collapsing in the ui after doing it in the Java causes really strange behaviour. Seems like a bug. I suggest you file a
bug ticket
. Note, you need to register to file it.

Thanks for your explanations, I have reported a new bug on Trac.