KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > debug > ui > launcher > VMArgumentsBlock


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.launcher;
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.StringVariableSelectionDialog;
18 import org.eclipse.jdt.debug.ui.launchConfigurations.JavaLaunchTab;
19 import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin;
20 import org.eclipse.jdt.internal.debug.ui.actions.ControlAccessibleListener;
21 import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
22 import org.eclipse.swt.SWT;
23 import org.eclipse.swt.events.ModifyEvent;
24 import org.eclipse.swt.events.ModifyListener;
25 import org.eclipse.swt.events.SelectionEvent;
26 import org.eclipse.swt.events.SelectionListener;
27 import org.eclipse.swt.graphics.Font;
28 import org.eclipse.swt.layout.GridData;
29 import org.eclipse.swt.layout.GridLayout;
30 import org.eclipse.swt.widgets.Button;
31 import org.eclipse.swt.widgets.Composite;
32 import org.eclipse.swt.widgets.Group;
33 import org.eclipse.swt.widgets.Text;
34
35 /**
36  * Editor for VM arguments of a Java launch configuration.
37  */

38 public class VMArgumentsBlock extends JavaLaunchTab {
39
40     // VM arguments widgets
41
protected Text fVMArgumentsText;
42     private Button fPgrmArgVariableButton;
43     
44     /**
45      * @see org.eclipse.debug.ui.ILaunchConfigurationTab#createControl(Composite)
46      */

47     public void createControl(Composite parent) {
48         Font font = parent.getFont();
49
50         Group group = new Group(parent, SWT.NONE);
51         setControl(group);
52         GridLayout topLayout = new GridLayout();
53         group.setLayout(topLayout);
54         GridData gd = new GridData(GridData.FILL_BOTH);
55         group.setLayoutData(gd);
56         group.setFont(font);
57         group.setText(LauncherMessages.JavaArgumentsTab_VM_ar_guments__6);
58         
59         fVMArgumentsText = new Text(group, SWT.MULTI | SWT.WRAP| SWT.BORDER | SWT.V_SCROLL);
60         gd = new GridData(GridData.FILL_BOTH);
61         gd.heightHint = 40;
62         gd.widthHint = 100;
63         fVMArgumentsText.setLayoutData(gd);
64         fVMArgumentsText.setFont(font);
65         fVMArgumentsText.addModifyListener(new ModifyListener() {
66             public void modifyText(ModifyEvent evt) {
67                 updateLaunchConfigurationDialog();
68             }
69         });
70         ControlAccessibleListener.addListener(fVMArgumentsText, group.getText());
71                 
72         fPgrmArgVariableButton = createPushButton(group, LauncherMessages.VMArgumentsBlock_4, null);
73         fPgrmArgVariableButton.setFont(font);
74         fPgrmArgVariableButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END));
75         fPgrmArgVariableButton.addSelectionListener(new SelectionListener() {
76             public void widgetSelected(SelectionEvent e) {
77                 StringVariableSelectionDialog dialog = new StringVariableSelectionDialog(getShell());
78                 dialog.open();
79                 String JavaDoc variable = dialog.getVariableExpression();
80                 if (variable != null) {
81                     fVMArgumentsText.insert(variable);
82                 }
83             }
84             public void widgetDefaultSelected(SelectionEvent e) {
85             }
86             
87         });
88     }
89
90     /**
91      * @see org.eclipse.debug.ui.ILaunchConfigurationTab#setDefaults(ILaunchConfigurationWorkingCopy)
92      */

93     public void setDefaults(ILaunchConfigurationWorkingCopy configuration) {
94         configuration.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS, (String JavaDoc)null);
95     }
96
97     /**
98      * @see org.eclipse.debug.ui.ILaunchConfigurationTab#initializeFrom(ILaunchConfiguration)
99      */

100     public void initializeFrom(ILaunchConfiguration configuration) {
101         try {
102             fVMArgumentsText.setText(configuration.getAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS, "")); //$NON-NLS-1$
103
} catch (CoreException e) {
104             setErrorMessage(LauncherMessages.JavaArgumentsTab_Exception_occurred_reading_configuration___15 + e.getStatus().getMessage());
105             JDIDebugUIPlugin.log(e);
106         }
107     }
108
109     /**
110      * @see org.eclipse.debug.ui.ILaunchConfigurationTab#performApply(ILaunchConfigurationWorkingCopy)
111      */

112     public void performApply(ILaunchConfigurationWorkingCopy configuration) {
113         configuration.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS, getAttributeValueFrom(fVMArgumentsText));
114     }
115
116     /**
117      * @see org.eclipse.debug.ui.ILaunchConfigurationTab#getName()
118      */

119     public String JavaDoc getName() {
120         return LauncherMessages.VMArgumentsBlock_VM_Arguments;
121     }
122     
123     /**
124      * Retuns the string in the text widget, or <code>null</code> if empty.
125      *
126      * @return text or <code>null</code>
127      */

128     protected String JavaDoc getAttributeValueFrom(Text text) {
129         String JavaDoc content = text.getText().trim();
130         if (content.length() > 0) {
131             return content;
132         }
133         return null;
134     }
135     
136     public void setEnabled(boolean enabled) {
137         fVMArgumentsText.setEnabled(enabled);
138         fPgrmArgVariableButton.setEnabled(enabled);
139     }
140 }
141
Popular Tags