author | dadubrow |
Thu, 18 Feb 2010 09:07:17 -0600 | |
changeset 983 | 8b4ee73c530c |
parent 969 | b0dd389735fb |
child 1011 | ac82c32cc589 |
permissions | -rw-r--r-- |
956 | 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 |
||
22 |
import org.eclipse.core.runtime.CoreException; |
|
23 |
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; |
|
24 |
import org.eclipse.jface.dialogs.Dialog; |
|
25 |
import org.eclipse.jface.dialogs.IDialogConstants; |
|
26 |
import org.eclipse.jface.dialogs.IPageChangedListener; |
|
27 |
import org.eclipse.jface.dialogs.PageChangedEvent; |
|
28 |
import org.eclipse.jface.layout.GridDataFactory; |
|
29 |
import org.eclipse.jface.wizard.IWizardContainer; |
|
30 |
import org.eclipse.jface.wizard.Wizard; |
|
31 |
import org.eclipse.jface.wizard.WizardDialog; |
|
32 |
import org.eclipse.swt.SWT; |
|
33 |
import org.eclipse.swt.events.SelectionAdapter; |
|
34 |
import org.eclipse.swt.events.SelectionEvent; |
|
35 |
import org.eclipse.swt.layout.GridLayout; |
|
36 |
import org.eclipse.swt.widgets.Button; |
|
37 |
import org.eclipse.swt.widgets.Composite; |
|
38 |
import org.eclipse.swt.widgets.Control; |
|
39 |
import org.eclipse.swt.widgets.Shell; |
|
40 |
||
983
8b4ee73c530c
New launch wizard UI tweaks based on demo feedback
dadubrow
parents:
969
diff
changeset
|
41 |
import com.nokia.carbide.cpp.ui.CarbideUIPlugin; |
8b4ee73c530c
New launch wizard UI tweaks based on demo feedback
dadubrow
parents:
969
diff
changeset
|
42 |
import com.nokia.carbide.cpp.ui.ICarbideSharedImages; |
956 | 43 |
import com.nokia.carbide.remoteconnections.interfaces.IService; |
44 |
import com.nokia.cdt.internal.debug.launch.LaunchPlugin; |
|
45 |
import com.nokia.cdt.internal.debug.launch.wizard.ILaunchCreationWizard; |
|
46 |
import com.nokia.cdt.internal.debug.launch.wizard.LaunchOptions; |
|
47 |
||
48 |
/** |
|
49 |
* New launch wizard for Carbide 3.0. |
|
50 |
* |
|
51 |
* See https://xdabug001.ext.nokia.com/bugzilla/show_bug.cgi?id=10419 |
|
52 |
*/ |
|
53 |
public class LaunchWizard extends Wizard implements ILaunchCreationWizard { |
|
54 |
||
55 |
private LaunchWizardData launchData; |
|
56 |
private UnifiedLaunchOptionsPage mainPage; |
|
57 |
private Button advancedButton; |
|
58 |
private boolean advancedEdit; |
|
59 |
private IPageChangedListener pageChangedListener; |
|
60 |
private boolean hasFinished; |
|
61 |
||
62 |
public LaunchWizard(LaunchOptions launchOptions, IService trkService) { |
|
63 |
launchData = new LaunchWizardData(launchOptions, trkService); |
|
64 |
mainPage = new UnifiedLaunchOptionsPage(launchData); |
|
65 |
mainPage.initializeSettings(); |
|
969 | 66 |
setWindowTitle(Messages.getString("LaunchWizard.Title")); //$NON-NLS-1$ |
956 | 67 |
} |
68 |
||
69 |
/* (non-Javadoc) |
|
70 |
* @see org.eclipse.jface.wizard.Wizard#addPages() |
|
71 |
*/ |
|
72 |
@Override |
|
73 |
public void addPages() { |
|
74 |
addPage(mainPage); |
|
75 |
} |
|
76 |
||
77 |
/* (non-Javadoc) |
|
78 |
* @see org.eclipse.jface.wizard.Wizard#setContainer(org.eclipse.jface.wizard.IWizardContainer) |
|
79 |
*/ |
|
80 |
@Override |
|
81 |
public void setContainer(final IWizardContainer wizardContainer) { |
|
82 |
super.setContainer(wizardContainer); |
|
83 |
||
84 |
// Thanks, JFace, for making it so hard to know when the UI is ready |
|
85 |
if (wizardContainer instanceof WizardDialog && advancedButton == null) { |
|
86 |
pageChangedListener = new IPageChangedListener() { |
|
87 |
||
88 |
public void pageChanged(PageChangedEvent event) { |
|
89 |
addAdvancedButton(); |
|
90 |
((WizardDialog)getContainer()).removePageChangedListener(pageChangedListener); |
|
91 |
} |
|
92 |
}; |
|
93 |
((WizardDialog)wizardContainer).addPageChangedListener(pageChangedListener); |
|
94 |
} |
|
95 |
} |
|
96 |
||
97 |
protected void addAdvancedButton() { |
|
98 |
if (advancedButton == null) { |
|
99 |
Composite parent = (Composite) ((Dialog) getContainer()).buttonBar; |
|
100 |
if (parent != null) { |
|
101 |
||
102 |
advancedButton = new Button(parent, SWT.CHECK); |
|
983
8b4ee73c530c
New launch wizard UI tweaks based on demo feedback
dadubrow
parents:
969
diff
changeset
|
103 |
GridDataFactory.swtDefaults().align(SWT.LEFT, SWT.CENTER).indent(6, 0).applyTo(advancedButton); |
956 | 104 |
((GridLayout) parent.getLayout()).numColumns++; |
105 |
advancedButton.moveBelow(parent.getChildren()[0]); |
|
106 |
||
969 | 107 |
advancedButton.setText(Messages.getString("LaunchWizard.AdvancedLabel")); //$NON-NLS-1$ |
956 | 108 |
advancedButton.setToolTipText(MessageFormat.format( |
969 | 109 |
Messages.getString("LaunchWizard.AdvancedTip"), //$NON-NLS-1$ |
956 | 110 |
launchData.getModeLabel())); |
111 |
advancedButton.addSelectionListener(new SelectionAdapter() { |
|
112 |
@Override |
|
113 |
public void widgetSelected(SelectionEvent e) { |
|
114 |
updateDebugEditButton(); |
|
115 |
} |
|
116 |
}); |
|
117 |
} |
|
118 |
||
119 |
// Thanks, JFace, for deleting validation messages on the first display |
|
120 |
mainPage.validatePage(); |
|
121 |
} |
|
122 |
} |
|
123 |
||
124 |
@Override |
|
125 |
public boolean canFinish() { |
|
126 |
if (advancedEdit) |
|
127 |
return true; |
|
128 |
return super.canFinish(); |
|
129 |
} |
|
130 |
||
131 |
protected void updateDebugEditButton() { |
|
132 |
Button finishButton = findFinishButton(); |
|
133 |
if (finishButton != null) { |
|
134 |
advancedEdit = advancedButton.getSelection(); |
|
135 |
if (advancedEdit) { |
|
969 | 136 |
finishButton.setText(Messages.getString("LaunchWizard.EditLabel")); //$NON-NLS-1$ |
137 |
finishButton.setToolTipText(Messages.getString("LaunchWizard.EditTip")); //$NON-NLS-1$ |
|
956 | 138 |
getContainer().updateButtons(); |
139 |
} else { |
|
140 |
finishButton.setText(launchData.getModeLabel()); |
|
969 | 141 |
finishButton.setToolTipText(Messages.getString("LaunchWizard.FinishTip")); //$NON-NLS-1$ |
956 | 142 |
getContainer().updateButtons(); |
143 |
} |
|
144 |
} |
|
145 |
} |
|
146 |
||
147 |
/** |
|
148 |
* Thanks, SWT and JFace, for making this so difficult |
|
149 |
* @return the Finish button |
|
150 |
*/ |
|
151 |
private Button findFinishButton() { |
|
152 |
if (getContainer() instanceof Dialog) { |
|
153 |
return findFinishButton((Composite) ((Dialog) getContainer()).buttonBar); |
|
154 |
} |
|
155 |
return null; |
|
156 |
} |
|
157 |
||
158 |
/** |
|
159 |
* @param buttonBar |
|
160 |
* @return |
|
161 |
*/ |
|
162 |
private Button findFinishButton(Composite parent) { |
|
163 |
for (Control kid : parent.getChildren()) { |
|
164 |
if (kid instanceof Button) { |
|
165 |
if (kid.getData() instanceof Integer && (Integer) kid.getData() == IDialogConstants.FINISH_ID) { |
|
166 |
return (Button) kid; |
|
167 |
} |
|
168 |
} |
|
169 |
else if (kid instanceof Composite) { |
|
170 |
Button button = findFinishButton((Composite) kid); |
|
171 |
if (button != null) |
|
172 |
return button; |
|
173 |
} |
|
174 |
} |
|
175 |
return null; |
|
176 |
} |
|
177 |
||
178 |
@Override |
|
179 |
public boolean performFinish() { |
|
180 |
hasFinished = true; |
|
181 |
return true; |
|
182 |
} |
|
183 |
||
184 |
public boolean shouldOpenLaunchConfigurationDialog() { |
|
185 |
return hasFinished && advancedEdit; |
|
186 |
} |
|
187 |
||
188 |
public ILaunchConfigurationWorkingCopy getLaunchConfiguration() { |
|
189 |
if (!hasFinished) |
|
190 |
return null; |
|
191 |
||
192 |
ILaunchConfigurationWorkingCopy config = null; |
|
193 |
try { |
|
194 |
config = launchData.createConfiguration(); |
|
195 |
} catch (CoreException e) { |
|
196 |
LaunchPlugin.log(e); |
|
197 |
} |
|
198 |
||
199 |
return config; |
|
200 |
} |
|
201 |
||
202 |
public void init() { |
|
983
8b4ee73c530c
New launch wizard UI tweaks based on demo feedback
dadubrow
parents:
969
diff
changeset
|
203 |
setDefaultPageImageDescriptor(CarbideUIPlugin.getSharedImages().getImageDescriptor(ICarbideSharedImages.IMG_NEW_LAUNCH_CONFIG_WIZARD_BANNER)); |
956 | 204 |
} |
205 |
||
206 |
public int openWizard(Shell shell) { |
|
207 |
WizardDialog dialog = new WizardDialog(shell, this); |
|
208 |
return dialog.open(); |
|
209 |
} |
|
210 |
} |