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

@@ -16,23 +16,27 @@
* limitations under the License.
*/
mindplot.commands.AddIconToTopicCommand = new Class({
mindplot.commands.AddFeatureToTopicCommand = new Class({
Extends:mindplot.Command,
initialize: function(topicId, iconType) {
initialize: function(topicId, featureType, attributes) {
$assert($defined(topicId), 'topicId can not be null');
$assert(iconType, 'iconType can not be null');
this._topicsIds = topicId;
this._iconType = iconType;
$assert(featureType, 'featureType can not be null');
$assert(attributes, 'attributes can not be null');
this._topicId = topicId;
this._featureType = featureType;
this._attributes = attributes;
},
execute: function(commandContext) {
var topic = commandContext.findTopics(this._topicsIds)[0];
var iconImg = topic.addIcon(this._iconType, commandContext._designer);
this._iconModel = iconImg.getModel();
var topic = commandContext.findTopics(this._topicId)[0];
var icon = topic.addFeature(this._featureType, this._attributes);
this._featureModel = icon.getModel();
},
undoExecute: function(commandContext) {
var topic = commandContext.findTopics(this._topicsIds)[0];
topic.removeIcon(this._iconModel);
var topic = commandContext.findTopics(this._topicId)[0];
topic.removeFeature(this._featureModel);
}
});

View File

@@ -16,23 +16,28 @@
* limitations under the License.
*/
mindplot.commands.RemoveLinkFromTopicCommand = new Class({
mindplot.commands.ChangeFeatureToTopicCommand = new Class({
Extends:mindplot.Command,
initialize: function(topicId) {
initialize: function(topicId, featureId, attributes) {
$assert($defined(topicId), 'topicId can not be null');
this._topicsIds = topicId;
$assert($defined(featureId), 'featureId can not be null');
$assert($defined(attributes), 'attributes can not be null');
this._topicId = topicId;
this._featureId = featureId;
this._attributes = attributes;
},
execute: function(commandContext) {
var topic = commandContext.findTopics(this._topicsIds)[0];
var model = topic.getModel();
var links = model.getLinks()[0];
this._text = links.getUrl();
topic.removeLink();
var topic = commandContext.findTopics(this._topicId)[0];
var feature = topic.findFeatureById(this._featureId);
var oldAttributes = feature.getAttributes();
feature.setAttributes(this._attributes);
this._attributes = oldAttributes;
},
undoExecute: function(commandContext) {
var topic = commandContext.findTopics(this._topicsIds)[0];
topic.addLink(this._url, commandContext._designer);
this.execute(commandContext);
}
});

View File

@@ -1,48 +0,0 @@
/*
* 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.commands.ChangeLinkToTopicCommand = new Class({
Extends:mindplot.Command,
initialize: function(topicId, url) {
$assert($defined(topicId), 'topicId can not be null');
this._topicsIds = topicId;
this._url = url;
this._id = mindplot.Command._nextUUID();
},
execute: function(commandContext) {
var topic = commandContext.findTopics(this._topicsIds)[0];
if (topic.hasLink()) {
var model = topic.getModel();
var link = model.getLinks()[0];
this._oldUrl = link.getUrl();
topic.removeLink();
}
topic.addLink(this._url);
},
undoExecute: function(commandContext) {
var topic = commandContext.findTopics(this._topicsIds)[0];
if (this._oldtext) {
topic.removeLink();
topic.addLink(this._oldUrl);
} else {
topic.removeLink();
}
}
});

View File

@@ -1,49 +0,0 @@
/*
* 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.commands.ChangeNoteToTopicCommand = new Class({
Extends:mindplot.Command,
initialize: function(topicId, text) {
$assert($defined(topicId), 'topicId can not be null');
this._topicsIds = topicId;
this._text = text;
this._oldtext = null;
this._id = mindplot.Command._nextUUID();
},
execute: function(commandContext) {
var topic = commandContext.findTopics(this._topicsIds)[0];
if (topic.hasNote()) {
var model = topic.getModel();
var notes = model.getNotes()[0];
this._oldtext = notes.getText();
topic.removeNote();
}
topic.addNote(this._text);
},
undoExecute: function(commandContext) {
var topic = commandContext.findTopics(this._topicsIds)[0];
if (this._oldtext) {
topic.removeNote();
topic.addNote(this._oldtext);
} else {
topic.removeNote();
}
}
});

View File

@@ -16,21 +16,30 @@
* limitations under the License.
*/
mindplot.commands.RemoveNoteFromTopicCommand = new Class({
mindplot.commands.RemoveFeatureFromTopicCommand = new Class({
Extends:mindplot.Command,
initialize: function(topicId) {
initialize: function(topicId, featureId) {
$assert($defined(topicId), 'topicId can not be null');
this._topicsIds = topicId;
$assert(featureId, 'iconModel can not be null');
this._topicId = topicId;
this._featureId = featureId;
this._oldFeature = null;
},
execute: function(commandContext) {
var topic = commandContext.findTopics(this._topicsIds)[0];
var model = topic.getModel();
var notes = model.getNotes()[0];
this._text = notes.getText();
topic.removeNote();
var topic = commandContext.findTopics(this._topicId)[0];
var feature = topic.findFeatureById(this._featureId);
topic.removeFeature(feature);
this._oldFeature = feature;
},
undoExecute: function(commandContext) {
var topic = commandContext.findTopics(this._topicsIds)[0];
topic.addNote(this._text, commandContext._designer);
var topic = commandContext.findTopics(this._topicId)[0];
var feature = this._oldFeature;
topic.addFeature(feature.getType(), feature.getAttributes());
this._oldFeature = null;
}
});

View File

@@ -1,39 +0,0 @@
/*
* 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.commands.RemoveIconFromTopicCommand = new Class({
Extends:mindplot.Command,
initialize: function(topicIds, iconModel) {
$assert($defined(topicIds), 'topicIds can not be null');
$assert(iconModel, 'iconModel can not be null');
this._topicsIds = topicIds;
this._iconModel = iconModel;
},
execute: function(commandContext) {
var topic = commandContext.findTopics(this._topicsIds)[0];
topic.removeIcon(this._iconModel);
},
undoExecute: function(commandContext) {
var topic = commandContext.findTopics(this._topicsIds)[0];
var iconType = this._iconModel.getIconType();
var iconImg = topic.addIcon(iconType, commandContext._designer);
this._iconModel = iconImg.getModel();
}
});