2011-01-24 00:34:05 +01:00
|
|
|
/*
|
2011-08-03 22:52:39 +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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
mindplot.DragTopic = new Class({
|
2012-01-31 00:17:47 +01:00
|
|
|
initialize:function(dragShape, draggedNode, layoutManger) {
|
2011-08-03 22:52:39 +02:00
|
|
|
$assert(dragShape, 'Rect can not be null.');
|
|
|
|
$assert(draggedNode, 'draggedNode can not be null.');
|
2012-01-31 00:17:47 +01:00
|
|
|
$assert(layoutManger, 'layoutManger can not be null.');
|
2011-08-03 22:52:39 +02:00
|
|
|
|
|
|
|
this._elem2d = dragShape;
|
|
|
|
this._order = null;
|
|
|
|
this._draggedNode = draggedNode;
|
2012-01-31 00:17:47 +01:00
|
|
|
this._layoutManager = layoutManger;
|
2011-08-03 22:52:39 +02:00
|
|
|
this._position = new core.Point();
|
2012-01-21 14:26:58 +01:00
|
|
|
this._isInWorkspace = false;
|
2012-01-18 05:26:39 +01:00
|
|
|
this._isFreeLayoutEnabled = false;
|
2011-08-03 22:52:39 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
setOrder : function(order) {
|
|
|
|
this._order = order;
|
|
|
|
},
|
|
|
|
|
|
|
|
setPosition : function(x, y) {
|
2012-01-21 14:57:15 +01:00
|
|
|
// Update drag shadow position ....
|
|
|
|
var position = {x:x,y:y};
|
|
|
|
if (this.isFreeLayoutOn() && this.isConnected()) {
|
2012-01-31 00:17:47 +01:00
|
|
|
var _layoutManager = this._layoutManager;
|
2012-01-21 14:57:15 +01:00
|
|
|
var par = this.getConnectedToTopic();
|
2012-02-02 15:30:12 +01:00
|
|
|
position = _layoutManager.predict(par.getId(), this._draggedNode.getId(), position, true).position;
|
2012-01-21 14:57:15 +01:00
|
|
|
}
|
|
|
|
this._position.setValue(position.x, position.y);
|
2011-08-03 22:52:39 +02:00
|
|
|
|
|
|
|
// Elements are positioned in the center.
|
|
|
|
// All topic element must be positioned based on the innerShape.
|
|
|
|
var draggedNode = this._draggedNode;
|
|
|
|
var size = draggedNode.getSize();
|
2012-01-21 14:57:15 +01:00
|
|
|
var cx = Math.ceil(position.x - (size.width / 2));
|
|
|
|
var cy = Math.ceil(position.y - (size.height / 2));
|
2011-08-03 22:52:39 +02:00
|
|
|
this._elem2d.setPosition(cx, cy);
|
2012-01-14 18:16:59 +01:00
|
|
|
|
2012-01-21 14:57:15 +01:00
|
|
|
// In case is not free, pivot must be draw ...
|
2012-01-18 05:32:55 +01:00
|
|
|
if (this.isConnected() && !this.isFreeLayoutOn()) {
|
2012-01-14 18:16:59 +01:00
|
|
|
var parent = this.getConnectedToTopic();
|
2012-02-01 16:15:19 +01:00
|
|
|
var predict = this._layoutManager.predict(parent.getId(), this._draggedNode.getId(), this.getPosition());
|
2012-01-14 18:16:59 +01:00
|
|
|
if (this._order != predict.order) {
|
|
|
|
var dragPivot = this._getDragPivot();
|
2012-01-21 14:57:15 +01:00
|
|
|
var pivotPosition = predict.position;
|
|
|
|
dragPivot.connectTo(parent, pivotPosition);
|
2012-01-14 18:16:59 +01:00
|
|
|
this.setOrder(predict.order);
|
|
|
|
}
|
|
|
|
}
|
2011-08-03 22:52:39 +02:00
|
|
|
},
|
|
|
|
|
2012-01-18 05:26:39 +01:00
|
|
|
updateFreeLayout: function(event) {
|
2012-01-18 05:32:55 +01:00
|
|
|
var isFreeEnabled = (event.meta && Browser.Platform.mac) || (event.control && !Browser.Platform.mac);
|
|
|
|
if (this.isFreeLayoutOn() != isFreeEnabled) {
|
|
|
|
var dragPivot = this._getDragPivot();
|
|
|
|
dragPivot.setVisibility(!isFreeEnabled);
|
|
|
|
this._isFreeLayoutEnabled = isFreeEnabled;
|
|
|
|
}
|
2012-01-18 05:26:39 +01:00
|
|
|
},
|
|
|
|
|
2012-01-21 13:37:01 +01:00
|
|
|
setVisibility:function(value) {
|
|
|
|
var dragPivot = this._getDragPivot();
|
|
|
|
dragPivot.setVisibility(value);
|
|
|
|
},
|
|
|
|
|
|
|
|
isVisible:function() {
|
|
|
|
var dragPivot = this._getDragPivot();
|
|
|
|
return dragPivot.isVisible();
|
|
|
|
},
|
|
|
|
|
2011-08-03 22:52:39 +02:00
|
|
|
getInnerShape : function() {
|
|
|
|
return this._elem2d;
|
|
|
|
},
|
|
|
|
|
|
|
|
disconnect : function(workspace) {
|
|
|
|
// Clear connection line ...
|
|
|
|
var dragPivot = this._getDragPivot();
|
|
|
|
dragPivot.disconnect(workspace);
|
|
|
|
},
|
|
|
|
|
|
|
|
canBeConnectedTo : function(targetTopic) {
|
|
|
|
$assert(targetTopic, 'parent can not be null');
|
|
|
|
|
|
|
|
var result = true;
|
2012-01-12 03:30:26 +01:00
|
|
|
if (!targetTopic.areChildrenShrunken() && !targetTopic.isCollapsed()) {
|
2011-08-03 22:52:39 +02:00
|
|
|
// Dragged node can not be connected to himself.
|
|
|
|
if (targetTopic == this._draggedNode) {
|
|
|
|
result = false;
|
|
|
|
} else {
|
|
|
|
var draggedNode = this.getDraggedTopic();
|
|
|
|
var topicPosition = this.getPosition();
|
|
|
|
|
|
|
|
var targetTopicModel = targetTopic.getModel();
|
|
|
|
var childTopicModel = draggedNode.getModel();
|
|
|
|
|
2012-03-07 05:13:50 +01:00
|
|
|
result = targetTopicModel.canBeConnected(childTopicModel, topicPosition, 18, targetTopic.getSize());
|
2011-08-03 22:52:39 +02:00
|
|
|
}
|
|
|
|
} else {
|
2009-06-07 20:59:43 +02:00
|
|
|
result = false;
|
|
|
|
}
|
2011-08-03 22:52:39 +02:00
|
|
|
return result;
|
|
|
|
},
|
2009-06-07 20:59:43 +02:00
|
|
|
|
2011-08-03 22:52:39 +02:00
|
|
|
connectTo : function(parent) {
|
|
|
|
$assert(parent, 'Parent connection node can not be null.');
|
2009-06-07 20:59:43 +02:00
|
|
|
|
2012-01-14 18:16:59 +01:00
|
|
|
// Where it should be connected ?
|
2012-02-01 16:15:19 +01:00
|
|
|
var predict = designer._eventBussDispatcher._layoutManager.predict(parent.getId(), this._draggedNode.getId(), this.getPosition());
|
2012-01-14 18:16:59 +01:00
|
|
|
|
|
|
|
// Connect pivot ...
|
2011-08-03 22:52:39 +02:00
|
|
|
var dragPivot = this._getDragPivot();
|
2012-01-14 18:16:59 +01:00
|
|
|
var position = predict.position;
|
|
|
|
dragPivot.connectTo(parent, position);
|
2012-01-21 13:37:01 +01:00
|
|
|
dragPivot.setVisibility(true);
|
2012-01-14 18:16:59 +01:00
|
|
|
|
|
|
|
this.setOrder(predict.order);
|
2011-08-03 22:52:39 +02:00
|
|
|
},
|
2009-06-07 20:59:43 +02:00
|
|
|
|
2011-08-03 22:52:39 +02:00
|
|
|
getDraggedTopic : function() {
|
|
|
|
return this._draggedNode;
|
|
|
|
},
|
2009-06-07 20:59:43 +02:00
|
|
|
|
2011-08-03 22:52:39 +02:00
|
|
|
removeFromWorkspace : function(workspace) {
|
|
|
|
// Remove drag shadow.
|
|
|
|
workspace.removeChild(this._elem2d);
|
2012-01-21 14:26:58 +01:00
|
|
|
this._isInWorkspace = false;
|
2009-06-07 20:59:43 +02:00
|
|
|
|
2011-08-20 15:50:48 +02:00
|
|
|
// Remove pivot shape. To improve performace it will not be removed. Only the visibility will be changed.
|
2011-08-03 22:52:39 +02:00
|
|
|
var dragPivot = this._getDragPivot();
|
|
|
|
dragPivot.setVisibility(false);
|
2012-01-21 14:26:58 +01:00
|
|
|
|
|
|
|
},
|
|
|
|
|
2012-01-21 14:57:15 +01:00
|
|
|
isInWorkspace: function() {
|
2012-01-21 14:26:58 +01:00
|
|
|
return this._isInWorkspace;
|
2011-08-03 22:52:39 +02:00
|
|
|
},
|
2009-06-07 20:59:43 +02:00
|
|
|
|
2011-08-03 22:52:39 +02:00
|
|
|
addToWorkspace : function(workspace) {
|
|
|
|
workspace.appendChild(this._elem2d);
|
|
|
|
var dragPivot = this._getDragPivot();
|
|
|
|
dragPivot.addToWorkspace(workspace);
|
2012-01-21 14:26:58 +01:00
|
|
|
this._isInWorkspace = true;
|
2011-08-03 22:52:39 +02:00
|
|
|
},
|
2009-06-07 20:59:43 +02:00
|
|
|
|
2011-08-03 22:52:39 +02:00
|
|
|
_getDragPivot : function() {
|
|
|
|
return mindplot.DragTopic.__getDragPivot();
|
|
|
|
},
|
2009-06-07 20:59:43 +02:00
|
|
|
|
2011-08-03 22:52:39 +02:00
|
|
|
getPosition:function() {
|
|
|
|
return this._position;
|
2012-01-14 18:16:59 +01:00
|
|
|
},
|
2011-08-03 22:52:39 +02:00
|
|
|
|
|
|
|
isDragTopic : function() {
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
2012-01-12 17:44:35 +01:00
|
|
|
applyChanges : function(workspace) {
|
2011-08-03 22:52:39 +02:00
|
|
|
$assert(workspace, 'workspace can not be null');
|
|
|
|
|
|
|
|
|
|
|
|
var actionDispatcher = mindplot.ActionDispatcher.getInstance();
|
2012-01-18 05:26:39 +01:00
|
|
|
var draggedTopic = this.getDraggedTopic();
|
2011-08-03 22:52:39 +02:00
|
|
|
var topicId = draggedTopic.getId();
|
2012-01-18 05:26:39 +01:00
|
|
|
var position = this.getPosition();
|
|
|
|
|
|
|
|
if (!this.isFreeLayoutOn()) {
|
|
|
|
var order = null;
|
|
|
|
var parent = null;
|
|
|
|
var isDragConnected = this.isConnected();
|
|
|
|
if (isDragConnected) {
|
|
|
|
var targetTopic = this.getConnectedToTopic();
|
|
|
|
order = this._order;
|
|
|
|
parent = targetTopic;
|
|
|
|
}
|
2011-08-03 22:52:39 +02:00
|
|
|
|
2012-01-18 05:26:39 +01:00
|
|
|
// If the node is not connected, position based on the original drag topic position.
|
|
|
|
actionDispatcher.dragTopic(topicId, position, order, parent);
|
|
|
|
} else {
|
|
|
|
actionDispatcher.moveTopic(topicId, position);
|
2011-08-03 22:52:39 +02:00
|
|
|
}
|
|
|
|
},
|
2009-06-07 20:59:43 +02:00
|
|
|
|
2011-08-03 22:52:39 +02:00
|
|
|
getConnectedToTopic : function() {
|
|
|
|
var dragPivot = this._getDragPivot();
|
|
|
|
return dragPivot.getTargetTopic();
|
|
|
|
},
|
2009-06-07 20:59:43 +02:00
|
|
|
|
2011-08-03 22:52:39 +02:00
|
|
|
isConnected : function() {
|
|
|
|
return this.getConnectedToTopic() != null;
|
2012-01-18 05:26:39 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
isFreeLayoutOn: function() {
|
|
|
|
return this._isFreeLayoutEnabled;
|
2011-08-03 22:52:39 +02:00
|
|
|
}
|
2009-06-07 20:59:43 +02:00
|
|
|
|
2012-01-18 05:26:39 +01:00
|
|
|
});
|
2009-06-07 20:59:43 +02:00
|
|
|
|
2012-01-14 18:16:59 +01:00
|
|
|
mindplot.DragTopic.PIVOT_SIZE = {width:50,height:6};
|
2009-06-07 20:59:43 +02:00
|
|
|
|
2011-08-03 22:52:39 +02:00
|
|
|
mindplot.DragTopic.init = function(workspace) {
|
2009-06-07 20:59:43 +02:00
|
|
|
|
2011-08-03 22:52:39 +02:00
|
|
|
$assert(workspace, "workspace can not be null");
|
|
|
|
var pivot = mindplot.DragTopic.__getDragPivot();
|
|
|
|
workspace.appendChild(pivot);
|
2012-01-12 17:44:35 +01:00
|
|
|
};
|
2009-06-07 20:59:43 +02:00
|
|
|
|
2011-08-03 22:52:39 +02:00
|
|
|
mindplot.DragTopic.__getDragPivot = function() {
|
|
|
|
var result = mindplot.DragTopic._dragPivot;
|
|
|
|
if (!$defined(result)) {
|
|
|
|
result = new mindplot.DragPivot();
|
|
|
|
mindplot.DragTopic._dragPivot = result;
|
2009-06-07 20:59:43 +02:00
|
|
|
}
|
2011-08-03 22:52:39 +02:00
|
|
|
return result;
|
|
|
|
}
|
2011-08-08 00:51:03 +02:00
|
|
|
|