use of org.freeplane.core.io.IAttributeHandler in project freeplane by freeplane.
the class LogicalStyleController method createBuilder.
private void createBuilder() {
ModeController modeController = Controller.getCurrentModeController();
final MapController mapController = modeController.getMapController();
final ReadManager readManager = mapController.getReadManager();
readManager.addAttributeHandler(NodeBuilder.XML_NODE, "STYLE_REF", new IAttributeHandler() {
public void setAttribute(final Object node, final String value) {
final LogicalStyleModel extension = LogicalStyleModel.createExtension((NodeModel) node);
extension.setStyle(StyleFactory.create(value));
}
});
readManager.addAttributeHandler(NodeBuilder.XML_NODE, "LOCALIZED_STYLE_REF", new IAttributeHandler() {
public void setAttribute(final Object node, final String value) {
final LogicalStyleModel extension = LogicalStyleModel.createExtension((NodeModel) node);
extension.setStyle(StyleFactory.create(TranslatedObject.format(value)));
}
});
final WriteManager writeManager = mapController.getWriteManager();
writeManager.addAttributeWriter(NodeBuilder.XML_NODE, new IAttributeWriter() {
public void writeAttributes(final ITreeWriter writer, final Object node, final String tag) {
if (!NodeWriter.shouldWriteSharedContent(writer))
return;
final LogicalStyleModel extension = LogicalStyleModel.getExtension((NodeModel) node);
if (extension == null) {
return;
}
final IStyle style = extension.getStyle();
if (style == null) {
return;
}
final String value = StyleTranslatedObject.toKeyString(style);
if (style instanceof StyleTranslatedObject) {
writer.addAttribute("LOCALIZED_STYLE_REF", value);
} else {
writer.addAttribute("STYLE_REF", value);
}
}
});
}
use of org.freeplane.core.io.IAttributeHandler 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);
}
use of org.freeplane.core.io.IAttributeHandler in project freeplane by freeplane.
the class AttributeBuilder method registerAttributeHandlers.
private void registerAttributeHandlers(final ReadManager reader) {
reader.addAttributeHandler(AttributeBuilder.XML_NODE_REGISTERED_ATTRIBUTE_NAME, "NAME", new IAttributeHandler() {
public void setAttribute(final Object userObject, final String value) {
final RegisteredAttributeProperties rap = (RegisteredAttributeProperties) userObject;
rap.attributeName = value;
AttributeRegistry.getRegistry(getMap()).registry(value);
}
});
reader.addAttributeHandler(AttributeBuilder.XML_NODE_REGISTERED_ATTRIBUTE_NAME, "VISIBLE", new IAttributeHandler() {
public void setAttribute(final Object userObject, final String value) {
final RegisteredAttributeProperties rap = (RegisteredAttributeProperties) userObject;
rap.visible = true;
}
});
reader.addAttributeHandler(AttributeBuilder.XML_NODE_REGISTERED_ATTRIBUTE_NAME, "RESTRICTED", new IAttributeHandler() {
public void setAttribute(final Object userObject, final String value) {
final RegisteredAttributeProperties rap = (RegisteredAttributeProperties) userObject;
rap.restricted = true;
}
});
reader.addAttributeHandler(AttributeBuilder.XML_NODE_REGISTERED_ATTRIBUTE_NAME, "MANUAL", new IAttributeHandler() {
public void setAttribute(final Object userObject, final String value) {
final RegisteredAttributeProperties rap = (RegisteredAttributeProperties) userObject;
rap.manual = true;
}
});
reader.addAttributeHandler(AttributeBuilder.XML_NODE_REGISTERED_ATTRIBUTE_VALUE, "VALUE", new IAttributeHandler() {
public void setAttribute(final Object userObject, final String value) {
final AttributeProperties ap = (AttributeProperties) userObject;
ap.attributeValue = value;
}
});
reader.addAttributeHandler(AttributeBuilder.XML_NODE_REGISTERED_ATTRIBUTE_VALUE, "OBJECT", new IAttributeHandler() {
public void setAttribute(final Object userObject, final String value) {
final AttributeProperties ap = (AttributeProperties) userObject;
ap.attributeObject = value;
}
});
reader.addElementHandler(XML_NODE_ATTRIBUTE_LAYOUT, new IElementHandler() {
public Object createElement(final Object parent, final String tag, final XMLElement attributes) {
return parent;
}
});
reader.addAttributeHandler(AttributeBuilder.XML_NODE_ATTRIBUTE_LAYOUT, "NAME_WIDTH", new IAttributeHandler() {
public void setAttribute(final Object userObject, final String value) {
final NodeModel node = (NodeModel) userObject;
attributeController.createAttributeTableModel(node);
final AttributeTableLayoutModel layout = NodeAttributeTableModel.getModel(node).getLayout();
layout.setColumnWidth(0, LengthUnits.fromStringInPt(value));
}
});
reader.addAttributeHandler(AttributeBuilder.XML_NODE_ATTRIBUTE_LAYOUT, "VALUE_WIDTH", new IAttributeHandler() {
public void setAttribute(final Object userObject, final String value) {
final NodeModel node = (NodeModel) userObject;
attributeController.createAttributeTableModel(node);
final AttributeTableLayoutModel layout = NodeAttributeTableModel.getModel(node).getLayout();
layout.setColumnWidth(1, LengthUnits.fromStringInPt(value));
}
});
reader.addAttributeHandler(AttributeBuilder.XML_NODE_ATTRIBUTE, "NAME", new IAttributeHandler() {
public void setAttribute(final Object userObject, final String value) {
final AttributeProperties ap = (AttributeProperties) userObject;
ap.attributeName = value;
}
});
reader.addAttributeHandler(AttributeBuilder.XML_NODE_ATTRIBUTE, "VALUE", new IAttributeHandler() {
public void setAttribute(final Object userObject, final String value) {
final AttributeProperties ap = (AttributeProperties) userObject;
ap.attributeValue = value;
}
});
reader.addAttributeHandler(AttributeBuilder.XML_NODE_ATTRIBUTE, "OBJECT", new IAttributeHandler() {
public void setAttribute(final Object userObject, final String value) {
final AttributeProperties ap = (AttributeProperties) userObject;
ap.attributeObject = value;
}
});
reader.addAttributeHandler(AttributeBuilder.XML_NODE_ATTRIBUTE_REGISTRY, "RESTRICTED", new IAttributeHandler() {
public void setAttribute(final Object userObject, final String value) {
AttributeRegistry.getRegistry(getMap()).setRestricted(true);
}
});
reader.addAttributeHandler(AttributeBuilder.XML_NODE_ATTRIBUTE_REGISTRY, "SHOW_ATTRIBUTES", new IAttributeHandler() {
public void setAttribute(final Object userObject, final String value) {
final AttributeRegistry attributes = AttributeRegistry.getRegistry(getMap());
if (attributes != null)
attributes.setAttributeViewType(value);
}
});
reader.addAttributeHandler(AttributeBuilder.XML_NODE_ATTRIBUTE_REGISTRY, "FONT_SIZE", new IAttributeHandler() {
public void setAttribute(final Object userObject, final String value) {
final int size = Integer.parseInt(value.toString());
getMap().addExtension(new FontSizeExtension(size));
}
});
}
use of org.freeplane.core.io.IAttributeHandler in project freeplane by freeplane.
the class NodeTextBuilder method registerAttributeHandlers.
private void registerAttributeHandlers(final ReadManager reader) {
reader.addAttributeHandler(NodeBuilder.XML_NODE, NodeTextBuilder.XML_NODE_TEXT, new IAttributeHandler() {
public void setAttribute(final Object userObject, final String value) {
final NodeModel node = ((NodeModel) userObject);
final Object nodeContent = node.getUserObject();
if (nodeContent == null || nodeContent.equals("")) {
node.setText(value);
}
}
});
reader.addAttributeHandler(NodeBuilder.XML_NODE, NodeTextBuilder.XML_NODE_OBJECT, new IAttributeHandler() {
public void setAttribute(final Object userObject, final String value) {
final NodeModel node = ((NodeModel) userObject);
final Object newInstance = TypeReference.create(value);
// because formatting is saved as an extra attribute
if (newInstance instanceof IFormattedObject)
node.setUserObject(((IFormattedObject) newInstance).getObject());
else
node.setUserObject(newInstance);
}
});
IAttributeHandler textShortenedHandler = new IAttributeHandler() {
public void setAttribute(final Object userObject, final String value) {
final NodeModel node = ((NodeModel) userObject);
try {
if (Boolean.valueOf(value)) {
node.addExtension(new ShortenedTextModel());
}
} catch (Exception e) {
LogUtils.warn(e);
}
}
};
reader.addAttributeHandler(NodeBuilder.XML_NODE, NodeTextBuilder.XML_NODE_TEXT_SHORTENED, textShortenedHandler);
reader.addAttributeHandler(NodeBuilder.XML_STYLENODE, NodeTextBuilder.XML_NODE_TEXT_SHORTENED, textShortenedHandler);
reader.addAttributeHandler(NodeBuilder.XML_STYLENODE, NodeTextBuilder.XML_NODE_TEXT, new IAttributeHandler() {
public void setAttribute(final Object userObject, final String value) {
final NodeModel node = ((NodeModel) userObject);
node.setUserObject(StyleFactory.create(value));
}
});
reader.addAttributeHandler(NodeBuilder.XML_NODE, NodeTextBuilder.XML_NODE_LOCALIZED_TEXT, new IAttributeHandler() {
public void setAttribute(final Object userObject, final String value) {
final NodeModel node = ((NodeModel) userObject);
node.setUserObject(StyleFactory.create(TranslatedObject.format(value)));
}
});
reader.addAttributeHandler(NodeBuilder.XML_STYLENODE, NodeTextBuilder.XML_NODE_LOCALIZED_TEXT, new IAttributeHandler() {
public void setAttribute(final Object userObject, final String value) {
final NodeModel node = ((NodeModel) userObject);
node.setUserObject(StyleFactory.create(TranslatedObject.format(value)));
}
});
}
Aggregations