KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > launcher > AbstractPDELaunchConfigurationTabGroup


1 /*******************************************************************************
2  * Copyright (c) 2005, 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.pde.internal.ui.launcher;
12
13 import org.eclipse.core.runtime.CoreException;
14 import org.eclipse.core.runtime.Preferences;
15 import org.eclipse.debug.core.ILaunchConfiguration;
16 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
17 import org.eclipse.debug.ui.AbstractLaunchConfigurationTabGroup;
18 import org.eclipse.debug.ui.ILaunchConfigurationTab;
19 import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
20 import org.eclipse.pde.internal.core.ICoreConstants;
21 import org.eclipse.pde.internal.core.PDECore;
22 import org.eclipse.pde.ui.launcher.IPDELauncherConstants;
23 import org.eclipse.swt.custom.BusyIndicator;
24 import org.eclipse.swt.widgets.Display;
25
26 public abstract class AbstractPDELaunchConfigurationTabGroup extends
27         AbstractLaunchConfigurationTabGroup {
28
29     /**
30      * @see org.eclipse.debug.ui.AbstractLaunchConfigurationTabGroup#initializeFrom(ILaunchConfiguration)
31      */

32     public void initializeFrom(ILaunchConfiguration configuration) {
33         final ILaunchConfiguration config = configuration;
34         final ILaunchConfigurationTab[] tabs = getTabs();
35         BusyIndicator.showWhile(Display.getCurrent(), new Runnable JavaDoc() {
36             public void run() {
37                 try {
38                     if (config instanceof ILaunchConfigurationWorkingCopy) {
39                         checkBackwardCompatibility(
40                             (ILaunchConfigurationWorkingCopy) config);
41                     }
42                 } catch (CoreException e) {
43                 }
44                 for (int i = 0; i < tabs.length; i++) {
45                     tabs[i].initializeFrom(config);
46                 }
47             }
48         });
49     }
50     
51     private void checkBackwardCompatibility(ILaunchConfigurationWorkingCopy wc) throws CoreException {
52         String JavaDoc id = wc.getAttribute(
53                         IJavaLaunchConfigurationConstants.ATTR_SOURCE_PATH_PROVIDER,
54                         (String JavaDoc) null);
55         if (id == null) {
56             wc.setAttribute(
57                 IJavaLaunchConfigurationConstants.ATTR_SOURCE_PATH_PROVIDER,
58                 "org.eclipse.pde.ui.workbenchClasspathProvider"); //$NON-NLS-1$
59
}
60         
61         String JavaDoc value = wc.getAttribute("vmargs", (String JavaDoc)null); //$NON-NLS-1$
62
if (value != null) {
63             wc.setAttribute("vmargs", (String JavaDoc)null); //$NON-NLS-1$
64
wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS, value);
65         }
66         
67         value = wc.getAttribute("progargs", (String JavaDoc)null); //$NON-NLS-1$
68
if (value != null) {
69             wc.setAttribute("progargs", (String JavaDoc)null); //$NON-NLS-1$
70
wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, value);
71         }
72         
73         value = wc.getAttribute(IPDELauncherConstants.LOCATION + "0", (String JavaDoc)null); //$NON-NLS-1$
74
if (value != null) {
75             wc.setAttribute(IPDELauncherConstants.LOCATION + "0", (String JavaDoc)null); //$NON-NLS-1$
76
wc.setAttribute(IPDELauncherConstants.LOCATION, value);
77         }
78         
79         LaunchPluginValidator.checkBackwardCompatibility(wc, false);
80         wc.doSave();
81     }
82
83     /**
84      * @see org.eclipse.debug.ui.ILaunchConfigurationTabGroup#setDefaults(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
85      */

86     public void setDefaults(ILaunchConfigurationWorkingCopy configuration) {
87         super.setDefaults(configuration);
88         configuration.setAttribute(
89             IJavaLaunchConfigurationConstants.ATTR_SOURCE_PATH_PROVIDER,
90             "org.eclipse.pde.ui.workbenchClasspathProvider"); //$NON-NLS-1$
91

92         // Set Program/VM arguments with preference values
93
Preferences preferences = PDECore.getDefault().getPluginPreferences();
94         String JavaDoc programArgs = preferences.getString(ICoreConstants.PROGRAM_ARGS);
95         if (programArgs.length() > 0)
96             configuration.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, programArgs);
97         String JavaDoc vmArgs = preferences.getString(ICoreConstants.VM_ARGS);
98         if (vmArgs.length() > 0)
99             configuration.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS, vmArgs);
100     }
101
102 }
103
Popular Tags