I have problem with change of tab panel layout by click event on buto开发者_如何转开发n located on that panel. The main idea is to have custom menu (new, open, del) on smal panel on every tab panel. When you click button, tab panel layout is change to form (for example). I don't want use modal window or new window, just change the tab panel layout (content) to something else by button click.
It, is wrong specified question - you should ask how to notify parent component. Bellow you have two examples show how to achive your goals. This first implementation does what Jens Janssons suggest on vaadin forum, you pass the ClickListener to the second panel as a constructor parameter. Note that to be able to remove the component from the outer panel, you need both a reference to the outer panel and to the inner panel. In this example Kim Lappanen stored the references in class variables. Note that ther is actually used a HorizontalLayout for what you called your "panel", you can change it.
public class TestcaseApplication extends Application implements ClickListener {
private static final long serialVersionUID = 75232258896642392L;
private final HorizontalLayout mainLayout = new HorizontalLayout();
private final YourPanel panel = new YourPanel(this);
@Override
public void init() {
setTheme("example");
Window mainWindow = new Window("Playground Application");
setMainWindow(mainWindow);
mainWindow.setContent(mainLayout);
mainLayout.addComponent(panel);
}
public void buttonClick(ClickEvent event) {
mainLayout.removeComponent(panel);
}
public class YourPanel extends Panel {
public YourPanel(ClickListener listener) {
super();
addComponent(new Button("Remove", listener));
}
}
}
Antoher example is to implement the ClickListener directly in the inner panel. In the buttonClick method, I just call getParent() (returns the out layout) and then removes itself from that layout.
public class TestcaseApplication extends Application {
private static final long serialVersionUID = 75232258896642392L;
@Override
public void init() {
setTheme("example");
Window mainWindow = new Window("Playground Application");
setMainWindow(mainWindow);
HorizontalLayout mainLayout = new HorizontalLayout();
mainWindow.setContent(mainLayout);
mainLayout.addComponent(new YourPanel());
}
public class YourPanel extends Panel implements ClickListener {
public YourPanel() {
super();
addComponent(new Button("Remove", this));
}
public void buttonClick(ClickEvent event) {
((ComponentContainer) getParent()).removeComponent(this);
}
}
}
精彩评论