KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > debug > ui > launchConfigurations > JavaArgumentsTab


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.debug.ui.launchConfigurations;
12
13  
14 import org.eclipse.core.runtime.CoreException;
15 import org.eclipse.debug.core.ILaunchConfiguration;
16 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
17 import org.eclipse.debug.ui.ILaunchConfigurationDialog;
18 import org.eclipse.debug.ui.StringVariableSelectionDialog;
19 import org.eclipse.jdt.internal.debug.ui.IJavaDebugHelpContextIds;
20 import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin;
21 import org.eclipse.jdt.internal.debug.ui.JavaDebugImages;
22 import org.eclipse.jdt.internal.debug.ui.actions.ControlAccessibleListener;
23 import org.eclipse.jdt.internal.debug.ui.launcher.LauncherMessages;
24 import org.eclipse.jdt.internal.debug.ui.launcher.VMArgumentsBlock;
25 import org.eclipse.jdt.internal.debug.ui.launcher.WorkingDirectoryBlock;
26 import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
27 import org.eclipse.swt.SWT;
28 import org.eclipse.swt.events.ModifyEvent;
29 import org.eclipse.swt.events.ModifyListener;
30 import org.eclipse.swt.events.SelectionEvent;
31 import org.eclipse.swt.events.SelectionListener;
32 import org.eclipse.swt.graphics.Font;
33 import org.eclipse.swt.graphics.Image;
34 import org.eclipse.swt.layout.GridData;
35 import org.eclipse.swt.layout.GridLayout;
36 import org.eclipse.swt.widgets.Button;
37 import org.eclipse.swt.widgets.Composite;
38 import org.eclipse.swt.widgets.Group;
39 import org.eclipse.swt.widgets.Label;
40 import org.eclipse.swt.widgets.Text;
41 import org.eclipse.ui.PlatformUI;
42
43 /**
44  * A launch configuration tab that displays and edits program arguments,
45  * VM arguments, and working directory launch configuration attributes.
46  * <p>
47  * This class may be instantiated. This class is not intended to be subclassed.
48  * </p>
49  * @since 2.0
50  */

51 public class JavaArgumentsTab extends JavaLaunchTab {
52         
53     // Program arguments widgets
54
protected Label fPrgmArgumentsLabel;
55     protected Text fPrgmArgumentsText;
56
57     // VM arguments widgets
58
protected VMArgumentsBlock fVMArgumentsBlock;
59     
60     // Working directory
61
protected WorkingDirectoryBlock fWorkingDirectoryBlock;
62         
63     protected static final String JavaDoc EMPTY_STRING = ""; //$NON-NLS-1$
64

65     public JavaArgumentsTab() {
66         fVMArgumentsBlock = createVMArgsBlock();
67         fWorkingDirectoryBlock = createWorkingDirBlock();
68     }
69     
70     protected VMArgumentsBlock createVMArgsBlock() {
71         return new VMArgumentsBlock();
72     }
73     
74     protected WorkingDirectoryBlock createWorkingDirBlock() {
75         return new WorkingDirectoryBlock();
76     }
77     
78     /**
79      * @see org.eclipse.debug.ui.ILaunchConfigurationTab#createControl(Composite)
80      */

81     public void createControl(Composite parent) {
82         Font font = parent.getFont();
83         Composite comp = new Composite(parent, SWT.NONE);
84         GridLayout layout = new GridLayout(1, true);
85         comp.setLayout(layout);
86         comp.setFont(font);
87         
88         GridData gd = new GridData(GridData.FILL_BOTH);
89         comp.setLayoutData(gd);
90         setControl(comp);
91         setHelpContextId();
92         
93         Group group = new Group(comp, SWT.NONE);
94         group.setFont(font);
95         layout = new GridLayout();
96         group.setLayout(layout);
97         group.setLayoutData(new GridData(GridData.FILL_BOTH));
98         
99         String JavaDoc controlName = (LauncherMessages.JavaArgumentsTab__Program_arguments__5);
100         group.setText(controlName);
101         
102         fPrgmArgumentsText = new Text(group, SWT.MULTI | SWT.WRAP | SWT.BORDER | SWT.V_SCROLL);
103         gd = new GridData(GridData.FILL_BOTH);
104         gd.heightHint = 40;
105         gd.widthHint = 100;
106         fPrgmArgumentsText.setLayoutData(gd);
107         fPrgmArgumentsText.setFont(font);
108         fPrgmArgumentsText.addModifyListener(new ModifyListener() {
109             public void modifyText(ModifyEvent evt) {
110                 updateLaunchConfigurationDialog();
111             }
112         });
113         ControlAccessibleListener.addListener(fPrgmArgumentsText, group.getText());
114         
115         String JavaDoc buttonLabel = LauncherMessages.JavaArgumentsTab_5;
116         Button pgrmArgVariableButton = createPushButton(group, buttonLabel, null);
117         pgrmArgVariableButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END));
118         pgrmArgVariableButton.addSelectionListener(new SelectionListener() {
119             public void widgetSelected(SelectionEvent e) {
120                 StringVariableSelectionDialog dialog = new StringVariableSelectionDialog(getShell());
121                 dialog.open();
122                 String JavaDoc variable = dialog.getVariableExpression();
123                 if (variable != null) {
124                     fPrgmArgumentsText.insert(variable);
125                 }
126             }
127             public void widgetDefaultSelected(SelectionEvent e) {
128             }
129             
130         });
131         
132         fVMArgumentsBlock.createControl(comp);
133         
134         fWorkingDirectoryBlock.createControl(comp);
135     }
136     
137     /**
138      * Set the help context id for this launch config tab. Subclasses may
139      * override this method.
140      */

141     protected void setHelpContextId() {
142         PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), IJavaDebugHelpContextIds.LAUNCH_CONFIGURATION_DIALOG_ARGUMENTS_TAB);
143     }
144             
145     /**
146      * @see org.eclipse.debug.ui.ILaunchConfigurationTab#dispose()
147      */

148     public void dispose() {
149     }
150         
151     /**
152      * @see org.eclipse.debug.ui.ILaunchConfigurationTab#isValid(ILaunchConfiguration)
153      */

154     public boolean isValid(ILaunchConfiguration config) {
155         return fWorkingDirectoryBlock.isValid(config);
156     }
157
158     /**
159      * Defaults are empty.
160      *
161      * @see org.eclipse.debug.ui.ILaunchConfigurationTab#setDefaults(ILaunchConfigurationWorkingCopy)
162      */

163     public void setDefaults(ILaunchConfigurationWorkingCopy config) {
164         config.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, (String JavaDoc)null);
165         fVMArgumentsBlock.setDefaults(config);
166         fWorkingDirectoryBlock.setDefaults(config);
167     }
168
169     /**
170      * @see org.eclipse.debug.ui.ILaunchConfigurationTab#initializeFrom(ILaunchConfiguration)
171      */

172     public void initializeFrom(ILaunchConfiguration configuration) {
173         try {
174             fPrgmArgumentsText.setText(configuration.getAttribute(IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, "")); //$NON-NLS-1$
175
fVMArgumentsBlock.initializeFrom(configuration);
176             fWorkingDirectoryBlock.initializeFrom(configuration);
177         } catch (CoreException e) {
178             setErrorMessage(LauncherMessages.JavaArgumentsTab_Exception_occurred_reading_configuration___15 + e.getStatus().getMessage());
179             JDIDebugUIPlugin.log(e);
180         }
181     }
182
183     /**
184      * @see org.eclipse.debug.ui.ILaunchConfigurationTab#performApply(ILaunchConfigurationWorkingCopy)
185      */

186     public void performApply(ILaunchConfigurationWorkingCopy configuration) {
187         configuration.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, getAttributeValueFrom(fPrgmArgumentsText));
188         fVMArgumentsBlock.performApply(configuration);
189         fWorkingDirectoryBlock.performApply(configuration);
190     }
191
192     /**
193      * Returns the string in the text widget, or <code>null</code> if empty.
194      *
195      * @return text or <code>null</code>
196      */

197     protected String JavaDoc getAttributeValueFrom(Text text) {
198         String JavaDoc content = text.getText().trim();
199         if (content.length() > 0) {
200             return content;
201         }
202         return null;
203     }
204     
205     /**
206      * @see org.eclipse.debug.ui.ILaunchConfigurationTab#getName()
207      */

208     public String JavaDoc getName() {
209         return LauncherMessages.JavaArgumentsTab__Arguments_16;
210     }
211     
212     /**
213      * @see org.eclipse.debug.ui.ILaunchConfigurationTab#setLaunchConfigurationDialog(ILaunchConfigurationDialog)
214      */

215     public void setLaunchConfigurationDialog(ILaunchConfigurationDialog dialog) {
216         super.setLaunchConfigurationDialog(dialog);
217         fWorkingDirectoryBlock.setLaunchConfigurationDialog(dialog);
218         fVMArgumentsBlock.setLaunchConfigurationDialog(dialog);
219     }
220     /**
221      * @see org.eclipse.debug.ui.ILaunchConfigurationTab#getErrorMessage()
222      */

223     public String JavaDoc getErrorMessage() {
224         String JavaDoc m = super.getErrorMessage();
225         if (m == null) {
226             return fWorkingDirectoryBlock.getErrorMessage();
227         }
228         return m;
229     }
230
231     /**
232      * @see org.eclipse.debug.ui.ILaunchConfigurationTab#getMessage()
233      */

234     public String JavaDoc getMessage() {
235         String JavaDoc m = super.getMessage();
236         if (m == null) {
237             return fWorkingDirectoryBlock.getMessage();
238         }
239         return m;
240     }
241     
242     /**
243      * @see org.eclipse.debug.ui.ILaunchConfigurationTab#getImage()
244      */

245     public Image getImage() {
246         return JavaDebugImages.get(JavaDebugImages.IMG_VIEW_ARGUMENTS_TAB);
247     }
248     
249     /**
250      * @see org.eclipse.debug.ui.AbstractLaunchConfigurationTab#getId()
251      *
252      * @since 3.3
253      */

254     public String JavaDoc getId() {
255         return "org.eclipse.jdt.debug.ui.javaArgumentsTab"; //$NON-NLS-1$
256
}
257
258     /* (non-Javadoc)
259      * @see org.eclipse.debug.ui.ILaunchConfigurationTab#activated(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
260      */

261     public void activated(ILaunchConfigurationWorkingCopy workingCopy) {
262         fWorkingDirectoryBlock.initializeFrom(workingCopy);
263     }
264
265     /* (non-Javadoc)
266      * @see org.eclipse.debug.ui.ILaunchConfigurationTab#deactivated(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
267      */

268     public void deactivated(ILaunchConfigurationWorkingCopy workingCopy) {
269         // do nothing when deactivated
270
}
271 }
272
273
Popular Tags