1 package net.sourceforge.phpeclipse.xdebug.ui.php.launching;
3 import net.sourceforge.phpeclipse.xdebug.php.launching.IXDebugConstants;
5 import org.eclipse.core.runtime.CoreException;
6 import org.eclipse.debug.core.ILaunchConfiguration;
7 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
8 import org.eclipse.debug.ui.AbstractLaunchConfigurationTab;
9 import org.eclipse.swt.SWT;
10 import org.eclipse.swt.events.ModifyEvent;
11 import org.eclipse.swt.events.ModifyListener;
12 import org.eclipse.swt.events.SelectionAdapter;
13 import org.eclipse.swt.events.SelectionEvent;
14 import org.eclipse.swt.graphics.Font;
15 import org.eclipse.swt.layout.GridData;
16 import org.eclipse.swt.layout.GridLayout;
17 import org.eclipse.swt.widgets.Button;
18 import org.eclipse.swt.widgets.Composite;
19 import org.eclipse.swt.widgets.Group;
20 import org.eclipse.swt.widgets.Label;
21 import org.eclipse.swt.widgets.Text;
23 public class XDebugTab extends AbstractLaunchConfigurationTab {
25 private Label fPortLabel;
26 private Button fUseDefaultPortButton;
27 private Text fPortText;
33 public void createControl(Composite parent) {
34 Font font = parent.getFont();
36 Composite comp = new Composite(parent, SWT.NONE);
38 // PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), IJavaDebugHelpContextIds.LAUNCH_CONFIGURATION_DIALOG_MAIN_TAB);
39 GridLayout topLayout = new GridLayout();
40 topLayout.verticalSpacing = 0;
41 comp.setLayout(topLayout);
43 createDebugPortEditor(comp);
47 private void createDebugPortEditor(Composite parent) {
48 Font font= parent.getFont();
49 Group debugGroup= new Group(parent, SWT.NONE);
50 debugGroup.setText("Debug: ");
51 GridData gd = new GridData(GridData.FILL_HORIZONTAL);
52 debugGroup.setLayoutData(gd);
53 GridLayout layout = new GridLayout();
54 layout.numColumns = 2;
55 debugGroup.setLayout(layout);
56 debugGroup.setFont(font);
58 fPortLabel = new Label(debugGroup, SWT.NONE);
59 fPortLabel.setText("&DebugPort:");
60 // gd = new GridData(GridData.BEGINNING);
61 // fPortLabel.setLayoutData(gd);
62 fPortLabel.setFont(font);
65 fPortText = new Text(debugGroup, SWT.SINGLE | SWT.BORDER);
66 gd= new GridData(GridData.FILL_HORIZONTAL);
67 fPortText.setLayoutData(gd);
68 fPortText.setFont(font);
69 fPortText.addModifyListener(new ModifyListener() {
70 public void modifyText(ModifyEvent evt) {
71 updateLaunchConfigurationDialog();
77 fUseDefaultPortButton = new Button(debugGroup,SWT.CHECK);
78 fUseDefaultPortButton.setText("Use default interpreter");
79 gd = new GridData(GridData.FILL_HORIZONTAL);
80 fUseDefaultPortButton.setLayoutData(gd);
81 fUseDefaultPortButton.setFont(font);
82 fUseDefaultPortButton.addSelectionListener(new SelectionAdapter() {
83 public void widgetSelected(SelectionEvent event) {
84 handleDefaultSellected(event);
90 * Set the appropriate enabled state for the appletviewqer text widget.
92 protected void setDebugportEnabledState() {
93 if (isDefaultInterpreter()) {
94 fPortText.setEnabled(false);
95 fPortLabel.setEnabled(false);
97 fPortText.setEnabled(true);
98 fPortLabel.setEnabled(true);
103 * Returns whether the default appletviewer is to be used
105 protected boolean isDefaultInterpreter() {
106 return fUseDefaultPortButton.getSelection();
110 protected void handleDefaultSellected(SelectionEvent event) {
111 setDebugportEnabledState();
112 updateLaunchConfigurationDialog();
116 public void setDefaults(ILaunchConfigurationWorkingCopy configuration) {
117 // TODO Auto-generated method stub
121 public void initializeFrom(ILaunchConfiguration configuration) {
123 String portText=""+configuration.getAttribute(IXDebugConstants.ATTR_PHP_DEBUGPORT, 9000);
124 fPortText.setText(portText);
125 boolean selection=configuration.getAttribute(IXDebugConstants.ATTR_PHP_DEFAULT_DEBUGPORT, true);
126 fUseDefaultPortButton.setSelection(selection);
127 setDebugportEnabledState();
128 } catch (CoreException e) {
129 setErrorMessage(e.getMessage());
135 public void performApply(ILaunchConfigurationWorkingCopy configuration) {
136 configuration.setAttribute(IXDebugConstants.ATTR_PHP_DEFAULT_DEBUGPORT, this.fUseDefaultPortButton.getSelection());
138 configuration.setAttribute(IXDebugConstants.ATTR_PHP_DEBUGPORT, Integer.parseInt(this.fPortText.getText().trim()));
139 } catch (NumberFormatException nfe) {
145 * @see org.eclipse.debug.ui.ILaunchConfigurationTab#isValid(org.eclipse.debug.core.ILaunchConfiguration)
147 public boolean isValid(ILaunchConfiguration launchConfig) {
148 setErrorMessage(null);
150 Integer.parseInt(fPortText.getText().trim());
151 } catch(NumberFormatException nfe) {
152 setErrorMessage("Debugport is not a valid integer");
158 public String getName() {