ItEr11S13ProbasModuloRecursos: A zk component cannot be dinamically inserted after a native one, so adding a workaround.
This commit is contained in:
parent
16591a86df
commit
5172b54104
1 changed files with 22 additions and 1 deletions
|
|
@ -3,9 +3,11 @@ package org.zkoss.ganttz.util;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.zkoss.zk.ui.Component;
|
||||
import org.zkoss.zk.ui.HtmlNativeComponent;
|
||||
import org.zkoss.zk.ui.Page;
|
||||
import org.zkoss.zk.ui.event.Event;
|
||||
import org.zkoss.zk.ui.event.EventListener;
|
||||
|
|
@ -101,7 +103,7 @@ public class MenuBuilder<T extends XulElement> {
|
|||
});
|
||||
result.appendChild(menuItem);
|
||||
}
|
||||
root.appendChild(result);
|
||||
insertInRootComponent(result);
|
||||
if (setContext) {
|
||||
for (T element : elements) {
|
||||
element.setContext(result);
|
||||
|
|
@ -109,4 +111,23 @@ public class MenuBuilder<T extends XulElement> {
|
|||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private void insertInRootComponent(Menupopup result) {
|
||||
ArrayList<Component> children = new ArrayList<Component>(root
|
||||
.getChildren());
|
||||
Collections.reverse(children);
|
||||
// the Menupopup cannot be inserted after a HtmlNativeComponent, so we
|
||||
// try to avoid it
|
||||
if (children.isEmpty()) {
|
||||
root.appendChild(result);
|
||||
}
|
||||
for (Component child : children) {
|
||||
if (!(child instanceof HtmlNativeComponent)) {
|
||||
root.insertBefore(result, child);
|
||||
return;
|
||||
}
|
||||
}
|
||||
throw new RuntimeException("all children of " + root
|
||||
+ " are html native");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue