2011-11-30 04:32:24 +01:00
|
|
|
/*
|
|
|
|
* 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.Mindmap = new Class({
|
2012-07-07 16:52:23 +02:00
|
|
|
Extends:mindplot.model.IMindmap,
|
|
|
|
initialize:function (id, version) {
|
2011-11-30 04:32:24 +01:00
|
|
|
$assert(id, "Id can not be null");
|
|
|
|
this._branches = [];
|
|
|
|
this._description = null;
|
|
|
|
this._relationships = [];
|
2012-02-26 03:32:15 +01:00
|
|
|
this._version = $defined(version) ? version : mindplot.persistence.ModelCodeName.TANGO;
|
2011-11-30 04:32:24 +01:00
|
|
|
this._id = id;
|
|
|
|
},
|
|
|
|
|
2012-07-07 16:52:23 +02:00
|
|
|
getDescription:function () {
|
2011-11-30 04:32:24 +01:00
|
|
|
return this._description;
|
|
|
|
},
|
|
|
|
|
2012-07-07 16:52:23 +02:00
|
|
|
setDescription:function (value) {
|
2011-11-30 04:32:24 +01:00
|
|
|
this._description = value;
|
|
|
|
},
|
|
|
|
|
2012-07-07 16:52:23 +02:00
|
|
|
getId:function () {
|
2011-11-30 04:32:24 +01:00
|
|
|
return this._id;
|
|
|
|
},
|
|
|
|
|
|
|
|
|
2012-07-07 16:52:23 +02:00
|
|
|
setId:function (id) {
|
2011-11-30 04:32:24 +01:00
|
|
|
this._id = id;
|
|
|
|
},
|
|
|
|
|
2012-07-07 16:52:23 +02:00
|
|
|
getVersion:function () {
|
2011-11-30 04:32:24 +01:00
|
|
|
return this._version;
|
|
|
|
},
|
|
|
|
|
2012-07-07 16:52:23 +02:00
|
|
|
setVersion:function (version) {
|
2011-11-30 04:32:24 +01:00
|
|
|
this._version = version;
|
|
|
|
},
|
|
|
|
|
2012-07-07 16:52:23 +02:00
|
|
|
addBranch:function (nodeModel) {
|
2011-11-30 04:32:24 +01:00
|
|
|
$assert(nodeModel && nodeModel.isNodeModel(), 'Add node must be invoked with model objects');
|
|
|
|
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 {
|
|
|
|
$assert(nodeModel.getType() != mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE, "Mindmaps only have one cental topic");
|
|
|
|
}
|
|
|
|
|
|
|
|
this._branches.push(nodeModel);
|
|
|
|
},
|
|
|
|
|
2012-07-07 16:52:23 +02:00
|
|
|
removeBranch:function (nodeModel) {
|
2011-11-30 04:32:24 +01:00
|
|
|
$assert(nodeModel && nodeModel.isNodeModel(), 'Remove node must be invoked with model objects');
|
|
|
|
return this._branches.erase(nodeModel);
|
|
|
|
},
|
|
|
|
|
2012-07-07 16:52:23 +02:00
|
|
|
getBranches:function () {
|
2011-11-30 04:32:24 +01:00
|
|
|
return this._branches;
|
|
|
|
},
|
|
|
|
|
2012-07-07 16:52:23 +02:00
|
|
|
getRelationships:function () {
|
2011-11-30 04:32:24 +01:00
|
|
|
return this._relationships;
|
|
|
|
},
|
|
|
|
|
2012-07-07 16:52:23 +02:00
|
|
|
hasAlreadyAdded:function (node) {
|
2011-11-30 04:32:24 +01:00
|
|
|
var result = false;
|
|
|
|
|
|
|
|
// Check in not connected nodes.
|
|
|
|
var branches = this._branches;
|
|
|
|
for (var i = 0; i < branches.length; i++) {
|
|
|
|
result = branches[i]._isChildNode(node);
|
|
|
|
if (result) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-07-07 16:52:23 +02:00
|
|
|
createNode:function (type, id) {
|
2012-03-15 02:10:44 +01:00
|
|
|
type = !$defined(type) ? mindplot.model.INodeModel.MAIN_TOPIC_TYPE : type;
|
2011-11-30 04:32:24 +01:00
|
|
|
return new mindplot.model.NodeModel(type, this, id);
|
|
|
|
},
|
|
|
|
|
2012-07-07 16:52:23 +02:00
|
|
|
createRelationship:function (sourceNodeId, targetNodeId) {
|
2011-11-30 04:50:46 +01:00
|
|
|
$assert($defined(sourceNodeId), 'from node cannot be null');
|
|
|
|
$assert($defined(targetNodeId), 'to node cannot be null');
|
2011-11-30 04:32:24 +01:00
|
|
|
|
2011-11-30 04:50:46 +01:00
|
|
|
return new mindplot.model.RelationshipModel(sourceNodeId, targetNodeId);
|
2011-11-30 04:32:24 +01:00
|
|
|
},
|
|
|
|
|
2012-07-07 16:52:23 +02:00
|
|
|
addRelationship:function (relationship) {
|
2011-11-30 04:32:24 +01:00
|
|
|
this._relationships.push(relationship);
|
|
|
|
},
|
|
|
|
|
2012-07-07 16:52:23 +02:00
|
|
|
deleteRelationship:function (relationship) {
|
2011-11-30 04:32:24 +01:00
|
|
|
this._relationships.erase(relationship);
|
2012-07-07 16:52:23 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
findNodeById:function (id) {
|
|
|
|
var result;
|
|
|
|
for (var i = 0; i < this._branches; i++) {
|
|
|
|
var branch = this._branches[i];
|
|
|
|
result = branch.findNodeById(id)
|
|
|
|
if (result) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2011-11-30 04:32:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2012-07-07 16:52:23 +02:00
|
|
|
mindplot.model.Mindmap.buildEmpty = function (mapId) {
|
2011-11-30 04:32:24 +01:00
|
|
|
var result = new mindplot.model.Mindmap(mapId);
|
|
|
|
var node = result.createNode(mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE, 0);
|
|
|
|
result.addBranch(node);
|
|
|
|
return result;
|
|
|
|
};
|