/*******************************************************************************
 * Copyright (c) 2012-2016 Torkild U. Resheim.
 *
 * All rights reserved. This program and the accompanying materials are made
 * available under the terms of the Eclipse Public License v1.0 which
 * accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors: Torkild U. Resheim - initial API and implementation
 *******************************************************************************/
package net.resheim.eclipse.launcher.macosx;

import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.TaskBar;
import org.eclipse.swt.widgets.TaskItem;
import org.eclipse.ui.PlatformUI;

import net.resheim.eclipse.launcher.core.IWorkspaceDecorator;

/**
 * Obtains the {@link TaskItem} belonging to the running application and sets
 * the badge to the workspace name.*
 *
 * @author Torkild U. Resheim
 */
public class WorkspaceDecorator implements IWorkspaceDecorator {

	public WorkspaceDecorator() {
	}

	private static TaskItem getTaskBarItem() {
		TaskBar bar = PlatformUI.getWorkbench().getDisplay().getSystemTaskBar();
		if (bar == null) {
			return null;
		}
		TaskItem item = bar.getItem(null);
		return item;
	}

	public void decorateWorkspace(final String name) {
		Display.getDefault().asyncExec(new Runnable() {
			public void run() {
				TaskItem item = getTaskBarItem();
				item.setOverlayText(name);
			}
		});
	}

}

@@ -1425,16 +1425,41 @@
 Item();%0A
+%09%09%09%09if (item != null) %7B%0A%09
 %09%09%09%09item
@@ -1481,16 +1481,22 @@
 (name);%0A
+%09%09%09%09%7D%0A
 %09%09%09%7D%0A%09%09%7D

Handle potential null pointer