558210: Task List view “Failed to create the part’s controls”

Change-Id: Iabc0d9c09fc2b27699ed24469edac68ebe79a63a
Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=558210
diff --git a/org.eclipse.mylyn.tasks.index.ui/src/org/eclipse/mylyn/internal/tasks/index/ui/IndexReference.java b/org.eclipse.mylyn.tasks.index.ui/src/org/eclipse/mylyn/internal/tasks/index/ui/IndexReference.java
index 475404a..303689b 100644
--- a/org.eclipse.mylyn.tasks.index.ui/src/org/eclipse/mylyn/internal/tasks/index/ui/IndexReference.java
+++ b/org.eclipse.mylyn.tasks.index.ui/src/org/eclipse/mylyn/internal/tasks/index/ui/IndexReference.java
@@ -1,10 +1,10 @@
 /*******************************************************************************
  * Copyright (c) 2012 Tasktop Technologies and others.
- * 
+ *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v. 2.0 which is available at
  * https://www.eclipse.org/legal/epl-2.0
- * 
+ *
  * SPDX-License-Identifier: EPL-2.0
  *
  * Contributors:
@@ -55,7 +55,7 @@
 	public TaskListIndex index() {
 		synchronized (IndexReference.class) {
 			if (index == null) {
-				if (theIndex == null) {
+				if (theIndex == null && TasksUiPlugin.getTaskDataManager() != null) {
 					final IRepositoryManager repositoryManager = TasksUiPlugin.getRepositoryManager();
 					theIndex = new TaskListIndex(TasksUiPlugin.getTaskList(), TasksUiPlugin.getTaskDataManager(),
 							repositoryManager, getDefaultIndexLocation());
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/views/TaskListView.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/views/TaskListView.java
index 90b71fa..ebd72a5 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/views/TaskListView.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/views/TaskListView.java
@@ -1,10 +1,10 @@
 /*******************************************************************************
  * Copyright (c) 2004, 2016 Tasktop Technologies and others.
- * 
+ *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v. 2.0 which is available at
  * https://www.eclipse.org/legal/epl-2.0
- * 
+ *
  * SPDX-License-Identifier: EPL-2.0
  *
  * Contributors:
@@ -56,6 +56,7 @@
 import org.eclipse.jface.viewers.TextCellEditor;
 import org.eclipse.jface.viewers.TreeViewer;
 import org.eclipse.mylyn.commons.core.StatusHandler;
+import org.eclipse.mylyn.commons.notifications.feed.ServiceMessageManager;
 import org.eclipse.mylyn.commons.ui.CommonImages;
 import org.eclipse.mylyn.commons.ui.PlatformUiUtil;
 import org.eclipse.mylyn.commons.ui.compatibility.CommonThemes;
@@ -134,6 +135,7 @@
 import org.eclipse.swt.graphics.Rectangle;
 import org.eclipse.swt.layout.GridLayout;
 import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
 import org.eclipse.swt.widgets.Event;
 import org.eclipse.swt.widgets.Listener;
 import org.eclipse.swt.widgets.Menu;
@@ -778,11 +780,30 @@
 			message.setTitle(Messages.TaskListView_Welcome_Message_Title);
 			message.setImage(Dialog.DLG_IMG_MESSAGE_INFO);
 			serviceMessageControl.setMessage(message);
-			TasksUiPlugin.getDefault().getPreferenceStore().setValue(ITasksUiPreferenceConstants.WELCOME_MESSAGE,
-					Boolean.toString(true));
+			TasksUiPlugin.getDefault()
+					.getPreferenceStore()
+					.setValue(ITasksUiPreferenceConstants.WELCOME_MESSAGE, Boolean.toString(true));
 		}
 
-		TasksUiPlugin.getDefault().getServiceMessageManager().addServiceMessageListener(serviceMessageControl);
+		ServiceMessageManager serviceMessageManager = TasksUiPlugin.getDefault().getServiceMessageManager();
+		if (serviceMessageManager == null) {
+			Display.getDefault().asyncExec(new Runnable() {
+
+				@Override
+				public void run() {
+					ServiceMessageManager serviceMessageManager = TasksUiPlugin.getDefault().getServiceMessageManager();
+					if (serviceMessageManager != null) {
+						serviceMessageManager.addServiceMessageListener(serviceMessageControl);
+					} else {
+						StatusHandler.log(new Status(IStatus.ERROR, TasksUiPlugin.ID_PLUGIN,
+								"Could not add Listener for serviceMessageControl")); //$NON-NLS-1$
+
+					}
+				}
+			});
+		} else {
+			serviceMessageManager.addServiceMessageListener(serviceMessageControl);
+		}
 
 		// Need to do this because the page, which holds the active working set is not around on creation, see bug 203179
 		PlatformUI.getWorkbench().getActiveWorkbenchWindow().addPageListener(PAGE_LISTENER);
@@ -1530,7 +1551,8 @@
 					if (width) {
 						if (getViewSite().getActionBars().getToolBarManager() instanceof ToolBarManager) {
 							Point size = ((ToolBarManager) getViewSite().getActionBars().getToolBarManager())
-									.getControl().computeSize(SWT.DEFAULT, SWT.DEFAULT);
+									.getControl()
+									.computeSize(SWT.DEFAULT, SWT.DEFAULT);
 							// leave some room for the view menu drop-down
 							return size.x + PlatformUiUtil.getViewMenuWidth();
 						}