diff --git a/mindplot/pom.xml b/mindplot/pom.xml index 6ab721ae..19744d5b 100644 --- a/mindplot/pom.xml +++ b/mindplot/pom.xml @@ -52,7 +52,9 @@ + + @@ -86,10 +88,13 @@ - - + + - + @@ -108,10 +113,13 @@ - + - - + + MainTopicConnection. - if (currentConnection.getType() == mindplot.model.NodeModel.MAIN_TOPIC_TYPE) { + if (currentConnection.getType() == mindplot.model.INodeModel.MAIN_TOPIC_TYPE) { if (mainTopicToMainTopicConnection != currentConnection) { dragTopic.disconnect(this._workspace); } } - else if (currentConnection.getType() == mindplot.model.NodeModel.CENTRAL_TOPIC_TYPE) { + else if (currentConnection.getType() == mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE) { // Distance if greater that the allowed. var dragXPosition = dragTopic.getPosition().x; var currentXPosition = currentConnection.getPosition().x; @@ -90,7 +90,7 @@ mindplot.DragTopicPositioner = new Class({ for (var i = 0; i < topics.length; i++) { var targetTopic = topics[i]; var position = dragTopic.getPosition(); - if (targetTopic.getType() != mindplot.model.NodeModel.CENTRAL_TOPIC_TYPE && targetTopic != draggedNode) { + if (targetTopic.getType() != mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE && targetTopic != draggedNode) { var canBeConnected = dragTopic.canBeConnectedTo(targetTopic); if (canBeConnected) { var targetPosition = targetTopic.getPosition(); diff --git a/mindplot/src/main/javascript/MainTopic.js b/mindplot/src/main/javascript/MainTopic.js index 2dfce8e1..1862a3eb 100644 --- a/mindplot/src/main/javascript/MainTopic.js +++ b/mindplot/src/main/javascript/MainTopic.js @@ -31,10 +31,10 @@ mindplot.MainTopic = new Class({ // Create a new node ... var model = this.getModel(); var mindmap = model.getMindmap(); - siblingModel = mindmap.createNode(mindplot.model.NodeModel.MAIN_TOPIC_TYPE); + siblingModel = mindmap.createNode(mindplot.model.INodeModel.MAIN_TOPIC_TYPE); // Positionate following taking into account the sibling positon. - if (positionate && parentTopic.getType() == mindplot.model.NodeModel.CENTRAL_TOPIC_TYPE) { + if (positionate && parentTopic.getType() == mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE) { var pos = this.getPosition(); siblingModel.setPosition(pos.x, pos.y); } @@ -50,7 +50,7 @@ mindplot.MainTopic = new Class({ // Create a new node ... var model = this.getModel(); var mindmap = model.getMindmap(); - var childModel = mindmap.createNode(mindplot.model.NodeModel.MAIN_TOPIC_TYPE); + var childModel = mindmap.createNode(mindplot.model.INodeModel.MAIN_TOPIC_TYPE); // Get the hights model order position ... var children = this._getChildren(); @@ -99,14 +99,14 @@ mindplot.MainTopic = new Class({ _defaultShapeType : function() { - return mindplot.model.NodeModel.SHAPE_TYPE_LINE; + return mindplot.model.INodeModel.SHAPE_TYPE_LINE; }, updateTopicShape : function(targetTopic, workspace) { // Change figure based on the connected topic ... var model = this.getModel(); var shapeType = model.getShapeType(); - if (targetTopic.getType() != mindplot.model.NodeModel.CENTRAL_TOPIC_TYPE) { + if (targetTopic.getType() != mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE) { if (!$defined(shapeType)) { // Get the real shape type ... shapeType = this.getShapeType(); @@ -127,7 +127,7 @@ mindplot.MainTopic = new Class({ if (!$defined(shapeType)) { // Change figure ... shapeType = this.getShapeType(); - this._setShapeType(mindplot.model.NodeModel.SHAPE_TYPE_ROUNDED_RECT, false); + this._setShapeType(mindplot.model.INodeModel.SHAPE_TYPE_ROUNDED_RECT, false); } var innerShape = this.getInnerShape(); innerShape.setVisibility(true); @@ -171,7 +171,7 @@ mindplot.MainTopic = new Class({ var isAtRight = mindplot.util.Shape.isAtRight(sourcePosition, pos); var result = mindplot.util.Shape.calculateRectConnectionPoint(pos, size, isAtRight); - if (this.getShapeType() == mindplot.model.NodeModel.SHAPE_TYPE_LINE) { + if (this.getShapeType() == mindplot.model.INodeModel.SHAPE_TYPE_LINE) { result.y = result.y + (this.getSize().height / 2); } @@ -196,7 +196,7 @@ mindplot.MainTopic = new Class({ var isAtRight = mindplot.util.Shape.isAtRight(targetPosition, pos); var result; - if (this.getShapeType() == mindplot.model.NodeModel.SHAPE_TYPE_LINE) { + if (this.getShapeType() == mindplot.model.INodeModel.SHAPE_TYPE_LINE) { // if (!this.isConnectedToCentralTopic()) // { result = new core.Point(); @@ -238,7 +238,7 @@ mindplot.MainTopic = new Class({ _getInnerPadding : function() { var result; var parent = this.getModel().getParent(); - if (parent && mindplot.model.NodeModel.MAIN_TOPIC_TYPE == parent.getType()) { + if (parent && mindplot.model.INodeModel.MAIN_TOPIC_TYPE == parent.getType()) { result = 3; } else { @@ -251,14 +251,14 @@ mindplot.MainTopic = new Class({ var model = this.getModel(); var parent = model.getParent(); - return parent && parent.getType() === mindplot.model.NodeModel.CENTRAL_TOPIC_TYPE; + return parent && parent.getType() === mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE; }, _defaultText : function() { var targetTopic = this.getOutgoingConnectedTopic(); var result = ""; if ($defined(targetTopic)) { - if (targetTopic.getType() == mindplot.model.NodeModel.CENTRAL_TOPIC_TYPE) { + if (targetTopic.getType() == mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE) { result = "Main Topic"; } else { result = "Sub Topic"; @@ -273,7 +273,7 @@ mindplot.MainTopic = new Class({ var targetTopic = this.getOutgoingConnectedTopic(); var result; if ($defined(targetTopic)) { - if (targetTopic.getType() == mindplot.model.NodeModel.CENTRAL_TOPIC_TYPE) { + if (targetTopic.getType() == mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE) { result = { font:"Arial", size: 8, diff --git a/mindplot/src/main/javascript/MindmapDesigner.js b/mindplot/src/main/javascript/MindmapDesigner.js index 0916ce4b..66db21e7 100644 --- a/mindplot/src/main/javascript/MindmapDesigner.js +++ b/mindplot/src/main/javascript/MindmapDesigner.js @@ -94,7 +94,7 @@ mindplot.MindmapDesigner = new Class({ // Create a new topic model ... var mindmap = this.getMindmap(); - var model = mindmap.createNode(mindplot.model.NodeModel.MAIN_TOPIC_TYPE); + var model = mindmap.createNode(mindplot.model.INodeModel.MAIN_TOPIC_TYPE); model.setPosition(pos.x, pos.y); // Get central topic ... @@ -281,7 +281,7 @@ mindplot.MindmapDesigner = new Class({ } var topic = nodes[0]; - if (topic.getType() == mindplot.model.NodeModel.CENTRAL_TOPIC_TYPE) { + if (topic.getType() == mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE) { // Central topic doesn't have siblings ... this.createChildForSelectedNode(); @@ -514,7 +514,7 @@ mindplot.MindmapDesigner = new Class({ }, _removeNode : function(node) { - if (node.getTopicType() != mindplot.model.NodeModel.CENTRAL_TOPIC_TYPE) { + if (node.getTopicType() != mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE) { var parent = node._parent; node.disconnect(this._workspace); @@ -539,7 +539,7 @@ mindplot.MindmapDesigner = new Class({ deleteCurrentNode : function() { var validateFunc = function(object) { - return object.getType() == mindplot.RelationshipLine.type || object.getTopicType() != mindplot.model.NodeModel.CENTRAL_TOPIC_TYPE + return object.getType() == mindplot.RelationshipLine.type || object.getTopicType() != mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE }; var validateError = 'Central topic can not be deleted.'; @@ -580,7 +580,7 @@ mindplot.MindmapDesigner = new Class({ changeBackgroundColor : function(color) { var validateFunc = function(topic) { - return topic.getShapeType() != mindplot.model.NodeModel.SHAPE_TYPE_LINE + return topic.getShapeType() != mindplot.model.INodeModel.SHAPE_TYPE_LINE }; var validateError = 'Color can not be set to line topics.'; @@ -592,7 +592,7 @@ mindplot.MindmapDesigner = new Class({ changeBorderColor : function(color) { var validateFunc = function(topic) { - return topic.getShapeType() != mindplot.model.NodeModel.SHAPE_TYPE_LINE + return topic.getShapeType() != mindplot.model.INodeModel.SHAPE_TYPE_LINE }; var validateError = 'Color can not be set to line topics.'; var topicsIds = this.getModel().filterTopicsIds(validateFunc, validateError); @@ -610,7 +610,7 @@ mindplot.MindmapDesigner = new Class({ changeTopicShape : function(shape) { var validateFunc = function(topic) { - return !(topic.getType() == mindplot.model.NodeModel.CENTRAL_TOPIC_TYPE && shape == mindplot.model.NodeModel.SHAPE_TYPE_LINE) + return !(topic.getType() == mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE && shape == mindplot.model.INodeModel.SHAPE_TYPE_LINE) }; var validateError = 'Central Topic shape can not be changed to line figure.'; var topicsIds = this.getModel().filterTopicsIds(validateFunc, validateError); diff --git a/mindplot/src/main/javascript/NodeGraph.js b/mindplot/src/main/javascript/NodeGraph.js index 15158fd9..72e303b7 100644 --- a/mindplot/src/main/javascript/NodeGraph.js +++ b/mindplot/src/main/javascript/NodeGraph.js @@ -135,10 +135,10 @@ mindplot.NodeGraph.create = function(nodeModel, options) { $assert(type, 'Node model type can not be null'); var result; - if (type == mindplot.model.NodeModel.CENTRAL_TOPIC_TYPE) { + if (type == mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE) { result = new mindplot.CentralTopic(nodeModel, options); } else - if (type == mindplot.model.NodeModel.MAIN_TOPIC_TYPE) { + if (type == mindplot.model.INodeModel.MAIN_TOPIC_TYPE) { result = new mindplot.MainTopic(nodeModel, options); } else { assert(false, "unsupported node type:" + type); diff --git a/mindplot/src/main/javascript/Topic.js b/mindplot/src/main/javascript/Topic.js index 81f7e70b..ab32f0a1 100644 --- a/mindplot/src/main/javascript/Topic.js +++ b/mindplot/src/main/javascript/Topic.js @@ -32,7 +32,7 @@ mindplot.Topic = new Class({ // Position a topic .... var pos = model.getPosition(); - if (pos != null && model.getType() == mindplot.model.NodeModel.CENTRAL_TOPIC_TYPE) { + if (pos != null && model.getType() == mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE) { this.setPosition(pos); } @@ -151,7 +151,7 @@ mindplot.Topic = new Class({ this._setBorderColor(brColor, false); // Define the pointer ... - if (this.getType() != mindplot.model.NodeModel.CENTRAL_TOPIC_TYPE) { + if (this.getType() != mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE) { this._innerShape.setCursor('move'); } else { this._innerShape.setCursor('default'); @@ -167,16 +167,16 @@ mindplot.Topic = new Class({ type = this.getShapeType(); } - if (type == mindplot.model.NodeModel.SHAPE_TYPE_RECT) { + if (type == mindplot.model.INodeModel.SHAPE_TYPE_RECT) { result = new web2d.Rect(0, attributes); } - else if (type == mindplot.model.NodeModel.SHAPE_TYPE_ELIPSE) { + else if (type == mindplot.model.INodeModel.SHAPE_TYPE_ELIPSE) { result = new web2d.Rect(0.9, attributes); } - else if (type == mindplot.model.NodeModel.SHAPE_TYPE_ROUNDED_RECT) { + else if (type == mindplot.model.INodeModel.SHAPE_TYPE_ROUNDED_RECT) { result = new web2d.Rect(0.3, attributes); } - else if (type == mindplot.model.NodeModel.SHAPE_TYPE_LINE) { + else if (type == mindplot.model.INodeModel.SHAPE_TYPE_LINE) { result = new web2d.Line({strokeColor:"#495879",strokeWidth:1, strokeOpacity:1}); result.setSize = function(width, height) { this.size = {width:width, height:height}; @@ -226,7 +226,7 @@ mindplot.Topic = new Class({ getOuterShape : function() { if (!$defined(this._outerShape)) { - var rect = this.buildShape(mindplot.Topic.OUTER_SHAPE_ATTRIBUTES, mindplot.model.NodeModel.SHAPE_TYPE_ROUNDED_RECT); + var rect = this.buildShape(mindplot.Topic.OUTER_SHAPE_ATTRIBUTES, mindplot.model.INodeModel.SHAPE_TYPE_ROUNDED_RECT); rect.setPosition(-2, -3); rect.setOpacity(0); this._outerShape = rect; @@ -408,7 +408,7 @@ mindplot.Topic = new Class({ if (!disableEventsListeners) { // Propagate mouse events ... - if (this.getType() != mindplot.model.NodeModel.CENTRAL_TOPIC_TYPE) { + if (this.getType() != mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE) { result.setCursor('move'); } else { result.setCursor('default'); @@ -621,7 +621,7 @@ mindplot.Topic = new Class({ this.getOrBuildIconGroup(); } - if (this.getType() != mindplot.model.NodeModel.CENTRAL_TOPIC_TYPE) { + if (this.getType() != mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE) { shrinkConnector.addToWorkspace(group); } @@ -828,7 +828,7 @@ mindplot.Topic = new Class({ setBranchVisibility : function(value) { var current = this; var parent = this; - while (parent != null && parent.getType() != mindplot.model.NodeModel.CENTRAL_TOPIC_TYPE) { + while (parent != null && parent.getType() != mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE) { current = parent; parent = current.getParent(); } diff --git a/mindplot/src/main/javascript/XMLMindmapSerializer_Beta.js b/mindplot/src/main/javascript/XMLMindmapSerializer_Beta.js index fb0d7a84..c29c22b4 100644 --- a/mindplot/src/main/javascript/XMLMindmapSerializer_Beta.js +++ b/mindplot/src/main/javascript/XMLMindmapSerializer_Beta.js @@ -44,11 +44,11 @@ mindplot.XMLMindmapSerializer_Beta = new Class({ var parentTopic = document.createElement("topic"); // Set topic attributes... - if (topic.getType() == mindplot.model.NodeModel.CENTRAL_TOPIC_TYPE) { + if (topic.getType() == mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE) { parentTopic.setAttribute("central", true); } else { var parent = topic.getParent(); - if (parent == null || parent.getType() == mindplot.model.NodeModel.CENTRAL_TOPIC_TYPE) { + if (parent == null || parent.getType() == mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE) { var pos = topic.getPosition(); parentTopic.setAttribute("position", pos.x + ',' + pos.y); } else { @@ -179,7 +179,7 @@ mindplot.XMLMindmapSerializer_Beta = new Class({ }, _deserializeNode : function(domElem, mindmap) { - var type = (domElem.getAttribute('central') != null) ? mindplot.model.NodeModel.CENTRAL_TOPIC_TYPE : mindplot.model.NodeModel.MAIN_TOPIC_TYPE; + var type = (domElem.getAttribute('central') != null) ? mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE : mindplot.model.INodeModel.MAIN_TOPIC_TYPE; var topic = mindmap.createNode(type); // Load attributes... diff --git a/mindplot/src/main/javascript/XMLMindmapSerializer_Pela.js b/mindplot/src/main/javascript/XMLMindmapSerializer_Pela.js index c28d29f5..09015b13 100644 --- a/mindplot/src/main/javascript/XMLMindmapSerializer_Pela.js +++ b/mindplot/src/main/javascript/XMLMindmapSerializer_Pela.js @@ -62,7 +62,7 @@ mindplot.XMLMindmapSerializer_Pela = new Class({ var parentTopic = document.createElement("topic"); // Set topic attributes... - if (topic.getType() == mindplot.model.NodeModel.CENTRAL_TOPIC_TYPE) { + if (topic.getType() == mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE) { parentTopic.setAttribute("central", true); } else { var parent = topic.getParent(); @@ -234,7 +234,7 @@ mindplot.XMLMindmapSerializer_Pela = new Class({ }, _deserializeNode : function(domElem, mindmap) { - var type = (domElem.getAttribute('central') != null) ? mindplot.model.NodeModel.CENTRAL_TOPIC_TYPE : mindplot.model.NodeModel.MAIN_TOPIC_TYPE; + var type = (domElem.getAttribute('central') != null) ? mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE : mindplot.model.INodeModel.MAIN_TOPIC_TYPE; // Load attributes... var id = domElem.getAttribute('id'); if ($defined(id)) { diff --git a/mindplot/src/main/javascript/collaboration/framework/AbstractCollaborativeFramework.js b/mindplot/src/main/javascript/collaboration/framework/AbstractCollaborativeFramework.js index 44c9aee6..73c7f0b9 100644 --- a/mindplot/src/main/javascript/collaboration/framework/AbstractCollaborativeFramework.js +++ b/mindplot/src/main/javascript/collaboration/framework/AbstractCollaborativeFramework.js @@ -38,7 +38,7 @@ mindplot.collaboration.framework.AbstractCollaborativeFramework = new Class({ _buildInitialCollaborativeModel: function() { var mindmap = this._collaborativeModelFactory.buildMindMap(); - var centralTopic = mindmap.createNode(mindplot.model.NodeModel.CENTRAL_TOPIC_TYPE); + var centralTopic = mindmap.createNode(mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE); mindmap.addBranch(centralTopic, true); this.addMindmap(mindmap); return mindmap; diff --git a/mindplot/src/main/javascript/commands/DragTopicCommand.js b/mindplot/src/main/javascript/commands/DragTopicCommand.js index 38f2d7de..cb59f2b2 100644 --- a/mindplot/src/main/javascript/commands/DragTopicCommand.js +++ b/mindplot/src/main/javascript/commands/DragTopicCommand.js @@ -29,6 +29,7 @@ mindplot.commands.DragTopicCommand = new Class({ this._order = order; this._id = mindplot.Command._nextUUID(); }, + execute: function(commandContext) { var topic = commandContext.findTopics([this._objectsIds])[0]; @@ -37,14 +38,10 @@ mindplot.commands.DragTopicCommand = new Class({ var origParentTopic = topic.getOutgoingConnectedTopic(); var origOrder = null; var origPosition = null; -// if (topic.getType() == mindplot.model.NodeModel.MAIN_TOPIC_TYPE && origParentTopic != null && origParentTopic.getType() == mindplot.model.NodeModel.MAIN_TOPIC_TYPE) -// { + // In this case, topics are positioned using order ... origOrder = topic.getOrder(); -// } else -// { - origPosition = topic.getPosition().clone(); -// } + origPosition = topic.getPosition(); // Disconnect topic .. if ($defined(origParentTopic)) { diff --git a/mindplot/src/main/javascript/layout/BaseLayoutManager.js b/mindplot/src/main/javascript/layout/BaseLayoutManager.js index ccddff2f..acb81fe6 100644 --- a/mindplot/src/main/javascript/layout/BaseLayoutManager.js +++ b/mindplot/src/main/javascript/layout/BaseLayoutManager.js @@ -74,7 +74,7 @@ mindplot.layout.BaseLayoutManager = new Class({ }, _isCentralTopic:function(node){ var type = node.getModel().getType(); - return type == mindplot.model.NodeModel.CENTRAL_TOPIC_TYPE; + return type == mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE; }, getClassName:function(){ return mindplot.layout.BaseLayoutManager.NAME; diff --git a/mindplot/src/main/javascript/layout/FreeMindLayoutManager.js b/mindplot/src/main/javascript/layout/FreeMindLayoutManager.js index e5f44bc5..8e738223 100644 --- a/mindplot/src/main/javascript/layout/FreeMindLayoutManager.js +++ b/mindplot/src/main/javascript/layout/FreeMindLayoutManager.js @@ -58,7 +58,7 @@ mindplot.layout.FreeMindLayoutManager = mindplot.layout.BaseLayoutManager.extend }); // Add drag behaviour ... - if (topic.getType() != mindplot.model.NodeModel.CENTRAL_TOPIC_TYPE) + if (topic.getType() != mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE) { topic.addEvent("mousedown",this._reconnectMouseDownListener.bindWithEvent(this,[topic])); } @@ -261,7 +261,7 @@ mindplot.layout.FreeMindLayoutManager = mindplot.layout.BaseLayoutManager.extend } }, addHelpers:function(node){ - if (node.getType() != mindplot.model.NodeModel.CENTRAL_TOPIC_TYPE) + if (node.getType() != mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE) this._addMoveHelper(node); }, _addMoveHelper:function(node){ diff --git a/mindplot/src/main/javascript/layout/OriginalLayoutManager.js b/mindplot/src/main/javascript/layout/OriginalLayoutManager.js index 68098cd7..cde07d23 100644 --- a/mindplot/src/main/javascript/layout/OriginalLayoutManager.js +++ b/mindplot/src/main/javascript/layout/OriginalLayoutManager.js @@ -61,7 +61,7 @@ mindplot.layout.OriginalLayoutManager = new Class({ } } nodesByOrder = null; - return node.getTopicType() != mindplot.model.NodeModel.CENTRAL_TOPIC_TYPE ? result : children; + return node.getTopicType() != mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE ? result : children; }, _nodeResizeEvent:function(node) { @@ -123,7 +123,7 @@ mindplot.layout.OriginalLayoutManager = new Class({ registerListenersOnNode : function(topic) { // Register node listeners ... - if (topic.getType() != mindplot.model.NodeModel.CENTRAL_TOPIC_TYPE) { + if (topic.getType() != mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE) { // Central Topic doesn't support to be dragged var dragger = this._dragger; diff --git a/mindplot/src/main/javascript/model/IMindmap.js b/mindplot/src/main/javascript/model/IMindmap.js new file mode 100644 index 00000000..31717e1b --- /dev/null +++ b/mindplot/src/main/javascript/model/IMindmap.js @@ -0,0 +1,164 @@ +/* + * Copyright [2011] [wisemapping] + * + * Licensed under WiseMapping Public License, Version 1.0 (the "License"). + * It is basically the Apache License, Version 2.0 (the "License") plus the + * "powered by wisemapping" text requirement on every single page; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the license at + * + * http://www.wisemapping.org/license + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +mindplot.model.IMindmap = new Class({ + initialize : function() { + throw "Unsupported operation"; + }, + + getCentralTopic : function() { + return this.getBranches()[0]; + }, + + getDescription : function() { + throw "Unsupported operation"; + }, + + setDescription : function(value) { + throw "Unsupported operation"; + }, + + getId : function() { + throw "Unsupported operation"; + }, + + setId : function(id) { + throw "Unsupported operation"; + }, + + getVersion : function() { + throw "Unsupported operation"; + }, + + setVersion : function(version) { + throw "Unsupported operation"; + }, + + addBranch : function(nodeModel) { + throw "Unsupported operation"; + }, + + getBranches : function() { + throw "Unsupported operation"; + }, + + removeBranch : function(node) { + throw "Unsupported operation"; + }, + + getRelationships : function() { + throw "Unsupported operation"; + }, + + connect : function(parent, child) { + // Child already has a parent ? + $assert(!child.getParent(), 'Child model seems to be already connected'); + + // Connect node... + parent._appendChild(child); + + // Remove from the branch ... + this.removeBranch(child); + }, + + disconnect : function(child) { + var parent = child.getParent(); + $assert(child, 'Child can not be null.'); + $assert(parent, 'Child model seems to be already connected'); + + parent._removeChild(child); + + this.addBranch(child); + }, + + hasAlreadyAdded : function(node) { + throw "Unsupported operation"; + }, + + createNode : function(type, id) { + throw "Unsupported operation"; + }, + + createRelationship : function(fromNode, toNode) { + throw "Unsupported operation"; + }, + + addRelationship : function(relationship) { + throw "Unsupported operation"; + }, + + removeRelationship : function(relationship) { + throw "Unsupported operation"; + }, + + inspect : function() { + var result = ''; + result = '{ '; + + var branches = this.getBranches(); + for (var i = 0; i < branches.length; i++) { + var node = branches[i]; + if (i != 0) { + result = result + ', '; + } + + result = result + this._toString(node); + } + + result = result + ' } '; + + return result; + }, + + _toString : function(node) { + var result = node.inspect(); + var children = node.getChildren(); + + for (var i = 0; i < children.length; i++) { + var child = children[i]; + + if (i == 0) { + result = result + '-> {'; + } else { + result = result + ', '; + } + + result = result + this._toString(child); + + if (i == children.length - 1) { + result = result + '}'; + } + } + + return result; + }, + + copyTo : function(mindmap) { + var version = this.getVersion(); + mindmap.setVersion(version); + + var desc = this.getDescription(); + mindmap.setDescription(desc); + + var sbranchs = this.getBranches(); + sbranchs.forEach(function(snode) { + var tnode = mindmap.createNode(snode.getType(), snode.getId()); + snode.copyTo(tnode); + mindmap.addBranch(snode); + }); + } +}); \ No newline at end of file diff --git a/mindplot/src/main/javascript/model/INodeModel.js b/mindplot/src/main/javascript/model/INodeModel.js index bf6965df..20c4c4f5 100644 --- a/mindplot/src/main/javascript/model/INodeModel.js +++ b/mindplot/src/main/javascript/model/INodeModel.js @@ -51,7 +51,7 @@ mindplot.model.INodeModel = new Class({ }, getText : function() { - this.getProperty('text'); + return this.getProperty('text'); }, setPosition : function(x, y) { @@ -162,7 +162,7 @@ mindplot.model.INodeModel = new Class({ }, areChildrenShrinked : function() { - this.getProperty('childrenShrinked'); + return this.getProperty('childrenShrinked'); }, setChildrenShrinked : function(value) { diff --git a/mindplot/src/main/javascript/model/Mindmap.js b/mindplot/src/main/javascript/model/Mindmap.js index 73d16ff9..b85f9b23 100644 --- a/mindplot/src/main/javascript/model/Mindmap.js +++ b/mindplot/src/main/javascript/model/Mindmap.js @@ -16,6 +16,7 @@ * limitations under the License. */ mindplot.model.Mindmap = new Class({ + Extends: mindplot.model.IMindmap, initialize : function() { this._branches = []; this._description = null; @@ -23,10 +24,6 @@ mindplot.model.Mindmap = new Class({ this._relationships = []; }, - getCentralTopic : function() { - return this._branches[0]; - }, - getDescription : function() { return this._description; }, @@ -44,14 +41,14 @@ mindplot.model.Mindmap = new Class({ return this._version; }, - setVersion : function(version) { this._version = version; }, addBranch : function(nodeModel) { $assert(nodeModel && nodeModel.isNodeModel(), 'Add node must be invoked with model objects'); - if (this._branches.length == 0) { + var branches = this.getBranches(); + if (branches.length == 0) { $assert(nodeModel.getType() == mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE, "First element must be the central topic"); nodeModel.setPosition(0, 0); } else { @@ -61,6 +58,11 @@ mindplot.model.Mindmap = new Class({ this._branches.push(nodeModel); }, + removeBranch : function(nodeModel){ + $assert(nodeModel && nodeModel.isNodeModel(), 'Remove node must be invoked with model objects'); + return this._branches.erase(nodeModel); + }, + getBranches : function() { return this._branches; }, @@ -69,30 +71,6 @@ mindplot.model.Mindmap = new Class({ return this._relationships; }, - connect : function(parent, child) { - // Child already has a parent ? - var branches = this.getBranches(); - $assert(!child.getParent(), 'Child model seems to be already connected'); - - // Connect node... - parent._appendChild(child); - - // Remove from the branch ... - branches.erase(child); - }, - - disconnect : function(child) { - var parent = child.getParent(); - $assert(child, 'Child can not be null.'); - $assert(parent, 'Child model seems to be already connected'); - - parent._removeChild(child); - - var branches = this.getBranches(); - branches.push(child); - - }, - hasAlreadyAdded : function(node) { var result = false; @@ -108,13 +86,7 @@ mindplot.model.Mindmap = new Class({ createNode : function(type, id) { $assert(type, "node type can not be null"); - return this._createNode(type, id); - }, - - _createNode : function(type, id) { - $assert(type, 'Node type must be specified.'); - var result = new mindplot.model.NodeModel(type, this, id); - return result; + return new mindplot.model.NodeModel(type, this, id); }, createRelationship : function(fromNode, toNode) { @@ -130,48 +102,6 @@ mindplot.model.Mindmap = new Class({ removeRelationship : function(relationship) { this._relationships.erase(relationship); - }, - - inspect : function() { - var result = ''; - result = '{ '; - - var branches = this.getBranches(); - for (var i = 0; i < branches.length; i++) { - var node = branches[i]; - if (i != 0) { - result = result + ', '; - } - - result = result + this._toString(node); - } - - result = result + ' } '; - - return result; - }, - - _toString : function(node) { - var result = node.inspect(); - var children = node.getChildren(); - - for (var i = 0; i < children.length; i++) { - var child = children[i]; - - if (i == 0) { - result = result + '-> {'; - } else { - result = result + ', '; - } - - result = result + this._toString(child); - - if (i == children.length - 1) { - result = result + '}'; - } - } - - return result; } } ); \ No newline at end of file