I am developing a pure Vaadin 7 - application from scratch. in this application I want to use a custom widget which will show some special graphical stuff. It’s very important for me to handle the resizing when the user changs the size o th browser-window.
To test the integration with vaadin I started with a widget which extends a ResizeComposite (which is able to track the resizing). I started with some buttons with some simple ClickHandlers for tst purposes and a label which are layouted by a HeaderPanel:
public class DendrogramWidget extends ResizeComposite {
public static final String CLASSNAME = "dendrogram";
private HeaderPanel mainPanel;
private Button header = new Button("graph-header");
private Button footer = new Button("graph-footer");
private Label label = new Label("later on, here will come the graphical stuff");
public DendrogramWidget() {
this.mainPanel = new HeaderPanel();
this.initWidget(this.mainPanel);
this.setStyleName(CLASSNAME);
this.mainPanel.setSize("100%", "100%");
this.mainPanel.add(header);
this.mainPanel.add(label);
this.mainPanel.add(footer);
this.mainPanel.setHeaderWidget(header);
this.mainPanel.setContentWidget(label);
this.mainPanel.setFooterWidget(footer);
this.header.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
String name = ((Button)event.getSource()).getText();
label.setText("clicked on "+name);
}
});
this.footer.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
String name = ((Button)event.getSource()).getText();
label.setText("clicked on "+name);
}
});
}
@Override
public void onResize() {
super.onResize();
label.setText("onResize() called ["+DendrogramWidget.this.getOffsetWidth()+","+DendrogramWidget.this.getOffsetHeight()+"]
");
}
}
The server-side Code looks like this:
[code]
@Theme(“kuba”)
public class KubaUI extends UI {
@Override
protected void init(VaadinRequest request) {
final Layout layout = this.createComponents();
this.setContent(layout);
}
private Layout createComponents() {
VerticalLayout mainLayout = new VerticalLayout();
mainLayout.setSizeFull();
// placeholder title
Panel title = new Panel("title");
title.setWidth("100%");
mainLayout.addComponent(title);
// placeholder toolbar
Panel toolbar = new Panel("toolbar");
toolbar.setWidth("100%");
mainLayout.addComponent(toolbar);
// content area
HorizontalLayout contentLayout = new HorizontalLayout();
contentLayout.setSizeFull();
mainLayout.addComponent(contentLayout);
mainLayout.setExpandRatio(contentLayout, 1);
Dendrogram dendrogram = new Dendrogram();
dendrogram.setSizeFull();
contentLayout.addComponent(dendrogram);
contentLayout.setExpandRatio(dendrogram, 0.5f);
// placeholder product-table
Panel products = new Panel("product-table");
products.setSizeFull();
contentLayout.addComponent(products);
contentLayout.setExpandRatio(products, 0.2f);
// placeholder kpi-table
Panel kpis = new Panel("kpi-table");
kpis.setSizeFull();
contentLayout.addComponent(kpis);
contentLayout.setExpandRatio(kpis, 0.3f);
// placeholder statusline
Panel status = new Panel("status line");
status.setWidth("100%");
mainLayout.addComponent(status);
return mainLayout;
}
}
[/code]As you can see, I’m concentrating on the general layout first. The Vaadin-Integration works very well and the Layout acts as expected, but there is an issue concerning the resizing of the custom widget. I have to listen to resize-events because I will have to rearrange the graphical content in the widget. I’m doing this by overriding the onResize()-Method of the ResizeComposite.
But unfortunately nothing happens- it seems like onResize() isn’t called at all. I also tried to add a Resize-EventHandler to the HeaderPanel without success.
What’s wrong? I’m quite new to Vaadin - maybe I am missing something… For now I’m totally stuck…
Any suggestions?
Greetings, Jens