LabelUtil.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import { is } from '../../util/ModelUtil';
  2. function getLabelAttr(semantic) {
  3. if (
  4. is(semantic, 'bpmn:FlowElement') ||
  5. is(semantic, 'bpmn:Participant') ||
  6. is(semantic, 'bpmn:Lane') ||
  7. is(semantic, 'bpmn:SequenceFlow') ||
  8. is(semantic, 'bpmn:MessageFlow') ||
  9. is(semantic, 'bpmn:DataInput') ||
  10. is(semantic, 'bpmn:DataOutput')
  11. ) {
  12. return 'name';
  13. }
  14. if (is(semantic, 'bpmn:TextAnnotation')) {
  15. return 'text';
  16. }
  17. if (is(semantic, 'bpmn:Group')) {
  18. return 'categoryValueRef';
  19. }
  20. }
  21. function getCategoryValue(semantic) {
  22. var categoryValueRef = semantic['categoryValueRef'];
  23. if (!categoryValueRef) {
  24. return '';
  25. }
  26. return categoryValueRef.value || '';
  27. }
  28. export function getLabel(element) {
  29. var semantic = element.businessObject,
  30. attr = getLabelAttr(semantic);
  31. if (attr) {
  32. if (attr === 'categoryValueRef') {
  33. return getCategoryValue(semantic);
  34. }
  35. return semantic[attr] || '';
  36. }
  37. }
  38. export function setLabel(element, text, isExternal) {
  39. var semantic = element.businessObject,
  40. attr = getLabelAttr(semantic);
  41. if (attr) {
  42. if (attr === 'categoryValueRef') {
  43. semantic['categoryValueRef'].value = text;
  44. } else {
  45. semantic[attr] = text;
  46. }
  47. }
  48. return element;
  49. }