First steps on icon drag support.

This commit is contained in:
Paulo Gustavo Veiga
2012-03-07 17:40:10 -03:00
parent 24047e02bb
commit a1f6542264
7 changed files with 105 additions and 36 deletions

View File

@@ -160,6 +160,7 @@ mindplot.Designer = new Class({
this._workspace.setZoom(model.getZoom(), true);
},
_buildNodeGraph : function(model, readOnly) {
var workspace = this._workspace;
@@ -340,6 +341,30 @@ mindplot.Designer = new Class({
return childModel;
},
addDraddedNode: function(event, options) {
$assert(event, "event can not be null");
$assert(options, "option can not be null");
// Create a new node ...
var mindmap = this.getMindmap();
var model = mindmap.createNode(mindplot.model.INodeModel.MAIN_TOPIC_TYPE);
model.setShapeType(mindplot.model.TopicShape.IMAGE);
// Set node specified options ...
model.setImageUrl(options.imageUrl);
model.setImageSize(options.imageWidth, options.imageHeight);
model.setMetadata(options.metadata);
// 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);
},
createSiblingForSelectedNode : function() {
var nodes = this.getModel().filterSelectedTopics();
if (nodes.length <= 0) {
@@ -423,42 +448,42 @@ mindplot.Designer = new Class({
this._mindmap = mindmapModel;
// try {
// Init layout manager ...
var size = {width:25,height:25};
var layoutManager = new mindplot.layout.LayoutManager(mindmapModel.getCentralTopic().getId(), size);
layoutManager.addEvent('change', function(event) {
var id = event.getId();
var topic = this.getModel().findTopicById(id);
topic.setPosition(event.getPosition());
topic.setOrder(event.getOrder());
}.bind(this));
this._eventBussDispatcher.setLayoutManager(layoutManager);
// Init layout manager ...
var size = {width:25,height:25};
var layoutManager = new mindplot.layout.LayoutManager(mindmapModel.getCentralTopic().getId(), size);
layoutManager.addEvent('change', function(event) {
var id = event.getId();
var topic = this.getModel().findTopicById(id);
topic.setPosition(event.getPosition());
topic.setOrder(event.getOrder());
}.bind(this));
this._eventBussDispatcher.setLayoutManager(layoutManager);
// 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);
// 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);
// Update shrink render state...
nodeGraph.setBranchVisibility(true);
}
// Update shrink render state...
nodeGraph.setBranchVisibility(true);
}
var relationships = mindmapModel.getRelationships();
for (var j = 0; j < relationships.length; j++) {
this._relationshipModelToRelationship(relationships[j]);
}
var relationships = mindmapModel.getRelationships();
for (var j = 0; j < relationships.length; j++) {
this._relationshipModelToRelationship(relationships[j]);
}
// Place the focus on the Central Topic
var centralTopic = this.getModel().getCentralTopic();
this.goToNode(centralTopic);
// Place the focus on the Central Topic
var centralTopic = this.getModel().getCentralTopic();
this.goToNode(centralTopic);
// Finally, sort the map ...
mindplot.EventBus.instance.fireEvent(mindplot.EventBus.events.DoLayout);
// Finally, sort the map ...
mindplot.EventBus.instance.fireEvent(mindplot.EventBus.events.DoLayout);
this.fireEvent('loadSuccess');
this.fireEvent('loadSuccess');
// } catch(e) {
// this.fireEvent('loadError', e);
// }
@@ -668,7 +693,7 @@ mindplot.Designer = new Class({
changeBorderColor : function(color) {
var validateFunc = function(topic) {
return topic.getShapeType() != mindplot.model.TopicShape.LINE ;
return topic.getShapeType() != mindplot.model.TopicShape.LINE;
};
var validateError = 'Color can not be set to line topics.';
var topicsIds = this.getModel().filterTopicsIds(validateFunc, validateError);

View File

@@ -87,6 +87,15 @@ mindplot.model.INodeModel = new Class({
},
getMetadata:function() {
return this.getProperty('metadata');
},
setMetadata:function(json) {
this.putProperty('metadata', json);
},
getImageUrl:function() {
return this.getProperty('imageUrl');
},

View File

@@ -127,6 +127,11 @@ mindplot.persistence.XMLSerializer_Pela = new Class({
parentTopic.setAttribute('brColor', brColor);
}
var metadata = topic.getMetadata();
if ($defined(metadata)) {
parentTopic.setAttribute('metadata', metadata);
}
// Serialize features ...
var features = topic.getFeatures();
for (var i = 0; i < features.length; i++) {
@@ -314,6 +319,11 @@ mindplot.persistence.XMLSerializer_Pela = new Class({
topic.setPosition(pos[0], pos[1]);
}
var metadata = domElem.getAttribute('metadata');
if ($defined(metadata)) {
topic.setMetadata(metadata);
}
//Creating icons and children nodes
var children = domElem.childNodes;
for (var i = 0; i < children.length; i++) {