Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion diagram-builder-demo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<groupId>org.vaadin</groupId>
<artifactId>diagram-builder-demo</artifactId>
<packaging>war</packaging>
<version>1.3-SNAPSHOT</version>
<version>1.3.1</version>
<name>DiagramBuilder Add-on Demo</name>

<properties>
Expand Down
2 changes: 1 addition & 1 deletion diagram-builder/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>org.vaadin</groupId>
<artifactId>diagram-builder</artifactId>
<packaging>jar</packaging>
<version>1.3-SNAPSHOT</version>
<version>1.3.1</version>
<name>diagram-builder</name>

<properties>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
package org.vaadin.diagrambuilder;

import java.util.List;

/**
* Created by bsasschetti on 03/05/18.
*/
public class CustomNodeAttribute {
private String name;
private String defaultValue;
private boolean readOnly = false;
// TODO later we can add different types
private boolean isComboBox = false;
private List<String> options;

public CustomNodeAttribute(String name) {
this(name, "");
Expand All @@ -16,6 +22,28 @@ public CustomNodeAttribute(String name, String defaultValue) {
this.defaultValue = defaultValue;
}

public CustomNodeAttribute(String name, String defaultValue, boolean readOnly) {
this.name = name;
this.defaultValue = defaultValue;
this.readOnly = readOnly;
}

public CustomNodeAttribute(String name, String defaultValue, boolean isComboBox, List<String> options) {
this.name = name;
this.defaultValue = defaultValue;
this.isComboBox = isComboBox;
this.options = options;
}

public CustomNodeAttribute(String name, String defaultValue, boolean readOnly, boolean isComboBox, List<String> options) {
this.name = name;
this.defaultValue = defaultValue;
this.readOnly = readOnly;
this.isComboBox = isComboBox;
this.options = options;
}


public String getName() {
return name;
}
Expand All @@ -31,4 +59,28 @@ public String getDefaultValue() {
public void setDefaultValue(String defaultValue) {
this.defaultValue = defaultValue;
}

public boolean isComboBox() {
return isComboBox;
}

public void setComboBox(boolean comboBox) {
isComboBox = comboBox;
}

public List<String> getOptions() {
return options;
}

public void setOptions(List<String> options) {
this.options = options;
}

public boolean isReadOnly() {
return readOnly;
}

public void setReadOnly(boolean readOnly) {
this.readOnly = readOnly;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public class CustomNodeType {

private String type;
private List<CustomNodeAttribute> customAttributes;
private boolean usesDefaultAttributes = true;

public CustomNodeType(String type) {
this.type = type;
Expand All @@ -20,6 +21,12 @@ public CustomNodeType(String type, CustomNodeAttribute... customAttributes) {
this.customAttributes = Arrays.asList(customAttributes);
}

public CustomNodeType(String type, boolean usesDefaultAttributes, CustomNodeAttribute... customAttributes) {
this.type = type;
this.customAttributes = Arrays.asList(customAttributes);
this.setUsesDefaultAttributes(usesDefaultAttributes);
}

public String getType() {
return type;
}
Expand All @@ -36,4 +43,11 @@ public void setCustomAttributes(List<CustomNodeAttribute> customAttributes) {
this.customAttributes = customAttributes;
}

public boolean isUsesDefaultAttributes() {
return usesDefaultAttributes;
}

public void setUsesDefaultAttributes(boolean usesDefaultAttributes) {
this.usesDefaultAttributes = usesDefaultAttributes;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,66 +16,107 @@ public static native void create(JavaScriptObject conf, int id, DiagramBuilderWi
'aui-diagram-builder',
function(Y) {

var customNodes = conf.customNodeTypes;
var customNodeTypes = conf.customNodeTypes;

if (typeof customNodes != 'undefined') {
for (var i = 0; i < customNodes.length; i++) {
var customNode = customNodes[i];
if (typeof customNodeTypes != 'undefined') {
for (var i = 0; i < customNodeTypes.length; i++) {
var customNodeType = customNodeTypes[i];
var attrs = {
type: {
value: customNode.type
value: customNodeType.type
}
};

var customAttributes = customNode.customAttributes;

var attributesForModel = new Array();
var customAttributes = customNodeType.customAttributes;

if (typeof customAttributes != 'undefined') {
for (var j = 0; j < customAttributes.length; j++) {
var customAttr = customAttributes[j];
attrs[customAttr.name] = {
attrs[customAttr.name.toLowerCase()] = {
validator: Y.Lang.isString,
value: customAttr.defaultValue
};
attributesForModel.push({
attributeName: customAttr.name,
name: customAttr.name
});
}
Y["DiagramNodeCustom" + customNodeType.type + "_custom_attrs"] = customAttributes;
}

Y["DiagramNodeCustom" + customNode.type] = Y.Component.create({
Y["DiagramNodeCustom" + customNodeType.type] = Y.Component.create({
NAME: 'diagram-node',

ATTRS: attrs,

EXTENDS: Y.DiagramNodeTask,

prototype: {

customNodeTypeName: customNodeType.type,
customNodeTypeUsesDefaultAttributes: customNodeType.usesDefaultAttributes,

initializer: function() {
var instance = this;

this.SERIALIZABLE_ATTRS = this.SERIALIZABLE_ATTRS.concat(
attributesForModel.map(
function(x) {
return x.attributeName;
}));
if(!instance.customNodeTypeUsesDefaultAttributes) {
this.SERIALIZABLE_ATTRS = this.SERIALIZABLE_ATTRS.filter(function (attributeName) {
if(["name", "description"].indexOf(attributeName) == -1){
return attributeName;
}
});
}


customAttributes = Y["DiagramNodeCustom" + instance.customNodeTypeName + "_custom_attrs"];

if (typeof customAttributes != 'undefined') {
for (var j = 0; j < customAttributes.length; j++) {
var customAttr = customAttributes[j];
this.SERIALIZABLE_ATTRS.push(customAttr.name.toLowerCase());
}
}
},

getPropertyModel: function () {
var instance = this;

var model = Y.DiagramNodeTask.superclass.getPropertyModel.apply(instance, arguments);

model = model.concat(attributesForModel);
customAttributes = Y["DiagramNodeCustom" + instance.customNodeTypeName + "_custom_attrs"];

var model = Y.DiagramNodeTask.superclass.getPropertyModel.apply(instance, arguments);
if(!instance.customNodeTypeUsesDefaultAttributes) {
model = model.filter(function (attrObject) {
if(["name", "description"].indexOf(attrObject.attributeName) == -1){
return attrObject;
}
});
}
if (typeof customAttributes != 'undefined') {
for (var j = 0; j < customAttributes.length; j++) {
var customAttr = customAttributes[j];
var attrObject;
attrObject = {
attributeName: customAttr.name.toLowerCase(),
name: customAttr.name,
value: customAttr.defaultValue,
readOnly: customAttr.readOnly
};
if (customAttr.comboBox) {
attrObject.editor =
new Y.DropDownCellEditor({
options: customAttr.options,
});
} else {
attrObject.editor =
new Y.TextCellEditor({
options: customAttr.options,
});
}
model.push(attrObject);
}
}
return model;
}
}
});

Y.DiagramBuilder.types[customNode.type] = Y["DiagramNodeCustom" + customNode.type];
Y.DiagramBuilder.types[customNodeType.type] = Y["DiagramNodeCustom" + customNodeType.type];
}
}

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<groupId>org.vaadin</groupId>
<artifactId>diagram-builder-root</artifactId>
<packaging>pom</packaging>
<version>1.3-SNAPSHOT</version>
<version>1.3.1</version>
<name>DiagramBuilder Add-on Root Project</name>

<modules>
Expand Down