Add IMindmap and INode.
This commit is contained in:
164
mindplot/src/main/javascript/model/IMindmap.js
Normal file
164
mindplot/src/main/javascript/model/IMindmap.js
Normal file
@@ -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);
|
||||
});
|
||||
}
|
||||
});
|
@@ -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) {
|
||||
|
@@ -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;
|
||||
}
|
||||
}
|
||||
);
|
Reference in New Issue
Block a user