Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 284557 | Differences between
and this patch

Collapse All | Expand All

(-)core/org/eclipse/debug/internal/core/LaunchConfigurationType.java (+9 lines)
Lines 186-197 Link Here
186
		} else {
186
		} else {
187
			fPreferredDelegates.put(modes, delegate);
187
			fPreferredDelegates.put(modes, delegate);
188
		}
188
		}
189
		((LaunchManager)DebugPlugin.getDefault().getLaunchManager()).persistPreferredLaunchDelegate(this);
189
	}
190
	}
190
	
191
	
191
	/**
192
	/**
192
	 * @see org.eclipse.debug.core.ILaunchConfigurationType#getPreferredDelegate(java.util.Set)
193
	 * @see org.eclipse.debug.core.ILaunchConfigurationType#getPreferredDelegate(java.util.Set)
193
	 */
194
	 */
194
	public ILaunchDelegate getPreferredDelegate(Set modes) {
195
	public ILaunchDelegate getPreferredDelegate(Set modes) {
196
		initializePreferredDelegates();
195
		return (ILaunchDelegate) fPreferredDelegates.get(modes);
197
		return (ILaunchDelegate) fPreferredDelegates.get(modes);
196
	}
198
	}
197
	
199
	
Lines 208-213 Link Here
208
	 * @since 3.3
210
	 * @since 3.3
209
	 */
211
	 */
210
	public Map getPreferredDelegates() {
212
	public Map getPreferredDelegates() {
213
		initializePreferredDelegates();
211
		return fPreferredDelegates;
214
		return fPreferredDelegates;
212
	}
215
	}
213
	
216
	
Lines 503-507 Link Here
503
		return fModeCombinations.contains(modes);
506
		return fModeCombinations.contains(modes);
504
	}
507
	}
505
508
509
	/** 
510
	 * Called on preference import to reset preferred delegates.
511
	 */
512
	void resetPreferredDelegates() {
513
		fPreferredDelegates = null;
514
	}
506
}
515
}
507
516
(-)core/org/eclipse/debug/internal/core/LaunchManager.java (-27 / +44 lines)
Lines 1596-1601 Link Here
1596
	}
1596
	}
1597
	
1597
	
1598
	/**
1598
	/**
1599
	 * Allows internal access to reset preferred delegates when re-importing 
1600
	 * preferences.  
1601
	 * 
1602
	 * @since 3.6
1603
	 */
1604
	protected void resetPreferredDelegates() {
1605
	    fPreferredDelegates = null;
1606
	}
1607
	
1608
	/**
1599
	 * Allows internal access to a preferred delegate for a given type and mode set
1609
	 * Allows internal access to a preferred delegate for a given type and mode set
1600
	 * @param typeid the id of the <code>ILaunchConfigurationType</code> to find a delegate for
1610
	 * @param typeid the id of the <code>ILaunchConfigurationType</code> to find a delegate for
1601
	 * @param modes the set of modes for the delegate
1611
	 * @param modes the set of modes for the delegate
Lines 2347-2389 Link Here
2347
	 * 
2357
	 * 
2348
	 * @since 3.3
2358
	 * @since 3.3
2349
	 */
2359
	 */
2350
	private void persistPreferredLaunchDelegates() {
2360
	public void persistPreferredLaunchDelegates() {
2351
        ILaunchConfigurationType[] types = getLaunchConfigurationTypes();
2361
        ILaunchConfigurationType[] types = getLaunchConfigurationTypes();
2352
        Map preferred = null;
2353
        ILaunchDelegate delegate = null;
2354
        Set modes = null;
2355
        for(int i = 0; i < types.length; i++) {
2362
        for(int i = 0; i < types.length; i++) {
2356
            String preferenceName = PREF_PREFERRED_DELEGATES + '/' + types[i].getIdentifier();
2363
            persistPreferredLaunchDelegate((LaunchConfigurationType)types[i]);
2357
            preferred = ((LaunchConfigurationType)types[i]).getPreferredDelegates();
2364
        }
2358
            if(preferred != null && preferred.size() > 0) {
2365
	}
2359
                StringBuffer str = new StringBuffer();
2366
2360
                for(Iterator iter = preferred.keySet().iterator(); iter.hasNext();) {
2367
	/**
2361
                    modes = (Set) iter.next();
2368
	 * Persists the given launch configuration delegate. 
2362
                    delegate = (ILaunchDelegate) preferred.get(modes);
2369
	 * @param type Launch configuration type to persist
2363
                    if(delegate != null) {
2370
	 * 
2364
                        str.append(delegate.getId());
2371
	 * @since 3.6
2365
                        str.append(',');
2372
	 */
2366
                        for(Iterator iter2 = modes.iterator(); iter2.hasNext();) {
2373
    public void persistPreferredLaunchDelegate(LaunchConfigurationType type) {
2367
                            str.append(iter2.next());
2374
        String preferenceName = PREF_PREFERRED_DELEGATES + '/' + type.getIdentifier();
2368
                            if(iter2.hasNext()) {
2375
        Map preferred = type.getPreferredDelegates();
2369
                                str.append(',');
2376
        if(preferred != null && preferred.size() > 0) {
2370
                            }
2377
            StringBuffer str = new StringBuffer();
2371
                        }
2378
            for(Iterator iter = preferred.keySet().iterator(); iter.hasNext();) {
2372
                        if (iter.hasNext()) {
2379
                Set modes = (Set) iter.next();
2373
                            str.append(';');
2380
                ILaunchDelegate delegate = (ILaunchDelegate) preferred.get(modes);
2381
                if(delegate != null) {
2382
                    str.append(delegate.getId());
2383
                    str.append(',');
2384
                    for(Iterator iter2 = modes.iterator(); iter2.hasNext();) {
2385
                        str.append(iter2.next());
2386
                        if(iter2.hasNext()) {
2387
                            str.append(',');
2374
                        }
2388
                        }
2375
                    }
2389
                    }
2390
                    if (iter.hasNext()) {
2391
                        str.append(';');
2392
                    }
2376
                }
2393
                }
2377
                Preferences.setString(DebugPlugin.getUniqueIdentifier(), preferenceName, str.toString(), null);
2378
            } else {
2379
            	Preferences.setToDefault(DebugPlugin.getUniqueIdentifier(), preferenceName);
2380
            }
2394
            }
2395
            Preferences.setString(DebugPlugin.getUniqueIdentifier(), preferenceName, str.toString(), null);
2396
        } else {
2397
            Preferences.setToDefault(DebugPlugin.getUniqueIdentifier(), preferenceName);
2381
        }
2398
        }
2382
2399
2383
        // Reset the legacy preference string.
2400
        // Reset the legacy preference string.
2384
        Preferences.setToDefault(DebugPlugin.getUniqueIdentifier(), PREF_PREFERRED_DELEGATES);
2401
        Preferences.setToDefault(DebugPlugin.getUniqueIdentifier(), PREF_PREFERRED_DELEGATES);
2385
	}
2402
    }
2386
	
2403
2387
	/**
2404
	/**
2388
	 * finds and terminates any running launch configurations associated with the given resource
2405
	 * finds and terminates any running launch configurations associated with the given resource
2389
	 * @param resource the resource to search for launch configurations and hence launches for
2406
	 * @param resource the resource to search for launch configurations and hence launches for
(-)core/org/eclipse/debug/internal/core/PreferredDelegateModifyListener.java (+55 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.debug.internal.core;
12
13
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
14
import org.eclipse.core.runtime.preferences.IPreferenceNodeVisitor;
15
import org.eclipse.core.runtime.preferences.PreferenceModifyListener;
16
import org.eclipse.debug.core.DebugPlugin;
17
import org.eclipse.debug.core.ILaunchConfigurationType;
18
import org.osgi.service.prefs.BackingStoreException;
19
20
/**
21
 * Used to listen for preference imports that include changes to 
22
 * preferred launch delegates.
23
 * 
24
 * @since 3.6
25
 */
26
public class PreferredDelegateModifyListener extends PreferenceModifyListener {
27
	class Visitor implements IPreferenceNodeVisitor {
28
29
		public boolean visit(IEclipsePreferences node) throws BackingStoreException {
30
			if (node.name().equals(DebugPlugin.getUniqueIdentifier())) {
31
				// reset preferred delegates, so they are re-initialized from the preferences
32
				LaunchManager manager = (LaunchManager)DebugPlugin.getDefault().getLaunchManager();
33
				manager.resetPreferredDelegates();
34
				ILaunchConfigurationType[] types = manager.getLaunchConfigurationTypes();
35
				for (int i = 0; i < types.length; i++) {
36
					((LaunchConfigurationType) types[i]).resetPreferredDelegates();
37
				}
38
				return false;
39
			}
40
			return true;
41
		}
42
		
43
	}
44
45
	public IEclipsePreferences preApply(IEclipsePreferences node) {
46
		try {
47
			// force VMs to be initialized before we import the new VMs
48
			node.accept(new Visitor());
49
		} catch (BackingStoreException e) {
50
            DebugPlugin.log(e);
51
		}
52
		return node;
53
	}
54
55
}
(-)plugin.xml (+3 lines)
Lines 234-239 Link Here
234
      <initializer
234
      <initializer
235
            class="org.eclipse.debug.internal.core.DebugPreferenceInitializer">
235
            class="org.eclipse.debug.internal.core.DebugPreferenceInitializer">
236
      </initializer>
236
      </initializer>
237
      <modifier
238
            class="org.eclipse.debug.internal.core.PreferredDelegateModifyListener">
239
      </modifier>
237
   </extension>
240
   </extension>
238
241
239
<!-- ===================================== -->
242
<!-- ===================================== -->

Return to bug 284557