Office-support: Preference page fix
    - registered Activator class in manifest
    - fixed ID extraction from Excel docs (ID column specified in preferences).

Signed-off-by: Dusan Kalanj <kalanj@chalmers.se>
diff --git a/org.eclipse.capra.ui.office/META-INF/MANIFEST.MF b/org.eclipse.capra.ui.office/META-INF/MANIFEST.MF
index 0408a38..efad947 100644
--- a/org.eclipse.capra.ui.office/META-INF/MANIFEST.MF
+++ b/org.eclipse.capra.ui.office/META-INF/MANIFEST.MF
@@ -22,4 +22,5 @@
 Bundle-ActivationPolicy: lazy
 Export-Package: org.eclipse.capra.ui.office.objects,
  org.eclipse.capra.ui.office.utils
+Bundle-Activator: org.eclipse.capra.ui.office.Activator
 
diff --git a/org.eclipse.capra.ui.office/src/org/eclipse/capra/ui/office/preferences/PreferenceActivator.java b/org.eclipse.capra.ui.office/src/org/eclipse/capra/ui/office/Activator.java
similarity index 67%
rename from org.eclipse.capra.ui.office/src/org/eclipse/capra/ui/office/preferences/PreferenceActivator.java
rename to org.eclipse.capra.ui.office/src/org/eclipse/capra/ui/office/Activator.java
index ac609fa..7d123ce 100644
--- a/org.eclipse.capra.ui.office/src/org/eclipse/capra/ui/office/preferences/PreferenceActivator.java
+++ b/org.eclipse.capra.ui.office/src/org/eclipse/capra/ui/office/Activator.java
@@ -9,7 +9,7 @@
  * 	   Chalmers | University of Gothenburg and rt-labs - initial API and implementation and/or initial documentation
  *******************************************************************************/
 
-package org.eclipse.capra.ui.office.preferences;
+package org.eclipse.capra.ui.office;
 
 import org.eclipse.ui.plugin.AbstractUIPlugin;
 import org.osgi.framework.BundleContext;
@@ -20,34 +20,39 @@
  * @author Dusan Kalanj
  *
  */
-public class PreferenceActivator extends AbstractUIPlugin {
-
-	private static PreferenceActivator preferenceActivator = new PreferenceActivator();
+public class Activator extends AbstractUIPlugin {
 
 	/**
-	 * Empty constructor
+	 * The plugin ID
 	 */
-	public PreferenceActivator() {
+	public static final String PLUGIN_ID = "org.eclipse.capra.ui.office";
+
+	private static Activator plugin;
+
+	/**
+	 * An empty constructor
+	 */
+	public Activator() {
 	}
 
 	@Override
 	public void start(BundleContext context) throws Exception {
 		super.start(context);
-		preferenceActivator = this;
+		plugin = this;
 	}
 
 	@Override
 	public void stop(BundleContext context) throws Exception {
-		preferenceActivator = null;
+		plugin = null;
 		super.stop(context);
 	}
 
 	/**
-	 * Returns the shared instance of the PreferenceActivator class.
+	 * Returns the shared instance
 	 *
-	 * @return instance of PreferenceActivator class
+	 * @return the shared instance
 	 */
-	public static PreferenceActivator getDefault() {
-		return preferenceActivator;
+	public static Activator getDefault() {
+		return plugin;
 	}
 }
\ No newline at end of file
diff --git a/org.eclipse.capra.ui.office/src/org/eclipse/capra/ui/office/objects/CapraExcelRow.java b/org.eclipse.capra.ui.office/src/org/eclipse/capra/ui/office/objects/CapraExcelRow.java
index 30c1440..fd0fcb5 100644
--- a/org.eclipse.capra.ui.office/src/org/eclipse/capra/ui/office/objects/CapraExcelRow.java
+++ b/org.eclipse.capra.ui.office/src/org/eclipse/capra/ui/office/objects/CapraExcelRow.java
@@ -52,7 +52,7 @@
 	 * RegEx of characters (tabs, newlines, carriage returns and invisible
 	 * control characters) to be replaced with white-spaces in the Office View.
 	 */
-	private static final String LINE_BREAKS_AND_CONTROL_REQE = "[\r\n\t\\p{C}]+";
+	private static final String LINE_BREAKS_AND_CONTROL_REQ = "[\r\n\t\\p{C}]+";
 
 	private static final DataFormatter FORMATTER = new DataFormatter();
 
@@ -78,6 +78,12 @@
 	private static final String NO_LAST_CELL_REFERENCE = "-1";
 
 	/**
+	 * The ID of the column that is used to extract the identifier of the row
+	 * (if value is "0", then line numbers are used as identifiers).
+	 */
+	private String idColumn;
+
+	/**
 	 * A constructor that generates a new instance of CapraExcelRow where the
 	 * parent properties are extracted from the provided Excel row and File
 	 * object that contains the row.
@@ -90,13 +96,9 @@
 	 */
 	public CapraExcelRow(File officeFile, Row row, String idColumn) {
 		super();
+		this.idColumn = idColumn;
 
-		String rowId;
-		if (idColumn.equals(OfficePreferences.EXCEL_COLUMN_VALUE_DEFAULT))
-			rowId = Integer.toString(row.getRowNum());
-		else
-			rowId = FORMATTER.formatCellValue(row.getCell(CellReference.convertColStringToIndex(idColumn)));
-
+		String rowId = getRowIdFromExcelRow(row);
 		StringBuilder rowBuilder = new StringBuilder();
 		rowBuilder.append("ID " + rowId + ": ");
 
@@ -116,7 +118,7 @@
 		}
 
 		if (firstCellSet) {
-			Pattern p = Pattern.compile(LINE_BREAKS_AND_CONTROL_REQE);
+			Pattern p = Pattern.compile(LINE_BREAKS_AND_CONTROL_REQ);
 			Matcher m = p.matcher(rowBuilder);
 
 			String rowContent = (m.replaceAll(" ")).trim();
@@ -132,7 +134,7 @@
 	public void showOfficeObjectInNativeEnvironment() throws CapraOfficeObjectNotFound {
 
 		String fileType = Files.getFileExtension(getFile().getAbsolutePath());
-		String rowId = getRowId();
+		String rowId = getRowIdFromObjectUri();
 		String sheetName = getSheetName();
 
 		Sheet sheet;
@@ -148,14 +150,13 @@
 			return;
 		}
 
-		DataFormatter formatter = new DataFormatter();
 		int rowIndex = NO_ROW_INDEX;
 		String lastCellReference = NO_LAST_CELL_REFERENCE;
 		for (int i = 0; i <= sheet.getLastRowNum(); i++) {
 			Row row = sheet.getRow(i);
 			if (row != null) {
-				String currRowID = formatter.formatCellValue(row.getCell(0));
-				if (currRowID.equals(rowId)) {
+				String currRowId = getRowIdFromExcelRow(row);
+				if (currRowId.equals(rowId)) {
 					rowIndex = i;
 					lastCellReference = CellReference.convertNumToColString(row.getLastCellNum()) + (rowIndex + 1);
 					break;
@@ -164,7 +165,7 @@
 		}
 
 		if (rowIndex == NO_ROW_INDEX || lastCellReference == NO_LAST_CELL_REFERENCE)
-			throw new CapraOfficeObjectNotFound(getRowId());
+			throw new CapraOfficeObjectNotFound(getRowIdFromObjectUri());
 
 		int firstDisplayedRowIndex = (rowIndex - 2 > 0) ? rowIndex - 2 : 1;
 		if (fileType.equals(CapraOfficeObject.XLSX)) {
@@ -207,15 +208,29 @@
 		}
 	}
 
+	/**
+	 * Extracts the name of the sheet which the object is associated with.
+	 * 
+	 * @return name of the sheet
+	 */
 	public String getSheetName() {
 		String itemId = getId();
 		int lastIndexOfDelimiter = itemId.lastIndexOf(ID_DELIMITER);
 		return itemId.substring(0, lastIndexOfDelimiter);
 	}
 
-	public String getRowId() {
+	private String getRowIdFromObjectUri() {
 		String itemId = getId();
 		int lastIndexOfDelimiter = itemId.lastIndexOf(ID_DELIMITER);
 		return itemId.substring(lastIndexOfDelimiter + 1);
 	}
+
+	private String getRowIdFromExcelRow(Row row) {
+		String rowId = "";
+		if (idColumn.equals(OfficePreferences.EXCEL_COLUMN_VALUE_DEFAULT))
+			rowId = Integer.toString(row.getRowNum() + 1);
+		else
+			rowId = FORMATTER.formatCellValue(row.getCell(CellReference.convertColStringToIndex(idColumn)));
+		return rowId;
+	}
 }
diff --git a/org.eclipse.capra.ui.office/src/org/eclipse/capra/ui/office/preferences/OfficePreferences.java b/org.eclipse.capra.ui.office/src/org/eclipse/capra/ui/office/preferences/OfficePreferences.java
index b53821b..cad9a1a 100644
--- a/org.eclipse.capra.ui.office/src/org/eclipse/capra/ui/office/preferences/OfficePreferences.java
+++ b/org.eclipse.capra.ui.office/src/org/eclipse/capra/ui/office/preferences/OfficePreferences.java
@@ -11,6 +11,7 @@
 
 package org.eclipse.capra.ui.office.preferences;
 
+import org.eclipse.capra.ui.office.Activator;
 import org.eclipse.capra.ui.office.views.OfficeView;
 import org.eclipse.jface.preference.IPreferenceStore;
 import org.eclipse.jface.preference.PreferencePage;
@@ -91,11 +92,11 @@
 
 	@Override
 	public void init(IWorkbench workbench) {
-		setPreferenceStore(PreferenceActivator.getDefault().getPreferenceStore());
+		setPreferenceStore(Activator.getDefault().getPreferenceStore());
 	}
 
 	private void storeValues() {
-		IPreferenceStore store = PreferenceActivator.getDefault().getPreferenceStore();
+		IPreferenceStore store = Activator.getDefault().getPreferenceStore();
 
 		boolean idIsRowNumber;
 		String idColumn;
@@ -117,7 +118,7 @@
 	}
 
 	private void initializeValues() {
-		IPreferenceStore store = PreferenceActivator.getDefault().getPreferenceStore();
+		IPreferenceStore store = Activator.getDefault().getPreferenceStore();
 
 		boolean idIsRowNumber = store.getBoolean(EXCEL_COLUMN_RADIO_CHOICE);
 		if (idIsRowNumber) {
diff --git a/org.eclipse.capra.ui.office/src/org/eclipse/capra/ui/office/preferences/PreferenceInitializer.java b/org.eclipse.capra.ui.office/src/org/eclipse/capra/ui/office/preferences/PreferenceInitializer.java
index 8af4bf0..f96f7a9 100644
--- a/org.eclipse.capra.ui.office/src/org/eclipse/capra/ui/office/preferences/PreferenceInitializer.java
+++ b/org.eclipse.capra.ui.office/src/org/eclipse/capra/ui/office/preferences/PreferenceInitializer.java
@@ -11,6 +11,7 @@
 
 package org.eclipse.capra.ui.office.preferences;
 
+import org.eclipse.capra.ui.office.Activator;
 import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
 import org.eclipse.jface.preference.IPreferenceStore;
 
@@ -28,7 +29,7 @@
 
 	@Override
 	public void initializeDefaultPreferences() {
-		IPreferenceStore store = PreferenceActivator.getDefault().getPreferenceStore();
+		IPreferenceStore store = Activator.getDefault().getPreferenceStore();
 		store.setDefault(OfficePreferences.CHAR_COUNT, OfficePreferences.CHAR_COUNT_DEFAULT);
 		store.setDefault(OfficePreferences.EXCEL_COLUMN_RADIO_CHOICE,
 				OfficePreferences.EXCEL_COLUMN_RADIO_ID_IS_LINE_NUMBER);
diff --git a/org.eclipse.capra.ui.office/src/org/eclipse/capra/ui/office/views/OfficeView.java b/org.eclipse.capra.ui.office/src/org/eclipse/capra/ui/office/views/OfficeView.java
index 1448739..217aa07 100644
--- a/org.eclipse.capra.ui.office/src/org/eclipse/capra/ui/office/views/OfficeView.java
+++ b/org.eclipse.capra.ui.office/src/org/eclipse/capra/ui/office/views/OfficeView.java
@@ -26,13 +26,13 @@
 import org.apache.poi.xwpf.usermodel.XWPFDocument;
 import org.apache.poi.xwpf.usermodel.XWPFParagraph;
 import org.apache.xmlbeans.SchemaTypeLoaderException;
+import org.eclipse.capra.ui.office.Activator;
 import org.eclipse.capra.ui.office.exceptions.CapraOfficeFileNotSupportedException;
 import org.eclipse.capra.ui.office.exceptions.CapraOfficeObjectNotFound;
 import org.eclipse.capra.ui.office.objects.CapraExcelRow;
 import org.eclipse.capra.ui.office.objects.CapraOfficeObject;
 import org.eclipse.capra.ui.office.objects.CapraWordRequirement;
 import org.eclipse.capra.ui.office.preferences.OfficePreferences;
-import org.eclipse.capra.ui.office.preferences.PreferenceActivator;
 import org.eclipse.capra.ui.office.utils.OfficeTransferType;
 import org.eclipse.core.commands.ExecutionEvent;
 import org.eclipse.core.commands.ExecutionException;
@@ -138,7 +138,7 @@
 
 		@Override
 		public String getText(Object obj) {
-			int minAllowed = PreferenceActivator.getDefault().getPreferenceStore().getInt(OfficePreferences.CHAR_COUNT);
+			int minAllowed = Activator.getDefault().getPreferenceStore().getInt(OfficePreferences.CHAR_COUNT);
 			String text = obj.toString();
 			int textLength = Math.min(text.length(), minAllowed);
 			if (textLength == minAllowed)
@@ -355,8 +355,7 @@
 
 		clearSelection();
 
-		String idColumn = PreferenceActivator.getDefault().getPreferenceStore()
-				.getString(OfficePreferences.EXCEL_COLUMN_VALUE);
+		String idColumn = Activator.getDefault().getPreferenceStore().getString(OfficePreferences.EXCEL_COLUMN_VALUE);
 		for (int i = 0; i <= sheet.getLastRowNum(); i++) {
 			Row row = sheet.getRow(i);
 			if (row != null) {