From ca4c3de585c743486c2df55b551ec3f2dfd9b6a2 Mon Sep 17 00:00:00 2001 From: Axel Richard Date: Fri, 10 Mar 2017 16:30:18 +0100 Subject: Bug 41353 - Launch configuration prototypes First implementation of the launch configuration prototypes mechanism. Change-Id: I21a2a97b83aa9cb1be79153bbc4b72171cc6be20 Signed-off-by: Axel Richard --- .../debug/internal/ui/DebugPluginImages.java | 13 + .../eclipse/debug/internal/ui/DebugUIMessages.java | 4 +- .../debug/internal/ui/DebugUIMessages.properties | 4 +- .../debug/internal/ui/IDebugHelpContextIds.java | 4 +- .../internal/ui/IInternalDebugUIConstants.java | 14 +- .../GroupLaunchConfigurationSelectionDialog.java | 10 +- .../ExportLaunchConfigurationsWizardPage.java | 3 +- .../ImportLaunchConfigurationsWizardPage.java | 5 +- .../CreateLaunchConfigurationPrototypeAction.java | 147 ++++ .../DeleteLaunchConfigurationAction.java | 5 +- .../LaunchConfigurationTabGroupViewer.java | 11 +- .../LaunchConfigurationTreeContentProvider.java | 50 +- .../LaunchConfigurationView.java | 30 +- .../LaunchConfigurationsDialog.java | 66 ++ .../LaunchConfigurationsMessages.java | 40 +- .../LaunchConfigurationsMessages.properties | 42 +- .../launchConfigurations/LinkPrototypeAction.java | 159 +++++ .../ResetWithPrototypeValuesAction.java | 129 ++++ .../UnlinkPrototypeAction.java | 128 ++++ .../ui/sourcelookup/SourceLookupUIMessages.java | 6 +- .../sourcelookup/SourceLookupUIMessages.properties | 6 +- .../debug/ui/AbstractLaunchConfigurationTab.java | 61 +- .../ui/org/eclipse/debug/ui/CommonTab.java | 22 +- .../ui/org/eclipse/debug/ui/EnvironmentTab.java | 16 +- .../ui/org/eclipse/debug/ui/IDebugUIConstants.java | 10 +- .../org/eclipse/debug/ui/PrototypeDecorator.java | 52 ++ .../ui/org/eclipse/debug/ui/ProtoypeTab.java | 760 +++++++++++++++++++++ .../debug/ui/sourcelookup/SourceLookupTab.java | 16 +- 28 files changed, 1772 insertions(+), 41 deletions(-) create mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/CreateLaunchConfigurationPrototypeAction.java create mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LinkPrototypeAction.java create mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/ResetWithPrototypeValuesAction.java create mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/UnlinkPrototypeAction.java create mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/ui/PrototypeDecorator.java create mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/ui/ProtoypeTab.java (limited to 'org.eclipse.debug.ui/ui') diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/DebugPluginImages.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/DebugPluginImages.java index b1d01231a..68ec975bd 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/DebugPluginImages.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/DebugPluginImages.java @@ -12,6 +12,7 @@ * Wind River Systems - Pawel Piech - Added Modules view (bug 211158) * Lars.Vogel - Bug 430620 * Lucas Bullen - Bug 518652 + * Axel Richard (Obeo) - Bug 41353 - Launch configurations prototypes *******************************************************************************/ package org.eclipse.debug.internal.ui; @@ -117,6 +118,10 @@ public class DebugPluginImages { declareRegistryImage(IInternalDebugUIConstants.IMG_DLCL_NEW_CONFIG, DLCL + "new_con.png"); //$NON-NLS-1$ declareRegistryImage(IInternalDebugUIConstants.IMG_DLCL_DELETE_CONFIG, DLCL + "rem_co.png"); //$NON-NLS-1$ declareRegistryImage(IInternalDebugUIConstants.IMG_DLCL_FILTER_CONFIGS, DLCL + "filter_ps.png"); //$NON-NLS-1$ + declareRegistryImage(IInternalDebugUIConstants.IMG_DLCL_NEW_PROTO, DLCL + "new_proto.png"); //$NON-NLS-1$ + declareRegistryImage(IInternalDebugUIConstants.IMG_DLCL_LINK_PROTO, DLCL + "link_proto.png"); //$NON-NLS-1$ + declareRegistryImage(IInternalDebugUIConstants.IMG_DLCL_UNLINK_PROTO, DLCL + "unlink_proto.png"); //$NON-NLS-1$ + declareRegistryImage(IInternalDebugUIConstants.IMG_DLCL_RESET_PROTO, DLCL + "reset_proto.png"); //$NON-NLS-1$ declareRegistryImage(IInternalDebugUIConstants.IMG_DLCL_DISCONNECT, DLCL + "disconnect_co.png"); //$NON-NLS-1$ declareRegistryImage(IInternalDebugUIConstants.IMG_DLCL_SUSPEND, DLCL + "suspend_co.png"); //$NON-NLS-1$ declareRegistryImage(IInternalDebugUIConstants.IMG_DLCL_RESUME, DLCL + "resume_co.png"); //$NON-NLS-1$ @@ -156,6 +161,10 @@ public class DebugPluginImages { declareRegistryImage(IInternalDebugUIConstants.IMG_ELCL_DUPLICATE_CONFIG, ELCL + "copy_edit_co.png"); //$NON-NLS-1$ declareRegistryImage(IInternalDebugUIConstants.IMG_ELCL_NEW_CONFIG, ELCL + "new_con.png"); //$NON-NLS-1$ declareRegistryImage(IInternalDebugUIConstants.IMG_ELCL_DELETE_CONFIG, ELCL + "delete_config.png"); //$NON-NLS-1$ + declareRegistryImage(IInternalDebugUIConstants.IMG_ELCL_NEW_PROTO, ELCL + "new_proto.png"); //$NON-NLS-1$ + declareRegistryImage(IInternalDebugUIConstants.IMG_ELCL_LINK_PROTO, ELCL + "link_proto.png"); //$NON-NLS-1$ + declareRegistryImage(IInternalDebugUIConstants.IMG_ELCL_UNLINK_PROTO, ELCL + "unlink_proto.png"); //$NON-NLS-1$ + declareRegistryImage(IInternalDebugUIConstants.IMG_ELCL_RESET_PROTO, ELCL + "reset_proto.png"); //$NON-NLS-1$ declareRegistryImage(IInternalDebugUIConstants.IMG_ELCL_SUSPEND, ELCL + "suspend_co.png"); //$NON-NLS-1$ declareRegistryImage(IInternalDebugUIConstants.IMG_ELCL_RESUME, ELCL + "resume_co.png"); //$NON-NLS-1$ declareRegistryImage(IInternalDebugUIConstants.IMG_ELCL_STEP_RETURN, ELCL + "stepreturn_co.png"); //$NON-NLS-1$ @@ -209,12 +218,15 @@ public class DebugPluginImages { declareRegistryImage(IInternalDebugUIConstants.IMG_OBJECT_MEMORY, OBJECT + "memory_obj.png"); //$NON-NLS-1$ declareRegistryImage(IInternalDebugUIConstants.IMG_OBJS_BREAKPOINT_TYPE, OBJECT + "brkp_type.png"); //$NON-NLS-1$ declareRegistryImage(IInternalDebugUIConstants.IMG_OBJS_LAUNCH_GROUP, OBJECT + "lgroup_obj.png"); //$NON-NLS-1$ + declareRegistryImage(IInternalDebugUIConstants.IMG_OBJS_CHECK, OBJECT + "check.png"); //$NON-NLS-1$ + declareRegistryImage(IInternalDebugUIConstants.IMG_OBJS_UNCHECK, OBJECT + "uncheck.png"); //$NON-NLS-1$ // tabs declareRegistryImage(IInternalDebugUIConstants.IMG_OBJS_COMMON_TAB, OBJECT + "common_tab.png"); //$NON-NLS-1$ declareRegistryImage(IInternalDebugUIConstants.IMG_OBJS_REFRESH_TAB, OBJECT + "refresh_tab.png"); //$NON-NLS-1$ declareRegistryImage(IInternalDebugUIConstants.IMG_OBJS_PERSPECTIVE_TAB, OBJECT + "persp_tab.png"); //$NON-NLS-1$ declareRegistryImage(IDebugUIConstants.IMG_OBJS_ENVIRONMENT, OBJECT + "environment_obj.png"); //$NON-NLS-1$ + declareRegistryImage(IInternalDebugUIConstants.IMG_OBJS_PROTO_TAB, OBJECT + "proto_tab.png"); //$NON-NLS-1$ // Views declareRegistryImage(IDebugUIConstants.IMG_VIEW_BREAKPOINTS, VIEW + "breakpoint_view.png"); //$NON-NLS-1$ @@ -240,6 +252,7 @@ public class DebugPluginImages { declareRegistryImage(IInternalDebugUIConstants.IMG_OVR_TRANSPARENT, OVR + "transparent.png"); //$NON-NLS-1$ declareRegistryImage(IDebugUIConstants.IMG_OVR_SKIP_BREAKPOINT, OVR + "skip_breakpoint_ov.png"); //$NON-NLS-1$ declareRegistryImage(IInternalDebugUIConstants.IMG_OVR_SHOW_LOGICAL_STRUCTURE, OVR + "var_cntnt_prvdr_ov.png"); //$NON-NLS-1$ + declareRegistryImage(IDebugUIConstants.IMG_OVR_PROTOTYPE, OVR + "prototype.png"); //$NON-NLS-1$ //source location declareRegistryImage(IInternalDebugUIConstants.IMG_SRC_LOOKUP_MENU, ELCL + "edtsrclkup_co.png"); //$NON-NLS-1$ diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/DebugUIMessages.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/DebugUIMessages.java index aeae3b518..3ad431651 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/DebugUIMessages.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/DebugUIMessages.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2016 IBM Corporation and others. + * Copyright (c) 2000, 2017 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -9,6 +9,7 @@ * IBM - Initial API and implementation * Wind River Systems - Ted Williams - [Memory View] Memory View: Workflow Enhancements (Bug 215432) * Remy Chi Jian Suen - Make WorkingDirectoryBlock from JDT a Debug API class (Bug 221973) + * Obeo - Axel Richard - Launch configurations prototypes (Bug 41353) *******************************************************************************/ package org.eclipse.debug.internal.ui; @@ -244,6 +245,7 @@ public class DebugUIMessages extends NLS { public static String GroupLaunch_Error; public static String GroupLaunchConfigurationSelectionDialog_0; public static String GroupLaunchConfigurationSelectionDialog_1; + public static String GroupLaunchConfigurationSelectionDialog_2; public static String GroupLaunchConfigurationSelectionDialog_10; public static String GroupLaunchConfigurationSelectionDialog_11; public static String GroupLaunchConfigurationSelectionDialog_12; diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/DebugUIMessages.properties b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/DebugUIMessages.properties index 386d6fe44..6f7a9d77d 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/DebugUIMessages.properties +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/DebugUIMessages.properties @@ -1,5 +1,5 @@ ############################################################################### -# Copyright (c) 2000, 2012 IBM Corporation and others. +# Copyright (c) 2000, 2017 IBM Corporation and others. # All rights reserved. This program and the accompanying materials # are made available under the terms of the Eclipse Public License v1.0 # which accompanies this distribution, and is available at @@ -9,6 +9,7 @@ # IBM Corporation - initial API and implementation # Wind River Systems - Ted Williams - [Memory View] Memory View: Workflow Enhancements (Bug 215432) # Remy Chi Jian Suen - Make WorkingDirectoryBlock from JDT a Debug API class (Bug 221973) +# Obeo - Axel Richard - Launch configurations prototypes (Bug 41353) ############################################################################### DebugUIPlugin_23=Build in Progress @@ -123,6 +124,7 @@ GroupLaunchConfigurationSelectionDialog_7=Select a launch configuration GroupLaunchConfigurationSelectionDialog_8=&Post launch action: GroupLaunchConfigurationSelectionDialog_9=&Seconds: GroupLaunchConfigurationSelectionDialog_1=Selected launch mode is not supported for selected launch configuration(s) +GroupLaunchConfigurationSelectionDialog_2=The selection contains prototype(s) GroupLaunchConfigurationSelectionDialog_10=Enter valid number of seconds GroupLaunchConfigurationSelectionDialog_11=Select only one launch configuration GroupLaunchConfigurationSelectionDialog_12=Add Launch Configuration diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/IDebugHelpContextIds.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/IDebugHelpContextIds.java index 2ae06eff4..868bbcffc 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/IDebugHelpContextIds.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/IDebugHelpContextIds.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2011 IBM Corporation and others. + * Copyright (c) 2000, 2017 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -9,6 +9,7 @@ * IBM Corporation - initial API and implementation * QNX Software Systems - Mikhail Khodjaiants - Registers View (Bug 53640) * Wind River Systems - Pawel Piech - Added Modules view (bug 211158) + * Axel Richard (Obeo) - Bug 41353 - Launch configurations prototypes *******************************************************************************/ package org.eclipse.debug.internal.ui; @@ -140,6 +141,7 @@ public interface IDebugHelpContextIds { public static final String LAUNCH_CONFIGURATION_DIALOG_PERSPECTIVE_TAB = PREFIX + "launch_configuration_dialog_perspective_tab"; //$NON-NLS-1$ public static final String LAUNCH_CONFIGURATION_DIALOG_REFRESH_TAB = PREFIX + "launch_configuration_dialog_refresh_tab"; //$NON-NLS-1$ public static final String LAUNCH_CONFIGURATION_DIALOG_ENVIRONMENT_TAB = PREFIX + "launch_configuration_dialog_environment_tab"; //$NON-NLS-1$ + public static final String LAUNCH_CONFIGURATION_DIALOG_PROTOTYPE_TAB = PREFIX + "launch_configuration_dialog_prototype_tab"; //$NON-NLS-1$ // Working set page public static final String WORKING_SET_PAGE = PREFIX + "working_set_page_context"; //$NON-NLS-1$ diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/IInternalDebugUIConstants.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/IInternalDebugUIConstants.java index 093a9648c..b404e9fa9 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/IInternalDebugUIConstants.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/IInternalDebugUIConstants.java @@ -10,6 +10,7 @@ * QNX Software Systems - Mikhail Khodjaiants - Bug 114664 * Wind River Systems - Pawel Piech - Added Modules view (bug 211158) * Lucas Bullen (Red Hat Inc.) - Bug 518652 + * Axel Richard (Obeo) - Bug 41353 - Launch configurations prototypes *******************************************************************************/ package org.eclipse.debug.internal.ui; @@ -70,6 +71,10 @@ public interface IInternalDebugUIConstants { public static final String IMG_DLCL_DUPLICATE_CONFIG = "IMG_DLCL_DUPLICATE_CONFIG"; //$NON-NLS-1$ public static final String IMG_DLCL_DELETE_CONFIG = "IMG_DLCL_DELETE_CONFIG"; //$NON-NLS-1$ public static final String IMG_DLCL_FILTER_CONFIGS = "IMG_DLCL_FILTER_CONFIGS"; //$NON-NLS-1$ + public static final String IMG_DLCL_NEW_PROTO = "IMG_DLCL_NEW_PROTO"; //$NON-NLS-1$ + public static final String IMG_DLCL_LINK_PROTO = "IMG_DLCL_LINK_PROTO"; //$NON-NLS-1$ + public static final String IMG_DLCL_UNLINK_PROTO = "IMG_DLCL_UNLINK_PROTO"; //$NON-NLS-1$ + public static final String IMG_DLCL_RESET_PROTO = "IMG_DLCL_RESET_PROTO"; //$NON-NLS-1$ public static final String IMG_DLCL_SUSPEND = "IMG_DLCL_SUSPEND"; //$NON-NLS-1$ public static final String IMG_DLCL_RESUME = "IMG_DLCL_RESUME"; //$NON-NLS-1$ public static final String IMG_DLCL_STEP_RETURN = "IMG_DLCL_STEP_RETURN"; //$NON-NLS-1$ @@ -114,6 +119,10 @@ public interface IInternalDebugUIConstants { public static final String IMG_ELCL_DELETE_CONFIG = "IMG_ELCL_DELETE_CONFIG"; //$NON-NLS-1$ public static final String IMG_ELCL_FILTER_CONFIGS = "IMG_ELCL_FILTER_CONFIGS"; //$NON-NLS-1$ public static final String IMG_ELCL_DUPLICATE_CONFIG = "IMG_ELCL_DUPLICATE_CONFIG"; //$NON-NLS-1$ + public static final String IMG_ELCL_NEW_PROTO = "IMG_ELCL_NEW_PROTO"; //$NON-NLS-1$ + public static final String IMG_ELCL_LINK_PROTO = "IMG_ELCL_LINK_PROTO"; //$NON-NLS-1$ + public static final String IMG_ELCL_UNLINK_PROTO = "IMG_ELCL_UNLINK_PROTO"; //$NON-NLS-1$ + public static final String IMG_ELCL_RESET_PROTO = "IMG_ELCL_RESET_PROTO"; //$NON-NLS-1$ public static final String IMG_ELCL_SUSPEND = "IMG_ELCL_SUSPEND"; //$NON-NLS-1$ public static final String IMG_ELCL_RESUME = "IMG_ELCL_RESUME"; //$NON-NLS-1$ public static final String IMG_ELCL_STEP_RETURN = "IMG_ELCL_STEP_RETURN"; //$NON-NLS-1$ @@ -140,7 +149,10 @@ public interface IInternalDebugUIConstants { public static final String IMG_OBJECT_MEMORY_CHANGED="IMG_OBJECT_MEMORY_CHANGED"; //$NON-NLS-1$ public static final String IMG_OBJECT_MEMORY="IMG_OBJECT_MEMORY"; //$NON-NLS-1$ public static final String IMG_OBJS_BREAKPOINT_TYPE="IMG_OBJ_BREAKPOINT_TYPE"; //$NON-NLS-1$ - public static final String IMG_OBJS_LAUNCH_GROUP = "IMG_OBJ_LAUNCH_GROUP"; //$NON-NLS-1$ + public static final String IMG_OBJS_LAUNCH_GROUP = "IMG_OBJ_LAUNCH_GROUP"; //$NON-NLS-1$ + public static final String IMG_OBJS_CHECK = "IMG_OBJS_CHECK"; //$NON-NLS-1$ + public static final String IMG_OBJS_UNCHECK = "IMG_OBJS_UNCHECK"; //$NON-NLS-1$ + public static final String IMG_OBJS_PROTO_TAB = "IMG_OBJS_PROTO_TAB"; //$NON-NLS-1$ // wizard images public static final String IMG_WIZBAN_IMPORT_BREAKPOINTS = "IMG_WIZBAN_IMPORT_BREAKPOINTS"; //$NON-NLS-1$ diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/groups/GroupLaunchConfigurationSelectionDialog.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/groups/GroupLaunchConfigurationSelectionDialog.java index 3b951a736..2b5f0ac04 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/groups/GroupLaunchConfigurationSelectionDialog.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/groups/GroupLaunchConfigurationSelectionDialog.java @@ -9,6 +9,7 @@ * QNX Software Systems - initial API and implementation * Freescale Semiconductor * SSI Schaefer + * Axel Richard (Obeo) - Bug 41353 - Launch configurations prototypes *******************************************************************************/ package org.eclipse.debug.internal.ui.groups; @@ -104,10 +105,10 @@ class GroupLaunchConfigurationSelectionDialog extends TitleAreaDialog implements if (type.equals(groupType)) { // we're hiding ourselves. if we're the only group, // don't show the type. - return getLaunchManager().getLaunchConfigurations(type).length > 1; + return getLaunchManager().getLaunchConfigurations(type, ILaunchConfiguration.CONFIGURATION).length > 1; } - return getLaunchManager().getLaunchConfigurations(type).length > 0; + return getLaunchManager().getLaunchConfigurations(type, ILaunchConfiguration.CONFIGURATION).length > 0; } else if (element instanceof ILaunchConfiguration) { ILaunchConfiguration c = (ILaunchConfiguration) element; if (c.getName().equals(self.getName()) && c.getType().equals(groupType)) { @@ -388,7 +389,10 @@ class GroupLaunchConfigurationSelectionDialog extends TitleAreaDialog implements } setErrorMessage(isValid ? null : DebugUIMessages.GroupLaunchConfigurationSelectionDialog_1); } - + if (isValid && sel.isPrototype()) { + isValid = false; + setErrorMessage(DebugUIMessages.GroupLaunchConfigurationSelectionDialog_2); + } if (!isValid) { break; } diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/importexport/launchconfigurations/ExportLaunchConfigurationsWizardPage.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/importexport/launchconfigurations/ExportLaunchConfigurationsWizardPage.java index 7425eb494..e3084a035 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/importexport/launchconfigurations/ExportLaunchConfigurationsWizardPage.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/importexport/launchconfigurations/ExportLaunchConfigurationsWizardPage.java @@ -9,6 +9,7 @@ * IBM Corporation - initial API and implementation * Lars Vogel - Bug 490755 * Lucas Bullen & Ian Pun - Bug 518652 + * Axel Richard (Obeo) - Bug 41353 - Launch configurations prototypes *******************************************************************************/ package org.eclipse.debug.internal.ui.importexport.launchconfigurations; @@ -87,7 +88,7 @@ public class ExportLaunchConfigurationsWizardPage extends WizardPage { public Object[] getChildren(Object parentElement) { if(parentElement instanceof ILaunchConfigurationType) { try { - return lm.getLaunchConfigurations((ILaunchConfigurationType) parentElement); + return lm.getLaunchConfigurations((ILaunchConfigurationType) parentElement, ILaunchConfiguration.CONFIGURATION | ILaunchConfiguration.PROTOTYPE); } catch (Exception e) { DebugUIPlugin.logErrorMessage(e.getMessage()); diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/importexport/launchconfigurations/ImportLaunchConfigurationsWizardPage.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/importexport/launchconfigurations/ImportLaunchConfigurationsWizardPage.java index 4cd723ce9..61703d169 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/importexport/launchconfigurations/ImportLaunchConfigurationsWizardPage.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/importexport/launchconfigurations/ImportLaunchConfigurationsWizardPage.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2013 IBM Corporation and others. + * Copyright (c) 2007, 2017 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Axel Richard (Obeo) - Bug 41353 - Launch configurations prototypes *******************************************************************************/ package org.eclipse.debug.internal.ui.importexport.launchconfigurations; @@ -110,7 +111,7 @@ public class ImportLaunchConfigurationsWizardPage extends WizardResourceImportPa if(child.isFile()) { Path childpath = new Path(child.getAbsolutePath()); String extension = childpath.getFileExtension(); - if(extension != null && extension.equals(ILaunchConfiguration.LAUNCH_CONFIGURATION_FILE_EXTENSION)) { + if (extension != null && (extension.equals(ILaunchConfiguration.LAUNCH_CONFIGURATION_FILE_EXTENSION) || extension.equals(ILaunchConfiguration.LAUNCH_CONFIGURATION_PROTOTYPE_FILE_EXTENSION))) { newelement = new DebugFileSystemElement(provider.getLabel(child), this, provider.isFolder(child)); newelement.setFileSystemObject(child); } diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/CreateLaunchConfigurationPrototypeAction.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/CreateLaunchConfigurationPrototypeAction.java new file mode 100644 index 000000000..d817072d6 --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/CreateLaunchConfigurationPrototypeAction.java @@ -0,0 +1,147 @@ +/******************************************************************************* + * Copyright (c) 2017 Obeo. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Obeo - initial API and implementation + *******************************************************************************/ +package org.eclipse.debug.internal.ui.launchConfigurations; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.debug.core.DebugPlugin; +import org.eclipse.debug.core.ILaunchConfiguration; +import org.eclipse.debug.core.ILaunchConfigurationType; +import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; +import org.eclipse.debug.internal.ui.DebugUIPlugin; +import org.eclipse.debug.internal.ui.IInternalDebugUIConstants; +import org.eclipse.debug.ui.DebugUITools; +import org.eclipse.debug.ui.ILaunchConfigurationDialog; +import org.eclipse.debug.ui.ILaunchConfigurationTab; +import org.eclipse.debug.ui.ILaunchConfigurationTabGroup; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.Viewer; + +/** + * Creates a new launch configuration prototype based on the selection. + * + * @since 3.13 + */ +public class CreateLaunchConfigurationPrototypeAction extends AbstractLaunchConfigurationAction { + + /** + * Action identifier for IDebugView#getAction(String) + */ + public static final String ID_CREATE_PROTOTYPE_ACTION = DebugUIPlugin.getUniqueIdentifier() + ".ID_CREATE_PROTOTYPE_ACTION"; //$NON-NLS-1$ + + /** + * Constructs an action to create a launch configuration prototype + * + * @param viewer the viewer + * @param mode the mode the action applies to + */ + public CreateLaunchConfigurationPrototypeAction(Viewer viewer, String mode) { + super(LaunchConfigurationsMessages.CreateLaunchConfigurationPrototypeAction_Ne_w_1, viewer, mode); + } + + /** + * @see AbstractLaunchConfigurationAction#performAction() + */ + @Override + protected void performAction() { + Object object = getStructuredSelection().getFirstElement(); + // double click with Ctrl key mask results in empty selection: bug + // 156087 do no work if the selection is null + if (object != null) { + ILaunchConfigurationType type = null; + // Construct a new configuration prototype of the selected type + if (object instanceof ILaunchConfiguration) { + ILaunchConfiguration config = (ILaunchConfiguration) object; + try { + type = config.getType(); + } catch (CoreException e) { + errorDialog(e); + return; + } + } else { + type = (ILaunchConfigurationType) object; + } + try { + ILaunchConfigurationWorkingCopy wc = type.newPrototypeInstance(null, DebugPlugin.getDefault().getLaunchManager().generateLaunchConfigurationName(LaunchConfigurationsMessages.CreateLaunchConfigurationPrototypeAction_New_prototype_2)); + ILaunchConfigurationTabGroup tabGroup = LaunchConfigurationPresentationManager.getDefault().getTabGroup(wc, getMode()); + // this only works because this action is only present when the + // dialog is open + ILaunchConfigurationDialog dialog = LaunchConfigurationsDialog.getCurrentlyVisibleLaunchConfigurationDialog(); + tabGroup.createTabs(dialog, dialog.getMode()); + ILaunchConfigurationTab[] tabs = tabGroup.getTabs(); + for (int i = 0; i < tabs.length; i++) { + tabs[i].setLaunchConfigurationDialog(dialog); + } + tabGroup.setDefaults(wc); + tabGroup.dispose(); + wc.doSave(); + } catch (CoreException e) { + errorDialog(e); + return; + } + } + } + + /** + * @see org.eclipse.ui.actions.SelectionListenerAction#updateSelection(org.eclipse.jface.viewers.IStructuredSelection) + */ + @Override + protected boolean updateSelection(IStructuredSelection selection) { + if (selection.size() == 1) { + Object object = getStructuredSelection().getFirstElement(); + if (object != null) { + ILaunchConfigurationType type = null; + // Construct a new configuration prototype of the selected type + if (object instanceof ILaunchConfiguration) { + ILaunchConfiguration config = (ILaunchConfiguration) object; + try { + type = config.getType(); + } catch (CoreException e) { + errorDialog(e); + } + } else { + type = (ILaunchConfigurationType) object; + } + if (type != null) { + return type.supportsPrototypes(); + } + } + } + return false; + } + + /* + * (non-Javadoc) + * @see org.eclipse.jface.action.Action#getDisabledImageDescriptor() + */ + @Override + public ImageDescriptor getDisabledImageDescriptor() { + return DebugUITools.getImageDescriptor(IInternalDebugUIConstants.IMG_DLCL_NEW_PROTO); + } + + /* + * (non-Javadoc) + * @see org.eclipse.jface.action.Action#getImageDescriptor() + */ + @Override + public ImageDescriptor getImageDescriptor() { + return DebugUITools.getImageDescriptor(IInternalDebugUIConstants.IMG_ELCL_NEW_PROTO); + } + + /* + * (non-Javadoc) + * @see org.eclipse.jface.action.Action#getToolTipText() + */ + @Override + public String getToolTipText() { + return LaunchConfigurationsMessages.LaunchConfigurationsDialog_2; + } +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/DeleteLaunchConfigurationAction.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/DeleteLaunchConfigurationAction.java index 0c1eebba3..9f1ebac3f 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/DeleteLaunchConfigurationAction.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/DeleteLaunchConfigurationAction.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2013 IBM Corporation and others. + * Copyright (c) 2000, 2017 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Axel Richard (Obeo) - Bug 41353 - Launch configurations prototypes *******************************************************************************/ package org.eclipse.debug.internal.ui.launchConfigurations; @@ -70,7 +71,7 @@ public class DeleteLaunchConfigurationAction extends AbstractLaunchConfiguration while (iterator.hasNext()) { ILaunchConfiguration configuration = (ILaunchConfiguration)iterator.next(); try { - configuration.delete(); + configuration.delete(ILaunchConfiguration.UPDATE_PROTOTYPE_CHILDREN); } catch (CoreException e) { errorDialog(e); } diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationTabGroupViewer.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationTabGroupViewer.java index f3ba24630..2a02359e6 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationTabGroupViewer.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationTabGroupViewer.java @@ -10,6 +10,7 @@ * Mohamed Hussein (Mentor Graphics) - Added getWarningMessage (Bug 386673) * Robert Roth - Used consistent apply button location (Bug 432832) * Lucas Bullen (Red Hat Inc.) - Added export configuration message (Bug 518652) + * Axel Richard (Obeo) - Bug 41353 - Launch configurations prototypes *******************************************************************************/ package org.eclipse.debug.internal.ui.launchConfigurations; @@ -347,11 +348,15 @@ public class LaunchConfigurationTabGroupViewer { int width = parent.getBounds().width - 30; SWTFactory.createWrapLabel(parent, LaunchConfigurationsMessages.LaunchConfigurationTabGroupViewer_1, 1, width); SWTFactory.createWrapCLabel(parent, LaunchConfigurationsMessages.LaunchConfigurationTabGroupViewer_2, DebugUITools.getImage(IInternalDebugUIConstants.IMG_ELCL_NEW_CONFIG), 1, width); + SWTFactory.createWrapCLabel(parent, LaunchConfigurationsMessages.LaunchConfigurationTabGroupViewer_9, DebugUITools.getImage(IInternalDebugUIConstants.IMG_ELCL_NEW_PROTO), 1, width); SWTFactory.createWrapCLabel(parent, LaunchConfigurationsMessages.LaunchConfigurationTabGroupViewer_7, DebugUITools.getImage(IInternalDebugUIConstants.IMG_ELCL_EXPORT_CONFIG), 1, width); SWTFactory.createWrapCLabel(parent, LaunchConfigurationsMessages.LaunchConfigurationTabGroupViewer_6, DebugUITools.getImage(IInternalDebugUIConstants.IMG_ELCL_DUPLICATE_CONFIG), 1, width); SWTFactory.createWrapCLabel(parent, LaunchConfigurationsMessages.LaunchConfigurationTabGroupViewer_4, DebugUITools.getImage(IInternalDebugUIConstants.IMG_ELCL_DELETE_CONFIG), 1, width); - SWTFactory.createWrapCLabel(parent, LaunchConfigurationsMessages.LaunchConfigurationTabGroupViewer_8, DebugUITools.getImage(IInternalDebugUIConstants.IMG_ELCL_FILTER_CONFIGS), 1, width); - SWTFactory.createWrapCLabel(parent, LaunchConfigurationsMessages.LaunchConfigurationTabGroupViewer_3, DebugUITools.getImage(IInternalDebugUIConstants.IMG_OVR_TRANSPARENT), 1, width); + SWTFactory.createWrapCLabel(parent, LaunchConfigurationsMessages.LaunchConfigurationTabGroupViewer_8, DebugUITools.getImage(IInternalDebugUIConstants.IMG_ELCL_FILTER_CONFIGS), 1, width); + SWTFactory.createWrapCLabel(parent, LaunchConfigurationsMessages.LaunchConfigurationTabGroupViewer_3, DebugUITools.getImage(IInternalDebugUIConstants.IMG_OVR_TRANSPARENT), 1, width); + SWTFactory.createWrapCLabel(parent, LaunchConfigurationsMessages.LaunchConfigurationTabGroupViewer_10, DebugUITools.getImage(IInternalDebugUIConstants.IMG_ELCL_LINK_PROTO), 1, width); + SWTFactory.createWrapCLabel(parent, LaunchConfigurationsMessages.LaunchConfigurationTabGroupViewer_11, DebugUITools.getImage(IInternalDebugUIConstants.IMG_ELCL_UNLINK_PROTO), 1, width); + SWTFactory.createWrapCLabel(parent, LaunchConfigurationsMessages.LaunchConfigurationTabGroupViewer_12, DebugUITools.getImage(IInternalDebugUIConstants.IMG_ELCL_RESET_PROTO), 1, width); SWTFactory.createHorizontalSpacer(parent, 2); Link link = new Link(parent, SWT.LEFT | SWT.WRAP); @@ -1511,7 +1516,7 @@ public class LaunchConfigurationTabGroupViewer { getLaunchConfigurationDialog().run(true, false, runnable); } else { - saved[0] = fWorkingCopy.doSave(); + saved[0] = fWorkingCopy.doSave(ILaunchConfiguration.UPDATE_PROTOTYPE_CHILDREN); } } updateButtons(); diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationTreeContentProvider.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationTreeContentProvider.java index 14a06251d..2f655af3c 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationTreeContentProvider.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationTreeContentProvider.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2016 IBM Corporation and others. + * Copyright (c) 2000, 2017 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -8,6 +8,7 @@ * Contributors: * IBM Corporation - initial API and implementation * Lars Vogel - Bug 490755 + * Axel Richard (Obeo) - Bug 41353 - Launch configurations prototypes *******************************************************************************/ package org.eclipse.debug.internal.ui.launchConfigurations; @@ -74,17 +75,30 @@ public class LaunchConfigurationTreeContentProvider implements ITreeContentProvi */ @Override public Object[] getChildren(Object parentElement) { - if (parentElement instanceof ILaunchConfiguration) { - return EMPTY_ARRAY; - } else if (parentElement instanceof ILaunchConfigurationType) { - try { - ILaunchConfigurationType type = (ILaunchConfigurationType)parentElement; - return getLaunchManager().getLaunchConfigurations(type); - } catch (CoreException e) { - DebugUIPlugin.errorDialog(getShell(), LaunchConfigurationsMessages.LaunchConfigurationDialog_Error_19, LaunchConfigurationsMessages.LaunchConfigurationDialog_An_exception_occurred_while_retrieving_launch_configurations_20, e); // + try { + if (parentElement instanceof ILaunchConfiguration) { + if (((ILaunchConfiguration) parentElement).isPrototype()) { + return ((ILaunchConfiguration) parentElement).getPrototypeChildren().toArray(); + } + } else if (parentElement instanceof ILaunchConfigurationType) { + List configs = new ArrayList<>(); + ILaunchConfigurationType type = (ILaunchConfigurationType) parentElement; + ILaunchConfiguration[] launchConfigurations = getLaunchManager().getLaunchConfigurations(type, ILaunchConfiguration.CONFIGURATION); + for (ILaunchConfiguration launchConfig : launchConfigurations) { + if (launchConfig.getPrototype() == null) { + configs.add(launchConfig); + } + } + ILaunchConfiguration[] prototypes = getLaunchManager().getLaunchConfigurations(type, ILaunchConfiguration.PROTOTYPE); + for (ILaunchConfiguration prototype : prototypes) { + configs.add(prototype); + } + return configs.toArray(new ILaunchConfiguration[0]); + } else { + return getLaunchManager().getLaunchConfigurationTypes(); } - } else { - return getLaunchManager().getLaunchConfigurationTypes(); + } catch (CoreException e) { + DebugUIPlugin.errorDialog(getShell(), LaunchConfigurationsMessages.LaunchConfigurationDialog_Error_19, LaunchConfigurationsMessages.LaunchConfigurationDialog_An_exception_occurred_while_retrieving_launch_configurations_20, e); // } return EMPTY_ARRAY; } @@ -99,7 +113,12 @@ public class LaunchConfigurationTreeContentProvider implements ITreeContentProvi return null; } try { - return ((ILaunchConfiguration)element).getType(); + ILaunchConfiguration prototype = ((ILaunchConfiguration) element).getPrototype(); + if (prototype != null) { + return prototype; + } else { + return ((ILaunchConfiguration) element).getType(); + } } catch (CoreException e) { DebugUIPlugin.errorDialog(getShell(), LaunchConfigurationsMessages.LaunchConfigurationDialog_Error_19, LaunchConfigurationsMessages.LaunchConfigurationDialog_An_exception_occurred_while_retrieving_launch_configurations_20, e); // } @@ -115,6 +134,13 @@ public class LaunchConfigurationTreeContentProvider implements ITreeContentProvi @Override public boolean hasChildren(Object element) { if (element instanceof ILaunchConfiguration) { + if (((ILaunchConfiguration) element).isPrototype()) { + try { + return ((ILaunchConfiguration) element).getPrototypeChildren().size() > 0; + } catch (CoreException e) { + DebugUIPlugin.errorDialog(getShell(), LaunchConfigurationsMessages.LaunchConfigurationDialog_Error_19, LaunchConfigurationsMessages.LaunchConfigurationDialog_An_exception_occurred_while_retrieving_launch_configurations_20, e); // + } + } return false; } return getChildren(element).length > 0; diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationView.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationView.java index 73f7087c1..ab40eec23 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationView.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationView.java @@ -8,6 +8,7 @@ * Contributors: * IBM Corporation - initial API and implementation * Ian Pun (Red Hat Inc.) - Bug 518652 + * Axel Richard (Obeo) - Bug 41353 - Launch configurations prototypes *******************************************************************************/ package org.eclipse.debug.internal.ui.launchConfigurations; @@ -76,10 +77,14 @@ public class LaunchConfigurationView extends AbstractDebugView implements ILaunc * Actions */ private CreateLaunchConfigurationAction fCreateAction; + private CreateLaunchConfigurationPrototypeAction fCreatePrototypeAction; private DeleteLaunchConfigurationAction fDeleteAction; private DuplicateLaunchConfigurationAction fDuplicateAction; private ExportLaunchConfigurationAction fExportAction; private CollapseAllLaunchConfigurationAction fCollapseAllAction; + private LinkPrototypeAction fLinkPrototypeAction; + private UnlinkPrototypeAction fUnlinkPrototypeAction; + private ResetWithPrototypeValuesAction fResetWithPrototypeValuesAction; /** * Action for providing filtering to the Launch Configuration Dialog @@ -196,6 +201,9 @@ public class LaunchConfigurationView extends AbstractDebugView implements ILaunc fCreateAction = new CreateLaunchConfigurationAction(getViewer(), getLaunchGroup().getMode()); setAction(CreateLaunchConfigurationAction.ID_CREATE_ACTION, fCreateAction); + fCreatePrototypeAction = new CreateLaunchConfigurationPrototypeAction(getViewer(), getLaunchGroup().getMode()); + setAction(CreateLaunchConfigurationPrototypeAction.ID_CREATE_PROTOTYPE_ACTION, fCreatePrototypeAction); + fDeleteAction = new DeleteLaunchConfigurationAction(getViewer(), getLaunchGroup().getMode()); setAction(DeleteLaunchConfigurationAction.ID_DELETE_ACTION, fDeleteAction); setAction(IDebugView.REMOVE_ACTION, fDeleteAction); @@ -212,6 +220,14 @@ public class LaunchConfigurationView extends AbstractDebugView implements ILaunc fFilterAction = new FilterLaunchConfigurationAction(); setAction(FilterLaunchConfigurationAction.ID_FILTER_ACTION, fFilterAction); + fLinkPrototypeAction = new LinkPrototypeAction(getViewer(), getLaunchGroup().getMode()); + setAction(LinkPrototypeAction.ID_LINK_PROTOTYPE_ACTION, fLinkPrototypeAction); + + fUnlinkPrototypeAction = new UnlinkPrototypeAction(getViewer(), getLaunchGroup().getMode()); + setAction(UnlinkPrototypeAction.ID_UNLINK_PROTOTYPE_ACTION, fUnlinkPrototypeAction); + + fResetWithPrototypeValuesAction = new ResetWithPrototypeValuesAction(getViewer(), getLaunchGroup().getMode()); + setAction(ResetWithPrototypeValuesAction.ID_RESET_WITH_PROTOTYPE_VALUES_ACTION, fResetWithPrototypeValuesAction); } /** @@ -228,10 +244,14 @@ public class LaunchConfigurationView extends AbstractDebugView implements ILaunc @Override protected void fillContextMenu(IMenuManager menu) { menu.add(fCreateAction); + menu.add(fCreatePrototypeAction); menu.add(fExportAction); menu.add(fDuplicateAction); menu.add(fDeleteAction); menu.add(new Separator()); + menu.add(fLinkPrototypeAction); + menu.add(fUnlinkPrototypeAction); + menu.add(fResetWithPrototypeValuesAction); } /** @@ -255,11 +275,15 @@ public class LaunchConfigurationView extends AbstractDebugView implements ILaunc @Override public void dispose() { fCreateAction.dispose(); + fCreatePrototypeAction.dispose(); fDeleteAction.dispose(); fDuplicateAction.dispose(); fExportAction.dispose(); fFilterAction = null; fCollapseAllAction = null; + fLinkPrototypeAction.dispose(); + fUnlinkPrototypeAction.dispose(); + fResetWithPrototypeValuesAction.dispose(); getLaunchManager().removeLaunchConfigurationListener(this); } @@ -295,7 +319,11 @@ public class LaunchConfigurationView extends AbstractDebugView implements ILaunc if (viewer != null) { try { viewer.getControl().setRedraw(false); - viewer.add(configuration.getType(), configuration); + if (configuration.getPrototype() != null) { + viewer.add(configuration.getPrototype(), configuration); + } else { + viewer.add(configuration.getType(), configuration); + } // if moved, remove original now if (from != null) { viewer.remove(from); diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationsDialog.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationsDialog.java index 3d3a9d78a..e889e8d76 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationsDialog.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationsDialog.java @@ -9,6 +9,7 @@ * IBM Corporation - initial API and implementation * Sebastian Davids - Bug 137923 * Mohamed Hussein (Mentor Graphics) - Added s/getWarningMessage (Bug 386673) + * Axel Richard (Obeo) - Bug 41353 - Launch configurations prototypes *******************************************************************************/ package org.eclipse.debug.internal.ui.launchConfigurations; @@ -516,6 +517,7 @@ public class LaunchConfigurationsDialog extends TitleAreaDialog implements ILaun */ protected void createToolbarActions(ToolBarManager tmanager) { tmanager.add(getNewAction()); + tmanager.add(getNewPrototypeAction()); tmanager.add(getExportAction()); tmanager.add(getDuplicateAction()); tmanager.add(getDeleteAction()); @@ -617,14 +619,22 @@ public class LaunchConfigurationsDialog extends TitleAreaDialog implements ILaun getDuplicateAction().setConfirmationRequestor(requestor); getExportAction().setConfirmationRequestor(requestor); getNewAction().setConfirmationRequestor(requestor); + getNewPrototypeAction().setConfirmationRequestor(requestor); + getLinkPrototypeAction().setConfirmationRequestor(requestor); + getUnlinkPrototypeAction().setConfirmationRequestor(requestor); + getResetWithPrototypeValuesAction().setConfirmationRequestor(requestor); ((StructuredViewer) viewer).addPostSelectionChangedListener(new ISelectionChangedListener() { @Override public void selectionChanged(SelectionChangedEvent event) { handleLaunchConfigurationSelectionChanged(event); getNewAction().setEnabled(getNewAction().isEnabled()); + getNewPrototypeAction().setEnabled(getNewPrototypeAction().isEnabled()); getDeleteAction().setEnabled(getDeleteAction().isEnabled()); getExportAction().setEnabled(getExportAction().isEnabled()); getDuplicateAction().setEnabled(getDuplicateAction().isEnabled()); + getLinkPrototypeAction().setEnabled(getLinkPrototypeAction().isEnabled()); + getUnlinkPrototypeAction().setEnabled(getUnlinkPrototypeAction().isEnabled()); + getResetWithPrototypeValuesAction().setEnabled(getResetWithPrototypeValuesAction().isEnabled()); } }); return comp; @@ -874,6 +884,50 @@ public class LaunchConfigurationsDialog extends TitleAreaDialog implements ILaun return (AbstractLaunchConfigurationAction)fLaunchConfigurationView.getAction(CreateLaunchConfigurationAction.ID_CREATE_ACTION); } + /** + * Gets the new prototype menu action + * + * @return the new prototype menu action + * + * @since 3.13 + */ + protected AbstractLaunchConfigurationAction getNewPrototypeAction() { + return (AbstractLaunchConfigurationAction) fLaunchConfigurationView.getAction(CreateLaunchConfigurationPrototypeAction.ID_CREATE_PROTOTYPE_ACTION); + } + + /** + * Gets the link prototype menu action + * + * @return the link prototype menu action + * + * @since 3.13 + */ + protected AbstractLaunchConfigurationAction getLinkPrototypeAction() { + return (AbstractLaunchConfigurationAction) fLaunchConfigurationView.getAction(LinkPrototypeAction.ID_LINK_PROTOTYPE_ACTION); + } + + /** + * Gets the unlink prototype menu action + * + * @return the unlink prototype menu action + * + * @since 3.13 + */ + protected AbstractLaunchConfigurationAction getUnlinkPrototypeAction() { + return (AbstractLaunchConfigurationAction) fLaunchConfigurationView.getAction(UnlinkPrototypeAction.ID_UNLINK_PROTOTYPE_ACTION); + } + + /** + * Gets the reset with prototype values menu action + * + * @return the reset with prototype values menu action + * + * @since 3.13 + */ + protected AbstractLaunchConfigurationAction getResetWithPrototypeValuesAction() { + return (AbstractLaunchConfigurationAction) fLaunchConfigurationView.getAction(ResetWithPrototypeValuesAction.ID_RESET_WITH_PROTOTYPE_VALUES_ACTION); + } + /** * Returns the reserved name set (if there is one), null otherwise * @return the reserved name set or null @@ -1311,6 +1365,15 @@ public class LaunchConfigurationsDialog extends TitleAreaDialog implements ILaun updateButtons(); } + /** + * Refresh the launch configurations' tree viewer + * + * @since 3.13 + */ + protected void refreshLaunchConfigurationView() { + fLaunchConfigurationView.getTreeViewer().refresh(); + } + /** * resize the dialog to show all relevant content */ @@ -1604,6 +1667,9 @@ public class LaunchConfigurationsDialog extends TitleAreaDialog implements ILaun getExportAction().setEnabled(getExportAction().isEnabled()); getDeleteAction().setEnabled(getDeleteAction().isEnabled()); getDuplicateAction().setEnabled(getDuplicateAction().isEnabled()); + getLinkPrototypeAction().setEnabled(getLinkPrototypeAction().isEnabled()); + getUnlinkPrototypeAction().setEnabled(getUnlinkPrototypeAction().isEnabled()); + getResetWithPrototypeValuesAction().setEnabled(getResetWithPrototypeValuesAction().isEnabled()); fTabViewer.refresh(); getButton(ID_LAUNCH_BUTTON).setEnabled(fTabViewer.canLaunch() & fTabViewer.canLaunchWithModes() & !fTabViewer.hasDuplicateDelegates()); } else { diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationsMessages.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationsMessages.java index eacb87f84..8bbe5942a 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationsMessages.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationsMessages.java @@ -8,6 +8,7 @@ * Contributors: * IBM - Initial API and implementation * Ian Pun & Lucas Bullen (Red Hat Inc.) - Bug 518652 + * Axel Richard (Obeo) - Bug 41353 - Launch configurations prototypes *******************************************************************************/ package org.eclipse.debug.internal.ui.launchConfigurations; @@ -49,6 +50,15 @@ public class LaunchConfigurationsMessages extends NLS { public static String CommonTab_8; public static String CommonTab_9; + public static String CommonTab_AttributeLabel_ConsoleEncoding; + public static String CommonTab_AttributeLabel_CaptureOutput; + public static String CommonTab_AttributeLabel_CaptureInConsole; + public static String CommonTab_AttributeLabel_CaptureStdInFile; + public static String CommonTab_AttributeLabel_CaptureInFile; + public static String CommonTab_AttributeLabel_AppendToFile; + public static String CommonTab_AttributeLabel_LaunchInBackground; + public static String CommonTab_AttributeLabel_FavoriteGroups; + public static String CompileErrorProjectPromptStatusHandler_0; public static String CompileErrorProjectPromptStatusHandler_1; public static String CompileErrorPromptStatusHandler_0; @@ -140,6 +150,11 @@ public class LaunchConfigurationsMessages extends NLS { public static String CreateLaunchConfigurationAction_Ne_w_1; public static String ExportLaunchConfigurationAction_Export_1; public static String CreateLaunchConfigurationAction_New_configuration_2; + public static String CreateLaunchConfigurationPrototypeAction_Ne_w_1; + public static String CreateLaunchConfigurationPrototypeAction_New_prototype_2; + public static String LinkPrototypeAction_Link_prototype_1; + public static String UnlinkPrototypeAction_Unlink_prototype_1; + public static String ResetWithPrototypeValuesAction_Reset_with_prototype_values_1; public static String EnvironmentTab_Variable_1; public static String EnvironmentTab_Value_2; @@ -158,6 +173,21 @@ public class LaunchConfigurationsMessages extends NLS { public static String EnvironmentTab_18; public static String EnvironmentTab_19; public static String EnvironmentTab_20; + public static String EnvironmentTab_AttributeLabel_AppendEnvironmentVariables; + public static String EnvironmentTab_AttributeLabel_EnvironmentVariables; + + public static String PrototypeTab_Prototype_1; + public static String PrototypeTab_Label_2; + public static String PrototypeTab_Link_Button_Label_3; + public static String PrototypeTab_Unlink_Button_Label_4; + public static String PrototypeTab_Select_Message_5; + public static String PrototypeTab_Select_Empty_Message_6; + public static String PrototypeTab_Select_Prototype_Error_7; + public static String PrototypeTab_Reset_Button_Label_8; + public static String PrototypeTab_Reset_Menu_Action_9; + public static String PrototypeTab_Explanation_Label_10; + public static String PrototypeTab_Explanation_Label_11; + public static String PrototypeTab_Explanation_Label_12; public static String FavoritesDialog_1; public static String FavoritesDialog_2; @@ -189,7 +219,11 @@ public class LaunchConfigurationsMessages extends NLS { public static String LaunchConfigurationTabGroupViewer_3; public static String LaunchConfigurationTabGroupViewer_4; public static String LaunchConfigurationTabGroupViewer_5; - public static String LaunchConfigurationTabGroupViewer_6; + public static String LaunchConfigurationTabGroupViewer_6; + public static String LaunchConfigurationTabGroupViewer_9; + public static String LaunchConfigurationTabGroupViewer_10; + public static String LaunchConfigurationTabGroupViewer_11; + public static String LaunchConfigurationTabGroupViewer_12; public static String LaunchConfigurationTabGroupViewer_7; public static String SaveScopeResourcesHandler_1; @@ -200,9 +234,13 @@ public class LaunchConfigurationsMessages extends NLS { public static String LaunchConfigurationsDialog_0; public static String LaunchConfigurationsDialog_1; + public static String LaunchConfigurationsDialog_2; public static String LaunchConfigurationsDialog_4; public static String LaunchConfigurationsDialog_5; public static String LaunchConfigurationsDialog_6; + public static String LaunchConfigurationsDialog_7; + public static String LaunchConfigurationsDialog_8; + public static String LaunchConfigurationsDialog_9; public static String FilterLaunchConfigurationAction_0; diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationsMessages.properties b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationsMessages.properties index 72d08e819..c7451e5d9 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationsMessages.properties +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationsMessages.properties @@ -8,6 +8,7 @@ # Contributors: # IBM Corporation - initial API and implementation # Ian Pun & Lucas Bullen (Red Hat Inc.) - Bug 518652 +# Axel Richard (Obeo) - Bug 41353 - Launch configurations prototypes ############################################################################### CommonTab__Browse_6=&Browse... @@ -41,6 +42,14 @@ CommonTab_6=Output Fi&le: CommonTab_7=File &System... CommonTab_8=No file specified for process output CommonTab_9=Variables... +CommonTab_AttributeLabel_ConsoleEncoding=Console encoding +CommonTab_AttributeLabel_CaptureOutput=Capture output +CommonTab_AttributeLabel_CaptureInConsole=Capture in console +CommonTab_AttributeLabel_CaptureStdInFile=Capture standard input file +CommonTab_AttributeLabel_CaptureInFile=Capture in file +CommonTab_AttributeLabel_AppendToFile=Append to file +CommonTab_AttributeLabel_LaunchInBackground=Launch in background +CommonTab_AttributeLabel_FavoriteGroups=Favorite groups CompileErrorPromptStatusHandler_0=Errors in Workspace CompileErrorPromptStatusHandler_1=Errors exist in a required project. Continue launch? @@ -56,13 +65,17 @@ LaunchConfigurationDialog__Name__16=&Name: LaunchConfigurationDialog_An_exception_occurred_while_retrieving_launch_configurations_20=An exception occurred while retrieving launch configurations LaunchConfigurationTabGroupViewer_1=Configure launch settings from this dialog: -LaunchConfigurationTabGroupViewer_2=- Press the 'New' button to create a configuration of the selected type. +LaunchConfigurationTabGroupViewer_2=- Press the 'New configuration' button to create a configuration of the selected type. LaunchConfigurationTabGroupViewer_3=- Edit or view an existing configuration by selecting it. LaunchConfigurationTabGroupViewer_4=- Press the 'Delete' button to remove the selected configuration. LaunchConfigurationTabGroupViewer_6=- Press the 'Duplicate' button to copy the selected configuration. LaunchConfigurationTabGroupViewer_5=Configure launch perspective settings from the 'Perspectives' preference page. LaunchConfigurationTabGroupViewer_7=- Press the 'Export' button to export the selected configurations. LaunchConfigurationTabGroupViewer_8=- Press the 'Filter' button to configure filtering options. +LaunchConfigurationTabGroupViewer_9=- Press the 'New prototype' button to create a launch configuration prototype of the selected type. +LaunchConfigurationTabGroupViewer_10=- Select launch configuration(s) and then select 'Link prototype' menu item to link a prototype. +LaunchConfigurationTabGroupViewer_11=- Select launch configuration(s) and then select 'Unlink prototype' menu item to unlink a prototype. +LaunchConfigurationTabGroupViewer_12=- Select launch configuration(s) and then select 'Reset with prototype values' menu item to reset with prototype values. LaunchConfigurationTabGroupViewer_13=Select a supported launch mode. LaunchConfigurationTabGroupViewer_14=This configuration does not support some of the launch modes: {0} LaunchConfigurationTabGroupViewer_15=More than one launcher available - Select other... @@ -104,9 +117,13 @@ LaunchConfigurationsDialog_Warning_2=Warning LaunchConfigurationsDialog_Information_3=Information LaunchConfigurationsDialog_0=New launch configuration LaunchConfigurationsDialog_1=Delete selected launch configuration(s) +LaunchConfigurationsDialog_2=New launch configuration prototype LaunchConfigurationsDialog_4=Filter launch configurations... LaunchConfigurationsDialog_5=Duplicates the currently selected launch configuration LaunchConfigurationsDialog_6=Export launch configuration +LaunchConfigurationsDialog_7=Link prototype +LaunchConfigurationsDialog_8=Unlink prototype +LaunchConfigurationsDialog_9=Reset with prototype values LaunchConfigurationSelectionDialog_0=Select Configuration LaunchConfigurationSelectionDialog_1=&Select a configuration to launch: LaunchConfigurationView_0=Filter matched {0} of {1} items @@ -150,9 +167,14 @@ DuplicateLaunchConfigurationAction__Duplicate_1=&Duplicate DeleteLaunchConfigurationAction_Dele_te_1=Dele&te -CreateLaunchConfigurationAction_Ne_w_1=Ne&w +CreateLaunchConfigurationAction_Ne_w_1=Ne&w configuration ExportLaunchConfigurationAction_Export_1=E&xport CreateLaunchConfigurationAction_New_configuration_2=New_configuration +CreateLaunchConfigurationPrototypeAction_Ne_w_1=New &prototype +CreateLaunchConfigurationPrototypeAction_New_prototype_2=New_prototype +LinkPrototypeAction_Link_prototype_1=&Link prototype +UnlinkPrototypeAction_Unlink_prototype_1=&Unlink prototype +ResetWithPrototypeValuesAction_Reset_with_prototype_values_1=&Reset with prototype values EnvironmentTab_Variable_1=Variable EnvironmentTab_Value_2=Value @@ -177,6 +199,22 @@ EnvironmentTab_17=Re&place native environment with specified environment EnvironmentTab_18=Se&lect... EnvironmentTab_19=Select &environment variables to add: EnvironmentTab_20=Select Environment Variables +EnvironmentTab_AttributeLabel_AppendEnvironmentVariables=Append environment to native environment +EnvironmentTab_AttributeLabel_EnvironmentVariables=Environment variables + +#PrototypeTab +PrototypeTab_Prototype_1=Prototype +PrototypeTab_Label_2=Prototype: +PrototypeTab_Link_Button_Label_3=Link... +PrototypeTab_Unlink_Button_Label_4=Unlink +PrototypeTab_Select_Message_5=Please select a prototype +PrototypeTab_Select_Empty_Message_6=You have to select a prototype +PrototypeTab_Select_Prototype_Error_7=The prototype doesn't exists. Please select a valid prototype. +PrototypeTab_Reset_Button_Label_8=Reset +PrototypeTab_Reset_Menu_Action_9=Reset selected checked attribute(s) with prototype value(s) +PrototypeTab_Explanation_Label_10=- Values of checked attributes from prototype are applied on associated launch configurations. +PrototypeTab_Explanation_Label_11=- Values of unchecked attributes from prototype are not applied on associated launch configurations. +PrototypeTab_Explanation_Label_12=- Grayed state attributes have different values in the launch configuration and the associated prototype. FavoritesDialog_1=Organize {0} Favorites FavoritesDialog_2=Fa&vorites: diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LinkPrototypeAction.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LinkPrototypeAction.java new file mode 100644 index 000000000..a1b28b72d --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LinkPrototypeAction.java @@ -0,0 +1,159 @@ +/******************************************************************************* + * Copyright (c) 2017 Obeo. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Obeo - initial API and implementation + *******************************************************************************/ +package org.eclipse.debug.internal.ui.launchConfigurations; + +import java.util.Collection; +import java.util.HashSet; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.debug.core.ILaunchConfiguration; +import org.eclipse.debug.core.ILaunchConfigurationType; +import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; +import org.eclipse.debug.internal.ui.DebugUIPlugin; +import org.eclipse.debug.internal.ui.IInternalDebugUIConstants; +import org.eclipse.debug.ui.DebugUITools; +import org.eclipse.debug.ui.ILaunchConfigurationDialog; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.viewers.DecoratingLabelProvider; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.jface.window.Window; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.dialogs.ElementListSelectionDialog; + +/** + * Link attributes from a prototype to the selected launch configuration(s). + * + * @since 3.13 + */ +public class LinkPrototypeAction extends AbstractLaunchConfigurationAction { + + /** + * Action identifier for IDebugView#getAction(String) + */ + public static final String ID_LINK_PROTOTYPE_ACTION = DebugUIPlugin.getUniqueIdentifier() + ".ID_LINK_PROTOTYPE_ACTION"; //$NON-NLS-1$ + + /** + * Constructs an action to apply a prototype to a launch configuration + * + * @param viewer the viewer + * @param mode the mode the action applies to + */ + public LinkPrototypeAction(Viewer viewer, String mode) { + super(LaunchConfigurationsMessages.LinkPrototypeAction_Link_prototype_1, viewer, mode); + } + + /** + * @see AbstractLaunchConfigurationAction#performAction() + */ + @Override + protected void performAction() { + try { + ILaunchConfiguration firstLaunchConfiguration = (ILaunchConfiguration) getStructuredSelection().getFirstElement(); + ILaunchConfigurationType type = firstLaunchConfiguration.getType(); + ILaunchConfiguration[] prototypes = type.getPrototypes(); + // Select the prototype + DecoratingLabelProvider labelProvider = new DecoratingLabelProvider(DebugUITools.newDebugModelPresentation(), PlatformUI.getWorkbench().getDecoratorManager().getLabelDecorator()); + ElementListSelectionDialog selectPrototypeDialog = new ElementListSelectionDialog(getShell(), labelProvider); + selectPrototypeDialog.setElements(prototypes); + selectPrototypeDialog.setMultipleSelection(false); + selectPrototypeDialog.setEmptySelectionMessage("You have to select a prototype."); //$NON-NLS-1$ + selectPrototypeDialog.setTitle("Please select a prototype"); //$NON-NLS-1$ + int open = selectPrototypeDialog.open(); + if (open == Window.OK) { + Object selectedPrototype = selectPrototypeDialog.getFirstResult(); + for (Object launchConfiguration : getStructuredSelection().toList()) { + if (launchConfiguration instanceof ILaunchConfiguration) { + // Link the prototype attributes to the selected launch + // configuration + ILaunchConfigurationWorkingCopy workingCopy = ((ILaunchConfiguration) launchConfiguration).getWorkingCopy(); + workingCopy.setPrototype((ILaunchConfiguration) selectedPrototype, true); + workingCopy.doSave(); + // if only one configuration is selected, refresh the + // tabs to display visible attributes values from the + // prototype + if (getStructuredSelection().size() == 1) { + ILaunchConfigurationDialog dialog = LaunchConfigurationsDialog.getCurrentlyVisibleLaunchConfigurationDialog(); + if (dialog instanceof LaunchConfigurationsDialog) { + ((LaunchConfigurationsDialog) dialog).getTabViewer().setInput(workingCopy); + } + } + } + } + getViewer().refresh(); + } + } catch (CoreException e) { + errorDialog(e); + } + } + + /** + * @see org.eclipse.ui.actions.SelectionListenerAction#updateSelection(org.eclipse.jface.viewers.IStructuredSelection) + */ + @Override + protected boolean updateSelection(IStructuredSelection selection) { + // Enable action only if launch configuration(s) of the same type + // is(are) selected and the launch configuration type allows prototypes + Collection launchConfigurationTypes = new HashSet<>(); + for (Object object : selection.toList()) { + if (object instanceof ILaunchConfiguration) { + if (((ILaunchConfiguration) object).isPrototype()) { + return false; + } else { + ILaunchConfigurationType type = null; + try { + type = ((ILaunchConfiguration) object).getType(); + } catch (CoreException e) { + DebugUIPlugin.log(e.getStatus()); + } + if (type != null) { + launchConfigurationTypes.add(type); + } else { + return false; + } + } + } else { + return false; + } + } + if (launchConfigurationTypes.size() == 1) { + return launchConfigurationTypes.iterator().next().supportsPrototypes(); + } + return false; + } + + /* + * (non-Javadoc) + * @see org.eclipse.jface.action.Action#getDisabledImageDescriptor() + */ + @Override + public ImageDescriptor getDisabledImageDescriptor() { + return DebugUITools.getImageDescriptor(IInternalDebugUIConstants.IMG_DLCL_LINK_PROTO); + } + + /* + * (non-Javadoc) + * @see org.eclipse.jface.action.Action#getImageDescriptor() + */ + @Override + public ImageDescriptor getImageDescriptor() { + return DebugUITools.getImageDescriptor(IInternalDebugUIConstants.IMG_ELCL_LINK_PROTO); + } + + /* + * (non-Javadoc) + * @see org.eclipse.jface.action.Action#getToolTipText() + */ + @Override + public String getToolTipText() { + return LaunchConfigurationsMessages.LaunchConfigurationsDialog_7; + } +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/ResetWithPrototypeValuesAction.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/ResetWithPrototypeValuesAction.java new file mode 100644 index 000000000..944182212 --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/ResetWithPrototypeValuesAction.java @@ -0,0 +1,129 @@ +/******************************************************************************* + * Copyright (c) 2017 Obeo. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Obeo - initial API and implementation + *******************************************************************************/ +package org.eclipse.debug.internal.ui.launchConfigurations; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.debug.core.ILaunchConfiguration; +import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; +import org.eclipse.debug.internal.ui.DebugUIPlugin; +import org.eclipse.debug.internal.ui.IInternalDebugUIConstants; +import org.eclipse.debug.ui.DebugUITools; +import org.eclipse.debug.ui.ILaunchConfigurationDialog; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.Viewer; + +/** + * Reset selected launch configuration(s) attributes with values from associated + * prototype(s). + * + * @since 3.13 + */ +public class ResetWithPrototypeValuesAction extends AbstractLaunchConfigurationAction { + + /** + * Action identifier for IDebugView#getAction(String) + */ + public static final String ID_RESET_WITH_PROTOTYPE_VALUES_ACTION = DebugUIPlugin.getUniqueIdentifier() + ".ID_RESET_WITH_PROTOTYPE_VALUES_ACTION"; //$NON-NLS-1$ + + /** + * Constructs an action to reset a launch configuration with prototype + * values + * + * @param viewer the viewer + * @param mode the mode the action applies to + */ + public ResetWithPrototypeValuesAction(Viewer viewer, String mode) { + super(LaunchConfigurationsMessages.ResetWithPrototypeValuesAction_Reset_with_prototype_values_1, viewer, mode); + } + + /** + * @see AbstractLaunchConfigurationAction#performAction() + */ + @Override + protected void performAction() { + try { + for (Object launchConfiguration : getStructuredSelection().toList()) { + if (launchConfiguration instanceof ILaunchConfiguration) { + ILaunchConfigurationWorkingCopy workingCopy = ((ILaunchConfiguration) launchConfiguration).getWorkingCopy(); + workingCopy.setPrototype(((ILaunchConfiguration) launchConfiguration).getPrototype(), true); + workingCopy.doSave(); + // if only one configuration is selected, refresh the + // tabs to display visible attributes values from the + // prototype + if (getStructuredSelection().size() == 1) { + ILaunchConfigurationDialog dialog = LaunchConfigurationsDialog.getCurrentlyVisibleLaunchConfigurationDialog(); + if (dialog instanceof LaunchConfigurationsDialog) { + ((LaunchConfigurationsDialog) dialog).getTabViewer().setInput(workingCopy); + } + } + } + } + } catch (CoreException e) { + errorDialog(e); + } + } + + /** + * @see org.eclipse.ui.actions.SelectionListenerAction#updateSelection(org.eclipse.jface.viewers.IStructuredSelection) + */ + @Override + protected boolean updateSelection(IStructuredSelection selection) { + boolean onlyLaunchConfigurationWithPrototypeSelected = false; + for (Object object : selection.toList()) { + if (object instanceof ILaunchConfiguration) { + if (((ILaunchConfiguration) object).isPrototype()) { + return false; + } else { + try { + if (((ILaunchConfiguration) object).getPrototype() != null) { + onlyLaunchConfigurationWithPrototypeSelected = true; + } else { + return false; + } + } catch (CoreException e) { + DebugUIPlugin.log(e.getStatus()); + } + } + } else { + return false; + } + } + return onlyLaunchConfigurationWithPrototypeSelected; + } + + /* + * (non-Javadoc) + * @see org.eclipse.jface.action.Action#getDisabledImageDescriptor() + */ + @Override + public ImageDescriptor getDisabledImageDescriptor() { + return DebugUITools.getImageDescriptor(IInternalDebugUIConstants.IMG_DLCL_RESET_PROTO); + } + + /* + * (non-Javadoc) + * @see org.eclipse.jface.action.Action#getImageDescriptor() + */ + @Override + public ImageDescriptor getImageDescriptor() { + return DebugUITools.getImageDescriptor(IInternalDebugUIConstants.IMG_ELCL_RESET_PROTO); + } + + /* + * (non-Javadoc) + * @see org.eclipse.jface.action.Action#getToolTipText() + */ + @Override + public String getToolTipText() { + return LaunchConfigurationsMessages.LaunchConfigurationsDialog_9; + } +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/UnlinkPrototypeAction.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/UnlinkPrototypeAction.java new file mode 100644 index 000000000..f1cbc5d50 --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/UnlinkPrototypeAction.java @@ -0,0 +1,128 @@ +/******************************************************************************* + * Copyright (c) 2017 Obeo. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Obeo - initial API and implementation + *******************************************************************************/ +package org.eclipse.debug.internal.ui.launchConfigurations; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.debug.core.ILaunchConfiguration; +import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; +import org.eclipse.debug.internal.ui.DebugUIPlugin; +import org.eclipse.debug.internal.ui.IInternalDebugUIConstants; +import org.eclipse.debug.ui.DebugUITools; +import org.eclipse.debug.ui.ILaunchConfigurationDialog; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.Viewer; + +/** + * Unlink prototype to the selected launch configuration(s). + * + * @since 3.13 + */ +public class UnlinkPrototypeAction extends AbstractLaunchConfigurationAction { + + /** + * Action identifier for IDebugView#getAction(String) + */ + public static final String ID_UNLINK_PROTOTYPE_ACTION = DebugUIPlugin.getUniqueIdentifier() + ".ID_UNLINK_PROTOTYPE_ACTION"; //$NON-NLS-1$ + + /** + * Constructs an action to unlink a prototype to a launch configuration + * + * @param viewer the viewer + * @param mode the mode the action applies to + */ + public UnlinkPrototypeAction(Viewer viewer, String mode) { + super(LaunchConfigurationsMessages.UnlinkPrototypeAction_Unlink_prototype_1, viewer, mode); + } + + /** + * @see AbstractLaunchConfigurationAction#performAction() + */ + @Override + protected void performAction() { + try { + for (Object launchConfiguration : getStructuredSelection().toList()) { + if (launchConfiguration instanceof ILaunchConfiguration) { + ILaunchConfigurationWorkingCopy workingCopy = ((ILaunchConfiguration) launchConfiguration).getWorkingCopy(); + workingCopy.setPrototype(null, false); + workingCopy.doSave(); + // if only one configuration is selected, refresh the + // tabs to display visible attributes values from the + // prototype + if (getStructuredSelection().size() == 1) { + ILaunchConfigurationDialog dialog = LaunchConfigurationsDialog.getCurrentlyVisibleLaunchConfigurationDialog(); + if (dialog instanceof LaunchConfigurationsDialog) { + ((LaunchConfigurationsDialog) dialog).getTabViewer().setInput(workingCopy); + } + } + } + } + getViewer().refresh(); + } catch (CoreException e) { + errorDialog(e); + } + } + + /** + * @see org.eclipse.ui.actions.SelectionListenerAction#updateSelection(org.eclipse.jface.viewers.IStructuredSelection) + */ + @Override + protected boolean updateSelection(IStructuredSelection selection) { + boolean onlyLaunchConfigurationWithPrototypeSelected = false; + for (Object object : selection.toList()) { + if (object instanceof ILaunchConfiguration) { + if (((ILaunchConfiguration) object).isPrototype()) { + return false; + } else { + try { + if (((ILaunchConfiguration) object).getPrototype() != null) { + onlyLaunchConfigurationWithPrototypeSelected = true; + } else { + return false; + } + } catch (CoreException e) { + DebugUIPlugin.log(e.getStatus()); + } + } + } else { + return false; + } + } + return onlyLaunchConfigurationWithPrototypeSelected; + } + + /* + * (non-Javadoc) + * @see org.eclipse.jface.action.Action#getDisabledImageDescriptor() + */ + @Override + public ImageDescriptor getDisabledImageDescriptor() { + return DebugUITools.getImageDescriptor(IInternalDebugUIConstants.IMG_DLCL_UNLINK_PROTO); + } + + /* + * (non-Javadoc) + * @see org.eclipse.jface.action.Action#getImageDescriptor() + */ + @Override + public ImageDescriptor getImageDescriptor() { + return DebugUITools.getImageDescriptor(IInternalDebugUIConstants.IMG_ELCL_UNLINK_PROTO); + } + + /* + * (non-Javadoc) + * @see org.eclipse.jface.action.Action#getToolTipText() + */ + @Override + public String getToolTipText() { + return LaunchConfigurationsMessages.LaunchConfigurationsDialog_8; + } +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/sourcelookup/SourceLookupUIMessages.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/sourcelookup/SourceLookupUIMessages.java index a4e9ef95e..696d7c0b3 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/sourcelookup/SourceLookupUIMessages.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/sourcelookup/SourceLookupUIMessages.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2003, 2009 IBM Corporation and others. + * Copyright (c) 2003, 2017 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -8,6 +8,7 @@ * Contributors: * IBM - Initial API and implementation * QNX Software Systems - Mikhail Khodjaiants - Bug 114664 + * Axel Richard (Obeo) - Bug 41353 - Launch configurations prototypes *******************************************************************************/ package org.eclipse.debug.internal.ui.sourcelookup; @@ -37,6 +38,9 @@ public class SourceLookupUIMessages extends NLS { public static String sourceTab_tabTitle; public static String sourceTab_defaultButton; + public static String sourceTab_AttributeLabel_SourceLocatorMemento; + public static String sourceTab_AttributeLabel_SourceLocatorID; + public static String addSourceLocation_title; public static String addSourceLocation_description; diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/sourcelookup/SourceLookupUIMessages.properties b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/sourcelookup/SourceLookupUIMessages.properties index 5c56dd2f3..3158c2f3d 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/sourcelookup/SourceLookupUIMessages.properties +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/sourcelookup/SourceLookupUIMessages.properties @@ -1,5 +1,5 @@ ############################################################################### -# Copyright (c) 2003, 2013 IBM Corporation and others. +# Copyright (c) 2003, 2017 IBM Corporation and others. # All rights reserved. This program and the accompanying materials # are made available under the terms of the Eclipse Public License v1.0 # which accompanies this distribution, and is available at @@ -8,6 +8,7 @@ # Contributors: # IBM Corporation - initial API and implementation # QNX Software Systems - Mikhail Khodjaiants - Bug 114664 +# Axel Richard (Obeo) - Bug 41353 - Launch configurations prototypes ############################################################################### # Source search launch configuration tab/errors/dialogs @@ -21,6 +22,9 @@ sourceTab_addButton = &Add... sourceTab_tabTitle = Source sourceTab_defaultButton = Restore Defa&ult +sourceTab_AttributeLabel_SourceLocatorMemento=Source locator memento +sourceTab_AttributeLabel_SourceLocatorID=Source locator ID + addSourceLocation_title = Add Source addSourceLocation_description = Add a container to the source lookup path diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/AbstractLaunchConfigurationTab.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/AbstractLaunchConfigurationTab.java index 5503ed937..cbe4e76f3 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/AbstractLaunchConfigurationTab.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/AbstractLaunchConfigurationTab.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2013 IBM Corporation and others. + * Copyright (c) 2000, 2017 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -8,10 +8,14 @@ * Contributors: * IBM Corporation - initial API and implementation * Mohamed Hussein (Mentor Graphics) - Added s/getWarningMessage (Bug 386673) + * Axel Richard (Obeo) - Bug 41353 - Launch configurations prototypes *******************************************************************************/ package org.eclipse.debug.ui; +import java.util.HashMap; +import java.util.Map; + import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; @@ -21,6 +25,7 @@ import org.eclipse.debug.core.ILaunch; import org.eclipse.debug.core.ILaunchConfiguration; import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; import org.eclipse.debug.core.ILaunchManager; +import org.eclipse.debug.core.IPrototypeAttributesLabelProvider; import org.eclipse.debug.internal.ui.SWTFactory; import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Image; @@ -40,7 +45,7 @@ import org.eclipse.ui.progress.WorkbenchJob; * @see ILaunchConfigurationTab * @since 2.0 */ -public abstract class AbstractLaunchConfigurationTab implements ILaunchConfigurationTab2 { +public abstract class AbstractLaunchConfigurationTab implements ILaunchConfigurationTab2, IPrototypeAttributesLabelProvider { /** * The control for this page, or null @@ -92,8 +97,46 @@ public abstract class AbstractLaunchConfigurationTab implements ILaunchConfigura private String fHelpContextId = null; /** - * Returns the dialog this tab is contained in, or - * null if not yet set. + * Attributes labels for prototype tab. + * + * @since 3.13 + */ + private Map fAttributesLabelsForPrototype; + + /** + * Default constructor. + * + * @since 3.13 + */ + public AbstractLaunchConfigurationTab() { + fAttributesLabelsForPrototype = new HashMap<>(); + initializeAttributes(); + } + + /** + * Initialize attributes labels. + * + * @since 3.13 + */ + protected void initializeAttributes() { + } + + /* + * (non-Javadoc) + * @see org.eclipse.debug.core.IPrototypeAttributesLabelProvider#getLabel(java.lang.String) + */ + @Override + public String getAttributeLabel(String attribute) { + String label = fAttributesLabelsForPrototype.get(attribute); + if (label != null) { + return label; + } + return null; + } + + /** + * Returns the dialog this tab is contained in, or null if not + * yet set. * * @return launch configuration dialog, or null */ @@ -513,5 +556,15 @@ public abstract class AbstractLaunchConfigurationTab implements ILaunchConfigura public String getHelpContextId() { return fHelpContextId; } + + /** + * Get the attributes labels for prototype tab. + * + * @return the attributes labels for prototype tab. + * @since 3.13 + */ + protected Map getAttributesLabelsForPrototype() { + return fAttributesLabelsForPrototype; + } } diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/CommonTab.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/CommonTab.java index 6ed04e176..1c482fd7e 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/CommonTab.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/CommonTab.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2015 IBM Corporation and others. + * Copyright (c) 2000, 2017 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -8,6 +8,7 @@ * Contributors: * IBM Corporation - initial API and implementation * Stephan Wahlbrink - Bug 471829 + * Axel Richard (Obeo) - Bug 41353 - Launch configurations prototypes *******************************************************************************/ package org.eclipse.debug.ui; @@ -160,6 +161,7 @@ public class CommonTab extends AbstractLaunchConfigurationTab { * Constructs a new tab with default context help. */ public CommonTab() { + super(); setHelpContextId(IDebugHelpContextIds.LAUNCH_CONFIGURATION_DIALOG_COMMON_TAB); } @@ -1101,6 +1103,24 @@ public class CommonTab extends AbstractLaunchConfigurationTab { @Override public void deactivated(ILaunchConfigurationWorkingCopy workingCopy) {} + /* + * (non-Javadoc) + * @see org.eclipse.debug.ui.AbstractLaunchConfigurationTab#initializeAttributes() + * @since 3.13 + */ + @Override + protected void initializeAttributes() { + super.initializeAttributes(); + getAttributesLabelsForPrototype().put(DebugPlugin.ATTR_CONSOLE_ENCODING, LaunchConfigurationsMessages.CommonTab_AttributeLabel_ConsoleEncoding); + getAttributesLabelsForPrototype().put(DebugPlugin.ATTR_CAPTURE_OUTPUT, LaunchConfigurationsMessages.CommonTab_AttributeLabel_CaptureOutput); + getAttributesLabelsForPrototype().put(IDebugUIConstants.ATTR_CAPTURE_IN_CONSOLE, LaunchConfigurationsMessages.CommonTab_AttributeLabel_CaptureInConsole); + getAttributesLabelsForPrototype().put(IDebugUIConstants.ATTR_CAPTURE_STDIN_FILE, LaunchConfigurationsMessages.CommonTab_AttributeLabel_CaptureStdInFile); + getAttributesLabelsForPrototype().put(IDebugUIConstants.ATTR_CAPTURE_IN_FILE, LaunchConfigurationsMessages.CommonTab_AttributeLabel_CaptureInFile); + getAttributesLabelsForPrototype().put(IDebugUIConstants.ATTR_APPEND_TO_FILE, LaunchConfigurationsMessages.CommonTab_AttributeLabel_AppendToFile); + getAttributesLabelsForPrototype().put(IDebugUIConstants.ATTR_LAUNCH_IN_BACKGROUND, LaunchConfigurationsMessages.CommonTab_AttributeLabel_LaunchInBackground); + getAttributesLabelsForPrototype().put(IDebugUIConstants.ATTR_FAVORITE_GROUPS, LaunchConfigurationsMessages.CommonTab_AttributeLabel_FavoriteGroups); + } + /** * Content provider for the favorites table */ diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/EnvironmentTab.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/EnvironmentTab.java index b307bcf90..b19a779ac 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/EnvironmentTab.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/EnvironmentTab.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2013 Keith Seitz and others. + * Copyright (c) 2000, 2017 Keith Seitz and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -9,6 +9,7 @@ * Keith Seitz (keiths@redhat.com) - initial implementation * IBM Corporation - integration and code cleanup * Jan Opacki (jan.opacki@gmail.com) bug 307139 + * Axel Richard (Obeo) - Bug 41353 - Launch configurations prototypes *******************************************************************************/ package org.eclipse.debug.ui; @@ -191,6 +192,7 @@ public class EnvironmentTab extends AbstractLaunchConfigurationTab { * Constructs a new tab with default context help. */ public EnvironmentTab() { + super(); setHelpContextId(IDebugHelpContextIds.LAUNCH_CONFIGURATION_DIALOG_ENVIRONMENT_TAB); } @@ -603,6 +605,18 @@ public class EnvironmentTab extends AbstractLaunchConfigurationTab { // do nothing when deactivated } + /* + * (non-Javadoc) + * @see org.eclipse.debug.ui.AbstractLaunchConfigurationTab#initializeAttributes() + * @since 3.13 + */ + @Override + protected void initializeAttributes() { + super.initializeAttributes(); + getAttributesLabelsForPrototype().put(ILaunchManager.ATTR_APPEND_ENVIRONMENT_VARIABLES, LaunchConfigurationsMessages.EnvironmentTab_AttributeLabel_AppendEnvironmentVariables); + getAttributesLabelsForPrototype().put(ILaunchManager.ATTR_ENVIRONMENT_VARIABLES, LaunchConfigurationsMessages.EnvironmentTab_AttributeLabel_EnvironmentVariables); + } + /** * This dialog allows users to select one or more known native environment variables from a list. */ diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/IDebugUIConstants.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/IDebugUIConstants.java index 04659d962..467afa298 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/IDebugUIConstants.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/IDebugUIConstants.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2014 IBM Corporation and others. + * Copyright (c) 2000, 2017 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -9,6 +9,7 @@ * IBM Corporation - initial API and implementation * QNX Software Systems - Mikhail Khodjaiants - Registers View (Bug 53640) * Wind River Systems - Pawel Piech - Added Modules view (bug 211158) + * Axel Richard (Obeo) - Bug 41353 - Launch configurations prototypes *******************************************************************************/ package org.eclipse.debug.ui; @@ -618,6 +619,13 @@ public interface IDebugUIConstants { */ public static final String IMG_OVR_SKIP_BREAKPOINT = "IMG_OVR_SKIP_BREAKPOINT"; //$NON-NLS-1$ + /** + * Prototype image overlay identifier. + * + * @since 3.13 + */ + public static final String IMG_OVR_PROTOTYPE = "IMG_OVR_PROTOTYPE"; //$NON-NLS-1$ + /** * Debug action set identifier (value "org.eclipse.debug.ui.debugActionSet"). */ diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/PrototypeDecorator.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/PrototypeDecorator.java new file mode 100644 index 000000000..e39b2dc2f --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/PrototypeDecorator.java @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2017 Obeo. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Obeo - initial API and implementation + *******************************************************************************/ +package org.eclipse.debug.ui; + +import org.eclipse.debug.core.ILaunchConfiguration; +import org.eclipse.debug.internal.core.LaunchConfiguration; +import org.eclipse.jface.viewers.IDecoration; +import org.eclipse.jface.viewers.ILabelProviderListener; +import org.eclipse.jface.viewers.ILightweightLabelDecorator; + +/** + * Decorator for {@link ILaunchConfiguration} prototypes. + * + * @since 3.13 + * + */ +public class PrototypeDecorator implements ILightweightLabelDecorator { + + @Override + public void addListener(ILabelProviderListener listener) { + } + + @Override + public void dispose() { + } + + @Override + public boolean isLabelProperty(Object element, String property) { + return false; + } + + @Override + public void removeListener(ILabelProviderListener listener) { + } + + @Override + public void decorate(Object element, IDecoration decoration) { + if (element instanceof LaunchConfiguration) { + if (((LaunchConfiguration) element).isPrototype()) { + decoration.addOverlay(DebugUITools.getImageDescriptor(IDebugUIConstants.IMG_OVR_PROTOTYPE)); + } + } + } +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/ProtoypeTab.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/ProtoypeTab.java new file mode 100644 index 000000000..84d243876 --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/ProtoypeTab.java @@ -0,0 +1,760 @@ +/******************************************************************************* + * Copyright (c) 2017 Obeo. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Obeo - initial API and implementation + *******************************************************************************/ +package org.eclipse.debug.ui; + +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; +import java.util.stream.Collectors; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.debug.core.ILaunchConfiguration; +import org.eclipse.debug.core.ILaunchConfigurationType; +import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; +import org.eclipse.debug.internal.core.LaunchConfiguration; +import org.eclipse.debug.internal.ui.DebugUIPlugin; +import org.eclipse.debug.internal.ui.IDebugHelpContextIds; +import org.eclipse.debug.internal.ui.IInternalDebugUIConstants; +import org.eclipse.debug.internal.ui.SWTFactory; +import org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationsMessages; +import org.eclipse.jface.action.Action; +import org.eclipse.jface.action.IMenuListener; +import org.eclipse.jface.action.IMenuManager; +import org.eclipse.jface.action.MenuManager; +import org.eclipse.jface.fieldassist.ControlDecoration; +import org.eclipse.jface.fieldassist.FieldDecoration; +import org.eclipse.jface.fieldassist.FieldDecorationRegistry; +import org.eclipse.jface.viewers.CheckStateChangedEvent; +import org.eclipse.jface.viewers.CheckboxTreeViewer; +import org.eclipse.jface.viewers.ColumnLabelProvider; +import org.eclipse.jface.viewers.DecoratingLabelProvider; +import org.eclipse.jface.viewers.ICheckStateListener; +import org.eclipse.jface.viewers.ICheckStateProvider; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.ITreeContentProvider; +import org.eclipse.jface.viewers.TreeViewerColumn; +import org.eclipse.jface.window.Window; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Menu; +import org.eclipse.swt.widgets.Text; +import org.eclipse.swt.widgets.Tree; +import org.eclipse.swt.widgets.TreeColumn; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.dialogs.ElementListSelectionDialog; + +/** + * Launch configuration tab used to specify the prototype associated with a + * launch configuration, and also listed attributes from prototype shared with + * the launch configuration. + *

+ * Clients may call {@link #setHelpContextId(String)} on this tab prior to + * control creation to alter the default context help associated with this tab. + *

+ *

+ * Clients may instantiate this class only if the associated launch + * configuration type allows prototypes. + * + * @see ILaunchConfigurationType#supportsPrototypes() + *

+ * + * @since 3.13 + * @noextend This class is not intended to be subclassed by clients. + */ +public class ProtoypeTab extends AbstractLaunchConfigurationTab { + + private static final String PROTOTYPE_TAB_ID = "org.eclipse.debug.ui.prototypeTab"; //$NON-NLS-1$ + + private static final String ATTRIBUTE = "Attribute"; //$NON-NLS-1$ + + private static final String MODIFIED = "Modified"; //$NON-NLS-1$ + + private static final String PROTOTYPE_VALUE = "Prototype Value"; //$NON-NLS-1$ + + private ILaunchConfiguration fSelectedLaunchConfiguration; + + private ILaunchConfiguration fAppliedPrototype; + + private Composite fPrototypeComposite; + + private Text fPrototypeText; + + private ControlDecoration fPrototypeTextDecoration; + + private Button fLinkPrototypeButton; + + private Button fUnlinkPrototypeButton; + + private Button fResetPrototypeButton; + + private CheckboxTreeViewer fAttributesTreeViewer; + + /** + * Constructs a new tab with default context help. + */ + public ProtoypeTab() { + setHelpContextId(IDebugHelpContextIds.LAUNCH_CONFIGURATION_DIALOG_PROTOTYPE_TAB); + } + + /* + * (non-Javadoc) + * @see + * org.eclipse.debug.ui.ILaunchConfigurationTab#createControl(org.eclipse. + * swt.widgets.Composite) + */ + @Override + public void createControl(Composite parent) { + Composite comp = SWTFactory.createComposite(parent, 1, 1, GridData.FILL_BOTH); + setControl(comp); + PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), getHelpContextId()); + + createConfigPrototypeComponent(comp); + createPrototypeExplanationsComponent(comp); + createPrototypeAttributesTreeComponent(comp); + } + + /** + * Creates the config prototype location component + * + * @param parent the parent composite to add this component to + */ + private void createConfigPrototypeComponent(Composite parent) { + fPrototypeComposite = new Composite(parent, SWT.NONE); + fPrototypeComposite.setLayout(new GridLayout(5, false)); + fPrototypeComposite.setFont(parent.getFont()); + GridData gd = new GridData(SWT.FILL, SWT.FILL, true, false); + fPrototypeComposite.setLayoutData(gd); + SWTFactory.createLabel(fPrototypeComposite, LaunchConfigurationsMessages.PrototypeTab_Label_2, 1); + fPrototypeText = SWTFactory.createSingleText(fPrototypeComposite, 1); + fPrototypeText.setEditable(false); + fPrototypeTextDecoration = new ControlDecoration(fPrototypeText, SWT.TOP | SWT.LEFT); + FieldDecoration errorDecoration = FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_ERROR); + fPrototypeTextDecoration.setDescriptionText(LaunchConfigurationsMessages.PrototypeTab_Select_Prototype_Error_7); + fPrototypeTextDecoration.setImage(errorDecoration.getImage()); + fLinkPrototypeButton = SWTFactory.createPushButton(fPrototypeComposite, LaunchConfigurationsMessages.PrototypeTab_Link_Button_Label_3, null); + fLinkPrototypeButton.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent evt) { + handleLinkPrototypeButtonSelected(); + } + }); + fUnlinkPrototypeButton = SWTFactory.createPushButton(fPrototypeComposite, LaunchConfigurationsMessages.PrototypeTab_Unlink_Button_Label_4, null); + fUnlinkPrototypeButton.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent evt) { + handleUnlinkPrototypeButtonSelected(); + } + }); + fResetPrototypeButton = SWTFactory.createPushButton(fPrototypeComposite, LaunchConfigurationsMessages.PrototypeTab_Reset_Button_Label_8, null); + fResetPrototypeButton.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent evt) { + handleResetPrototypeButtonSelected(); + } + }); + } + + /** + * Creates the prototype explanations component + * + * @param parent the parent composite to add this component to + */ + private void createPrototypeExplanationsComponent(Composite parent) { + SWTFactory.createLabel(parent, LaunchConfigurationsMessages.PrototypeTab_Explanation_Label_10, 1); + SWTFactory.createLabel(parent, LaunchConfigurationsMessages.PrototypeTab_Explanation_Label_11, 1); + } + + /** + * Creates the prototype attributes tree component + * + * @param parent the parent composite to add this one to + */ + private void createPrototypeAttributesTreeComponent(Composite parent) { + Composite attributesPrototypeTableComposite = new Composite(parent, SWT.NONE); + attributesPrototypeTableComposite.setLayout(new GridLayout(1, false)); + attributesPrototypeTableComposite.setFont(parent.getFont()); + GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true); + attributesPrototypeTableComposite.setLayoutData(gd); + + fAttributesTreeViewer = createCheckboxTreeViewer(attributesPrototypeTableComposite); + } + + /** + * Update prototype text widget decorator. + */ + private void updateProductDecorator() { + if (fAppliedPrototype != null && !fAppliedPrototype.exists()) { + fPrototypeTextDecoration.show(); + } else { + fPrototypeTextDecoration.hide(); + } + } + + /** + * Handles the config prototype apply button being selected + */ + private void handleLinkPrototypeButtonSelected() { + String currentSelectedPrototypeString = fPrototypeText.getText(); + DecoratingLabelProvider labelProvider = new DecoratingLabelProvider(DebugUITools.newDebugModelPresentation(), PlatformUI.getWorkbench().getDecoratorManager().getLabelDecorator()); + ElementListSelectionDialog selectPrototypeDialog = new ElementListSelectionDialog(getShell(), labelProvider); + try { + ILaunchConfigurationType type = fSelectedLaunchConfiguration.getType(); + ILaunchConfiguration[] prototypes = type.getPrototypes(); + selectPrototypeDialog.setElements(prototypes); + selectPrototypeDialog.setMultipleSelection(false); + selectPrototypeDialog.setTitle(LaunchConfigurationsMessages.PrototypeTab_Select_Message_5); + selectPrototypeDialog.setEmptySelectionMessage(LaunchConfigurationsMessages.PrototypeTab_Select_Empty_Message_6); + selectPrototypeDialog.setInitialSelections(getPrototype(prototypes, currentSelectedPrototypeString)); + int open = selectPrototypeDialog.open(); + if (open == Window.OK) { + Object selectedPrototype = selectPrototypeDialog.getFirstResult(); + if (selectedPrototype instanceof ILaunchConfiguration) { + fAppliedPrototype = (ILaunchConfiguration) selectedPrototype; + ILaunchConfigurationWorkingCopy workingCopy = getWorkingCopy(); + workingCopy.setPrototype(fAppliedPrototype, true); + fPrototypeText.setText(((ILaunchConfiguration) selectedPrototype).getName()); + fAttributesTreeViewer.setInput(fAppliedPrototype); + fUnlinkPrototypeButton.setEnabled(true); + fResetPrototypeButton.setEnabled(true); + updateColumnsWidth(); + updateProductDecorator(); + setDirty(true); + updateLaunchConfigurationDialog(); + reinitTabs(workingCopy); + } + } + } catch (CoreException e) { + DebugUIPlugin.log(e.getStatus()); + } + } + + /** + * Handles the config prototype unapply button being selected + */ + private void handleUnlinkPrototypeButtonSelected() { + try { + fAppliedPrototype = null; + ILaunchConfigurationWorkingCopy workingCopy = getWorkingCopy(); + workingCopy.setPrototype(null, false); + fPrototypeText.setText(""); //$NON-NLS-1$ + fAttributesTreeViewer.setInput(null); + fUnlinkPrototypeButton.setEnabled(false); + fResetPrototypeButton.setEnabled(false); + updateProductDecorator(); + setDirty(true); + updateLaunchConfigurationDialog(); + reinitTabs(workingCopy); + } catch (CoreException e) { + DebugUIPlugin.log(e.getStatus()); + } + } + + /** + * Handles the config prototype reset button being selected + */ + private void handleResetPrototypeButtonSelected() { + try { + ILaunchConfigurationWorkingCopy workingCopy = getWorkingCopy(); + workingCopy.setPrototype(fAppliedPrototype, true); + fAttributesTreeViewer.refresh(); + setDirty(true); + updateLaunchConfigurationDialog(); + reinitTabs(workingCopy); + } catch (CoreException e) { + DebugUIPlugin.log(e.getStatus()); + } + } + + /** + * Get the working copy of the launch configuration associated with this + * tab. + * + * @return an {@link ILaunchConfigurationWorkingCopy}. + * @throws CoreException + */ + private ILaunchConfigurationWorkingCopy getWorkingCopy() throws CoreException { + ILaunchConfigurationWorkingCopy workingCopy; + if (fSelectedLaunchConfiguration instanceof ILaunchConfigurationWorkingCopy) { + workingCopy = (ILaunchConfigurationWorkingCopy) fSelectedLaunchConfiguration; + } else { + workingCopy = fSelectedLaunchConfiguration.getWorkingCopy(); + } + return workingCopy; + } + + /** + * Reinit the tabs of the launch configuration dialog. + * + * @param launchConfiguration the {@link LaunchConfiguration}. + */ + private void reinitTabs(ILaunchConfiguration launchConfiguration) { + ILaunchConfigurationTab[] tabs = getLaunchConfigurationDialog().getTabs(); + for (ILaunchConfigurationTab configTab : tabs) { + configTab.initializeFrom(launchConfiguration); + } + } + + /** + * Get the prototype with the given name in the given prototypes list. + * + * @param prototypes the prototypes list + * @param name the prototype to get + * @return the prototype with the given name in the given prototypes list. + */ + private Object[] getPrototype(ILaunchConfiguration[] prototypes, String name) { + for (ILaunchConfiguration prototype : prototypes) { + if (name.equals(prototype.getName())) { + return new Object[] { prototype }; + } + } + return new Object[0]; + } + + /** + * Creates the checkbox tree viewer that contains attributes. + * + * @param parent the parent composite to add this one to + * @return a {@link CheckboxTreeViewer} + */ + private CheckboxTreeViewer createCheckboxTreeViewer(Composite parent) { + Tree tree = new Tree(parent, SWT.MULTI | SWT.CHECK | SWT.H_SCROLL | SWT.V_SCROLL); + GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true); + tree.setLayoutData(gd); + tree.setHeaderVisible(true); + tree.setLinesVisible(true); + + CheckboxTreeViewer treeViewer = new CheckboxTreeViewer(tree); + + treeViewer.setContentProvider(new PrototypeAttributesContentProvider()); + treeViewer.setCheckStateProvider(new AttributesTreeCheckStateProvider()); + treeViewer.addCheckStateListener(new AttributesTreeCheckStateListener()); + + MenuManager menuMgr = new MenuManager(); + Menu contextMenu = menuMgr.createContextMenu(tree); + menuMgr.addMenuListener(new ResetMenuListener()); + menuMgr.setRemoveAllWhenShown(true); + tree.setMenu(contextMenu); + + return treeViewer; + } + + /** + * Add columns to the given {@link CheckboxTreeViewer}. + * + * @param treeViewer the given {@link CheckboxTreeViewer}. + */ + private void addColumnsToTreeViewer(CheckboxTreeViewer treeViewer) { + for (TreeColumn treeColumn : treeViewer.getTree().getColumns()) { + treeColumn.dispose(); + } + TreeViewerColumn columnLabel = new TreeViewerColumn(treeViewer, SWT.LEFT, 0); + columnLabel.setLabelProvider(new ColumnAttributeLabelProvider()); + columnLabel.getColumn().setText(ATTRIBUTE); + if (fSelectedLaunchConfiguration != null && !fSelectedLaunchConfiguration.isPrototype()) { + TreeViewerColumn columnModified = new TreeViewerColumn(treeViewer, SWT.CENTER, 1); + columnModified.setLabelProvider(new ColumnModifiedLabelProvider()); + columnModified.getColumn().setText(MODIFIED); + } + TreeViewerColumn columnValue = new TreeViewerColumn(treeViewer, SWT.LEFT, fSelectedLaunchConfiguration != null && !fSelectedLaunchConfiguration.isPrototype() ? 2 : 1); + columnValue.setLabelProvider(new ColumnValueLabelProvider()); + columnValue.getColumn().setText(PROTOTYPE_VALUE); + } + + /* + * (non-Javadoc) + * @see + * org.eclipse.debug.ui.ILaunchConfigurationTab#initializeFrom(org.eclipse. + * debug.core.ILaunchConfiguration) + */ + @Override + public void initializeFrom(ILaunchConfiguration configuration) { + initialize(configuration); + } + + /* + * (non-Javadoc) + * @see org.eclipse.debug.ui.AbstractLaunchConfigurationTab#dispose() + */ + @Override + public void dispose() { + super.dispose(); + } + + /* + * (non-Javadoc) + * @see + * org.eclipse.debug.ui.ILaunchConfigurationTab#activated(org.eclipse.debug. + * core.ILaunchConfigurationWorkingCopy) + */ + @Override + public void activated(ILaunchConfigurationWorkingCopy workingCopy) { + initialize(workingCopy); + } + + /* + * (non-Javadoc) + * @see + * org.eclipse.debug.ui.ILaunchConfigurationTab#deactivated(org.eclipse. + * debug.core.ILaunchConfigurationWorkingCopy) + */ + @Override + public void deactivated(ILaunchConfigurationWorkingCopy workingCopy) { + } + + /** + * Initialize this tab with the given configuration. + * + * @param configuration the given configuration + * @see ProtoypeTab#activated(ILaunchConfigurationWorkingCopy) + * @see ProtoypeTab#initializeFrom(ILaunchConfiguration) + */ + private void initialize(ILaunchConfiguration configuration) { + try { + if (configuration.isPrototype()) { + fPrototypeComposite.setVisible(false); + GridData gridData = (GridData) fPrototypeComposite.getLayoutData(); + gridData.exclude = true; + fAppliedPrototype = configuration; + fSelectedLaunchConfiguration = configuration; + addColumnsToTreeViewer(fAttributesTreeViewer); + fAttributesTreeViewer.setInput(fAppliedPrototype); + fAttributesTreeViewer.getTree().setEnabled(true); + } else { + fPrototypeComposite.setVisible(true); + GridData gridData = (GridData) fPrototypeComposite.getLayoutData(); + gridData.exclude = false; + fSelectedLaunchConfiguration = configuration; + fAppliedPrototype = configuration.getPrototype(); + addColumnsToTreeViewer(fAttributesTreeViewer); + fAttributesTreeViewer.getTree().setEnabled(false); + if (fAppliedPrototype == null) { + fPrototypeText.setText(""); //$NON-NLS-1$ + fUnlinkPrototypeButton.setEnabled(false); + fResetPrototypeButton.setEnabled(false); + fAttributesTreeViewer.setInput(null); + } else if (!fAppliedPrototype.exists()) { + fPrototypeText.setText(fAppliedPrototype.getName()); + fUnlinkPrototypeButton.setEnabled(true); + fResetPrototypeButton.setEnabled(true); + fAttributesTreeViewer.setInput(null); + } else { + fPrototypeText.setText(fAppliedPrototype.getName()); + fUnlinkPrototypeButton.setEnabled(true); + fResetPrototypeButton.setEnabled(true); + fAttributesTreeViewer.setInput(fAppliedPrototype); + } + } + updateProductDecorator(); + updateColumnsWidth(); + } catch (CoreException e) { + DebugUIPlugin.log(e.getStatus()); + } + } + + /** + * Set columns tree widths dynamically + */ + private void updateColumnsWidth() { + getShell().getDisplay().asyncExec(new Runnable() { + @Override + public void run() { + TreeColumn[] columns = fAttributesTreeViewer.getTree().getColumns(); + for (TreeColumn treeColumn : columns) { + treeColumn.pack(); + } + } + }); + } + + /* + * (non-Javadoc) + * @see + * org.eclipse.debug.ui.ILaunchConfigurationTab#isValid(org.eclipse.debug. + * core.ILaunchConfiguration) + */ + @Override + public boolean isValid(ILaunchConfiguration config) { + setMessage(null); + setErrorMessage(null); + + if (fAppliedPrototype != null && !fAppliedPrototype.exists()) { + setErrorMessage(LaunchConfigurationsMessages.PrototypeTab_Select_Prototype_Error_7); + return false; + } + return !config.isPrototype(); + } + + /* + * (non-Javadoc) + * @see + * org.eclipse.debug.ui.ILaunchConfigurationTab#setDefaults(org.eclipse. + * debug.core.ILaunchConfigurationWorkingCopy) + */ + @Override + public void setDefaults(ILaunchConfigurationWorkingCopy config) { + } + + /* + * (non-Javadoc) + * @see + * org.eclipse.debug.ui.ILaunchConfigurationTab#performApply(org.eclipse. + * debug.core.ILaunchConfigurationWorkingCopy) + */ + @Override + public void performApply(ILaunchConfigurationWorkingCopy configuration) { + } + + /* + * (non-Javadoc) + * @see org.eclipse.debug.ui.ILaunchConfigurationTab#getName() + */ + @Override + public String getName() { + return LaunchConfigurationsMessages.PrototypeTab_Prototype_1; + } + + /* + * (non-Javadoc) + * @see org.eclipse.debug.ui.ILaunchConfigurationTab#getImage() + */ + @Override + public Image getImage() { + return DebugUITools.getImage(IInternalDebugUIConstants.IMG_OBJS_PROTO_TAB); + } + + /** + * @see org.eclipse.debug.ui.AbstractLaunchConfigurationTab#getId() + * + */ + @Override + public String getId() { + return PROTOTYPE_TAB_ID; + } + + /* + * (non-Javadoc) + * @see org.eclipse.debug.ui.ILaunchConfigurationTab#canSave() + */ + @Override + public boolean canSave() { + return true; + } + + /** + * Check if an attribute from the selected launch configuration is different + * from its prototype. + * + * @param element the given attribute. + */ + private boolean isAttributeModified(Entry element) { + try { + if (fSelectedLaunchConfiguration != null && !fSelectedLaunchConfiguration.isPrototype()) { + return fSelectedLaunchConfiguration.isAttributeModified(element.getKey()); + } + } catch (CoreException e) { + DebugUIPlugin.log(e.getStatus()); + } + return false; + } + + /** + * Content provider for the prototype attributes table + */ + private class PrototypeAttributesContentProvider implements ITreeContentProvider { + + @Override + public Object[] getElements(Object inputElement) { + if (inputElement instanceof ILaunchConfiguration) { + try { + Map attributes = ((ILaunchConfiguration) inputElement).getAttributes(); + return attributes.entrySet().toArray(); + } catch (CoreException e) { + DebugUIPlugin.log(e.getStatus()); + } + } + return new Object[0]; + } + + @Override + public Object[] getChildren(Object parentElement) { + return null; + } + + @Override + public Object getParent(Object element) { + return null; + } + + @Override + public boolean hasChildren(Object element) { + return false; + } + } + + /** + * Label provider for the prototype attributes tree column "Edited" + */ + private class ColumnModifiedLabelProvider extends ColumnLabelProvider { + @SuppressWarnings("unchecked") + @Override + public String getText(Object element) { + if (fSelectedLaunchConfiguration != null && !fSelectedLaunchConfiguration.isPrototype()) { + if (element instanceof Entry && isAttributeModified((Entry) element)) { + return "true"; //$NON-NLS-1$ + } + } + return "false"; //$NON-NLS-1$ + } + } + + /** + * Label provider for the prototype attributes tree column "Attribute" + */ + @SuppressWarnings({ "unchecked" }) + private class ColumnAttributeLabelProvider extends ColumnLabelProvider { + @Override + public String getText(Object element) { + String key = ((Entry) element).getKey(); + ILaunchConfigurationTab[] tabs = getLaunchConfigurationDialog().getTabs(); + for (ILaunchConfigurationTab tab : tabs) { + if (tab instanceof AbstractLaunchConfigurationTab) { + String attributeLabel = ((AbstractLaunchConfigurationTab) tab).getAttributeLabel(key); + if (attributeLabel != null) { + return attributeLabel; + } + } + } + return key; + } + } + + /** + * Label provider for the prototype attributes tree column "Value" + */ + @SuppressWarnings({ "unchecked" }) + private class ColumnValueLabelProvider extends ColumnLabelProvider { + @Override + public String getText(Object element) { + Object value = ((Entry) element).getValue(); + if (value instanceof Boolean) { + return ((Boolean) value).toString(); + } else if (value instanceof String) { + return (String) value; + } else if (value instanceof Integer) { + return value.toString(); + } else if (value instanceof List) { + return "[" + ((List) value).stream().collect(Collectors.joining(", ")) + "]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + } else if (value instanceof Set) { + return "[" + ((Set) value).stream().collect(Collectors.joining(", ")) + "]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + } else if (value instanceof Map) { + return "[" + ((Map) value).entrySet().stream().map(i -> "[" + i.getKey() + ", " + i.getValue() + "]").collect(Collectors.joining(", ")) + "]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ + } + return super.getText(element); + } + } + + /** + * Check state provider for attributes tree. + */ + @SuppressWarnings("unchecked") + private class AttributesTreeCheckStateProvider implements ICheckStateProvider { + @Override + public boolean isGrayed(Object element) { + return false; + } + + @Override + public boolean isChecked(Object element) { + try { + if (element instanceof Entry) { + return fAppliedPrototype.getPrototypeVisibleAttributes().contains(((Entry) element).getKey()); + } + } catch (CoreException e) { + DebugUIPlugin.log(e.getStatus()); + } + return false; + } + } + + /** + * Check state listener for attributes tree. + */ + @SuppressWarnings("unchecked") + private class AttributesTreeCheckStateListener implements ICheckStateListener { + @Override + public void checkStateChanged(CheckStateChangedEvent event) { + try { + Object data = event.getElement(); + if (data instanceof Entry) { + fAppliedPrototype.setPrototypeAttributeVisibility(((Entry) data).getKey(), event.getChecked()); + setDirty(true); + updateLaunchConfigurationDialog(); + } + } catch (CoreException e) { + DebugUIPlugin.log(e.getStatus()); + } + } + } + + /** + * Menu Listener for attributes table. + */ + private class ResetMenuListener implements IMenuListener { + + @Override + public void menuAboutToShow(IMenuManager manager) { + if (fSelectedLaunchConfiguration != null && !fSelectedLaunchConfiguration.isPrototype()) { + manager.add(new ResetAction()); + } + } + } + + /** + * Reset attribute menu action. + */ + @SuppressWarnings("unchecked") + private class ResetAction extends Action { + + @Override + public String getText() { + return LaunchConfigurationsMessages.PrototypeTab_Reset_Menu_Action_9; + } + + @Override + public void run() { + IStructuredSelection selection = (IStructuredSelection) fAttributesTreeViewer.getSelection(); + try { + ILaunchConfigurationWorkingCopy workingCopy = getWorkingCopy(); + for (Object element : selection.toList()) { + if (element instanceof Entry) { + String key = ((Entry) element).getKey(); + if (fAppliedPrototype.getPrototypeVisibleAttributes().contains(key)) { + Object prototypeValue = fAppliedPrototype.getAttributes().get(key); + workingCopy.setAttribute(key, prototypeValue); + } + } + } + setDirty(true); + updateLaunchConfigurationDialog(); + reinitTabs(workingCopy); + } catch (CoreException e) { + DebugUIPlugin.log(e.getStatus()); + } + } + } +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/sourcelookup/SourceLookupTab.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/sourcelookup/SourceLookupTab.java index e908e70d0..173a13668 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/sourcelookup/SourceLookupTab.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/sourcelookup/SourceLookupTab.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2003, 2010 IBM Corporation and others. + * Copyright (c) 2003, 2017 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Axel Richard (Obeo) - Bug 41353 - Launch configurations prototypes *******************************************************************************/ package org.eclipse.debug.ui.sourcelookup; @@ -50,6 +51,7 @@ public class SourceLookupTab extends AbstractLaunchConfigurationTab { * Constructs a new tab with default context help. */ public SourceLookupTab() { + super(); setHelpContextId(IDebugHelpContextIds.SOURCELOOKUP_TAB); } @@ -169,4 +171,16 @@ public class SourceLookupTab extends AbstractLaunchConfigurationTab { } return super.getMessage(); } + + /* + * (non-Javadoc) + * @see org.eclipse.debug.ui.AbstractLaunchConfigurationTab#initializeAttributes() + * @since 3.13 + */ + @Override + protected void initializeAttributes() { + super.initializeAttributes(); + getAttributesLabelsForPrototype().put(ILaunchConfiguration.ATTR_SOURCE_LOCATOR_MEMENTO, SourceLookupUIMessages.sourceTab_AttributeLabel_SourceLocatorMemento); + getAttributesLabelsForPrototype().put(ILaunchConfiguration.ATTR_SOURCE_LOCATOR_ID, SourceLookupUIMessages.sourceTab_AttributeLabel_SourceLocatorID); + } } -- cgit v1.2.3