Introduce the convept of Feature to a topic.

This commit is contained in:
Paulo Gustavo Veiga
2012-02-27 18:17:15 -03:00
parent 9e44804314
commit 7ba0e36cb9
26 changed files with 483 additions and 1240 deletions

View File

@@ -0,0 +1,76 @@
/*
* 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.FeatureModel = new Class({
initialize:function(type, topic) {
$assert(type, 'type can not be null');
$assert(topic, 'topic can not be null');
this._id = mindplot.model.FeatureModel._nextUUID();
this._type = type;
this._topic = topic;
this._attributes = {};
// Create type method ...
this['is' + type.camelCase() + 'Model'] = function() {
return true;
};
},
getAttributes : function() {
return Object.clone(this._attributes);
},
setAttributes : function(attributes) {
for (key in attributes) {
this["set" + key.capitalize()](attributes[key]);
}
},
setAttribute : function(key, value) {
$assert(key, 'key id can not be null');
this._attributes[key] = value;
},
getAttribute : function(key) {
$assert(key, 'key id can not be null');
return this._attributes[key];
},
getTopic : function() {
return this._topic;
},
getId : function() {
return this._id;
},
getType:function() {
return this._type;
}
});
mindplot.model.FeatureModel._nextUUID = function() {
if (!$defined(this._uuid)) {
this._uuid = 0;
}
this._uuid = this._uuid + 1;
return this._uuid;
};

View File

@@ -248,58 +248,10 @@ mindplot.model.INodeModel = new Class({
throw "Unsupported operation";
},
createLink : function(url) {
throw "Unsupported operation";
},
addLink : function(link) {
throw "Unsupported operation";
},
createNote : function(text) {
throw "Unsupported operation";
},
addNote : function(note) {
throw "Unsupported operation";
},
removeNote : function(note) {
throw "Unsupported operation";
},
createIcon : function(iconType) {
throw "Unsupported operation";
},
addIcon : function(icon) {
throw "Unsupported operation";
},
removeIcon : function(icon) {
throw "Unsupported operation";
},
removeLastIcon : function() {
throw "Unsupported operation";
},
getChildren : function() {
throw "Unsupported operation";
},
getIcons : function() {
throw "Unsupported operation";
},
getLinks : function() {
throw "Unsupported operation";
},
getNotes : function() {
throw "Unsupported operation";
},
getParent : function() {
throw "Unsupported operation";
},

View File

@@ -17,46 +17,19 @@
*/
mindplot.model.IconModel = new Class({
initialize:function(iconType, topic) {
$assert(iconType, 'Icon id can not be null');
$assert(topic, 'topic can not be null');
this._iconType = iconType;
this._id = mindplot.model.IconModel._nextUUID();
this._topic = topic;
},
getId : function() {
return this._id;
Extends: mindplot.model.FeatureModel,
initialize:function(topic, attributes) {
this.parent(mindplot.model.IconModel.FEATURE_TYPE, topic);
this.setIconType(attributes.id);
},
getIconType : function() {
return this._iconType;
return this.getAttribute('id');
},
setIconType : function(iconType) {
this._iconType = iconType;
},
getTopic : function() {
return this._topic;
},
isIconModel : function() {
return true;
}});
/**
* @todo: This method must be implemented.
*/
mindplot.model.IconModel._nextUUID = function() {
if (!$defined(this._uuid)) {
this._uuid = 0;
$assert(iconType, 'iconType id can not be null');
this.setAttribute('id', iconType);
}
this._uuid = this._uuid + 1;
return this._uuid;
};
});
mindplot.model.IconModel.FEATURE_TYPE = "icon";

View File

@@ -17,31 +17,27 @@
*/
mindplot.model.LinkModel = new Class({
initialize : function(url, topic) {
$assert(url, 'url can not be null');
$assert(topic, 'mindmap can not be null');
this._topic = topic;
this.setUrl(url);
Extends: mindplot.model.FeatureModel,
initialize : function(topic, attributes) {
this.parent(mindplot.model.LinkModel.FEATURE_TYPE, topic);
this.setUrl(attributes.url);
},
getUrl : function() {
return this._url;
return this.getAttribute('url');
},
setUrl : function(url) {
$assert(url, 'url can not be null');
this._url = this._fixUrl(url);
this._type = this._url.contains('mailto:') ? 'mail' : 'url';
var fixedUrl = this._fixUrl(url);
this.setAttribute('url', fixedUrl);
var type = fixedUrl.contains('mailto:') ? 'mail' : 'url';
this.setAttribute('type', type);
},
getTopic : function() {
return this._topic;
},
isLinkModel : function() {
return true;
}
,
_fixUrl : function(url) {
var result = url;
if (!result.contains('http://') && !result.contains('https://') && !result.contains('mailto://')) {
@@ -49,4 +45,6 @@ mindplot.model.LinkModel = new Class({
}
return result;
}
});
});
mindplot.model.LinkModel.FEATURE_TYPE = 'link';

View File

@@ -30,9 +30,39 @@ mindplot.model.NodeModel = new Class({
this.setSize(50, 20);
this._children = [];
this._icons = [];
this._links = [];
this._notes = [];
this._feature = [];
},
createFeature: function(type, attributes) {
return mindplot.TopicFeature.createModel(type, this, attributes);
},
addFeature: function(feature) {
$assert(feature, 'feature can not be null');
this._feature.push(feature);
},
getFeatures: function() {
return this._feature;
},
removeFeature: function(feature) {
$assert(feature, 'feature can not be null');
this._feature.erase(feature);
},
findFeatureByType : function(type) {
$assert(type, 'type can not be null');
return this._feature.filter(function(feature) {
return feature.getType() == type;
});
},
findFeatureById : function(id) {
$assert($defined(id), 'id can not be null');
return this._feature.filter(function(feature) {
return feature.getId() == id;
})[0];
},
getPropertiesKeys : function() {
@@ -64,67 +94,10 @@ mindplot.model.NodeModel = new Class({
});
result._properties = Object.clone(this._properties);
result._icons = this._icons.clone();
result._links = this._links.clone();
result._notes = this._notes.clone();
result._feature = this._feature.clone();
return result;
},
addChildren : function() {
$assert(child && child.isNodeModel(), 'Only NodeModel can be appended to Mindmap object');
this._children.push(child);
child._parent = this;
},
createLink : function(url) {
$assert(url, 'Link URL must be specified.');
return new mindplot.model.LinkModel(url, this);
},
addLink : function(link) {
$assert(link && link.isLinkModel(), 'Only LinkModel can be appended to Mindmap object as links');
this._links.push(link);
},
_removeLink : function(link) {
$assert(link && link.isLinkModel(), 'Only LinkModel can be appended to Mindmap object as links');
this._links.erase(link);
},
createNote : function(text) {
$assert(text != null, 'note text must be specified.');
return new mindplot.model.NoteModel(text, this);
},
addNote : function(note) {
$assert(note && note.isNoteModel(), 'Only NoteModel can be appended to Mindmap object as links');
this._notes.push(note);
},
removeNote : function(note) {
$assert(note && note.isNoteModel(), 'Only NoteModel can be appended to Mindmap object as links');
this._notes.erase(note);
},
createIcon : function(iconType) {
$assert(iconType, 'IconType must be specified.');
return new mindplot.model.IconModel(iconType, this);
},
addIcon : function(icon) {
$assert(icon && icon.isIconModel(), 'Only IconModel can be appended to Mindmap object as icons');
this._icons.push(icon);
},
removeIcon : function(icon) {
$assert(icon && icon.isIconModel(), 'Only IconModel can be appended to Mindmap object as icons');
this._icons.erase(icon);
},
removeLastIcon : function() {
this._icons.pop();
},
appendChild : function(child) {
$assert(child && child.isNodeModel(), 'Only NodeModel can be appended to Mindmap object');
this._children.push(child);
@@ -141,18 +114,6 @@ mindplot.model.NodeModel = new Class({
return this._children;
},
getIcons : function() {
return this._icons;
},
getLinks : function() {
return this._links;
},
getNotes : function() {
return this._notes;
},
getParent : function() {
return this._parent;
},

View File

@@ -17,26 +17,20 @@
*/
mindplot.model.NoteModel = new Class({
initialize : function(text, topic) {
$assert(text, 'text text can not be null');
$assert(topic, 'topic can not be null');
this._text = text;
this._topic = topic;
Extends: mindplot.model.FeatureModel,
initialize : function(topic, attributes) {
this.parent(mindplot.model.NoteModel.FEATURE_TYPE, topic);
this.setText(attributes.text);
},
getText:function() {
return this._text;
return this.getAttribute('text');
},
setText : function(text) {
this._text = text;
},
getTopic : function() {
return this._topic;
},
isNoteModel : function() {
return true;
$assert(text, 'text can not be null');
this.setAttribute('text', text);
}
});
});
mindplot.model.NoteModel.FEATURE_TYPE = "note";