if (isWrapper(masterLeftLeafCmp))
removeFromWrapper(masterLeftLeafCmp, leftDockable);
// Update the model
AggregationPosition constraintAggPosition = AggregationPosition.DEFAULT;
Split rootSplit = (Split) multiSplitPaneModelRoot;
List<Node> children = rootSplit.getChildren();
for (int i = 0, size = children.size(); i < size; i++) {
Node node = children.get(i);
if (node == leftLeaf) {
if (i == 0) {
if (rootSplit.isRowLayout())
constraintAggPosition = AggregationPosition.RIGHT;
else
constraintAggPosition = AggregationPosition.BOTTOM;
} else if (rootSplit.isRowLayout())
constraintAggPosition = AggregationPosition.LEFT;
else
constraintAggPosition = AggregationPosition.TOP;
break;
}
}
multiSplitPaneModelRoot = leftLeaf;
multiSplitPaneModelRoot.setParent(null);
// Update the pane
multiSplitPane.setModel(multiSplitPaneModelRoot);
multiSplitPane.removeAll();
multiSplitPane.add(getWrapperForComponent(leftDockable, leftLeafCmp, Action.REMOVE_DOCK), "1");
// Finalize
leafNameCounter = 1;
SwingUtil.repaint(this);
// Prepare constraint
return new DockableConstraint(leftLeaf,
constraintAggPosition,
-1);
}
} else {
DockableConstraint dockableConstraint = null;
DockableLeaf dockableLeaf = getLeaf(dockable);
if (dockableLeaf == null)
throw new IllegalArgumentException("Cannot remove the dockable. Cannot find leaf. [id : " + dockable.getId() + "]");
if (dockableLeaf.getDockables().size() > 1) {
// There are more than one dockable on the same leaf
// Remove the dockable from leaf and from aggregating component...
dockableLeaf.getDockables().remove(dockable.getId());
int index = removeFromWrapper(multiSplitPane.getMultiSplitLayout().getChildMap().get(dockableLeaf.getName()),
dockable);
// Prepare dockableConstraint
return new DockableConstraint(dockableLeaf,
AggregationPosition.DEFAULT,
index);
} else {
leafNameCounter--;
// There is one dockable on the leaf. We have to rearrange the layout...
String leafKey = dockableLeaf.getName();
int leafValue = Integer.parseInt(leafKey);
Component component = multiSplitPane.getMultiSplitLayout().getChildMap().get(leafKey);
// Remove content
if (component != null) {
// Remove the component from the multiSplitPane
if (isWrapper(component))
removeFromWrapper(component, dockable);
multiSplitPane.remove(component);
// Update model
// Navigate the model to look for the requested leaf
Stack<Split> stack = new Stack<Split>();
stack.push((Split) multiSplitPaneModelRoot);
boolean setChild = true;
while (!stack.isEmpty()) {
Split split = stack.pop();
List<Node> children = split.getChildren();
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,