diff options
author | Jonah Graham | 2019-01-04 17:00:42 +0000 |
---|---|---|
committer | Jonah Graham | 2019-07-10 01:17:22 +0000 |
commit | f96971a278189debdfa2f8b7af64c70642bdfbe9 (patch) | |
tree | 9e501a023a15da8d990f94b44bbc403a2ac0d132 /launch | |
parent | edfc7d4c0eeb1b99a45302ec6fa324538a4e74d5 (diff) | |
download | org.eclipse.cdt-f96971a278189debdfa2f8b7af64c70642bdfbe9.tar.gz org.eclipse.cdt-f96971a278189debdfa2f8b7af64c70642bdfbe9.tar.xz org.eclipse.cdt-f96971a278189debdfa2f8b7af64c70642bdfbe9.zip |
Bug 542488: Remove duplicated code
When DSF was first created it was a separate project that borrowed
heavily from CDT, as such (AFAICT) some code was copied from
o.e.cdt.launch to DSF. This commit de-duplicates some of that code
as the DAP implementation wants to reuse the code too and another
copy is not wanted.
Change-Id: Ie54187dabc9c32224575c0bf51bcabfab00ca340
Diffstat (limited to 'launch')
6 files changed, 380 insertions, 200 deletions
diff --git a/launch/org.eclipse.cdt.launch/META-INF/MANIFEST.MF b/launch/org.eclipse.cdt.launch/META-INF/MANIFEST.MF index 26910934d4b..cbfeba7e8b0 100644 --- a/launch/org.eclipse.cdt.launch/META-INF/MANIFEST.MF +++ b/launch/org.eclipse.cdt.launch/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %pluginName Bundle-SymbolicName: org.eclipse.cdt.launch; singleton:=true -Bundle-Version: 9.2.1.qualifier +Bundle-Version: 9.3.0.qualifier Bundle-Activator: org.eclipse.cdt.launch.internal.ui.LaunchUIPlugin Bundle-Vendor: %providerName Bundle-Localization: plugin diff --git a/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/LaunchUtils.java b/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/LaunchUtils.java index d9a0d729392..eef1fd7984e 100644 --- a/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/LaunchUtils.java +++ b/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/LaunchUtils.java @@ -15,6 +15,7 @@ *******************************************************************************/ package org.eclipse.cdt.launch; +import java.io.FileNotFoundException; import java.io.IOException; import java.util.HashSet; import java.util.Set; @@ -24,6 +25,7 @@ import org.eclipse.cdt.core.IBinaryParser; import org.eclipse.cdt.core.IBinaryParser.IBinaryObject; import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.CoreModelUtil; +import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.settings.model.ICConfigExtensionReference; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; import org.eclipse.cdt.core.settings.model.ICOutputEntry; @@ -33,14 +35,19 @@ import org.eclipse.cdt.core.settings.model.extension.CConfigurationData; import org.eclipse.cdt.core.settings.model.util.CDataUtil; import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants; import org.eclipse.cdt.internal.core.resources.ResourceLookup; +import org.eclipse.cdt.launch.internal.ui.LaunchUIPlugin; import org.eclipse.cdt.utils.CommandLineUtil; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.MultiStatus; import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.SubProgressMonitor; import org.eclipse.core.variables.IStringVariableManager; import org.eclipse.core.variables.VariablesPlugin; @@ -49,6 +56,8 @@ import org.eclipse.ui.PlatformUI; import org.eclipse.ui.activities.IActivityManager; import org.eclipse.ui.activities.IWorkbenchActivitySupport; +import com.ibm.icu.text.MessageFormat; + /** * Utility methods. */ @@ -103,6 +112,90 @@ public class LaunchUtils { } /** + * Return the program path + * + * @param configuration Launch configuration to obtain paths from + * @return the program path + * @throws CoreException if program path can not be resolved. + */ + public static String getProgramPath(ILaunchConfiguration configuration) throws CoreException { + return resolveProgramPath(configuration, null); + } + + /** + * Return the program path, resolved as an absolute OS string. + * + * @param configuration Launch configuration to obtain paths from + * @param programName Optional (can be null) starting point for program name + * @return the program path + * @throws CoreException if program path can not be resolved. + */ + public static String resolveProgramPath(ILaunchConfiguration configuration, String programName) + throws CoreException { + if (programName == null) { + programName = configuration.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME, (String) null); + } + if (programName == null) { + throwException(Messages.LaunchUtils_program_file_not_specified, null, + ICDTLaunchConfigurationConstants.ERR_UNSPECIFIED_PROGRAM); + } + programName = VariablesPlugin.getDefault().getStringVariableManager().performStringSubstitution(programName); + IPath programPath = new Path(programName); + if (programPath.isEmpty()) { + throwException(Messages.LaunchUtils_program_file_does_not_exist, null, + ICDTLaunchConfigurationConstants.ERR_PROGRAM_NOT_EXIST); + } + + if (!programPath.isAbsolute()) { + IProject project = getProject(configuration); + ICProject cproject = CCorePlugin.getDefault().getCoreModel().create(project); + if (cproject != null) { + // Find the specified program within the specified project + IFile wsProgramPath = cproject.getProject().getFile(programPath); + programPath = wsProgramPath.getLocation(); + } + } + if (!programPath.toFile().exists()) { + throwException(Messages.LaunchUtils_program_file_does_not_exist, + new FileNotFoundException( + MessageFormat.format(Messages.LaunchUtils__0_not_found, programPath.toOSString())), + ICDTLaunchConfigurationConstants.ERR_PROGRAM_NOT_EXIST); + } + + return programPath.toOSString(); + } + + /** + * Return project or <code>null</code> if project is not accessible or not specified. + * @param configuration Launch configuration to obtain project from + * @return the project + * @throws CoreException + */ + public static IProject getProject(ILaunchConfiguration configuration) throws CoreException { + String projectName = configuration.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME, + (String) null); + IProject project = null; + if (projectName == null) { + IResource[] resources = configuration.getMappedResources(); + if (resources != null && resources.length > 0 && resources[0] instanceof IProject) { + project = (IProject) resources[0]; + } + } else { + projectName = projectName.trim(); + if (projectName.length() == 0) { + return null; + } + project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName); + } + + if (project == null || !project.isAccessible()) { + // No project + return null; + } + return project; + } + + /** * @since 6.0 */ public static IBinaryObject getBinary(IProject project, IPath exePath) throws CoreException { @@ -243,4 +336,24 @@ public class LaunchUtils { } return buildConfig; } + + /** + * Throws a core exception with an error status object built from the given + * message, lower level exception, and error code. + * + * @param message + * the status message + * @param exception + * lower level exception associated with the error, or + * <code>null</code> if none + * @param code + * error code + */ + private static void throwException(String message, Throwable exception, int code) throws CoreException { + MultiStatus status = new MultiStatus(LaunchUIPlugin.PLUGIN_ID, code, message, exception); + status.add(new Status(IStatus.ERROR, LaunchUIPlugin.PLUGIN_ID, code, + exception == null ? "" : exception.getLocalizedMessage(), //$NON-NLS-1$ + exception)); + throw new CoreException(status); + } } diff --git a/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/Messages.java b/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/Messages.java new file mode 100644 index 00000000000..7d0b3f256b8 --- /dev/null +++ b/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/Messages.java @@ -0,0 +1,27 @@ +/******************************************************************************* + * Copyright (c) 2019 Kichwa Coders and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + *******************************************************************************/ +package org.eclipse.cdt.launch; + +import org.eclipse.osgi.util.NLS; + +public class Messages extends NLS { + private static final String BUNDLE_NAME = "org.eclipse.cdt.launch.messages"; //$NON-NLS-1$ + public static String LaunchUtils__0_not_found; + public static String LaunchUtils_program_file_does_not_exist; + public static String LaunchUtils_program_file_not_specified; + static { + // initialize resource bundle + NLS.initializeMessages(BUNDLE_NAME, Messages.class); + } + + private Messages() { + } +} diff --git a/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/messages.properties b/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/messages.properties new file mode 100644 index 00000000000..426d03f33f4 --- /dev/null +++ b/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/messages.properties @@ -0,0 +1,13 @@ +############################################################################### +# Copyright (c) 2019 Kichwa Coders and others. +# +# This program and the accompanying materials +# are made available under the terms of the Eclipse Public License 2.0 +# which accompanies this distribution, and is available at +# https://www.eclipse.org/legal/epl-2.0/ +# +# SPDX-License-Identifier: EPL-2.0 +############################################################################### +LaunchUtils__0_not_found={0} not found +LaunchUtils_program_file_does_not_exist=Program file does not exist +LaunchUtils_program_file_not_specified=Program file not specified diff --git a/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/ui/CAbstractArgumentsTab.java b/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/ui/CAbstractArgumentsTab.java new file mode 100644 index 00000000000..4fa02b821cf --- /dev/null +++ b/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/ui/CAbstractArgumentsTab.java @@ -0,0 +1,224 @@ +/******************************************************************************* + * Copyright (c) 2005, 2016 QNX Software Systems and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * QNX Software Systems - Initial API and implementation + * IBM Corporation + *******************************************************************************/ +package org.eclipse.cdt.launch.ui; + +import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants; +import org.eclipse.cdt.launch.internal.ui.LaunchImages; +import org.eclipse.cdt.launch.internal.ui.LaunchMessages; +import org.eclipse.cdt.launch.internal.ui.LaunchUIPlugin; +import org.eclipse.cdt.launch.internal.ui.WorkingDirectoryBlock; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.debug.core.ILaunchConfiguration; +import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; +import org.eclipse.debug.ui.ILaunchConfigurationDialog; +import org.eclipse.osgi.util.NLS; +import org.eclipse.swt.SWT; +import org.eclipse.swt.accessibility.AccessibleAdapter; +import org.eclipse.swt.accessibility.AccessibleEvent; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.graphics.Font; +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.Control; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Text; + +/** + * A launch configuration tab that displays and edits program arguments, + * and working directory launch configuration attributes. + */ +public abstract class CAbstractArgumentsTab extends CLaunchConfigurationTab { + // Program arguments UI widgets + protected Label fPrgmArgumentsLabel; + protected Text fPrgmArgumentsText; + protected Button fArgumentVariablesButton; + + /** + * Working Directory + * @noreference This field is not intended to be referenced by clients. + */ + protected WorkingDirectoryBlock fWorkingDirectoryBlock = new WorkingDirectoryBlock(); + + @Override + public void createControl(Composite parent) { + Font font = parent.getFont(); + Composite comp = new Composite(parent, SWT.NONE); + GridLayout layout = new GridLayout(1, true); + comp.setLayout(layout); + comp.setFont(font); + + GridData gd = new GridData(GridData.FILL_BOTH); + comp.setLayoutData(gd); + setControl(comp); + + LaunchUIPlugin.getDefault().getWorkbench().getHelpSystem().setHelp(getControl(), + ICDTLaunchHelpContextIds.LAUNCH_CONFIGURATION_DIALOG_ARGUMNETS_TAB); + + createArgumentComponent(comp, 1); + + fWorkingDirectoryBlock.createControl(comp); + } + + protected void createArgumentComponent(Composite comp, int horizontalSpan) { + Font font = comp.getFont(); + Group group = new Group(comp, SWT.NONE); + group.setFont(font); + group.setLayout(new GridLayout()); + GridData gd = new GridData(GridData.FILL_BOTH); + gd.horizontalSpan = horizontalSpan; + group.setLayoutData(gd); + + group.setText(LaunchMessages.CArgumentsTab_C_Program_Arguments); + fPrgmArgumentsText = new Text(group, SWT.MULTI | SWT.WRAP | SWT.BORDER | SWT.V_SCROLL); + fPrgmArgumentsText.getAccessible().addAccessibleListener(new AccessibleAdapter() { + @Override + public void getName(AccessibleEvent e) { + e.result = LaunchMessages.CArgumentsTab_C_Program_Arguments; + } + }); + gd = new GridData(GridData.FILL_BOTH); + gd.heightHint = 40; + gd.widthHint = 100; + fPrgmArgumentsText.setLayoutData(gd); + fPrgmArgumentsText.setFont(font); + fPrgmArgumentsText.addModifyListener(new ModifyListener() { + @Override + public void modifyText(ModifyEvent evt) { + updateLaunchConfigurationDialog(); + } + }); + fArgumentVariablesButton = createVariablesButton(group, LaunchMessages.CArgumentsTab_Variables, + fPrgmArgumentsText); + gd = new GridData(GridData.HORIZONTAL_ALIGN_END); + fArgumentVariablesButton.setLayoutData(gd); + addControlAccessibleListener(fArgumentVariablesButton, fArgumentVariablesButton.getText()); // need to strip the mnemonic from buttons + } + + public void addControlAccessibleListener(Control control, String controlName) { + // Strip mnemonic (&) + String[] strs = controlName.split("&"); //$NON-NLS-1$ + StringBuilder stripped = new StringBuilder(); + for (int i = 0; i < strs.length; i++) { + stripped.append(strs[i]); + } + control.getAccessible().addAccessibleListener(new ControlAccessibleListener(stripped.toString())); + } + + private class ControlAccessibleListener extends AccessibleAdapter { + private String controlName; + + ControlAccessibleListener(String name) { + controlName = name; + } + + @Override + public void getName(AccessibleEvent e) { + e.result = controlName; + } + } + + @Override + public boolean isValid(ILaunchConfiguration config) { + return fWorkingDirectoryBlock.isValid(config); + } + + @Override + public void setDefaults(ILaunchConfigurationWorkingCopy config) { + config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, (String) null); + config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY, (String) null); + } + + @Override + public void initializeFrom(ILaunchConfiguration configuration) { + try { + fPrgmArgumentsText + .setText(configuration.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, "")); //$NON-NLS-1$ + fWorkingDirectoryBlock.initializeFrom(configuration); + } catch (CoreException e) { + setErrorMessage(NLS.bind(LaunchMessages.Launch_common_Exception_occurred_reading_configuration_EXCEPTION, + e.getStatus().getMessage())); + LaunchUIPlugin.log(e); + } + } + + @Override + public void performApply(ILaunchConfigurationWorkingCopy configuration) { + configuration.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, + getAttributeValueFrom(fPrgmArgumentsText)); + fWorkingDirectoryBlock.performApply(configuration); + } + + /** + * Returns the string in the text widget, or <code>null</code> if empty. + * + * @return text or <code>null</code> + */ + protected String getAttributeValueFrom(Text text) { + String content = text.getText().trim(); + // Bug #131513 - eliminate Windows \r line delimiter + content = content.replaceAll("\r\n", "\n"); //$NON-NLS-1$//$NON-NLS-2$ + if (!content.isEmpty()) { + return content; + } + return null; + } + + @Override + abstract public String getId(); + + @Override + public String getName() { + return LaunchMessages.CArgumentsTab_Arguments; + } + + @Override + public void setLaunchConfigurationDialog(ILaunchConfigurationDialog dialog) { + super.setLaunchConfigurationDialog(dialog); + fWorkingDirectoryBlock.setLaunchConfigurationDialog(dialog); + } + + @Override + public String getErrorMessage() { + String m = super.getErrorMessage(); + if (m == null) { + return fWorkingDirectoryBlock.getErrorMessage(); + } + return m; + } + + @Override + public String getMessage() { + String m = super.getMessage(); + if (m == null) { + return fWorkingDirectoryBlock.getMessage(); + } + return m; + } + + @Override + public Image getImage() { + return LaunchImages.get(LaunchImages.IMG_VIEW_ARGUMENTS_TAB); + } + + @Override + protected void updateLaunchConfigurationDialog() { + super.updateLaunchConfigurationDialog(); + } +} diff --git a/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/ui/CArgumentsTab.java b/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/ui/CArgumentsTab.java index fa277410245..14f19c582bf 100644 --- a/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/ui/CArgumentsTab.java +++ b/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/ui/CArgumentsTab.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2016 QNX Software Systems and others. + * Copyright (c) 2005, 2019 QNX Software Systems and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -14,32 +14,6 @@ *******************************************************************************/ package org.eclipse.cdt.launch.ui; -import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants; -import org.eclipse.cdt.launch.internal.ui.LaunchImages; -import org.eclipse.cdt.launch.internal.ui.LaunchMessages; -import org.eclipse.cdt.launch.internal.ui.LaunchUIPlugin; -import org.eclipse.cdt.launch.internal.ui.WorkingDirectoryBlock; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.debug.core.ILaunchConfiguration; -import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; -import org.eclipse.debug.ui.ILaunchConfigurationDialog; -import org.eclipse.osgi.util.NLS; -import org.eclipse.swt.SWT; -import org.eclipse.swt.accessibility.AccessibleAdapter; -import org.eclipse.swt.accessibility.AccessibleEvent; -import org.eclipse.swt.events.ModifyEvent; -import org.eclipse.swt.events.ModifyListener; -import org.eclipse.swt.graphics.Font; -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.Control; -import org.eclipse.swt.widgets.Group; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Text; - /** * A launch configuration tab that displays and edits program arguments, * and working directory launch configuration attributes. @@ -48,7 +22,7 @@ import org.eclipse.swt.widgets.Text; * </p> * @noextend This class is not intended to be subclassed by clients. */ -public class CArgumentsTab extends CLaunchConfigurationTab { +public class CArgumentsTab extends CAbstractArgumentsTab { /** * Tab identifier used for ordering of tabs added using the * <code>org.eclipse.debug.ui.launchConfigurationTabs</code> @@ -58,179 +32,8 @@ public class CArgumentsTab extends CLaunchConfigurationTab { */ public static final String TAB_ID = "org.eclipse.cdt.cdi.launch.argumentsTab"; //$NON-NLS-1$ - // Program arguments UI widgets - protected Label fPrgmArgumentsLabel; - protected Text fPrgmArgumentsText; - protected Button fArgumentVariablesButton; - - // Working directory - protected WorkingDirectoryBlock fWorkingDirectoryBlock = new WorkingDirectoryBlock(); - - @Override - public void createControl(Composite parent) { - Font font = parent.getFont(); - Composite comp = new Composite(parent, SWT.NONE); - GridLayout layout = new GridLayout(1, true); - comp.setLayout(layout); - comp.setFont(font); - - GridData gd = new GridData(GridData.FILL_BOTH); - comp.setLayoutData(gd); - setControl(comp); - - LaunchUIPlugin.getDefault().getWorkbench().getHelpSystem().setHelp(getControl(), - ICDTLaunchHelpContextIds.LAUNCH_CONFIGURATION_DIALOG_ARGUMNETS_TAB); - - createArgumentComponent(comp, 1); - - fWorkingDirectoryBlock.createControl(comp); - } - - protected void createArgumentComponent(Composite comp, int horizontalSpan) { - Font font = comp.getFont(); - Group group = new Group(comp, SWT.NONE); - group.setFont(font); - group.setLayout(new GridLayout()); - GridData gd = new GridData(GridData.FILL_BOTH); - gd.horizontalSpan = horizontalSpan; - group.setLayoutData(gd); - - group.setText(LaunchMessages.CArgumentsTab_C_Program_Arguments); - fPrgmArgumentsText = new Text(group, SWT.MULTI | SWT.WRAP | SWT.BORDER | SWT.V_SCROLL); - fPrgmArgumentsText.getAccessible().addAccessibleListener(new AccessibleAdapter() { - @Override - public void getName(AccessibleEvent e) { - e.result = LaunchMessages.CArgumentsTab_C_Program_Arguments; - } - }); - gd = new GridData(GridData.FILL_BOTH); - gd.heightHint = 40; - gd.widthHint = 100; - fPrgmArgumentsText.setLayoutData(gd); - fPrgmArgumentsText.setFont(font); - fPrgmArgumentsText.addModifyListener(new ModifyListener() { - @Override - public void modifyText(ModifyEvent evt) { - updateLaunchConfigurationDialog(); - } - }); - fArgumentVariablesButton = createVariablesButton(group, LaunchMessages.CArgumentsTab_Variables, - fPrgmArgumentsText); - gd = new GridData(GridData.HORIZONTAL_ALIGN_END); - fArgumentVariablesButton.setLayoutData(gd); - addControlAccessibleListener(fArgumentVariablesButton, fArgumentVariablesButton.getText()); // need to strip the mnemonic from buttons - } - - public void addControlAccessibleListener(Control control, String controlName) { - // Strip mnemonic (&) - String[] strs = controlName.split("&"); //$NON-NLS-1$ - StringBuilder stripped = new StringBuilder(); - for (int i = 0; i < strs.length; i++) { - stripped.append(strs[i]); - } - control.getAccessible().addAccessibleListener(new ControlAccessibleListener(stripped.toString())); - } - - private class ControlAccessibleListener extends AccessibleAdapter { - private String controlName; - - ControlAccessibleListener(String name) { - controlName = name; - } - - @Override - public void getName(AccessibleEvent e) { - e.result = controlName; - } - } - - @Override - public boolean isValid(ILaunchConfiguration config) { - return fWorkingDirectoryBlock.isValid(config); - } - - @Override - public void setDefaults(ILaunchConfigurationWorkingCopy config) { - config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, (String) null); - config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY, (String) null); - } - - @Override - public void initializeFrom(ILaunchConfiguration configuration) { - try { - fPrgmArgumentsText - .setText(configuration.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, "")); //$NON-NLS-1$ - fWorkingDirectoryBlock.initializeFrom(configuration); - } catch (CoreException e) { - setErrorMessage(NLS.bind(LaunchMessages.Launch_common_Exception_occurred_reading_configuration_EXCEPTION, - e.getStatus().getMessage())); - LaunchUIPlugin.log(e); - } - } - - @Override - public void performApply(ILaunchConfigurationWorkingCopy configuration) { - configuration.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, - getAttributeValueFrom(fPrgmArgumentsText)); - fWorkingDirectoryBlock.performApply(configuration); - } - - /** - * Returns the string in the text widget, or <code>null</code> if empty. - * - * @return text or <code>null</code> - */ - protected String getAttributeValueFrom(Text text) { - String content = text.getText().trim(); - // Bug #131513 - eliminate Windows \r line delimiter - content = content.replaceAll("\r\n", "\n"); //$NON-NLS-1$//$NON-NLS-2$ - if (!content.isEmpty()) { - return content; - } - return null; - } - @Override public String getId() { return TAB_ID; } - - @Override - public String getName() { - return LaunchMessages.CArgumentsTab_Arguments; - } - - @Override - public void setLaunchConfigurationDialog(ILaunchConfigurationDialog dialog) { - super.setLaunchConfigurationDialog(dialog); - fWorkingDirectoryBlock.setLaunchConfigurationDialog(dialog); - } - - @Override - public String getErrorMessage() { - String m = super.getErrorMessage(); - if (m == null) { - return fWorkingDirectoryBlock.getErrorMessage(); - } - return m; - } - - @Override - public String getMessage() { - String m = super.getMessage(); - if (m == null) { - return fWorkingDirectoryBlock.getMessage(); - } - return m; - } - - @Override - public Image getImage() { - return LaunchImages.get(LaunchImages.IMG_VIEW_ARGUMENTS_TAB); - } - - @Override - protected void updateLaunchConfigurationDialog() { - super.updateLaunchConfigurationDialog(); - } } |