diff --git a/lib/import/Importer.js b/lib/import/Importer.js
index 20b27547..0d9df911 100644
--- a/lib/import/Importer.js
+++ b/lib/import/Importer.js
@@ -1,3 +1,5 @@
+'use strict';
+
var _ = require('lodash');
var BpmnTreeWalker = require('./BpmnTreeWalker'),
@@ -14,6 +16,10 @@ function hasLabel(element) {
}
+function isCollapsed(element, di) {
+ return di && !di.isExpanded;
+}
+
function getWaypointsMid(waypoints) {
var mid = waypoints.length / 2 - 1;
@@ -28,6 +34,10 @@ function getWaypointsMid(waypoints) {
}
+/**
+ * Returns the bounds of an elements label, parsed from the elements DI or
+ * generated from its bounds.
+ */
function getLabelBounds(di, data) {
var mid,
@@ -106,10 +116,15 @@ function importBpmnDiagram(diagram, definitions, done) {
if (di.$type === 'bpmndi:BPMNShape') {
var bounds = di.bounds;
+ var collapsed = isCollapsed(element, di);
+ var hidden = parent && (parent.hidden || parent.collapsed);
+
shape = {
id: element.id, type: element.$type,
x: bounds.x, y: bounds.y,
width: bounds.width, height: bounds.height,
+ collapsed: collapsed,
+ hidden: hidden,
parent: parent
};
diff --git a/test/fixtures/bpmn/import/collapsed-subprocess-children.bpmn b/test/fixtures/bpmn/import/collapsed-subprocess-children.bpmn
new file mode 100644
index 00000000..75cc061a
--- /dev/null
+++ b/test/fixtures/bpmn/import/collapsed-subprocess-children.bpmn
@@ -0,0 +1,65 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/test/spec/browser/import/ImporterSpec.js b/test/spec/browser/import/ImporterSpec.js
index ffa32413..2d450017 100644
--- a/test/spec/browser/import/ImporterSpec.js
+++ b/test/spec/browser/import/ImporterSpec.js
@@ -1,3 +1,5 @@
+'use strict';
+
var fs = require('fs'),
Diagram = require('diagram-js/lib/Diagram');
@@ -9,8 +11,10 @@ var bpmnModule = require('../../../../lib/di').defaultModule;
require('../../../../lib/core/BpmnRegistry');
require('../../../../lib/draw/BpmnRenderer');
+
var Matchers = require('../../Matchers');
+
describe('import/Importer', function() {
var bpmnModel = BpmnModel.instance();
@@ -38,6 +42,7 @@ describe('import/Importer', function() {
});
}
+
it('should fire during import', function(done) {
// given
@@ -52,6 +57,7 @@ describe('import/Importer', function() {
events.push({ type: 'add', semantic: e.semantic.id, di: e.di.id, diagramElement: e.diagramElement.id });
});
+ // when
BpmnModel.fromXML(xml, function(err, definitions) {
if (err) {
return done(err);
diff --git a/test/spec/browser/import/elements/CollapsedImportSpec.js b/test/spec/browser/import/elements/CollapsedImportSpec.js
new file mode 100644
index 00000000..73616bbf
--- /dev/null
+++ b/test/spec/browser/import/elements/CollapsedImportSpec.js
@@ -0,0 +1,105 @@
+'use strict';
+
+var fs = require('fs');
+
+var Viewer = require('../../../../../lib/Viewer');
+
+var Matchers = require('../../../Matchers');
+
+
+describe('import - collapsed container', function() {
+
+ beforeEach(Matchers.add);
+
+ var container, renderer;
+
+ beforeEach(function(done) {
+
+ if (!container) {
+
+ // create container
+ var c = document.createElement('div');
+ document.getElementsByTagName('body')[0].appendChild(c);
+
+ // import XML
+ var xml = fs.readFileSync('test/fixtures/bpmn/import/collapsed-subprocess-children.bpmn', 'utf8');
+
+ renderer = new Viewer(c);
+
+ renderer.importXML(xml, function(err) {
+ if (err) {
+ done(err);
+ } else {
+ container = c;
+ done();
+ }
+ });
+ } else {
+ done();
+ }
+ });
+
+
+ it('should import collapsed subProcess', function() {
+
+ var elementRegistry = renderer.get('elementRegistry');
+
+ var collapsedShape = elementRegistry.getShapeById('SubProcess_1');
+ var childShape = elementRegistry.getShapeById('IntermediateCatchEvent_1');
+
+ expect(collapsedShape.collapsed).toBe(true);
+ expect(childShape.hidden).toBe(true);
+ });
+
+
+ it('should import collapsed transaction', function() {
+
+ var elementRegistry = renderer.get('elementRegistry');
+
+ var collapsedShape = elementRegistry.getShapeById('Transaction_1');
+ var childShape = elementRegistry.getShapeById('UserTask_1');
+
+ expect(collapsedShape.collapsed).toBe(true);
+ expect(childShape.hidden).toBe(true);
+ });
+
+
+ it('should import collapsed adhocSubProcess', function() {
+
+ var elementRegistry = renderer.get('elementRegistry');
+
+ var collapsedShape = elementRegistry.getShapeById('AdHocSubProcess_1');
+ var childShape = elementRegistry.getShapeById('StartEvent_1');
+
+ expect(collapsedShape.collapsed).toBe(true);
+ expect(childShape.hidden).toBe(true);
+ });
+
+
+ it('should import collapsed with nested elements', function() {
+
+ var elementRegistry = renderer.get('elementRegistry');
+
+ var collapsedShape = elementRegistry.getShapeById('SubProcess_4');
+ var childShape = elementRegistry.getShapeById('SubProcess_5');
+ var nestedChildShape = elementRegistry.getShapeById('Task_3');
+
+ expect(collapsedShape.collapsed).toBe(true);
+ expect(childShape.hidden).toBe(true);
+ expect(nestedChildShape.hidden).toBe(true);
+ });
+
+
+ it('should import expanded subProcess', function() {
+
+ var elementRegistry = renderer.get('elementRegistry');
+
+ var expandedShape = elementRegistry.getShapeById('SubProcess_3');
+ var childShape = elementRegistry.getShapeById('Task_2');
+
+ expect(expandedShape.collapsed).toBe(false);
+ expect(childShape.hidden).toBe(false);
+ });
+
+
+});
\ No newline at end of file
diff --git a/test/spec/browser/import/LabelImportSpec.js b/test/spec/browser/import/elements/LabelImportSpec.js
similarity index 93%
rename from test/spec/browser/import/LabelImportSpec.js
rename to test/spec/browser/import/elements/LabelImportSpec.js
index a15c5c3e..f1c1406f 100644
--- a/test/spec/browser/import/LabelImportSpec.js
+++ b/test/spec/browser/import/elements/LabelImportSpec.js
@@ -2,9 +2,9 @@
var fs = require('fs');
-var Viewer = require('../../../../lib/Viewer');
+var Viewer = require('../../../../../lib/Viewer');
-var Matchers = require('../../Matchers');
+var Matchers = require('../../../Matchers');
describe('import - labels', function() {