KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2005, 2007 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.ui.launcher;
12
13 import org.eclipse.core.runtime.CoreException;
14 import org.eclipse.debug.core.ILaunchConfiguration;
15 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
16 import org.eclipse.debug.ui.AbstractLaunchConfigurationTabGroup;
17 import org.eclipse.debug.ui.ILaunchConfigurationTab;
18 import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
19 import org.eclipse.pde.internal.core.TargetPlatformHelper;
20 import org.eclipse.pde.internal.ui.IPDEUIConstants;
21 import org.eclipse.pde.internal.ui.launcher.LaunchArgumentsHelper;
22 import org.eclipse.pde.internal.ui.launcher.LaunchPluginValidator;
23 import org.eclipse.swt.custom.BusyIndicator;
24 import org.eclipse.swt.widgets.Display;
25
26 /**
27  * An abstract class subclassed by the Eclipse application and JUnit Plug-in launch
28  * configuration tab groups.
29  * <p>
30  * This class is not intended to be subclassed by clients.
31  * </p>
32  * @since 3.3
33  */

34 public abstract class AbstractPDELaunchConfigurationTabGroup extends
35         AbstractLaunchConfigurationTabGroup {
36
37     /**
38      * The tab group delegates to all tabs in the group.
39      * Prior to the delegation, it migrates all pre-3.2 launch configurations
40      * to make them 3.2-compliant.
41      *
42      * @see org.eclipse.debug.ui.AbstractLaunchConfigurationTabGroup#initializeFrom(org.eclipse.debug.core.ILaunchConfiguration)
43      */

44     public void initializeFrom(ILaunchConfiguration configuration) {
45         final ILaunchConfiguration config = configuration;
46         final ILaunchConfigurationTab[] tabs = getTabs();
47         BusyIndicator.showWhile(Display.getCurrent(), new Runnable JavaDoc() {
48             public void run() {
49                 try {
50                     if (config instanceof ILaunchConfigurationWorkingCopy) {
51                         checkBackwardCompatibility(
52                             (ILaunchConfigurationWorkingCopy) config);
53                     }
54                 } catch (CoreException e) {
55                 }
56                 for (int i = 0; i < tabs.length; i++) {
57                     tabs[i].initializeFrom(config);
58                 }
59             }
60         });
61     }
62     
63     /**
64      * Checks if the launch configuration is 3.2-compliant and migrates it if it's not.
65      *
66      * @param wc
67      * the launch configuration to be migrated if it's not 3.2-compliant
68      * @throws CoreException
69      * a CoreException is thrown if there was an error retrieving launch
70      * configuration attributes
71      */

72     private void checkBackwardCompatibility(ILaunchConfigurationWorkingCopy wc) throws CoreException {
73         String JavaDoc id = wc.getAttribute(
74                         IJavaLaunchConfigurationConstants.ATTR_SOURCE_PATH_PROVIDER,
75                         (String JavaDoc) null);
76         if (id == null) {
77             wc.setAttribute(
78                 IJavaLaunchConfigurationConstants.ATTR_SOURCE_PATH_PROVIDER,
79                 PDESourcePathProvider.ID);
80         }
81         
82         String JavaDoc value = wc.getAttribute("vmargs", (String JavaDoc)null); //$NON-NLS-1$
83
if (value != null) {
84             wc.setAttribute("vmargs", (String JavaDoc)null); //$NON-NLS-1$
85
wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS, value);
86         }
87         
88         value = wc.getAttribute("progargs", (String JavaDoc)null); //$NON-NLS-1$
89
if (value != null) {
90             wc.setAttribute("progargs", (String JavaDoc)null); //$NON-NLS-1$
91
wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, value);
92         }
93         
94         value = wc.getAttribute(IPDELauncherConstants.LOCATION + "0", (String JavaDoc)null); //$NON-NLS-1$
95
if (value != null) {
96             wc.setAttribute(IPDELauncherConstants.LOCATION + "0", (String JavaDoc)null); //$NON-NLS-1$
97
wc.setAttribute(IPDELauncherConstants.LOCATION, value);
98         }
99         
100         LaunchPluginValidator.checkBackwardCompatibility(wc, false);
101         wc.doSave();
102     }
103
104     /**
105      * Delegates to all tabs to set defaults.
106      * It then sets program and VM arguments based on values on the
107      * <b>Plug-in Development > Target Platform > Launching Arguments</b> preference page.
108      *
109      * @see org.eclipse.debug.ui.AbstractLaunchConfigurationTabGroup#setDefaults(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
110      */

111     public void setDefaults(ILaunchConfigurationWorkingCopy configuration) {
112         super.setDefaults(configuration);
113         if (TargetPlatformHelper.usesNewApplicationModel())
114             configuration.setAttribute(IPDEUIConstants.LAUNCHER_PDE_VERSION, "3.3"); //$NON-NLS-1$
115
else if (TargetPlatformHelper.getTargetVersion() >= 3.2)
116             configuration.setAttribute(IPDEUIConstants.LAUNCHER_PDE_VERSION, "3.2a"); //$NON-NLS-1$
117

118         configuration.setAttribute(
119             IJavaLaunchConfigurationConstants.ATTR_SOURCE_PATH_PROVIDER,
120             PDESourcePathProvider.ID);
121         
122         // Set Program/VM arguments with preference values
123
String JavaDoc programArgs = LaunchArgumentsHelper.getInitialProgramArguments().trim();
124         if (programArgs.length() > 0)
125             configuration.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, programArgs);
126
127         String JavaDoc vmArgs = LaunchArgumentsHelper.getInitialVMArguments().trim();
128         if (vmArgs.length() > 0)
129             configuration.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS, vmArgs);
130         
131         configuration.setAttribute(IPDEUIConstants.APPEND_ARGS_EXPLICITLY, true);
132     }
133
134 }
135
Popular Tags