Start working on ActionDispatcher migration.

This commit is contained in:
Paulo Veiga 2011-08-03 17:52:39 -03:00
parent 6a4a0f68fc
commit 63cda0a170
20 changed files with 544 additions and 569 deletions

View File

@ -55,6 +55,9 @@
<filelist dir="${basedir}/src/main/javascript/" files="Mindmap.js"/>
<filelist dir="${basedir}/src/main/javascript/" files="NodeModel.js"/>
<filelist dir="${basedir}/src/main/javascript/" files="RelationshipModel.js"/>
<filelist dir="${basedir}/src/main/javascript/" files="ActionDispatcher.js"/>
<filelist dir="${basedir}/src/main/javascript/" files="BrixActionDispatcher.js"/>
<filelist dir="${basedir}/src/main/javascript/" files="LocalActionDispatcher.js"/>
<filelist dir="${basedir}/src/main/javascript/" files="MindmapDesigner.js"/>
<filelist dir="${basedir}/src/main/javascript/" files="ScreenManager.js"/>
<filelist dir="${basedir}/src/main/javascript/" files="Workspace.js"/>

View File

@ -16,7 +16,8 @@
* limitations under the License.
*/
mindplot.BaseCommandDispatcher = new Class({
//noinspection JSUnusedLocalSymbols
mindplot.ActionDispatcher = new Class({
initialize: function() {
},
@ -41,19 +42,15 @@ mindplot.BaseCommandDispatcher = new Class({
throw "method must be implemented.";
},
changeIcon: function(topicId, iconId, iconType) {
deleteTopics: function(topicsIds) {
throw "method must be implemented.";
},
deleteTopic: function(topicsIds) {
dragTopic: function(topicId, position, order, parentTopic) {
throw "method must be implemented.";
},
dragTopic: function(topicId) {
throw "method must be implemented.";
},
moveControlPoint: function(trlPointController, point) {
moveControlPoint: function(ctrlPoint, point) {
throw "method must be implemented.";
},
@ -65,8 +62,46 @@ mindplot.BaseCommandDispatcher = new Class({
throw "method must be implemented.";
},
removeNodeFromTopic: function(topicId) {
removeNoteFromTopic: function(topicId) {
throw "method must be implemented.";
},
changeFontFamilyToTopic: function(topicIds, fontFamily) {
throw "method must be implemented.";
},
changeFontStyleToTopic: function(topicsIds) {
throw "method must be implemented.";
},
changeFontColorToTopic: function(topicsIds, color) {
throw "method must be implemented.";
},
changeBackgroundColorToTopic: function(topicsIds, color) {
throw "method must be implemented.";
},
changeBorderColorToTopic: function(topicsIds, color) {
throw "method must be implemented.";
},
changeShapeToTopic : function(topicsIds, shapeType) {
throw "method must be implemented.";
},
changeFontWeightToTopic : function(topicsIds) {
throw "method must be implemented.";
}
});
mindplot.ActionDispatcher.setInstance = function(dispatcher) {
mindplot.ActionDispatcher._instance = dispatcher;
};
mindplot.ActionDispatcher.getInstance = function() {
return mindplot.ActionDispatcher._instance;
};

View File

@ -0,0 +1,26 @@
/*
* 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.BrixActionDispatcher = new Class({
Extends: mindplot.ActionDispatcher,
initialize: function(designer) {
$assert(designer, "designer can not be null");
}
});

View File

@ -113,8 +113,10 @@ mindplot.ControlPoint = new Class({
_mouseUp : function(event, point) {
this._workspace.getScreenManager().removeEventListener('mousemove', this._mouseMoveFunction);
this._workspace.getScreenManager().removeEventListener('mouseup', this._mouseUpFunction);
var command = new mindplot.commands.MoveControlPointCommand(this, point);
designer._actionRunner.execute(command); //todo:Uggly!! designer is global!!
var actionDispatcher = mindplot.ActionDispatcher.getInstance();
actionDispatcher.moveControlPoint(this, point);
this._isBinded = false;
/*event.preventDefault();
event.stop();

View File

@ -16,8 +16,10 @@
* limitations under the License.
*/
// @Todo: Why the whole desginer ?. Must decouple this...
mindplot.DesignerActionRunner = new Class({
initialize: function(designer) {
$assert(designer, "designer can not be null");
this._designer = designer;
this._undoManager = new mindplot.DesignerUndoManager();
this._context = new mindplot.CommandContext(this._designer);
@ -124,11 +126,3 @@ mindplot.CommandContext = new Class({
return this._designer.getSelectedRelationshipLines();
}
});
mindplot.DesignerActionRunner.setInstance = function(actionRunner) {
mindplot.DesignerActionRunner._instance = actionRunner;
};
mindplot.DesignerActionRunner.getInstance = function() {
return mindplot.DesignerActionRunner._instance;
};

View File

@ -1,239 +1,203 @@
/*
* 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.
*/
* 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.DragTopic = function(dragShape, draggedNode)
{
$assert(dragShape, 'Rect can not be null.');
$assert(draggedNode, 'draggedNode can not be null.');
mindplot.DragTopic = new Class({
initialize:function(dragShape, draggedNode) {
$assert(dragShape, 'Rect can not be null.');
$assert(draggedNode, 'draggedNode can not be null.');
this._elem2d = dragShape;
this._order = null;
this._draggedNode = draggedNode;
this._position = new core.Point();
};
this._elem2d = dragShape;
this._order = null;
this._draggedNode = draggedNode;
this._position = new core.Point();
},
mindplot.DragTopic.initialize = function(workspace)
{
setOrder : function(order) {
this._order = order;
},
setPosition : function(x, y) {
this._position.setValue(x, y);
// Elements are positioned in the center.
// All topic element must be positioned based on the innerShape.
var draggedNode = this._draggedNode;
var size = draggedNode.getSize();
var cx = Math.ceil(x - (size.width / 2));
var cy = Math.ceil(y - (size.height / 2));
// Update visual position.
this._elem2d.setPosition(cx, cy);
},
getInnerShape : function() {
return this._elem2d;
},
disconnect : function(workspace) {
// Clear connection line ...
var dragPivot = this._getDragPivot();
dragPivot.disconnect(workspace);
},
canBeConnectedTo : function(targetTopic) {
$assert(targetTopic, 'parent can not be null');
var result = true;
if (!targetTopic.areChildrenShrinked() && !targetTopic.isCollapsed()) {
// Dragged node can not be connected to himself.
if (targetTopic == this._draggedNode) {
result = false;
} else {
var draggedNode = this.getDraggedTopic();
var topicPosition = this.getPosition();
var targetTopicModel = targetTopic.getModel();
var childTopicModel = draggedNode.getModel();
result = targetTopicModel.canBeConnected(childTopicModel, topicPosition, 18);
}
} else {
result = false;
}
return result;
},
connectTo : function(parent) {
$assert(parent, 'Parent connection node can not be null.');
var dragPivot = this._getDragPivot();
dragPivot.connectTo(parent);
},
getDraggedTopic : function() {
return this._draggedNode;
},
removeFromWorkspace : function(workspace) {
// Remove drag shadow.
workspace.removeChild(this._elem2d);
// Remove pivot shape. To improve performace it will not be removed. Only the visilility will be changed.
var dragPivot = this._getDragPivot();
dragPivot.setVisibility(false);
},
addToWorkspace : function(workspace) {
workspace.appendChild(this._elem2d);
var dragPivot = this._getDragPivot();
dragPivot.addToWorkspace(workspace);
dragPivot.setVisibility(true);
},
_getDragPivot : function() {
return mindplot.DragTopic.__getDragPivot();
},
getPosition:function() {
return this._position;
}
,
isDragTopic : function() {
return true;
},
updateDraggedTopic : function(workspace) {
$assert(workspace, 'workspace can not be null');
var dragPivot = this._getDragPivot();
var draggedTopic = this.getDraggedTopic();
var isDragConnected = this.isConnected();
// @Todo: Remove this static ...
var actionDispatcher = mindplot.ActionDispatcher.getInstance();
var topicId = draggedTopic.getId();
if (isDragConnected) {
var targetTopic = this.getConnectedToTopic();
if (targetTopic.getType() == mindplot.NodeModel.CENTRAL_TOPIC_TYPE) {
// Update topic position ...
var dragPivotPosition = dragPivot.getPosition();
// Must position the dragged topic taking into account the current node size.
var pivotSize = dragPivot.getSize();
var draggedTopicSize = draggedTopic.getSize();
var xOffset = draggedTopicSize.width - pivotSize.width;
xOffset = Math.round(xOffset / 2);
if (dragPivotPosition.x > 0) {
dragPivotPosition.x = parseInt(dragPivotPosition.x) + xOffset;
}
else {
dragPivotPosition.x = parseInt(dragPivotPosition.x) - xOffset;
}
// Set new position ...
actionDispatcher.dragTopic(topicId, dragPivotPosition, null, targetTopic);
} else {
// Main topic connections can be positioned only with the order ...
actionDispatcher.dragTopic(topicId, null, this._order, targetTopic);
}
} else {
// If the node is not connected, positionate based on the original drag topic position.
var dragPosition = this.getPosition();
actionDispatcher.dragTopic(topicId, dragPosition);
}
},
setBoardPosition : function(point) {
$assert(point, 'point can not be null');
var dragPivot = this._getDragPivot();
dragPivot.setPosition(point);
},
getConnectedToTopic : function() {
var dragPivot = this._getDragPivot();
return dragPivot.getTargetTopic();
},
isConnected : function() {
return this.getConnectedToTopic() != null;
}
});
mindplot.DragTopic.PIVOT_SIZE = {width:50,height:10};
mindplot.DragTopic.init = function(workspace) {
$assert(workspace, "workspace can not be null");
var pivot = mindplot.DragTopic.__getDragPivot();
workspace.appendChild(pivot);
};
}
mindplot.DragTopic.prototype.setOrder = function(order)
{
this._order = order;
};
mindplot.DragTopic.prototype.setPosition = function(x, y)
{
this._position.setValue(x, y);
// Elements are positioned in the center.
// All topic element must be positioned based on the innerShape.
var draggedNode = this._draggedNode;
var size = draggedNode.getSize();
var cx = Math.ceil(x - (size.width / 2));
var cy = Math.ceil(y - (size.height / 2));
// Update visual position.
this._elem2d.setPosition(cx, cy);
};
mindplot.DragTopic.prototype.getInnerShape = function()
{
return this._elem2d;
};
mindplot.DragTopic.prototype.disconnect = function(workspace)
{
// Clear connection line ...
var dragPivot = this._getDragPivot();
dragPivot.disconnect(workspace);
};
mindplot.DragTopic.prototype.canBeConnectedTo = function(targetTopic)
{
$assert(targetTopic, 'parent can not be null');
var result = true;
if (!targetTopic.areChildrenShrinked() && !targetTopic.isCollapsed())
{
// Dragged node can not be connected to himself.
if (targetTopic == this._draggedNode)
{
result = false;
} else
{
var draggedNode = this.getDraggedTopic();
var topicPosition = this.getPosition();
var targetTopicModel = targetTopic.getModel();
var childTopicModel = draggedNode.getModel();
result = targetTopicModel.canBeConnected(childTopicModel, topicPosition, 18);
}
} else
{
result = false;
}
return result;
};
mindplot.DragTopic.prototype.connectTo = function(parent)
{
$assert(parent, 'Parent connection node can not be null.');
var dragPivot = this._getDragPivot();
dragPivot.connectTo(parent);
};
mindplot.DragTopic.prototype.getDraggedTopic = function()
{
return this._draggedNode;
};
mindplot.DragTopic.prototype.removeFromWorkspace = function(workspace)
{
// Remove drag shadow.
workspace.removeChild(this._elem2d);
// Remove pivot shape. To improve performace it will not be removed. Only the visilility will be changed.
var dragPivot = this._getDragPivot();
dragPivot.setVisibility(false);
};
mindplot.DragTopic.prototype.addToWorkspace = function(workspace)
{
workspace.appendChild(this._elem2d);
var dragPivot = this._getDragPivot();
dragPivot.addToWorkspace(workspace);
dragPivot.setVisibility(true);
};
mindplot.DragTopic.prototype._getDragPivot = function()
{
return mindplot.DragTopic.__getDragPivot();
};
mindplot.DragTopic.__getDragPivot = function()
{
mindplot.DragTopic.__getDragPivot = function() {
var result = mindplot.DragTopic._dragPivot;
if (!$defined(result))
{
if (!$defined(result)) {
result = new mindplot.DragPivot();
mindplot.DragTopic._dragPivot = result;
}
return result;
};
}
mindplot.DragTopic.prototype.getPosition = function()
{
return this._position;
};
mindplot.DragTopic.prototype.isDragTopic = function()
{
return true;
};
mindplot.DragTopic.prototype.updateDraggedTopic = function(workspace)
{
$assert(workspace, 'workspace can not be null');
var dragPivot = this._getDragPivot();
var draggedTopic = this.getDraggedTopic();
var isDragConnected = this.isConnected();
var actionRunner = mindplot.DesignerActionRunner.getInstance();
var topicId = draggedTopic.getId();
var command = new mindplot.commands.DragTopicCommand(topicId);
if (isDragConnected)
{
var targetTopic = this.getConnectedToTopic();
if (targetTopic.getType() == mindplot.NodeModel.CENTRAL_TOPIC_TYPE)
{
// Update topic position ...
var dragPivotPosition = dragPivot.getPosition();
// Must position the dragged topic taking into account the current node size.
var pivotSize = dragPivot.getSize();
var draggedTopicSize = draggedTopic.getSize();
var xOffset = draggedTopicSize.width - pivotSize.width;
xOffset = Math.round(xOffset / 2);
if (dragPivotPosition.x > 0)
{
dragPivotPosition.x = parseInt(dragPivotPosition.x) + xOffset;
}
else
{
dragPivotPosition.x = parseInt(dragPivotPosition.x) - xOffset;
}
// Set new position ...
command.setPosition(dragPivotPosition);
} else
{
// Main topic connections can be positioned only with the order ...
command.setOrder(this._order);
}
// Set new parent topic ..
command.setParetTopic(targetTopic);
} else {
// If the node is not connected, positionate based on the original drag topic position.
var dragPosition = this.getPosition();
command = new mindplot.commands.DragTopicCommand(topicId, dragPosition);
command.setPosition(dragPosition);
}
actionRunner.execute(command);
};
mindplot.DragTopic.prototype.setBoardPosition = function(point)
{
$assert(point, 'point can not be null');
var dragPivot = this._getDragPivot();
dragPivot.setPosition(point);
};
mindplot.DragTopic.prototype.getBoardPosition = function(point)
{
$assert(point, 'point can not be null');
var dragPivot = this._getDragPivot();
return dragPivot.getPosition();
};
mindplot.DragTopic.prototype.getConnectedToTopic = function()
{
var dragPivot = this._getDragPivot();
return dragPivot.getTargetTopic();
};
mindplot.DragTopic.prototype.isConnected = function()
{
return this.getConnectedToTopic() != null;
};
mindplot.DragTopic.PIVOT_SIZE = {width:50,height:10};

View File

@ -16,8 +16,7 @@
* limitations under the License.
*/
mindplot.ImageIcon = new Class(
{
mindplot.ImageIcon = new Class({
Extends:mindplot.Icon,
initialize:function(iconModel, topic, designer) {
$assert(iconModel, 'iconModel can not be null');
@ -44,16 +43,15 @@ mindplot.ImageIcon = new Class(
if (!$defined(designer._viewMode) || ($defined(designer._viewMode) && !designer._viewMode)) {
removeImage.addEvent('click', function(event) {
var actionRunner = designer._actionRunner;
var command = new mindplot.commands.RemoveIconFromTopicCommand(this._topic.getId(), iconModel);
actionRunner.execute(command);
removeImage.addEvent('click', function() {
var actionDispatcher = mindplot.ActionDispatcher.getInstance();
actionDispatcher.removeIconFromTopic(this._topic.getId(), iconModel);
tip.forceClose();
}.bindWithEvent(this));
//Icon
var image = this.getImage();
image.addEventListener('click', function(event) {
image.addEventListener('click', function() {
var iconType = iconModel.getIconType();
var newIconType = this._getNextFamilyIconId(iconType);
iconModel.setIconType(newIconType);
@ -83,7 +81,7 @@ mindplot.ImageIcon = new Class(
}
},
_getImageUrl : function(iconId) {
_getImageUrl : function(iconId) {
return "../icons/" + iconId + ".png";
},
@ -99,7 +97,6 @@ mindplot.ImageIcon = new Class(
var result = null;
for (var i = 0; i < familyIcons.length && result == null; i++) {
if (familyIcons[i] == iconId) {
var nextIconId;
//Is last one?
if (i == (familyIcons.length - 1)) {
result = familyIcons[0];
@ -164,7 +161,7 @@ mindplot.ImageIcon.prototype.ICON_FAMILIES = [
{"id": "bullet", "icons" : ["bullet_black","bullet_blue","bullet_green","bullet_orange","bullet_red","bullet_pink","bullet_purple"]},
{"id": "tag", "icons" : ["tag_blue","tag_green","tag_orange","tag_red","tag_pink","tag_yellow"]},
{"id": "object", "icons" : ["object_bell","object_clanbomber","object_key","object_pencil","object_phone","object_magnifier","object_clip","object_music","object_star","object_wizard","object_house","object_cake","object_camera","object_palette","object_rainbow"]}
]
];

View File

@ -90,8 +90,9 @@ mindplot.LinkIcon = new Class({
removeBtn.setStyle("margin-left", "3px");
removeBtn.addEvent('click', function(event) {
var command = new mindplot.commands.RemoveLinkFromTopicCommand(this._topic.getId());
designer._actionRunner.execute(command);
var actionDispatcher = mindplot.ActionDispatcher.getInstance();
actionDispatcher.removeLinkFromTopic(this._topic.getId());
bubbleTip.forceClose();
}.bindWithEvent(this));
@ -148,7 +149,7 @@ mindplot.LinkIcon = new Class({
});
},
getUrl : function() {
getUrl : function() {
return this._url;
},

View File

@ -0,0 +1,209 @@
/*
* 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.LocalActionDispatcher = new Class({
Extends: mindplot.ActionDispatcher,
initialize: function(designer) {
$assert(designer, "designer can not be null");
this._actionRunner = new mindplot.DesignerActionRunner(designer);
},
addIconToTopic: function(topicId, iconType) {
var command = new mindplot.commands.AddIconToTopicCommand(topicId, iconType);
this.execute(command);
},
addLinkToTopic: function(topicId, url) {
var command = new mindplot.commands.AddLinkToTopicCommand(topicId, url);
this.execute(command);
},
addTopic:function(model, parentTopicId, animated) {
var command = new mindplot.commands.AddTopicCommand(model, parentTopicId, animated);
this.execute(command);
},
addNoteToTopic: function(topicId, text) {
var command = new mindplot.commands.AddNoteToTopicCommand(topicId, text);
this.execute(command);
},
addRelationship: function(model, mindmap) {
var command = new mindplot.commands.AddRelationshipCommand(model, mindmap);
this.execute(command);
},
deleteTopics: function(topicsIds) {
var command = new mindplot.commands.DeleteTopicCommand(topicsIds);
this.execute(command);
},
dragTopic: function(topicId, position, order, parentTopic) {
var command = new mindplot.commands.DragTopicCommand(topicId, position, order, parentTopic);
this.execute(command);
},
moveControlPoint: function(ctrlPoint, point) {
var command = new mindplot.commands.MoveControlPointCommand(ctrlPoint, point);
this.execute(command);
},
removeIconFromTopic: function(topicId, iconModel) {
var command = new mindplot.commands.RemoveIconFromTopicCommand(topicId, iconModel);
this.execute(command);
},
removeLinkFromTopic: function(topicId) {
var command = new mindplot.commands.RemoveLinkFromTopicCommand(topicId);
this.execute(command);
},
removeNoteFromTopic: function(topicId) {
var command = new mindplot.commands.RemoveNoteFromTopicCommand(topicId);
this.execute(command);
},
changeFontStyleToTopic: function(topicsIds) {
var commandFunc = function(topic) {
var result = topic.getFontStyle();
var style = (result == "italic") ? "normal" : "italic";
topic.setFontStyle(style, true);
return result;
};
var command = new mindplot.commands.GenericFunctionCommand(commandFunc, topicsIds);
this._actionRunner.execute(command);
},
changeFontFamilyToTopic: function(topicIds, fontFamily) {
$assert(topicIds, "topicIds can not be null");
$assert(fontFamily, "fontFamily can not be null");
var commandFunc = function(topic, fontFamily) {
var result = topic.getFontFamily();
topic.setFontFamily(fontFamily, true);
core.Executor.instance.delay(topic.updateNode, 0, topic);
return result;
};
var command = new mindplot.commands.GenericFunctionCommand(commandFunc, topicIds, fontFamily);
this.execute(command);
},
changeFontColorToTopic: function(topicsIds, color) {
$assert(topicsIds, "topicIds can not be null");
$assert(color, "color can not be null");
var commandFunc = function(topic, color) {
var result = topic.getFontColor();
topic.setFontColor(color, true);
return result;
};
var command = new mindplot.commands.GenericFunctionCommand(commandFunc, topicsIds, color);
command.discartDuplicated = "fontColorCommandId";
this.execute(command);
},
changeBackgroundColorToTopic: function(topicsIds, color) {
$assert(topicsIds, "topicIds can not be null");
$assert(color, "color can not be null");
var commandFunc = function(topic, color) {
var result = topic.getBackgroundColor();
topic.setBackgroundColor(color);
return result;
};
var command = new mindplot.commands.GenericFunctionCommand(commandFunc, topicsIds, color);
command.discartDuplicated = "backColor";
this.execute(command);
},
changeBorderColorToTopic : function(topicsIds, color) {
$assert(topicsIds, "topicIds can not be null");
$assert(color, "topicIds can not be null");
var commandFunc = function(topic, color) {
var result = topic.getBorderColor();
topic.setBorderColor(color);
return result;
};
var command = new mindplot.commands.GenericFunctionCommand(commandFunc, topicsIds, color);
command.discartDuplicated = "borderColorCommandId";
this.execute(command);
},
changeFontSizeToTopic : function(topicsIds, size) {
$assert(topicsIds, "topicIds can not be null");
$assert(size, "size can not be null");
var commandFunc = function(topic, size) {
var result = topic.getFontSize();
topic.setFontSize(size, true);
core.Executor.instance.delay(topic.updateNode, 0, topic);
return result;
};
var command = new mindplot.commands.GenericFunctionCommand(commandFunc, topicsIds, size);
this.execute(command);
},
changeShapeToTopic : function(topicsIds, shapeType) {
$assert(topicsIds, "topicsIds can not be null");
$assert(shapeType, "shapeType can not be null");
var commandFunc = function(topic, shapeType) {
var result = topic.getShapeType();
topic.setShapeType(shapeType, true);
return result;
};
var command = new mindplot.commands.GenericFunctionCommand(commandFunc, topicsIds, shapeType);
this.execute(command);
},
changeFontWeightToTopic : function(topicsIds) {
$assert(topicsIds, "topicsIds can not be null");
var commandFunc = function(topic) {
var result = topic.getFontWeight();
var weight = (result == "bold") ? "normal" : "bold";
topic.setFontWeight(weight, true);
core.Executor.instance.delay(topic.updateNode, 0, topic);
/*var updated = function() {
topic.updateNode();
};
updated.delay(0);*/
return result;
};
var command = new mindplot.commands.GenericFunctionCommand(commandFunc, topicsIds);
this.execute(command);
},
execute:function(command) {
this._actionRunner.execute(command);
}
});

View File

@ -1,72 +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.BaseCommandDispatcher = new Class({
initialize: function() {
},
addIconToTopic: function(topicId, iconType) {
throw "method must be implemented.";
},
addLinkToTopic: function(topicId, url) {
throw "method must be implemented.";
},
addNoteToTopic: function(topicId, text) {
throw "method must be implemented.";
},
addRelationship: function(model, mindmap) {
throw "method must be implemented.";
},
addTopic: function(model, parentTopicId, animated) {
throw "method must be implemented.";
},
changeIcon: function(topicId, iconId, iconType) {
throw "method must be implemented.";
},
deleteTopic: function(topicsIds) {
throw "method must be implemented.";
},
dragTopic: function(topicId) {
throw "method must be implemented.";
},
moveControlPoint: function(trlPointController, point) {
throw "method must be implemented.";
},
removeIconFromTopic: function(topicId, iconModel) {
throw "method must be implemented.";
},
removeLinkFromTopic: function(topicId) {
throw "method must be implemented.";
},
removeNodeFromTopic: function(topicId) {
throw "method must be implemented.";
}
});

View File

@ -22,9 +22,11 @@ mindplot.MindmapDesigner = new Class({
$assert(profile.zoom, "zoom must be defined");
$assert(divElement, "divElement must be defined");
// Undo manager ...
this._actionRunner = new mindplot.DesignerActionRunner(this);
mindplot.DesignerActionRunner.setInstance(this._actionRunner);
// Dispatcher manager ...
// @Todo: Remove this static. Sucks...
this._actionDispatcher = new mindplot.LocalActionDispatcher(this);
mindplot.ActionDispatcher.setInstance(this._actionDispatcher);
// Initial Zoom
this._zoom = profile.zoom;
@ -39,21 +41,14 @@ mindplot.MindmapDesigner = new Class({
var editorClass = mindplot.TextEditorFactory.getTextEditorFromName(mindplot.EditorOptions.textEditor);
this._editor = new editorClass(this, this._actionRunner);
// Init layout managers ...
this._topics = [];
// var layoutManagerClass = mindplot.layout.LayoutManagerFactory.getManagerByName(mindplot.EditorOptions.LayoutManager);
// this._layoutManager = new layoutManagerClass(this);
this._layoutManager = new mindplot.layout.OriginalLayoutManager(this);
// Register handlers..
this._registerEvents();
this._relationships = {};
this._events = {};
// Action !
},
_getTopics : function() {
@ -112,8 +107,7 @@ mindplot.MindmapDesigner = new Class({
var centralTopicId = centralTopic.getId();
// Execute action ...
var command = new mindplot.commands.AddTopicCommand(model, centralTopicId, true);
this._actionRunner.execute(command);
this._actionDispatcher.addTopic(model, centralTopicId, true);
}
}.bind(this));
}
@ -216,8 +210,9 @@ mindplot.MindmapDesigner = new Class({
var parentTopicId = centalTopic.getId();
var childModel = centalTopic.createChildModel(this._layoutManager.needsPrepositioning());
var command = new mindplot.commands.AddTopicCommand(childModel, parentTopicId, true);
this._actionRunner.execute(command);
// Execute event ...
this._actionDispatcher.addTopic(childModel, parentTopicId, true);
},
createSiblingForSelectedNode : function() {
@ -243,9 +238,8 @@ mindplot.MindmapDesigner = new Class({
var parentTopic = topic.getOutgoingConnectedTopic();
var siblingModel = topic.createSiblingModel(this._layoutManager.needsPrepositioning());
var parentTopicId = parentTopic.getId();
var command = new mindplot.commands.AddTopicCommand(siblingModel, parentTopicId, true);
this._actionRunner.execute(command);
this._actionDispatcher.addTopic(siblingModel, parentTopicId, true);
}
},
@ -305,8 +299,8 @@ mindplot.MindmapDesigner = new Class({
var mindmap = this.getMindmap();
var model = mindmap.createRelationship(fromNode.getModel().getId(), toNode.getModel().getId());
var command = new mindplot.commands.AddRelationshipCommand(model, mindmap);
this._actionRunner.execute(command);
this._actionDispatcher.addRelationship(model, mindmap);
},
needsSave : function() {
@ -558,8 +552,7 @@ mindplot.MindmapDesigner = new Class({
var validateError = 'Central topic can not be deleted.';
var selectedObjects = this._getValidSelectedObjectsIds(validateFunc, validateError);
if (selectedObjects.nodes.length > 0 || selectedObjects.relationshipLines.length > 0) {
var command = new mindplot.commands.DeleteTopicCommand(selectedObjects);
this._actionRunner.execute(command);
this._actionDispatcher.deleteTopics(selectedObjects);
}
},
@ -568,19 +561,8 @@ mindplot.MindmapDesigner = new Class({
var validSelectedObjects = this._getValidSelectedObjectsIds();
var topicsIds = validSelectedObjects.nodes;
if (topicsIds.length > 0) {
var commandFunc = function(topic, font) {
var result = topic.getFontFamily();
topic.setFontFamily(font, true);
this._actionDispatcher.changeFontFamilyToTopic(topicsIds, font);
core.Executor.instance.delay(topic.updateNode, 0, topic);
/*var updated = function() {
topic.updateNode();
};
updated.delay(0);*/
return result;
}
var command = new mindplot.commands.GenericFunctionCommand(commandFunc, font, topicsIds);
this._actionRunner.execute(command);
}
},
@ -588,14 +570,7 @@ mindplot.MindmapDesigner = new Class({
var validSelectedObjects = this._getValidSelectedObjectsIds();
var topicsIds = validSelectedObjects.nodes;
if (topicsIds.length > 0) {
var commandFunc = function(topic) {
var result = topic.getFontStyle();
var style = (result == "italic") ? "normal" : "italic";
topic.setFontStyle(style, true);
return result;
}
var command = new mindplot.commands.GenericFunctionCommand(commandFunc, "", topicsIds);
this._actionRunner.execute(command);
this._actionDispatcher.changeFontStyleToTopic(topicsIds);
}
},
@ -603,14 +578,7 @@ mindplot.MindmapDesigner = new Class({
var validSelectedObjects = this._getValidSelectedObjectsIds();
var topicsIds = validSelectedObjects.nodes;
if (topicsIds.length > 0) {
var commandFunc = function(topic, color) {
var result = topic.getFontColor();
topic.setFontColor(color, true);
return result;
}
var command = new mindplot.commands.GenericFunctionCommand(commandFunc, color, topicsIds);
command.discartDuplicated = "fontColorCommandId";
this._actionRunner.execute(command);
this._actionDispatcher.changeFontColorToTopic(topicsIds, color);
}
},
@ -619,20 +587,11 @@ mindplot.MindmapDesigner = new Class({
var validateFunc = function(topic) {
return topic.getShapeType() != mindplot.NodeModel.SHAPE_TYPE_LINE
};
var validateError = 'Color can not be setted to line topics.';
var validateError = 'Color can not be set to line topics.';
var validSelectedObjects = this._getValidSelectedObjectsIds(validateFunc, validateError);
;
var topicsIds = validSelectedObjects.nodes;
if (topicsIds.length > 0) {
var commandFunc = function(topic, color) {
var result = topic.getBackgroundColor();
topic.setBackgroundColor(color);
return result;
}
var command = new mindplot.commands.GenericFunctionCommand(commandFunc, color, topicsIds);
command.discartDuplicated = "backColor";
this._actionRunner.execute(command);
this._actionDispatcher.changeBackgroundColorToTopic(topicsIds, color);
}
},
@ -679,20 +638,12 @@ mindplot.MindmapDesigner = new Class({
var validateFunc = function(topic) {
return topic.getShapeType() != mindplot.NodeModel.SHAPE_TYPE_LINE
};
var validateError = 'Color can not be setted to line topics.';
var validateError = 'Color can not be set to line topics.';
var validSelectedObjects = this._getValidSelectedObjectsIds(validateFunc, validateError);
;
var topicsIds = validSelectedObjects.nodes;
if (topicsIds.length > 0) {
var commandFunc = function(topic, color) {
var result = topic.getBorderColor();
topic.setBorderColor(color);
return result;
}
var command = new mindplot.commands.GenericFunctionCommand(commandFunc, color, topicsIds);
command.discartDuplicated = "borderColorCommandId";
this._actionRunner.execute(command);
this._actionDispatcher.changeBorderColorToTopic(topicsIds, color);
}
},
@ -700,19 +651,7 @@ mindplot.MindmapDesigner = new Class({
var validSelectedObjects = this._getValidSelectedObjectsIds();
var topicsIds = validSelectedObjects.nodes;
if (topicsIds.length > 0) {
var commandFunc = function(topic, size) {
var result = topic.getFontSize();
topic.setFontSize(size, true);
core.Executor.instance.delay(topic.updateNode, 0, topic);
/*var updated = function() {
topic.updateNode();
};
updated.delay(0);*/
return result;
}
var command = new mindplot.commands.GenericFunctionCommand(commandFunc, size, topicsIds);
this._actionRunner.execute(command);
this._actionDispatcher.changeFontSizeToTopic(topicsIds, size);
}
},
@ -725,13 +664,7 @@ mindplot.MindmapDesigner = new Class({
var topicsIds = validSelectedObjects.nodes;
if (topicsIds.length > 0) {
var commandFunc = function(topic, size) {
var result = topic.getShapeType();
topic.setShapeType(size, true);
return result;
}
var command = new mindplot.commands.GenericFunctionCommand(commandFunc, shape, topicsIds);
this._actionRunner.execute(command);
this._actionDispatcher.changeShapeToTopic(topicsIds, shape);
}
},
@ -740,20 +673,7 @@ mindplot.MindmapDesigner = new Class({
var validSelectedObjects = this._getValidSelectedObjectsIds();
var topicsIds = validSelectedObjects.nodes;
if (topicsIds.length > 0) {
var commandFunc = function(topic) {
var result = topic.getFontWeight();
var weight = (result == "bold") ? "normal" : "bold";
topic.setFontWeight(weight, true);
core.Executor.instance.delay(topic.updateNode, 0, topic);
/*var updated = function() {
topic.updateNode();
};
updated.delay(0);*/
return result;
}
var command = new mindplot.commands.GenericFunctionCommand(commandFunc, "", topicsIds);
this._actionRunner.execute(command);
this._actionDispatcher.changeFontWeightToTopic(topicsIds);
}
},
@ -761,9 +681,7 @@ mindplot.MindmapDesigner = new Class({
var validSelectedObjects = this._getValidSelectedObjectsIds();
var topicsIds = validSelectedObjects.nodes;
if (topicsIds.length > 0) {
var command = new mindplot.commands.AddIconToTopicCommand(topicsIds[0], iconType);
this._actionRunner.execute(command);
this._actionDispatcher.addIconToTopic(topicsIds[0], iconType);
}
},
@ -771,8 +689,7 @@ mindplot.MindmapDesigner = new Class({
var validSelectedObjects = this._getValidSelectedObjectsIds();
var topicsIds = validSelectedObjects.nodes;
if (topicsIds.length > 0) {
var command = new mindplot.commands.AddLinkToTopicCommand(topicsIds[0], url);
this._actionRunner.execute(command);
this._actionDispatcher.addLinkToTopic(topicsIds[0], url);
}
},
@ -784,11 +701,11 @@ mindplot.MindmapDesigner = new Class({
if (!$defined(topic._hasLink)) {
var msg = new Element('div');
var urlText = new Element('div').inject(msg);
urlText.innerHTML = "URL:"
urlText.innerHTML = "URL:";
var formElem = new Element('form', {'action': 'none', 'id':'linkFormId'});
var urlInput = new Element('input', {'type': 'text', 'size':30});
urlInput.inject(formElem);
formElem.inject(msg)
formElem.inject(msg);
var okButtonId = "linkOkButtonId";
formElem.addEvent('submit', function(e) {
@ -824,8 +741,7 @@ mindplot.MindmapDesigner = new Class({
var validSelectedObjects = this._getValidSelectedObjectsIds();
var topicsIds = validSelectedObjects.nodes;
if (topicsIds.length > 0) {
var command = new mindplot.commands.AddNoteToTopicCommand(topicsIds[0], text);
this._actionRunner.execute(command);
this._actionDispatcher.addNoteToTopic(topicsIds[0], text);
}
},

View File

@ -50,8 +50,9 @@ mindplot.Note = new Class({
removeBtn.setStyle("margin-left", "3px");
removeBtn.addEvent('click', function(event) {
var command = new mindplot.commands.RemoveNoteFromTopicCommand(this._topic.getId());
designer._actionRunner.execute(command);
var actionDispatcher = mindplot.ActionDispatcher.getInstance();
actionDispatcher.removeNoteFromTopic(this._topic.getId());
bubbleTip.forceClose();
}.bindWithEvent(this));

View File

@ -1,53 +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.SingleCommandDispatcher = new Class(
{
Extends:mindplot.BaseCommandDispatcher,
initialize: function() {
},
addIconToTopic: function() {
throw "method must be implemented.";
},
addLinkToTopic: function() {
throw "method must be implemented.";
},
addNoteToTopic: function() {
throw "method must be implemented.";
},addRelationship: function() {
throw "method must be implemented.";
},addTopic: function() {
throw "method must be implemented.";
},changeIcon: function() {
throw "method must be implemented.";
},deleteTopic: function() {
throw "method must be implemented.";
},dragTopic: function() {
throw "method must be implemented.";
},moveControllPoint: function() {
throw "method must be implemented.";
} ,removeIconFromTopic: function() {
throw "method must be implemented.";
},removeLinkFromTopic: function() {
throw "method must be implemented.";
},removeNodeFromTopic: function() {
throw "method must be implemented.";
}
});

View File

@ -17,11 +17,10 @@
*/
mindplot.TextEditor = new Class({
initialize:function(designer, actionRunner) {
initialize:function(designer) {
this._designer = designer;
this._screenManager = designer.getWorkSpace().getScreenManager();
this._container = this._screenManager.getContainer();
this._actionRunner = actionRunner;
this._isVisible = false;
//Create editor ui

View File

@ -26,10 +26,11 @@ mindplot.commands.AddTopicCommand = new Class(
this._id = mindplot.Command._nextUUID();
this._animated = $defined(animated) ? animated : false;
},
execute: function(commandContext) {
// Add a new topic ...
var topic = commandContext.createTopic(this._model, !this._animated);
execute: function(commandContext) {
// Add a new topic ...
var topic = commandContext.createTopic(this._model, !this._animated);
// Connect to topic ...
if ($defined(this._parentId)) {
@ -49,6 +50,7 @@ mindplot.commands.AddTopicCommand = new Class(
} else
doneFn.attempt();
},
undoExecute: function(commandContext) {
// Finally, delete the topic from the workspace ...
var topicId = this._model.getId();

View File

@ -1,45 +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.ChangeIconFromTopicCommand = new Class({
Extends:mindplot.Command,
initialize: function(topicId, iconId, iconType) {
$assert(topicId, 'topicId can not be null');
$assert(iconId, 'iconId can not be null');
$assert(iconType, 'iconType can not be null');
this._selectedObjectsIds = topicId;
this._iconModel = iconId;
this._iconType = iconType;
},
execute: function(commandContext) {
var topic = commandContext.findTopics(this._selectedObjectsIds)[0];
var updated = function() {
topic.removeIcon(this._iconModel);
topic.updateNode();
}.bind(this);
updated.delay(0);
},
undoExecute: function(commandContext) {
var topic = commandContext.findTopics(this._selectedObjectsIds)[0];
var updated = function() {
topic.addIcon(this._iconModel, commandContext._designer);
topic.updateNode();
}.bind(this);
updated.delay(0);
}
});

View File

@ -18,12 +18,15 @@
mindplot.commands.DragTopicCommand = new Class({
Extends:mindplot.Command,
initialize: function(topicId) {
$assert(topicId, "topicId must be defined");
this._selectedObjectsIds = topicId;
this._parentTopic = null;
this._position = null;
this._order = null;
initialize: function(topicIds, position, order, parentTopic) {
$assert(topicIds, "topicIds must be defined");
this._selectedObjectsIds = topicIds;
if ($defined(parentTopic))
this._parentId = parentTopic.getId();
this._position = position;
this._order = order;
this._id = mindplot.Command._nextUUID();
},
execute: function(commandContext) {
@ -78,19 +81,9 @@ mindplot.commands.DragTopicCommand = new Class({
undoExecute: function(commandContext) {
this.execute(commandContext);
var selectedRelationships = commandContext.getSelectedRelationshipLines();
selectedRelationships.forEach(function(relationshipLine, index) {
selectedRelationships.forEach(function(relationshipLine) {
relationshipLine.redraw();
});
},
setPosition: function(point) {
this._position = point;
},
setParetTopic: function(topic) {
this._parentId = topic.getId();
},
setOrder: function(order) {
this._order = order
}
});

View File

@ -18,9 +18,10 @@
mindplot.commands.GenericFunctionCommand = new Class({
Extends:mindplot.Command,
initialize: function(commandFunc, value, topicsIds) {
initialize: function(commandFunc, topicsIds,value) {
$assert(commandFunc, "commandFunc must be defined");
$assert(topicsIds, "topicsIds must be defined");
this._value = value;
this._selectedObjectsIds = topicsIds;
this._commandFunc = commandFunc;

View File

@ -19,9 +19,10 @@ mindplot.commands.MoveControlPointCommand = new Class({
Extends:mindplot.Command,
initialize: function(ctrlPointController, point) {
$assert(ctrlPointController, 'line can not be null');
$assert(point, 'point can not be null');
this._ctrlPointControler = ctrlPointController;
this._line = ctrlPointController._line;
var model = this._line.getModel();
this._controlPoint = this._ctrlPointControler.getControlPoint(point).clone();
this._oldControlPoint = this._ctrlPointControler.getOriginalCtrlPoint(point).clone();
this._originalEndPoint = this._ctrlPointControler.getOriginalEndPoint(point).clone();

View File

@ -24,12 +24,13 @@ mindplot.layout.OriginalLayoutManager = new Class({
initialize:function(designer, options) {
this.parent(designer, options);
this._dragTopicPositioner = new mindplot.DragTopicPositioner(this);
// Init dragger manager.
// Init drag manager.
var workSpace = this.getDesigner().getWorkSpace();
this._dragger = this._buildDragManager(workSpace);
// Add shapes to speed up the loading process ...
mindplot.DragTopic.initialize(workSpace);
mindplot.DragTopic.init(workSpace);
},
prepareNode:function(node, children) {
// Sort children by order to solve adding order in for OriginalLayoutManager...