Relationships works with commands ...

This commit is contained in:
Paulo Gustavo Veiga 2012-07-07 01:33:34 -03:00
parent 8da65a9102
commit 82dc1fc3d4
7 changed files with 48 additions and 62 deletions

View File

@ -23,7 +23,7 @@ mindplot.ActionDispatcher = new Class({
$assert(commandContext, "commandContext can not be null"); $assert(commandContext, "commandContext can not be null");
}, },
connectByRelation: function(model, mindmap) { addRelationship: function(model, mindmap) {
throw "method must be implemented."; throw "method must be implemented.";
}, },

View File

@ -491,15 +491,6 @@ mindplot.Designer = new Class({
this._relPivot.start(nodes[0], pos); this._relPivot.start(nodes[0], pos);
}, },
connectByRelation:function (sourceTopic, targetTopic) {
$assert(sourceTopic, "sourceTopic can not be null");
$assert(targetTopic, "targetTopic can not be null");
// Create a new topic model ...
var mindmap = this.getMindmap();
var model = mindmap.createRelationship(sourceTopic.getModel().getId(), targetTopic.getModel().getId());
this._actionDispatcher.connectByRelation(model);
},
needsSave:function () { needsSave:function () {
//@Todo: Review all this ... //@Todo: Review all this ...
@ -600,21 +591,22 @@ 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 relationship = this._buildRelationship(model); var result = this._buildRelationship(model);
var sourceTopic = relationship.getSourceTopic();
sourceTopic.connectByRelation(relationship);
var targetTopic = relationship.getTargetTopic(); var sourceTopic = result.getSourceTopic();
targetTopic.connectByRelation(relationship); sourceTopic.addRelationship(result);
relationship.setVisibility(sourceTopic.isVisible() && targetTopic.isVisible());
var workspace = this._workspace; var targetTopic = result.getTargetTopic();
workspace.appendChild(relationship); targetTopic.addRelationship(result);
relationship.redraw();
return relationship; result.setVisibility(sourceTopic.isVisible() && targetTopic.isVisible());
this._workspace.appendChild(result);
result.redraw();
return result;
}, },
createRelationship:function (model) { _addRelationship:function (model) {
this._mindmap.addRelationship(model); this._mindmap.addRelationship(model);
return this._relationshipModelToRelationship(model); return this._relationshipModelToRelationship(model);
}, },
@ -641,14 +633,14 @@ mindplot.Designer = new Class({
var targetTopic = dmodel.findTopicById(targetTopicId); var targetTopic = dmodel.findTopicById(targetTopicId);
// Build relationship line .... // Build relationship line ....
var relationship = new mindplot.Relationship(sourceTopic, targetTopic, model); var result = new mindplot.Relationship(sourceTopic, targetTopic, model);
relationship.addEvent('onfocus', function (event) { result.addEvent('onfocus', function (event) {
this.onObjectFocusEvent(relationship, event); this.onObjectFocusEvent(result, event);
}.bind(this)); }.bind(this));
// Append it to the workspace ... // Append it to the workspace ...
dmodel.addRelationship(relationship); dmodel.addRelationship(result);
return relationship; return result;
}, },
_removeTopic:function (node) { _removeTopic:function (node) {

View File

@ -17,7 +17,7 @@
*/ */
mindplot.RelationshipPivot = new Class({ mindplot.RelationshipPivot = new Class({
initialize: function(workspace, designer) { initialize:function (workspace, designer) {
$assert(workspace, "workspace can not be null"); $assert(workspace, "workspace can not be null");
$assert(designer, "designer can not be null"); $assert(designer, "designer can not be null");
this._workspace = workspace; this._workspace = workspace;
@ -29,7 +29,7 @@ mindplot.RelationshipPivot = new Class({
}, },
start : function(sourceTopic, targetPos) { start:function (sourceTopic, targetPos) {
$assert(sourceTopic, "sourceTopic can not be null"); $assert(sourceTopic, "sourceTopic can not be null");
$assert(targetPos, "targetPos can not be null"); $assert(targetPos, "targetPos can not be null");
@ -53,14 +53,14 @@ mindplot.RelationshipPivot = new Class({
// Register focus events on all topics ... // Register focus events on all topics ...
var model = this._designer.getModel(); var model = this._designer.getModel();
var topics = model.getTopics(); var topics = model.getTopics();
topics.forEach(function(topic) { topics.forEach(function (topic) {
topic.addEvent('ontfocus', this._onTopicClick); topic.addEvent('ontfocus', this._onTopicClick);
}.bind(this)); }.bind(this));
} }
}, },
dispose : function() { dispose:function () {
var workspace = this._workspace; var workspace = this._workspace;
if (this._isActive()) { if (this._isActive()) {
@ -69,7 +69,7 @@ mindplot.RelationshipPivot = new Class({
var model = this._designer.getModel(); var model = this._designer.getModel();
var topics = model.getTopics(); var topics = model.getTopics();
topics.forEach(function(topic) { topics.forEach(function (topic) {
topic.removeEvent('ontfocus', this._onTopicClick); topic.removeEvent('ontfocus', this._onTopicClick);
}.bind(this)); }.bind(this));
@ -81,7 +81,7 @@ mindplot.RelationshipPivot = new Class({
} }
}, },
_mouseMove : function(event) { _mouseMove:function (event) {
var screen = this._workspace.getScreenManager(); var screen = this._workspace.getScreenManager();
var pos = screen.getWorkspaceMousePosition(event); var pos = screen.getWorkspaceMousePosition(event);
@ -90,21 +90,22 @@ mindplot.RelationshipPivot = new Class({
return false; return false;
}, },
_cleanOnMouseClick : function (event) { _cleanOnMouseClick:function (event) {
// The user clicks on a desktop on in other element that is not a node. // The user clicks on a desktop on in other element that is not a node.
this.dispose(); this.dispose();
event.stopPropagation(); event.stopPropagation();
}, },
_connectOnFocus : function(topic) { _connectOnFocus:function (targetTopic) {
var sourceTopic = this._sourceTopic; var sourceTopic = this._sourceTopic;
var mindmap = this._designer.getMindmap();
var relModel = mindmap.createRelationship(targetTopic.getId(), sourceTopic.getId());
this._designer._actionDispatcher.addRelationship(relModel);
this.dispose(); this.dispose();
this._designer.connectByRelation(sourceTopic, topic);
}, },
_isActive : function() { _isActive:function () {
return this._pivot != null; return this._pivot != null;
} }
}); });

View File

@ -34,7 +34,7 @@ mindplot.StandaloneActionDispatcher = new Class({
this.execute(command); this.execute(command);
}, },
connectByRelation:function (model) { addRelationship:function (model) {
var command = new mindplot.commands.AddRelationshipCommand(model); var command = new mindplot.commands.AddRelationshipCommand(model);
this.execute(command); this.execute(command);
}, },
@ -276,9 +276,9 @@ mindplot.CommandContext = new Class({
topic.disconnect(this._designer._workspace); topic.disconnect(this._designer._workspace);
}, },
createRelationship:function (model) { addRelationship:function (model) {
$assert(model, "model cannot be null"); $assert(model, "model cannot be null");
return this._designer.createRelationship(model); return this._designer._addRelationship(model);
}, },
deleteRelationship:function (relationship) { deleteRelationship:function (relationship) {

View File

@ -311,7 +311,7 @@ mindplot.Topic = new Class({
this._adjustShapes(); this._adjustShapes();
}, },
connectByRelation : function(relationship) { addRelationship : function(relationship) {
this._relationships.push(relationship); this._relationships.push(relationship);
}, },

View File

@ -17,24 +17,19 @@
*/ */
mindplot.commands.AddRelationshipCommand = new Class({ mindplot.commands.AddRelationshipCommand = new Class({
Extends:mindplot.Command, Extends:mindplot.Command,
initialize: function(model) { initialize:function (model) {
$assert(model, 'Relationship model can not be null'); $assert(model, 'Relationship model can not be null');
this.parent(); this.parent();
this._model = model; this._model = model;
}, },
execute: function(commandContext) { execute:function (commandContext) {
var relationship = commandContext.createRelationship(this._model); var relationship = commandContext.addRelationship(this._model);
// Finally, focus ...
var designer = commandContext._designer;
designer.onObjectFocusEvent.attempt(relationship, designer);
relationship.setOnFocus(true); relationship.setOnFocus(true);
}, },
undoExecute: function(commandContext) {
var relationship = commandContext.deleteRelationship(this._model);
// @Todo: Esto esta mal. Designer toca el mindmap ... undoExecute:function (commandContext) {
// this._mindmap.removeRelationship(this._model); var rel = commandContext.findRelationships(this._model.getId());
commandContext.deleteRelationship(rel[0]);
} }
}); });

View File

@ -19,15 +19,14 @@
mindplot.commands.DeleteCommand = new Class({ mindplot.commands.DeleteCommand = new Class({
Extends:mindplot.Command, Extends:mindplot.Command,
initialize:function (topicIds, relIds) { initialize:function (topicIds, relIds) {
$assert($defined(topicIds), 'topicIds can not be null'); $assert($defined(relIds), 'topicIds can not be null');
this.parent(); this.parent();
this._relIds = relIds; this._relIds = relIds;
this._topicIds = topicIds; this._topicIds = topicIds;
this._deletedTopicModels = []; this._deletedTopicModels = [];
this._deletedRelModel = [];
this._parentTopicIds = []; this._parentTopicIds = [];
this._deletedRelationships = [];
this._id = mindplot.Command._nextUUID();
}, },
execute:function (commandContext) { execute:function (commandContext) {
@ -42,7 +41,7 @@ mindplot.commands.DeleteCommand = new Class({
while (relationships.length > 0) { while (relationships.length > 0) {
var relationship = relationships[0]; var relationship = relationships[0];
this._deletedRelationships.push(relationship); this._deletedRelModel.push(relationship);
commandContext.deleteRelationship(relationship); commandContext.deleteRelationship(relationship);
} }
@ -65,7 +64,7 @@ mindplot.commands.DeleteCommand = new Class({
var rels = commandContext.findRelationships(this._relIds); var rels = commandContext.findRelationships(this._relIds);
if (rels.length > 0) { if (rels.length > 0) {
rels.forEach(function (rel) { rels.forEach(function (rel) {
this._deletedRelationships.push(rel.getModel().clone()); this._deletedRelModel.push(rel.getModel().clone());
commandContext.deleteRelationship(rel); commandContext.deleteRelationship(rel);
}.bind(this)); }.bind(this));
} }
@ -88,13 +87,12 @@ mindplot.commands.DeleteCommand = new Class({
}.bind(this) }.bind(this)
); );
this._deletedRelationships.forEach( this._deletedRelModel.forEach(function (model) {
function (rel) { commandContext.addRelationship(model);
commandContext.createRelationship(rel);
}.bind(this)); }.bind(this));
this._deletedTopicModels = []; this._deletedTopicModels = [];
this._parentTopicIds = []; this._parentTopicIds = [];
this._deletedRelationships = []; this._deletedRelModel = [];
} }
}); });