Hello
I have problems, to understand, how to load my own composites in my main window/class.
so, i have this class:
public class Test3UI extends UI {
private Button sample = new Button("Click");
private Label right = new Label("Right");
private CompositeTest ct = new CompositeTest();
private HorizontalSplitPanel hsplit = new HorizontalSplitPanel();
private Tree tree = new Tree("Hardware Inventory");
final Object[][]
planets = new Object[][]
{
new Object[]{"Mercury"},
new Object[]{"Venus"},
new Object[]{"Earth", "The Moon"},
new Object[]{"Mars", "Phobos", "Deimos"},
new Object[]{"Jupiter", "Io", "Europa", "Ganymedes","Callisto"},
new Object[]{"Saturn", "Titan", "Tethys", "Dione","Rhea", "Iapetus"},
new Object[]{"Uranus", "Miranda", "Ariel", "Umbriel","Titania", "Oberon"},
new Object[]{"Neptune", "Triton", "Proteus", "Nereid","Load1"}
};
@Override
protected void init(VaadinRequest request) {
initLayout();
changeContent();
}
public void initLayout(){
VerticalLayout mainLayout = new VerticalLayout();
mainLayout.setSizeFull();
HorizontalLayout topLayout = new HorizontalLayout();
topLayout.setMargin(false);
topLayout.setHeight("120px");
topLayout.addComponent(new Label("Top"));
mainLayout.addComponent(topLayout);
HorizontalSplitPanel hsplit = new HorizontalSplitPanel();
hsplit.setSizeFull();
hsplit.setFirstComponent(buildTree());
hsplit.setSecondComponent(right);
hsplit.setSplitPosition(220, Sizeable.UNITS_PIXELS);
mainLayout.addComponent(hsplit);
HorizontalLayout bottomLayout = new HorizontalLayout();
bottomLayout.setMargin(false);
bottomLayout.setHeight("60px");
bottomLayout.addComponent(new Label("Bottom"));
mainLayout.addComponent(bottomLayout);
mainLayout.setExpandRatio(hsplit, 1.0f);
setContent(mainLayout);
}
//button listener
public void changeContent(){
sample.addClickListener(new ClickListener() {
@Override
public void buttonClick(final ClickEvent event) {
Notification.show("The button was clicked",Type.TRAY_NOTIFICATION);
//hsplit.removeAllComponents();
hsplit.setSecondComponent(ct);
}
});
}
//navigation
public Tree buildTree(){
/* Add planets as root items in the tree. */
for (int i=0; i<planets.length; i++) {
String planet = (String) (planets[i]
[0]
);
tree.addItem(planet);
if (planets[i]
.length == 1) {
// The planet has no moons so make it a leaf.
tree.setChildrenAllowed(planet, false);
} else {
// Add children (moons) under the planets.
for (int j=1; j<planets[i]
.length; j++) {
String moon = (String) planets[i]
[j]
;
// Add the item as a regular item.
tree.addItem(moon);
// Set it to be a child.
tree.setParent(moon, planet);
// Make the moons look like leaves.
tree.setChildrenAllowed(moon, false);
}
// Expand the subtree.
tree.expandItemsRecursively(planet);
}
}
tree.setImmediate(true);
tree.addValueChangeListener(new ValueChangeListener() {
@Override
public void valueChange(final ValueChangeEvent event) {
final String valueString = (String) tree.getValue();
//final String valueString = String.valueOf(event.getProperty().getValue());
Notification.show("Value changed:", valueString,Type.TRAY_NOTIFICATION);
if(valueString.equals("Load1")){
// hsplit.removeAllComponents();
//hsplit.setSecondComponent(right);
hsplit.addComponent(ct);
//System.out.println(valueString);
}
}
});
return tree;
}
the problem is this part:
public void valueChange(final ValueChangeEvent event) {
final String valueString = (String) tree.getValue();
//final String valueString = String.valueOf(event.getProperty().getValue());
Notification.show("Value changed:", valueString,Type.TRAY_NOTIFICATION);
if(valueString.equals("Load1")){
// hsplit.removeAllComponents();
[b]
[color=#f70b0b]
hsplit.setSecondComponent(ct);
[/color]
[/b]
//hsplit.addComponent(ct);
//System.out.println(valueString);
}
i want to check with equals and load then my own composites.
now, nothing happens…
what’s wrong?
thanks
isa