org.uqbar.arena.tests.nestedCombos.NestedCombosWindow Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of arena-examples Show documentation
Show all versions of arena-examples Show documentation
Ejemplos básicos y tests del framework Arena
package org.uqbar.arena.tests.nestedCombos;
import org.apache.commons.collections15.Transformer;
import org.uqbar.arena.bindings.PropertyAdapter;
import org.uqbar.arena.bindings.transformers.AbstractReadOnlyTransformer;
import org.uqbar.arena.layout.VerticalLayout;
import org.uqbar.arena.widgets.Button;
import org.uqbar.arena.widgets.Label;
import org.uqbar.arena.widgets.List;
import org.uqbar.arena.widgets.Panel;
import org.uqbar.arena.widgets.RadioSelector;
import org.uqbar.arena.widgets.Selector;
import org.uqbar.arena.widgets.TextBox;
import org.uqbar.arena.widgets.tables.Column;
import org.uqbar.arena.widgets.tables.Table;
import org.uqbar.arena.windows.MainWindow;
import org.uqbar.lacar.ui.model.Action;
/**
* Examples on various {@link Selector} features.
* When a country is selected in the first {@link Selector}:
*
* - the elements in the {@link List} and second {@link Selector} should show the provinces of the selected
* country.
* - the displayed country in the {@link Label} should show the selected country.
* - the number of times should be incremented (testing {@link Selector#onSelection(Action)}
*
*
* All the elements in {@link Selector}s, {@link List}s and {@link Label}s should render nice Country or
* Province names (instead of an ugly {@link #toString()}.
*
* The {@link List} of provinces and the {@link Selector} of provinces should be synchronized. Selecting an
* element in either of each should increment the last {@link Label} too (since they are synchronized, the
* count is incremented twice.
*
* @author npasserini
*/
public class NestedCombosWindow extends MainWindow {
public static void main(String[] args) {
new NestedCombosWindow().startApplication();
}
public NestedCombosWindow() {
super(new NestedCombosDomain());
}
@Override
public void createContents(Panel mainPanel) {
mainPanel.setLayout(new VerticalLayout());
Selector countries = new Selector(mainPanel);
countries.setContents(this.getModelObject().getPossibleCountries(), "name");
PropertyAdapter nameAdapter = new PropertyAdapter(Country.class, "name");
countries.bindItemsToProperty("possibleCountries") //
.setAdapter(nameAdapter);
countries.bindValueToProperty("country");
Action changedAction = new Action() {
@Override
public void execute() {
getModelObject().changed();
}
};
countries.onSelection(changedAction);
Label country = new Label(mainPanel);
country.bindValueToProperty("country")
// TODO esto todavía no se puede hacer:
// .setAdapter(nameAdapter);
.setTransformer(new AbstractReadOnlyTransformer() {
@Override
public String modelToView(Country value) {
return value.name();
}
@Override
public Class getModelType() {
return Country.class;
}
@Override
public Class getViewType() {
return String.class;
}
});
List provincesList = new List(mainPanel);
provincesList.bindItemsToProperty("possibleProvinces") //
.setAdapter(new PropertyAdapter(Province.class, "name"));
provincesList.bindValueToProperty("province");
provincesList.setHeight(100);
provincesList.setWidth(100);
provincesList.onSelection(changedAction);
Selector provinces = new Selector(mainPanel);
provinces.bindItemsToProperty("possibleProvinces").setAdapter(new PropertyAdapter(Province.class, "name"));
provinces.bindValueToProperty("province");
provinces.onSelection(changedAction);
Selector provincesRadioSelector = new RadioSelector(mainPanel);
provincesRadioSelector.bindItemsToProperty("possibleProvinces").setAdapter(new PropertyAdapter(Province.class, "name"));
provincesRadioSelector.bindValueToProperty("province");
provincesRadioSelector.setHeight(30);
provincesRadioSelector.onSelection(changedAction);
Label times = new Label(mainPanel);
times.bindValueToProperty("times"); // TODO esto todavía no se puede hacer: .setAdapter(nameAdapter);
new TextBox(mainPanel).bindValueToProperty("province.name");
new Button(mainPanel) //
.setCaption("Edit Province")
.onClick(() -> this.editProvince());
new Button(mainPanel) //
.setCaption("Delete Province")
.onClick(() -> getModelObject().deleteProvince());
Table table = new Table(mainPanel, Province.class);
table.setWidth(200);
table.setHeight(200);
table.bindItemsToProperty("possibleProvinces");
table.bindValueToProperty("province");
new Column(table).setTitle("Property").bindContentsToProperty("name");
new Column(table).setTitle("Transformer").bindContentsToProperty("pretty").setTransformer(
new Transformer() {
@Override
public String transform(Boolean pretty) {
if (pretty) {
return "yes";
} else {
return "no";
}
}
});
}
public void editProvince() {
new EditProvinceDialog(this, this.getModelObject().getProvince()).open();
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy