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 74480 | Differences between
and this patch

Collapse All | Expand All

(-)core/org/eclipse/debug/internal/core/LaunchManager.java (-1 / +106 lines)
Lines 57-62 Link Here
57
import org.eclipse.core.resources.IResourceDeltaVisitor;
57
import org.eclipse.core.resources.IResourceDeltaVisitor;
58
import org.eclipse.core.resources.IResourceProxy;
58
import org.eclipse.core.resources.IResourceProxy;
59
import org.eclipse.core.resources.IResourceProxyVisitor;
59
import org.eclipse.core.resources.IResourceProxyVisitor;
60
import org.eclipse.core.resources.ProjectScope;
60
import org.eclipse.core.resources.ResourcesPlugin;
61
import org.eclipse.core.resources.ResourcesPlugin;
61
import org.eclipse.core.runtime.CoreException;
62
import org.eclipse.core.runtime.CoreException;
62
import org.eclipse.core.runtime.IConfigurationElement;
63
import org.eclipse.core.runtime.IConfigurationElement;
Lines 65-75 Link Here
65
import org.eclipse.core.runtime.ISafeRunnable;
66
import org.eclipse.core.runtime.ISafeRunnable;
66
import org.eclipse.core.runtime.IStatus;
67
import org.eclipse.core.runtime.IStatus;
67
import org.eclipse.core.runtime.ListenerList;
68
import org.eclipse.core.runtime.ListenerList;
69
import org.eclipse.core.runtime.Path;
68
import org.eclipse.core.runtime.Platform;
70
import org.eclipse.core.runtime.Platform;
69
import org.eclipse.core.runtime.PlatformObject;
71
import org.eclipse.core.runtime.PlatformObject;
70
import org.eclipse.core.runtime.Preferences;
72
import org.eclipse.core.runtime.Preferences;
71
import org.eclipse.core.runtime.SafeRunner;
73
import org.eclipse.core.runtime.SafeRunner;
72
import org.eclipse.core.runtime.Status;
74
import org.eclipse.core.runtime.Status;
75
import org.eclipse.core.runtime.preferences.InstanceScope;
73
import org.eclipse.core.variables.VariablesPlugin;
76
import org.eclipse.core.variables.VariablesPlugin;
74
import org.eclipse.debug.core.DebugException;
77
import org.eclipse.debug.core.DebugException;
75
import org.eclipse.debug.core.DebugPlugin;
78
import org.eclipse.debug.core.DebugPlugin;
Lines 77-82 Link Here
77
import org.eclipse.debug.core.ILaunchConfiguration;
80
import org.eclipse.debug.core.ILaunchConfiguration;
78
import org.eclipse.debug.core.ILaunchConfigurationListener;
81
import org.eclipse.debug.core.ILaunchConfigurationListener;
79
import org.eclipse.debug.core.ILaunchConfigurationType;
82
import org.eclipse.debug.core.ILaunchConfigurationType;
83
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
80
import org.eclipse.debug.core.ILaunchDelegate;
84
import org.eclipse.debug.core.ILaunchDelegate;
81
import org.eclipse.debug.core.ILaunchListener;
85
import org.eclipse.debug.core.ILaunchListener;
82
import org.eclipse.debug.core.ILaunchManager;
86
import org.eclipse.debug.core.ILaunchManager;
Lines 94-99 Link Here
94
import org.eclipse.debug.internal.core.sourcelookup.SourceContainerType;
98
import org.eclipse.debug.internal.core.sourcelookup.SourceContainerType;
95
import org.eclipse.debug.internal.core.sourcelookup.SourcePathComputer;
99
import org.eclipse.debug.internal.core.sourcelookup.SourcePathComputer;
96
import org.eclipse.osgi.service.environment.Constants;
100
import org.eclipse.osgi.service.environment.Constants;
101
import org.osgi.service.prefs.BackingStoreException;
97
import org.w3c.dom.Document;
102
import org.w3c.dom.Document;
98
import org.w3c.dom.Element;
103
import org.w3c.dom.Element;
99
import org.w3c.dom.Node;
104
import org.w3c.dom.Node;
Lines 116-121 Link Here
116
	
121
	
117
	
122
	
118
	/**
123
	/**
124
	 * 
125
	 */
126
	private static final String DEFAULT_CONFIGURATION = "defaultConfiguration";
127
	/**
119
	 * Constants for xml node names
128
	 * Constants for xml node names
120
	 * 
129
	 * 
121
	 * @since 3.3
130
	 * @since 3.3
Lines 2312-2316 Link Here
2312
            }
2321
            }
2313
        }
2322
        }
2314
        return title;
2323
        return title;
2315
    }	
2324
    }
2325
2326
	/* (non-Javadoc)
2327
	 * @see org.eclipse.debug.core.ILaunchManager#getDefaultConfiguration(org.eclipse.core.resources.IResource)
2328
	 */
2329
	public ILaunchConfiguration getDefaultConfiguration(IResource resource) throws CoreException {
2330
		IProject project = resource.getProject();
2331
		if (project != null) {
2332
			org.osgi.service.prefs.Preferences projectNode = getProjectNode(resource);
2333
			String configValue = projectNode.get(DEFAULT_CONFIGURATION, null);
2334
			if (configValue != null) {
2335
				// shared config
2336
				IFile file = project.getFile(Path.fromPortableString(configValue));
2337
				return getLaunchConfiguration(file);
2338
			} else {
2339
				org.osgi.service.prefs.Preferences instanceNode = getInstanceNode(resource);
2340
				configValue = instanceNode.get(DEFAULT_CONFIGURATION, null);
2341
				if (configValue != null) {
2342
					// local config
2343
					return getLaunchConfiguration(configValue);
2344
				}
2345
			}
2346
		}
2347
		return null;
2348
	}
2349
2350
	/* (non-Javadoc)
2351
	 * @see org.eclipse.debug.core.ILaunchManager#setDefaultConfiguration(org.eclipse.core.resources.IResource, org.eclipse.debug.core.ILaunchConfiguration)
2352
	 */
2353
	public void setDefaultConfiguration(IResource resource, ILaunchConfiguration configuration) throws CoreException {
2354
		IProject project = resource.getProject();
2355
		if (project == null) {
2356
			throw new CoreException(new Status(IStatus.ERROR, DebugPlugin.getUniqueIdentifier(),
2357
					DebugPlugin.INTERNAL_ERROR, "Illegal argument: can only set default launch configuration on and within projects.", null));
2358
		}
2359
		if (configuration != null && !configuration.isLocal()) {
2360
			if (!configuration.getFile().getProject().equals(project)) {
2361
				throw new CoreException(new Status(IStatus.ERROR, DebugPlugin.getUniqueIdentifier(),
2362
						DebugPlugin.INTERNAL_ERROR, "A shared launch configuration must be shared in same project that it is a default configuration for.", null));
2363
			}
2364
		}
2365
		
2366
		// remove previous settings, if any
2367
		org.osgi.service.prefs.Preferences projectNode = getProjectNode(resource);
2368
		projectNode.remove(DEFAULT_CONFIGURATION);
2369
		flush(projectNode);
2370
		org.osgi.service.prefs.Preferences instanceNode = getInstanceNode(resource);
2371
		instanceNode.remove(DEFAULT_CONFIGURATION);
2372
		flush(instanceNode);
2373
		
2374
		if (configuration != null) {
2375
			org.osgi.service.prefs.Preferences node = null;
2376
			String configurationValue = null;
2377
			if (configuration.isLocal()) {
2378
				// for local configurations, use workspace (instance) scope preferences
2379
				node = instanceNode;
2380
				if (configuration.isWorkingCopy()) {
2381
					configurationValue = ((ILaunchConfigurationWorkingCopy)configuration).getOriginal().getMemento();
2382
				} else {
2383
					configurationValue = configuration.getMemento();
2384
				}
2385
			} else {
2386
				// for shared configurations, use project scope preferences
2387
				node = projectNode;
2388
				configurationValue = configuration.getFile().getProjectRelativePath().toPortableString();
2389
			}
2390
			node.put(DEFAULT_CONFIGURATION, configurationValue);
2391
			flush(node);
2392
		}
2393
		
2394
	}	
2395
	
2396
	private void flush(org.osgi.service.prefs.Preferences node) {
2397
		try {
2398
			node.flush();
2399
		} catch (BackingStoreException e) {
2400
			// TODO Auto-generated catch block
2401
			e.printStackTrace();
2402
		}
2403
	}
2404
	
2405
	private org.osgi.service.prefs.Preferences getProjectNode(IResource resource) {
2406
		org.osgi.service.prefs.Preferences node = Platform.getPreferencesService().getRootNode();
2407
		ProjectScope scope = new ProjectScope(resource.getProject());
2408
		node = scope.getNode(DebugPlugin.getUniqueIdentifier());
2409
		IProject project = resource.getProject();
2410
		if (!resource.equals(project)) {
2411
			node = node.node(resource.getProjectRelativePath().toString());
2412
		}
2413
		return node;
2414
	}
2415
	
2416
	private org.osgi.service.prefs.Preferences getInstanceNode(IResource resource) {
2417
		org.osgi.service.prefs.Preferences node = Platform.getPreferencesService().getRootNode();
2418
		node = node.node(InstanceScope.SCOPE).node(DebugPlugin.getUniqueIdentifier());
2419
		return node.node(resource.getFullPath().makeRelative().toString());
2420
	}
2316
}
2421
}
(-)core/org/eclipse/debug/core/ILaunchManager.java (+37 lines)
Lines 14-19 Link Here
14
import java.util.Map;
14
import java.util.Map;
15
15
16
import org.eclipse.core.resources.IFile;
16
import org.eclipse.core.resources.IFile;
17
import org.eclipse.core.resources.IResource;
17
import org.eclipse.core.runtime.CoreException;
18
import org.eclipse.core.runtime.CoreException;
18
import org.eclipse.debug.core.model.IDebugTarget;
19
import org.eclipse.debug.core.model.IDebugTarget;
19
import org.eclipse.debug.core.model.IPersistableSourceLocator;
20
import org.eclipse.debug.core.model.IPersistableSourceLocator;
Lines 459-464 Link Here
459
	 */
460
	 */
460
	public void removeLaunchListener(ILaunchListener listener);
461
	public void removeLaunchListener(ILaunchListener listener);
461
	
462
	
463
	/**
464
	 * Sets the given launch configuration as the default configuration for the specified
465
	 * resource. There is only one default configuration per resource and this replaces
466
	 * any previously existing launch configuration for the resource, if any. Specifying
467
	 * a configuration of <code>null</code> clears the default configuration for the
468
	 * given resource. 
469
	 * 
470
	 * @param resource resource
471
	 * @param configuration launch configuration or <code>null</code>
472
	 * @exception CoreException if unable to set as default
473
	 * @since 3.3
474
	 * <p>
475
	 * <strong>EXPERIMENTAL</strong>. This method has been added as
476
	 * part of a work in progress. There is no guarantee that this API will
477
	 * remain unchanged during the 3.3 release cycle. Please do not use this API
478
	 * without consulting with the Platform/Debug team.
479
	 * </p>
480
	 */
481
	public void setDefaultConfiguration(IResource resource, ILaunchConfiguration configuration) throws CoreException;
482
	
483
	/**
484
	 * Returns the default launch configuration for the specified resource, or <code>null</code>
485
	 * if none.
486
	 * 
487
	 * @param configuration launch configuration
488
	 * @return launch configuration or <code>null</code>
489
	 * @exception CoreException if an error occurs retrieving the configuration
490
	 * @since 3.3
491
	 * <p>
492
	 * <strong>EXPERIMENTAL</strong>. This method has been added as
493
	 * part of a work in progress. There is no guarantee that this API will
494
	 * remain unchanged during the 3.3 release cycle. Please do not use this API
495
	 * without consulting with the Platform/Debug team.
496
	 * </p>
497
	 */
498
	public ILaunchConfiguration getDefaultConfiguration(IResource resource) throws CoreException;
462
}
499
}
463
500
464
501
(-)plugin.xml (+7 lines)
Lines 1452-1457 Link Here
1452
            </or>
1452
            </or>
1453
         </enabledWhen>
1453
         </enabledWhen>
1454
      </page>
1454
      </page>
1455
      <page
1456
            adaptable="true"
1457
            class="org.eclipse.debug.internal.ui.launchConfigurations.properties.ExecutionPropertiesPage"
1458
            id="org.eclipse.debug.ui.properties.execution"
1459
            name="Execution"
1460
            objectClass="org.eclipse.core.resources.IResource">
1461
      </page>
1455
   </extension>
1462
   </extension>
1456
<!-- commands and their bindings
1463
<!-- commands and their bindings
1457
NOTE: 
1464
NOTE: 
(-)ui/org/eclipse/debug/internal/ui/IDebugHelpContextIds.java (+1 lines)
Lines 105-110 Link Here
105
	// Property pages
105
	// Property pages
106
	public static final String PROCESS_PROPERTY_PAGE = PREFIX + "process_property_page_context"; //$NON-NLS-1$
106
	public static final String PROCESS_PROPERTY_PAGE = PREFIX + "process_property_page_context"; //$NON-NLS-1$
107
	public static final String PROCESS_PAGE_RUN_AT = PREFIX + "process_page_run_at_time_widget"; //$NON-NLS-1$
107
	public static final String PROCESS_PAGE_RUN_AT = PREFIX + "process_page_run_at_time_widget"; //$NON-NLS-1$
108
	public static final String EXECUTION_PROPERTY_PAGE = PREFIX + "execution_property_page"; //$NON-NLS-1$
108
	
109
	
109
	// Launch configuration dialog pages
110
	// Launch configuration dialog pages
110
	public static final String LAUNCH_CONFIGURATION_DIALOG_COMMON_TAB = PREFIX + "launch_configuration_dialog_common_tab"; //$NON-NLS-1$
111
	public static final String LAUNCH_CONFIGURATION_DIALOG_COMMON_TAB = PREFIX + "launch_configuration_dialog_common_tab"; //$NON-NLS-1$
(-)ui/org/eclipse/debug/internal/ui/launchConfigurations/properties/ExecutionPropertiesPage.java (+209 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 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.ui.launchConfigurations.properties;
12
13
import java.util.ArrayList;
14
import java.util.List;
15
16
import org.eclipse.core.resources.IResource;
17
import org.eclipse.core.runtime.CoreException;
18
import org.eclipse.core.runtime.IAdaptable;
19
import org.eclipse.core.runtime.IPath;
20
import org.eclipse.debug.core.DebugPlugin;
21
import org.eclipse.debug.core.ILaunchConfiguration;
22
import org.eclipse.debug.core.ILaunchManager;
23
import org.eclipse.debug.internal.ui.DebugUIPlugin;
24
import org.eclipse.debug.internal.ui.DefaultLabelProvider;
25
import org.eclipse.debug.internal.ui.IDebugHelpContextIds;
26
import org.eclipse.debug.internal.ui.SWTUtil;
27
import org.eclipse.jface.viewers.CheckStateChangedEvent;
28
import org.eclipse.jface.viewers.CheckboxTableViewer;
29
import org.eclipse.jface.viewers.ICheckStateListener;
30
import org.eclipse.jface.viewers.IStructuredContentProvider;
31
import org.eclipse.jface.viewers.Viewer;
32
import org.eclipse.swt.SWT;
33
import org.eclipse.swt.layout.GridData;
34
import org.eclipse.swt.layout.GridLayout;
35
import org.eclipse.swt.widgets.Composite;
36
import org.eclipse.swt.widgets.Control;
37
import org.eclipse.swt.widgets.Table;
38
import org.eclipse.ui.PlatformUI;
39
import org.eclipse.ui.dialogs.PropertyPage;
40
import org.eclipse.ui.model.WorkbenchViewerComparator;
41
42
import com.ibm.icu.text.MessageFormat;
43
44
/**
45
 * Displays execution settings for a resource - associated launch configurations.
46
 * 
47
 * @since 3.3
48
 */
49
public class ExecutionPropertiesPage extends PropertyPage implements ICheckStateListener {
50
	
51
	private CheckboxTableViewer viewer;
52
	
53
	class ContentProvider implements IStructuredContentProvider {
54
55
		/* (non-Javadoc)
56
		 * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
57
		 */
58
		public Object[] getElements(Object inputElement) {
59
			IResource resource = (IResource)inputElement;			
60
			IPath resourcePath = resource.getFullPath();
61
			ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager();
62
			try {
63
				List list = new ArrayList();
64
				ILaunchConfiguration[] configurations = manager.getLaunchConfigurations();
65
				for (int i = 0; i < configurations.length; i++) {
66
					ILaunchConfiguration configuration = configurations[i];
67
					IResource[] resources = configuration.getMappedResources();
68
					if (resources != null) {
69
						for (int j = 0; j < resources.length; j++) {
70
							IResource mappedResource = resources[j];
71
							if (resource.equals(mappedResource) || 
72
									resourcePath.isPrefixOf(mappedResource.getFullPath())) {
73
								list.add(configuration);
74
								break;
75
							}
76
						}
77
					}
78
				}
79
				return list.toArray();
80
			} catch (CoreException e) {
81
				DebugUIPlugin.log(e);
82
			}
83
			return new Object[0];
84
		}
85
86
		/* (non-Javadoc)
87
		 * @see org.eclipse.jface.viewers.IContentProvider#dispose()
88
		 */
89
		public void dispose() {
90
		}
91
92
		/* (non-Javadoc)
93
		 * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
94
		 */
95
		public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
96
		}
97
		
98
	}
99
	
100
	/* (non-Javadoc)
101
	 * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
102
	 */
103
	protected Control createContents(Composite parent) {
104
		// TODO: add help to documentation
105
		PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, IDebugHelpContextIds.EXECUTION_PROPERTY_PAGE);
106
		
107
		Composite composite = new Composite(parent, SWT.NONE);
108
		composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
109
		GridLayout layout = new GridLayout();
110
		layout.marginHeight = 0;
111
		layout.marginWidth = 0;
112
		layout.numColumns = 2;
113
		composite.setLayout(layout);
114
		
115
		SWTUtil.createLabel(composite, MessageFormat.format("Select default launch &configuration for {0}:", new String[]{getResource().getName()}), 2);
116
		
117
		viewer= CheckboxTableViewer.newCheckList(composite, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER);
118
		viewer.setLabelProvider(new DefaultLabelProvider());
119
		viewer.setContentProvider(new ContentProvider());
120
		viewer.setComparator(new WorkbenchViewerComparator());
121
		viewer.addCheckStateListener(this);
122
		//TODO: launch config filters?
123
		Table builderTable= viewer.getTable();
124
		GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
125
		gridData.heightHint = 300;
126
		builderTable.setLayoutData(gridData);
127
		
128
		IResource resource = getResource();
129
		viewer.setInput(resource);
130
		try {
131
			ILaunchConfiguration configuration = DebugPlugin.getDefault().getLaunchManager().getDefaultConfiguration(resource);
132
			if (configuration != null) {
133
				viewer.setChecked(configuration, true);
134
			}
135
		} catch (CoreException e) {
136
			setErrorMessage(e.getMessage());
137
		}
138
		
139
		applyDialogFont(composite);
140
		return composite;
141
	}
142
143
	/**
144
	 * Returns the resource this property page is open on.
145
	 * 
146
	 * @return resource
147
	 */
148
	protected IResource getResource() {
149
		Object element = getElement();
150
		IResource resource = null;
151
		if (element instanceof IResource) {
152
			resource = (IResource) element;
153
		} else if (element instanceof IAdaptable) {
154
			resource = (IResource) ((IAdaptable)element).getAdapter(IResource.class);
155
		}
156
		return resource;
157
	}
158
159
	/* (non-Javadoc)
160
	 * @see org.eclipse.jface.viewers.ICheckStateListener#checkStateChanged(org.eclipse.jface.viewers.CheckStateChangedEvent)
161
	 */
162
	public void checkStateChanged(CheckStateChangedEvent event) {
163
		ILaunchConfiguration configuration = (ILaunchConfiguration) event.getElement();
164
		// only allow one check
165
		viewer.setCheckedElements(new Object[]{configuration});
166
		// validate
167
		if (!configuration.isLocal()) {
168
			if (!getResource().getProject().equals(configuration.getFile().getProject())) {
169
				// a config must be stored in the same project that it is a default config for
170
				setErrorMessage(MessageFormat.format("Configuration must be located in project {0}", new String[]{getResource().getProject().getName()}));
171
				setValid(false);
172
				return;
173
			}
174
		}
175
		setErrorMessage(null);
176
		setValid(true);
177
	}
178
179
	/* (non-Javadoc)
180
	 * @see org.eclipse.jface.preference.PreferencePage#performOk()
181
	 */
182
	public boolean performOk() {
183
		Object[] checked = viewer.getCheckedElements();
184
		try {
185
			ILaunchConfiguration def = null;
186
			if (checked.length == 1) {
187
					def = (ILaunchConfiguration) checked[0];
188
			}
189
			DebugPlugin.getDefault().getLaunchManager().setDefaultConfiguration(getResource(), def);
190
		} catch (CoreException e) {
191
			setErrorMessage(e.getMessage());
192
			return false;
193
		}
194
		return super.performOk();
195
	}
196
197
	/* (non-Javadoc)
198
	 * @see org.eclipse.jface.preference.PreferencePage#performDefaults()
199
	 */
200
	protected void performDefaults() {
201
		viewer.setAllChecked(false);
202
		setErrorMessage(null);
203
		setValid(true);
204
		super.performDefaults();
205
	}
206
207
	
208
	
209
}

Return to bug 74480