2009-06-08 02:59:43 +08:00
|
|
|
/*
|
2011-07-27 19:25:10 +08:00
|
|
|
* 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.
|
|
|
|
*/
|
2009-06-08 02:59:43 +08:00
|
|
|
|
2011-08-04 04:52:39 +08:00
|
|
|
// @Todo: Why the whole desginer ?. Must decouple this...
|
2009-06-08 02:59:43 +08:00
|
|
|
mindplot.DesignerActionRunner = new Class({
|
2011-07-27 19:25:10 +08:00
|
|
|
initialize: function(designer) {
|
2011-08-04 04:52:39 +08:00
|
|
|
$assert(designer, "designer can not be null");
|
2011-07-27 19:25:10 +08:00
|
|
|
this._designer = designer;
|
|
|
|
this._undoManager = new mindplot.DesignerUndoManager();
|
|
|
|
this._context = new mindplot.CommandContext(this._designer);
|
|
|
|
},
|
|
|
|
|
|
|
|
execute:function(command) {
|
2011-07-28 01:33:02 +08:00
|
|
|
$assert(command, "command can not be null");
|
2009-06-08 02:59:43 +08:00
|
|
|
// Execute action ...
|
|
|
|
command.execute(this._context);
|
|
|
|
|
|
|
|
// Enqueue it ...
|
|
|
|
this._undoManager.enqueue(command);
|
|
|
|
|
|
|
|
// Fire event
|
|
|
|
var event = this._undoManager._buildEvent();
|
|
|
|
this._designer._fireEvent("change", event);
|
|
|
|
},
|
2011-07-27 19:25:10 +08:00
|
|
|
|
|
|
|
undo: function() {
|
2009-06-08 02:59:43 +08:00
|
|
|
this._undoManager.execUndo(this._context);
|
|
|
|
|
|
|
|
// Fire event
|
|
|
|
var event = this._undoManager._buildEvent();
|
|
|
|
this._designer._fireEvent("change", event);
|
|
|
|
},
|
2011-07-27 19:25:10 +08:00
|
|
|
|
|
|
|
redo: function() {
|
2009-06-08 02:59:43 +08:00
|
|
|
this._undoManager.execRedo(this._context);
|
|
|
|
|
|
|
|
// Fire event
|
|
|
|
var event = this._undoManager._buildEvent();
|
|
|
|
this._designer._fireEvent("change", event);
|
|
|
|
|
|
|
|
},
|
2011-07-27 19:25:10 +08:00
|
|
|
|
|
|
|
markAsChangeBase: function() {
|
2009-06-08 02:59:43 +08:00
|
|
|
return this._undoManager.markAsChangeBase();
|
|
|
|
},
|
2011-07-27 19:25:10 +08:00
|
|
|
hasBeenChanged: function() {
|
2009-06-08 02:59:43 +08:00
|
|
|
return this._undoManager.hasBeenChanged();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
mindplot.CommandContext = new Class({
|
2011-07-27 19:25:10 +08:00
|
|
|
initialize: function(designer) {
|
2009-06-08 02:59:43 +08:00
|
|
|
this._designer = designer;
|
|
|
|
},
|
2011-07-27 19:25:10 +08:00
|
|
|
findTopics:function(topicsIds) {
|
2009-06-08 02:59:43 +08:00
|
|
|
var designerTopics = this._designer._topics;
|
2011-07-27 19:25:10 +08:00
|
|
|
if (!(topicsIds instanceof Array)) {
|
2009-06-08 02:59:43 +08:00
|
|
|
topicsIds = [topicsIds];
|
|
|
|
}
|
|
|
|
|
|
|
|
var result = designerTopics.filter(function(topic) {
|
|
|
|
var found = false;
|
2011-07-27 19:25:10 +08:00
|
|
|
if (topic != null) {
|
2009-06-08 02:59:43 +08:00
|
|
|
var topicId = topic.getId();
|
|
|
|
found = topicsIds.contains(topicId);
|
|
|
|
}
|
|
|
|
return found;
|
|
|
|
|
|
|
|
});
|
|
|
|
return result;
|
|
|
|
},
|
2011-07-27 19:25:10 +08:00
|
|
|
deleteTopic:function(topic) {
|
2009-06-08 02:59:43 +08:00
|
|
|
this._designer._removeNode(topic);
|
|
|
|
},
|
2011-07-27 19:25:10 +08:00
|
|
|
createTopic:function(model, isVisible) {
|
2011-07-28 01:33:02 +08:00
|
|
|
$assert(model, "model can not be null");
|
2011-02-09 22:29:09 +08:00
|
|
|
var topic = this._designer._nodeModelToNodeGraph(model, isVisible);
|
2009-06-08 02:59:43 +08:00
|
|
|
|
|
|
|
return topic;
|
|
|
|
},
|
2011-07-27 19:25:10 +08:00
|
|
|
createModel:function() {
|
2009-06-08 02:59:43 +08:00
|
|
|
var mindmap = this._designer.getMindmap();
|
|
|
|
var model = mindmap.createNode(mindplot.NodeModel.MAIN_TOPIC_TYPE);
|
|
|
|
return model;
|
|
|
|
},
|
2011-07-27 19:25:10 +08:00
|
|
|
connect:function(childTopic, parentTopic, isVisible) {
|
2011-02-09 22:29:09 +08:00
|
|
|
childTopic.connectTo(parentTopic, this._designer._workspace, isVisible);
|
2009-06-08 02:59:43 +08:00
|
|
|
} ,
|
2011-07-27 19:25:10 +08:00
|
|
|
disconnect:function(topic) {
|
2009-06-08 02:59:43 +08:00
|
|
|
topic.disconnect(this._designer._workspace);
|
2010-12-13 22:07:20 +08:00
|
|
|
},
|
2011-07-27 19:25:10 +08:00
|
|
|
createRelationship:function(model) {
|
2011-07-28 01:33:02 +08:00
|
|
|
$assert(model, "model cannot be null");
|
2010-12-13 22:07:20 +08:00
|
|
|
var relationship = this._designer.createRelationship(model);
|
|
|
|
return relationship;
|
|
|
|
},
|
|
|
|
removeRelationship:function(model) {
|
|
|
|
this._designer.removeRelationship(model);
|
2010-12-23 06:34:24 +08:00
|
|
|
},
|
2011-07-27 19:25:10 +08:00
|
|
|
findRelationships:function(lineIds) {
|
2010-12-23 06:34:24 +08:00
|
|
|
var result = [];
|
2011-07-27 19:25:10 +08:00
|
|
|
lineIds.forEach(function(lineId, index) {
|
2010-12-23 06:34:24 +08:00
|
|
|
var line = this._designer._relationships[lineId];
|
2011-07-28 00:44:09 +08:00
|
|
|
if ($defined(line)) {
|
2010-12-23 06:34:24 +08:00
|
|
|
result.push(line);
|
|
|
|
}
|
|
|
|
}.bind(this));
|
|
|
|
return result;
|
2011-01-20 23:05:42 +08:00
|
|
|
},
|
2011-07-27 19:25:10 +08:00
|
|
|
getSelectedRelationshipLines:function() {
|
2011-01-20 23:05:42 +08:00
|
|
|
return this._designer.getSelectedRelationshipLines();
|
2009-06-08 02:59:43 +08:00
|
|
|
}
|
|
|
|
});
|