Search in sources :

Example 1 with IReadCompletionListener

use of org.freeplane.core.io.IReadCompletionListener in project freeplane by freeplane.

the class NodeBuilder method registerAttributeHandlers.

private void registerAttributeHandlers(final ReadManager reader) {
    reader.addAttributeHandler(NodeBuilder.XML_NODE, NodeBuilder.XML_NODE_ENCRYPTED_CONTENT, new IAttributeHandler() {

        private void createEncryptedNode(final NodeModel node, final String additionalInfo) {
            final EncryptionModel encryptionModel = new EncryptionModel(node, additionalInfo);
            node.addExtension(encryptionModel);
        }

        public void setAttribute(final Object userObject, final String value) {
            final NodeModel node = (NodeModel) userObject;
            createEncryptedNode(node, value);
            node.setFolded(true);
        }
    });
    reader.addAttributeHandler(NodeBuilder.XML_NODE, NodeBuilder.XML_NODE_HISTORY_CREATED_AT, new IAttributeHandler() {

        public void setAttribute(final Object userObject, final String value) {
            final NodeModel node = (NodeModel) userObject;
            if (node.getHistoryInformation() == null) {
                node.setHistoryInformation(new HistoryInformationModel());
            }
            node.getHistoryInformation().setCreatedAt(TreeXmlReader.xmlToDate(value));
        }
    });
    reader.addAttributeHandler(NodeBuilder.XML_NODE, NodeBuilder.XML_NODE_HISTORY_LAST_MODIFIED_AT, new IAttributeHandler() {

        public void setAttribute(final Object userObject, final String value) {
            final NodeModel node = (NodeModel) userObject;
            if (node.getHistoryInformation() == null) {
                node.setHistoryInformation(new HistoryInformationModel());
            }
            node.getHistoryInformation().setLastModifiedAt(TreeXmlReader.xmlToDate(value));
        }
    });
    reader.addAttributeHandler(NodeBuilder.XML_STYLENODE, "FOLDED", new IAttributeHandler() {

        public void setAttribute(Object userObject, String value) {
        }
    });
    reader.addAttributeHandler(NodeBuilder.XML_NODE, "FOLDED", new IAttributeHandler() {

        public void setAttribute(final Object userObject, final String value) {
            final NodeModel node = (NodeModel) userObject;
            final Object mode = mapReader.getCurrentNodeTreeCreator().getHint(Hint.MODE);
            if (mode.equals(Mode.FILE)) {
                final String loadFolding = ResourceController.getResourceController().getProperty(NodeBuilder.RESOURCES_LOAD_FOLDING);
                if (loadFolding.equals(NodeBuilder.RESOURCES_ALWAYS_FOLD_ALL_AFTER_LOAD) || loadFolding.equals(NodeBuilder.RESOURCES_ALWAYS_UNFOLD_ALL_AFTER_LOAD) || loadFolding.equals(NodeBuilder.RESOURCES_ALWAYS_SHOW_LESS_THAN_N_NODES_AFTER_LOAD)) {
                    return;
                }
                mapReader.getCurrentNodeTreeCreator().setHint(FOLDING_LOADED, Boolean.TRUE);
            }
            if (value.equals("true")) {
                node.setFolded(true);
            }
        }
    });
    reader.addReadCompletionListener(new IReadCompletionListener() {

        private int foldAll(final NodeModel node, int nodeCount) {
            if (node.getChildCount() == 0) {
                return nodeCount;
            }
            if (nodeCount <= 0) {
                node.setFolded(true);
            } else {
                nodeCount -= node.getChildCount();
            }
            for (final NodeModel child : node.getChildren()) {
                nodeCount = foldAll(child, nodeCount);
            }
            return nodeCount;
        }

        public void readingCompleted(final NodeModel topNode, final Map<String, String> newIds) {
            if (!Mode.FILE.equals(mapReader.getCurrentNodeTreeCreator().getHint(Hint.MODE))) {
                return;
            }
            if (Boolean.TRUE.equals(mapReader.getCurrentNodeTreeCreator().getHint(NodeBuilder.FOLDING_LOADED))) {
                return;
            }
            final ResourceController resourceController = ResourceController.getResourceController();
            final String loadFolding = resourceController.getProperty(NodeBuilder.RESOURCES_LOAD_FOLDING);
            if (loadFolding.equals(NodeBuilder.RESOURCES_ALWAYS_FOLD_ALL_AFTER_LOAD) || loadFolding.equals(NodeBuilder.RESOURCES_LOAD_FOLDING_FROM_MAP_DEFAULT_FOLD_ALL) || loadFolding.equals(NodeBuilder.RESOURCES_ALWAYS_SHOW_LESS_THAN_N_NODES_AFTER_LOAD) || loadFolding.equals(NodeBuilder.RESOURCES_SHOW_LESS_THAN_N_NODES_BY_DEFAULT_AFTER_LOAD)) {
                int nodeCount = 1;
                if (loadFolding.equals(NodeBuilder.RESOURCES_ALWAYS_SHOW_LESS_THAN_N_NODES_AFTER_LOAD) || loadFolding.equals(NodeBuilder.RESOURCES_SHOW_LESS_THAN_N_NODES_BY_DEFAULT_AFTER_LOAD))
                    nodeCount = resourceController.getIntProperty(NodeBuilder.MAX_DISPLAYED_NODE_COUNT, 20);
                final List<NodeModel> children = topNode.getChildren();
                nodeCount = nodeCount - 1 - children.size();
                for (final NodeModel child : children) {
                    nodeCount = foldAll(child, nodeCount);
                }
            }
        }
    });
    final IAttributeHandler positionHandler = new IAttributeHandler() {

        public void setAttribute(final Object userObject, final String value) {
            final NodeModel node = (NodeModel) userObject;
            node.setLeft(value.equals("left"));
        }
    };
    reader.addAttributeHandler(NodeBuilder.XML_NODE, "POSITION", positionHandler);
    reader.addAttributeHandler(NodeBuilder.XML_STYLENODE, "POSITION", positionHandler);
    reader.addAttributeHandler(NodeBuilder.XML_NODE, "ID", new IAttributeHandler() {

        public void setAttribute(final Object userObject, final String value) {
            final NodeModel node = (NodeModel) userObject;
            final String realId = getMap().generateNodeID(value);
            node.setID(realId);
            if (!realId.equals(value)) {
                mapReader.getCurrentNodeTreeCreator().substituteNodeID(value, realId);
            }
        }
    });
    final IAttributeHandler subtreeReferenceHandler = new CloneHandler(CloneType.TREE);
    reader.addAttributeHandler(NodeBuilder.XML_NODE, "REFERENCE_ID", subtreeReferenceHandler);
    reader.addAttributeHandler(NodeBuilder.XML_NODE, "TREE_ID", subtreeReferenceHandler);
    final IAttributeHandler contentReferenceHandler = new CloneHandler(CloneType.CONTENT);
    reader.addAttributeHandler(NodeBuilder.XML_NODE, "CONTENT_ID", contentReferenceHandler);
}
Also used : IAttributeHandler(org.freeplane.core.io.IAttributeHandler) ResourceController(org.freeplane.core.resources.ResourceController) IReadCompletionListener(org.freeplane.core.io.IReadCompletionListener) List(java.util.List) Hint(org.freeplane.features.map.MapWriter.Hint)

Aggregations

List (java.util.List)1 IAttributeHandler (org.freeplane.core.io.IAttributeHandler)1 IReadCompletionListener (org.freeplane.core.io.IReadCompletionListener)1 ResourceController (org.freeplane.core.resources.ResourceController)1 Hint (org.freeplane.features.map.MapWriter.Hint)1