e3ed6ac3d11f993dcb1762666b21f56ca03f7cb8
[phpeclipse.git] / net.sourceforge.phpeclipse.xdebug.ui / src / net / sourceforge / phpeclipse / xdebug / ui / php / launching / XDebugTab.java
1 package net.sourceforge.phpeclipse.xdebug.ui.php.launching;
2
3 import net.sourceforge.phpeclipse.xdebug.php.launching.IXDebugConstants;
4
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;
22
23 public class XDebugTab extends AbstractLaunchConfigurationTab {
24
25         private Label fPortLabel;
26
27         private Button fUseDefaultPortButton;
28
29         private Text fPortText;
30
31         public XDebugTab() {
32                 super();
33         }
34
35         public void createControl(Composite parent) {
36                 Font font = parent.getFont();
37
38                 Composite comp = new Composite(parent, SWT.NONE);
39                 setControl(comp);
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);
45                 comp.setFont(font);
46                 createDebugPortEditor(comp);
47
48         }
49
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);
60
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);
66
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();
74                         }
75                 });
76
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);
85                         }
86                 });
87         }
88
89         /**
90          * Set the appropriate enabled state for the appletviewqer text widget.
91          */
92         protected void setDebugportEnabledState() {
93                 if (isDefaultInterpreter()) {
94                         fPortText.setEnabled(false);
95                         fPortLabel.setEnabled(false);
96                 } else {
97                         fPortText.setEnabled(true);
98                         fPortLabel.setEnabled(true);
99                 }
100         }
101
102         /**
103          * Returns whether the default appletviewer is to be used
104          */
105         protected boolean isDefaultInterpreter() {
106                 return fUseDefaultPortButton.getSelection();
107         }
108
109         protected void handleDefaultSellected(SelectionEvent event) {
110                 setDebugportEnabledState();
111                 updateLaunchConfigurationDialog();
112         }
113
114         public void setDefaults(ILaunchConfigurationWorkingCopy configuration) {
115                 // TODO Auto-generated method stub
116
117         }
118
119         public void initializeFrom(ILaunchConfiguration configuration) {
120                 try {
121                         String portText = ""
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());
131                 }
132
133         }
134
135         public void performApply(ILaunchConfigurationWorkingCopy configuration) {
136                 configuration.setAttribute(IXDebugConstants.ATTR_PHP_DEFAULT_DEBUGPORT,
137                                 this.fUseDefaultPortButton.getSelection());
138                 try {
139                         configuration.setAttribute(IXDebugConstants.ATTR_PHP_DEBUGPORT,
140                                         Integer.parseInt(this.fPortText.getText().trim()));
141                 } catch (NumberFormatException nfe) {
142                 }
143
144         }
145
146         /*
147          * (non-Javadoc)
148          * 
149          * @see org.eclipse.debug.ui.ILaunchConfigurationTab#isValid(org.eclipse.debug.core.ILaunchConfiguration)
150          */
151         public boolean isValid(ILaunchConfiguration launchConfig) {
152                 setErrorMessage(null);
153                 try {
154                         Integer.parseInt(fPortText.getText().trim());
155                 } catch (NumberFormatException nfe) {
156                         setErrorMessage("Debugport is not a valid integer");
157                         return false;
158                 }
159                 return true;
160         }
161
162         public String getName() {
163                 return "XDebug";
164         }
165
166 }