Search in sources :

Example 1 with SummaryLevels

use of org.freeplane.features.map.SummaryLevels in project freeplane by freeplane.

the class SummaryNodeMapUpdater method updateSummaryNodes.

private void updateSummaryNodes(NodeModel parentNode) {
    final NodeModel[] nodes = parentNode.getChildren().toArray(new NodeModel[] {});
    for (NodeModel node : nodes) {
        SummaryLevels summaryLevels = null;
        if (SummaryNode.isFirstGroupNode(node)) {
            if (summaryLevels == null)
                summaryLevels = new SummaryLevels(parentNode);
            if (summaryLevels.findSummaryNode(node.getIndex()) == null)
                node.removeExtension(FirstGroupNodeFlag.class);
        }
        if (SummaryNode.isSummaryNode(node)) {
            if (summaryLevels == null)
                summaryLevels = new SummaryLevels(parentNode);
            final NodeModel groupBeginNode = summaryLevels.findGroupBeginNode(parentNode.previousNodeIndex(node.getIndex(), node.isLeft()));
            if (groupBeginNode == null)
                node.removeExtension(SummaryNodeFlag.class);
            else {
                if (!groupBeginNode.containsExtension(FirstGroupNodeFlag.class)) {
                    if (SummaryNode.isSummaryNode(groupBeginNode))
                        groupBeginNode.addExtension(FirstGroupNodeFlag.FIRST_GROUP);
                    else {
                        final NodeModel newFirstGroupNode = mapController.addNewNode(groupBeginNode.getParentNode(), groupBeginNode.getIndex(), groupBeginNode.isLeft());
                        newFirstGroupNode.addExtension(FirstGroupNodeFlag.FIRST_GROUP);
                    }
                }
                if (node.isFolded() || !node.hasChildren() || !node.getText().isEmpty()) {
                    node.removeExtension(SummaryNodeFlag.class);
                    final NodeModel newParent = mapController.addNewNode(node.getParentNode(), node.getIndex(), node.isLeft());
                    newParent.addExtension(SummaryNodeFlag.SUMMARY);
                    if (SummaryNode.isFirstGroupNode(node)) {
                        node.removeExtension(FirstGroupNodeFlag.class);
                        newParent.addExtension(FirstGroupNodeFlag.FIRST_GROUP);
                    }
                    mapController.moveNodeAndItsClones(node, newParent, 0, false, false);
                }
            }
        } else if (SummaryNode.isFirstGroupNode(node) && (node.hasChildren() || !node.getText().isEmpty())) {
            final NodeModel newFirstGroupNode = mapController.addNewNode(node.getParentNode(), node.getIndex(), node.isLeft());
            node.removeExtension(FirstGroupNodeFlag.class);
            newFirstGroupNode.addExtension(FirstGroupNodeFlag.FIRST_GROUP);
        }
        updateSummaryNodes(node);
    }
}
Also used : NodeModel(org.freeplane.features.map.NodeModel) SummaryNodeFlag(org.freeplane.features.map.SummaryNodeFlag) SummaryLevels(org.freeplane.features.map.SummaryLevels) FirstGroupNodeFlag(org.freeplane.features.map.FirstGroupNodeFlag)

Example 2 with SummaryLevels

use of org.freeplane.features.map.SummaryLevels in project freeplane by freeplane.

the class MMapController method deleteSingleSummaryNode.

private void deleteSingleSummaryNode(NodeModel summarynode) {
    final NodeModel summaryParent = summarynode.getParentNode();
    final SummaryLevels summaryLevels = new SummaryLevels(summaryParent);
    final int summaryNodeIndex = summarynode.getIndex();
    final int groupBeginNodeIndex = summaryLevels.findGroupBeginNodeIndex(summaryNodeIndex - 1);
    deleteSingleNode(summaryParent, summaryNodeIndex);
    deleteSingleNode(summaryParent, groupBeginNodeIndex);
}
Also used : NodeModel(org.freeplane.features.map.NodeModel) SummaryLevels(org.freeplane.features.map.SummaryLevels) Point(java.awt.Point)

Aggregations

NodeModel (org.freeplane.features.map.NodeModel)2 SummaryLevels (org.freeplane.features.map.SummaryLevels)2 Point (java.awt.Point)1 FirstGroupNodeFlag (org.freeplane.features.map.FirstGroupNodeFlag)1 SummaryNodeFlag (org.freeplane.features.map.SummaryNodeFlag)1