Refactor designer moving methods to a designer model.

This commit is contained in:
Paulo Veiga 2011-08-24 23:41:39 -03:00
parent f01a01b72d
commit 046789bb6a
21 changed files with 276 additions and 229 deletions

View File

@ -297,7 +297,7 @@ core.Utils.animatePosition = function (elems, doneFn, designer) {
for (var j = 0; j < keys.length; j++) {
var id = keys[j];
var mod = elems.get(id);
var allTopics = designer._getTopics();
var allTopics = designer.getModel().getTopics();
var currentTopic = allTopics.filter(function(node) {
return node.getId() == id;
})[0];
@ -314,7 +314,7 @@ core.Utils.animatePosition = function (elems, doneFn, designer) {
for (var j = 0; j < keys.length; j++) {
var id = keys[j];
var mod = elems.get(id);
var allTopics = designer._getTopics();
var allTopics = designer.getModel().getTopics();
var currentTopic = allTopics.filter(function(node) {
return node.getId() == id;
})[0];

View File

@ -58,6 +58,7 @@
<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="DesignerModel.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"/>
@ -113,7 +114,7 @@
<filelist dir="${basedir}/src/main/javascript/"
files="commands/GenericFunctionCommand.js"/>
<filelist dir="${basedir}/src/main/javascript/"
files="commands/DeleteTopicCommand.js"/>
files="commands/DeleteCommand.js"/>
<filelist dir="${basedir}/src/main/javascript/"
files="commands/DragTopicCommand.js"/>
<filelist dir="${basedir}/src/main/javascript/"

View File

@ -221,7 +221,7 @@ mindplot.DesignerKeyboard = new Class({
// If it's not registered, let's
if (!isRegistered && !excludes.contains(key) && !modifiers.contains(key) && !key.contains('meta') && !key.contains('ctrl') && !key.contains('control')) {
var nodes = designer.getSelectedNodes();
var nodes = designer.getModel().filterSelectedTopics();
if (nodes.length > 0) {
nodes[0].showTextEditor(event.key);
event.stopPropagation();
@ -324,7 +324,7 @@ mindplot.DesignerKeyboard = new Class({
},
_getSelectedNode : function(designer) {
var nodes = designer.getSelectedNodes();
var nodes = designer.filterSelectedTopics();
return (nodes.length > 0) ? nodes[0] : null;
}
});

View File

@ -0,0 +1,136 @@
/*
* 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.DesignerModel = new Class({
initialize : function(options) {
this._zoom = options.zoom;
this._topics = [];
this._relationships = {};
},
getZoom : function() {
return this._zoom;
},
setZoom : function(zoom) {
this._zoom = zoom;
},
getTopics : function() {
return this._topics;
},
getCentralTopic : function() {
var topics = this.getTopics();
return topics[0];
},
filterSelectedTopics : function() {
var result = [];
for (var i = 0; i < this._topics.length; i++) {
if (this._topics[i].isOnFocus()) {
result.push(this._topics[i]);
}
}
return result;
},
filterSelectedRelations : function() {
var result = [];
for (var id in this._relationships) {
var relationship = this._relationships[id];
if (relationship.isOnFocus()) {
result.push(relationship);
}
}
return result;
},
getObjects : function() {
var result = [].append(this._topics);
for (var id in this._relationships) {
result.push(this._relationships[id]);
}
return result;
},
removeTopic : function(topic) {
$assert(topic, "topic can not be null");
this._topics.erase(topic);
},
addTopic : function(topic) {
$assert(topic, "topic can not be null");
this._topics.push(topic);
},
filterTopicsIds : function(validate, errorMsg) {
var result = [];
var topics = this.filterSelectedTopics();
if (topics.length==0) {
core.Monitor.getInstance().logMessage('At least one element must be selected to execute this operation.');
} else {
var isValid = true;
for (var i = 0; i < topics.length; i++) {
var selectedNode = topics[i];
if ($defined(validate)) {
isValid = validate(selectedNode);
}
// Add node only if it's valid.
if (isValid) {
result.push(selectedNode.getId());
} else {
core.Monitor.getInstance().logMessage(errorMsg);
}
}
}
return result;
},
filterRelationIds : function(validate, errorMsg) {
var result = [];
var relationships = this.filterSelectedRelations();
if (relationships.length == 0) {
core.Monitor.getInstance().logMessage('At least one element must be selected to execute this operation.');
} else {
var isValid = true;
for (var j = 0; j < relationships.length; j++) {
var selectedLine = relationships[j];
isValid = true;
if ($defined(validate)) {
isValid = validate(selectedLine);
}
if (isValid) {
result.push(selectedLine.getId());
} else {
core.Monitor.getInstance().logMessage(errorMsg);
}
}
}
return result;
},
getRelationshipsById : function() {
return this._relationships;
}
});

View File

@ -20,7 +20,7 @@ mindplot.DragTopicPositioner = new Class({
initialize:function(layoutManager) {
$assert(layoutManager, 'layoutManager can not be null');
this._layoutManager = layoutManager;
this._topics = layoutManager.getDesigner()._getTopics();
this._topics = layoutManager.getDesigner().getModel().getTopics();
this._workspace = layoutManager.getDesigner().getWorkSpace();
},

View File

@ -54,7 +54,7 @@ mindplot.LocalActionDispatcher = new Class({
},
deleteTopics: function(topicsIds) {
var command = new mindplot.commands.DeleteTopicCommand(topicsIds);
var command = new mindplot.commands.DeleteCommand(topicsIds);
this.execute(command);
},
@ -240,8 +240,9 @@ mindplot.CommandContext = new Class({
$assert(designer, "designer can not be null");
this._designer = designer;
},
findTopics:function(topicsIds) {
var designerTopics = this._designer._topics;
var designerTopics = this._designer.getModel().getTopics();
if (!(topicsIds instanceof Array)) {
topicsIds = [topicsIds];
}
@ -290,18 +291,14 @@ mindplot.CommandContext = new Class({
findRelationships:function(lineIds) {
var result = [];
lineIds.forEach(function(lineId, index) {
var line = this._designer._relationships[lineId];
lineIds.forEach(function(lineId) {
var line = this._designer.getModel().getRelationshipsById()[lineId];
if ($defined(line)) {
result.push(line);
}
}.bind(this));
return result;
},
getSelectedRelationshipLines:function() {
return this._designer.getSelectedRelationshipLines();
}
});

View File

@ -26,34 +26,31 @@ mindplot.MindmapDesigner = new Class({
var commandContext = new mindplot.CommandContext(this);
// this._actionDispatcher = new mindplot.BrixActionDispatcher(commandContext);
this._actionDispatcher = new mindplot.LocalActionDispatcher(commandContext);
this._actionDispatcher.addEvent("modelUpdate", function(event) {
this._fireEvent("modelUpdate", event);
}.bind(this));
mindplot.ActionDispatcher.setInstance(this._actionDispatcher);
// Initial Zoom
this._zoom = profile.zoom;
this._model = new mindplot.DesignerModel(profile);
// Init Screen manager..
var screenManager = new mindplot.ScreenManager(profile.width, profile.height, divElement);
this._workspace = new mindplot.Workspace(profile, screenManager, this._zoom);
this._readOnly = profile.readOnly ? true : false;
// Init layout managers ...
this._topics = [];
this._layoutManager = new mindplot.layout.OriginalLayoutManager(this);
// Register handlers..
this._relationships = {};
this._events = {};
// Register events
if (!profile.readOnly) {
this._registerEvents();
}
this._events = {};
},
_registerEvents : function() {
@ -78,7 +75,7 @@ mindplot.MindmapDesigner = new Class({
// Initialize workspace event listeners.
screenManager.addEvent('update', function() {
// Topic must be set to his original state. All editors must be closed.
var objects = this.getObjects();
var objects = this.getModel().getObjects();
objects.forEach(function(object) {
object.closeEditors();
});
@ -105,7 +102,7 @@ mindplot.MindmapDesigner = new Class({
model.setPosition(pos.x, pos.y);
// Get central topic ...
var centralTopic = this.getCentralTopic();
var centralTopic = this.getModel().getCentralTopic();
var centralTopicId = centralTopic.getId();
// Execute action ...
@ -125,15 +122,6 @@ mindplot.MindmapDesigner = new Class({
},
_getTopics : function() {
return this._topics;
},
getCentralTopic : function() {
var topics = this._getTopics();
return topics[0];
},
addEvent : function(eventType, listener) {
this._events[eventType] = listener;
},
@ -151,13 +139,10 @@ mindplot.MindmapDesigner = new Class({
// Create node graph ...
var topic = mindplot.NodeGraph.create(model);
this._layoutManager.addHelpers(topic);
// Append it to the workspace ...
var topics = this._topics;
topics.push(topic);
this.getModel().addTopic(topic);
// Add Topic events ...
if (!this._readOnly) {
@ -195,12 +180,13 @@ mindplot.MindmapDesigner = new Class({
onObjectFocusEvent : function(currentObject, event) {
// Close node editors ..
var topics = this._getTopics();
var topics = this.getModel().getTopics();
topics.forEach(function(topic) {
topic.closeEditors();
});
var objects = this.getObjects();
var model = this.getModel();
var objects = model.getObjects();
objects.forEach(function(object) {
// Disable all nodes on focus but not the current if Ctrl key isn't being pressed
if (!$defined(event) || (!event.ctrlKey && !event.metaKey)) {
@ -216,9 +202,10 @@ mindplot.MindmapDesigner = new Class({
if (!factor)
factor = 1.2;
var scale = this._zoom * factor;
var model = this.getModel();
var scale = model.getZoom() * factor;
if (scale <= 4) {
this._zoom = scale;
model.setZoom(scale);
this._workspace.setZoom(this._zoom);
}
else {
@ -228,14 +215,15 @@ mindplot.MindmapDesigner = new Class({
},
selectAll : function() {
var objects = this.getObjects();
var model = this.getModel();
var objects = model.getObjects();
objects.forEach(function(object) {
object.setOnFocus(true);
});
},
deselectAll : function() {
var objects = this.getObjects();
var objects = this.getModel().getObjects();
objects.forEach(function(object) {
object.setOnFocus(false);
});
@ -245,20 +233,24 @@ mindplot.MindmapDesigner = new Class({
if (!factor)
factor = 1.2;
var scale = this._zoom / factor;
var model = this.getModel();
var scale = model.getZoom() / factor;
if (scale >= 0.3) {
this._zoom = scale;
model.setZoom(scale);
this._workspace.setZoom(this._zoom);
}
else {
core.Monitor.getInstance().logMessage('Sorry, no more zoom can be applied. \n Why do you need more?');
}
}
,
},
getModel : function() {
return this._model;
},
createChildForSelectedNode : function() {
var nodes = this.getSelectedNodes();
var nodes = this.getModel().filterSelectedTopics();
if (nodes.length <= 0) {
// If there are more than one node selected,
core.Monitor.getInstance().logMessage('Could not create a topic. Only one node must be selected.');
@ -283,7 +275,7 @@ mindplot.MindmapDesigner = new Class({
},
createSiblingForSelectedNode : function() {
var nodes = this.getSelectedNodes();
var nodes = this.getModel().filterSelectedTopics();
if (nodes.length <= 0) {
// If there are more than one node selected,
core.Monitor.getInstance().logMessage('Could not create a topic. Only one node must be selected.');
@ -314,7 +306,7 @@ mindplot.MindmapDesigner = new Class({
addRelationShip : function(event) {
var screen = this._workspace.getScreenManager();
var pos = screen.getWorkspaceMousePosition(event);
var selectedTopics = this.getSelectedNodes();
var selectedTopics = this.getModel().filterSelectedTopics();
if (selectedTopics.length > 0 &&
(!$defined(this._creatingRelationship) || ($defined(this._creatingRelationship) && !this._creatingRelationship))) {
this._workspace.enableWorkspaceEvents(false);
@ -370,8 +362,7 @@ mindplot.MindmapDesigner = new Class({
this._actionDispatcher.addRelationship(model, mindmap);
}
,
},
needsSave : function() {
return this._actionRunner.hasBeenChanged();
@ -398,20 +389,18 @@ mindplot.MindmapDesigner = new Class({
// Refresh undo state...
this._actionRunner.markAsChangeBase();
}
,
},
loadFromCollaborativeModel: function(collaborationManager) {
var mindmap = collaborationManager.buildWiseModel();
this._loadMap(1, mindmap);
// Place the focus on the Central Topic
var centralTopic = this.getCentralTopic();
var centralTopic = this.getModel().getCentralTopic();
this.goToNode.attempt(centralTopic, this);
this._fireEvent("loadsuccess");
}
,
},
loadFromXML : function(mapId, xmlContent) {
$assert(xmlContent, 'mindmapId can not be null');
@ -426,13 +415,12 @@ mindplot.MindmapDesigner = new Class({
this._loadMap(mapId, mindmap);
// Place the focus on the Central Topic
var centralTopic = this.getCentralTopic();
var centralTopic = this.getModel().getCentralTopic();
this.goToNode(centralTopic);
this._fireEvent("loadsuccess");
}
,
},
load : function(mapId) {
$assert(mapId, 'mapName can not be null');
@ -447,7 +435,7 @@ mindplot.MindmapDesigner = new Class({
this._loadMap(mapId, mindmap);
// Place the focus on the Central Topic
var centralTopic = this.getCentralTopic();
var centralTopic = this.getModel().getCentralTopic();
this.goToNode.attempt(centralTopic, this);
this._fireEvent("loadsuccess");
@ -475,29 +463,26 @@ mindplot.MindmapDesigner = new Class({
this._relationshipModelToRelationship(relationships[j]);
}
}
this._getTopics().forEach(function(topic) {
this.getModel().getTopics().forEach(function(topic) {
delete topic.getModel()._finalPosition;
});
this._fireEvent("loadsuccess");
}
,
},
getMindmap : function() {
return this._mindmap;
}
,
},
undo : function() {
this._actionRunner.undo();
}
,
},
redo : function() {
this._actionRunner.redo();
}
,
},
_nodeModelToNodeGraph : function(nodeModel, isVisible) {
$assert(nodeModel, "Node model can not be null");
@ -552,15 +537,16 @@ mindplot.MindmapDesigner = new Class({
delete this._relationships[model.getId()];
},
_buildRelationship : function (model) {
_buildRelationship : function (topicModel) {
var elem = this;
var fromNodeId = model.getFromNode();
var toNodeId = model.getToNode();
var fromNodeId = topicModel.getFromNode();
var toNodeId = topicModel.getToNode();
var fromTopic = null;
var toTopic = null;
var topics = this._topics;
var model = this.getModel();
var topics = model.getTopics();
for (var i = 0; i < topics.length; i++) {
var t = topics[i];
@ -576,21 +562,21 @@ mindplot.MindmapDesigner = new Class({
}
// Create node graph ...
var relationLine = new mindplot.RelationshipLine(fromTopic, toTopic, model.getLineType());
if ($defined(model.getSrcCtrlPoint())) {
var srcPoint = model.getSrcCtrlPoint().clone();
var relationLine = new mindplot.RelationshipLine(fromTopic, toTopic, topicModel.getLineType());
if ($defined(topicModel.getSrcCtrlPoint())) {
var srcPoint = topicModel.getSrcCtrlPoint().clone();
relationLine.setSrcControlPoint(srcPoint);
}
if ($defined(model.getDestCtrlPoint())) {
var destPoint = model.getDestCtrlPoint().clone();
if ($defined(topicModel.getDestCtrlPoint())) {
var destPoint = topicModel.getDestCtrlPoint().clone();
relationLine.setDestControlPoint(destPoint);
}
relationLine.getLine().setDashed(3, 2);
relationLine.setShowEndArrow(model.getEndArrow());
relationLine.setShowStartArrow(model.getStartArrow());
relationLine.setModel(model);
relationLine.setShowEndArrow(topicModel.getEndArrow());
relationLine.setShowStartArrow(topicModel.getStartArrow());
relationLine.setModel(topicModel);
//Add Listeners
relationLine.addEvent('onfocus', function(event) {
@ -598,7 +584,7 @@ mindplot.MindmapDesigner = new Class({
});
// Append it to the workspace ...
this._relationships[model.getId()] = relationLine;
this._relationships[topicModel.getId()] = relationLine;
return relationLine;
},
@ -614,7 +600,7 @@ mindplot.MindmapDesigner = new Class({
}
this._workspace.removeChild(node);
this._topics.erase(node);
this.getModel().removeTopic(node);
// Delete this node from the model...
var model = node.getModel();
@ -632,16 +618,18 @@ mindplot.MindmapDesigner = new Class({
return selectedObject.getType() == mindplot.RelationshipLine.type || selectedObject.getTopicType() != mindplot.model.NodeModel.CENTRAL_TOPIC_TYPE
};
var validateError = 'Central topic can not be deleted.';
var selectedObjects = this._getValidSelectedObjectsIds(validateFunc, validateError);
if (selectedObjects.nodes.length > 0 || selectedObjects.relationshipLines.length > 0) {
this._actionDispatcher.deleteTopics(selectedObjects);
var model = this.getModel();
var topics = model.filterTopicsIds(validateFunc, validateError);
var rel = model.filterRelationIds(validateFunc, validateError);
if (objects.length > 0) {
this._actionDispatcher.deleteTopics({'nodes':topics,'relationship':rel});
}
},
changeFontFamily : function(font) {
var validSelectedObjects = this._getValidSelectedObjectsIds();
var topicsIds = validSelectedObjects.nodes;
var topicsIds = this.getModel().filterTopicsIds();
if (topicsIds.length > 0) {
this._actionDispatcher.changeFontFamilyToTopic(topicsIds, font);
@ -649,8 +637,7 @@ mindplot.MindmapDesigner = new Class({
},
changeFontStyle : function() {
var validSelectedObjects = this._getValidSelectedObjectsIds();
var topicsIds = validSelectedObjects.nodes;
var topicsIds = this.getModel().filterTopicsIds();
if (topicsIds.length > 0) {
this._actionDispatcher.changeFontStyleToTopic(topicsIds);
}
@ -658,8 +645,8 @@ mindplot.MindmapDesigner = new Class({
changeFontColor : function(color) {
$assert(color, "color can not be null");
var validSelectedObjects = this._getValidSelectedObjectsIds();
var topicsIds = validSelectedObjects.nodes;
var topicsIds = this.getModel().filterTopicsIds();
if (topicsIds.length > 0) {
this._actionDispatcher.changeFontColorToTopic(topicsIds, color);
}
@ -671,67 +658,26 @@ mindplot.MindmapDesigner = new Class({
return topic.getShapeType() != mindplot.model.NodeModel.SHAPE_TYPE_LINE
};
var validateError = 'Color can not be set to line topics.';
var validSelectedObjects = this._getValidSelectedObjectsIds(validateFunc, validateError);
var topicsIds = validSelectedObjects.nodes;
var topicsIds = this.getModel().filterTopicsIds(validateFunc, validateError);
if (topicsIds.length > 0) {
this._actionDispatcher.changeBackgroundColorToTopic(topicsIds, color);
}
},
_getValidSelectedObjectsIds : function(validate, errorMsg) {
var result = {"nodes":[],"relationshipLines":[]};
var selectedNodes = this.getSelectedNodes();
var selectedRelationshipLines = this.getSelectedRelationshipLines();
if (selectedNodes.length == 0 && selectedRelationshipLines.length == 0) {
core.Monitor.getInstance().logMessage('At least one element must be selected to execute this operation.');
} else {
var isValid = true;
for (var i = 0; i < selectedNodes.length; i++) {
var selectedNode = selectedNodes[i];
if ($defined(validate)) {
isValid = validate(selectedNode);
}
// Add node only if it's valid.
if (isValid) {
result.nodes.push(selectedNode.getId());
} else {
core.Monitor.getInstance().logMessage(errorMsg);
}
}
for (var j = 0; j < selectedRelationshipLines.length; j++) {
var selectedLine = selectedRelationshipLines[j];
isValid = true;
if ($defined(validate)) {
isValid = validate(selectedLine);
}
if (isValid) {
result.relationshipLines.push(selectedLine.getId());
} else {
core.Monitor.getInstance().logMessage(errorMsg);
}
}
}
return result;
},
changeBorderColor : function(color) {
var validateFunc = function(topic) {
return topic.getShapeType() != mindplot.model.NodeModel.SHAPE_TYPE_LINE
};
var validateError = 'Color can not be set to line topics.';
var validSelectedObjects = this._getValidSelectedObjectsIds(validateFunc, validateError);
var topicsIds = validSelectedObjects.nodes;
var topicsIds = this.getModel().filterTopicsIds(validateFunc, validateError);
if (topicsIds.length > 0) {
this._actionDispatcher.changeBorderColorToTopic(topicsIds, color);
}
},
changeFontSize : function(size) {
var validSelectedObjects = this._getValidSelectedObjectsIds();
var topicsIds = validSelectedObjects.nodes;
var topicsIds = this.getModel().filterTopicsIds();
if (topicsIds.length > 0) {
this._actionDispatcher.changeFontSizeToTopic(topicsIds, size);
}
@ -743,40 +689,35 @@ mindplot.MindmapDesigner = new Class({
return !(topic.getType() == mindplot.model.NodeModel.CENTRAL_TOPIC_TYPE && shape == mindplot.model.NodeModel.SHAPE_TYPE_LINE)
};
var validateError = 'Central Topic shape can not be changed to line figure.';
var validSelectedObjects = this._getValidSelectedObjectsIds(validateFunc, validateError);
var topicsIds = validSelectedObjects.nodes;
var topicsIds = this.getModel().filterTopicsIds(validateFunc, validateError);
if (topicsIds.length > 0) {
this._actionDispatcher.changeShapeToTopic(topicsIds, shape);
}
},
changeFontWeight : function() {
var validSelectedObjects = this._getValidSelectedObjectsIds();
var topicsIds = validSelectedObjects.nodes;
var topicsIds = this.getModel().filterTopicsIds();
if (topicsIds.length > 0) {
this._actionDispatcher.changeFontWeightToTopic(topicsIds);
}
},
addIconType : function(iconType) {
var validSelectedObjects = this._getValidSelectedObjectsIds();
var topicsIds = validSelectedObjects.nodes;
var topicsIds = this.getModel().filterTopicsIds();
if (topicsIds.length > 0) {
this._actionDispatcher.addIconToTopic(topicsIds[0], iconType);
}
},
addLink2Node : function(url) {
var validSelectedObjects = this._getValidSelectedObjectsIds();
var topicsIds = validSelectedObjects.nodes;
var topicsIds = this.getModel().filterTopicsIds();
if (topicsIds.length > 0) {
this._actionDispatcher.addLinkToTopic(topicsIds[0], url);
}
},
addLink : function() {
var selectedTopics = this.getSelectedNodes();
var selectedTopics = this.getModel().filterSelectedTopics();
var topic = null;
if (selectedTopics.length > 0) {
topic = selectedTopics[0];
@ -820,15 +761,14 @@ mindplot.MindmapDesigner = new Class({
},
addNote2Node : function(text) {
var validSelectedObjects = this._getValidSelectedObjectsIds();
var topicsIds = validSelectedObjects.nodes;
var topicsIds = this.getModel().filterTopicsIds();
if (topicsIds.length > 0) {
this._actionDispatcher.addNoteToTopic(topicsIds[0], text);
}
},
addNote : function() {
var selectedTopics = this.getSelectedNodes();
var selectedTopics = this.getModel().filterSelectedTopics();
var topic = null;
if (selectedTopics.length > 0) {
topic = selectedTopics[0];
@ -870,35 +810,6 @@ mindplot.MindmapDesigner = new Class({
}
},
getSelectedNodes : function() {
var result = new Array();
for (var i = 0; i < this._topics.length; i++) {
if (this._topics[i].isOnFocus()) {
result.push(this._topics[i]);
}
}
return result;
},
getSelectedRelationshipLines : function() {
var result = new Array();
for (var id in this._relationships) {
var relationship = this._relationships[id];
if (relationship.isOnFocus()) {
result.push(relationship);
}
}
return result;
},
getObjects : function() {
var result = [].append(this._topics);
for (var id in this._relationships) {
result.push(this._relationships[id]);
}
return result;
},
goToNode : function(node) {
node.setOnFocus(true);
this.onObjectFocusEvent(node);

View File

@ -21,12 +21,12 @@ mindplot.commands.AddIconToTopicCommand = new Class({
initialize: function(topicId, iconType) {
$assert(topicId, 'topicId can not be null');
$assert(iconType, 'iconType can not be null');
this._selectedObjectsIds = topicId;
this._objectsIds = topicId;
this._iconType = iconType;
},
execute: function(commandContext) {
var topic = commandContext.findTopics(this._selectedObjectsIds)[0];
var topic = commandContext.findTopics(this._objectsIds)[0];
var updated = function() {
var iconImg = topic.addIcon(this._iconType, commandContext._designer);
this._iconModel = iconImg.getModel();
@ -36,7 +36,7 @@ mindplot.commands.AddIconToTopicCommand = new Class({
},
undoExecute: function(commandContext) {
var topic = commandContext.findTopics(this._selectedObjectsIds)[0];
var topic = commandContext.findTopics(this._objectsIds)[0];
var updated = function() {
topic.removeIcon(this._iconModel);
topic.updateNode();

View File

@ -20,12 +20,12 @@ mindplot.commands.AddLinkToTopicCommand = new Class({
Extends:mindplot.Command,
initialize: function(topicId, url) {
$assert(topicId, 'topicId can not be null');
this._selectedObjectsIds = topicId;
this._objectsIds = topicId;
this._url = url;
this._id = mindplot.Command._nextUUID();
},
execute: function(commandContext) {
var topic = commandContext.findTopics(this._selectedObjectsIds)[0];
var topic = commandContext.findTopics(this._objectsIds)[0];
var updated = function() {
topic.addLink(this._url, commandContext._designer);
topic.updateNode();
@ -33,7 +33,7 @@ mindplot.commands.AddLinkToTopicCommand = new Class({
updated.delay(0);
},
undoExecute: function(commandContext) {
var topic = commandContext.findTopics(this._selectedObjectsIds)[0];
var topic = commandContext.findTopics(this._objectsIds)[0];
var updated = function() {
topic.removeLink();
}.bind(this);

View File

@ -20,12 +20,12 @@ mindplot.commands.AddNoteToTopicCommand = new Class({
Extends:mindplot.Command,
initialize: function(topicId, text) {
$assert(topicId, 'topicId can not be null');
this._selectedObjectsIds = topicId;
this._objectsIds = topicId;
this._text = text;
this._id = mindplot.Command._nextUUID();
},
execute: function(commandContext) {
var topic = commandContext.findTopics(this._selectedObjectsIds)[0];
var topic = commandContext.findTopics(this._objectsIds)[0];
var updated = function() {
topic.addNote(this._text, commandContext._designer);
topic.updateNode();
@ -33,7 +33,7 @@ mindplot.commands.AddNoteToTopicCommand = new Class({
updated.delay(0);
},
undoExecute: function(commandContext) {
var topic = commandContext.findTopics(this._selectedObjectsIds)[0];
var topic = commandContext.findTopics(this._objectsIds)[0];
var updated = function() {
topic.removeNote();
}.bind(this);

View File

@ -16,18 +16,19 @@
* limitations under the License.
*/
mindplot.commands.DeleteTopicCommand = new Class({
mindplot.commands.DeleteCommand = new Class({
Extends:mindplot.Command,
initialize: function(topicsIds) {
$assert(topicsIds, "topicsIds must be defined");
this._selectedObjectsIds = topicsIds;
initialize: function(objectIds) {
$assert(objectIds, "objectIds must be defined");
this._objectsIds = objectIds;
this._deletedTopicModels = [];
this._parentTopicIds = [];
this._deletedRelationships = [];
this._id = mindplot.Command._nextUUID();
},
execute: function(commandContext) {
var topics = commandContext.findTopics(this._selectedObjectsIds.nodes);
var topics = commandContext.findTopics(this._objectsIds.nodes);
if (topics.length > 0) {
topics.forEach(
function(topic, index) {
@ -57,7 +58,7 @@ mindplot.commands.DeleteTopicCommand = new Class({
}.bind(this)
);
}
var lines = commandContext.findRelationships(this._selectedObjectsIds.relationshipLines);
var lines = commandContext.findRelationships(this._objectsIds.relationship);
if (lines.length > 0) {
lines.forEach(function(line, index) {
if (line.isInWorkspace()) {
@ -69,7 +70,7 @@ mindplot.commands.DeleteTopicCommand = new Class({
},
undoExecute: function(commandContext) {
var topics = commandContext.findTopics(this._selectedObjectsIds);
var topics = commandContext.findTopics(this._objectsIds);
var parent = commandContext.findTopics(this._parentTopicIds);
this._deletedTopicModels.forEach(

View File

@ -21,7 +21,7 @@ mindplot.commands.DragTopicCommand = new Class({
initialize: function(topicIds, position, order, parentTopic) {
$assert(topicIds, "topicIds must be defined");
this._selectedObjectsIds = topicIds;
this._objectsIds = topicIds;
if ($defined(parentTopic))
this._parentId = parentTopic.getId();
@ -31,7 +31,7 @@ mindplot.commands.DragTopicCommand = new Class({
},
execute: function(commandContext) {
var topic = commandContext.findTopics([this._selectedObjectsIds])[0];
var topic = commandContext.findTopics([this._objectsIds])[0];
// Save old position ...
var origParentTopic = topic.getOutgoingConnectedTopic();
@ -80,7 +80,7 @@ mindplot.commands.DragTopicCommand = new Class({
},
undoExecute: function(commandContext) {
this.execute(commandContext);
var selectedRelationships = commandContext.getSelectedRelationshipLines();
var selectedRelationships = commandContext.filterSelectedRelations();
selectedRelationships.forEach(function(relationshipLine) {
relationshipLine.redraw();
});

View File

@ -23,14 +23,14 @@ mindplot.commands.GenericFunctionCommand = new Class({
$assert(topicsIds, "topicsIds must be defined");
this._value = value;
this._selectedObjectsIds = topicsIds;
this._objectsIds = topicsIds;
this._commandFunc = commandFunc;
this._oldValues = [];
this._id = mindplot.Command._nextUUID();
},
execute: function(commandContext) {
if (!this.applied) {
var topics = commandContext.findTopics(this._selectedObjectsIds);
var topics = commandContext.findTopics(this._objectsIds);
topics.forEach(function(topic) {
var oldValue = this._commandFunc(topic, this._value);
this._oldValues.push(oldValue);
@ -43,7 +43,7 @@ mindplot.commands.GenericFunctionCommand = new Class({
},
undoExecute: function(commandContext) {
if (this.applied) {
var topics = commandContext.findTopics(this._selectedObjectsIds);
var topics = commandContext.findTopics(this._objectsIds);
topics.forEach(function(topic, index) {
this._commandFunc(topic, this._oldValues[index]);

View File

@ -22,12 +22,12 @@ mindplot.commands.RemoveIconFromTopicCommand = new Class({
{
$assert(topicId, 'topicId can not be null');
$assert(iconModel, 'iconId can not be null');
this._selectedObjectsIds = topicId;
this._objectsIds = topicId;
this._iconModel = iconModel;
},
execute: function(commandContext)
{
var topic = commandContext.findTopics(this._selectedObjectsIds)[0];
var topic = commandContext.findTopics(this._objectsIds)[0];
var updated = function() {
topic.removeIcon(this._iconModel);
topic.updateNode();
@ -36,7 +36,7 @@ mindplot.commands.RemoveIconFromTopicCommand = new Class({
},
undoExecute: function(commandContext)
{
var topic = commandContext.findTopics(this._selectedObjectsIds)[0];
var topic = commandContext.findTopics(this._objectsIds)[0];
var updated = function() {
var iconType = this._iconModel.getIconType();
var iconImg = topic.addIcon(iconType, commandContext._designer);

View File

@ -20,10 +20,10 @@ mindplot.commands.RemoveLinkFromTopicCommand = new Class({
Extends:mindplot.Command,
initialize: function(topicId) {
$assert(topicId, 'topicId can not be null');
this._selectedObjectsIds = topicId;
this._objectsIds = topicId;
},
execute: function(commandContext) {
var topic = commandContext.findTopics(this._selectedObjectsIds)[0];
var topic = commandContext.findTopics(this._objectsIds)[0];
this._url = topic._link.getUrl();
var updated = function() {
topic.removeLink();
@ -31,7 +31,7 @@ mindplot.commands.RemoveLinkFromTopicCommand = new Class({
updated.delay(0);
},
undoExecute: function(commandContext) {
var topic = commandContext.findTopics(this._selectedObjectsIds)[0];
var topic = commandContext.findTopics(this._objectsIds)[0];
var updated = function() {
topic.addLink(this._url, commandContext._designer);
topic.updateNode();

View File

@ -21,11 +21,11 @@ mindplot.commands.RemoveNoteFromTopicCommand = new Class({
initialize: function(topicId)
{
$assert(topicId, 'topicId can not be null');
this._selectedObjectsIds = topicId;
this._objectsIds = topicId;
},
execute: function(commandContext)
{
var topic = commandContext.findTopics(this._selectedObjectsIds)[0];
var topic = commandContext.findTopics(this._objectsIds)[0];
this._text = topic._note.getText();
var updated = function() {
topic.removeNote();
@ -34,7 +34,7 @@ mindplot.commands.RemoveNoteFromTopicCommand = new Class({
},
undoExecute: function(commandContext)
{
var topic = commandContext.findTopics(this._selectedObjectsIds)[0];
var topic = commandContext.findTopics(this._objectsIds)[0];
var updated = function() {
topic.addNote(this._text,commandContext._designer);
topic.updateNode();

View File

@ -79,7 +79,7 @@ mindplot.layout.OriginalLayoutManager = new Class({
_buildDragManager: function(workspace) {
// Init dragger manager.
var dragger = new mindplot.DragManager(workspace);
var topics = this.getDesigner()._getTopics();
var topics = this.getDesigner().getModel().getTopics();
var dragTopicPositioner = this.getDragTopicPositioner();

View File

@ -28,8 +28,8 @@ mindplot.layout.boards.freemind.Board = mindplot.layout.boards.Board.extend({
var result = this.findNewNodeEntryIndex(entry);
// if creating a sibling or child
if(!this._layoutManager._isMovingNode && this._layoutManager.getDesigner().getSelectedNodes().length>0){
var selectedNode = this._layoutManager.getDesigner().getSelectedNodes()[0];
if(!this._layoutManager._isMovingNode && this._layoutManager.getDesigner().filterSelectedTopics().length>0){
var selectedNode = this._layoutManager.getDesigner().filterSelectedTopics()[0];
if(!$defined(pos)){
if(selectedNode.getParent()!= null && node.getParent().getId() == selectedNode.getParent().getId()){
//creating a sibling - Lets put the new node below the selected node.

View File

@ -40,11 +40,12 @@ mindplot.widget.Menu = new Class({
});
// Create panels ...
var designerModel = designer.getModel();
var fontFamilyModel = {
getValue: function() {
var nodes = designer.getSelectedNodes();
var nodes = designerModel.filterSelectedTopics();
var result = null;
for (var i=0; i < nodes.length; i++) {
for (var i = 0; i < nodes.length; i++) {
var fontFamily = nodes[i].getFontFamily();
if (result != null && result != fontFamily) {
result = null;
@ -64,9 +65,9 @@ mindplot.widget.Menu = new Class({
var fontSizeModel = {
getValue: function() {
var nodes = designer.getSelectedNodes();
var nodes = designerModel.filterSelectedTopics();
var result = null;
for (var i=0; i < nodes.length; i++) {
for (var i = 0; i < nodes.length; i++) {
var fontSize = nodes[i].getFontSize();
if (result != null && result != fontSize) {
result = null;
@ -84,9 +85,9 @@ mindplot.widget.Menu = new Class({
var topicShapeModel = {
getValue: function() {
var nodes = designer.getSelectedNodes();
var nodes = designerModel.filterSelectedTopics();
var result = null;
for (var i=0; i < nodes.length; i++) {
for (var i = 0; i < nodes.length; i++) {
var shapeType = nodes[i].getShapeType();
if (result != null && result != shapeType) {
result = null;
@ -117,9 +118,9 @@ mindplot.widget.Menu = new Class({
var topicColorModel =
{
getValue : function() {
var nodes = designer.getSelectedNodes();
var nodes = designerModel.filterSelectedTopics();
var result = null;
for (var i=0; i < nodes.length; i++) {
for (var i = 0; i < nodes.length; i++) {
var color = nodes[i].getBackgroundColor();
if (result != null && result != color) {
result = null;
@ -139,9 +140,9 @@ mindplot.widget.Menu = new Class({
var borderColorModel =
{
getValue : function() {
var nodes = designer.getSelectedNodes();
var nodes = designerModel.filterSelectedTopics();
var result = null;
for (var i=0; i < nodes.length; i++) {
for (var i = 0; i < nodes.length; i++) {
var color = nodes[i].getBorderColor();
if (result != null && result != color) {
result = null;
@ -162,8 +163,8 @@ mindplot.widget.Menu = new Class({
{
getValue : function() {
var result = null;
var nodes = designer.getSelectedNodes();
for (var i=0; i < nodes.length; i++) {
var nodes = designerModel.filterSelectedTopics();
for (var i = 0; i < nodes.length; i++) {
var color = nodes[i].getFontColor();
if (result != null && result != color) {
result = null;

View File

@ -89,9 +89,9 @@ TestCase("Mindplot test",{
var centralTopic = designer.getCentralTopic();
assertNotNull(centralTopic);
var target = designer.getWorkSpace().getScreenManager().getContainer();
var size = designer._getTopics().length;
var size = designer.getModel().getTopics().length;
fireNativeEvent('dblclick',target,new core.Point(50,50));
assertEquals(size+1, designer._getTopics().length);
assertEquals(size+1, designer.getModel().getTopics().length);
}
});

View File

@ -309,7 +309,7 @@ function buildMindmapDesigner() {
var screenWidth = window.getWidth();
var screenHeight = window.getHeight();
// Positionate node ...
// Position node ...
// header - footer
screenHeight = screenHeight - 90 - 61;