Fix several errors removing a node ...

This commit is contained in:
Paulo Gustavo Veiga 2012-07-07 11:52:23 -03:00
parent f3a13dfe7a
commit f3da916965
10 changed files with 616 additions and 557 deletions

View File

@ -122,7 +122,7 @@ mindplot.ConnectionLine = new Class({
var targetPosition = targetTopic.getPosition(); var targetPosition = targetTopic.getPosition();
var offset = mindplot.Topic.CONNECTOR_WIDTH / 2; var offset = mindplot.Topic.CONNECTOR_WIDTH / 2;
var targetTopicSize = targetTopic.getSize(); var targetTopicSize = targetTopic.getSize();
var y; var y, x;
if (targetTopic.getShapeType() == mindplot.model.TopicShape.LINE) { if (targetTopic.getShapeType() == mindplot.model.TopicShape.LINE) {
y = targetTopicSize.height; y = targetTopicSize.height;
} else { } else {
@ -133,14 +133,17 @@ mindplot.ConnectionLine = new Class({
var connector = targetTopic.getShrinkConnector(); var connector = targetTopic.getShrinkConnector();
if ($defined(connector)) { if ($defined(connector)) {
if (Math.sign(targetPosition.x) > 0) { if (Math.sign(targetPosition.x) > 0) {
var x = targetTopicSize.width; x = targetTopicSize.width;
connector.setPosition(x, y); connector.setPosition(x, y);
} }
else { else {
var x = -mindplot.Topic.CONNECTOR_WIDTH; x = -mindplot.Topic.CONNECTOR_WIDTH;
}
console.log("conector:" + x + ", " + y);
connector.setPosition(x, y); connector.setPosition(x, y);
} }
}
}, },
setStroke:function (color, style, opacity) { setStroke:function (color, style, opacity) {

View File

@ -506,7 +506,6 @@ mindplot.Designer = new Class({
$assert(mindmapModel, "mindmapModel can not be null"); $assert(mindmapModel, "mindmapModel can not be null");
this._mindmap = mindmapModel; this._mindmap = mindmapModel;
// try {
// Init layout manager ... // Init layout manager ...
var size = {width:25, height:25}; var size = {width:25, height:25};
var layoutManager = new mindplot.layout.LayoutManager(mindmapModel.getCentralTopic().getId(), size); var layoutManager = new mindplot.layout.LayoutManager(mindmapModel.getCentralTopic().getId(), size);
@ -543,9 +542,6 @@ mindplot.Designer = new Class({
mindplot.EventBus.instance.fireEvent(mindplot.EventBus.events.DoLayout); mindplot.EventBus.instance.fireEvent(mindplot.EventBus.events.DoLayout);
this.fireEvent('loadSuccess'); this.fireEvent('loadSuccess');
// } catch(e) {
// this.fireEvent('loadError', e);
// }
}, },
getMindmap:function () { getMindmap:function () {
@ -591,7 +587,7 @@ mindplot.Designer = new Class({
_relationshipModelToRelationship:function (model) { _relationshipModelToRelationship:function (model) {
$assert(model, "Node model can not be null"); $assert(model, "Node model can not be null");
var result = this._buildRelationship(model); var result = this._buildRelationshipShape(model);
var sourceTopic = result.getSourceTopic(); var sourceTopic = result.getSourceTopic();
sourceTopic.addRelationship(result); sourceTopic.addRelationship(result);
@ -602,7 +598,6 @@ mindplot.Designer = new Class({
result.setVisibility(sourceTopic.isVisible() && targetTopic.isVisible()); result.setVisibility(sourceTopic.isVisible() && targetTopic.isVisible());
this._workspace.appendChild(result); this._workspace.appendChild(result);
result.redraw();
return result; return result;
}, },
@ -623,7 +618,7 @@ mindplot.Designer = new Class({
this.getModel().removeRelationship(relationship); this.getModel().removeRelationship(relationship);
}, },
_buildRelationship:function (model) { _buildRelationshipShape:function (model) {
var dmodel = this.getModel(); var dmodel = this.getModel();
var sourceTopicId = model.getFromNode(); var sourceTopicId = model.getFromNode();
@ -674,16 +669,20 @@ mindplot.Designer = new Class({
// If there are more than one node selected, // If there are more than one node selected,
$notify($msg('ENTITIES_COULD_NOT_BE_DELETED')); $notify($msg('ENTITIES_COULD_NOT_BE_DELETED'));
return; return;
} else if (topics.length == 1 && topics[0].getTopicType() == mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE) {
$notify($msg('CENTRAL_TOPIC_CAN_NOT_BE_DELETED'));
return;
} }
// Filter the lists ... // If the central topic has been selected, I must filter ir
var validateFunc = function (object) { var topicIds = topics.filter(function (topic) {
return object.getType() == mindplot.Relationship.type || object.getTopicType() != mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE return topic.getTopicType() != mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE
}; }).map(function (topic) {
var validateError = $msg('CENTRAL_TOPIC_CAN_NOT_BE_DELETED'); return topic.getId()
var model = this.getModel(); });
var topicIds = model.filterTopicsIds(validateFunc, validateError);
var relIds = model.filterSelectedRelationships().map(function (rel) {
var relIds = topics.map(function (rel) {
return rel.getId(); return rel.getId();
}); });

View File

@ -42,11 +42,11 @@ mindplot.DesignerKeyboard = new Class({
var model = designer.getModel(); var model = designer.getModel();
var keyboardEvents = { var keyboardEvents = {
'backspace':function (event) { 'backspace':function (event) {
designer.deleteSelectedEntities();
event.preventDefault(); event.preventDefault();
event.stopPropagation(); event.stopPropagation();
designer.deleteSelectedEntities();
}.bind(this), }.bind(this),
'space':function () { 'space':function () {
@ -73,129 +73,123 @@ mindplot.DesignerKeyboard = new Class({
}.bind(this), }.bind(this),
'meta+enter':function (event) { 'meta+enter':function (event) {
designer.createChildForSelectedNode();
event.preventDefault(); event.preventDefault();
event.stopPropagation(); event.stopPropagation();
designer.createChildForSelectedNode();
}.bind(this), }.bind(this),
'ctrl+z':function () { 'ctrl+z':function () {
designer.undo();
event.preventDefault(event); event.preventDefault(event);
event.stopPropagation(); event.stopPropagation();
designer.undo();
}.bind(this), }.bind(this),
'meta+z':function (event) { 'meta+z':function (event) {
designer.undo();
event.preventDefault(); event.preventDefault();
event.stopPropagation(); event.stopPropagation();
designer.undo();
}.bind(this), }.bind(this),
'ctrl+z+shift':function (event) { 'ctrl+z+shift':function (event) {
designer.redo();
event.preventDefault(); event.preventDefault();
event.stopPropagation(); event.stopPropagation();
designer.redo();
}.bind(this), }.bind(this),
'meta+z+shift':function (event) { 'meta+z+shift':function (event) {
designer.redo();
event.preventDefault(); event.preventDefault();
event.stopPropagation(); event.stopPropagation();
designer.redo();
}.bind(this), }.bind(this),
'ctrl+y':function (event) { 'ctrl+y':function (event) {
designer.redo();
event.preventDefault(); event.preventDefault();
event.stopPropagation(); event.stopPropagation();
designer.redo();
}.bind(this), }.bind(this),
'meta+y':function (event) { 'meta+y':function (event) {
designer.redo();
event.preventDefault(); event.preventDefault();
event.stopPropagation(); event.stopPropagation();
designer.redo();
}.bind(this), }.bind(this),
'ctrl+a':function (event) { 'ctrl+a':function (event) {
designer.selectAll();
event.preventDefault(); event.preventDefault();
event.stopPropagation(); event.stopPropagation();
designer.selectAll();
}, },
'ctrl+b':function (event) { 'ctrl+b':function (event) {
designer.changeFontWeight();
event.preventDefault(); event.preventDefault();
event.stopPropagation(); event.stopPropagation();
designer.changeFontWeight();
}, },
'meta+b':function (event) { 'meta+b':function (event) {
designer.changeFontWeight();
event.preventDefault(); event.preventDefault();
event.stopPropagation(); event.stopPropagation();
designer.changeFontWeight();
}, },
'ctrl+s':function (event) { 'ctrl+s':function (event) {
event.preventDefault();
$('save').fireEvent('click');
event.preventDefault(); event.preventDefault();
event.stopPropagation(); event.stopPropagation();
$('save').fireEvent('click');
}, },
'meta+s':function (event) { 'meta+s':function (event) {
event.preventDefault();
$('save').fireEvent('click');
event.preventDefault(); event.preventDefault();
event.stopPropagation(); event.stopPropagation();
$('save').fireEvent('click');
}, },
'ctrl+i':function (event) { 'ctrl+i':function (event) {
designer.changeFontStyle();
event.preventDefault(); event.preventDefault();
event.stopPropagation(); event.stopPropagation();
designer.changeFontStyle();
}, },
'meta+i':function (event) { 'meta+i':function (event) {
designer.changeFontStyle();
event.preventDefault(); event.preventDefault();
event.stopPropagation(); event.stopPropagation();
designer.changeFontStyle();
}, },
'meta+shift+a':function (event) { 'meta+shift+a':function (event) {
designer.deselectAll();
event.preventDefault(); event.preventDefault();
event.stopPropagation(); event.stopPropagation();
designer.deselectAll();
}, },
'ctrl+shift+a':function (event) { 'ctrl+shift+a':function (event) {
designer.deselectAll();
event.preventDefault(); event.preventDefault();
event.stopPropagation(); event.stopPropagation();
designer.deselectAll();
}, },
'meta+a':function (event) { 'meta+a':function (event) {
designer.selectAll();
event.preventDefault(); event.preventDefault();
event.stopPropagation(); event.stopPropagation();
designer.selectAll();
}, },
'right':function () { 'right':function () {

View File

@ -17,6 +17,12 @@
*/ */
mindplot.Relationship = new Class({ mindplot.Relationship = new Class({
Extends:mindplot.ConnectionLine, Extends:mindplot.ConnectionLine,
Static:{
getStrokeColor:function () {
return '#9b74e6';
},
type: "Relationship"
},
initialize:function (sourceNode, targetNode, model) { initialize:function (sourceNode, targetNode, model) {
$assert(sourceNode, "sourceNode can not be null"); $assert(sourceNode, "sourceNode can not be null");
$assert(targetNode, "targetNode can not be null"); $assert(targetNode, "targetNode can not be null");
@ -161,6 +167,8 @@ mindplot.Relationship = new Class({
this.parent(workspace); this.parent(workspace);
this._positionArrows(); this._positionArrows();
this.redraw();
}, },
_initializeControlPointController:function () { _initializeControlPointController:function () {
@ -310,9 +318,3 @@ mindplot.Relationship = new Class({
return this._model.getId(); return this._model.getId();
} }
}); });
mindplot.Relationship.type = "Relationship";
mindplot.Relationship.getStrokeColor = function () {
return '#9b74e6';
};

View File

@ -30,10 +30,14 @@ mindplot.commands.DeleteCommand = new Class({
}, },
execute:function (commandContext) { execute:function (commandContext) {
var topics = commandContext.findTopics(this._topicIds);
// If a parent has been selected for deletion, the children must be excluded from the delete ...
var topics = this._filterChildren(this._topicIds, commandContext);
if (topics.length > 0) { if (topics.length > 0) {
topics.forEach( topics.forEach(
function (topic, index) { function (topic) {
var model = topic.getModel(); var model = topic.getModel();
// Delete relationships // Delete relationships
@ -45,9 +49,8 @@ mindplot.commands.DeleteCommand = new Class({
commandContext.deleteRelationship(relationship); commandContext.deleteRelationship(relationship);
} }
// Delete the node itself ...
this._deletedTopicModels.push(model); this._deletedTopicModels.push(model);
// Is connected?.
var outTopic = topic.getOutgoingConnectedTopic(); var outTopic = topic.getOutgoingConnectedTopic();
var outTopicId = null; var outTopicId = null;
if (outTopic != null) { if (outTopic != null) {
@ -72,9 +75,7 @@ mindplot.commands.DeleteCommand = new Class({
undoExecute:function (commandContext) { undoExecute:function (commandContext) {
var topics = commandContext.findTopics(this._topicIds);
var parent = commandContext.findTopics(this._parentTopicIds); var parent = commandContext.findTopics(this._parentTopicIds);
this._deletedTopicModels.forEach( this._deletedTopicModels.forEach(
function (model, index) { function (model, index) {
var topic = commandContext.createTopic(model); var topic = commandContext.createTopic(model);
@ -95,5 +96,28 @@ mindplot.commands.DeleteCommand = new Class({
this._deletedTopicModels = []; this._deletedTopicModels = [];
this._parentTopicIds = []; this._parentTopicIds = [];
this._deletedRelModel = []; this._deletedRelModel = [];
},
_filterChildren:function (topicIds, commandContext) {
var topics = commandContext.findTopics(topicIds);
var result = [];
topics.forEach(function (topic) {
var parent = topic.getParent();
var found = false;
while (parent != null && !found) {
found = topicIds.contains(parent.getId());
if (found) {
break;
}
parent = parent.getParent();
}
if (!found) {
result.push(topic);
}
});
return result;
} }
}); });

View File

@ -198,7 +198,7 @@ mindplot.layout.BalancedSorter = new Class({
var factor = node.getOrder() % 2 == 0 ? 2 : 1; var factor = node.getOrder() % 2 == 0 ? 2 : 1;
for (var i = 0; i < children.length; i++) { for (var i = 0; i < children.length; i++) {
var order = i == 0 && factor == 1 ? 1 : (factor * i); var order = i == 0 && factor == 1 ? 1 : (factor * i);
$assert(children[i].getOrder() == order, "Missing order elements. Missing order: " + (i * factor)); $assert(children[i].getOrder() == order, "Missing order elements. Missing order: " + (i * factor) + ". Parent:" + node.getId() + ",Node:" + children[i].getId());
} }
}, },

View File

@ -65,7 +65,7 @@ mindplot.layout.OriginalLayout = new Class({
this._treeSet.disconnect(nodeId); this._treeSet.disconnect(nodeId);
// Fire a basic validation ... // Fire a basic validation ...
sorter.verify(this._treeSet, node); parent.getSorter().verify(this._treeSet, parent);
}, },
layout:function () { layout:function () {
@ -88,8 +88,12 @@ mindplot.layout.OriginalLayout = new Class({
var nodeId = node.getId(); var nodeId = node.getId();
var children = this._treeSet.getChildren(node); var children = this._treeSet.getChildren(node);
var parent = this._treeSet.getParent(node); var parent = this._treeSet.getParent(node);
var childrenOrderMoved = children.some(function(child) { return child.hasOrderChanged(); }); var childrenOrderMoved = children.some(function (child) {
var childrenSizeChanged = children.some(function(child) { return child.hasSizeChanged(); }); return child.hasOrderChanged();
});
var childrenSizeChanged = children.some(function (child) {
return child.hasSizeChanged();
});
// If ether any of the nodes has been changed of position or the height of the children is not // If ether any of the nodes has been changed of position or the height of the children is not
// the same, children nodes must be repositioned .... // the same, children nodes must be repositioned ....

View File

@ -108,6 +108,17 @@ mindplot.model.Mindmap = new Class({
deleteRelationship:function (relationship) { deleteRelationship:function (relationship) {
this._relationships.erase(relationship); this._relationships.erase(relationship);
},
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;
}
}
} }
} }
); );

View File

@ -184,9 +184,26 @@ mindplot.model.NodeModel = new Class({
} }
} }
return result; return result;
}, },
findNodeById : function(id) {
var result = null;
if (this.getId() == id) {
return this;
} else {
var children = this.getChildren();
for (var i = 0; i < children.length; i++) {
var child = children[i];
result = child.findNodeById(id);
if (result) {
break;
}
}
}
return result;
},
inspect : function() { inspect : function() {
return '(type:' + this.getType() + ' , id: ' + this.getId() + ')'; return '(type:' + this.getType() + ' , id: ' + this.getId() + ')';
} }

View File

@ -410,6 +410,11 @@ mindplot.persistence.XMLSerializer_Pela = new Class({
if (srcId == destId) { if (srcId == destId) {
return null; return null;
} }
// Is the connections points valid ?. If it's not, do not load the relationship ...
if (mindmap.findNodeById(srcId) == null || mindmap.findNodeById(destId)) {
return null;
}
var model = mindmap.createRelationship(srcId, destId); var model = mindmap.createRelationship(srcId, destId);
model.setLineType(lineType); model.setLineType(lineType);
if ($defined(srcCtrlPoint) && srcCtrlPoint != "") { if ($defined(srcCtrlPoint) && srcCtrlPoint != "") {