66852a3a3df72efc6059a7812201034c07e82678
[phpeclipse.git] / net.sourceforge.phpeclipse.xdebug.ui / src / net / sourceforge / phpeclipse / xdebug / ui / XDebugMainTab.java
1 /*
2  * Created on 25.11.2004
3  *
4  * TODO To change the template for this generated file go to
5  * Window - Preferences - Java - Code Style - Code Templates
6  */
7 package net.sourceforge.phpeclipse.xdebug.ui;
8
9 import org.eclipse.core.resources.IFile;
10 import org.eclipse.core.resources.IResource;
11 import org.eclipse.core.resources.ResourcesPlugin;
12 import org.eclipse.core.runtime.CoreException;
13 import org.eclipse.core.runtime.IPath;
14 import org.eclipse.core.runtime.Path;
15 import org.eclipse.debug.core.ILaunchConfiguration;
16 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
17 import net.sourceforge.phpeclipse.xdebug.core.IXDebugConstants;
18 import org.eclipse.debug.ui.AbstractLaunchConfigurationTab;
19 import org.eclipse.jface.window.Window;
20 import org.eclipse.swt.SWT;
21 import org.eclipse.swt.events.ModifyEvent;
22 import org.eclipse.swt.events.ModifyListener;
23 import org.eclipse.swt.events.SelectionAdapter;
24 import org.eclipse.swt.events.SelectionEvent;
25 import org.eclipse.swt.graphics.Font;
26 import org.eclipse.swt.layout.GridData;
27 import org.eclipse.swt.layout.GridLayout;
28 import org.eclipse.swt.widgets.Button;
29 import org.eclipse.swt.widgets.Composite;
30 import org.eclipse.swt.widgets.Label;
31 import org.eclipse.swt.widgets.Text;
32 import org.eclipse.ui.dialogs.ResourceListSelectionDialog;
33
34 /**
35  * @author Axel
36  *
37  * TODO To change the template for this generated type comment go to
38  * Window - Preferences - Java - Code Style - Code Templates
39  */
40 public class XDebugMainTab  extends AbstractLaunchConfigurationTab {
41         
42         private Text fProgramText;
43         private Button fProgramButton;
44         
45         /* (non-Javadoc)
46          * @see org.eclipse.debug.ui.ILaunchConfigurationTab#createControl(org.eclipse.swt.widgets.Composite)
47          */
48         public void createControl(Composite parent) {
49                 Font font = parent.getFont();
50                 
51                 Composite comp = new Composite(parent, SWT.NONE);
52                 setControl(comp);
53                 GridLayout topLayout = new GridLayout();
54                 topLayout.verticalSpacing = 0;
55                 topLayout.numColumns = 3;
56                 comp.setLayout(topLayout);
57                 comp.setFont(font);
58                 
59                 createVerticalSpacer(comp, 3);
60                 
61                 Label programLabel = new Label(comp, SWT.NONE);
62                 programLabel.setText("&Program:");
63                 GridData gd = new GridData(GridData.BEGINNING);
64                 programLabel.setLayoutData(gd);
65                 programLabel.setFont(font);
66                 
67                 fProgramText = new Text(comp, SWT.SINGLE | SWT.BORDER);
68                 gd = new GridData(GridData.FILL_HORIZONTAL);
69                 fProgramText.setLayoutData(gd);
70                 fProgramText.setFont(font);
71                 fProgramText.addModifyListener(new ModifyListener() {
72                         public void modifyText(ModifyEvent e) {
73                                 updateLaunchConfigurationDialog();
74                         }
75                 });
76                 
77                 fProgramButton = createPushButton(comp, "&Browse...", null); //$NON-NLS-1$
78                 fProgramButton.addSelectionListener(new SelectionAdapter() {
79                         public void widgetSelected(SelectionEvent e) {
80                                 browsePDAFiles();
81                         }
82                 });
83         }
84         
85         /**
86          * Open a resource chooser to select a PDA program 
87          */
88         protected void browsePDAFiles() {
89                 ResourceListSelectionDialog dialog = new ResourceListSelectionDialog(getShell(), ResourcesPlugin.getWorkspace().getRoot(), IResource.FILE);
90                 dialog.setTitle("PDA Program");
91                 dialog.setMessage("Select PDA Program");
92                 // TODO: single select
93                 if (dialog.open() == Window.OK) {
94                         Object[] files = dialog.getResult();
95                         IFile file = (IFile) files[0];
96                         fProgramText.setText(file.getFullPath().toString());
97                 }
98                 
99         }
100         /* (non-Javadoc)
101          * @see org.eclipse.debug.ui.ILaunchConfigurationTab#setDefaults(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
102          */
103         public void setDefaults(ILaunchConfigurationWorkingCopy configuration) {
104         }
105         /* (non-Javadoc)
106          * @see org.eclipse.debug.ui.ILaunchConfigurationTab#initializeFrom(org.eclipse.debug.core.ILaunchConfiguration)
107          */
108         public void initializeFrom(ILaunchConfiguration configuration) {
109                 try {
110                         String program = configuration.getAttribute(IXDebugConstants.ATTR_XDEBUG_PROGRAM, (String)null);
111                         if (program != null) {
112                                 fProgramText.setText(program);
113                         }
114                 } catch (CoreException e) {
115                         setErrorMessage(e.getMessage());
116                 }
117         }
118         /* (non-Javadoc)
119          * @see org.eclipse.debug.ui.ILaunchConfigurationTab#performApply(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
120          */
121         public void performApply(ILaunchConfigurationWorkingCopy configuration) {
122                 String program = fProgramText.getText().trim();
123                 if (program.length() == 0) {
124                         program = null;
125                 }
126                 configuration.setAttribute(IXDebugConstants.ATTR_XDEBUG_PROGRAM, program);
127         }
128         /* (non-Javadoc)
129          * @see org.eclipse.debug.ui.ILaunchConfigurationTab#getName()
130          */
131         public String getName() {
132                 return "Main";
133         }
134         /* (non-Javadoc)
135          * @see org.eclipse.debug.ui.ILaunchConfigurationTab#isValid(org.eclipse.debug.core.ILaunchConfiguration)
136          */
137         public boolean isValid(ILaunchConfiguration launchConfig) {
138                 String text = fProgramText.getText();
139                 if (text.length() > 0) {
140                         IPath path = new Path(text);
141                         if (ResourcesPlugin.getWorkspace().getRoot().findMember(path) == null) {
142                                 setErrorMessage("Specified program does not exist");
143                                 return false;
144                         }
145                 } else {
146                         setMessage("Specify a program");
147                 }
148                 return super.isValid(launchConfig);
149         }
150 }