1414import org .eclipse .core .runtime .IStatus ;
1515import org .eclipse .core .runtime .Status ;
1616import org .eclipse .core .runtime .jobs .Job ;
17+ import org .eclipse .debug .core .DebugPlugin ;
18+ import org .eclipse .debug .core .ILaunchConfigurationType ;
1719import org .eclipse .jface .dialogs .IDialogSettings ;
20+ import org .eclipse .jface .dialogs .PageChangingEvent ;
1821import org .eclipse .jface .viewers .ISelectionProvider ;
1922import org .eclipse .jface .viewers .StructuredSelection ;
23+ import org .eclipse .jface .wizard .WizardDialog ;
2024import org .eclipse .launchbar .core .ILaunchBarManager ;
25+ import org .eclipse .launchbar .core .ILaunchDescriptor ;
2126import org .eclipse .launchbar .core .target .ILaunchTarget ;
2227import org .eclipse .launchbar .core .target .ILaunchTargetManager ;
28+ import org .eclipse .launchbar .ui .NewLaunchConfigWizard ;
29+ import org .eclipse .launchbar .ui .NewLaunchConfigWizardDialog ;
30+ import org .eclipse .launchbar .ui .internal .dialogs .NewLaunchConfigEditPage ;
2331import org .eclipse .swt .events .DisposeEvent ;
2432import org .eclipse .swt .events .DisposeListener ;
2533import org .eclipse .swt .widgets .Display ;
34+ import org .eclipse .swt .widgets .Shell ;
2635import org .eclipse .tools .templates .core .IGenerator ;
2736import org .eclipse .tools .templates .ui .TemplateWizard ;
2837import org .eclipse .ui .IViewPart ;
4857@ SuppressWarnings ("restriction" )
4958public class NewIDFProjectWizard extends TemplateWizard
5059{
60+ private static final String NEW_LAUNCH_CONFIG_EDIT_PAGE = "NewLaunchConfigEditPage" ; //$NON-NLS-1$
5161 public static final String TARGET_SWITCH_JOB = "TARGET SWITCH JOB" ; //$NON-NLS-1$
5262 private NewProjectCreationWizardPage projectCreationWizardPage ;
5363
@@ -72,16 +82,17 @@ public void addPages()
7282 super .addPages ();
7383
7484 this .setWindowTitle (Messages .NewIDFProjectWizard_NewIDFProject );
75-
85+
7686 TemplatesManager templatesManager = new TemplatesManager ();
7787 ITemplateNode templateRoot = templatesManager .getTemplates ();
78- projectCreationWizardPage = new NewProjectCreationWizardPage (templateRoot , Messages .NewIDFProjectWizard_TemplatesHeader );
88+ projectCreationWizardPage = new NewProjectCreationWizardPage (templateRoot ,
89+ Messages .NewIDFProjectWizard_TemplatesHeader );
7990 ITemplateNode templateNode = templatesManager .getTemplateNode (IDFConstants .DEFAULT_TEMPLATE_ID );
8091 if (templateNode != null )
8192 {
8293 projectCreationWizardPage .setInitialTemplateId (templateNode );
8394 }
84-
95+
8596 this .addPage (projectCreationWizardPage );
8697 }
8798
@@ -101,19 +112,61 @@ public boolean performFinish()
101112 selProvider .setSelection (new StructuredSelection (project ));
102113 }
103114 }
115+
104116 final String target = projectCreationWizardPage .getSelectedTarget ();
105117 this .getShell ().addDisposeListener (new DisposeListener ()
106118 {
107119 @ Override
108- public void widgetDisposed (DisposeEvent e )
120+ public void widgetDisposed (DisposeEvent event )
109121 {
122+ ILaunchBarManager launchBarManager = UIPlugin .getService (ILaunchBarManager .class );
110123 TargetSwitchJob targetSwtichJob = new TargetSwitchJob (target );
111124 targetSwtichJob .schedule ();
125+ try
126+ {
127+ ILaunchDescriptor desc = launchBarManager .getActiveLaunchDescriptor ();
128+ createDefaultDebugConfig ();
129+ launchBarManager .setActiveLaunchDescriptor (desc );
130+ }
131+ catch (CoreException e )
132+ {
133+ Logger .log (e );
134+ }
135+
112136 }
113137 });
114138 return performFinish ;
115139 }
116-
140+
141+ private void createDefaultDebugConfig ()
142+ {
143+ Shell activeShell = Display .getDefault ().getActiveShell ();
144+
145+ NewLaunchConfigWizard wizard = new NewLaunchConfigWizard ();
146+ WizardDialog dialog = new NewLaunchConfigWizardDialog (activeShell , wizard );
147+ dialog .create ();
148+
149+ NewLaunchConfigEditPage editPage = (NewLaunchConfigEditPage ) wizard .getPage (NEW_LAUNCH_CONFIG_EDIT_PAGE );
150+ ILaunchConfigurationType debugLaunchConfigType = DebugPlugin .getDefault ().getLaunchManager ()
151+ .getLaunchConfigurationType (IDFLaunchConstants .DEBUG_LAUNCH_CONFIG_TYPE );
152+ editPage .setLaunchConfigType (debugLaunchConfigType );
153+
154+ PageChangingEvent pageChangingEvent = new PageChangingEvent (wizard , wizard .getStartingPage (), editPage );
155+ editPage .handlePageChanging (pageChangingEvent );
156+
157+ wizard .performFinish ();
158+
159+ try
160+ {
161+ wizard .getWorkingCopy ().doSave ();
162+ }
163+ catch (CoreException e )
164+ {
165+ Logger .log (e );
166+ }
167+ wizard .dispose ();
168+ }
169+
117170 @ Override
118171 protected IGenerator getGenerator ()
119172 {
@@ -126,7 +179,8 @@ protected IGenerator getGenerator()
126179 manifest = null ;
127180 }
128181
129- IDFProjectGenerator generator = new IDFProjectGenerator (manifest , selectedTemplate , true , projectCreationWizardPage .getSelectedTarget ());
182+ IDFProjectGenerator generator = new IDFProjectGenerator (manifest , selectedTemplate , true ,
183+ projectCreationWizardPage .getSelectedTarget ());
130184 generator .setProjectName (projectCreationWizardPage .getProjectName ());
131185 if (!projectCreationWizardPage .useDefaults ())
132186 {
@@ -135,19 +189,18 @@ protected IGenerator getGenerator()
135189 return generator ;
136190 }
137191
138-
139192 private class TargetSwitchJob extends Job
140193 {
141194 private ILaunchBarManager launchBarManager ;
142195 private String target ;
196+
143197 public TargetSwitchJob (String target )
144198 {
145199 super (TARGET_SWITCH_JOB );
146200 this .target = target ;
147201 launchBarManager = UIPlugin .getService (ILaunchBarManager .class );
148202 }
149203
150-
151204 private Job findInternalJob ()
152205 {
153206 for (Job job : Job .getJobManager ().find (null ))
@@ -157,10 +210,9 @@ private Job findInternalJob()
157210 return job ;
158211 }
159212 }
160-
213+
161214 return null ;
162215 }
163-
164216
165217 @ Override
166218 protected IStatus run (IProgressMonitor monitor )
@@ -177,7 +229,7 @@ protected IStatus run(IProgressMonitor monitor)
177229 Logger .log (e1 );
178230 }
179231 }
180-
232+
181233 Display .getDefault ().syncExec (() -> {
182234 ILaunchTarget launchTarget = findSuitableTargetForSelectedTargetString ();
183235 try
@@ -187,13 +239,13 @@ protected IStatus run(IProgressMonitor monitor)
187239 catch (CoreException e )
188240 {
189241 Logger .log (e );
190- }
242+ }
191243 });
192-
244+
193245 return Status .OK_STATUS ;
194-
246+
195247 }
196-
248+
197249 private ILaunchTarget findSuitableTargetForSelectedTargetString ()
198250 {
199251 ILaunchTargetManager launchTargetManager = UIPlugin .getService (ILaunchTargetManager .class );
@@ -202,14 +254,13 @@ private ILaunchTarget findSuitableTargetForSelectedTargetString()
202254
203255 for (ILaunchTarget iLaunchTarget : targets )
204256 {
205- String idfTarget = iLaunchTarget .getAttribute (IDFLaunchConstants .ATTR_IDF_TARGET ,
206- null );
257+ String idfTarget = iLaunchTarget .getAttribute (IDFLaunchConstants .ATTR_IDF_TARGET , null );
207258 if (idfTarget .contentEquals (target ))
208259 {
209260 return iLaunchTarget ;
210261 }
211262 }
212-
263+
213264 return null ;
214265 }
215266 }
0 commit comments