11/*******************************************************************************
2- * Copyright (c) 2007, 2025 IBM Corporation and others.
2+ * Copyright (c) 2007, 2026 IBM Corporation and others.
33 *
44 * This program and the accompanying materials
55 * are made available under the terms of the Eclipse Public License 2.0
3838import org .eclipse .jface .viewers .IStructuredSelection ;
3939import org .eclipse .jface .viewers .StructuredSelection ;
4040import org .eclipse .jface .window .Window ;
41+ import org .eclipse .osgi .util .NLS ;
42+ import org .eclipse .swt .graphics .Image ;
43+ import org .eclipse .swt .widgets .Shell ;
4144import org .eclipse .ui .IEditorPart ;
4245
4346/**
@@ -153,7 +156,9 @@ else if(esize > 1) {
153156 else if (esize < 1 ) {
154157 if (DebugUIPlugin .getDefault ().getPreferenceStore ().getBoolean (IInternalDebugUIConstants .PREF_LAUNCH_LAST_IF_NOT_LAUNCHABLE )) {
155158 if (!launchLast (group , isShift )) {
156- MessageDialog .openInformation (DebugUIPlugin .getShell (), ContextMessages .ContextRunner_0 , ContextMessages .ContextRunner_7 );
159+ openNoRecentLaunchDialog (DebugUIPlugin .getShell (), ContextMessages .ContextRunner_7 , mode ,
160+ group .getIdentifier ());
161+
157162 }
158163 } else {
159164 if (resource != null ) {
@@ -166,12 +171,13 @@ else if(esize < 1) {
166171 if (!resource .isAccessible ()) {
167172 msg = MessageFormat .format (ContextMessages .ContextRunner_13 , resource .getName ());
168173 }
169- MessageDialog . openInformation (DebugUIPlugin .getShell (), ContextMessages . ContextRunner_0 , msg );
174+ openNoRecentLaunchDialog (DebugUIPlugin .getShell (), msg , mode , group . getIdentifier () );
170175 }
171176 }
172177 else {
173178 if (!launchLast (group , isShift )) {
174- MessageDialog .openInformation (DebugUIPlugin .getShell (), ContextMessages .ContextRunner_0 , ContextMessages .ContextRunner_7 );
179+ openNoRecentLaunchDialog (DebugUIPlugin .getShell (), ContextMessages .ContextRunner_7 ,
180+ mode , group .getIdentifier ());
175181 }
176182 }
177183 }
@@ -188,6 +194,64 @@ else if(csize > 1){
188194 }
189195 }
190196
197+ /**
198+ * Returns the label for the launch configuration button based on the given
199+ * launch mode.
200+ *
201+ * @param launchMode launch mode identifier (e.g., run or debug)
202+ * @return the corresponding button label for opening the launch configuration
203+ * dialog
204+ */
205+ private String launchButtonName (String launchMode ) {
206+ String config = launchMode .substring (0 , 1 ).toUpperCase () + launchMode .substring (1 );
207+ return NLS .bind (ContextMessages .OpenLaunchConfigButton , config );
208+ }
209+
210+ /**
211+ * Opens a dialog informing the user that no recent launch configuration is
212+ * available. The dialog provides an option to proceed with opening launch
213+ * configuration using the given mode.
214+ *
215+ * @param shell the parent {@link Shell} for the dialog
216+ * @param message the message to be displayed in the dialog
217+ * @param mode the launch mode (e.g., run or debug) used to
218+ * determine the button label
219+ * @param launchIdentifier an identifier associated with the launch, used for
220+ * handling the action
221+ */
222+ private void openNoRecentLaunchDialog (Shell shell , String message , String mode , String launchIdentifier ) {
223+ LaunchFailedDialog launchDialog = new LaunchFailedDialog (shell ,
224+ ContextMessages .ContextRunner_0 , null , message , MessageDialog .INFORMATION ,
225+ new String [] { launchButtonName (mode ), IDialogConstants .OK_LABEL }, launchIdentifier );
226+ launchDialog .open ();
227+ }
228+ /**
229+ * Custom dialog shown when a launch fails with no recent configurations.
230+ * Provides an option to directly open the corresponding launch configuration
231+ * group.
232+ */
233+ private static class LaunchFailedDialog extends MessageDialog {
234+
235+ private final String launchGroup ;
236+
237+ LaunchFailedDialog (Shell parentShell , String dialogTitle , Image dialogTitleImage , String dialogMessage ,
238+ int dialogImageType , String [] dialogButtonLabels , String launchGroup ) {
239+ super (parentShell , dialogTitle , dialogTitleImage , dialogMessage , dialogImageType , dialogButtonLabels , 1 );
240+ this .launchGroup = launchGroup ;
241+ }
242+
243+ @ Override
244+ protected void buttonPressed (int buttonId ) {
245+ if (buttonId == 0 ) {
246+ DebugUITools .openLaunchConfigurationDialogOnGroup (getShell (), null , launchGroup );
247+ setReturnCode (buttonId );
248+ close ();
249+ return ;
250+ }
251+ super .buttonPressed (buttonId );
252+ }
253+ }
254+
191255 /**
192256 * Validates the given launch mode and launches.
193257 *
0 commit comments