diff --git a/mindplot/src/main/javascript/Topic.js b/mindplot/src/main/javascript/Topic.js index f287fe34..41c0c5ce 100644 --- a/mindplot/src/main/javascript/Topic.js +++ b/mindplot/src/main/javascript/Topic.js @@ -274,19 +274,16 @@ mindplot.Topic = new Class({ return result; }, - addFeature:function (type, attributes, featureId) { + addFeature:function (featureModel) { var iconGroup = this.getOrBuildIconGroup(); this.closeEditors(); - var model = this.getModel(); - // Update model ... - var feature = model.createFeature(type, attributes, featureId); - model.addFeature(feature); + var model = this.getModel(); + model.addFeature(featureModel); - - var result = mindplot.TopicFeature.createIcon(this, feature, this.isReadOnly()); - iconGroup.addIcon(result, type == mindplot.TopicFeature.Icon.id && !this.isReadOnly()); + var result = mindplot.TopicFeature.createIcon(this, featureModel, this.isReadOnly()); + iconGroup.addIcon(result, featureModel.getType() == mindplot.TopicFeature.Icon.id && !this.isReadOnly()); this._adjustShapes(); return result; diff --git a/mindplot/src/main/javascript/TopicFeature.js b/mindplot/src/main/javascript/TopicFeature.js index ca21b3cd..d6368d62 100644 --- a/mindplot/src/main/javascript/TopicFeature.js +++ b/mindplot/src/main/javascript/TopicFeature.js @@ -41,14 +41,14 @@ mindplot.TopicFeature = { }); }, - createModel:function (type, attributes, id) { + createModel:function (type, attributes) { $assert(type, 'type can not be null'); $assert(attributes, 'attributes can not be null'); var model = mindplot.TopicFeature._featuresMetadataById.filter(function (elem) { return elem.id == type; })[0].model; - return new model(attributes, id); + return new model(attributes); }, createIcon:function (topic, model, readOnly) { diff --git a/mindplot/src/main/javascript/commands/AddFeatureToTopicCommand.js b/mindplot/src/main/javascript/commands/AddFeatureToTopicCommand.js index b23d8490..f208c791 100644 --- a/mindplot/src/main/javascript/commands/AddFeatureToTopicCommand.js +++ b/mindplot/src/main/javascript/commands/AddFeatureToTopicCommand.js @@ -18,7 +18,7 @@ mindplot.commands.AddFeatureToTopicCommand = new Class({ Extends:mindplot.Command, - initialize: function(topicId, featureType, attributes) { + initialize:function (topicId, featureType, attributes) { $assert($defined(topicId), 'topicId can not be null'); $assert(featureType, 'featureType can not be null'); @@ -28,15 +28,21 @@ mindplot.commands.AddFeatureToTopicCommand = new Class({ this._topicId = topicId; this._featureType = featureType; this._attributes = attributes; + this._featureModel = null; }, - execute: function(commandContext) { + execute:function (commandContext) { var topic = commandContext.findTopics(this._topicId)[0]; - var icon = topic.addFeature(this._featureType, this._attributes); - this._featureModel = icon.getModel(); + + // Feature must be created only one time. + if (!this._featureModel) { + var model = topic.getModel(); + this._featureModel = model.createFeature(this._featureType, this._attributes); + } + topic.addFeature(this._featureModel); }, - undoExecute: function(commandContext) { + undoExecute:function (commandContext) { var topic = commandContext.findTopics(this._topicId)[0]; topic.removeFeature(this._featureModel); } diff --git a/mindplot/src/main/javascript/commands/RemoveFeatureFromTopicCommand.js b/mindplot/src/main/javascript/commands/RemoveFeatureFromTopicCommand.js index 4f8990a0..1536f875 100644 --- a/mindplot/src/main/javascript/commands/RemoveFeatureFromTopicCommand.js +++ b/mindplot/src/main/javascript/commands/RemoveFeatureFromTopicCommand.js @@ -37,8 +37,7 @@ mindplot.commands.RemoveFeatureFromTopicCommand = new Class({ undoExecute:function (commandContext) { var topic = commandContext.findTopics(this._topicId)[0]; - var feature = this._oldFeature; - topic.addFeature(feature.getType(), feature.getAttributes(), this._featureId); + topic.addFeature(this._oldFeature); this._oldFeature = null; } }); \ No newline at end of file diff --git a/mindplot/src/main/javascript/model/FeatureModel.js b/mindplot/src/main/javascript/model/FeatureModel.js index 698649b8..a8bccec3 100644 --- a/mindplot/src/main/javascript/model/FeatureModel.js +++ b/mindplot/src/main/javascript/model/FeatureModel.js @@ -28,9 +28,9 @@ mindplot.model.FeatureModel = new Class({ } }, - initialize:function (type, id) { + initialize:function (type) { $assert(type, 'type can not be null'); - this._id = $defined(id) ? id : mindplot.model.FeatureModel._nextUUID(); + this._id = mindplot.model.FeatureModel._nextUUID(); this._type = type; this._attributes = {}; diff --git a/mindplot/src/main/javascript/model/IconModel.js b/mindplot/src/main/javascript/model/IconModel.js index 06236f8e..80124d3a 100644 --- a/mindplot/src/main/javascript/model/IconModel.js +++ b/mindplot/src/main/javascript/model/IconModel.js @@ -18,8 +18,8 @@ mindplot.model.IconModel = new Class({ Extends:mindplot.model.FeatureModel, - initialize:function (attributes, id) { - this.parent(mindplot.model.IconModel.FEATURE_TYPE, id); + initialize:function (attributes) { + this.parent(mindplot.model.IconModel.FEATURE_TYPE); this.setIconType(attributes.id); }, diff --git a/mindplot/src/main/javascript/model/LinkModel.js b/mindplot/src/main/javascript/model/LinkModel.js index a2ba595a..259adc87 100644 --- a/mindplot/src/main/javascript/model/LinkModel.js +++ b/mindplot/src/main/javascript/model/LinkModel.js @@ -18,8 +18,8 @@ mindplot.model.LinkModel = new Class({ Extends:mindplot.model.FeatureModel, - initialize:function (attributes,id) { - this.parent(mindplot.model.LinkModel.FEATURE_TYPE,id); + initialize:function (attributes) { + this.parent(mindplot.model.LinkModel.FEATURE_TYPE); this.setUrl(attributes.url); }, diff --git a/mindplot/src/main/javascript/model/NodeModel.js b/mindplot/src/main/javascript/model/NodeModel.js index 77b95d5c..e41b3d8f 100644 --- a/mindplot/src/main/javascript/model/NodeModel.js +++ b/mindplot/src/main/javascript/model/NodeModel.js @@ -32,8 +32,8 @@ mindplot.model.NodeModel = new Class({ this._feature = []; }, - createFeature:function (type, attributes, featureId) { - return mindplot.TopicFeature.createModel(type, attributes, featureId); + createFeature:function (type, attributes) { + return mindplot.TopicFeature.createModel(type, attributes); }, addFeature:function (feature) { @@ -47,9 +47,12 @@ mindplot.model.NodeModel = new Class({ removeFeature:function (feature) { $assert(feature, 'feature can not be null'); + var size = this._feature.length; this._feature = this._feature.filter(function (f) { return feature.getId() != f.getId(); }); + $assert(size - 1 == this._feature.length, 'Could not be removed ...'); + }, findFeatureByType:function (type) { @@ -61,9 +64,11 @@ mindplot.model.NodeModel = new Class({ findFeatureById:function (id) { $assert($defined(id), 'id can not be null'); - return this._feature.filter(function (feature) { + var result = this._feature.filter(function (feature) { return feature.getId() == id; - })[0]; + }); + $assert(result.length == 1, "Feature could not be found:" + id); + return result[0] }, getPropertiesKeys:function () { diff --git a/mindplot/src/main/javascript/model/NoteModel.js b/mindplot/src/main/javascript/model/NoteModel.js index 768b4366..27b320fe 100644 --- a/mindplot/src/main/javascript/model/NoteModel.js +++ b/mindplot/src/main/javascript/model/NoteModel.js @@ -18,8 +18,8 @@ mindplot.model.NoteModel = new Class({ Extends:mindplot.model.FeatureModel, - initialize:function (attributes, id) { - this.parent(mindplot.model.NoteModel.FEATURE_TYPE, id); + initialize:function (attributes) { + this.parent(mindplot.model.NoteModel.FEATURE_TYPE); var noteText = attributes.text ? attributes.text : " "; this.setText(noteText); },