NativeSelect select = new NativeSelect(
"Choose component to edit");
select.setNullSelectionAllowed(false);
IndexedContainer container = new IndexedContainer();
container.addContainerProperty("caption", String.class, "");
Iterator<Component> componentIterator = l
.getComponentIterator();
while (componentIterator.hasNext()) {
AbstractComponent next = (AbstractComponent) componentIterator
.next();
Item item = container.addItem(next);
String caption = next.getClass().getSimpleName();
caption += "; cap: " + next.getCaption() + "; debugid"
+ getId();
if (next instanceof Property) {
caption += " value:"
+ ((Property<?>) next).getValue();
}
item.getItemProperty("caption").setValue(caption);
}
select.setContainerDataSource(container);
select.setItemCaptionPropertyId("caption");
select.setImmediate(true);
select.addListener(new ValueChangeListener() {
@Override
public void valueChange(ValueChangeEvent event) {
editcomponent((Component) event.getProperty()
.getValue());
getMainWindow().removeWindow(chooser);
}
});
layout.addComponent(select);
getMainWindow().addWindow(chooser);
}
});
addComponent(componentChooser);
Button addComp = new Button("add component");
addComp.addListener(new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
VerticalLayout layout = new VerticalLayout();
layout.setMargin(true);
final Window chooser = new Window(
"Choose component type to add", layout);
layout.setSizeUndefined();
chooser.setModal(true);
NativeSelect select = new NativeSelect(
"Choose component to edit");
select.setNullSelectionAllowed(false);
IndexedContainer container = new IndexedContainer();
URL resource = AbstractComponent.class.getResource(".");
File directory = new File(resource.getFile());
if (directory.exists()) {
// Get the list of the files contained in the
// package
final String[] files = directory.list();
for (int j = 0; j < files.length; j++) {
// we are only interested in .class files
if (files[j].endsWith(".class")) {
// removes the .class extension
String p = resource.toString()
+ files[j].substring(0,
files[j].length() - 6);
p = p.replaceAll(".*classes/", "");
p = p.replaceAll("/", ".");
Class<?> c;
try {
c = Class.forName(p);
if (AbstractComponent.class
.isAssignableFrom(c)
&& !p.toLowerCase().contains(
"layout")
&& !p.toLowerCase().contains(
"abstract")) {
container.addItem(c);
}
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}