KickJava   Java API By Example, From Geeks To Geeks.

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


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.internal.ui.launcher;
12
13 import java.util.TreeSet JavaDoc;
14
15 import org.eclipse.core.runtime.CoreException;
16 import org.eclipse.debug.core.ILaunchConfiguration;
17 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
18 import org.eclipse.pde.internal.ui.IPDEUIConstants;
19 import org.eclipse.pde.internal.ui.PDEUIMessages;
20 import org.eclipse.pde.ui.launcher.AbstractLauncherTab;
21 import org.eclipse.pde.ui.launcher.IPDELauncherConstants;
22
23 public class JUnitProgramBlock extends ProgramBlock {
24
25     public JUnitProgramBlock(AbstractLauncherTab tab) {
26         super(tab);
27     }
28
29     protected String JavaDoc getApplicationAttribute() {
30         return IPDELauncherConstants.APP_TO_TEST;
31     }
32     
33     public void setDefaults(ILaunchConfigurationWorkingCopy config) {
34         if (!LauncherUtils.requiresUI(config))
35             config.setAttribute(IPDELauncherConstants.APPLICATION,
36                     IPDEUIConstants.CORE_TEST_APPLICATION);
37         else
38             super.setDefaults(config);
39     }
40     
41     protected String JavaDoc[] getApplicationNames() {
42         TreeSet JavaDoc result = new TreeSet JavaDoc();
43         result.add(PDEUIMessages.JUnitProgramBlock_headless);
44         String JavaDoc[] appNames = super.getApplicationNames();
45         for (int i = 0; i < appNames.length; i++) {
46             result.add(appNames[i]);
47         }
48         return (String JavaDoc[])result.toArray(new String JavaDoc[result.size()]);
49     }
50     
51     /* (non-Javadoc)
52      * @see org.eclipse.pde.internal.ui.launcher.BasicLauncherTab#initializeApplicationSection(org.eclipse.debug.core.ILaunchConfiguration)
53      */

54     protected void initializeApplicationSection(ILaunchConfiguration config)
55             throws CoreException {
56         String JavaDoc application = config.getAttribute(IPDELauncherConstants.APPLICATION, (String JavaDoc)null);
57         if (IPDEUIConstants.CORE_TEST_APPLICATION.equals(application))
58             fApplicationCombo.setText(PDEUIMessages.JUnitProgramBlock_headless);
59         else
60             super.initializeApplicationSection(config);
61     }
62     
63     /* (non-Javadoc)
64      * @see org.eclipse.pde.internal.ui.launcher.BasicLauncherTab#saveApplicationSection(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
65      */

66     protected void saveApplicationSection(ILaunchConfigurationWorkingCopy config) {
67         if (fApplicationCombo.getText().equals(PDEUIMessages.JUnitProgramBlock_headless)) {
68             String JavaDoc appName = fApplicationCombo.isEnabled() ? IPDEUIConstants.CORE_TEST_APPLICATION : null;
69             config.setAttribute(IPDELauncherConstants.APPLICATION, appName);
70             config.setAttribute(IPDELauncherConstants.APP_TO_TEST, (String JavaDoc)null);
71         } else {
72             config.setAttribute(IPDELauncherConstants.APPLICATION, (String JavaDoc)null);
73             super.saveApplicationSection(config);
74         }
75     }
76     
77 }
78
Popular Tags