<commit_before>/*
 * Copyright (c) 2014 <NAME> (Berlin, Germany) and others.
 * 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:
 *    <NAME> - initial API and implementation
 */
package org.eclipse.oomph.internal.ui;

import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent;
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.TaskBar;
import org.eclipse.swt.widgets.TaskItem;
import org.eclipse.ui.IWindowListener;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;

/**
 *
 * @author <NAME>
 */
public class TaskItemDecorator
{
  private static final IWorkbench WORKBENCH = PlatformUI.getWorkbench();

  private static final TaskBar SYSTEM_TASK_BAR = WORKBENCH.getDisplay().getSystemTaskBar();

  public static final String IDE_NODE = "org.eclipse.ui.ide";

  public static final String WORKSPACE_NAME = "WORKSPACE_NAME";

  private static final IEclipsePreferences IDE_PREFERENCES = InstanceScope.INSTANCE.getNode(IDE_NODE);

  public TaskItemDecorator()
  {
    if (SYSTEM_TASK_BAR != null)
    {
      IDE_PREFERENCES.addPreferenceChangeListener(new IEclipsePreferences.IPreferenceChangeListener()
      {
        public void preferenceChange(PreferenceChangeEvent event)
        {
          Object value = event.getNewValue();
          update(value == null ? "" : value.toString());
        }
      });

      WORKBENCH.addWindowListener(new IWindowListener()
      {
        public void windowOpened(IWorkbenchWindow window)
        {
          Shell shell = window.getShell();
          if (shell != null && !shell.isDisposed())
          {
            update(shell, getWorkspaceName());
          }
        }

        public void windowDeactivated(IWorkbenchWindow window)
        {
        }
<commit_msg>[467875] SWTException in TaskBar.getItem (126)<commit_after>/*
 * Copyright (c) 2014 <NAME> (Berlin, Germany) and others.
 * 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:
 *    <NAME> - initial API and implementation
 */
package org.eclipse.oomph.internal.ui;

import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent;
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.TaskBar;
import org.eclipse.swt.widgets.TaskItem;
import org.eclipse.ui.IWindowListener;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;

/**
 *
 * @author <NAME>
 */
public class TaskItemDecorator
{
  private static final IWorkbench WORKBENCH = PlatformUI.getWorkbench();

  private static final TaskBar SYSTEM_TASK_BAR = WORKBENCH.getDisplay().getSystemTaskBar();

  public static final String IDE_NODE = "org.eclipse.ui.ide";

  public static final String WORKSPACE_NAME = "WORKSPACE_NAME";

  private static final IEclipsePreferences IDE_PREFERENCES = InstanceScope.INSTANCE.getNode(IDE_NODE);

  public TaskItemDecorator()
  {
    if (SYSTEM_TASK_BAR != null)
    {
      IDE_PREFERENCES.addPreferenceChangeListener(new IEclipsePreferences.IPreferenceChangeListener()
      {
        public void preferenceChange(PreferenceChangeEvent event)
        {
          if (WORKSPACE_NAME.equals(event.getKey()))
          {
            Object value = event.getNewValue();
            update(value == null ? "" : value.toString());
          }
        }
      });

      WORKBENCH.addWindowListener(new IWindowListener()
      {
        public void windowOpened(IWorkbenchWindow window)
        {
          Shell shell = window.getShell();
          if (shell != null && !shell.isDisposed())
          {
            update(shell, getWorkspaceName());
          }
        }

        public void windowDeactivated(IWorkbenchWindow window)
        {
        }

{'fraction_non_alphanumeric': 0.09774266365688487, 'fraction_numerical': 0.0056433408577878106, 'mean_word_length': 3.4487951807228914, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6651624', 'n_tokens_mistral': 1302, 'n_tokens_neox': 1253, 'n_words': 282}