|
1 /* |
|
2 * Copyright (c) 2010 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 |
|
18 package com.nokia.cdt.internal.debug.launch.newwizard; |
|
19 |
|
20 import java.text.MessageFormat; |
|
21 import java.util.ArrayList; |
|
22 |
|
23 import org.eclipse.core.runtime.IStatus; |
|
24 import org.eclipse.core.runtime.Status; |
|
25 import org.eclipse.jface.layout.GridDataFactory; |
|
26 import org.eclipse.jface.layout.GridLayoutFactory; |
|
27 import org.eclipse.jface.wizard.WizardPage; |
|
28 import org.eclipse.swt.SWT; |
|
29 import org.eclipse.swt.widgets.Composite; |
|
30 |
|
31 import com.nokia.cdt.internal.debug.launch.LaunchPlugin; |
|
32 import com.nokia.cdt.internal.debug.launch.newwizard.IWizardSection.ISectionChangeListener; |
|
33 |
|
34 /** |
|
35 * This page presents three sections: |
|
36 * <p> |
|
37 * Connection to use: container for the Remote Connection selection UI, plus a label |
|
38 * explaining how to handle the case of no connections defined. |
|
39 * <p> |
|
40 * Debug process: section explaining how the launch will happen, with a combo |
|
41 * allowing selecting different process to launch, and a button allowing more |
|
42 * in-depth configuration. |
|
43 * <p> |
|
44 * Build before debug: section with the build-before-debug preference for this |
|
45 * launch configuration. |
|
46 */ |
|
47 public class UnifiedLaunchOptionsPage extends WizardPage implements ISectionChangeListener { |
|
48 |
|
49 private final LaunchOptionsData data; |
|
50 private ArrayList<IWizardSection> sections; |
|
51 |
|
52 |
|
53 /** |
|
54 * @param mmps |
|
55 * @param exes |
|
56 * @param defaultExecutable |
|
57 * @param project |
|
58 * @param configurationName |
|
59 */ |
|
60 public UnifiedLaunchOptionsPage(LaunchOptionsData data) { |
|
61 super("Configure Launch Settings"); |
|
62 |
|
63 setDescription("Configure the connection and process to launch."); |
|
64 |
|
65 this.data = data; |
|
66 this.sections = new ArrayList<IWizardSection>(); |
|
67 |
|
68 |
|
69 IWizardSection section; |
|
70 |
|
71 section = new ConnectToDeviceSection(data, this); |
|
72 sections.add(section); |
|
73 |
|
74 section = new DebugRunProcessSection(data); |
|
75 sections.add(section); |
|
76 |
|
77 section = new OtherSettingsSection(data); |
|
78 sections.add(section); |
|
79 } |
|
80 |
|
81 /* (non-Javadoc) |
|
82 * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite) |
|
83 */ |
|
84 public void createControl(Composite parent) { |
|
85 Composite composite = new Composite(parent, SWT.NONE); |
|
86 |
|
87 GridLayoutFactory.fillDefaults().applyTo(composite); |
|
88 |
|
89 setPageComplete(false); |
|
90 |
|
91 for (IWizardSection section : sections) { |
|
92 section.createControl(composite); |
|
93 section.setChangeListener(this); |
|
94 GridDataFactory.fillDefaults().grab(true, true).applyTo(section.getControl()); |
|
95 } |
|
96 |
|
97 |
|
98 setControl(composite); |
|
99 } |
|
100 |
|
101 /** |
|
102 * @return |
|
103 */ |
|
104 public void validatePage() { |
|
105 setMessage(null, INFORMATION); |
|
106 setErrorMessage(null); |
|
107 setPageComplete(true); |
|
108 |
|
109 IStatus pageStatus = null; |
|
110 |
|
111 // validate the subsections |
|
112 StringBuilder builder = new StringBuilder(); |
|
113 int severity = IStatus.OK; |
|
114 for (IWizardSection section : sections) { |
|
115 IStatus status = section.getStatus(); |
|
116 if (status.isOK()) |
|
117 continue; |
|
118 if (builder.length() > 0) |
|
119 builder.append("\n"); |
|
120 |
|
121 builder.append(MessageFormat.format("{0}: {1}", |
|
122 section.getSectionName(), |
|
123 status.getMessage())); |
|
124 severity = Math.max(severity, status.getSeverity()); |
|
125 } |
|
126 if (severity != 0 || builder.length() > 0) { |
|
127 // error from one or more sections |
|
128 pageStatus = new Status(severity, LaunchPlugin.PLUGIN_ID, builder.toString()); |
|
129 } else { |
|
130 // sections are good; validate the page as a whole |
|
131 pageStatus = data.validate(); |
|
132 } |
|
133 |
|
134 setTitle("Configure launch configuration"); |
|
135 |
|
136 if (pageStatus != null && !pageStatus.isOK()) { |
|
137 setMessage(pageStatus.getMessage(), severityToMsgType(pageStatus.getSeverity())); |
|
138 setPageComplete(false); |
|
139 } |
|
140 } |
|
141 |
|
142 private int severityToMsgType(int severity) { |
|
143 switch (severity) { |
|
144 case IStatus.OK: |
|
145 case IStatus.INFO: |
|
146 return INFORMATION; |
|
147 case IStatus.WARNING: |
|
148 return WARNING; |
|
149 case IStatus.ERROR: |
|
150 default: |
|
151 return ERROR; |
|
152 } |
|
153 } |
|
154 |
|
155 /* |
|
156 private String getSeverityTag(int severity) { |
|
157 if (severity == IStatus.OK || severity == IStatus.INFO || severity == IStatus.CANCEL) |
|
158 return ""; |
|
159 if (severity == IStatus.WARNING) |
|
160 return "warning"; |
|
161 return "error"; |
|
162 } |
|
163 */ |
|
164 |
|
165 public void initializeSettings() { |
|
166 for (IWizardSection section : sections) { |
|
167 section.initializeSettings(); |
|
168 } |
|
169 validatePage(); |
|
170 } |
|
171 |
|
172 /* (non-Javadoc) |
|
173 * @see com.nokia.cdt.internal.debug.launch.wizard2.IWizardSection.ISectionChangeListener#changed() |
|
174 */ |
|
175 public void changed() { |
|
176 validatePage(); |
|
177 } |
|
178 } |