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;
27 private Button fUseDefaultPortButton;
29 private Text fPortText;
35 public void createControl(Composite parent) {
36 Font font = parent.getFont();
38 Composite comp = new Composite(parent, SWT.NONE);
40 // PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(),
41 // IJavaDebugHelpContextIds.LAUNCH_CONFIGURATION_DIALOG_MAIN_TAB);
42 GridLayout topLayout = new GridLayout();
43 topLayout.verticalSpacing = 0;
44 comp.setLayout(topLayout);
46 createDebugPortEditor(comp);
50 private void createDebugPortEditor(Composite parent) {
51 Font font = parent.getFont();
52 Group debugGroup = new Group(parent, SWT.NONE);
53 debugGroup.setText("Debug: ");
54 GridData gd = new GridData(GridData.FILL_HORIZONTAL);
55 debugGroup.setLayoutData(gd);
56 GridLayout layout = new GridLayout();
57 layout.numColumns = 2;
58 debugGroup.setLayout(layout);
59 debugGroup.setFont(font);
61 fPortLabel = new Label(debugGroup, SWT.NONE);
62 fPortLabel.setText("&DebugPort:");
63 // gd = new GridData(GridData.BEGINNING);
64 // fPortLabel.setLayoutData(gd);
65 fPortLabel.setFont(font);
67 fPortText = new Text(debugGroup, SWT.SINGLE | SWT.BORDER);
68 gd = new GridData(GridData.FILL_HORIZONTAL);
69 fPortText.setLayoutData(gd);
70 fPortText.setFont(font);
71 fPortText.addModifyListener(new ModifyListener() {
72 public void modifyText(ModifyEvent evt) {
73 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();
109 protected void handleDefaultSellected(SelectionEvent event) {
110 setDebugportEnabledState();
111 updateLaunchConfigurationDialog();
114 public void setDefaults(ILaunchConfigurationWorkingCopy configuration) {
115 // TODO Auto-generated method stub
119 public void initializeFrom(ILaunchConfiguration configuration) {
122 + configuration.getAttribute(
123 IXDebugConstants.ATTR_PHP_DEBUGPORT, 9000);
124 fPortText.setText(portText);
125 boolean selection = configuration.getAttribute(
126 IXDebugConstants.ATTR_PHP_DEFAULT_DEBUGPORT, true);
127 fUseDefaultPortButton.setSelection(selection);
128 setDebugportEnabledState();
129 } catch (CoreException e) {
130 setErrorMessage(e.getMessage());
135 public void performApply(ILaunchConfigurationWorkingCopy configuration) {
136 configuration.setAttribute(IXDebugConstants.ATTR_PHP_DEFAULT_DEBUGPORT,
137 this.fUseDefaultPortButton.getSelection());
139 configuration.setAttribute(IXDebugConstants.ATTR_PHP_DEBUGPORT,
140 Integer.parseInt(this.fPortText.getText().trim()));
141 } catch (NumberFormatException nfe) {
149 * @see org.eclipse.debug.ui.ILaunchConfigurationTab#isValid(org.eclipse.debug.core.ILaunchConfiguration)
151 public boolean isValid(ILaunchConfiguration launchConfig) {
152 setErrorMessage(null);
154 Integer.parseInt(fPortText.getText().trim());
155 } catch (NumberFormatException nfe) {
156 setErrorMessage("Debugport is not a valid integer");
162 public String getName() {