diff --git a/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/internal/LaunchBarManager.java b/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/internal/LaunchBarManager.java index c17331bbe3c..fa2dc6e6c38 100644 --- a/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/internal/LaunchBarManager.java +++ b/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/internal/LaunchBarManager.java @@ -948,7 +948,9 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration Activator.trace("launch config not claimed"); //$NON-NLS-1$ try { ILaunchDescriptor desc = defaultDescriptorType.getDescriptor(configuration); - addDescriptor(configuration, desc); + if( desc != null ) { + addDescriptor(configuration, desc); + } } catch (CoreException e) { Activator.log(e.getStatus()); } diff --git a/bundles/org.eclipse.launchbar.ui/src/org/eclipse/launchbar/ui/internal/Messages.java b/bundles/org.eclipse.launchbar.ui/src/org/eclipse/launchbar/ui/internal/Messages.java index 97d8fbc75ce..34637d6ea5d 100644 --- a/bundles/org.eclipse.launchbar.ui/src/org/eclipse/launchbar/ui/internal/Messages.java +++ b/bundles/org.eclipse.launchbar.ui/src/org/eclipse/launchbar/ui/internal/Messages.java @@ -55,6 +55,22 @@ public class Messages extends NLS { public static String StopActiveCommandHandler_0; public static String StopActiveCommandHandler_1; public static String TargetSelector_CreateNewTarget; + + public static String DescriptorMustNotBeNull; + public static String DescriptorMustNotBeNullDesc; + public static String NoActiveTarget; + public static String NoActiveTargetDesc; + public static String NoLaunchConfigType; + public static String CannotEditLaunchConfiguration; + public static String NoLaunchModeSelected; + public static String NoLaunchGroupSelected; + public static String LaunchConfigurationNotFound; + public static String LaunchConfigurationNotFoundDesc; + public static String NoLaunchTabsDefined; + public static String NoLaunchTabsDefinedDesc; + + + static { // initialize resource bundle NLS.initializeMessages(BUNDLE_NAME, Messages.class); diff --git a/bundles/org.eclipse.launchbar.ui/src/org/eclipse/launchbar/ui/internal/commands/ConfigureActiveLaunchHandler.java b/bundles/org.eclipse.launchbar.ui/src/org/eclipse/launchbar/ui/internal/commands/ConfigureActiveLaunchHandler.java index 6d9b02d20e3..f11b404c9a0 100644 --- a/bundles/org.eclipse.launchbar.ui/src/org/eclipse/launchbar/ui/internal/commands/ConfigureActiveLaunchHandler.java +++ b/bundles/org.eclipse.launchbar.ui/src/org/eclipse/launchbar/ui/internal/commands/ConfigureActiveLaunchHandler.java @@ -14,18 +14,22 @@ import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; import org.eclipse.debug.core.ILaunchConfiguration; import org.eclipse.debug.core.ILaunchConfigurationType; import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; import org.eclipse.debug.core.ILaunchMode; import org.eclipse.debug.internal.ui.DebugUIPlugin; +import org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationPresentationManager; import org.eclipse.debug.internal.ui.launchConfigurations.LaunchGroupExtension; +import org.eclipse.debug.ui.ILaunchConfigurationTabGroup; import org.eclipse.debug.ui.ILaunchGroup; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.launchbar.core.ILaunchDescriptor; import org.eclipse.launchbar.core.internal.LaunchBarManager; import org.eclipse.launchbar.ui.internal.Activator; +import org.eclipse.launchbar.ui.internal.Messages; import org.eclipse.launchbar.ui.internal.dialogs.LaunchConfigurationEditDialog; import org.eclipse.remote.core.IRemoteConnection; import org.eclipse.swt.widgets.Shell; @@ -42,43 +46,90 @@ public class ConfigureActiveLaunchHandler extends AbstractHandler { return Status.OK_STATUS; } + + public static IStatus canOpenConfigurationEditor(ILaunchDescriptor desc) { + if (desc == null) + return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.DescriptorMustNotBeNull, new Exception(Messages.DescriptorMustNotBeNullDesc)); + LaunchBarManager manager = Activator.getDefault().getLaunchBarUIManager().getManager(); + ILaunchMode mode = manager.getActiveLaunchMode(); + IRemoteConnection target = manager.getActiveLaunchTarget(); + if (target == null) { + return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.NoActiveTarget, new Exception(Messages.NoActiveTargetDesc)); + } + + ILaunchConfigurationType configType = null; + try { + configType = manager.getLaunchConfigurationType(desc, target); + } catch(CoreException ce) {/* ignore */ }; + if (configType == null) { + return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.NoLaunchConfigType, new Exception(Messages.CannotEditLaunchConfiguration)); + } + + if( mode == null ) { + return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.NoLaunchModeSelected, new Exception(Messages.NoLaunchModeSelected)); + } + + ILaunchGroup group = DebugUIPlugin.getDefault().getLaunchConfigurationManager().getLaunchGroup(configType, mode.getIdentifier()); + if( group == null ) { + return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.NoLaunchGroupSelected, new Exception(Messages.NoLaunchGroupSelected)); + } + + String mode2 = group.getMode(); + if( mode2 == null ) { + return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.NoLaunchModeSelected, new Exception(Messages.CannotEditLaunchConfiguration)); + } + + LaunchGroupExtension groupExt = DebugUIPlugin.getDefault().getLaunchConfigurationManager().getLaunchGroup(group.getIdentifier()); + if (groupExt != null) { + ILaunchConfiguration config = null; + try { + config = manager.getLaunchConfiguration(desc, target); + } catch(CoreException ce) { + // Ignore + } + if (config == null) { + return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.LaunchConfigurationNotFound, new Exception(Messages.LaunchConfigurationNotFoundDesc)); + } + try { + LaunchConfigurationPresentationManager mgr = LaunchConfigurationPresentationManager.getDefault(); + ILaunchConfigurationTabGroup tabgroup = mgr.getTabGroup(config, mode.getIdentifier()); + } catch(CoreException ce) { + return new Status(IStatus.ERROR, Activator.PLUGIN_ID,Messages.NoLaunchTabsDefined, new Exception(Messages.NoLaunchTabsDefinedDesc)); + } + } else { + return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.CannotEditLaunchConfiguration, new Exception(Messages.CannotEditLaunchConfiguration)); + } + return Status.OK_STATUS; + } + + public static void openConfigurationEditor(ILaunchDescriptor desc) { if (desc == null) return; + + // Display the error message + Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); + IStatus s = canOpenConfigurationEditor(desc); + if( !s.isOK()) { + MessageDialog.openError(shell, s.getMessage(), s.getException() == null ? s.getMessage() : s.getException().getMessage()); + return; + } + + // At this point, no error handling should be needed. try { - Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); LaunchBarManager manager = Activator.getDefault().getLaunchBarUIManager().getManager(); ILaunchMode mode = manager.getActiveLaunchMode(); IRemoteConnection target = manager.getActiveLaunchTarget(); - if (target == null) { - MessageDialog.openError(shell, "No Active Target", "You must create a target to edit this launch configuration."); - return; - } ILaunchConfigurationType configType = manager.getLaunchConfigurationType(desc, target); - if (configType == null) { - MessageDialog.openError(shell, "No launch configuration type", "Cannot edit this configuration"); - return; - } - ILaunchGroup group = DebugUIPlugin.getDefault().getLaunchConfigurationManager() - .getLaunchGroup(configType, mode.getIdentifier()); - LaunchGroupExtension groupExt = DebugUIPlugin.getDefault().getLaunchConfigurationManager() - .getLaunchGroup(group.getIdentifier()); - if (groupExt != null) { - ILaunchConfiguration config = manager.getLaunchConfiguration(desc, target); - if (config == null) { - MessageDialog.openError(shell, "No launch configuration", "Cannot edit this configuration"); - return; - } - if (config.isWorkingCopy() && ((ILaunchConfigurationWorkingCopy) config).isDirty()) { - config = ((ILaunchConfigurationWorkingCopy) config).doSave(); - } - final LaunchConfigurationEditDialog dialog = new LaunchConfigurationEditDialog(shell, config, groupExt); - dialog.setInitialStatus(Status.OK_STATUS); - dialog.open(); - } else { - MessageDialog.openError(shell, "Cannot determine mode", "Cannot edit this configuration"); - return; + ILaunchGroup group = DebugUIPlugin.getDefault().getLaunchConfigurationManager().getLaunchGroup(configType, mode.getIdentifier()); + LaunchGroupExtension groupExt = DebugUIPlugin.getDefault().getLaunchConfigurationManager().getLaunchGroup(group.getIdentifier()); + ILaunchConfiguration config = manager.getLaunchConfiguration(desc, target); + if (config.isWorkingCopy() && ((ILaunchConfigurationWorkingCopy) config).isDirty()) { + config = ((ILaunchConfigurationWorkingCopy) config).doSave(); } + final LaunchConfigurationEditDialog dialog = new LaunchConfigurationEditDialog(shell, config, groupExt); + dialog.setInitialStatus(Status.OK_STATUS); + dialog.open(); } catch (CoreException e2) { Activator.log(e2); } diff --git a/bundles/org.eclipse.launchbar.ui/src/org/eclipse/launchbar/ui/internal/messages.properties b/bundles/org.eclipse.launchbar.ui/src/org/eclipse/launchbar/ui/internal/messages.properties index 910ac545fc7..be73c78e828 100644 --- a/bundles/org.eclipse.launchbar.ui/src/org/eclipse/launchbar/ui/internal/messages.properties +++ b/bundles/org.eclipse.launchbar.ui/src/org/eclipse/launchbar/ui/internal/messages.properties @@ -39,3 +39,16 @@ NewLaunchConfigWizard_0=Create Launch Configuration StopActiveCommandHandler_0=Stopping launches StopActiveCommandHandler_1=Stopping build TargetSelector_CreateNewTarget=Create New Connection... + +DescriptorMustNotBeNull=Descriptor must not be null +DescriptorMustNotBeNullDesc=The launch descriptor must not be null. +NoActiveTarget=No Active Target +NoActiveTargetDesc=You must create a target to edit this launch configuration. +NoLaunchConfigType=No launch configuration type matches selected launch descriptor. +CannotEditLaunchConfiguration=Cannot edit this configuration. +NoLaunchModeSelected=No launch mode selected. +NoLaunchGroupSelected=No launch group found for the current selection. +LaunchConfigurationNotFound=Launch Configuration Not Found +LaunchConfigurationNotFoundDesc=No launch configuration is found for the given launch descriptor and target. +NoLaunchTabsDefined=No launch tabs defined. +NoLaunchTabsDefinedDesc=No launch tabs have been defined for this launch configuration type.