16 */ |
16 */ |
17 |
17 |
18 package com.nokia.cdt.internal.debug.launch.newwizard; |
18 package com.nokia.cdt.internal.debug.launch.newwizard; |
19 |
19 |
20 import java.io.File; |
20 import java.io.File; |
21 import java.text.MessageFormat; |
|
22 import java.util.ArrayList; |
|
23 |
21 |
24 import org.eclipse.core.runtime.IStatus; |
22 import org.eclipse.core.runtime.IStatus; |
25 import org.eclipse.core.runtime.Status; |
23 import org.eclipse.core.runtime.Status; |
26 import org.eclipse.jface.layout.GridDataFactory; |
|
27 import org.eclipse.jface.layout.GridLayoutFactory; |
|
28 import org.eclipse.jface.wizard.WizardPage; |
|
29 import org.eclipse.swt.SWT; |
|
30 import org.eclipse.swt.widgets.Composite; |
|
31 import org.eclipse.swt.widgets.Control; |
|
32 |
24 |
33 import com.nokia.cdt.internal.debug.launch.LaunchPlugin; |
25 import com.nokia.cdt.internal.debug.launch.LaunchPlugin; |
34 import com.nokia.cdt.internal.debug.launch.newwizard.IWizardSection.ISectionChangeListener; |
|
35 import com.nokia.cdt.internal.debug.launch.newwizard.LaunchWizardData.EExeSelection; |
26 import com.nokia.cdt.internal.debug.launch.newwizard.LaunchWizardData.EExeSelection; |
36 import com.nokia.cpp.internal.api.utils.ui.WorkbenchUtils; |
|
37 |
27 |
38 /** |
28 /** |
39 * This page presents three sections: |
29 * This page presents three sections: |
40 * <p> |
30 * <p> |
41 * Connection to use: container for the Remote Connection selection UI, plus a label |
31 * Connection to use: container for the Remote Connection selection UI, plus a label |
49 * launch configuration. |
39 * launch configuration. |
50 * <p> |
40 * <p> |
51 * Each section is validated separately and editable with its own dialog. Changes in |
41 * Each section is validated separately and editable with its own dialog. Changes in |
52 * the dialog are not applied until the dialog is accepted. |
42 * the dialog are not applied until the dialog is accepted. |
53 */ |
43 */ |
54 public class UnifiedLaunchOptionsPage extends WizardPage implements ISectionChangeListener { |
44 public class UnifiedLaunchOptionsPage extends AbstractUnifiedLaunchOptionsPage { |
55 |
45 |
56 private final LaunchWizardData data; |
|
57 private ArrayList<IWizardSection> sections; |
|
58 |
|
59 |
|
60 /** |
|
61 * @param mmps |
|
62 * @param exes |
|
63 * @param defaultExecutable |
|
64 * @param project |
|
65 * @param configurationName |
|
66 */ |
|
67 public UnifiedLaunchOptionsPage(LaunchWizardData data) { |
46 public UnifiedLaunchOptionsPage(LaunchWizardData data) { |
68 super(Messages.getString("UnifiedLaunchOptionsPage.Title")); //$NON-NLS-1$ |
47 super(Messages.getString("UnifiedLaunchOptionsPage.Title"), data); //$NON-NLS-1$ |
69 |
|
70 setDescription(Messages.getString("UnifiedLaunchOptionsPage.Desc")); //$NON-NLS-1$ |
48 setDescription(Messages.getString("UnifiedLaunchOptionsPage.Desc")); //$NON-NLS-1$ |
71 |
49 |
72 this.data = data; |
50 addSection(new ConnectToDeviceSection(data, this)); |
73 this.sections = new ArrayList<IWizardSection>(); |
51 addSection(new DebugRunProcessSection(data, this)); |
74 |
52 addSection(new OtherSettingsSection(data, this)); |
75 |
|
76 IWizardSection section; |
|
77 |
|
78 section = new ConnectToDeviceSection(data, this); |
|
79 sections.add(section); |
|
80 |
|
81 section = new DebugRunProcessSection(data, this); |
|
82 sections.add(section); |
|
83 |
|
84 section = new OtherSettingsSection(data, this); |
|
85 sections.add(section); |
|
86 } |
|
87 |
|
88 /* (non-Javadoc) |
|
89 * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite) |
|
90 */ |
|
91 public void createControl(Composite parent) { |
|
92 Composite composite = new Composite(parent, SWT.NONE); |
|
93 |
|
94 GridLayoutFactory.fillDefaults().applyTo(composite); |
|
95 |
|
96 setPageComplete(false); |
|
97 |
|
98 for (IWizardSection section : sections) { |
|
99 section.createControl(composite); |
|
100 section.setChangeListener(this); |
|
101 GridDataFactory.fillDefaults().grab(true, true).applyTo(section.getControl()); |
|
102 } |
|
103 |
|
104 WorkbenchUtils.setHelpContextId(composite, LaunchWizardHelpIds.WIZARD_DIALOG_LAUNCH_OPTIONS_PAGE); |
|
105 |
|
106 setControl(composite); |
|
107 } |
|
108 |
|
109 /** |
|
110 * @return |
|
111 */ |
|
112 public void validatePage() { |
|
113 setMessage(null, INFORMATION); |
|
114 setErrorMessage(null); |
|
115 setPageComplete(true); |
|
116 |
|
117 IStatus pageStatus = null; |
|
118 |
|
119 // validate the subsections |
|
120 StringBuilder builder = new StringBuilder(); |
|
121 int severity = IStatus.OK; |
|
122 for (IWizardSection section : sections) { |
|
123 IStatus status = section.getStatus(); |
|
124 if (status.isOK()) |
|
125 continue; |
|
126 if (builder.length() > 0) |
|
127 builder.append("\n"); //$NON-NLS-1$ |
|
128 |
|
129 builder.append(MessageFormat.format("{0}: {1}", //$NON-NLS-1$ |
|
130 section.getSectionName(), |
|
131 status.getMessage())); |
|
132 severity = Math.max(severity, status.getSeverity()); |
|
133 } |
|
134 if (severity == IStatus.OK) { |
|
135 IStatus status = getStatus(); |
|
136 if (!status.isOK()) { |
|
137 builder.append(status.getMessage()); |
|
138 severity = status.getSeverity(); |
|
139 } |
|
140 } |
|
141 if (severity != 0 || builder.length() > 0) { |
|
142 // error from one or more sections |
|
143 pageStatus = new Status(severity, LaunchPlugin.PLUGIN_ID, builder.toString()); |
|
144 } else { |
|
145 // sections are good; validate the page as a whole |
|
146 pageStatus = data.validate(); |
|
147 } |
|
148 |
|
149 setTitle(Messages.getString("UnifiedLaunchOptionsPage.TitleText")); //$NON-NLS-1$ |
|
150 |
|
151 if (pageStatus != null && !pageStatus.isOK()) { |
|
152 setMessage(pageStatus.getMessage(), severityToMsgType(pageStatus.getSeverity())); |
|
153 setPageComplete(pageStatus.getSeverity() < IStatus.ERROR); |
|
154 } |
|
155 } |
|
156 |
|
157 private int severityToMsgType(int severity) { |
|
158 switch (severity) { |
|
159 case IStatus.OK: |
|
160 case IStatus.INFO: |
|
161 return INFORMATION; |
|
162 case IStatus.WARNING: |
|
163 return WARNING; |
|
164 case IStatus.ERROR: |
|
165 default: |
|
166 return ERROR; |
|
167 } |
|
168 } |
53 } |
169 |
54 |
170 protected IStatus getStatus() { |
55 protected IStatus getStatus() { |
171 return checkBuildProducts(); |
56 return checkBuildProducts(); |
172 } |
57 } |
183 // check launch file |
68 // check launch file |
184 if (data.getExeSelection().equals(EExeSelection.USE_PROJECT_EXECUTABLE) && |
69 if (data.getExeSelection().equals(EExeSelection.USE_PROJECT_EXECUTABLE) && |
185 !data.getExePath().toFile().exists()) { |
70 !data.getExePath().toFile().exists()) { |
186 return new Status(IStatus.WARNING, LaunchPlugin.PLUGIN_ID, |
71 return new Status(IStatus.WARNING, LaunchPlugin.PLUGIN_ID, |
187 Messages.getString("UnifiedLaunchOptionsPage.ExeFileMissingWarning")); //$NON-NLS-1$ |
72 Messages.getString("UnifiedLaunchOptionsPage.ExeFileMissingWarning")); //$NON-NLS-1$ |
188 |
|
189 } |
73 } |
190 } |
74 } |
191 |
75 |
192 return Status.OK_STATUS; |
76 return Status.OK_STATUS; |
193 } |
77 } |
194 |
|
195 public void initializeSettings() { |
|
196 for (IWizardSection section : sections) { |
|
197 section.initializeSettings(); |
|
198 } |
|
199 validatePage(); |
|
200 } |
|
201 |
|
202 /* (non-Javadoc) |
|
203 * @see com.nokia.cdt.internal.debug.launch.wizard2.IWizardSection.ISectionChangeListener#changed() |
|
204 */ |
|
205 public void changed() { |
|
206 validatePage(); |
|
207 Control control = getControl(); |
|
208 if (control != null && !control.isDisposed()) |
|
209 getWizard().getContainer().getShell().pack(); |
|
210 |
|
211 } |
|
212 } |
78 } |