Basic topic propeties integrated with brix.

This commit is contained in:
Paulo Veiga
2011-09-06 01:03:27 -03:00
parent 85defa2ab9
commit e2da27ebc8
26 changed files with 346 additions and 271 deletions

View File

@@ -6,11 +6,11 @@ mindplot.collaboration.CollaborationManager = new Class({
this.wiseReady = false;
},
isCollaborationFrameworkAvailable:function() {
isCollaborationFrameworkAvailable : function() {
return (typeof goog != "undefined") && (typeof goog.collab != "undefined");
},
setCollaborativeFramework:function(framework) {
setCollaborativeFramework : function(framework) {
this._collaborativeFramework = framework;
this.collaborativeModelReady = true;
if (this.wiseReady) {

View File

@@ -1,31 +1,33 @@
mindplot.collaboration.frameworks = {};
mindplot.collaboration.frameworks.AbstractCollaborativeFramework = new Class({
initialize: function(model, collaborativeModelFactory){
initialize: function(model, collaborativeModelFactory) {
this._collaborativeModelFactory = collaborativeModelFactory;
if(!$defined(model)){
if (!$defined(model)) {
model = this._buildInitialCollaborativeModel();
}
this._model = model;
this._actionDispatcher = null;
},
getModel: function(){
getModel : function() {
return this._model;
},
buildWiseModel: function(){
buildWiseModel : function() {
var cmindMap = this.getModel();
var mindmap = new mindplot.model.Mindmap();
var branches = cmindMap.getBranches();
branches.forEach(function(branch){
branches.forEach(function(branch) {
var type = branch.getType();
var id = branch.getId();
var node = mindmap.createNode(type,id);
var node = mindmap.createNode(type, id);
node.setText(branch.getText());
var position = branch.getPosition();
node.setPosition(position.x, position.y);
var children = branch.getChildren();
children.forEach(function(child){
var node2 = new mindplot.model.NodeModel(child.getType(),mindmap, child.getId());
children.forEach(function(child) {
var node2 = new mindplot.model.NodeModel(child.getType(), mindmap, child.getId());
node2.setText(child.getText());
var pos = child.getPosition();
node2.setPosition(pos.x, pos.y);
@@ -35,35 +37,45 @@ mindplot.collaboration.frameworks.AbstractCollaborativeFramework = new Class({
}.bind(this));
return mindmap;
},
_buildInitialCollaborativeModel: function(){
_buildInitialCollaborativeModel: function() {
var mindmap = this._collaborativeModelFactory.buildMindMap();
var centralTopic = mindmap.createNode(mindplot.model.NodeModel.CENTRAL_TOPIC_TYPE);
mindmap.addBranch(centralTopic, true);
this.addMindmap(mindmap);
return mindmap;
},
addMindmap:function(model){},
getTopic:function(id){
var branches = this.getModel().getBranches();
for(var i = 0; i<branches.length; i++){
if(branches[i].getId()==id){
return branches[i];
}else {
addMindmap:function(model) {
},
var children = branches[i].getChildren();
for(var j=0; j<children.length; j++){
if(children[j].getId()==id){
return children[j];
}
}
_findTopic : function(topics, id) {
var result;
for (var i = 0; i < topics.length; i++) {
var topic = topics[i];
if (topic.getId() == id) {
result = topic;
} else {
var children = topic.getChildren();
result = this._findTopic(children, id)
}
if (result != null) {
break;
}
}
return null;
return result;
},
getActionDispatcher:function(){
if(this._actionDispatcher == null){
getTopic:function(id) {
$assert(id, "id can not be null")
var branches = this.getModel().getBranches();
var result = this._findTopic(branches, id);
$assert(result, "Could not find topic:" + id);
return result;
},
getActionDispatcher:function() {
if (this._actionDispatcher == null) {
var context = mindplot.ActionDispatcher.getInstance()._commandContext;
this._actionDispatcher = new mindplot.LocalActionDispatcher(context);
}

View File

@@ -22,6 +22,7 @@ mindplot.collaboration.frameworks.brix.BrixFramework = new Class({
return this.parent();
}
});
instanciated = false;
mindplot.collaboration.frameworks.brix.BrixFramework.instanciate = function() {
if ((typeof isGoogleBrix != "undefined") && !instanciated) {

View File

@@ -15,71 +15,123 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
mindplot.collaboration.frameworks.brix={};
mindplot.collaboration.frameworks.brix = {};
mindplot.collaboration.frameworks.brix.model = {};
mindplot.collaboration.frameworks.brix.model.NodeModel = new Class({
Extends: mindplot.model.NodeModel,
initialize:function(brixModel, brixFramework, type, mindmap, id) {
Attributes: ['text','fontSize','fontFamily','fontStyle','fontColor','fontWeight','borderColor','backgroundColor','shapeType'],
initialize : function(brixModel, brixFramework, type, mindmap, id) {
// Inject property getters and setters ...
this._injectSetAndGet();
this._brixModel = brixModel;
this._brixFramework = brixFramework;
if($defined(this._brixModel)){
if ($defined(this._brixModel)) {
type = this._brixModel.get("type");
id = this._brixModel.get("id");
}
this.parent(type, mindmap, id);
if(!$defined(this._brixModel)){
if (!$defined(this._brixModel)) {
this._brixModel = this._createBrixModel();
}else{
var text = this._brixModel.get("text");
this.setText(text, false);
} else {
// Call all the required setters for simple properties ...
var keys = mindplot.collaboration.frameworks.brix.model.NodeModel.prototype.Attributes;
keys.forEach(function(key) {
// Call setters ...
var funName = 'set' + key.capitalize();
var value = this._brixModel.get(key);
if (value != null) {
this[funName](value, false);
}
}.bind(this));
var position = this._brixModel.get("position");
this.setPosition(position.get("x"),position.get("y"), false);
this.setPosition(position.get("x"), position.get("y"), false);
var children = this._brixModel.get("children");
for(var i=0; i<children.size(); i++){
for (var i = 0; i < children.size(); i++) {
var bChild = children.get(i);
var child= new mindplot.collaboration.frameworks.brix.model.NodeModel(bChild, this._brixFramework, null, mindmap);
var child = new mindplot.collaboration.frameworks.brix.model.NodeModel(bChild, this._brixFramework, null, mindmap);
this._appendChild(child, false);
}
}
this._addBrixListeners();
},
_addBrixListeners:function(){
this._brixModel.addListener("valueChanged", this._valuechangeListener.bindWithEvent(this));
this._brixModel.get("children").addListener("valuesAdded", this._childAddedListener.bindWithEvent(this));
_injectSetAndGet : function() {
var keys = mindplot.collaboration.frameworks.brix.model.NodeModel.prototype.Attributes;
keys.forEach(function(key) {
// Create setters ...
var setterName = 'set' + key.capitalize();
this[setterName] = function(value, updateModel) {
console.log('Calling setter for:' + setterName);
if (!$defined(updateModel) || updateModel) {
this._brixModel.put(key, value);
}
};
// Create getters ...
var getterName = 'get' + key.capitalize();
this[getterName] = function() {
return this._brixModel.get(key);
};
}.bind(this));
},
_valuechangeListener:function(event){
this._brixFramework.getActionDispatcher().changeTextOnTopic(this.getId(),event.getNewValue());
_addBrixListeners:function() {
// Register listener for properties changes ....
this._brixModel.addListener("valueChanged", function(event) {
var key = event.getProperty();
var actionDispatcher = this._brixFramework.getActionDispatcher();
var value = event.getNewValue();
var funName = 'change' + key.capitalize() + 'ToTopic';
if (!$defined(actionDispatcher[funName])) {
throw "No implementation for:" + funName;
}
actionDispatcher[funName](this.getId(), value);
}.bind(this));
this._brixModel.get("children").addListener("valuesAdded", this._childAddedListener.bind(this));
},
_childAddedListener:function(event){
_childAddedListener:function(event) {
var newValue = event.getValues().get(0);
var cmodel = new mindplot.collaboration.frameworks.brix.model.NodeModel(newValue,this._brixFramework, null, this.getMindmap());
var cmodel = new mindplot.collaboration.frameworks.brix.model.NodeModel(newValue, this._brixFramework, null, this.getMindmap());
this._appendChild(cmodel, false);
var model = new mindplot.model.NodeModel(newValue.get("type"),designer.getMindmap(), newValue.get("id"));
var model = new mindplot.model.NodeModel(newValue.get("type"), designer.getMindmap(), newValue.get("id"));
var position = newValue.get("position");
var x = position.get("x");
var y = position.get("y");
model.setPosition(x, y);
this._brixFramework.getActionDispatcher().addTopic(model, this.getId(), true);
},
_createBrixModel:function(){
}
,
_createBrixModel:function() {
var model = this._brixFramework.getBrixModel().create("Map");
model.put("type",this._type);
model.put("id",this._id);
model.put("text",this._type==mindplot.model.NodeModel.CENTRAL_TOPIC_TYPE?"Central Topic":"Main Topic");
model.put("type", this._type);
model.put("id", this._id);
model.put("text", this._type == mindplot.model.NodeModel.CENTRAL_TOPIC_TYPE ? "Central Topic" : "Main Topic");
var position = this._brixFramework.getBrixModel().create("Map");
position.put("x",0);
position.put("y",0);
model.put("position",position);
position.put("x", 0);
position.put("y", 0);
model.put("position", position);
var children = this._brixFramework.getBrixModel().create("List");
model.put("children", children);
return model;
},
getBrixModel:function(){
}
,
getBrixModel:function() {
return this._brixModel;
},
}
,
clone : function() {
var result = new mindplot.model.NodeModel(this._type, this._mindmap);
result._order = this._order;
@@ -98,7 +150,7 @@ mindplot.collaboration.frameworks.brix.model.NodeModel = new Class({
result._position = this._position;
result._id = this._id;
result._mindmap = this._mindmap;
result._textShape = this._textShape;
result._text = this._text;
result._shapeType = this._shapeType;
result._fontFamily = this._fontFamily;
result._fontSize = this._fontSize;
@@ -109,15 +161,18 @@ mindplot.collaboration.frameworks.brix.model.NodeModel = new Class({
result._backgroundColor = this._backgroundColor;
result._areChildrenShrinked = this._areChildrenShrinked;
return result;
},
}
,
areChildrenShrinked : function() {
return this._areChildrenShrinked;
},
}
,
setChildrenShrinked : function(value) {
this._areChildrenShrinked = value;
},
}
,
getId : function() {
return this._id;
@@ -135,17 +190,6 @@ mindplot.collaboration.frameworks.brix.model.NodeModel = new Class({
return this._type;
},
setText : function(text,updateModel) {
this.parent(text);
if($defined(updateModel) && updateModel){
this._brixModel.put("text",text);
}
},
getText : function() {
return this._textShape;
},
isNodeModel : function() {
return true;
},
@@ -192,38 +236,44 @@ mindplot.collaboration.frameworks.brix.model.NodeModel = new Class({
addIcon : function(icon) {
$assert(icon && icon.isIconModel(), 'Only IconModel can be appended to Mindmap object as icons');
this._icons.push(icon);
},
}
,
removeIcon : function(icon) {
$assert(icon && icon.isIconModel(), 'Only IconModel can be appended to Mindmap object as icons');
this._icons.erase(icon);
},
}
,
removeLastIcon : function() {
this._icons.pop();
},
}
,
_appendChild : function(child, updateModel) {
this.parent(child);
if(!$defined(updateModel) || ($defined(updateModel) && updateModel)){
if (!$defined(updateModel) || ($defined(updateModel) && updateModel)) {
this.getBrixModel().get("children").add(child.getBrixModel());
}
},
}
,
_removeChild : function(child) {
$assert(child && child.isNodeModel(), 'Only NodeModel can be appended to Mindmap object.');
this._children.erase(child);
child._parent = null;
},
}
,
setPosition : function(x, y, updateModel) {
this.parent(x,y);
if(!$defined(updateModel) || ($defined(updateModel) && updateModel)){
this.parent(x, y);
if (!$defined(updateModel) || ($defined(updateModel) && updateModel)) {
var position = this.getBrixModel().get("position");
position.put("x",this._position.x);
position.put("y",this._position.y);
position.put("x", this._position.x);
position.put("y", this._position.y);
}
},
}
,
setFinalPosition : function(x, y) {
$assert(x, "x coordinate must be defined");
@@ -234,7 +284,8 @@ mindplot.collaboration.frameworks.brix.model.NodeModel = new Class({
}
this._finalPosition.x = parseInt(x);
this._finalPosition.y = parseInt(y);
},
}
,
getFinalPosition : function() {
return this._finalPosition;
@@ -243,7 +294,8 @@ mindplot.collaboration.frameworks.brix.model.NodeModel = new Class({
setSize : function(width, height) {
this._size.width = width;
this._size.height = height;
},
}
,
getSize : function() {
return {width:this._size.width,height:this._size.height};
@@ -251,32 +303,39 @@ mindplot.collaboration.frameworks.brix.model.NodeModel = new Class({
getChildren : function() {
return this._children;
},
}
,
getIcons : function() {
return this._icons;
},
}
,
getLinks : function() {
return this._links;
},
}
,
getNotes : function() {
return this._notes;
},
}
,
getParent : function() {
return this._parent;
},
}
,
getMindmap : function() {
return this._mindmap;
},
}
,
setParent : function(parent) {
$assert(parent != this, 'The same node can not be parent and child if itself.');
this._parent = parent;
},
}
,
canBeConnected : function(sourceModel, sourcePosition, targetTopicHeight) {
$assert(sourceModel != this, 'The same node can not be parent and child if itself.');
@@ -322,7 +381,8 @@ mindplot.collaboration.frameworks.brix.model.NodeModel = new Class({
throw "No implemented yet";
}
return result;
},
}
,
_isChildNode : function(node) {
var result = false;
@@ -340,12 +400,14 @@ mindplot.collaboration.frameworks.brix.model.NodeModel = new Class({
}
return result;
},
}
,
disconnect : function() {
var mindmap = this.getMindmap();
mindmap.disconnect(this);
},
}
,
getOrder : function() {
return this._order;
@@ -363,66 +425,6 @@ mindplot.collaboration.frameworks.brix.model.NodeModel = new Class({
this._order = value;
},
setFontFamily : function(value) {
this._fontFamily = value;
},
getOrder : function() {
return this._order;
},
getFontFamily : function() {
return this._fontFamily;
},
setFontStyle : function(value) {
this._fontStyle = value;
},
getFontStyle : function() {
return this._fontStyle;
},
setFontWeight : function(value) {
this._fontWeight = value;
},
getFontWeight : function() {
return this._fontWeight;
},
setFontColor : function(value) {
this._fontColor = value;
},
getFontColor : function() {
return this._fontColor;
},
setFontSize : function(value) {
this._fontSize = value;
},
getFontSize : function() {
return this._fontSize;
},
getBorderColor : function() {
return this._borderColor;
},
setBorderColor : function(color) {
this._borderColor = color;
},
getBackgroundColor : function() {
return this._backgroundColor;
},
setBackgroundColor : function(color) {
this._backgroundColor = color;
},
deleteNode : function() {
var mindmap = this._mindmap;
@@ -443,33 +445,10 @@ mindplot.collaboration.frameworks.brix.model.NodeModel = new Class({
var branches = mindmap.getBranches();
branches.erase(this);
},
}
,
inspect : function() {
inspect : function() {
return '(type:' + this.getType() + ' , id: ' + this.getId() + ')';
}
});
mindplot.model.NodeModel.CENTRAL_TOPIC_TYPE = 'CentralTopic';
mindplot.model.NodeModel.MAIN_TOPIC_TYPE = 'MainTopic';
mindplot.model.NodeModel.DRAGGED_TOPIC_TYPE = 'DraggedTopic';
mindplot.model.NodeModel.SHAPE_TYPE_RECT = 'rectagle';
mindplot.model.NodeModel.SHAPE_TYPE_ROUNDED_RECT = 'rounded rectagle';
mindplot.model.NodeModel.SHAPE_TYPE_ELIPSE = 'elipse';
mindplot.model.NodeModel.SHAPE_TYPE_LINE = 'line';
mindplot.model.NodeModel.MAIN_TOPIC_TO_MAIN_TOPIC_DISTANCE = 220;
/**
* @todo: This method must be implemented.
*/
mindplot.model.NodeModel._nextUUID = function() {
if (!$defined(this._uuid)) {
this._uuid = 0;
}
this._uuid = this._uuid + 1;
return this._uuid;
}