LabelUtil.js 822 B

12345678910111213141516171819202122232425262728293031323334353637383940
  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. }
  18. export function getLabel(element) {
  19. var semantic = element.businessObject,
  20. attr = getLabelAttr(semantic);
  21. if (attr) {
  22. return semantic[attr] || '';
  23. }
  24. }
  25. export function setLabel(element, text, isExternal) {
  26. var semantic = element.businessObject,
  27. attr = getLabelAttr(semantic);
  28. if (attr) {
  29. semantic[attr] = text;
  30. }
  31. return element;
  32. }