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