Bug 513053 - Provide more meaningful display names for reqif elements

Since users can define custom attributes for their ReqIf requirements,
a preference page is added to allow the users to provide the name of
the attribute they wish to use in the display name.
If this is not provided, Capra will use the first attribute defined.

Change-Id: I22091ebba1db24773977919077bf2b6876c00cea
diff --git a/bundles/org.eclipse.capra.handler.reqIf/META-INF/MANIFEST.MF b/bundles/org.eclipse.capra.handler.reqIf/META-INF/MANIFEST.MF
index ef203e9..1abc192 100644
--- a/bundles/org.eclipse.capra.handler.reqIf/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.capra.handler.reqIf/META-INF/MANIFEST.MF
@@ -3,12 +3,11 @@
 Bundle-Name: Capra Handler for ReqIF Models
 Bundle-SymbolicName: org.eclipse.capra.handler.reqIf;singleton:=true
 Bundle-Version: 0.7.0.qualifier
-Export-Package: org.eclipse.capra.handler.reqif
-Require-Bundle: org.eclipse.emf.ecore,
- org.eclipse.jface,
- org.eclipse.capra.core,
+Export-Package: org.eclipse.capra.handler.reqif,
+ org.eclipse.capra.handler.reqif.preferences
+Require-Bundle: org.eclipse.capra.core,
  org.eclipse.rmf.reqif10.pror,
- org.eclipse.core.resources
-Import-Package: org.eclipse.papyrus.infra.emf.utils
+ org.eclipse.core.resources,
+ org.eclipse.core.runtime
 Bundle-RequiredExecutionEnvironment: JavaSE-1.8
 Bundle-Vendor: Capra Development Team
diff --git a/bundles/org.eclipse.capra.handler.reqIf/plugin.xml b/bundles/org.eclipse.capra.handler.reqIf/plugin.xml
index a6a8b2c..37f1823 100644
--- a/bundles/org.eclipse.capra.handler.reqIf/plugin.xml
+++ b/bundles/org.eclipse.capra.handler.reqIf/plugin.xml
@@ -22,6 +22,4 @@
             class="org.eclipse.capra.handler.reqif.ReqIfHandler">
       </artifactHandler>
    </extension>
-
-
 </plugin>
diff --git a/bundles/org.eclipse.capra.handler.reqIf/src/org/eclipse/capra/handler/reqif/ReqIfHandler.java b/bundles/org.eclipse.capra.handler.reqIf/src/org/eclipse/capra/handler/reqif/ReqIfHandler.java
index 453a540..8798a58 100644
--- a/bundles/org.eclipse.capra.handler.reqIf/src/org/eclipse/capra/handler/reqif/ReqIfHandler.java
+++ b/bundles/org.eclipse.capra.handler.reqIf/src/org/eclipse/capra/handler/reqif/ReqIfHandler.java
@@ -18,10 +18,14 @@
 
 import org.eclipse.capra.core.adapters.Connection;
 import org.eclipse.capra.core.handlers.AbstractArtifactHandler;
+import org.eclipse.capra.handler.reqif.preferences.ReqifPreferences;
 import org.eclipse.core.resources.IResourceDelta;
+import org.eclipse.core.runtime.preferences.IEclipsePreferences;
 import org.eclipse.emf.ecore.EObject;
+import org.eclipse.rmf.reqif10.AttributeValue;
 import org.eclipse.rmf.reqif10.SpecHierarchy;
 import org.eclipse.rmf.reqif10.SpecObject;
+import org.eclipse.rmf.reqif10.common.util.ReqIF10Util;
 
 public class ReqIfHandler extends AbstractArtifactHandler<SpecHierarchy> {
 
@@ -39,8 +43,22 @@
 
 	@Override
 	public String getDisplayName(SpecHierarchy spec) {
+		IEclipsePreferences preference = ReqifPreferences.getPreferences();
+		String idAttribute = preference.get(ReqifPreferences.REQIF_ID_ATTRIBUTE,
+				ReqifPreferences.REQIF_ID_ATTRIBUTE_DEFAULT);
 		SpecObject specObject = spec.getObject();
-		return specObject.getIdentifier();
+		if (specObject != null) {
+			AttributeValue attributeValue = ReqIF10Util.getAttributeValueForLabel(specObject, idAttribute);
+			if (attributeValue != null) {
+				return ReqIF10Util.getTheValue(attributeValue).toString();
+			} else {
+				// as a default fall back use the first column as an ID
+				// column
+				AttributeValue defaultAttributeValue = specObject.getValues().get(0);
+				return ReqIF10Util.getTheValue(defaultAttributeValue).toString();
+			}
+		} else // empty row is selected
+			return "";
 	}
 
 	@Override
diff --git a/bundles/org.eclipse.capra.handler.reqIf/src/org/eclipse/capra/handler/reqif/preferences/ReqifPreferences.java b/bundles/org.eclipse.capra.handler.reqIf/src/org/eclipse/capra/handler/reqif/preferences/ReqifPreferences.java
new file mode 100644
index 0000000..039255c
--- /dev/null
+++ b/bundles/org.eclipse.capra.handler.reqIf/src/org/eclipse/capra/handler/reqif/preferences/ReqifPreferences.java
@@ -0,0 +1,31 @@
+/*******************************************************************************
+ * Copyright (c) 2016, 2019 Chalmers | University of Gothenburg, rt-labs and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v2.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v20.html
+ *  
+ * SPDX-License-Identifier: EPL-2.0
+ *  
+ * Contributors:
+ *      Chalmers | University of Gothenburg and rt-labs - initial API and implementation and/or initial documentation
+ *      Chalmers | University of Gothenburg - additional features, updated API
+ *******************************************************************************/
+package org.eclipse.capra.handler.reqif.preferences;
+
+import org.eclipse.core.runtime.preferences.IEclipsePreferences;
+import org.eclipse.core.runtime.preferences.IScopeContext;
+import org.eclipse.core.runtime.preferences.InstanceScope;
+
+public class ReqifPreferences {
+	public static final IScopeContext SCOPE_CONTEXT = InstanceScope.INSTANCE;
+	public static final String PREFERENCE_NODE = "org.eclipse.capra.ui.reqif";
+
+	// ID attribute
+	public static final String REQIF_ID_ATTRIBUTE = "";
+	public static final String REQIF_ID_ATTRIBUTE_DEFAULT = "ID";
+
+	public static IEclipsePreferences getPreferences() {
+		return SCOPE_CONTEXT.getNode(PREFERENCE_NODE);
+	}
+}
diff --git a/bundles/org.eclipse.capra.ui.reqif/.classpath b/bundles/org.eclipse.capra.ui.reqif/.classpath
new file mode 100644
index 0000000..22f3064
--- /dev/null
+++ b/bundles/org.eclipse.capra.ui.reqif/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="src" path="src"/>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
+	<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+	<classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/bundles/org.eclipse.capra.ui.reqif/.project b/bundles/org.eclipse.capra.ui.reqif/.project
new file mode 100644
index 0000000..391ab62
--- /dev/null
+++ b/bundles/org.eclipse.capra.ui.reqif/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>org.eclipse.capra.ui.reqif</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.jdt.core.javabuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.eclipse.pde.ManifestBuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.eclipse.pde.SchemaBuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+		<nature>org.eclipse.pde.PluginNature</nature>
+	</natures>
+</projectDescription>
diff --git a/bundles/org.eclipse.capra.ui.reqif/.settings/org.eclipse.jdt.core.prefs b/bundles/org.eclipse.capra.ui.reqif/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..3a21537
--- /dev/null
+++ b/bundles/org.eclipse.capra.ui.reqif/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,11 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.8
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.8
diff --git a/bundles/org.eclipse.capra.ui.reqif/META-INF/MANIFEST.MF b/bundles/org.eclipse.capra.ui.reqif/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..c4e1fe8
--- /dev/null
+++ b/bundles/org.eclipse.capra.ui.reqif/META-INF/MANIFEST.MF
@@ -0,0 +1,12 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: ReqIf UI Plugin
+Bundle-SymbolicName: org.eclipse.capra.ui.reqif;singleton:=true
+Bundle-Version: 0.7.0.qualifier
+Require-Bundle: org.eclipse.jface,
+ org.eclipse.ui.workbench,
+ org.eclipse.equinox.preferences,
+ org.eclipse.capra.handler.reqIf
+Export-Package: org.eclipse.capra.ui.reqif.preferences
+Bundle-RequiredExecutionEnvironment: JavaSE-1.8
+Bundle-Vendor: Capra Development Team
diff --git a/bundles/org.eclipse.capra.ui.reqif/build.properties b/bundles/org.eclipse.capra.ui.reqif/build.properties
new file mode 100644
index 0000000..af525cf
--- /dev/null
+++ b/bundles/org.eclipse.capra.ui.reqif/build.properties
@@ -0,0 +1,17 @@
+###############################################################################
+# Copyright (c) 2016, 2019 Chalmers | University of Gothenburg, rt-labs and others.
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v2.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v20.html
+#  
+# SPDX-License-Identifier: EPL-2.0
+#  
+# Contributors:
+#      Chalmers | University of Gothenburg and rt-labs - initial API and implementation and/or initial documentation
+#      Chalmers | University of Gothenburg - additional features, updated API
+###############################################################################
+source.. = src/
+bin.includes = META-INF/,\
+               .,\
+               plugin.xml
diff --git a/bundles/org.eclipse.capra.ui.reqif/plugin.xml b/bundles/org.eclipse.capra.ui.reqif/plugin.xml
new file mode 100644
index 0000000..c749c9b
--- /dev/null
+++ b/bundles/org.eclipse.capra.ui.reqif/plugin.xml
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.4"?>
+<!--
+    Copyright (c) 2016, 2019 Chalmers | University of Gothenburg, rt-labs and others.
+    All rights reserved. This program and the accompanying materials
+    are made available under the terms of the Eclipse Public License v2.0
+    which accompanies this distribution, and is available at
+    http://www.eclipse.org/legal/epl-v20.html
+     
+    SPDX-License-Identifier: EPL-2.0
+     
+    Contributors:
+         Chalmers | University of Gothenburg and rt-labs - initial API and implementation and/or initial documentation
+         Chalmers | University of Gothenburg - additional features, updated API
+ -->
+<plugin>
+<extension
+         point="org.eclipse.core.runtime.preferences">
+      <initializer
+            class="org.eclipse.capra.ui.reqif.preferences.ReqifPreferenceInitializer">
+      </initializer>
+   </extension>
+   <extension
+         point="org.eclipse.ui.preferencePages">
+      <page
+            category="org.eclipse.capra.ui.preferences.CapraPreferences"
+            class="org.eclipse.capra.ui.reqif.preferences.ReqifPreferencePage"
+            id="org.eclipse.capra.handler.reqif.preferences.ReqifPreferencePage"
+            name="Reqif Preferences">
+      </page>
+   </extension>
+
+</plugin>
diff --git a/bundles/org.eclipse.capra.ui.reqif/pom.xml b/bundles/org.eclipse.capra.ui.reqif/pom.xml
new file mode 100644
index 0000000..c2bfc24
--- /dev/null
+++ b/bundles/org.eclipse.capra.ui.reqif/pom.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    Copyright (c) 2016, 2019 Chalmers | University of Gothenburg, rt-labs and others.
+    All rights reserved. This program and the accompanying materials
+    are made available under the terms of the Eclipse Public License v2.0
+    which accompanies this distribution, and is available at
+    http://www.eclipse.org/legal/epl-v20.html
+     
+    SPDX-License-Identifier: EPL-2.0
+     
+    Contributors:
+         Chalmers | University of Gothenburg and rt-labs - initial API and implementation and/or initial documentation
+         Chalmers | University of Gothenburg - additional features, updated API
+ -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+	<modelVersion>4.0.0</modelVersion>
+
+	<parent>
+		<relativePath>../../pom.xml</relativePath>
+		<groupId>org.eclipse.capra</groupId>
+		<artifactId>parent</artifactId>
+		<version>0.7.0-SNAPSHOT</version>
+	</parent>
+
+	<artifactId>org.eclipse.capra.ui.reqif</artifactId>
+	<packaging>eclipse-plugin</packaging>
+
+</project>
diff --git a/bundles/org.eclipse.capra.ui.reqif/src/org/eclipse/capra/ui/reqif/preferences/ReqifPreferenceInitializer.java b/bundles/org.eclipse.capra.ui.reqif/src/org/eclipse/capra/ui/reqif/preferences/ReqifPreferenceInitializer.java
new file mode 100644
index 0000000..280bfb1
--- /dev/null
+++ b/bundles/org.eclipse.capra.ui.reqif/src/org/eclipse/capra/ui/reqif/preferences/ReqifPreferenceInitializer.java
@@ -0,0 +1,37 @@
+/*******************************************************************************
+ * Copyright (c) 2016, 2019 Chalmers | University of Gothenburg, rt-labs and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v2.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v20.html
+ *  
+ * SPDX-License-Identifier: EPL-2.0
+ *  
+ * Contributors:
+ *      Chalmers | University of Gothenburg and rt-labs - initial API and implementation and/or initial documentation
+ *      Chalmers | University of Gothenburg - additional features, updated API
+ *******************************************************************************/
+package org.eclipse.capra.ui.reqif.preferences;
+
+import org.eclipse.capra.handler.reqif.preferences.ReqifPreferences;
+import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
+import org.eclipse.core.runtime.preferences.InstanceScope;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.ui.preferences.ScopedPreferenceStore;
+
+public class ReqifPreferenceInitializer extends AbstractPreferenceInitializer {
+
+
+	public ReqifPreferenceInitializer() {
+
+	}
+
+	@Override
+	public void initializeDefaultPreferences() {
+		IPreferenceStore store = new ScopedPreferenceStore(InstanceScope.INSTANCE,
+				ReqifPreferencePage.REQIF_PREFERENCE_PAGE_ID);
+		store.setDefault(ReqifPreferences.REQIF_ID_ATTRIBUTE, ReqifPreferences.REQIF_ID_ATTRIBUTE_DEFAULT);
+
+	}
+
+}
diff --git a/bundles/org.eclipse.capra.ui.reqif/src/org/eclipse/capra/ui/reqif/preferences/ReqifPreferencePage.java b/bundles/org.eclipse.capra.ui.reqif/src/org/eclipse/capra/ui/reqif/preferences/ReqifPreferencePage.java
new file mode 100644
index 0000000..3f0d448
--- /dev/null
+++ b/bundles/org.eclipse.capra.ui.reqif/src/org/eclipse/capra/ui/reqif/preferences/ReqifPreferencePage.java
@@ -0,0 +1,47 @@
+/*******************************************************************************
+ * Copyright (c) 2016, 2019 Chalmers | University of Gothenburg, rt-labs and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v2.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v20.html
+ *  
+ * SPDX-License-Identifier: EPL-2.0
+ *  
+ * Contributors:
+ *      Chalmers | University of Gothenburg and rt-labs - initial API and implementation and/or initial documentation
+ *      Chalmers | University of Gothenburg - additional features, updated API
+ *******************************************************************************/
+package org.eclipse.capra.ui.reqif.preferences;
+
+import org.eclipse.capra.handler.reqif.preferences.ReqifPreferences;
+import org.eclipse.core.runtime.preferences.InstanceScope;
+import org.eclipse.jface.preference.FieldEditorPreferencePage;
+import org.eclipse.jface.preference.StringFieldEditor;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPreferencePage;
+import org.eclipse.ui.preferences.ScopedPreferenceStore;
+
+public class ReqifPreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage {
+
+	public static final String REQIF_PREFERENCE_PAGE_ID = "org.eclipse.capra.ui.reqif";
+	public static final String ID_ATTRIBUTE = "Attribute containing requirement ID";
+	private StringFieldEditor stringEditor;
+
+	public ReqifPreferencePage() {
+		super(GRID);
+	}
+
+	@Override
+	protected void createFieldEditors() {
+		stringEditor = new StringFieldEditor(ReqifPreferences.REQIF_ID_ATTRIBUTE, ID_ATTRIBUTE,
+				getFieldEditorParent());
+		addField(stringEditor);
+	}
+
+	@Override
+	public void init(IWorkbench workbench) {
+		setPreferenceStore(
+				new ScopedPreferenceStore(InstanceScope.INSTANCE, REQIF_PREFERENCE_PAGE_ID));
+		setDescription(null);
+	}
+}
diff --git a/features/org.eclipse.capra.handler.reqIf.feature/feature.xml b/features/org.eclipse.capra.handler.reqIf.feature/feature.xml
index 4e92e0f..bb8429e 100644
--- a/features/org.eclipse.capra.handler.reqIf.feature/feature.xml
+++ b/features/org.eclipse.capra.handler.reqIf.feature/feature.xml
@@ -26,4 +26,11 @@
          version="0.0.0"
          unpack="false"/>
 
+   <plugin
+         id="org.eclipse.capra.ui.reqif"
+         download-size="0"
+         install-size="0"
+         version="0.0.0"
+         unpack="false"/>
+
 </feature>
diff --git a/pom.xml b/pom.xml
index 292f64a..9098b2c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -49,6 +49,7 @@
 		<module>bundles/org.eclipse.capra.ui.office</module>
 		<module>bundles/org.eclipse.capra.ui.drive</module>
 		<module>bundles/org.eclipse.capra.ui.zest</module>
+		<module>bundles/org.eclipse.capra.ui.reqif</module>
 		
 		<!-- Tests -->
 		<module>tests/org.eclipse.capra.testsuite</module>