for (int i = 0; i < children.size(); i++) {
Node child = children.get(i);
if (child instanceof Leaf) {
Leaf leaf = (Leaf) child;
String leafName = leaf.getName();
if (leafName.equals(leafKey)) {
// Analyze parent
children.remove(i);
// Analyze children now...
if (children.size() == 2) {
Split grandpa = split.getParent();
if (grandpa == null) {
multiSplitPaneModelRoot = getFirstNotDivider(children);
multiSplitPaneModelRoot.setParent(null);
// Prepare dockableConstraint
AggregationPosition position;
if (children.get(0) == multiSplitPaneModelRoot) {
position = (split.isRowLayout()) ? AggregationPosition.RIGHT : AggregationPosition.BOTTOM;
} else
position = (split.isRowLayout()) ? AggregationPosition.LEFT : AggregationPosition.TOP;
dockableConstraint = new DockableConstraint(multiSplitPaneModelRoot,
position,
-1);
setChild = false;
} else {
List<Node> grenpaChildren = grandpa.getChildren();
if (children.get(0) instanceof Divider) {
grenpaChildren.set(grenpaChildren.indexOf(split),
children.get(1));
// Prepare dockableConstraint
dockableConstraint = new DockableConstraint(children.get(1),
(split.isRowLayout()) ? AggregationPosition.LEFT : AggregationPosition.TOP,
-1);
} else {
grenpaChildren.set(grenpaChildren.indexOf(split),
children.get(0));
// Prepare dockableConstraint
dockableConstraint = new DockableConstraint(children.get(0),
(split.isRowLayout()) ? AggregationPosition.RIGHT : AggregationPosition.BOTTOM,
-1);
}
grandpa.setChildren(grenpaChildren);
setChild = false;
}
} else {
// Remove the divider
if (i < children.size()) {
children.remove(i);
dockableConstraint = new DockableConstraint(children.get(i),
(split.isRowLayout()) ? AggregationPosition.LEFT : AggregationPosition.TOP,
-1);
} else {
children.remove(i - 1);
dockableConstraint = new DockableConstraint(children.get(i - 2),
(split.isRowLayout()) ? AggregationPosition.RIGHT : AggregationPosition.BOTTOM,
-1);
}
i--;
}
} else {
// We have to rename the leaf if the name is not valid.
Integer keyValue = Integer.parseInt(leafName);
if (keyValue > leafValue) {
String newKey = "" + (keyValue - 1);
leaf.setName(newKey);
}
}
} else if (child instanceof Split) {
stack.push((Split) child);
}