integration/cauldron/ConceptDecorator.js

  1. /**
  2. * ConceptDecorator - decorates Concept nodes in TreeBrowser trees
  3. *
  4. * This code is licensed under the MIT License (MIT).
  5. *
  6. * Copyright 2020, 2021, 2022 Rolf Bagge, Janus B. Kristensen, CAVI,
  7. * Center for Advanced Visualization and Interaction, Aarhus University
  8. *
  9. * Permission is hereby granted, free of charge, to any person obtaining a copy
  10. * of this software and associated documentation files (the “Software”), to deal
  11. * in the Software without restriction, including without limitation the rights
  12. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  13. * copies of the Software, and to permit persons to whom the Software is
  14. * furnished to do so, subject to the following conditions:
  15. *
  16. * The above copyright notice and this permission notice shall be included in
  17. * all copies or substantial portions of the Software.
  18. *
  19. * THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  20. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  22. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  23. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  24. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  25. * THE SOFTWARE.
  26. *
  27. */
  28. /**
  29. *
  30. */
  31. class ConceptDecorator {
  32. /**
  33. * Attempts to decorate the given TreeNode
  34. * @param {TreeNode} node - The node to decorate
  35. * @returns {boolean} True/False depending on if the node was decorated
  36. */
  37. static decorate(node) {
  38. if(node.type === "ConceptNode") {
  39. node.setProperty("content", node.context.name);
  40. node.setProperty("icon", IconRegistry.createIcon("mdc:api"));
  41. return true;
  42. } else if(node.type === "ConceptInstanceNode") {
  43. node.setProperty("content", node.context.uuid);
  44. node.setProperty("icon", IconRegistry.createIcon("mdc:class"));
  45. return true;
  46. } else if(node.type === "DatastoreNode") {
  47. node.setProperty("content", node.context.name);
  48. node.setProperty("icon", IconRegistry.createIcon("mdc:circle"));
  49. return true;
  50. } else if(node.type === "ConceptRootNode") {
  51. node.setProperty("content", "Concepts");
  52. node.setProperty("icon", IconRegistry.createIcon("mdc:all_out"));
  53. return true;
  54. }
  55. return false;
  56. }
  57. /**
  58. * Attempts to decorate the given DataTransfer based on the given TreeNode
  59. * @param {TreeNode} node
  60. * @param {DataTransfer} dataTransfer
  61. * @returns {boolean} True/False depending on if the DataTransfer was decorated
  62. */
  63. static decorateDataTransfer(node, dataTransfer) {
  64. return false;
  65. }
  66. }
  67. window.ConceptDecorator = ConceptDecorator;
  68. TreeGenerator.registerDecorator(ConceptDecorator, 10);