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