KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > debug > ui > jres > StandardVMCommandTab


1 /*******************************************************************************
2  * Copyright (c) 2000, 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.jdt.internal.debug.ui.jres;
12
13
14 import com.ibm.icu.text.MessageFormat;
15 import java.util.HashMap JavaDoc;
16 import java.util.Map JavaDoc;
17
18 import org.eclipse.core.runtime.CoreException;
19 import org.eclipse.debug.core.ILaunchConfiguration;
20 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
21 import org.eclipse.debug.ui.AbstractLaunchConfigurationTab;
22 import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin;
23 import org.eclipse.jdt.internal.debug.ui.actions.ControlAccessibleListener;
24 import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
25 import org.eclipse.swt.SWT;
26 import org.eclipse.swt.events.ModifyEvent;
27 import org.eclipse.swt.events.ModifyListener;
28 import org.eclipse.swt.events.SelectionAdapter;
29 import org.eclipse.swt.events.SelectionEvent;
30 import org.eclipse.swt.graphics.Font;
31 import org.eclipse.swt.layout.GridData;
32 import org.eclipse.swt.layout.GridLayout;
33 import org.eclipse.swt.widgets.Button;
34 import org.eclipse.swt.widgets.Composite;
35 import org.eclipse.swt.widgets.Group;
36 import org.eclipse.swt.widgets.Text;
37
38 public class StandardVMCommandTab extends AbstractLaunchConfigurationTab {
39     
40     protected Text fJavaCommandText;
41     protected Button fDefaultButton;
42     protected Button fSpecificButton;
43     
44     protected static final Map JavaDoc EMPTY_MAP = new HashMap JavaDoc(1);
45     
46     /**
47      * @see ILaunchConfigurationTab#createControl(Composite)
48      */

49     public void createControl(Composite parent) {
50         Font font = parent.getFont();
51         Composite comp = new Composite(parent, parent.getStyle());
52         GridLayout layout = new GridLayout();
53         comp.setLayout(layout);
54         comp.setLayoutData(new GridData(GridData.FILL_BOTH));
55         comp.setFont(font);
56         
57         Group group = new Group(comp, SWT.NONE);
58         setControl(group);
59         GridLayout topLayout = new GridLayout();
60         group.setLayout(topLayout);
61         topLayout.numColumns = 2;
62         GridData gd = new GridData(GridData.FILL_HORIZONTAL);
63         group.setLayoutData(gd);
64         group.setFont(font);
65         
66         group.setText(JREMessages.AbstractJavaCommandTab_1);
67         
68         fDefaultButton = new Button(group, SWT.RADIO);
69         fDefaultButton.setFont(font);
70         gd = new GridData(GridData.BEGINNING);
71         gd.horizontalSpan = 2;
72         fDefaultButton.setLayoutData(gd);
73         fDefaultButton.setText(MessageFormat.format(JREMessages.AbstractJavaCommandTab_2, new String JavaDoc[]{getDefaultCommand()}));
74         
75         fDefaultButton.addSelectionListener(new SelectionAdapter() {
76             public void widgetSelected(SelectionEvent evt) {
77                 handleSelection();
78             }
79         });
80         
81         fSpecificButton = new Button(group, SWT.RADIO);
82         fSpecificButton.setFont(font);
83         gd = new GridData(GridData.BEGINNING);
84         fSpecificButton.setLayoutData(gd);
85         fSpecificButton.setText(JREMessages.AbstractJavaCommandTab_4);
86         
87         fSpecificButton.addSelectionListener(new SelectionAdapter() {
88             public void widgetSelected(SelectionEvent evt) {
89                 handleSelection();
90             }
91         });
92                 
93         fJavaCommandText= new Text(group, SWT.SINGLE | SWT.BORDER);
94         gd = new GridData(GridData.FILL_HORIZONTAL);
95         fJavaCommandText.setLayoutData(gd);
96         fJavaCommandText.setFont(font);
97         fJavaCommandText.addModifyListener(new ModifyListener() {
98             public void modifyText(ModifyEvent evt) {
99                 updateLaunchConfigurationDialog();
100             }
101         });
102         ControlAccessibleListener.addListener(fJavaCommandText, fSpecificButton.getText());
103         setControl(group);
104     }
105
106     protected void handleSelection() {
107         boolean useDefault = fDefaultButton.getSelection();
108         fDefaultButton.setSelection(useDefault);
109         fSpecificButton.setSelection(!useDefault);
110         fJavaCommandText.setEnabled(!useDefault);
111         updateLaunchConfigurationDialog();
112     }
113     
114     protected String JavaDoc getDefaultCommand() {
115         return "javaw"; //$NON-NLS-1$
116
}
117
118     /* (non-Javadoc)
119      * @see org.eclipse.debug.ui.ILaunchConfigurationTab#getName()
120      */

121     public String JavaDoc getName() {
122         return JREMessages.AbstractJavaCommandTab_3;
123     }
124
125     /* (non-Javadoc)
126      * @see org.eclipse.debug.ui.ILaunchConfigurationTab#initializeFrom(org.eclipse.debug.core.ILaunchConfiguration)
127      */

128     public void initializeFrom(ILaunchConfiguration configuration) {
129         String JavaDoc javaCommand= null;
130         try {
131             Map JavaDoc attributeMap = configuration.getAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_INSTALL_TYPE_SPECIFIC_ATTRS_MAP, (Map JavaDoc)null);
132             if (attributeMap != null) {
133                 javaCommand = (String JavaDoc) attributeMap.get(IJavaLaunchConfigurationConstants.ATTR_JAVA_COMMAND);
134             }
135         } catch(CoreException ce) {
136             JDIDebugUIPlugin.log(ce);
137         }
138         if (javaCommand == null) {
139             javaCommand = getDefaultCommand();
140         }
141         fJavaCommandText.setText(javaCommand);
142         if (javaCommand.equals(getDefaultCommand())) {
143             //using the default
144
fDefaultButton.setSelection(true);
145         } else {
146             fDefaultButton.setSelection(false);
147         }
148         handleSelection();
149     }
150
151     /* (non-Javadoc)
152      * @see org.eclipse.debug.ui.ILaunchConfigurationTab#performApply(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
153      */

154     public void performApply(ILaunchConfigurationWorkingCopy configuration) {
155         if (fDefaultButton.getSelection()) {
156             configuration.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_INSTALL_TYPE_SPECIFIC_ATTRS_MAP, (Map JavaDoc)null);
157         } else {
158             String JavaDoc javaCommand = fJavaCommandText.getText();
159             Map JavaDoc attributeMap = new HashMap JavaDoc(1);
160             attributeMap.put(IJavaLaunchConfigurationConstants.ATTR_JAVA_COMMAND, javaCommand);
161             configuration.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_INSTALL_TYPE_SPECIFIC_ATTRS_MAP, attributeMap);
162         }
163     }
164     
165     /* (non-Javadoc)
166      * @see org.eclipse.debug.ui.ILaunchConfigurationTab#setDefaults(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
167      */

168     public void setDefaults(ILaunchConfigurationWorkingCopy configuration) {
169         configuration.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_INSTALL_TYPE_SPECIFIC_ATTRS_MAP, (Map JavaDoc)null);
170     }
171
172     /**
173      * @see org.eclipse.debug.ui.AbstractLaunchConfigurationTab#getTabId()
174      */

175     public String JavaDoc getId() {
176         return "org.eclipse.jdt.debug.ui.standardVMCommandTab"; //$NON-NLS-1$
177
}
178     
179     /* (non-Javadoc)
180      * @see org.eclipse.debug.ui.ILaunchConfigurationTab#isValid(org.eclipse.debug.core.ILaunchConfiguration)
181      */

182     public boolean isValid(ILaunchConfiguration launchConfig) {
183         boolean valid= fDefaultButton.getSelection() || fJavaCommandText.getText().length() != 0;
184         if (valid) {
185             setErrorMessage(null);
186             setMessage(null);
187         } else {
188             setErrorMessage(JREMessages.AbstractJavaCommandTab_Java_executable_must_be_specified_5);
189             setMessage(null);
190         }
191         return valid;
192     }
193 }
194
Popular Tags