Bug 451742 - Add org.eclipse.team.ui plugin to General > Tracing preference page
diff --git a/bundles/org.eclipse.team.ui/plugin.properties b/bundles/org.eclipse.team.ui/plugin.properties
index ca2303c..916b251 100644
--- a/bundles/org.eclipse.team.ui/plugin.properties
+++ b/bundles/org.eclipse.team.ui/plugin.properties
@@ -1,5 +1,5 @@
 ###############################################################################
-# Copyright (c) 2000, 2012 IBM Corporation and others.
+# Copyright (c) 2000, 2014 IBM Corporation 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
@@ -87,3 +87,5 @@
 PatchSyncParticipant=Patch
 PatchSyncWizard=Synchronize with Patch
 PatchSyncWizard_description=Synchronize resources with patch contents.
+
+TraceComponentLabel=Platform Team UI
diff --git a/bundles/org.eclipse.team.ui/plugin.xml b/bundles/org.eclipse.team.ui/plugin.xml
index eac01bc..c281c51 100644
--- a/bundles/org.eclipse.team.ui/plugin.xml
+++ b/bundles/org.eclipse.team.ui/plugin.xml
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <?eclipse version="3.0"?>
 <!--
-    Copyright (c) 2001, 2012 IBM Corporation and others.
+    Copyright (c) 2001, 2014 IBM Corporation 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
@@ -718,5 +718,16 @@
                icon="icons/full/obj/hunk_obj.gif"
                modelProviderId="org.eclipse.team.ui.patchModelProvider">
          </teamContentProvider>
-      </extension>	            
+      </extension>
+      <extension
+            point="org.eclipse.ui.trace.traceComponents">
+         <component
+               id="org.eclipse.team.ui.trace"
+               label="%TraceComponentLabel">
+            <bundle
+                  consumed="false"
+                  name="org.eclipse.team.ui">
+            </bundle>
+         </component>
+      </extension>
 </plugin>
diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/Policy.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/Policy.java
index 4094518..54ee5e6 100644
--- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/Policy.java
+++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/Policy.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2010 IBM Corporation and others.
+ * Copyright (c) 2000, 2014 IBM Corporation 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
@@ -13,7 +13,8 @@
 import java.util.ResourceBundle;
 
 import org.eclipse.core.runtime.*;
-
+import org.eclipse.osgi.service.debug.DebugOptions;
+import org.eclipse.osgi.service.debug.DebugOptionsListener;
 
 /**
  * Policy implements NLS convenience methods for the plugin and
@@ -38,16 +39,16 @@
             return tmpBundle;
         return actionBundle = ResourceBundle.getBundle(ACTION_BUNDLE);
     }
-    
-	static {
-		//init debug options
-		if (TeamUIPlugin.getPlugin().isDebugging()) {
-			DEBUG_SYNC_MODELS = "true".equalsIgnoreCase(Platform.getDebugOption(TeamUIPlugin.ID + "/syncmodels"));//$NON-NLS-1$ //$NON-NLS-2$
-			DEBUG_HISTORY = "true".equalsIgnoreCase(Platform.getDebugOption(TeamUIPlugin.ID + "/history"));//$NON-NLS-1$ //$NON-NLS-2$
-			DEBUG_DND = "true".equalsIgnoreCase(Platform.getDebugOption(TeamUIPlugin.ID + "/dnd"));//$NON-NLS-1$ //$NON-NLS-2$
+
+	static final DebugOptionsListener DEBUG_OPTIONS_LISTENER = new DebugOptionsListener() {
+		public void optionsChanged(DebugOptions options) {
+			boolean DEBUG = options.getBooleanOption(TeamUIPlugin.ID + "/debug", false); //$NON-NLS-1$
+			DEBUG_SYNC_MODELS = DEBUG && options.getBooleanOption(TeamUIPlugin.ID + "/syncmodels", false); //$NON-NLS-1$
+			DEBUG_HISTORY = DEBUG && options.getBooleanOption(TeamUIPlugin.ID + "/history", false); //$NON-NLS-1$
+			DEBUG_DND = DEBUG && options.getBooleanOption(TeamUIPlugin.ID + "/dnd", false); //$NON-NLS-1$
 		}
-	}
-	
+	};
+
 	/**
 	 * Checks if the progress monitor is canceled.
 	 * 
diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/TeamUIPlugin.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/TeamUIPlugin.java
index f180ded..b8e5ad0 100644
--- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/TeamUIPlugin.java
+++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/TeamUIPlugin.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2011 IBM Corporation and others.
+ * Copyright (c) 2000, 2014 IBM Corporation 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
@@ -10,7 +10,6 @@
  *******************************************************************************/
 package org.eclipse.team.internal.ui;
 
-
 import java.lang.reflect.InvocationTargetException;
 import java.net.URL;
 import java.util.*;
@@ -24,6 +23,8 @@
 import org.eclipse.jface.resource.ImageDescriptor;
 import org.eclipse.jface.util.IPropertyChangeListener;
 import org.eclipse.jface.util.PropertyChangeEvent;
+import org.eclipse.osgi.service.debug.DebugOptions;
+import org.eclipse.osgi.service.debug.DebugOptionsListener;
 import org.eclipse.swt.custom.BusyIndicator;
 import org.eclipse.swt.graphics.Image;
 import org.eclipse.swt.widgets.Display;
@@ -39,8 +40,7 @@
 import org.eclipse.team.ui.synchronize.*;
 import org.eclipse.ui.*;
 import org.eclipse.ui.plugin.AbstractUIPlugin;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
+import org.osgi.framework.*;
 
 /**
  * TeamUIPlugin is the plugin for generic, non-provider specific,
@@ -71,6 +71,8 @@
 	// manages synchronize participants
 	private SynchronizeManager synchronizeManager;
 
+	private ServiceRegistration debugRegistration;
+
 	/**
 	 * ID of the 'Remove from View' action.
 	 * Value: <code>"org.eclipse.team.internal.ui.RemoveFromView"</code>
@@ -212,7 +214,12 @@
 	 */
 	public void start(BundleContext context) throws Exception {
 		super.start(context);
-		
+
+		// register debug options listener
+		Hashtable properties = new Hashtable(2);
+		properties.put(DebugOptions.LISTENER_SYMBOLICNAME, ID);
+		debugRegistration = context.registerService(DebugOptionsListener.class, Policy.DEBUG_OPTIONS_LISTENER, properties);
+
 		initializeImages(this);
 
 		// This is a backwards compatibility check to ensure that repository
@@ -246,6 +253,10 @@
 	 */
 	public void stop(BundleContext context) throws Exception {
 		try {
+			// unregister debug options listener
+			debugRegistration.unregister();
+			debugRegistration = null;
+
 			if (synchronizeManager != null)
 				synchronizeManager.dispose();
 		} finally {
diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/SynchronizeModelUpdateHandler.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/SynchronizeModelUpdateHandler.java
index 51873e5..a34b3b2 100644
--- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/SynchronizeModelUpdateHandler.java
+++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/SynchronizeModelUpdateHandler.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2006 IBM Corporation and others.
+ * Copyright (c) 2000, 2014 IBM Corporation 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
@@ -41,9 +41,6 @@
  * handler's thread.
  */
 public class SynchronizeModelUpdateHandler extends BackgroundEventHandler implements IResourceChangeListener, ISyncInfoSetChangeListener {
-    
-    private static final boolean DEBUG = Policy.DEBUG_SYNC_MODELS;
-    
     private static final IWorkspaceRoot ROOT = ResourcesPlugin.getWorkspace().getRoot();
     
     // Event that indicates that the markers for a set of elements has changed
@@ -212,7 +209,7 @@
 				propagateProblemMarkers(element);
 				updateParentLabels(element);
 			}
-			if (DEBUG) {
+			if (Policy.DEBUG_SYNC_MODELS) {
 				long time = System.currentTimeMillis() - start;
 				DateFormat TIME_FORMAT = new SimpleDateFormat("m:ss.SSS"); //$NON-NLS-1$
 				String took = TIME_FORMAT.format(new Date(time));
@@ -419,7 +416,7 @@
     public void nodeAdded(ISynchronizeModelElement element, AbstractSynchronizeModelProvider provider) {
         element.addPropertyChangeListener(listener);
         this.provider.nodeAdded(element, provider);
-        if (DEBUG) {
+        if (Policy.DEBUG_SYNC_MODELS) {
             System.out.println("Node added: " + getDebugDisplayLabel(element) + " -> " + getDebugDisplayLabel((ISynchronizeModelElement)element.getParent()) + " : " + getDebugDisplayLabel(provider)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
         }
     }
@@ -436,7 +433,7 @@
     public void nodeRemoved(ISynchronizeModelElement element, AbstractSynchronizeModelProvider provider) {
         element.removePropertyChangeListener(listener);
         this.provider.nodeRemoved(element, provider);
-        if (DEBUG) {
+        if (Policy.DEBUG_SYNC_MODELS) {
             System.out.println("Node removed: " + getDebugDisplayLabel(element) + " -> " + getDebugDisplayLabel((ISynchronizeModelElement)element.getParent()) + " : " + getDebugDisplayLabel(provider)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
         }
     }
@@ -450,7 +447,7 @@
     public void modelObjectCleared(ISynchronizeModelElement node) {
         node.removePropertyChangeListener(listener);
         this.provider.modelObjectCleared(node);
-        if (DEBUG) {
+        if (Policy.DEBUG_SYNC_MODELS) {
             System.out.println("Node cleared: " + getDebugDisplayLabel(node)); //$NON-NLS-1$
         }
     }
@@ -579,7 +576,7 @@
                     if (additionsMap != null && !additionsMap.isEmpty() && Utils.canUpdateViewer(viewer)) {
                         for (Iterator iter = additionsMap.keySet().iterator(); iter.hasNext();) {
                             ISynchronizeModelElement parent = (ISynchronizeModelElement) iter.next();
-                            if (DEBUG) {
+                            if (Policy.DEBUG_SYNC_MODELS) {
                                 System.out.println("Adding child view items of " + parent.getName()); //$NON-NLS-1$
                             }
                             Set toAdd = (Set)additionsMap.get(parent);
@@ -716,14 +713,14 @@
      */
     protected void doAdd(ISynchronizeModelElement parent, ISynchronizeModelElement element) {
         if (additionsMap == null) {
-            if (DEBUG) {
+            if (Policy.DEBUG_SYNC_MODELS) {
                 System.out.println("Added view item " + element.getName()); //$NON-NLS-1$
             }
             AbstractTreeViewer viewer = (AbstractTreeViewer)getViewer();
             viewer.add(parent, element);
         } else {
             // Accumulate the additions
-            if (DEBUG) {
+            if (Policy.DEBUG_SYNC_MODELS) {
                 System.out.println("Queueing view item for addition " + element.getName()); //$NON-NLS-1$
             }
             Set toAdd = (Set)additionsMap.get(parent);