diff --git a/mindplot/pom.xml b/mindplot/pom.xml index 19744d5b..213d1a9b 100644 --- a/mindplot/pom.xml +++ b/mindplot/pom.xml @@ -51,6 +51,14 @@ + + + + + diff --git a/mindplot/src/main/javascript/BrixActionDispatcher.js b/mindplot/src/main/javascript/BrixActionDispatcher.js index eb40eafa..54b1477a 100644 --- a/mindplot/src/main/javascript/BrixActionDispatcher.js +++ b/mindplot/src/main/javascript/BrixActionDispatcher.js @@ -23,6 +23,27 @@ mindplot.BrixActionDispatcher = new Class({ this._commandContext = commandContext; }, + dragTopic: function(topicId, position, order, parentTopic) { + var framework = this._getFramework(); + var node = framework.getTopic(topicId); + + // Set node order ... + if (order != null) { + node.setOrder(order); + } else if (position != null) { + // Set position ... + node.setPosition(position); + } else { + $assert("Illegal commnad state exception."); + } + // Finally, connect node ... + if ($defined(this._parentId)) { + var parentNode = topic.findTopics([this._parentId])[0]; + node.disconnect(); + node.connect(parentNode); + } + }, + changeTextToTopic : function(topicsIds, text) { var framework = this._getFramework(); var topicId; @@ -127,7 +148,7 @@ mindplot.BrixActionDispatcher = new Class({ var topicId = topicsIds[0]; var topic = framework.getTopic(topicId); $assert(topic, "Could not find topic with id:" + topicId); - mindmap.disconnect(topic); + topic.deleteNode(); } }); diff --git a/mindplot/src/main/javascript/MindmapDesigner.js b/mindplot/src/main/javascript/MindmapDesigner.js index ac184c50..61788145 100644 --- a/mindplot/src/main/javascript/MindmapDesigner.js +++ b/mindplot/src/main/javascript/MindmapDesigner.js @@ -57,9 +57,9 @@ mindplot.MindmapDesigner = new Class({ // To prevent the user from leaving the page with changes ... $(window).addEvent('beforeunload', function () { - if (this.needsSave()) { +// if (this.needsSave()) { // this.save(null, false) - } +// } }.bind(this)); }, diff --git a/mindplot/src/main/javascript/collaboration/framework/brix/model/Mindmap.js b/mindplot/src/main/javascript/collaboration/framework/brix/model/Mindmap.js index 32e8196c..fd2532e8 100644 --- a/mindplot/src/main/javascript/collaboration/framework/brix/model/Mindmap.js +++ b/mindplot/src/main/javascript/collaboration/framework/brix/model/Mindmap.js @@ -60,8 +60,10 @@ mindplot.collaboration.framework.brix.model.Mindmap = new Class({ var branches = this._brixModel.get("branches"); for (var i = 0; i < branches.size(); i++) { var node = branches.get(i); - var nodeModel = new mindplot.collaboration.framework.brix.model.NodeModel(this._brixFramework, node, this); - result.push(nodeModel); + if (node != null) { + var nodeModel = new mindplot.collaboration.framework.brix.model.NodeModel(this._brixFramework, node, this); + result.push(nodeModel); + } } return result; }, @@ -78,10 +80,14 @@ mindplot.collaboration.framework.brix.model.Mindmap = new Class({ var branches = this._brixModel.get("branches"); for (var i = 0; i < branches.size(); i++) { - if (branches.get(i) == nodeModel.getBrixModel()) { - branches.remove(i); - break; + // @Todo: remove should remove null elements ... + var branch = branches.get(i); + if (branch != null) { + if (branch == nodeModel.getBrixModel()) { + branches.remove(i); + break; + } } } }, diff --git a/mindplot/src/main/javascript/collaboration/framework/brix/model/NodeModel.js b/mindplot/src/main/javascript/collaboration/framework/brix/model/NodeModel.js index 7da4fef6..cd8547cc 100644 --- a/mindplot/src/main/javascript/collaboration/framework/brix/model/NodeModel.js +++ b/mindplot/src/main/javascript/collaboration/framework/brix/model/NodeModel.js @@ -21,6 +21,8 @@ mindplot.collaboration.framework.brix.model.NodeModel = new Class({ initialize : function(brixFramework, brixModel, mindmap) { $assert(brixFramework, "brixFramework can not null"); $assert(brixModel, "brixModel can not null"); + $assert(mindmap && mindmap.getBranches, "mindmap can not null"); + this.parent(mindmap); this._brixModel = brixModel; @@ -33,10 +35,9 @@ mindplot.collaboration.framework.brix.model.NodeModel = new Class({ // Nodes creation should be cached ... if (!this._brixModel.__registered) { // Register listener for properties changes .... + var actionDispatcher = this._brixFramework.getActionDispatcher(); this._brixModel.addListener("valueChanged", function(event) { var key = event.getProperty(); - - var actionDispatcher = this._brixFramework.getActionDispatcher(); var value = event.getNewValue(); var funName = 'change' + key.capitalize() + 'ToTopic'; @@ -44,6 +45,7 @@ mindplot.collaboration.framework.brix.model.NodeModel = new Class({ throw "No implementation for:" + funName; } console.log("This action dispatcher:" + funName); + actionDispatcher[funName]([this.getId()], value); }.bind(this)); @@ -57,7 +59,19 @@ mindplot.collaboration.framework.brix.model.NodeModel = new Class({ var model = new mindplot.model.NodeModel(cmodel.getType(), designer.getMindmap(), this.getId()); cmodel.copyTo(model); - this._brixFramework.getActionDispatcher().addTopic(model, this.getId(), true); + actionDispatcher.addTopic(model, this.getId(), true); + }.bind(this)); + + children.addListener("valuesRemoved", function(event) { + console.log("remove node:" + funName); + + var brixChildren = event.getValues(); + for (var i = 0; i < brixChildren.size(); i++) { + var brixNodeModel = brixChildren.get(i); + var cmodel = new mindplot.collaboration.framework.brix.model.NodeModel(this._brixFramework, brixNodeModel, this.getMindmap()); + actionDispatcher.deleteTopics(cmodel.getId()); + } + }.bind(this)); this._brixModel.__registered = true; @@ -69,7 +83,8 @@ mindplot.collaboration.framework.brix.model.NodeModel = new Class({ var children = this._brixModel.get("children"); for (var i = 0; i < children.size(); i++) { var node = children.get(i); - var nodeModel = new mindplot.collaboration.framework.brix.model.NodeModel(this._brixFramework, node, this); + var nodeModel = new mindplot.collaboration.framework.brix.model.NodeModel(this._brixFramework, node, this.getMindmap()); + nodeModel.setParent(this); result.push(nodeModel); } return result; @@ -98,11 +113,27 @@ mindplot.collaboration.framework.brix.model.NodeModel = new Class({ return this._brixModel._parent; }, + setParent : function(parent) { + this._brixModel._parent = parent; + }, + appendChild : function(node) { $assert(node && node.isNodeModel(), 'Only NodeModel can be appended to Mindmap object'); var children = this._brixModel.get("children"); children.add(node.getBrixModel()); - node.getBrixModel()._parent = this; + this.setParent(this); + }, + + removeChild : function(child) { + $assert(child && child.isNodeModel(), 'Only NodeModel can be appended to Mindmap object.'); + var children = this._brixModel.get("children"); + for (var i = 0; i < children.size(); i++) { + if (children.get(i) == child.getBrixModel()) { + children.remove(i); + break; + } + } + this.setParent(null); } }); diff --git a/mindplot/src/main/javascript/model/IMindmap.js b/mindplot/src/main/javascript/model/IMindmap.js index 77e11b73..d7def611 100644 --- a/mindplot/src/main/javascript/model/IMindmap.js +++ b/mindplot/src/main/javascript/model/IMindmap.js @@ -81,7 +81,6 @@ mindplot.model.IMindmap = new Class({ $assert(parent, 'Child model seems to be already connected'); parent.removeChild(child); - this.addBranch(child); }, diff --git a/mindplot/src/main/javascript/model/INodeModel.js b/mindplot/src/main/javascript/model/INodeModel.js index 3c3ef719..69b1009c 100644 --- a/mindplot/src/main/javascript/model/INodeModel.js +++ b/mindplot/src/main/javascript/model/INodeModel.js @@ -18,7 +18,7 @@ mindplot.model.INodeModel = new Class({ initialize: function(mindmap) { - $assert(mindmap, 'mindmap can not be null'); + $assert(mindmap && mindmap.getBranches, 'mindmap can not be null'); this._mindmap = mindmap; }, @@ -200,6 +200,50 @@ mindplot.model.INodeModel = new Class({ mindmap.connect(parent, this); }, + copyTo : function(target) { + var source = this; + // Copy properties ... + var keys = source.getPropertiesKeys(); + keys.forEach(function(key) { + var value = source.getProperty(key); + target.putProperty(key, value); + }); + + // Copy childrens ... + var children = this.getChildren(); + var tmindmap = target.getMindmap(); + + children.forEach(function(snode) { + var tnode = tmindmap.createNode(snode.getType(), snode.getId()); + snode.copyTo(tnode); + target.appendChild(tnode); + }); + + return target; + }, + + deleteNode : function() { + var mindmap = this.getMindmap(); + + // if it has children nodes, Their must be disconnected. + var children = this.getChildren(); + var length = children.length; + + for (var i = 0; i < length; i++) { + var child = children[i]; + mindmap.disconnect(child); + } + + // if it is connected, I must remove it from the parent.. + var parent = this.getParent(); + if ($defined(parent)) { + mindmap.disconnect(this); + } + + // It's an isolated node. It must be a hole branch ... + mindmap.removeBranch(this); + }, + getPropertiesKeys : function() { throw "Unsupported operation"; }, @@ -212,10 +256,6 @@ mindplot.model.INodeModel = new Class({ throw "Unsupported operation"; }, - deleteNode : function() { - throw "Unsupported operation"; - }, - createLink : function(url) { throw "Unsupported operation"; }, @@ -283,7 +323,7 @@ mindplot.model.INodeModel = new Class({ var children = this.getChildren(); if (children.length > 0) { - result = result + "{(size:" + children.length; + result = result + ", children: {(size:" + children.length; children.forEach(function(node) { result = result + "=> (" + node.getPropertiesKeys() + ")"; }.bind(this)); @@ -293,26 +333,9 @@ mindplot.model.INodeModel = new Class({ return result; }, - copyTo : function(target) { - var source = this; - // Copy properties ... - var keys = source.getPropertiesKeys(); - keys.forEach(function(key) { - var value = source.getProperty(key); - target.putProperty(key, value); - }); + removeChild : function(child) { + throw "Unsupported operation"; - // Copy childrens ... - var children = this.getChildren(); - var tmindmap = target.getMindmap(); - - children.forEach(function(snode) { - var tnode = tmindmap.createNode(snode.getType(), snode.getId()); - snode.copyTo(tnode); - target.appendChild(tnode); - }); - - return target; } }); diff --git a/mindplot/src/main/javascript/model/NodeModel.js b/mindplot/src/main/javascript/model/NodeModel.js index 1a779112..08e56ef8 100644 --- a/mindplot/src/main/javascript/model/NodeModel.js +++ b/mindplot/src/main/javascript/model/NodeModel.js @@ -41,9 +41,8 @@ mindplot.model.NodeModel = new Class({ }, - getProperties: function() - { - return this._properties; + getProperties: function() { + return this._properties; }, getProperty : function(key) { @@ -67,10 +66,10 @@ mindplot.model.NodeModel = new Class({ return result; }, - addChildren : function(){ + addChildren : function() { $assert(child && child.isNodeModel(), 'Only NodeModel can be appended to Mindmap object'); - this._children.push(child); - child._parent = this; + this._children.push(child); + child._parent = this; }, createLink : function(url) { @@ -223,28 +222,6 @@ mindplot.model.NodeModel = new Class({ }, - deleteNode : function() { - var mindmap = this._mindmap; - - // if it has children nodes, Their must be disconnected. - var lenght = this._children; - for (var i = 0; i < lenght; i++) { - var child = this._children[i]; - mindmap.disconnect(child); - } - - var parent = this._parent; - if ($defined(parent)) { - // if it is connected, I must remove it from the parent.. - mindmap.disconnect(this); - } - - // It's an isolated node. It must be a hole branch ... - var branches = mindmap.getBranches(); - branches.erase(this); - - }, - inspect : function() { return '(type:' + this.getType() + ' , id: ' + this.getId() + ')'; } diff --git a/web2d/src/main/javascript/Workspace.js b/web2d/src/main/javascript/Workspace.js index 8a74c1f6..8fe78d5c 100644 --- a/web2d/src/main/javascript/Workspace.js +++ b/web2d/src/main/javascript/Workspace.js @@ -175,7 +175,7 @@ web2d.Workspace = new Class({ } if (element == this) { - throw "It's not posible to add the group as a child of itself"; + throw "It's not possible to add the group as a child of itself"; } var elementType = element.getType(); diff --git a/wise-doc/src/main/webapp/html/editor.html b/wise-doc/src/main/webapp/html/editor.html index 69ada6e5..33488d6e 100644 --- a/wise-doc/src/main/webapp/html/editor.html +++ b/wise-doc/src/main/webapp/html/editor.html @@ -12,17 +12,12 @@ - - - - -