The visual editor expects and requires a few things about the structure of the class you want to edit.
The easiest way to get started is to create the class with the New → Vaadin Custom Component wizard (if I remember the name correctly). You should not touch the methods marked with the @AutoGenerated annotation directly - they are overwritten by the visual editor, and only certain statements are supported in them if you want to re-open the class with the visual editor - but write your custom code in other parts of the class.