2009-06-07 20:59:43 +02:00
|
|
|
/*
|
2011-07-27 19:53:32 +02: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.
|
|
|
|
*/
|
|
|
|
|
2011-10-04 06:16:29 +02:00
|
|
|
mindplot.Designer = new Class({
|
2012-07-01 22:21:02 +02:00
|
|
|
Extends:Events,
|
|
|
|
initialize:function (options, divElement) {
|
2012-02-02 00:31:40 +01:00
|
|
|
$assert(options, "options must be defined");
|
|
|
|
$assert(options.zoom, "zoom must be defined");
|
2011-07-27 19:53:32 +02:00
|
|
|
$assert(divElement, "divElement must be defined");
|
|
|
|
|
2012-07-01 22:21:02 +02:00
|
|
|
// Set up i18n location ...
|
2012-07-01 22:54:46 +02:00
|
|
|
mindplot.Messages.init(options.locale);
|
2012-07-01 22:21:02 +02:00
|
|
|
|
2012-02-02 00:31:40 +01:00
|
|
|
this._options = options;
|
|
|
|
|
2012-02-04 01:21:29 +01:00
|
|
|
// Set full div elem render area ...
|
|
|
|
divElement.setStyles(options.size);
|
|
|
|
|
2011-08-03 22:52:39 +02:00
|
|
|
// Dispatcher manager ...
|
2011-08-05 03:12:53 +02:00
|
|
|
var commandContext = new mindplot.CommandContext(this);
|
2012-02-02 16:28:54 +01:00
|
|
|
if (!$defined(options.collab) || options.collab == 'standalone') {
|
2011-10-02 17:22:09 +02:00
|
|
|
this._actionDispatcher = new mindplot.StandaloneActionDispatcher(commandContext);
|
|
|
|
} else {
|
|
|
|
this._actionDispatcher = new mindplot.BrixActionDispatcher(commandContext);
|
|
|
|
}
|
|
|
|
|
2012-07-01 22:21:02 +02:00
|
|
|
this._actionDispatcher.addEvent("modelUpdate", function (event) {
|
2011-09-07 03:12:11 +02:00
|
|
|
this.fireEvent("modelUpdate", event);
|
2011-08-05 03:12:53 +02:00
|
|
|
}.bind(this));
|
2011-09-07 03:12:11 +02:00
|
|
|
|
2011-08-05 03:12:53 +02:00
|
|
|
mindplot.ActionDispatcher.setInstance(this._actionDispatcher);
|
2012-02-02 00:31:40 +01:00
|
|
|
this._model = new mindplot.DesignerModel(options);
|
2011-08-25 04:41:39 +02:00
|
|
|
|
2011-07-27 19:53:32 +02:00
|
|
|
// Init Screen manager..
|
2011-08-27 00:41:50 +02:00
|
|
|
var screenManager = new mindplot.ScreenManager(divElement);
|
|
|
|
this._workspace = new mindplot.Workspace(screenManager, this._model.getZoom());
|
2012-01-31 00:17:47 +01:00
|
|
|
|
|
|
|
// Init layout manager ...
|
|
|
|
this._eventBussDispatcher = new mindplot.layout.EventBusDispatcher(this.getModel());
|
2011-07-27 19:53:32 +02:00
|
|
|
|
2011-08-19 18:38:37 +02:00
|
|
|
// Register events
|
2012-02-02 00:31:40 +01:00
|
|
|
if (!this.isReadOnly()) {
|
2011-08-19 18:38:37 +02:00
|
|
|
this._registerEvents();
|
2012-01-31 00:17:47 +01:00
|
|
|
this._dragManager = this._buildDragManager(this._workspace);
|
2011-08-19 18:38:37 +02:00
|
|
|
}
|
2011-10-09 22:59:16 +02:00
|
|
|
|
|
|
|
this._relPivot = new mindplot.RelationshipPivot(this._workspace, this);
|
2012-02-04 01:21:29 +01:00
|
|
|
|
|
|
|
// Set editor working area ...
|
|
|
|
this.setViewPort(options.viewPort);
|
|
|
|
|
2012-03-20 12:56:20 +01:00
|
|
|
mindplot.TopicEventDispatcher.configure(this.isReadOnly());
|
2011-08-19 18:38:37 +02:00
|
|
|
},
|
|
|
|
|
2012-03-19 11:44:59 +01:00
|
|
|
/**
|
|
|
|
* Deactivates the keyboard events so you can enter text into forms
|
|
|
|
*/
|
2012-07-01 22:21:02 +02:00
|
|
|
deactivateKeyboard:function () {
|
2012-03-19 11:44:59 +01:00
|
|
|
mindplot.DesignerKeyboard.getInstance().deactivate();
|
|
|
|
this.deselectAll();
|
|
|
|
},
|
2012-03-20 12:56:20 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Activates the keyboard events so you can enter text into forms
|
|
|
|
*/
|
2012-07-01 22:21:02 +02:00
|
|
|
activateKeyboard:function () {
|
2012-03-19 11:44:59 +01:00
|
|
|
mindplot.DesignerKeyboard.getInstance().activate();
|
|
|
|
},
|
|
|
|
|
|
|
|
|
2012-07-01 22:21:02 +02:00
|
|
|
_registerEvents:function () {
|
2011-08-19 18:38:37 +02:00
|
|
|
// Register mouse events ...
|
|
|
|
this._registerMouseEvents();
|
|
|
|
|
|
|
|
// Register keyboard events ...
|
2011-08-20 15:50:48 +02:00
|
|
|
mindplot.DesignerKeyboard.register(this);
|
2011-08-19 18:38:37 +02:00
|
|
|
},
|
|
|
|
|
2012-07-01 22:21:02 +02:00
|
|
|
addEvent:function (type, listener) {
|
2012-03-20 12:56:20 +01:00
|
|
|
if (type == mindplot.TopicEvent.EDIT || type == mindplot.TopicEvent.CLICK) {
|
|
|
|
var editor = mindplot.TopicEventDispatcher.getInstance();
|
2012-03-15 02:10:44 +01:00
|
|
|
editor.addEvent(type, listener);
|
|
|
|
} else {
|
|
|
|
this.parent(type, listener);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-07-01 22:21:02 +02:00
|
|
|
_registerMouseEvents:function () {
|
2011-08-19 18:38:37 +02:00
|
|
|
var workspace = this._workspace;
|
|
|
|
var screenManager = workspace.getScreenManager();
|
|
|
|
|
|
|
|
// Initialize workspace event listeners.
|
2012-07-01 22:21:02 +02:00
|
|
|
screenManager.addEvent('update', function () {
|
2011-08-20 15:50:48 +02:00
|
|
|
// Topic must be set to his original state. All editors must be closed.
|
2011-10-09 22:59:16 +02:00
|
|
|
var topics = this.getModel().getTopics();
|
2012-07-01 22:21:02 +02:00
|
|
|
topics.forEach(function (object) {
|
2011-08-20 15:50:48 +02:00
|
|
|
object.closeEditors();
|
|
|
|
});
|
|
|
|
|
2011-08-19 18:38:37 +02:00
|
|
|
// Clean some selected nodes on event ..
|
2011-08-27 00:41:50 +02:00
|
|
|
if (this._cleanScreen)
|
|
|
|
this._cleanScreen();
|
2011-08-19 18:38:37 +02:00
|
|
|
|
|
|
|
}.bind(this));
|
|
|
|
|
|
|
|
// Deselect on click ...
|
2012-07-01 22:21:02 +02:00
|
|
|
screenManager.addEvent('click', function (event) {
|
2011-08-19 18:38:37 +02:00
|
|
|
this.onObjectFocusEvent(null, event);
|
|
|
|
}.bind(this));
|
|
|
|
|
|
|
|
// Create nodes on double click...
|
2012-07-01 22:21:02 +02:00
|
|
|
screenManager.addEvent('dblclick', function (event) {
|
2011-08-19 18:38:37 +02:00
|
|
|
if (workspace.isWorkspaceEventsEnabled()) {
|
2012-01-17 04:51:13 +01:00
|
|
|
|
|
|
|
var mousePos = screenManager.getWorkspaceMousePosition(event);
|
|
|
|
|
2011-08-25 04:41:39 +02:00
|
|
|
var centralTopic = this.getModel().getCentralTopic();
|
2012-01-17 04:51:13 +01:00
|
|
|
var model = this._createChildModel(centralTopic, mousePos);
|
2012-01-14 18:16:59 +01:00
|
|
|
this._actionDispatcher.addTopic(model, centralTopic.getId());
|
2011-08-19 18:38:37 +02:00
|
|
|
}
|
|
|
|
}.bind(this));
|
2011-08-23 19:25:49 +02:00
|
|
|
|
|
|
|
|
2012-07-01 22:21:02 +02:00
|
|
|
$(document).addEvent('mousewheel', function (event) {
|
2012-03-15 03:37:54 +01:00
|
|
|
// Change mousewheel handling so we let the default
|
|
|
|
//event happen if we are outside the container.
|
|
|
|
var coords = screenManager.getContainer().getCoordinates();
|
|
|
|
var isOutsideContainer = event.client.y < coords.top ||
|
|
|
|
event.client.y > coords.bottom ||
|
|
|
|
event.client.x < coords.left ||
|
|
|
|
event.client.x > coords.right;
|
|
|
|
|
|
|
|
if (!isOutsideContainer) {
|
|
|
|
if (event.wheel > 0) {
|
|
|
|
this.zoomIn(1.05);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
this.zoomOut(1.05);
|
|
|
|
}
|
|
|
|
event.preventDefault();
|
2011-08-23 19:25:49 +02:00
|
|
|
}
|
|
|
|
}.bind(this));
|
|
|
|
|
2011-07-27 19:53:32 +02:00
|
|
|
},
|
2009-06-07 20:59:43 +02:00
|
|
|
|
2012-07-01 22:21:02 +02:00
|
|
|
_buildDragManager:function (workspace) {
|
2012-01-12 01:12:22 +01:00
|
|
|
|
2012-01-31 00:17:47 +01:00
|
|
|
var designerModel = this.getModel();
|
|
|
|
var dragConnector = new mindplot.DragConnector(designerModel, this._workspace);
|
|
|
|
var dragManager = new mindplot.DragManager(workspace, this._eventBussDispatcher);
|
|
|
|
var topics = designerModel.getTopics();
|
2012-01-12 01:12:22 +01:00
|
|
|
|
2012-07-01 22:21:02 +02:00
|
|
|
dragManager.addEvent('startdragging', function () {
|
2012-01-12 01:12:22 +01:00
|
|
|
// Enable all mouse events.
|
|
|
|
for (var i = 0; i < topics.length; i++) {
|
|
|
|
topics[i].setMouseEventsEnabled(false);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2012-07-01 22:21:02 +02:00
|
|
|
dragManager.addEvent('dragging', function (event, dragTopic) {
|
2012-01-18 05:26:39 +01:00
|
|
|
dragTopic.updateFreeLayout(event);
|
|
|
|
if (!dragTopic.isFreeLayoutOn(event)) {
|
|
|
|
// The node is being drag. Is the connection still valid ?
|
|
|
|
dragConnector.checkConnection(dragTopic);
|
2012-01-21 13:37:01 +01:00
|
|
|
|
|
|
|
if (!dragTopic.isVisible() && dragTopic.isConnected()) {
|
|
|
|
dragTopic.setVisibility(true);
|
|
|
|
}
|
2012-01-21 22:02:38 +01:00
|
|
|
}
|
2012-01-12 01:12:22 +01:00
|
|
|
});
|
|
|
|
|
2012-07-01 22:21:02 +02:00
|
|
|
dragManager.addEvent('enddragging', function (event, dragTopic) {
|
2012-01-12 01:12:22 +01:00
|
|
|
for (var i = 0; i < topics.length; i++) {
|
|
|
|
topics[i].setMouseEventsEnabled(true);
|
|
|
|
}
|
2012-01-21 13:37:01 +01:00
|
|
|
dragTopic.applyChanges(workspace);
|
2012-01-12 01:12:22 +01:00
|
|
|
});
|
|
|
|
|
2012-01-31 00:17:47 +01:00
|
|
|
return dragManager;
|
2012-01-12 01:12:22 +01:00
|
|
|
},
|
|
|
|
|
2012-07-01 22:21:02 +02:00
|
|
|
setViewPort:function (size) {
|
2011-08-27 00:41:50 +02:00
|
|
|
this._workspace.setViewPort(size);
|
2011-08-28 16:38:15 +02:00
|
|
|
var model = this.getModel();
|
|
|
|
this._workspace.setZoom(model.getZoom(), true);
|
2011-08-27 00:41:50 +02:00
|
|
|
},
|
2011-07-27 19:53:32 +02:00
|
|
|
|
2012-03-07 21:40:10 +01:00
|
|
|
|
2012-07-01 22:21:02 +02:00
|
|
|
_buildNodeGraph:function (model, readOnly) {
|
2011-07-27 19:53:32 +02:00
|
|
|
var workspace = this._workspace;
|
|
|
|
|
|
|
|
// Create node graph ...
|
2012-02-02 00:31:40 +01:00
|
|
|
var topic = mindplot.NodeGraph.create(model, {readOnly:readOnly});
|
2011-07-27 19:53:32 +02:00
|
|
|
|
|
|
|
// Append it to the workspace ...
|
2011-08-25 04:41:39 +02:00
|
|
|
this.getModel().addTopic(topic);
|
2011-08-20 15:50:48 +02:00
|
|
|
|
2011-07-27 19:53:32 +02:00
|
|
|
// Add Topic events ...
|
2012-02-02 00:31:40 +01:00
|
|
|
if (!readOnly) {
|
2011-08-20 15:50:48 +02:00
|
|
|
// If a node had gained focus, clean the rest of the nodes ...
|
2012-07-01 22:21:02 +02:00
|
|
|
topic.addEvent('mousedown', function (event) {
|
2011-08-20 15:50:48 +02:00
|
|
|
this.onObjectFocusEvent(topic, event);
|
|
|
|
}.bind(this));
|
2012-01-12 01:12:22 +01:00
|
|
|
|
|
|
|
// Register node listeners ...
|
|
|
|
if (topic.getType() != mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE) {
|
|
|
|
|
|
|
|
// Central Topic doesn't support to be dragged
|
2012-02-02 00:31:40 +01:00
|
|
|
this._dragManager.add(topic);
|
2012-01-12 01:12:22 +01:00
|
|
|
}
|
2011-08-20 15:50:48 +02:00
|
|
|
}
|
2011-07-27 19:53:32 +02:00
|
|
|
|
|
|
|
// Connect Topic ...
|
|
|
|
var isConnected = model.isConnected();
|
|
|
|
if (isConnected) {
|
|
|
|
// Improve this ...
|
|
|
|
var targetTopicModel = model.getParent();
|
|
|
|
var targetTopic = null;
|
|
|
|
|
2011-09-06 06:03:27 +02:00
|
|
|
var topics = this.getModel().getTopics();
|
2011-07-27 19:53:32 +02:00
|
|
|
for (var i = 0; i < topics.length; i++) {
|
|
|
|
var t = topics[i];
|
|
|
|
if (t.getModel() == targetTopicModel) {
|
|
|
|
targetTopic = t;
|
|
|
|
// Disconnect the node. It will be connected again later ...
|
|
|
|
model.disconnect();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$assert(targetTopic, "Could not find a topic to connect");
|
|
|
|
topic.connectTo(targetTopic, workspace);
|
2009-06-07 20:59:43 +02:00
|
|
|
}
|
|
|
|
|
2012-07-01 22:21:02 +02:00
|
|
|
topic.addEvent('ontblur', function () {
|
2011-10-04 06:16:29 +02:00
|
|
|
var topics = this.getModel().filterSelectedTopics();
|
|
|
|
var rels = this.getModel().filterSelectedRelations();
|
|
|
|
|
|
|
|
if (topics.length == 0 || rels.length == 0) {
|
|
|
|
this.fireEvent('onblur');
|
|
|
|
}
|
|
|
|
}.bind(this));
|
|
|
|
|
2012-07-01 22:21:02 +02:00
|
|
|
topic.addEvent('ontfocus', function () {
|
2011-10-04 06:16:29 +02:00
|
|
|
var topics = this.getModel().filterSelectedTopics();
|
|
|
|
var rels = this.getModel().filterSelectedRelations();
|
|
|
|
|
|
|
|
if (topics.length == 1 || rels.length == 1) {
|
|
|
|
this.fireEvent('onfocus');
|
|
|
|
}
|
|
|
|
}.bind(this));
|
|
|
|
|
2011-07-27 19:53:32 +02:00
|
|
|
return topic;
|
2011-08-20 15:50:48 +02:00
|
|
|
},
|
2011-07-27 19:53:32 +02:00
|
|
|
|
2012-07-01 22:21:02 +02:00
|
|
|
onObjectFocusEvent:function (currentObject, event) {
|
2011-08-20 15:50:48 +02:00
|
|
|
// Close node editors ..
|
2011-08-25 04:41:39 +02:00
|
|
|
var topics = this.getModel().getTopics();
|
2012-07-01 22:21:02 +02:00
|
|
|
topics.forEach(function (topic) {
|
2011-08-20 15:50:48 +02:00
|
|
|
topic.closeEditors();
|
|
|
|
});
|
2011-08-05 06:06:56 +02:00
|
|
|
|
2011-08-25 04:41:39 +02:00
|
|
|
var model = this.getModel();
|
|
|
|
var objects = model.getObjects();
|
2012-07-01 22:21:02 +02:00
|
|
|
objects.forEach(function (object) {
|
2011-08-20 15:50:48 +02:00
|
|
|
// Disable all nodes on focus but not the current if Ctrl key isn't being pressed
|
2011-11-29 04:51:38 +01:00
|
|
|
if (!$defined(event) || (!event.control && !event.meta)) {
|
2011-08-19 18:38:37 +02:00
|
|
|
if (object.isOnFocus() && object != currentObject) {
|
|
|
|
object.setOnFocus(false);
|
2011-07-27 19:53:32 +02:00
|
|
|
}
|
2011-08-20 15:50:48 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2011-07-27 19:53:32 +02:00
|
|
|
},
|
2009-06-07 20:59:43 +02:00
|
|
|
|
2012-07-01 22:21:02 +02:00
|
|
|
selectAll:function () {
|
2011-08-25 04:41:39 +02:00
|
|
|
var model = this.getModel();
|
|
|
|
var objects = model.getObjects();
|
2012-07-01 22:21:02 +02:00
|
|
|
objects.forEach(function (object) {
|
2011-08-19 18:38:37 +02:00
|
|
|
object.setOnFocus(true);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2012-07-01 22:21:02 +02:00
|
|
|
deselectAll:function () {
|
2011-08-25 04:41:39 +02:00
|
|
|
var objects = this.getModel().getObjects();
|
2012-07-01 22:21:02 +02:00
|
|
|
objects.forEach(function (object) {
|
2011-08-19 18:38:37 +02:00
|
|
|
object.setOnFocus(false);
|
|
|
|
});
|
|
|
|
},
|
2012-03-20 12:56:20 +01:00
|
|
|
|
2012-03-19 11:44:59 +01:00
|
|
|
/**
|
|
|
|
* Set the zoom of the map.
|
|
|
|
* @param: zoom: number between 0.3 and 1.9
|
|
|
|
*/
|
2012-07-01 22:21:02 +02:00
|
|
|
setZoom:function (zoom) {
|
2012-03-19 11:44:59 +01:00
|
|
|
if (zoom > 1.9 || zoom < 0.3) {
|
2012-07-01 22:21:02 +02:00
|
|
|
$notify($msg('ZOOM_IN_ERROR'));
|
2012-03-19 11:44:59 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.getModel().setZoom(zoom);
|
|
|
|
this._workspace.setZoom(zoom);
|
|
|
|
},
|
|
|
|
|
2012-07-01 22:21:02 +02:00
|
|
|
zoomOut:function (factor) {
|
2011-08-25 05:01:17 +02:00
|
|
|
if (!factor)
|
|
|
|
factor = 1.2;
|
|
|
|
|
|
|
|
var model = this.getModel();
|
|
|
|
var scale = model.getZoom() * factor;
|
|
|
|
if (scale <= 1.9) {
|
|
|
|
model.setZoom(scale);
|
|
|
|
this._workspace.setZoom(scale);
|
|
|
|
}
|
|
|
|
else {
|
2012-07-01 22:21:02 +02:00
|
|
|
$notify($msg('ZOOM_ERROR'));
|
2011-08-25 05:01:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2012-07-01 22:21:02 +02:00
|
|
|
zoomIn:function (factor) {
|
2011-08-23 19:25:49 +02:00
|
|
|
if (!factor)
|
|
|
|
factor = 1.2;
|
|
|
|
|
2011-08-25 04:41:39 +02:00
|
|
|
var model = this.getModel();
|
|
|
|
var scale = model.getZoom() / factor;
|
2011-08-25 05:01:17 +02:00
|
|
|
|
2011-07-27 19:53:32 +02:00
|
|
|
if (scale >= 0.3) {
|
2011-08-25 04:41:39 +02:00
|
|
|
model.setZoom(scale);
|
2011-08-25 05:01:17 +02:00
|
|
|
this._workspace.setZoom(scale);
|
2011-07-27 19:53:32 +02:00
|
|
|
}
|
|
|
|
else {
|
2012-07-01 22:21:02 +02:00
|
|
|
$notify($msg('ZOOM_ERROR'));
|
2011-07-27 19:53:32 +02:00
|
|
|
}
|
2011-08-25 04:41:39 +02:00
|
|
|
},
|
|
|
|
|
2012-07-01 22:21:02 +02:00
|
|
|
getModel:function () {
|
2011-08-25 04:41:39 +02:00
|
|
|
return this._model;
|
|
|
|
},
|
2009-06-07 20:59:43 +02:00
|
|
|
|
2012-07-03 03:54:59 +02:00
|
|
|
|
|
|
|
shrinkSelectedBranch:function () {
|
|
|
|
var nodes = this.getModel().filterSelectedTopics();
|
|
|
|
if (nodes.length <= 0) {
|
|
|
|
// If there are more than one node selected,
|
|
|
|
$notify($msg('ONE_TOPIC_MUST_BE_SELECTED'));
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
if (nodes.length != 1) {
|
|
|
|
// If there are more than one node selected,
|
|
|
|
$notify($msg('ONLY_ONE_TOPIC_MUST_BE_SELECTED'));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Execute event ...
|
|
|
|
var topic = nodes[0];
|
|
|
|
this._actionDispatcher.shrinkBranch([topic.getId()], !topic.areChildrenShrunken());
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2012-07-01 22:21:02 +02:00
|
|
|
createChildForSelectedNode:function () {
|
2011-08-25 04:41:39 +02:00
|
|
|
var nodes = this.getModel().filterSelectedTopics();
|
2011-07-27 19:53:32 +02:00
|
|
|
if (nodes.length <= 0) {
|
|
|
|
// If there are more than one node selected,
|
2012-07-01 22:21:02 +02:00
|
|
|
$notify($msg('ONE_TOPIC_MUST_BE_SELECTED'));
|
2011-07-27 19:53:32 +02:00
|
|
|
return;
|
2009-06-07 20:59:43 +02:00
|
|
|
|
2011-07-27 19:53:32 +02:00
|
|
|
}
|
2011-09-10 02:53:41 +02:00
|
|
|
if (nodes.length != 1) {
|
2009-06-07 20:59:43 +02:00
|
|
|
|
2011-07-27 19:53:32 +02:00
|
|
|
// If there are more than one node selected,
|
2012-07-01 22:21:02 +02:00
|
|
|
$notify($msg('ONLY_ONE_TOPIC_MUST_BE_SELECTED'));
|
2011-07-27 19:53:32 +02:00
|
|
|
return;
|
|
|
|
}
|
2009-06-07 20:59:43 +02:00
|
|
|
|
2011-07-27 19:53:32 +02:00
|
|
|
// Add new node ...
|
2011-09-10 02:53:41 +02:00
|
|
|
var parentTopic = nodes[0];
|
|
|
|
var parentTopicId = parentTopic.getId();
|
2012-01-14 13:58:06 +01:00
|
|
|
var childModel = this._createChildModel(parentTopic);
|
2009-06-07 20:59:43 +02:00
|
|
|
|
2011-08-03 22:52:39 +02:00
|
|
|
// Execute event ...
|
|
|
|
this._actionDispatcher.addTopic(childModel, parentTopicId, true);
|
|
|
|
|
2011-08-20 15:50:48 +02:00
|
|
|
},
|
2009-06-07 20:59:43 +02:00
|
|
|
|
2012-07-01 22:21:02 +02:00
|
|
|
_createChildModel:function (topic, mousePos) {
|
2012-01-14 13:58:06 +01:00
|
|
|
// Create a new node ...
|
|
|
|
var model = topic.getModel();
|
|
|
|
var mindmap = model.getMindmap();
|
2012-03-15 02:10:44 +01:00
|
|
|
var childModel = mindmap.createNode();
|
2012-01-14 13:58:06 +01:00
|
|
|
|
|
|
|
// Create a new node ...
|
|
|
|
var layoutManager = this._eventBussDispatcher.getLayoutManager();
|
2012-02-02 15:30:12 +01:00
|
|
|
var result = layoutManager.predict(topic.getId(), null, mousePos);
|
2012-01-14 13:58:06 +01:00
|
|
|
childModel.setOrder(result.order);
|
|
|
|
|
|
|
|
var position = result.position;
|
|
|
|
childModel.setPosition(position.x, position.y);
|
|
|
|
|
|
|
|
return childModel;
|
|
|
|
},
|
|
|
|
|
2012-07-01 22:21:02 +02:00
|
|
|
addDraggedNode:function (event, model) {
|
2012-03-07 21:40:10 +01:00
|
|
|
$assert(event, "event can not be null");
|
2012-03-15 02:10:44 +01:00
|
|
|
$assert(model, "model can not be null");
|
2012-03-07 21:40:10 +01:00
|
|
|
|
|
|
|
// Position far from the visual area ...
|
|
|
|
model.setPosition(1000, 1000);
|
|
|
|
|
|
|
|
this._actionDispatcher.addTopic(model, null, false);
|
|
|
|
var topic = this.getModel().findTopicById(model.getId());
|
|
|
|
|
|
|
|
// Simulate a mouse down event to start the dragging ...
|
|
|
|
topic.fireEvent("mousedown", event);
|
|
|
|
},
|
|
|
|
|
2012-07-01 22:21:02 +02:00
|
|
|
createSiblingForSelectedNode:function () {
|
2011-08-25 04:41:39 +02:00
|
|
|
var nodes = this.getModel().filterSelectedTopics();
|
2011-07-27 19:53:32 +02:00
|
|
|
if (nodes.length <= 0) {
|
2012-03-14 21:47:59 +01:00
|
|
|
// If there are no nodes selected,
|
2012-07-01 22:21:02 +02:00
|
|
|
$notify($msg('ONE_TOPIC_MUST_BE_SELECTED'));
|
2011-07-27 19:53:32 +02:00
|
|
|
return;
|
2009-06-07 20:59:43 +02:00
|
|
|
|
2011-07-27 19:53:32 +02:00
|
|
|
}
|
|
|
|
if (nodes.length > 1) {
|
|
|
|
// If there are more than one node selected,
|
2012-07-01 22:21:02 +02:00
|
|
|
$notify($msg('ONLY_ONE_TOPIC_MUST_BE_SELECTED'));
|
2011-07-27 19:53:32 +02:00
|
|
|
return;
|
|
|
|
}
|
2009-06-07 20:59:43 +02:00
|
|
|
|
2011-07-27 19:53:32 +02:00
|
|
|
var topic = nodes[0];
|
2011-09-08 15:03:42 +02:00
|
|
|
if (topic.getType() == mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE) {
|
2011-07-27 19:53:32 +02:00
|
|
|
// Central topic doesn't have siblings ...
|
|
|
|
this.createChildForSelectedNode();
|
2009-06-07 20:59:43 +02:00
|
|
|
|
2011-07-27 19:53:32 +02:00
|
|
|
} else {
|
|
|
|
var parentTopic = topic.getOutgoingConnectedTopic();
|
2012-01-14 13:58:06 +01:00
|
|
|
var siblingModel = this._createSiblingModel(topic);
|
2012-03-14 21:47:59 +01:00
|
|
|
|
|
|
|
// Hack: if parent is central topic, add node below not on opposite side.
|
|
|
|
// This should be done in the layout
|
|
|
|
if (parentTopic.getType() == mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE) {
|
|
|
|
siblingModel.setOrder(topic.getOrder() + 2);
|
|
|
|
}
|
|
|
|
|
2011-07-27 19:53:32 +02:00
|
|
|
var parentTopicId = parentTopic.getId();
|
2011-08-03 22:52:39 +02:00
|
|
|
this._actionDispatcher.addTopic(siblingModel, parentTopicId, true);
|
2009-06-07 20:59:43 +02:00
|
|
|
}
|
2011-08-25 05:17:13 +02:00
|
|
|
},
|
2011-07-27 19:53:32 +02:00
|
|
|
|
2012-07-01 22:21:02 +02:00
|
|
|
_createSiblingModel:function (topic) {
|
2012-01-14 13:58:06 +01:00
|
|
|
var result = null;
|
|
|
|
var parentTopic = topic.getOutgoingConnectedTopic();
|
|
|
|
if (parentTopic != null) {
|
|
|
|
|
|
|
|
// Create a new node ...
|
|
|
|
var model = topic.getModel();
|
|
|
|
var mindmap = model.getMindmap();
|
2012-03-15 02:10:44 +01:00
|
|
|
result = mindmap.createNode();
|
2012-01-14 13:58:06 +01:00
|
|
|
|
|
|
|
// Create a new node ...
|
|
|
|
var order = topic.getOrder() + 1;
|
|
|
|
result.setOrder(order);
|
|
|
|
result.setPosition(10, 10); // Set a dummy pisition ...
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
},
|
|
|
|
|
2012-07-01 22:21:02 +02:00
|
|
|
showRelPivot:function (event) {
|
2011-10-09 22:59:16 +02:00
|
|
|
// Current mouse position ....
|
2011-07-27 19:53:32 +02:00
|
|
|
var screen = this._workspace.getScreenManager();
|
|
|
|
var pos = screen.getWorkspaceMousePosition(event);
|
2011-10-09 22:59:16 +02:00
|
|
|
var selectedTopic = this.getModel().selectedTopic();
|
2011-07-27 19:53:32 +02:00
|
|
|
|
2011-10-09 22:59:16 +02:00
|
|
|
// create a connection ...
|
|
|
|
this._relPivot.start(selectedTopic, pos);
|
2011-08-20 15:50:48 +02:00
|
|
|
},
|
2011-07-27 19:53:32 +02:00
|
|
|
|
2012-07-01 22:21:02 +02:00
|
|
|
connectByRelation:function (sourceTopic, targetTopic) {
|
2011-10-09 22:59:16 +02:00
|
|
|
$assert(sourceTopic, "sourceTopic can not be null");
|
|
|
|
$assert(targetTopic, "targetTopic can not be null");
|
2011-07-27 19:53:32 +02:00
|
|
|
|
|
|
|
// Create a new topic model ...
|
2011-10-09 23:38:41 +02:00
|
|
|
// @Todo: Model should not be modified from here ...
|
2011-07-27 19:53:32 +02:00
|
|
|
var mindmap = this.getMindmap();
|
2011-10-09 22:59:16 +02:00
|
|
|
var model = mindmap.createRelationship(sourceTopic.getModel().getId(), targetTopic.getModel().getId());
|
2011-10-09 23:38:41 +02:00
|
|
|
|
2011-10-09 22:59:16 +02:00
|
|
|
this._actionDispatcher.connectByRelation(model);
|
2011-08-25 04:41:39 +02:00
|
|
|
},
|
2011-07-27 19:53:32 +02:00
|
|
|
|
2012-07-01 22:21:02 +02:00
|
|
|
needsSave:function () {
|
2011-10-02 19:47:54 +02:00
|
|
|
//@Todo: Review all this ...
|
2011-10-15 18:23:27 +02:00
|
|
|
return this._actionDispatcher._actionRunner.hasBeenChanged();
|
2011-07-27 19:53:32 +02:00
|
|
|
},
|
|
|
|
|
2009-06-07 20:59:43 +02:00
|
|
|
|
2012-07-01 22:21:02 +02:00
|
|
|
getMindmapProperties:function () {
|
2012-01-12 03:30:26 +01:00
|
|
|
return {zoom:this.getModel().getZoom()};
|
2011-08-25 04:41:39 +02:00
|
|
|
},
|
2009-06-07 20:59:43 +02:00
|
|
|
|
2012-07-01 22:21:02 +02:00
|
|
|
loadMap:function (mindmapModel) {
|
2011-09-08 14:16:50 +02:00
|
|
|
$assert(mindmapModel, "mindmapModel can not be null");
|
|
|
|
this._mindmap = mindmapModel;
|
2009-06-07 20:59:43 +02:00
|
|
|
|
2012-03-08 04:30:27 +01:00
|
|
|
// try {
|
2012-03-15 02:10:44 +01:00
|
|
|
// Init layout manager ...
|
2012-07-01 22:21:02 +02:00
|
|
|
var size = {width:25, height:25};
|
2012-03-15 02:10:44 +01:00
|
|
|
var layoutManager = new mindplot.layout.LayoutManager(mindmapModel.getCentralTopic().getId(), size);
|
2012-07-01 22:21:02 +02:00
|
|
|
layoutManager.addEvent('change', function (event) {
|
2012-03-15 02:10:44 +01:00
|
|
|
var id = event.getId();
|
|
|
|
var topic = this.getModel().findTopicById(id);
|
|
|
|
topic.setPosition(event.getPosition());
|
|
|
|
topic.setOrder(event.getOrder());
|
|
|
|
}.bind(this));
|
|
|
|
this._eventBussDispatcher.setLayoutManager(layoutManager);
|
2012-01-21 22:02:38 +01:00
|
|
|
|
|
|
|
|
2012-03-15 02:10:44 +01:00
|
|
|
// Building node graph ...
|
|
|
|
var branches = mindmapModel.getBranches();
|
|
|
|
for (var i = 0; i < branches.length; i++) {
|
|
|
|
// NodeModel -> NodeGraph ...
|
|
|
|
var nodeModel = branches[i];
|
|
|
|
var nodeGraph = this._nodeModelToNodeGraph(nodeModel, false);
|
2009-06-07 20:59:43 +02:00
|
|
|
|
2012-03-15 02:10:44 +01:00
|
|
|
// Update shrink render state...
|
|
|
|
nodeGraph.setBranchVisibility(true);
|
|
|
|
}
|
2011-11-14 01:18:34 +01:00
|
|
|
|
2012-03-15 02:10:44 +01:00
|
|
|
var relationships = mindmapModel.getRelationships();
|
|
|
|
for (var j = 0; j < relationships.length; j++) {
|
|
|
|
this._relationshipModelToRelationship(relationships[j]);
|
|
|
|
}
|
2009-06-07 20:59:43 +02:00
|
|
|
|
2012-03-15 02:10:44 +01:00
|
|
|
// Place the focus on the Central Topic
|
|
|
|
var centralTopic = this.getModel().getCentralTopic();
|
|
|
|
this.goToNode(centralTopic);
|
2012-01-10 03:50:52 +01:00
|
|
|
|
2012-03-15 02:10:44 +01:00
|
|
|
// Finally, sort the map ...
|
|
|
|
mindplot.EventBus.instance.fireEvent(mindplot.EventBus.events.DoLayout);
|
2012-02-04 16:51:50 +01:00
|
|
|
|
2012-03-15 02:10:44 +01:00
|
|
|
this.fireEvent('loadSuccess');
|
2012-03-08 04:30:27 +01:00
|
|
|
// } catch(e) {
|
|
|
|
// this.fireEvent('loadError', e);
|
|
|
|
// }
|
2011-09-07 03:12:11 +02:00
|
|
|
},
|
2009-06-07 20:59:43 +02:00
|
|
|
|
2012-07-01 22:21:02 +02:00
|
|
|
getMindmap:function () {
|
2011-07-27 19:53:32 +02:00
|
|
|
return this._mindmap;
|
2011-08-25 04:41:39 +02:00
|
|
|
},
|
2009-06-07 20:59:43 +02:00
|
|
|
|
2012-07-01 22:21:02 +02:00
|
|
|
undo:function () {
|
2011-10-15 18:23:27 +02:00
|
|
|
// @Todo: This is a hack...
|
|
|
|
this._actionDispatcher._actionRunner.undo();
|
2011-08-25 04:41:39 +02:00
|
|
|
},
|
2009-06-07 20:59:43 +02:00
|
|
|
|
2012-07-01 22:21:02 +02:00
|
|
|
redo:function () {
|
2011-10-15 18:23:27 +02:00
|
|
|
this._actionDispatcher._actionRunner.redo();
|
2011-08-25 04:41:39 +02:00
|
|
|
},
|
2009-06-07 20:59:43 +02:00
|
|
|
|
2012-07-01 22:21:02 +02:00
|
|
|
isReadOnly:function () {
|
2012-02-02 00:31:40 +01:00
|
|
|
return this._options.readOnly;
|
|
|
|
},
|
|
|
|
|
2012-07-01 22:21:02 +02:00
|
|
|
_nodeModelToNodeGraph:function (nodeModel, isVisible) {
|
2011-07-27 19:53:32 +02:00
|
|
|
$assert(nodeModel, "Node model can not be null");
|
2012-01-12 04:49:18 +01:00
|
|
|
var children = nodeModel.getChildren().slice();
|
2012-07-01 22:21:02 +02:00
|
|
|
children = children.sort(function (a, b) {
|
2012-01-14 14:45:39 +01:00
|
|
|
return a.getOrder() - b.getOrder()
|
|
|
|
});
|
2012-01-12 04:49:18 +01:00
|
|
|
|
2012-02-02 00:31:40 +01:00
|
|
|
var nodeGraph = this._buildNodeGraph(nodeModel, this.isReadOnly());
|
2009-06-07 20:59:43 +02:00
|
|
|
|
2012-01-12 04:49:18 +01:00
|
|
|
if (isVisible) {
|
2011-07-27 19:53:32 +02:00
|
|
|
nodeGraph.setVisibility(isVisible);
|
2012-01-12 04:49:18 +01:00
|
|
|
}
|
2011-02-09 15:29:09 +01:00
|
|
|
|
2012-01-12 04:49:18 +01:00
|
|
|
this._workspace.appendChild(nodeGraph);
|
2011-07-27 19:53:32 +02:00
|
|
|
for (var i = 0; i < children.length; i++) {
|
|
|
|
var child = children[i];
|
|
|
|
if ($defined(child))
|
2011-08-05 06:06:56 +02:00
|
|
|
this._nodeModelToNodeGraph(child, false);
|
2011-07-27 19:53:32 +02:00
|
|
|
}
|
2009-06-07 20:59:43 +02:00
|
|
|
|
2011-07-27 19:53:32 +02:00
|
|
|
return nodeGraph;
|
2011-11-14 01:18:34 +01:00
|
|
|
},
|
2011-07-27 19:53:32 +02:00
|
|
|
|
2012-07-01 22:21:02 +02:00
|
|
|
_relationshipModelToRelationship:function (model) {
|
2011-07-27 19:53:32 +02:00
|
|
|
$assert(model, "Node model can not be null");
|
2011-10-09 22:59:16 +02:00
|
|
|
|
2011-07-27 19:53:32 +02:00
|
|
|
var relationship = this._buildRelationship(model);
|
|
|
|
var sourceTopic = relationship.getSourceTopic();
|
2011-10-09 22:59:16 +02:00
|
|
|
sourceTopic.connectByRelation(relationship);
|
|
|
|
|
2011-07-27 19:53:32 +02:00
|
|
|
var targetTopic = relationship.getTargetTopic();
|
2011-10-09 22:59:16 +02:00
|
|
|
targetTopic.connectByRelation(relationship);
|
2011-07-27 19:53:32 +02:00
|
|
|
relationship.setVisibility(sourceTopic.isVisible() && targetTopic.isVisible());
|
2011-10-09 22:59:16 +02:00
|
|
|
|
2011-07-27 19:53:32 +02:00
|
|
|
var workspace = this._workspace;
|
|
|
|
workspace.appendChild(relationship);
|
|
|
|
relationship.redraw();
|
|
|
|
return relationship;
|
2011-10-09 22:59:16 +02:00
|
|
|
},
|
2011-07-27 19:53:32 +02:00
|
|
|
|
2012-07-01 22:21:02 +02:00
|
|
|
createRelationship:function (model) {
|
2011-07-27 19:53:32 +02:00
|
|
|
this._mindmap.addRelationship(model);
|
|
|
|
return this._relationshipModelToRelationship(model);
|
2011-08-20 15:50:48 +02:00
|
|
|
},
|
2011-07-27 19:53:32 +02:00
|
|
|
|
2012-07-01 22:21:02 +02:00
|
|
|
removeRelationship:function (model) {
|
2011-07-27 19:53:32 +02:00
|
|
|
this._mindmap.removeRelationship(model);
|
|
|
|
var relationship = this._relationships[model.getId()];
|
|
|
|
var sourceTopic = relationship.getSourceTopic();
|
|
|
|
sourceTopic.removeRelationship(relationship);
|
|
|
|
var targetTopic = relationship.getTargetTopic();
|
|
|
|
targetTopic.removeRelationship(relationship);
|
|
|
|
this._workspace.removeChild(relationship);
|
|
|
|
delete this._relationships[model.getId()];
|
2011-08-20 15:50:48 +02:00
|
|
|
},
|
2011-07-27 19:53:32 +02:00
|
|
|
|
2012-07-01 22:21:02 +02:00
|
|
|
_buildRelationship:function (model) {
|
2011-07-27 19:53:32 +02:00
|
|
|
var elem = this;
|
|
|
|
|
2011-10-09 22:59:16 +02:00
|
|
|
var fromNodeId = model.getFromNode();
|
|
|
|
var toNodeId = model.getToNode();
|
2011-07-27 19:53:32 +02:00
|
|
|
|
2011-10-09 22:59:16 +02:00
|
|
|
var sourceTopic = null;
|
|
|
|
var targetTopic = null;
|
|
|
|
var dmodel = this.getModel();
|
|
|
|
var topics = dmodel.getTopics();
|
2011-07-27 19:53:32 +02:00
|
|
|
|
|
|
|
for (var i = 0; i < topics.length; i++) {
|
|
|
|
var t = topics[i];
|
|
|
|
if (t.getModel().getId() == fromNodeId) {
|
2011-10-09 22:59:16 +02:00
|
|
|
sourceTopic = t;
|
2011-07-27 19:53:32 +02:00
|
|
|
}
|
|
|
|
if (t.getModel().getId() == toNodeId) {
|
2011-10-09 22:59:16 +02:00
|
|
|
targetTopic = t;
|
2011-07-27 19:53:32 +02:00
|
|
|
}
|
2011-10-09 22:59:16 +02:00
|
|
|
if (targetTopic != null && sourceTopic != null) {
|
2011-07-27 19:53:32 +02:00
|
|
|
break;
|
|
|
|
}
|
2011-01-11 22:54:20 +01:00
|
|
|
}
|
2011-07-27 19:53:32 +02:00
|
|
|
|
|
|
|
// Create node graph ...
|
2011-10-09 22:59:16 +02:00
|
|
|
var relationLine = new mindplot.RelationshipLine(sourceTopic, targetTopic, model.getLineType());
|
|
|
|
if ($defined(model.getSrcCtrlPoint())) {
|
|
|
|
var srcPoint = model.getSrcCtrlPoint().clone();
|
2011-07-27 19:53:32 +02:00
|
|
|
relationLine.setSrcControlPoint(srcPoint);
|
2011-01-11 22:54:20 +01:00
|
|
|
}
|
2011-10-09 22:59:16 +02:00
|
|
|
if ($defined(model.getDestCtrlPoint())) {
|
|
|
|
var destPoint = model.getDestCtrlPoint().clone();
|
2011-07-27 19:53:32 +02:00
|
|
|
relationLine.setDestControlPoint(destPoint);
|
2010-12-13 15:07:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-07-27 19:53:32 +02:00
|
|
|
relationLine.getLine().setDashed(3, 2);
|
2011-10-09 22:59:16 +02:00
|
|
|
relationLine.setShowEndArrow(model.getEndArrow());
|
|
|
|
relationLine.setShowStartArrow(model.getStartArrow());
|
|
|
|
relationLine.setModel(model);
|
2009-06-07 20:59:43 +02:00
|
|
|
|
2011-07-27 19:53:32 +02:00
|
|
|
//Add Listeners
|
2012-07-01 22:21:02 +02:00
|
|
|
relationLine.addEvent('onfocus', function (event) {
|
2011-10-09 22:59:16 +02:00
|
|
|
elem.onObjectFocusEvent(relationLine, event);
|
2011-07-27 19:53:32 +02:00
|
|
|
});
|
2009-06-07 20:59:43 +02:00
|
|
|
|
2011-07-27 19:53:32 +02:00
|
|
|
// Append it to the workspace ...
|
2011-10-09 22:59:16 +02:00
|
|
|
dmodel.addRelationship(model.getId(), relationLine);
|
2009-06-07 20:59:43 +02:00
|
|
|
|
2011-07-27 19:53:32 +02:00
|
|
|
return relationLine;
|
2011-08-20 15:50:48 +02:00
|
|
|
},
|
2009-06-07 20:59:43 +02:00
|
|
|
|
2012-07-01 22:21:02 +02:00
|
|
|
_removeNode:function (node) {
|
2011-09-08 15:03:42 +02:00
|
|
|
if (node.getTopicType() != mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE) {
|
2011-07-27 19:53:32 +02:00
|
|
|
var parent = node._parent;
|
|
|
|
node.disconnect(this._workspace);
|
|
|
|
|
|
|
|
//remove children
|
2012-03-07 05:13:50 +01:00
|
|
|
while (node.getChildren().length > 0) {
|
|
|
|
this._removeNode(node.getChildren()[0]);
|
2011-07-27 19:53:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
this._workspace.removeChild(node);
|
2011-08-25 04:41:39 +02:00
|
|
|
this.getModel().removeTopic(node);
|
2011-07-27 19:53:32 +02:00
|
|
|
|
|
|
|
// Delete this node from the model...
|
|
|
|
var model = node.getModel();
|
|
|
|
model.deleteNode();
|
|
|
|
|
|
|
|
if ($defined(parent)) {
|
2011-08-19 18:38:37 +02:00
|
|
|
this.goToNode(parent);
|
2011-07-27 19:53:32 +02:00
|
|
|
}
|
|
|
|
}
|
2011-08-20 15:50:48 +02:00
|
|
|
},
|
2011-07-27 19:53:32 +02:00
|
|
|
|
2012-07-01 22:21:02 +02:00
|
|
|
deleteCurrentNode:function () {
|
2011-07-27 19:53:32 +02:00
|
|
|
|
2012-07-01 22:21:02 +02:00
|
|
|
var validateFunc = function (object) {
|
2011-09-08 15:03:42 +02:00
|
|
|
return object.getType() == mindplot.RelationshipLine.type || object.getTopicType() != mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE
|
2009-06-07 20:59:43 +02:00
|
|
|
};
|
2011-07-27 19:53:32 +02:00
|
|
|
var validateError = 'Central topic can not be deleted.';
|
2011-09-06 06:03:27 +02:00
|
|
|
|
2011-08-25 04:41:39 +02:00
|
|
|
var model = this.getModel();
|
2011-09-06 06:03:27 +02:00
|
|
|
var topicsIds = model.filterTopicsIds(validateFunc, validateError);
|
|
|
|
var relIds = model.filterRelationIds(validateFunc, validateError);
|
2011-08-25 04:41:39 +02:00
|
|
|
|
2011-09-06 06:03:27 +02:00
|
|
|
if (topicsIds.length > 0 || relIds.length > 0) {
|
2011-09-08 14:16:50 +02:00
|
|
|
this._actionDispatcher.deleteTopics(topicsIds, relIds);
|
2009-06-07 20:59:43 +02:00
|
|
|
}
|
|
|
|
|
2011-08-20 15:50:48 +02:00
|
|
|
},
|
2011-07-27 19:53:32 +02:00
|
|
|
|
2012-07-01 22:21:02 +02:00
|
|
|
changeFontFamily:function (font) {
|
2011-08-25 04:41:39 +02:00
|
|
|
var topicsIds = this.getModel().filterTopicsIds();
|
2011-07-27 19:53:32 +02:00
|
|
|
if (topicsIds.length > 0) {
|
2011-08-03 22:52:39 +02:00
|
|
|
this._actionDispatcher.changeFontFamilyToTopic(topicsIds, font);
|
|
|
|
|
2010-12-22 23:34:24 +01:00
|
|
|
}
|
2011-08-20 15:50:48 +02:00
|
|
|
},
|
2011-07-27 19:53:32 +02:00
|
|
|
|
2012-07-01 22:21:02 +02:00
|
|
|
changeFontStyle:function () {
|
2011-08-25 04:41:39 +02:00
|
|
|
var topicsIds = this.getModel().filterTopicsIds();
|
2011-07-27 19:53:32 +02:00
|
|
|
if (topicsIds.length > 0) {
|
2011-08-03 22:52:39 +02:00
|
|
|
this._actionDispatcher.changeFontStyleToTopic(topicsIds);
|
2010-12-22 23:34:24 +01:00
|
|
|
}
|
2011-08-20 15:50:48 +02:00
|
|
|
},
|
2011-07-27 19:53:32 +02:00
|
|
|
|
2012-07-01 22:21:02 +02:00
|
|
|
changeFontColor:function (color) {
|
2011-08-23 19:25:49 +02:00
|
|
|
$assert(color, "color can not be null");
|
2011-08-25 04:41:39 +02:00
|
|
|
|
|
|
|
var topicsIds = this.getModel().filterTopicsIds();
|
2011-07-27 19:53:32 +02:00
|
|
|
if (topicsIds.length > 0) {
|
2011-08-03 22:52:39 +02:00
|
|
|
this._actionDispatcher.changeFontColorToTopic(topicsIds, color);
|
2009-06-07 20:59:43 +02:00
|
|
|
}
|
2011-08-20 15:50:48 +02:00
|
|
|
},
|
2011-07-27 19:53:32 +02:00
|
|
|
|
2012-07-01 22:21:02 +02:00
|
|
|
changeBackgroundColor:function (color) {
|
2011-07-27 19:53:32 +02:00
|
|
|
|
2012-07-01 22:21:02 +02:00
|
|
|
var validateFunc = function (topic) {
|
2012-02-28 02:47:10 +01:00
|
|
|
return topic.getShapeType() != mindplot.model.TopicShape.LINE;
|
2009-06-07 20:59:43 +02:00
|
|
|
};
|
2011-08-03 22:52:39 +02:00
|
|
|
var validateError = 'Color can not be set to line topics.';
|
2011-08-25 04:41:39 +02:00
|
|
|
|
|
|
|
var topicsIds = this.getModel().filterTopicsIds(validateFunc, validateError);
|
2011-07-27 19:53:32 +02:00
|
|
|
if (topicsIds.length > 0) {
|
2011-08-03 22:52:39 +02:00
|
|
|
this._actionDispatcher.changeBackgroundColorToTopic(topicsIds, color);
|
2011-07-27 19:53:32 +02:00
|
|
|
}
|
2011-08-20 15:50:48 +02:00
|
|
|
},
|
2009-06-07 20:59:43 +02:00
|
|
|
|
2012-07-01 22:21:02 +02:00
|
|
|
changeBorderColor:function (color) {
|
|
|
|
var validateFunc = function (topic) {
|
2012-03-07 21:40:10 +01:00
|
|
|
return topic.getShapeType() != mindplot.model.TopicShape.LINE;
|
2011-07-27 19:53:32 +02:00
|
|
|
};
|
2011-08-03 22:52:39 +02:00
|
|
|
var validateError = 'Color can not be set to line topics.';
|
2011-08-25 04:41:39 +02:00
|
|
|
var topicsIds = this.getModel().filterTopicsIds(validateFunc, validateError);
|
2011-07-27 19:53:32 +02:00
|
|
|
if (topicsIds.length > 0) {
|
2011-08-03 22:52:39 +02:00
|
|
|
this._actionDispatcher.changeBorderColorToTopic(topicsIds, color);
|
2009-06-07 20:59:43 +02:00
|
|
|
}
|
2011-08-20 15:50:48 +02:00
|
|
|
},
|
2011-07-27 19:53:32 +02:00
|
|
|
|
2012-07-01 22:21:02 +02:00
|
|
|
changeFontSize:function (size) {
|
2011-08-25 04:41:39 +02:00
|
|
|
var topicsIds = this.getModel().filterTopicsIds();
|
2011-07-27 19:53:32 +02:00
|
|
|
if (topicsIds.length > 0) {
|
2011-08-03 22:52:39 +02:00
|
|
|
this._actionDispatcher.changeFontSizeToTopic(topicsIds, size);
|
2011-07-27 19:53:32 +02:00
|
|
|
}
|
2011-09-06 06:03:27 +02:00
|
|
|
},
|
2011-07-27 19:53:32 +02:00
|
|
|
|
2012-07-01 22:21:02 +02:00
|
|
|
changeTopicShape:function (shape) {
|
|
|
|
var validateFunc = function (topic) {
|
2012-02-28 02:47:10 +01:00
|
|
|
return !(topic.getType() == mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE && shape == mindplot.model.TopicShape.LINE)
|
2009-06-07 20:59:43 +02:00
|
|
|
};
|
2011-11-30 04:50:46 +01:00
|
|
|
|
2011-07-27 19:53:32 +02:00
|
|
|
var validateError = 'Central Topic shape can not be changed to line figure.';
|
2011-08-25 04:41:39 +02:00
|
|
|
var topicsIds = this.getModel().filterTopicsIds(validateFunc, validateError);
|
2011-07-27 19:53:32 +02:00
|
|
|
if (topicsIds.length > 0) {
|
2011-09-10 02:53:41 +02:00
|
|
|
this._actionDispatcher.changeShapeTypeToTopic(topicsIds, shape);
|
2011-07-27 19:53:32 +02:00
|
|
|
}
|
2011-08-20 15:50:48 +02:00
|
|
|
},
|
2011-07-27 19:53:32 +02:00
|
|
|
|
2012-07-01 22:21:02 +02:00
|
|
|
changeFontWeight:function () {
|
2011-08-25 04:41:39 +02:00
|
|
|
var topicsIds = this.getModel().filterTopicsIds();
|
2011-07-27 19:53:32 +02:00
|
|
|
if (topicsIds.length > 0) {
|
2011-08-03 22:52:39 +02:00
|
|
|
this._actionDispatcher.changeFontWeightToTopic(topicsIds);
|
2011-07-27 19:53:32 +02:00
|
|
|
}
|
2011-08-20 15:50:48 +02:00
|
|
|
},
|
2009-06-07 20:59:43 +02:00
|
|
|
|
2012-07-01 22:21:02 +02:00
|
|
|
addIconType:function (iconType) {
|
2011-08-25 04:41:39 +02:00
|
|
|
var topicsIds = this.getModel().filterTopicsIds();
|
2011-07-27 19:53:32 +02:00
|
|
|
if (topicsIds.length > 0) {
|
2012-02-27 22:17:15 +01:00
|
|
|
this._actionDispatcher.addFeatureToTopic(topicsIds[0], mindplot.TopicFeature.Icon.id, {id:iconType});
|
2011-07-27 19:53:32 +02:00
|
|
|
}
|
2011-08-20 15:50:48 +02:00
|
|
|
},
|
2009-06-07 20:59:43 +02:00
|
|
|
|
2012-07-01 22:21:02 +02:00
|
|
|
addLink:function () {
|
2011-10-07 06:30:55 +02:00
|
|
|
var model = this.getModel();
|
|
|
|
var topic = model.selectedTopic();
|
|
|
|
topic.showLinkEditor();
|
2011-07-27 19:53:32 +02:00
|
|
|
},
|
|
|
|
|
2012-07-01 22:21:02 +02:00
|
|
|
addNote:function () {
|
2011-08-26 03:08:39 +02:00
|
|
|
var model = this.getModel();
|
|
|
|
var topic = model.selectedTopic();
|
2011-10-07 06:30:55 +02:00
|
|
|
topic.showNoteEditor();
|
2011-07-27 19:53:32 +02:00
|
|
|
},
|
2009-06-07 20:59:43 +02:00
|
|
|
|
2012-07-01 22:21:02 +02:00
|
|
|
goToNode:function (node) {
|
2011-07-27 19:53:32 +02:00
|
|
|
node.setOnFocus(true);
|
2011-08-19 18:38:37 +02:00
|
|
|
this.onObjectFocusEvent(node);
|
2011-07-27 19:53:32 +02:00
|
|
|
},
|
|
|
|
|
2012-07-01 22:21:02 +02:00
|
|
|
getWorkSpace:function () {
|
2011-07-27 19:53:32 +02:00
|
|
|
return this._workspace;
|
2011-01-20 16:04:53 +01:00
|
|
|
}
|
|
|
|
}
|
2011-07-27 19:53:32 +02:00
|
|
|
);
|