wisemapping-open-source/mindplot/src/main/javascript/StandaloneActionDispatcher.js

361 lines
11 KiB
JavaScript
Raw Normal View History

/*
2015-04-12 05:15:12 +02:00
* Copyright [2015] [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.StandaloneActionDispatcher = new Class(/** @lends StandaloneActionDispatcher */{
2015-04-12 05:15:12 +02:00
Extends: mindplot.ActionDispatcher,
/**
* @extends mindplot.ActionDispatcher
* @constructs
* @param {mindplot.CommandContext} commandContext
*/
2015-04-12 05:15:12 +02:00
initialize: function (commandContext) {
2011-08-05 03:12:53 +02:00
this.parent(commandContext);
2011-08-05 06:06:56 +02:00
this._actionRunner = new mindplot.DesignerActionRunner(commandContext, this);
},
/** */
2015-04-12 05:15:12 +02:00
addTopics: function (models, parentTopicsId) {
2012-07-08 23:41:35 +02:00
var command = new mindplot.commands.AddTopicCommand(models, parentTopicsId);
this.execute(command);
},
/** */
2015-04-12 05:15:12 +02:00
addRelationship: function (model) {
2011-10-09 22:59:16 +02:00
var command = new mindplot.commands.AddRelationshipCommand(model);
this.execute(command);
},
/** */
2015-04-12 05:15:12 +02:00
deleteEntities: function (topicsIds, relIds) {
2011-11-14 01:18:34 +01:00
var command = new mindplot.commands.DeleteCommand(topicsIds, relIds);
this.execute(command);
},
/** */
2015-04-12 05:15:12 +02:00
dragTopic: function (topicId, position, order, parentTopic) {
var command = new mindplot.commands.DragTopicCommand(topicId, position, order, parentTopic);
this.execute(command);
},
/** */
2015-04-12 05:15:12 +02:00
moveTopic: function (topicId, position) {
2012-01-18 05:26:39 +01:00
$assert($defined(topicId), "topicsId can not be null");
$assert($defined(position), "position can not be null");
var commandFunc = function (topic, value) {
2012-01-18 05:26:39 +01:00
var result = topic.getPosition();
2015-04-12 05:15:12 +02:00
mindplot.EventBus.instance.fireEvent(mindplot.EventBus.events.NodeMoveEvent, {
node: topic.getModel(),
position: value
});
2012-01-18 05:26:39 +01:00
return result;
};
var command = new mindplot.commands.GenericFunctionCommand(commandFunc, topicId, position);
2012-01-18 05:32:55 +01:00
this.execute(command);
2012-01-18 05:26:39 +01:00
},
2012-01-18 05:32:55 +01:00
/** */
2015-04-12 05:15:12 +02:00
moveControlPoint: function (ctrlPoint, point) {
var command = new mindplot.commands.MoveControlPointCommand(ctrlPoint, point);
this.execute(command);
},
/** */
2015-04-12 05:15:12 +02:00
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);
2012-01-18 05:32:55 +01:00
this.execute(command);
},
/** */
2015-04-12 05:15:12 +02:00
changeTextToTopic: function (topicsIds, text) {
2011-09-10 02:53:41 +02:00
$assert($defined(topicsIds), "topicsIds can not be null");
2011-08-05 03:12:53 +02:00
var commandFunc = function (topic, value) {
2011-08-05 03:12:53 +02:00
var result = topic.getText();
topic.setText(value);
return result;
};
2015-04-12 05:15:12 +02:00
commandFunc.commandType = "changeTextToTopic";
2011-08-05 03:12:53 +02:00
var command = new mindplot.commands.GenericFunctionCommand(commandFunc, topicsIds, text);
2012-01-18 05:32:55 +01:00
this.execute(command);
2011-08-05 03:12:53 +02:00
},
/** */
2015-04-12 05:15:12 +02:00
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);
topic._adjustShapes();
return result;
};
var command = new mindplot.commands.GenericFunctionCommand(commandFunc, topicIds, fontFamily);
this.execute(command);
},
/** */
2015-04-12 05:15:12 +02:00
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.discardDuplicated = "fontColorCommandId";
this.execute(command);
},
/** */
2015-04-12 05:15:12 +02:00
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.discardDuplicated = "backColor";
this.execute(command);
},
/** */
2015-04-12 05:15:12 +02:00
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.discardDuplicated = "borderColorCommandId";
this.execute(command);
},
/** */
2015-04-12 05:15:12 +02:00
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);
topic._adjustShapes();
return result;
};
var command = new mindplot.commands.GenericFunctionCommand(commandFunc, topicsIds, size);
this.execute(command);
},
/** */
2015-04-12 05:15:12 +02:00
changeShapeTypeToTopic: 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);
},
/** */
2015-04-12 05:15:12 +02:00
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);
topic._adjustShapes();
return result;
};
var command = new mindplot.commands.GenericFunctionCommand(commandFunc, topicsIds);
this.execute(command);
},
/** */
2015-04-12 05:15:12 +02:00
shrinkBranch: function (topicsIds, collapse) {
2011-08-05 06:34:51 +02:00
$assert(topicsIds, "topicsIds can not be null");
var commandFunc = function (topic, isShrink) {
topic.setChildrenShrunken(isShrink);
2011-08-05 06:34:51 +02:00
return !isShrink;
};
var command = new mindplot.commands.GenericFunctionCommand(commandFunc, topicsIds, collapse);
2012-01-17 04:26:29 +01:00
this.execute(command, false);
2011-08-05 06:34:51 +02:00
},
/** */
2015-04-12 05:15:12 +02:00
addFeatureToTopic: function (topicId, featureType, attributes) {
var command = new mindplot.commands.AddFeatureToTopicCommand(topicId, featureType, attributes);
this.execute(command);
},
/** */
2015-04-12 05:15:12 +02:00
changeFeatureToTopic: function (topicId, featureId, attributes) {
var command = new mindplot.commands.ChangeFeatureToTopicCommand(topicId, featureId, attributes);
this.execute(command);
},
/** */
2015-04-12 05:15:12 +02:00
removeFeatureFromTopic: function (topicId, featureId) {
var command = new mindplot.commands.RemoveFeatureFromTopicCommand(topicId, featureId);
this.execute(command);
},
/** */
2015-04-12 05:15:12 +02:00
execute: function (command) {
this._actionRunner.execute(command);
}
});
mindplot.CommandContext = new Class(/** @lends CommandContext */{
/**
* @constructs
* @param {mindplot.Designer} designer
*/
2015-04-12 05:15:12 +02:00
initialize: function (designer) {
2011-08-05 03:12:53 +02:00
$assert(designer, "designer can not be null");
this._designer = designer;
},
/** */
2015-04-12 05:15:12 +02:00
findTopics: function (topicsIds) {
2011-09-10 02:53:41 +02:00
$assert($defined(topicsIds), "topicsIds can not be null");
2011-08-05 03:12:53 +02:00
if (!(topicsIds instanceof Array)) {
topicsIds = [topicsIds];
}
2011-08-30 01:32:12 +02:00
var designerTopics = this._designer.getModel().getTopics();
2012-09-24 18:11:11 +02:00
var result = designerTopics.filter(function (topic) {
2011-08-30 01:32:12 +02:00
return topicsIds.contains(topic.getId());
2011-08-05 03:12:53 +02:00
});
2012-09-24 18:11:11 +02:00
if (result.length != topicsIds.length) {
var ids = designerTopics.map(function (topic) {
return topic.getId();
});
2012-11-05 03:20:21 +01:00
$assert(result.length == topicsIds.length, "Could not find topic. Result:" + result + ", Filter Criteria:" + topicsIds + ", Current Topics: [" + ids + "]");
}
2012-09-24 18:11:11 +02:00
return result;
2011-08-05 03:12:53 +02:00
},
/** */
2015-04-12 05:15:12 +02:00
deleteTopic: function (topic) {
this._designer.removeTopic(topic);
2011-08-05 03:12:53 +02:00
},
/** */
2015-04-12 05:15:12 +02:00
createTopic: function (model) {
2011-08-05 03:12:53 +02:00
$assert(model, "model can not be null");
2015-04-12 05:15:12 +02:00
return this._designer.nodeModelToNodeGraph(model);
2011-08-05 03:12:53 +02:00
},
/** */
2015-04-12 05:15:12 +02:00
createModel: function () {
2011-08-05 03:12:53 +02:00
var mindmap = this._designer.getMindmap();
return mindmap.createNode(mindplot.NodeModel.MAIN_TOPIC_TYPE);
},
/** */
2015-04-12 05:15:12 +02:00
addTopic: function (topic) {
var mindmap = this._designer.getMindmap();
return mindmap.addBranch(topic.getModel());
},
/** */
2015-04-12 05:15:12 +02:00
connect: function (childTopic, parentTopic) {
childTopic.connectTo(parentTopic, this._designer._workspace);
},
2011-08-05 03:12:53 +02:00
/** */
2015-04-12 05:15:12 +02:00
disconnect: function (topic) {
2011-08-05 03:12:53 +02:00
topic.disconnect(this._designer._workspace);
},
/** */
2015-04-12 05:15:12 +02:00
addRelationship: function (model) {
2011-08-05 03:12:53 +02:00
$assert(model, "model cannot be null");
return this._designer.addRelationship(model);
2011-08-05 03:12:53 +02:00
},
/** */
2015-04-12 05:15:12 +02:00
deleteRelationship: function (relationship) {
this._designer.deleteRelationship(relationship);
2011-08-05 03:12:53 +02:00
},
/** */
2015-04-12 05:15:12 +02:00
findRelationships: function (relIds) {
$assert($defined(relIds), "relId can not be null");
if (!(relIds instanceof Array)) {
relIds = [relIds];
}
var designerRel = this._designer.getModel().getRelationships();
2015-04-12 05:15:12 +02:00
return designerRel.filter(function (rel) {
return relIds.contains(rel.getId());
});
2012-07-09 23:52:59 +02:00
},
/** */
2015-04-12 05:15:12 +02:00
moveTopic: function (topic, position) {
2012-07-09 23:52:59 +02:00
$assert(topic, "topic cannot be null");
$assert(position, "position cannot be null");
2015-04-12 05:15:12 +02:00
mindplot.EventBus.instance.fireEvent(mindplot.EventBus.events.NodeMoveEvent, {
node: topic.getModel(),
position: position
});
2011-09-02 07:31:03 +02:00
}
2011-08-05 03:12:53 +02:00
});