File size: 55,425 Bytes
fe66731 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 |
/**
* Contains the logic for the sidebar.
* @param graph the graph that belongs to these controls
* @returns {{}}
*/
module.exports = function ( graph ){
var editSidebar = {},
languageTools = webvowl.util.languageTools(),
elementTools = webvowl.util.elementTools();
var prefixModule = webvowl.util.prefixTools(graph);
var selectedElementForCharacteristics;
var oldPrefix, oldPrefixURL;
var prefix_editMode = false;
editSidebar.clearMetaObjectValue = function (){
d3.select("#titleEditor").node().value = "";
d3.select("#iriEditor").node().value = "";
d3.select("#versionEditor").node().value = "";
d3.select("#authorsEditor").node().value = "";
d3.select("#descriptionEditor").node().value = "";
// todo add clear description;
};
editSidebar.updatePrefixUi = function (){
editSidebar.updateElementWidth();
var prefixListContainer = d3.select("#prefixURL_Container");
while ( prefixListContainer.node().firstChild ) {
prefixListContainer.node().removeChild(prefixListContainer.node().firstChild);
}
setupPrefixList();
};
editSidebar.setup = function (){
setupCollapsing();
setupPrefixList();
setupAddPrefixButton();
setupSupportedDatatypes();
d3.select("#titleEditor")
.on("change", function (){
graph.options().addOrUpdateGeneralObjectEntry("title", d3.select("#titleEditor").node().value);
})
.on("keydown", function (){
d3.event.stopPropagation();
if ( d3.event.keyCode === 13 ) {
d3.event.preventDefault();
graph.options().addOrUpdateGeneralObjectEntry("title", d3.select("#titleEditor").node().value);
}
});
d3.select("#iriEditor")
.on("change", function (){
if ( graph.options().addOrUpdateGeneralObjectEntry("iri", d3.select("#iriEditor").node().value) === false ) {
// restore value
d3.select("#iriEditor").node().value = graph.options().getGeneralMetaObjectProperty('iri');
}
})
.on("keydown", function (){
d3.event.stopPropagation();
if ( d3.event.keyCode === 13 ) {
d3.event.preventDefault();
if ( graph.options().addOrUpdateGeneralObjectEntry("iri", d3.select("#iriEditor").node().value) === false ) {
// restore value
d3.select("#iriEditor").node().value = graph.options().getGeneralMetaObjectProperty('iri');
}
}
});
d3.select("#versionEditor")
.on("change", function (){
graph.options().addOrUpdateGeneralObjectEntry("version", d3.select("#versionEditor").node().value);
})
.on("keydown", function (){
d3.event.stopPropagation();
if ( d3.event.keyCode === 13 ) {
d3.event.preventDefault();
graph.options().addOrUpdateGeneralObjectEntry("version", d3.select("#versionEditor").node().value);
}
});
d3.select("#authorsEditor")
.on("change", function (){
graph.options().addOrUpdateGeneralObjectEntry("author", d3.select("#authorsEditor").node().value);
})
.on("keydown", function (){
d3.event.stopPropagation();
if ( d3.event.keyCode === 13 ) {
d3.event.preventDefault();
graph.options().addOrUpdateGeneralObjectEntry("author", d3.select("#authorsEditor").node().value);
}
});
d3.select("#descriptionEditor")
.on("change", function (){
graph.options().addOrUpdateGeneralObjectEntry("description", d3.select("#descriptionEditor").node().value);
});
editSidebar.updateElementWidth();
};
function setupSupportedDatatypes(){
var datatypeEditorSelection = d3.select("#typeEditor_datatype").node();
var supportedDatatypes = ["undefined", "xsd:boolean", "xsd:double", "xsd:integer", "xsd:string"];
for ( var i = 0; i < supportedDatatypes.length; i++ ) {
var optB = document.createElement('option');
optB.innerHTML = supportedDatatypes[i];
datatypeEditorSelection.appendChild(optB);
}
}
function highlightDeleteButton( enable, name ){
var deletePath = d3.select("#del_pathFor_" + name);
var deleteRect = d3.select("#del_rectFor_" + name);
if ( enable === false ) {
deletePath.node().style = "stroke: #f00;";
deleteRect.style("cursor", "auto");
} else {
deletePath.node().style = "stroke: #ff972d;";
deleteRect.style("cursor", "pointer");
}
}
function highlightEditButton( enable, name, fill ){
var editPath = d3.select("#pathFor_" + name);
var editRect = d3.select("#rectFor_" + name);
if ( enable === false ) {
if ( fill )
editPath.node().style = "fill: #fff; stroke : #fff; stroke-width : 1px";
else
editPath.node().style = " stroke : #fff; stroke-width : 1px";
editRect.style("cursor", "auto");
} else {
if ( fill )
editPath.node().style = "fill: #ff972d; stroke : #ff972d; stroke-width : 1px";
else
editPath.node().style = "stroke : #ff972d; stroke-width : 1px";
editRect.style("cursor", "pointer");
}
}
function setupAddPrefixButton(){
var btn = d3.select("#addPrefixButton");
btn.on("click", function (){
// check if we are still in editMode?
if ( prefix_editMode === false ) {
// create new line entry;
var name = "emptyPrefixEntry";
var prefixListContainer = d3.select("#prefixURL_Container");
var prefixEditContainer = prefixListContainer.append("div");
prefixEditContainer.classed("prefixIRIElements", true);
prefixEditContainer.node().id = "prefixContainerFor_" + name;
var IconContainer = prefixEditContainer.append("div");
IconContainer.style("position", "absolute");
IconContainer.node().id = "containerFor_" + name;
var editButton = IconContainer.append("svg");
editButton.style("width", "14px");
editButton.style("height", "20px");
// editButton.classed("editPrefixButton", true);
editButton.classed("noselect", true);
//editButton.node().innerHTML = "\u2714";
editButton.node().id = "editButtonFor_" + name;
editButton.node().elementStyle = "save";
editButton.node().selectorName = name;
var editIcon = editButton.append("g");
var editRect = editIcon.append("rect");
var editPath = editIcon.append("path");
editIcon.node().id = "iconFor_" + name;
editPath.node().id = "pathFor_" + name;
editRect.node().id = "rectFor_" + name;
editIcon.node().selectorName = name;
editPath.node().selectorName = name;
editRect.node().selectorName = name;
IconContainer.node().title = "Save new prefix and IRI";
editPath.classed("editPrefixIcon");
editPath.style("stroke", "#fff");
editPath.style("stroke-width", "1px");
editPath.style("fill", "#fff");
editRect.attr("width", "14px");
editRect.attr("height", "14px");
editRect.style("fill", "#18202A");
editRect.attr("transform", "matrix(1,0,0,1,-3,4)");
editButton.selectAll("g").on("mouseover", function (){
highlightEditButton(true, this.selectorName, true);
});
editButton.selectAll("g").on("mouseout", function (){
highlightEditButton(false, this.selectorName, true);
});
// Check mark
// M9 16.2L4.8 12l-1.4 1.4L9 19 21 7l-1.4-1.4L9 16.2z
// pencil
// M3 17.25V21h3.75L17.81 9.94l-3.75-3.75L3 17.25zM20.71 7.04c.39-.39.39-1.02 0-1.41l-2.34-2.34c-.39-.39-1.02-.39-1.41 0l-1.83 1.83 3.75 3.75 1.83-1.83z
editPath.attr("d", "M9 16.2L4.8 12l-1.4 1.4L9 19 21 7l-1.4-1.4L9 16.2z");
editPath.attr("transform", "matrix(0.45,0,0,0.45,0,5)");
var prefInput = prefixEditContainer.append("input");
prefInput.classed("prefixInput", true);
prefInput.node().type = "text";
prefInput.node().id = "prefixInputFor_" + name;
prefInput.node().autocomplete = "off";
prefInput.node().value = "";
prefInput.style("margin-left", "14px");
var prefURL = prefixEditContainer.append("input");
prefURL.classed("prefixURL", true);
prefURL.node().type = "text";
prefURL.node().id = "prefixURLFor_" + name;
prefURL.node().autocomplete = "off";
prefURL.node().value = "";
prefInput.node().disabled = false;
prefURL.node().disabled = false;
prefix_editMode = true;
var deleteContainer = prefixEditContainer.append("div");
deleteContainer.style("float", "right");
var deleteButton = deleteContainer.append("svg");
deleteButton.node().id = "deleteButtonFor_" + name;
deleteContainer.node().title = "Delete prefix and IRI";
deleteButton.style("width", "10px");
deleteButton.style("height", "20px");
var deleteIcon = deleteButton.append("g");
var deleteRect = deleteIcon.append("rect");
var deletePath = deleteIcon.append("path");
deleteIcon.node().id = "del_iconFor_" + name;
deletePath.node().id = "del_pathFor_" + name;
deleteRect.node().id = "del_rectFor_" + name;
deleteIcon.node().selectorName = name;
deletePath.node().selectorName = name;
deleteRect.node().selectorName = name;
deletePath.style("stroke", "#f00");
deleteRect.attr("width", "10px");
deleteRect.attr("height", "14px");
deleteRect.style("fill", "#18202A");
deleteRect.attr("transform", "matrix(1,0,0,1,-3,4)");
deletePath.attr("d", "M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z");
deletePath.attr("transform", "matrix(0.45,0,0,0.45,0,5)");
deleteButton.selectAll("g").on("mouseover", function (){
highlightDeleteButton(true, this.selectorName);
});
deleteButton.selectAll("g").on("mouseout", function (){
highlightDeleteButton(false, this.selectorName);
});
// connect the buttons;
editButton.on("click", enablePrefixEdit);
deleteButton.on("click", deletePrefixLine);
editSidebar.updateElementWidth();
// swap focus to prefixInput
prefInput.node().focus();
oldPrefix = name;
oldPrefixURL = "";
d3.select("#addPrefixButton").node().innerHTML = "Save Prefix";
} else {
d3.select("#editButtonFor_emptyPrefixEntry").on("click")(d3.select("#editButtonFor_emptyPrefixEntry").node());
}
});
}
function setupPrefixList(){
if ( graph.isEditorMode() === false ) return;
var prefixListContainer = d3.select("#prefixURL_Container");
var prefixElements = graph.options().prefixList();
for ( var name in prefixElements ) {
if ( prefixElements.hasOwnProperty(name) ) {
var prefixEditContainer = prefixListContainer.append("div");
prefixEditContainer.classed("prefixIRIElements", true);
prefixEditContainer.node().id = "prefixContainerFor_" + name;
// create edit button which enables the input fields
var IconContainer = prefixEditContainer.append("div");
IconContainer.style("position", "absolute");
IconContainer.node().id = "containerFor_" + name;
var editButton = IconContainer.append("svg");
editButton.style("width", "14px");
editButton.style("height", "20px");
editButton.classed("noselect", true);
editButton.node().id = "editButtonFor_" + name;
IconContainer.node().title = "Edit prefix and IRI";
editButton.node().elementStyle = "save";
editButton.node().selectorName = name;
editButton.node().id = "editButtonFor_" + name;
editButton.node().elementStyle = "edit";
var editIcon = editButton.append("g");
var editRect = editIcon.append("rect");
var editPath = editIcon.append("path");
editIcon.node().id = "iconFor_" + name;
editPath.node().id = "pathFor_" + name;
editRect.node().id = "rectFor_" + name;
editIcon.node().selectorName = name;
editPath.node().selectorName = name;
editRect.node().selectorName = name;
editPath.classed("editPrefixIcon");
editPath.style("stroke", "#fff");
editPath.style("stroke-width", "1px");
editRect.attr("width", "14px");
editRect.attr("height", "14px");
editRect.style("fill", "#18202A");
editRect.attr("transform", "matrix(1,0,0,1,-3,4)");
editButton.selectAll("g").on("mouseover", function (){
var sender = this;
var fill = false;
var enable = true;
var f_editPath = d3.select("#pathFor_" + sender.selectorName);
var f_editRect = d3.select("#rectFor_" + sender.selectorName);
if ( enable === false ) {
if ( fill )
f_editPath.node().style = "fill: #fff; stroke : #fff; stroke-width : 1px";
else
f_editPath.node().style = " stroke : #fff; stroke-width : 1px";
f_editRect.style("cursor", "auto");
} else {
if ( fill )
f_editPath.node().style = "fill: #ff972d; stroke : #ff972d; stroke-width : 1px";
else
f_editPath.node().style = "stroke : #ff972d; stroke-width : 1px";
f_editRect.style("cursor", "pointer");
}
});
editButton.selectAll("g").on("mouseout", function (){
var sender = this;
var fill = false;
var enable = false;
var f_editPath = d3.select("#pathFor_" + sender.selectorName);
var f_editRect = d3.select("#rectFor_" + sender.selectorName);
if ( enable === false ) {
if ( fill )
f_editPath.node().style = "fill: #fff; stroke : #fff; stroke-width : 1px";
else
f_editPath.node().style = " stroke : #fff; stroke-width : 1px";
f_editRect.style("cursor", "auto");
} else {
if ( fill )
f_editPath.node().style = "fill: #ff972d; stroke : #ff972d; stroke-width : 1px";
else
f_editPath.node().style = "stroke : #ff972d; stroke-width : 1px";
f_editRect.style("cursor", "pointer");
}
});
editPath.attr("d", "M3 17.25V21h3.75L17.81 9.94l-3.75-3.75L3 17.25zM20.71 7.04c.39-.39.39-1.02 0-1.41l-2.34-2.34c-.39-.39-1.02-.39-1.41 0l-1.83 1.83 3.75 3.75 1.83-1.83z");
editPath.attr("transform", "matrix(-0.45,0,0,0.45,10,5)");
// create input field for prefix
var prefInput = prefixEditContainer.append("input");
prefInput.classed("prefixInput", true);
prefInput.node().type = "text";
prefInput.node().id = "prefixInputFor_" + name;
prefInput.node().autocomplete = "off";
prefInput.node().value = name;
prefInput.style("margin-left", "14px");
// create input field for prefix url
var prefURL = prefixEditContainer.append("input");
prefURL.classed("prefixURL", true);
prefURL.node().type = "text";
prefURL.node().id = "prefixURLFor_" + name;
prefURL.node().autocomplete = "off";
prefURL.node().value = prefixElements[name];
prefURL.node().title = prefixElements[name];
// disable the input fields (already defined elements can be edited later)
prefInput.node().disabled = true;
prefURL.node().disabled = true;
// create the delete button
var deleteContainer = prefixEditContainer.append("div");
deleteContainer.style("float", "right");
var deleteButton = deleteContainer.append("svg");
deleteButton.node().id = "deleteButtonFor_" + name;
deleteContainer.node().title = "Delete prefix and IRI";
deleteButton.style("width", "10px");
deleteButton.style("height", "20px");
var deleteIcon = deleteButton.append("g");
var deleteRect = deleteIcon.append("rect");
var deletePath = deleteIcon.append("path");
deleteIcon.node().id = "del_iconFor_" + name;
deletePath.node().id = "del_pathFor_" + name;
deleteRect.node().id = "del_rectFor_" + name;
deleteIcon.node().selectorName = name;
deletePath.node().selectorName = name;
deleteRect.node().selectorName = name;
deletePath.style("stroke", "#f00");
deleteRect.attr("width", "10px");
deleteRect.attr("height", "14px");
deleteRect.style("fill", "#18202A");
deleteRect.attr("transform", "matrix(1,0,0,1,-3,4)");
deletePath.attr("d", "M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z");
deletePath.attr("transform", "matrix(0.45,0,0,0.45,0,5)");
deleteButton.selectAll("g").on("mouseover", function (){
var selector = this;
var enable = true;
var f_deletePath = d3.select("#del_pathFor_" + selector.selectorName);
var f_deleteRect = d3.select("#del_rectFor_" + selector.selectorName);
if ( enable === false ) {
f_deletePath.node().style = "stroke: #f00;";
f_deleteRect.style("cursor", "auto");
} else {
f_deletePath.node().style = "stroke: #ff972d;";
f_deleteRect.style("cursor", "pointer");
}
});
deleteButton.selectAll("g").on("mouseout", function (){
var selector = this;
var enable = false;
var f_deletePath = d3.select("#del_pathFor_" + selector.selectorName);
var f_deleteRect = d3.select("#del_rectFor_" + selector.selectorName);
if ( enable === false ) {
f_deletePath.node().style = "stroke: #f00;";
f_deleteRect.style("cursor", "auto");
} else {
f_deletePath.node().style = "stroke: #ff972d;";
f_deleteRect.style("cursor", "pointer");
}
});
editButton.on("click", enablePrefixEdit);
deleteButton.on("click", deletePrefixLine);
// EXPERIMENTAL
if ( name === "rdf" ||
name === "rdfs" ||
name === "xsd" || name === "dc" ||
name === "owl"
) {
// make them invis so the spacing does not change
IconContainer.classed("hidden", true);
deleteContainer.classed("hidden", true);
}
}
}
prefixModule.updatePrefixModel();
}
function deletePrefixLine(){
if ( this.disabled === true ) return;
d3.select("#addPrefixButton").node().innerHTML = "Add Prefix";
var selector = this.id.split("_")[1];
d3.select("#prefixContainerFor_" + selector).remove();
graph.options().removePrefix(selector);
prefix_editMode = false; // <<TODO make some sanity checks
prefixModule.updatePrefixModel();
}
function enablePrefixEdit( item ){
var agent = this;
if ( item )
agent = item;
if ( agent.disabled === true ) return;
var selector = agent.id.split("_")[1];
var stl = agent.elementStyle;
if ( stl === "edit" ) {
d3.select("#prefixInputFor_" + selector).node().disabled = false;
d3.select("#prefixURLFor_" + selector).node().disabled = false;
// change the button content
// this.innerHTML = "\u2714";
agent.elementStyle = "save";
oldPrefix = d3.select("#prefixInputFor_" + selector).node().value;
oldPrefixURL = d3.select("#prefixURLFor_" + selector).node().value;
prefix_editMode = true;
if ( d3.select("#containerFor_" + selector).node() )
d3.select("#containerFor_" + selector).node().title = "Save new prefix and IRI";
var editButton = d3.select(agent);
editButton.selectAll("g").on("mouseover", function (){
highlightEditButton(true, agent.selectorName, true);
});
editButton.selectAll("g").on("mouseout", function (){
highlightEditButton(false, agent.selectorName, true);
});
var editPath = d3.select("#pathFor_" + agent.selectorName);
editPath.attr("d", "M9 16.2L4.8 12l-1.4 1.4L9 19 21 7l-1.4-1.4L9 16.2z");
editPath.attr("transform", "matrix(0.45,0,0,0.45,0,5)");
highlightEditButton(true, agent.selectorName, true);
}
if ( stl === "save" ) {
var newPrefixURL = d3.select("#prefixURLFor_" + selector).node().value;
var newPrefix = d3.select("#prefixInputFor_" + selector).node().value;
if ( graph.options().updatePrefix(oldPrefix, newPrefix, oldPrefixURL, newPrefixURL) === true ) {
d3.select("#prefixInputFor_" + newPrefix).node().disabled = true;
d3.select("#prefixURLFor_" + newPrefix).node().disabled = true;
d3.select("#addPrefixButton").node().innerHTML = "Add Prefix";
if ( d3.select("#containerFor_" + selector).node() )
d3.select("#containerFor_" + selector).node().title = "Edit prefix and IRI";
// change the button content
agent.elementStyle = "edit";
prefix_editMode = false;
prefixModule.updatePrefixModel();
var saveButton = d3.select(agent);
saveButton.selectAll("g").on("mouseover", function (){
highlightEditButton(true, agent.selectorName, false);
});
saveButton.selectAll("g").on("mouseout", function (){
highlightEditButton(false, agent.selectorName, false);
});
var savePath = d3.select("#pathFor_" + agent.selectorName);
savePath.attr("d", "M3 17.25V21h3.75L17.81 9.94l-3.75-3.75L3 17.25zM20.71 7.04c.39-.39.39-1.02 0-1.41l-2.34-2.34c-.39-.39-1.02-.39-1.41 0l-1.83 1.83 3.75 3.75 1.83-1.83z");
savePath.attr("transform", "matrix(-0.45,0,0,0.45,10,5)");
highlightEditButton(true, agent.selectorName, false);
}
}
}
function changeDatatypeType( element ){
var datatypeEditorSelection = d3.select("#typeEditor_datatype").node();
var givenName = datatypeEditorSelection.value;
var identifier = givenName.split(":")[1];
if ( datatypeEditorSelection.value !== "undefined" ) {
d3.select("#element_iriEditor").node().disabled = true;
d3.select("#element_labelEditor").node().disabled = true;
} else {
identifier = "undefined";
d3.select("#element_iriEditor").node().disabled = false;
d3.select("#element_labelEditor").node().disabled = false;
}
element.label(identifier);
element.dType(givenName);
element.iri("http://www.w3.org/2001/XMLSchema#" + identifier);
element.baseIri("http://www.w3.org/2001/XMLSchema#");
element.redrawLabelText();
d3.select("#element_iriEditor").node().value = prefixModule.getPrefixRepresentationForFullURI(element.iri());
d3.select("#element_iriEditor").node().title = element.iri();
d3.select("#element_labelEditor").node().value = element.labelForCurrentLanguage();
}
function identifyExternalCharacteristicForElement( ontoIRI, elementIRI ){
return (elementIRI.indexOf(ontoIRI) === -1);
}
function defaultIriValue( element ){
// get the iri of that element;
if ( graph.options().getGeneralMetaObject().iri ) {
var str2Compare = graph.options().getGeneralMetaObject().iri + element.id();
return element.iri() === str2Compare;
}
return false;
}
function getURLFROMPrefixedVersion( element ){
var url = d3.select("#element_iriEditor").node().value;
var base = graph.options().getGeneralMetaObjectProperty("iri");
if ( validURL(url) === false ) {
// make better usability
// try to split element;
var tokens = url.split(":");
//console.log("try to split the input into prefix:name")
console.log("Tokens");
console.log(tokens);
console.log("---------------");
// TODO MORE VALIDATION TESTS
if ( tokens.length === 2 ) {
var pr = tokens[0];
var name = tokens[1];
if ( pr.length > 0 ) {
var basePref = graph.options().prefixList()[pr];
if ( basePref === undefined ) {
console.log("ERROR __________________");
graph.options().warningModule().showWarning("Invalid Element IRI",
"Could not resolve prefix '" + basePref + "'",
"Restoring previous IRI for Element" + element.iri(), 1, false);
d3.select("#element_iriEditor").node().value = element.iri();
return;
}
// check if url is not empty
if ( name.length === 0 ) {
graph.options().warningModule().showWarning("Invalid Element IRI",
"Input IRI is EMPTY",
"Restoring previous IRI for Element" + element.iri(), 1, false);
console.log("NO INPUT PROVIDED");
d3.select("#element_iriEditor").node().value = element.iri();
return;
}
url = basePref + name;
}
else {
url = base + name;
}
} else {
if ( url.length === 0 ) {
//
console.log("NO INPUT PROVIDED");
d3.select("#element_iriEditor").node().value = element.iri();
return;
}
// failed to identify anything useful
console.log("Tryig to use the input!");
url = base + url;
}
}
return url;
}
function changeIriForElement( element ){
var url = getURLFROMPrefixedVersion(element);
var base = graph.options().getGeneralMetaObjectProperty("iri");
var sanityCheckResult;
if ( elementTools.isNode(element) ) {
sanityCheckResult = graph.checkIfIriClassAlreadyExist(url);
if ( sanityCheckResult === false ) {
element.iri(url);
} else {
// throw warnign
graph.options().warningModule().showWarning("Already seen this class",
"Input IRI: " + url + " for element: " + element.labelForCurrentLanguage() + " already been set",
"Restoring previous IRI for Element : " + element.iri(), 2, false, sanityCheckResult);
editSidebar.updateSelectionInformation(element);
return;
}
}
if ( elementTools.isProperty(element) === true ) {
sanityCheckResult = editSidebar.checkProperIriChange(element, url);
if ( sanityCheckResult !== false ) {
graph.options().warningModule().showWarning("Already seen this property",
"Input IRI: " + url + " for element: " + element.labelForCurrentLanguage() + " already been set",
"Restoring previous IRI for Element : " + element.iri(), 1, false, sanityCheckResult);
editSidebar.updateSelectionInformation(element);
return;
}
}
// if (element.existingPropertyIRI(url)===true){
// console.log("I Have seen this Particular URL already "+url);
// graph.options().warningModule().showWarning("Already Seen This one ",
// "Input IRI For Element"+ element.labelForCurrentLanguage()+" already been set ",
// "Restoring previous IRI for Element"+element.iri(),1,false);
// d3.select("#element_iriEditor").node().value=graph.options().prefixModule().getPrefixRepresentationForFullURI(element.iri());
// editSidebar.updateSelectionInformation(element);
// return;
// }
element.iri(url);
if ( identifyExternalCharacteristicForElement(base, url) === true ) {
addAttribute(element, "external");
// background color for external element;
element.backgroundColor("#36C");
element.redrawElement();
element.redrawLabelText();
// handle visual selection
} else {
removeAttribute(element, "external");
// background color for external element;
element.backgroundColor(undefined);
element.redrawElement();
element.redrawLabelText();
}
if ( element.focused() ) {
graph.options().focuserModule().handle(element, true); // unfocus
graph.options().focuserModule().handle(element, true); // focus
}
// graph.options().focuserModule().handle(undefined);
d3.select("#element_iriEditor").node().value = prefixModule.getPrefixRepresentationForFullURI(url);
editSidebar.updateSelectionInformation(element);
}
function validURL( str ){
var urlregex = /^(https?|ftp):\/\/([a-zA-Z0-9.-]+(:[a-zA-Z0-9.&%$-]+)*@)*((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])){3}|([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]+\.(com|edu|gov|int|mil|net|org|biz|arpa|info|name|pro|aero|coop|museum|[a-zA-Z]{2}))(:[0-9]+)*(\/($|[a-zA-Z0-9.,?'\\+&%$#=~_-]+))*$/;
return urlregex.test(str);
}
function changeLabelForElement( element ){
element.label(d3.select("#element_labelEditor").node().value);
element.redrawLabelText();
}
editSidebar.updateEditDeleteButtonIds = function ( oldPrefix, newPrefix ){
d3.select("#prefixInputFor_" + oldPrefix).node().id = "prefixInputFor_" + newPrefix;
d3.select("#prefixURLFor_" + oldPrefix).node().id = "prefixURLFor_" + newPrefix;
d3.select("#deleteButtonFor_" + oldPrefix).node().id = "deleteButtonFor_" + newPrefix;
d3.select("#editButtonFor_" + oldPrefix).node().id = "editButtonFor_" + newPrefix;
d3.select("#prefixContainerFor_" + oldPrefix).node().id = "prefixContainerFor_" + newPrefix;
};
editSidebar.checkForExistingURL = function ( url ){
var i;
var allProps = graph.getUnfilteredData().properties;
for ( i = 0; i < allProps.length; i++ ) {
if ( allProps[i].iri() === url ) return true;
}
return false;
};
editSidebar.checkProperIriChange = function ( element, url ){
console.log("Element changed Label");
console.log("Testing URL " + url);
if ( element.type() === "rdfs:subClassOf" || element.type() === "owl:disjointWith" ) {
console.log("ignore this for now, already handled in the type and domain range changer");
} else {
var i;
var allProps = graph.getUnfilteredData().properties;
for ( i = 0; i < allProps.length; i++ ) {
if ( allProps[i] === element ) continue;
if ( allProps[i].iri() === url ) return allProps[i];
}
}
return false;
};
editSidebar.updateSelectionInformation = function ( element ){
if ( element === undefined ) {
// show hint;
d3.select("#selectedElementProperties").classed("hidden", true);
d3.select("#selectedElementPropertiesEmptyHint").classed("hidden", false);
selectedElementForCharacteristics = null;
editSidebar.updateElementWidth();
}
else {
d3.select("#selectedElementProperties").classed("hidden", false);
d3.select("#selectedElementPropertiesEmptyHint").classed("hidden", true);
d3.select("#typeEditForm_datatype").classed("hidden", true);
// set the element IRI, and labels
d3.select("#element_iriEditor").node().value = element.iri();
d3.select("#element_labelEditor").node().value = element.labelForCurrentLanguage();
d3.select("#element_iriEditor").node().title = element.iri();
d3.select("#element_iriEditor")
.on("change", function (){
var elementIRI = element.iri();
var prefixed = graph.options().prefixModule().getPrefixRepresentationForFullURI(elementIRI);
if ( prefixed === d3.select("#element_iriEditor").node().value ) {
console.log("Iri is identical, nothing has changed!");
return;
}
changeIriForElement(element);
})
.on("keydown", function (){
d3.event.stopPropagation();
if ( d3.event.keyCode === 13 ) {
d3.event.preventDefault();
console.log("IRI CHANGED Via ENTER pressed");
changeIriForElement(element);
d3.select("#element_iriEditor").node().title = element.iri();
}
});
var forceIRISync = defaultIriValue(element);
d3.select("#element_labelEditor")
.on("change", function (){
var sanityCheckResult;
console.log("Element changed Label");
var url = getURLFROMPrefixedVersion(element);
if ( element.iri() !== url ) {
if ( elementTools.isProperty(element) === true ) {
sanityCheckResult = editSidebar.checkProperIriChange(element, url);
if ( sanityCheckResult !== false ) {
graph.options().warningModule().showWarning("Already seen this property",
"Input IRI: " + url + " for element: " + element.labelForCurrentLanguage() + " already been set",
"Continuing with duplicate property!", 1, false, sanityCheckResult);
editSidebar.updateSelectionInformation(element);
return;
}
}
if ( elementTools.isNode(element) === true ) {
sanityCheckResult = graph.checkIfIriClassAlreadyExist(url);
if ( sanityCheckResult !== false ) {
graph.options().warningModule().showWarning("Already seen this Class",
"Input IRI: " + url + " for element: " + element.labelForCurrentLanguage() + " already been set",
"Restoring previous IRI for Element : " + element.iri(), 2, false, sanityCheckResult);
editSidebar.updateSelectionInformation(element);
return;
}
}
element.iri(url);
}
changeLabelForElement(element);
editSidebar.updateSelectionInformation(element); // prevents that it will be changed if node is still active
})
.on("keydown", function (){
d3.event.stopPropagation();
if ( d3.event.keyCode === 13 ) {
d3.event.preventDefault();
var sanityCheckResult;
console.log("Element changed Label");
var url = getURLFROMPrefixedVersion(element);
if ( element.iri() !== url ) {
if ( elementTools.isProperty(element) === true ) {
sanityCheckResult = editSidebar.checkProperIriChange(element, url);
if ( sanityCheckResult !== false ) {
graph.options().warningModule().showWarning("Already seen this property",
"Input IRI: " + url + " for element: " + element.labelForCurrentLanguage() + " already been set",
"Continuing with duplicate property!", 1, false, sanityCheckResult);
editSidebar.updateSelectionInformation(element);
return;
}
}
if ( elementTools.isNode(element) === true ) {
sanityCheckResult = graph.checkIfIriClassAlreadyExist(url);
if ( sanityCheckResult !== false ) {
graph.options().warningModule().showWarning("Already seen this Class",
"Input IRI: " + url + " for element: " + element.labelForCurrentLanguage() + " already been set",
"Restoring previous IRI for Element : " + element.iri(), 2, false, sanityCheckResult);
editSidebar.updateSelectionInformation(element);
return;
}
}
element.iri(url);
}
changeLabelForElement(element);
}
})
.on("keyup", function (){
if ( forceIRISync ) {
var labelName = d3.select("#element_labelEditor").node().value;
var resourceName = labelName.replaceAll(" ", "_");
var syncedIRI = element.baseIri() + resourceName;
//element.iri(syncedIRI);
d3.select("#element_iriEditor").node().title = element.iri();
d3.select("#element_iriEditor").node().value = prefixModule.getPrefixRepresentationForFullURI(syncedIRI);
}
});
// check if we are allowed to change IRI OR LABEL
d3.select("#element_iriEditor").node().disabled = false;
d3.select("#element_labelEditor").node().disabled = false;
if ( element.type() === "rdfs:subClassOf" ) {
d3.select("#element_iriEditor").node().value = "http://www.w3.org/2000/01/rdf-schema#subClassOf";
d3.select("#element_iriEditor").node().title = "http://www.w3.org/2000/01/rdf-schema#subClassOf";
d3.select("#element_labelEditor").node().value = "Subclass of";
d3.select("#element_iriEditor").node().disabled = true;
d3.select("#element_labelEditor").node().disabled = true;
}
if ( element.type() === "owl:Thing" ) {
d3.select("#element_iriEditor").node().value = "http://www.w3.org/2002/07/owl#Thing";
d3.select("#element_iriEditor").node().title = "http://www.w3.org/2002/07/owl#Thing";
d3.select("#element_labelEditor").node().value = "Thing";
d3.select("#element_iriEditor").node().disabled = true;
d3.select("#element_labelEditor").node().disabled = true;
}
if ( element.type() === "owl:disjointWith" ) {
d3.select("#element_iriEditor").node().value = "http://www.w3.org/2002/07/owl#disjointWith";
d3.select("#element_iriEditor").node().title = "http://www.w3.org/2002/07/owl#disjointWith";
d3.select("#element_iriEditor").node().disabled = true;
d3.select("#element_labelEditor").node().disabled = true;
}
if ( element.type() === "rdfs:Literal" ) {
d3.select("#element_iriEditor").node().value = "http://www.w3.org/2000/01/rdf-schema#Literal";
d3.select("#element_iriEditor").node().title = "http://www.w3.org/2000/01/rdf-schema#Literal";
d3.select("#element_iriEditor").node().disabled = true;
d3.select("#element_labelEditor").node().disabled = true;
element.iri("http://www.w3.org/2000/01/rdf-schema#Literal");
}
if ( element.type() === "rdfs:Datatype" ) {
var datatypeEditorSelection = d3.select("#typeEditor_datatype");
d3.select("#typeEditForm_datatype").classed("hidden", false);
element.iri("http://www.w3.org/2000/01/rdf-schema#Datatype");
d3.select("#element_iriEditor").node().value = "http://www.w3.org/2000/01/rdf-schema#Datatype";
d3.select("#element_iriEditor").node().title = "http://www.w3.org/2000/01/rdf-schema#Datatype";
d3.select("#element_iriEditor").node().disabled = true;
d3.select("#element_labelEditor").node().disabled = true;
datatypeEditorSelection.node().value = element.dType();
if ( datatypeEditorSelection.node().value === "undefined" ) {
d3.select("#element_iriEditor").node().disabled = true; // always prevent IRI modifications
d3.select("#element_labelEditor").node().disabled = false;
}
// reconnect the element
datatypeEditorSelection.on("change", function (){
changeDatatypeType(element);
});
}
// add type selector
var typeEditorSelection = d3.select("#typeEditor").node();
var htmlCollection = typeEditorSelection.children;
var numEntries = htmlCollection.length;
var i;
var elementPrototypes = getElementPrototypes(element);
for ( i = 0; i < numEntries; i++ )
typeEditorSelection.removeChild(htmlCollection[0]);
for ( i = 0; i < elementPrototypes.length; i++ ) {
var optA = document.createElement('option');
optA.innerHTML = elementPrototypes[i];
typeEditorSelection.appendChild(optA);
}
// set the proper value in the selection
typeEditorSelection.value = element.type();
d3.select("#typeEditor").on("change", function (){
elementTypeSelectionChanged(element);
});
// add characteristics selection
var needChar = elementNeedsCharacteristics(element);
d3.select("#property_characteristics_Container").classed("hidden", !needChar);
if ( needChar === true ) {
addElementsCharacteristics(element);
}
var fullURI = d3.select("#element_iriEditor").node().value;
d3.select("#element_iriEditor").node().value = prefixModule.getPrefixRepresentationForFullURI(fullURI);
d3.select("#element_iriEditor").node().title = fullURI;
editSidebar.updateElementWidth();
}
};
editSidebar.updateGeneralOntologyInfo = function (){
var preferredLanguage = graph && graph.language ? graph.language() : null;
// get it from graph.options
var generalMetaObj = graph.options().getGeneralMetaObject();
if ( generalMetaObj.hasOwnProperty("title") ) {
// title has language to it -.-
if ( typeof generalMetaObj.title === "object" ) {
d3.select("#titleEditor").node().value = languageTools.textInLanguage(generalMetaObj.title, preferredLanguage);
} else
d3.select("#titleEditor").node().value = generalMetaObj.title;
}
if ( generalMetaObj.hasOwnProperty("iri") ) d3.select("#iriEditor").node().value = generalMetaObj.iri;
if ( generalMetaObj.hasOwnProperty("version") ) d3.select("#versionEditor").node().value = generalMetaObj.version;
if ( generalMetaObj.hasOwnProperty("author") ) d3.select("#authorsEditor").node().value = generalMetaObj.author;
if ( generalMetaObj.hasOwnProperty("description") ) {
if ( typeof generalMetaObj.description === "object" )
d3.select("#descriptionEditor").node().value =
languageTools.textInLanguage(generalMetaObj.description, preferredLanguage);
else
d3.select("#descriptionEditor").node().value = generalMetaObj.description;
}
else
d3.select("#descriptionEditor").node().value = "No Description";
};
editSidebar.updateElementWidth = function (){
var height = window.innerHeight - 40;
var lsb_offset = d3.select("#logo").node().getBoundingClientRect().height + 5;
var lsb_height = height - lsb_offset;
d3.select("#containerForLeftSideBar").style("top", lsb_offset + "px");
d3.select("#leftSideBarCollapseButton").style("top", lsb_offset + "px");
d3.select("#containerForLeftSideBar").style("height", lsb_height + "px");
var div_width = d3.select("#generalDetailsEdit").node().getBoundingClientRect().width;
div_width += 10;
var title_labelWidth = d3.select("#titleEditor-label").node().getBoundingClientRect().width + 20;
var iri_labelWidth = d3.select("#iriEditor-label").node().getBoundingClientRect().width + 20;
var version_labelWidth = d3.select("#versionEditor-label").node().getBoundingClientRect().width + 20;
var author_labelWidth = d3.select("#authorsEditor-label").node().getBoundingClientRect().width + 20;
//find max width;
var maxW = 0;
maxW = Math.max(maxW, title_labelWidth);
maxW = Math.max(maxW, iri_labelWidth);
maxW = Math.max(maxW, version_labelWidth);
maxW = Math.max(maxW, author_labelWidth);
var meta_inputWidth = div_width - maxW - 10;
d3.select("#titleEditor").style("width", meta_inputWidth + "px");
d3.select("#iriEditor").style("width", meta_inputWidth + "px");
d3.select("#versionEditor").style("width", meta_inputWidth + "px");
d3.select("#authorsEditor").style("width", meta_inputWidth + "px");
var elementIri_width = d3.select("#element_iriEditor-label").node().getBoundingClientRect().width + 20;
var elementLabel_width = d3.select("#element_labelEditor-label").node().getBoundingClientRect().width + 20;
var elementType_width = d3.select("#typeEditor-label").node().getBoundingClientRect().width + 20;
var elementDType_width = d3.select("#typeEditor_datatype-label").node().getBoundingClientRect().width + 20;
maxW = 0;
maxW = Math.max(maxW, elementIri_width);
maxW = Math.max(maxW, elementLabel_width);
maxW = Math.max(maxW, elementType_width);
maxW = Math.max(maxW, elementDType_width);
var selectedElement_inputWidth = div_width - maxW - 10;
d3.select("#element_iriEditor").style("width", selectedElement_inputWidth + "px");
d3.select("#element_labelEditor").style("width", selectedElement_inputWidth + "px");
d3.select("#typeEditor").style("width", selectedElement_inputWidth + 4 + "px");
d3.select("#typeEditor_datatype").style("width", selectedElement_inputWidth + 4 + "px");
// update prefix Element width;
var containerWidth = d3.select("#containerForPrefixURL").node().getBoundingClientRect().width;
if ( containerWidth !== 0 ) {
var inputs = d3.selectAll(".prefixInput");
if ( inputs.node() ) {
var prefixWidth = d3.selectAll(".prefixInput").node().getBoundingClientRect().width;
d3.selectAll(".prefixURL").style("width", containerWidth - prefixWidth - 45 + "px");
}
}
};
function addElementsCharacteristics( element ){
// save selected element for checkbox handler
selectedElementForCharacteristics = element;
var i;
// KILL old elements
var charSelectionNode = d3.select("#property_characteristics_Selection");
var htmlCollection = charSelectionNode.node().children;
if ( htmlCollection ) {
var numEntries = htmlCollection.length;
for ( var q = 0; q < numEntries; q++ ) {
charSelectionNode.node().removeChild(htmlCollection[0]);
}
}
// datatypes kind of ignored by the elementsNeedCharacteristics function
// so we need to check if we are a node or not
if ( element.attributes().indexOf("external") > -1 ) {
// add external span to the div;
var externalCharSpan = charSelectionNode.append("span");
externalCharSpan.classed("spanForCharSelection", true);
externalCharSpan.node().innerHTML = "external";
}
var filterContainer,
filterCheckbox;
if ( elementTools.isNode(element) === true ) {
// add the deprecated characteristic;
var arrayOfNodeChars = ["deprecated"];
for ( i = 0; i < arrayOfNodeChars.length; i++ ) {
filterContainer = charSelectionNode
.append("div")
.classed("checkboxContainer", true)
.style("padding-top", "2px");
filterCheckbox = filterContainer.append("input")
.classed("filterCheckbox", true)
.attr("id", "CharacteristicsCheckbox" + i)
.attr("type", "checkbox")
.attr("characteristics", arrayOfNodeChars[i])
.property("checked", getPresentAttribute(element, arrayOfNodeChars[i]));
//
filterContainer.append("label")
.attr("for", "CharacteristicsCheckbox" + i)
.text(arrayOfNodeChars[i]);
filterCheckbox.on("click", handleCheckBoxClick);
}
}
else {
// add the deprecated characteristic;
var arrayOfPropertyChars = ["deprecated", "inverse functional", "functional", "transitive"];
if ( elementTools.isDatatypeProperty(element) === true ) {
arrayOfPropertyChars = ["deprecated", "functional"];
}
for ( i = 0; i < arrayOfPropertyChars.length; i++ ) {
filterContainer = charSelectionNode
.append("div")
.classed("checkboxContainer", true)
.style("padding-top", "2px");
filterCheckbox = filterContainer.append("input")
.classed("filterCheckbox", true)
.attr("id", "CharacteristicsCheckbox" + i)
.attr("type", "checkbox")
.attr("characteristics", arrayOfPropertyChars[i])
.property("checked", getPresentAttribute(element, arrayOfPropertyChars[i]));
//
filterContainer.append("label")
.attr("for", "CharacteristicsCheckbox" + i)
.text(arrayOfPropertyChars[i]);
filterCheckbox.on("click", handleCheckBoxClick);
}
}
}
function getPresentAttribute( selectedElement, element ){
return (selectedElement.attributes().indexOf(element) >= 0);
}
function handleCheckBoxClick(){
var checked = this.checked;
var char = this.getAttribute("characteristics");
if ( checked === true ) {
addAttribute(selectedElementForCharacteristics, char);
} else {
removeAttribute(selectedElementForCharacteristics, char);
}
// graph.executeColorExternalsModule();
selectedElementForCharacteristics.redrawElement();
// workaround to have the node still be focused as rendering element
selectedElementForCharacteristics.focused(false);
selectedElementForCharacteristics.toggleFocus();
}
function addAttribute( selectedElement, char ){
if ( selectedElement.attributes().indexOf(char) === -1 ) {
// not found add it
var attr = selectedElement.attributes();
attr.push(char);
selectedElement.attributes(attr);
}// indications string update;
if ( selectedElement.indications().indexOf(char) === -1 ) {
var indications = selectedElement.indications();
indications.push(char);
selectedElement.indications(indications);
}
// add visual attributes
var visAttr;
if ( selectedElement.visualAttributes().indexOf(char) === -1 ) {
visAttr = selectedElement.visualAttributes();
visAttr.push(char);
selectedElement.visualAttributes(visAttr);
}
if ( getPresentAttribute(selectedElement, "external") && getPresentAttribute(selectedElement, "deprecated") ) {
visAttr = selectedElement.visualAttributes();
var visInd = visAttr.indexOf("external");
if ( visInd > -1 ) {
visAttr.splice(visInd, 1);
}
selectedElement.visualAttributes(visAttr);
}
}
function removeAttribute( selectedElement, element ){
var attr = selectedElement.attributes();
var indications = selectedElement.indications();
var visAttr = selectedElement.visualAttributes();
var attrInd = attr.indexOf(element);
if ( attrInd >= 0 ) {
attr.splice(attrInd, 1);
}
var indInd = indications.indexOf(element);
if ( indInd > -1 ) {
indications.splice(indInd, 1);
}
var visInd = visAttr.indexOf(element);
if ( visInd > -1 ) {
visAttr.splice(visInd, 1);
}
selectedElement.attributes(attr);
selectedElement.indications(indications);
selectedElement.visualAttributes(visAttr);
if ( element === "deprecated" ) {
// set its to its original Style
//typeBaseThign
// todo : fix all different types
if ( selectedElement.type() === "owl:Class" ) selectedElement.styleClass("class");
if ( selectedElement.type() === "owl:DatatypeProperty" ) selectedElement.styleClass("datatypeproperty");
if ( selectedElement.type() === "owl:ObjectProperty" ) selectedElement.styleClass("objectproperty");
if ( selectedElement.type() === "owl:disjointWith" ) selectedElement.styleClass("disjointwith");
}
}
function elementNeedsCharacteristics( element ){
//TODO: Add more types
if ( element.type() === "owl:Thing" ||
element.type() === "rdfs:subClassOf" ||
element.type() === "rdfs:Literal" ||
element.type() === "rdfs:Datatype" ||
element.type() === "rdfs:disjointWith" )
return false;
// if (element.attributes().indexOf("external")||
// element.attributes().indexOf("deprecated"))
// return true;
return true;
}
function elementTypeSelectionChanged( element ){
if ( elementTools.isNode(element) ) {
if ( graph.changeNodeType(element) === false ) {
//restore old value
if ( elementTools.isDatatype(element) === true ) {
}
editSidebar.updateSelectionInformation(element);
}
}
if ( elementTools.isProperty(element) ) {
if ( graph.changePropertyType(element) === false ) {
//restore old value
editSidebar.updateSelectionInformation(element);
}
}
}
function getElementPrototypes( selectedElement ){
var availiblePrototypes = [];
// TODO the text should be also complied with the prefixes loaded into the ontology
if ( elementTools.isProperty(selectedElement) ) {
if ( selectedElement.type() === "owl:DatatypeProperty" )
availiblePrototypes.push("owl:DatatypeProperty");
else {
availiblePrototypes.push("owl:ObjectProperty");
// handling loops !
if ( selectedElement.domain() !== selectedElement.range() ) {
availiblePrototypes.push("rdfs:subClassOf");
}
availiblePrototypes.push("owl:disjointWith");
availiblePrototypes.push("owl:allValuesFrom");
availiblePrototypes.push("owl:someValuesFrom");
}
return availiblePrototypes;
}
if ( selectedElement.renderType() === "rect" ) {
availiblePrototypes.push("rdfs:Literal");
availiblePrototypes.push("rdfs:Datatype");
} else {
availiblePrototypes.push("owl:Class");
availiblePrototypes.push("owl:Thing");
// TODO: ADD MORE TYPES
// availiblePrototypes.push("owl:complementOf");
// availiblePrototypes.push("owl:disjointUnionOf");
}
return availiblePrototypes;
}
function setupCollapsing(){
// TODO : Decision , for now I want to have the control over the collapse expand operation of the
// TODO : elements, otherwise the old approach will also randomly collapse other containers
// adapted version of this example: http://www.normansblog.de/simple-jquery-accordion/
function collapseContainers( containers ){
containers.classed("hidden", true);
}
function expandContainers( containers ){
containers.classed("hidden", false);
}
var triggers = d3.selectAll(".accordion-trigger");
// Collapse all inactive triggers on startup
// collapseContainers(d3.selectAll(".accordion-trigger:not(.accordion-trigger-active) + div"));
triggers.on("click", function (){
var selectedTrigger = d3.select(this);
if ( selectedTrigger.classed("accordion-trigger-active") ) {
// Collapse the active (which is also the selected) trigger
collapseContainers(d3.select(selectedTrigger.node().nextElementSibling));
selectedTrigger.classed("accordion-trigger-active", false);
} else {
// Collapse the other trigger ...
// collapseContainers(d3.selectAll(".accordion-trigger-active + div"));
// ... and expand the selected one
expandContainers(d3.select(selectedTrigger.node().nextElementSibling));
selectedTrigger.classed("accordion-trigger-active", true);
}
editSidebar.updateElementWidth();
});
}
return editSidebar;
};
|