[489487] Support data items at the process level

Change-Id: I83c6fc56322a73a605a91fea2e69d5e53cd4b6a5
Signed-off-by: Paul Leacu <pleacu@redhat.com>
diff --git a/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/merrimac/clad/DefaultDetailComposite.java b/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/merrimac/clad/DefaultDetailComposite.java
index ced56f0..c697c4f 100644
--- a/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/merrimac/clad/DefaultDetailComposite.java
+++ b/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/merrimac/clad/DefaultDetailComposite.java
@@ -141,7 +141,7 @@
 			property += propArray[i];
 		}
 		
-		if (!property.isEmpty()) {
+		if (feature != null && !property.isEmpty()) {
 			// determine new object - may be a list
 			if (eclass!=null) {
 				Object value = be.eGet(feature);
diff --git a/plugins/org.eclipse.bpmn2.modeler.ui/plugin.xml b/plugins/org.eclipse.bpmn2.modeler.ui/plugin.xml
index 9228ad0..01dfc04 100644
--- a/plugins/org.eclipse.bpmn2.modeler.ui/plugin.xml
+++ b/plugins/org.eclipse.bpmn2.modeler.ui/plugin.xml
@@ -670,6 +670,7 @@
 			id="org.eclipse.bpmn2.modeler.dataitems.tab"
 			afterTab="org.eclipse.bpmn2.modeler.description.tab"
 			class="org.eclipse.bpmn2.modeler.ui.property.diagrams.DataItemsPropertySection"
+			type="org.eclipse.bpmn2.Process org.eclipse.bpmn2.Definitions"
 			label="%propertyTab.label.DataItems">
 		</propertyTab>
 
diff --git a/plugins/org.eclipse.bpmn2.modeler.ui/src/org/eclipse/bpmn2/modeler/ui/property/PropertyTabDescriptorProvider.java b/plugins/org.eclipse.bpmn2.modeler.ui/src/org/eclipse/bpmn2/modeler/ui/property/PropertyTabDescriptorProvider.java
index 8a779c0..391b746 100644
--- a/plugins/org.eclipse.bpmn2.modeler.ui/src/org/eclipse/bpmn2/modeler/ui/property/PropertyTabDescriptorProvider.java
+++ b/plugins/org.eclipse.bpmn2.modeler.ui/src/org/eclipse/bpmn2/modeler/ui/property/PropertyTabDescriptorProvider.java
@@ -62,18 +62,18 @@
 		
 		// No, we need build the list: get the Target Runtime <propertyTab> contributions
 		// and merge with the Default Runtime Tab Descriptors
-		List<PropertyTabDescriptor> desc = null;
+		List<PropertyTabDescriptor> tabDescriptors = null;
 		TargetRuntime rt = TargetRuntime.getRuntime(businessObject);
 		if (rt!=TargetRuntime.getDefaultRuntime()) {
-			desc = TargetRuntime.getDefaultRuntime().buildPropertyTabDescriptors();
-			desc.addAll(rt.buildPropertyTabDescriptors());
+			tabDescriptors = TargetRuntime.getDefaultRuntime().buildPropertyTabDescriptors();
+			tabDescriptors.addAll(rt.buildPropertyTabDescriptors());
 		}
 		else
-			desc = rt.buildPropertyTabDescriptors();
+			tabDescriptors = rt.buildPropertyTabDescriptors();
 		
 		// do tab replacement
 		ArrayList<PropertyTabDescriptor> replaced = new ArrayList<PropertyTabDescriptor>();
-		for (PropertyTabDescriptor d : desc) {
+		for (PropertyTabDescriptor d : tabDescriptors) {
 			String replacedId = d.getReplaceTab();
 			if (replacedId!=null) {
 				String[] replacements = replacedId.split(" "); //$NON-NLS-1$
@@ -89,9 +89,9 @@
 								PropertyTabDescriptor replacedTab = TargetRuntime.findPropertyTabDescriptor(id);
 								if (replacedTab!=null) {
 									replaced.add(replacedTab);
-									int i = desc.indexOf(replacedTab);
+									int i = tabDescriptors.indexOf(replacedTab);
 									if (i>=0) {
-										desc.set(i, d);
+										tabDescriptors.set(i, d);
 									}
 								}
 							}
@@ -101,48 +101,47 @@
 			}
 		}
 		if (replaced.size()>0)
-			desc.removeAll(replaced);
+			tabDescriptors.removeAll(replaced);
 
-		for (int i=desc.size()-1; i>=0; --i) {
-			PropertyTabDescriptor d = desc.get(i);
+		for (int i=tabDescriptors.size()-1; i>=0; --i) {
+			PropertyTabDescriptor d = tabDescriptors.get(i);
 			for (int j=i-1; j>=0; --j) {
-				if (desc.get(j)==d) {
-					desc.remove(i);
+				if (tabDescriptors.get(j)==d) {
+					tabDescriptors.remove(i);
 					break;
 				}
 			}
 		}
 		
-		// remove empty tabs
-		// also move the advanced tab to end of list
-		ArrayList<PropertyTabDescriptor> emptyTabs = new ArrayList<PropertyTabDescriptor>();
+		// Screen out tabs that don't apply to the selected component and move the advanced tab to end of list.
+		ArrayList<PropertyTabDescriptor> nonapplicableTabs = new ArrayList<PropertyTabDescriptor>();
 		PropertyTabDescriptor advancedPropertyTab = null;
-		for (PropertyTabDescriptor d : desc) {
+		for (PropertyTabDescriptor descriptor : tabDescriptors) {
 			boolean empty = true;
-			for (Bpmn2SectionDescriptor s : (List<Bpmn2SectionDescriptor>) d.getSectionDescriptors()) {
+			for (Bpmn2SectionDescriptor s : (List<Bpmn2SectionDescriptor>) descriptor.getSectionDescriptors()) {
 				if (s.appliesTo(part, selection)) {
 					empty = false;
 				}
 				if (s.getSectionClass() instanceof AdvancedPropertySection) {
-					advancedPropertyTab = d;
+					advancedPropertyTab = descriptor;
 				}
 			}
 			if (empty) {
-				emptyTabs.add(d);
+				nonapplicableTabs.add(descriptor);
 			}
 		}
 		
-		if (emptyTabs.size()>0)
-			desc.removeAll(emptyTabs);
+		if (nonapplicableTabs.size() > 0)
+			tabDescriptors.removeAll(nonapplicableTabs);
 		
 		if (advancedPropertyTab!=null) {
-			if (desc.remove(advancedPropertyTab))
-				desc.add(advancedPropertyTab);
+			if (tabDescriptors.remove(advancedPropertyTab))
+				tabDescriptors.add(advancedPropertyTab);
 		}
 		
 		// make copies of all tab descriptors to prevent cross-talk between editors
 		replaced.clear(); // we'll just reuse an ArrayList from before...
-		for (PropertyTabDescriptor td : desc) {
+		for (PropertyTabDescriptor td : tabDescriptors) {
 			// Note that the copy() makes the Tab Descriptor IDs and Section IDs unique.
 			// This is important because the TabbedPropertySheetPage uses these IDs to
 			// look up the Sections.