VerticalLayout patch

I needed some stuff from the underlying API that doesn’t make it through, and wanted to patch, but had this error:

My code:

package vaadin.patch;

import com.vaadin.terminal.gwt.client.ui.VVerticalLayout;
import com.vaadin.ui.AbstractOrderedLayout;
import com.vaadin.ui.ClientWidget;
import com.vaadin.ui.Component;
import com.vaadin.ui.ClientWidget.LoadStyle;

@ClientWidget(value = VVerticalLayout.class, loadStyle = LoadStyle.EAGER)
public class VerticalLayout extends AbstractOrderedLayout {
	public VerticalLayout() {
		setWidth("100%");
	}
	
	[color=#FF0000]
public int size(){
		return super.components.size();
	}
[/color]

    public void setComponent(Component c, int index) {
        components.set(index, c);
        requestRepaint();
    }
}

What else needs be done for it to work? Anyway, i just wanted the above methods from the VerticalLayout, what can i do about it? components linked list is protected in AbstractOrderedLayout and it becomes private in the first subclass, closing any inheritance.

What i needed to do was this:

if(sumsNavigation.size() > AnalysisUtil.CRITERIA_POS)
				sumsNavigation.removeComponent(sumsNavigation.getComponent(AnalysisUtil.CRITERIA_POS));

Otherwise i can get index out of bounds.

Did you recompile the widgetset? Although it might seem like it should work without compilation, the compilation actually creates the mapping between all the server side classes and client side implementations. So when you modify any of the @ClientWidget mappings, you need to recompile the widgetset.

And about the patch, this really should be in the core. I think there’s a ticket about it already, but it’s more than good that someone actually promotes it from the outside.

Recompiling the widgetset, on the project like it is, in place? Since there is none in my project other than the default in the original jar, i would have to put up a widgetsetfile.gwt.xml. Would i have to inherit anything in it?

EDIT: Thank you, hopefully this would suffice:
http://vaadin.com/book/-/page/gwt.eclipse.html#gwt.eclipse.compiling
<—EDIT2: forgot links don’t get parsed into tags by themselves, sorry -_-

But i won’t be doing it rigth now, yesterday had some fun punching a hole in data hiding with reflection:

static Field getField(Class c, String fieldName)
			throws NoSuchFieldException {
		try {
			return c.getDeclaredField(fieldName);
		} catch (NoSuchFieldException e) {
			Class superClass = c.getSuperclass();
			if (superClass == null) {
				throw e;
			} else {
				return getField(superClass, fieldName);
			}
		}
	}

	static Object readFieldsMethod(Object o, String fieldName, String methodName) {
		Class c = o.getClass();
		Field field = null;
		try {
			field = getField(c, fieldName);
		} catch (NoSuchFieldException e) {
			e.printStackTrace();
		}
		field.setAccessible(true);
		Object oReturn = null;
		Method m;
		try {
			m = field.getType().getMethod(methodName);
			m.setAccessible(true);
			oReturn = m.invoke(field.get(o));
		} catch (SecurityException e) {
			e.printStackTrace();
		} catch (NoSuchMethodException e) {
			e.printStackTrace();
		} catch (IllegalArgumentException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			e.printStackTrace();
		}
		return oReturn;
	}

This is addressed in
ticket 4611
, for Vaadin 6.5.