|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 package com.nokia.cdt.internal.debug.launch.ui; |
|
18 |
|
19 import java.util.StringTokenizer; |
|
20 |
|
21 import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants; |
|
22 import org.eclipse.cdt.launch.internal.ui.LaunchMessages; |
|
23 import org.eclipse.cdt.launch.internal.ui.LaunchUIPlugin; |
|
24 import org.eclipse.core.resources.IResourceChangeEvent; |
|
25 import org.eclipse.core.resources.IResourceChangeListener; |
|
26 import org.eclipse.core.resources.ResourcesPlugin; |
|
27 import org.eclipse.core.runtime.CoreException; |
|
28 import org.eclipse.core.runtime.Path; |
|
29 import org.eclipse.debug.core.ILaunchConfiguration; |
|
30 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; |
|
31 import org.eclipse.swt.SWT; |
|
32 import org.eclipse.swt.events.ModifyEvent; |
|
33 import org.eclipse.swt.events.ModifyListener; |
|
34 import org.eclipse.swt.layout.GridData; |
|
35 import org.eclipse.swt.layout.GridLayout; |
|
36 import org.eclipse.swt.widgets.Composite; |
|
37 import org.eclipse.swt.widgets.Display; |
|
38 import org.eclipse.swt.widgets.Label; |
|
39 import org.eclipse.swt.widgets.Text; |
|
40 |
|
41 import com.freescale.cdt.debug.cw.core.RemoteConnectionsTRKHelper; |
|
42 import com.nokia.carbide.remoteconnections.RemoteConnectionsActivator; |
|
43 import com.nokia.carbide.remoteconnections.interfaces.IClientServiceSiteUI; |
|
44 import com.nokia.carbide.remoteconnections.interfaces.IConnection; |
|
45 import com.nokia.carbide.remoteconnections.interfaces.IClientServiceSiteUI.IListener; |
|
46 import com.nokia.cdt.internal.debug.launch.LaunchPlugin; |
|
47 |
|
48 import cwdbg.PreferenceConstants; |
|
49 |
|
50 public class RunModeMainTab extends CarbideMainTab implements IResourceChangeListener { |
|
51 |
|
52 public RunModeMainTab() { |
|
53 super(DONT_CHECK_PROGRAM); |
|
54 } |
|
55 |
|
56 public RunModeMainTab(boolean wantsConnectionUI) { |
|
57 super(DONT_CHECK_PROGRAM); |
|
58 this.wantsConnectionUI = wantsConnectionUI; |
|
59 } |
|
60 |
|
61 protected Label remoteLabel; |
|
62 protected Text remoteText; |
|
63 protected IConnection connection; |
|
64 protected boolean wantsConnectionUI = true; |
|
65 protected IClientServiceSiteUI clientSiteUI; |
|
66 |
|
67 public void createControl(Composite parent) { |
|
68 Composite comp = new Composite(parent, SWT.NONE); |
|
69 setControl(comp); |
|
70 |
|
71 LaunchUIPlugin.getDefault().getWorkbench().getHelpSystem().setHelp(getControl(), LaunchTabHelpIds.RUN_MODE_MAIN); |
|
72 |
|
73 GridLayout topLayout = new GridLayout(); |
|
74 comp.setLayout(topLayout); |
|
75 |
|
76 createVerticalSpacer(comp, 1); |
|
77 createProjectGroup(comp, 1); |
|
78 createRemoteAppGroup(comp, 1); |
|
79 |
|
80 fProjLabel.setToolTipText(Messages.getString("RunModeMainTab.8")); //$NON-NLS-1$ |
|
81 fProjText.setToolTipText(Messages.getString("RunModeMainTab.8")); //$NON-NLS-1$ |
|
82 |
|
83 if (wantsConnectionUI) |
|
84 { |
|
85 createVerticalSpacer(comp, 1); |
|
86 clientSiteUI = RemoteConnectionsActivator.getConnectionsManager().getClientSiteUI(LaunchPlugin.getTRKService()); |
|
87 clientSiteUI.createComposite(comp); |
|
88 clientSiteUI.addListener(new IListener() { |
|
89 public void connectionSelected() { |
|
90 connection = clientSiteUI.getSelectedConnection(); |
|
91 updateLaunchConfigurationDialog(); |
|
92 } |
|
93 }); |
|
94 } |
|
95 |
|
96 createVerticalSpacer(comp, 1); |
|
97 if (wantsTerminalOption() /*&& ProcessFactory.supportesTerminal()*/) { |
|
98 createTerminalOption(comp, 1); |
|
99 } |
|
100 LaunchUIPlugin.setDialogShell(parent.getShell()); |
|
101 |
|
102 ResourcesPlugin.getWorkspace().addResourceChangeListener(this, IResourceChangeEvent.POST_BUILD); |
|
103 } |
|
104 |
|
105 public void dispose() { |
|
106 ResourcesPlugin.getWorkspace().removeResourceChangeListener(this); |
|
107 super.dispose(); |
|
108 } |
|
109 |
|
110 protected void createRemoteAppGroup(Composite parent, int colSpan) { |
|
111 Composite projComp = new Composite(parent, SWT.NONE); |
|
112 GridLayout projLayout = new GridLayout(); |
|
113 projLayout.numColumns = 2; |
|
114 projLayout.marginHeight = 0; |
|
115 projLayout.marginWidth = 0; |
|
116 projComp.setLayout(projLayout); |
|
117 GridData gd = new GridData(GridData.FILL_HORIZONTAL); |
|
118 gd.horizontalSpan = colSpan; |
|
119 projComp.setLayoutData(gd); |
|
120 |
|
121 remoteLabel = new Label(projComp, SWT.NONE); |
|
122 remoteLabel.setText(Messages.getString("RunModeMainTab.2")); //$NON-NLS-1$ |
|
123 gd = new GridData(); |
|
124 gd.horizontalSpan = 2; |
|
125 remoteLabel.setLayoutData(gd); |
|
126 remoteLabel.setToolTipText(Messages.getString("RunModeMainTab.3")); //$NON-NLS-1$ |
|
127 |
|
128 remoteText = new Text(projComp, SWT.SINGLE | SWT.BORDER); |
|
129 gd = new GridData(GridData.FILL_HORIZONTAL); |
|
130 remoteText.setLayoutData(gd); |
|
131 remoteText.setToolTipText(Messages.getString("RunModeMainTab.3")); //$NON-NLS-1$ |
|
132 remoteText.addModifyListener(new ModifyListener() { |
|
133 |
|
134 public void modifyText(ModifyEvent evt) { |
|
135 updateLaunchConfigurationDialog(); |
|
136 } |
|
137 }); |
|
138 |
|
139 } |
|
140 |
|
141 public void setDefaults(ILaunchConfigurationWorkingCopy config) { |
|
142 } |
|
143 |
|
144 public void initializeFrom(ILaunchConfiguration config) { |
|
145 super.initializeFrom(config); |
|
146 try { |
|
147 remoteText.setText(config.getAttribute(PreferenceConstants.J_PN_RemoteProcessToLaunch, "")); //$NON-NLS-1$ |
|
148 } catch (CoreException e) { |
|
149 setErrorMessage(LaunchMessages.getFormattedString("Launch.common.Exception_occurred_reading_configuration_EXCEPTION", e.getStatus().getMessage())); //$NON-NLS-1$ |
|
150 LaunchUIPlugin.log(e); |
|
151 } |
|
152 try { |
|
153 if (!RemoteConnectionsTRKHelper.configUsesConnectionAttribute(config)) { |
|
154 config = RemoteConnectionsTRKHelper.attemptUpdateLaunchConfiguration(config.getWorkingCopy()); |
|
155 } |
|
156 connection = RemoteConnectionsTRKHelper.getConnectionFromConfig(config); |
|
157 } catch (CoreException e) { |
|
158 } |
|
159 if (clientSiteUI != null) |
|
160 { |
|
161 if (connection != null) |
|
162 clientSiteUI.selectConnection(connection); |
|
163 else { |
|
164 connection = clientSiteUI.getSelectedConnection(); |
|
165 } |
|
166 } |
|
167 } |
|
168 |
|
169 public void performApply(ILaunchConfigurationWorkingCopy config) { |
|
170 super.performApply(config); |
|
171 config.setAttribute(PreferenceConstants.J_PN_RemoteProcessToLaunch, remoteText.getText()); |
|
172 if (connection != null) { |
|
173 config.setAttribute(RemoteConnectionsTRKHelper.CONNECTION_ATTRIBUTE, connection.getIdentifier()); |
|
174 } |
|
175 // Now check if the process to launch is the main target exe |
|
176 // for debugging. If not, try to set process to launch as the |
|
177 // main target if its in the list of target executables |
|
178 if (isRemoteTextValid(remoteText.getText()) == null) { |
|
179 try { |
|
180 Path processToLaunch = new Path(remoteText.getText()); |
|
181 Path mainExePath = new Path(config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME, "")); |
|
182 if (!processToLaunch.lastSegment().equalsIgnoreCase(mainExePath.lastSegment())) { |
|
183 // passing null as the monitor should be ok as its not really being used. |
|
184 String executablesToTarget = ExecutablesTab.getExecutablesToTarget(config, null); |
|
185 if (executablesToTarget != null && executablesToTarget.length() > 0) { |
|
186 StringTokenizer tokenizer = new StringTokenizer(executablesToTarget, ","); //$NON-NLS-1$ |
|
187 while (tokenizer.hasMoreTokens()) { |
|
188 String exe = tokenizer.nextToken(); |
|
189 String enabled = tokenizer.nextToken(); |
|
190 |
|
191 Path exePath = new Path(exe); |
|
192 if (enabled.compareTo("1") == 0 //$NON-NLS-1$ |
|
193 && exePath.lastSegment().equalsIgnoreCase(processToLaunch.lastSegment())) { |
|
194 config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME, exePath.toOSString()); |
|
195 break; |
|
196 } |
|
197 } |
|
198 } |
|
199 } |
|
200 } catch(CoreException ce) { |
|
201 ce.printStackTrace(); |
|
202 } |
|
203 } |
|
204 } |
|
205 |
|
206 public static String isRemoteTextValid(String remoteText) { |
|
207 String remoteProcess = remoteText.trim(); |
|
208 if (remoteProcess.length() < 1) { |
|
209 return Messages.getString("RunModeMainTab.6"); //$NON-NLS-1$ |
|
210 } else { |
|
211 char drive = remoteProcess.charAt(0); |
|
212 char colon = remoteProcess.length() < 2 ? 0x0 : remoteProcess.charAt(1); |
|
213 char root = remoteProcess.length() < 3 ? 0x0 : remoteProcess.charAt(2); |
|
214 char lastChar = remoteProcess.charAt(remoteProcess.length() - 1); |
|
215 if (!Character.isLetter(drive) || colon != ':' || root != '\\' || |
|
216 lastChar == '\\' || lastChar == '/' || lastChar == ':') { |
|
217 return Messages.getString("RunModeMainTab.7"); //$NON-NLS-1$ |
|
218 } |
|
219 } |
|
220 |
|
221 return null; |
|
222 } |
|
223 |
|
224 /* |
|
225 * (non-Javadoc) |
|
226 * |
|
227 * @see org.eclipse.debug.ui.ILaunchConfigurationTab#isValid(org.eclipse.debug.core.ILaunchConfiguration) |
|
228 */ |
|
229 public boolean isValid(ILaunchConfiguration config) { |
|
230 boolean result = super.isValid(config); |
|
231 if (result){ |
|
232 String error = isRemoteTextValid(remoteText.getText()); |
|
233 if (error != null) { |
|
234 setErrorMessage(error); |
|
235 result = false; |
|
236 } |
|
237 else { |
|
238 if (clientSiteUI != null) |
|
239 { |
|
240 connection = clientSiteUI.getSelectedConnection(); |
|
241 if (connection == null) { |
|
242 setErrorMessage(Messages.getString("RunModeMainTab.NoConnectionError")); //$NON-NLS-1$ |
|
243 result = false; |
|
244 } |
|
245 } |
|
246 } |
|
247 } |
|
248 |
|
249 return result; |
|
250 } |
|
251 |
|
252 public void resourceChanged(IResourceChangeEvent event) { |
|
253 if (event.getType() == IResourceChangeEvent.POST_BUILD) { |
|
254 |
|
255 final RunModeMainTab tab = this; |
|
256 Display.getDefault().asyncExec(new Runnable() { |
|
257 |
|
258 public void run() { |
|
259 tab.getLaunchConfigurationDialog().updateButtons(); |
|
260 tab.getLaunchConfigurationDialog().updateMessage(); |
|
261 } |
|
262 }); |
|
263 } |
|
264 } |
|
265 |
|
266 } |