From f024ed0dea872b8407327805f0e9702bf2b0cdf1 Mon Sep 17 00:00:00 2001 From: Leo Treggiari Date: Sat, 19 Nov 2005 20:30:18 +0000 Subject: [PATCH] Apply patch for Option, tooltip support (bugzilla 113363) --- .../schema/buildDefinitions.exsd | 2 +- .../cdt/managedbuilder/core/IOption.java | 17 ++ .../managedbuilder/internal/core/Option.java | 42 ++++ .../internal/core/OptionReference.java | 14 ++ .../BuildOptionComboFieldEditor.java | 67 ++++++ .../properties/BuildOptionSettingsPage.java | 210 +++++++----------- .../FileListControlFieldEditor.java | 51 +++++ 7 files changed, 278 insertions(+), 125 deletions(-) diff --git a/build/org.eclipse.cdt.managedbuilder.core/schema/buildDefinitions.exsd b/build/org.eclipse.cdt.managedbuilder.core/schema/buildDefinitions.exsd index 5564836249e..c2ce83c5cb0 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/schema/buildDefinitions.exsd +++ b/build/org.eclipse.cdt.managedbuilder.core/schema/buildDefinitions.exsd @@ -1144,7 +1144,7 @@ Additional special types exist to flag options of special relevance to the build - Specifies a "tip" that can be displayed in hover help or on the property page. Not implemented in 2.0. + Specifies a "tip" that can be displayed in hover help or on the property page. diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IOption.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IOption.java index ba8910af075..255483d0c6a 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IOption.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IOption.java @@ -7,6 +7,7 @@ * * Contributors: * IBM - Initial API and implementation + * ARM Ltd. - basic tooltip support *******************************************************************************/ package org.eclipse.cdt.managedbuilder.core; @@ -45,6 +46,7 @@ public interface IOption extends IBuildObject { public static final String CATEGORY = "category"; //$NON-NLS-1$ public static final String COMMAND = "command"; //$NON-NLS-1$ public static final String COMMAND_FALSE = "commandFalse"; //$NON-NLS-1$ + public static final String TOOL_TIP = "tip"; //$NON-NLS-1$ public static final String DEFAULT_VALUE = "defaultValue"; //$NON-NLS-1$ public static final String ENUM_VALUE = "enumeratedOptionValue"; //$NON-NLS-1$ public static final String IS_DEFAULT = "isDefault"; //$NON-NLS-1$ @@ -202,6 +204,21 @@ public interface IOption extends IBuildObject { */ public void setCommandFalse(String commandFalse); + /** + * Answers a String containing the tooltip + * associated with the option + * @return String + */ + public String getToolTip(); + + /** + * Sets a String containing the tooltip + * associated with the option + * + * @param String + */ + public void setToolTip(String tooltip); + /** * Answers the user-defined preprocessor symbols. * diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Option.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Option.java index 6fccf0108ee..d5a3e2f92ce 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Option.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Option.java @@ -7,6 +7,7 @@ * * Contributors: * IBM - Initial API and implementation + * ARM Ltd. - basic tooltip support *******************************************************************************/ package org.eclipse.cdt.managedbuilder.internal.core; @@ -59,6 +60,7 @@ public class Option extends BuildObject implements IOption { private String categoryId; private String command; private String commandFalse; + private String tip; private List enumList; private Map enumCommands; private Map enumNames; @@ -181,6 +183,9 @@ public class Option extends BuildObject implements IOption { if (option.commandFalse != null) { commandFalse = new String(option.commandFalse); } + if (option.tip != null) { + tip = new String(option.tip); + } if (option.categoryId != null) { categoryId = new String(option.categoryId); } @@ -294,6 +299,9 @@ public class Option extends BuildObject implements IOption { // Get the command defined for a Boolean option when the value is False commandFalse = element.getAttribute(COMMAND_FALSE); + // Get the tooltip for the option + tip = element.getAttribute(TOOL_TIP); + // Options hold different types of values String valueTypeStr = element.getAttribute(VALUE_TYPE); if (valueTypeStr != null) { @@ -407,6 +415,11 @@ public class Option extends BuildObject implements IOption { commandFalse = element.getAttribute(COMMAND_FALSE); } + // Get the tooltip for the option + if (element.hasAttribute(TOOL_TIP)) { + tip = element.getAttribute(TOOL_TIP); + } + // Options hold different types of values if (element.hasAttribute(VALUE_TYPE)) { String valueTypeStr = element.getAttribute(VALUE_TYPE); @@ -623,6 +636,10 @@ public class Option extends BuildObject implements IOption { element.setAttribute(COMMAND_FALSE, commandFalse); } + if (tip != null) { + element.setAttribute(TOOL_TIP, tip); + } + /* * Note: We store value & value-type as a pair, so we know what type of value we are * dealing with when we read it back in. @@ -978,6 +995,19 @@ public class Option extends BuildObject implements IOption { return commandFalse; } + /* (non-Javadoc) + * @see org.eclipse.cdt.managedbuilder.core.IOption#getToolTip() + */ + public String getToolTip() { + if (tip == null) { + if (superClass != null) { + return superClass.getToolTip(); + } else { + return EMPTY_STRING; + } + } + return tip; + } /* (non-Javadoc) * @see org.eclipse.cdt.managedbuilder.core.IOption#getDefinedSymbols() */ @@ -1339,6 +1369,17 @@ public class Option extends BuildObject implements IOption { } } + /* (non-Javadoc) + * @see org.eclipse.cdt.managedbuilder.core.IOption#setToolTip(String) + */ + public void setToolTip(String tooltip) { + if (tooltip == null && tip == null) return; + if (tooltip == null || tip == null || !tooltip.equals(tip)) { + tip = tooltip; + isDirty = true; + } + } + /* (non-Javadoc) * @see org.eclipse.cdt.managedbuilder.core.IOption#setResourceFilter(int) */ @@ -1521,6 +1562,7 @@ public class Option extends BuildObject implements IOption { categoryId == null && command == null && commandFalse == null && + tip == null && enumList == null && enumCommands == null && enumNames == null && diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/OptionReference.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/OptionReference.java index d09100a722b..3cc56e9934c 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/OptionReference.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/OptionReference.java @@ -7,6 +7,7 @@ * * Contributors: * IBM - Initial API and implementation + * ARM Ltd. - basic tooltip support *******************************************************************************/ package org.eclipse.cdt.managedbuilder.internal.core; @@ -294,6 +295,13 @@ public class OptionReference implements IOption { return option.getCommandFalse(); } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.build.managed.IOption#getToolTip() + */ + public String getToolTip() { + return option.getToolTip(); + } + /* (non-Javadoc) * @see org.eclipse.cdt.core.build.managed.IOption#getDefinedSymbols() */ @@ -750,6 +758,12 @@ public class OptionReference implements IOption { public void setCommandFalse(String cmd) { } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.build.managed.IOption#setToolTip(String) + */ + public void setToolTip(String tooltip) { + } + public PluginVersionIdentifier getVersion() { return option.getVersion(); } diff --git a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/BuildOptionComboFieldEditor.java b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/BuildOptionComboFieldEditor.java index 701f6333922..205f2cae63e 100644 --- a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/BuildOptionComboFieldEditor.java +++ b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/BuildOptionComboFieldEditor.java @@ -7,11 +7,13 @@ * * Contributors: * IBM Rational Software - Initial API and implementation + * ARM Ltd. - basic tooltip support *******************************************************************************/ package org.eclipse.cdt.managedbuilder.ui.properties; import org.eclipse.cdt.utils.ui.controls.ControlFactory; import org.eclipse.jface.preference.FieldEditor; +import org.eclipse.swt.SWTException; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.layout.GridData; @@ -40,6 +42,50 @@ public class BuildOptionComboFieldEditor extends FieldEditor { createControl(parent); } + /** + * @param name + * @param label + * @param tooltip + * @param opts + * @param sel + * @param parent + */ + public BuildOptionComboFieldEditor(String name, String label, String tooltip, String [] opts, String sel, Composite parent) { + this(name, label, opts, sel, parent); + setToolTip(tooltip); + } + + /** + * Sets the field editor's tool tip text to the argument, which + * may be null indicating that no tool tip text should be shown. + * + * @param string the new tool tip text (or null) + * + * @exception SWTException + */ + public void setToolTip(String tooltip) { + optionSelector.setToolTipText(tooltip); + getLabelControl().setToolTipText(tooltip); + } + + /** + * Returns the field editor's tool tip text, or null if it has + * not been set. + * + * @return the field editor's tool tip text + * + * @exception SWTException + */ + public String getToolTipText() { + return optionSelector.getToolTipText(); + } + /* (non-Javadoc) * @see org.eclipse.jface.preference.FieldEditor#adjustForNumColumns(int) */ @@ -128,6 +174,27 @@ public class BuildOptionComboFieldEditor extends FieldEditor { return 2; } + /** + * Returns this field editor's text control. + * + * @return the text control, or null if no + * text field is created yet + */ + protected Combo getComboControl() { + return optionSelector; + } + + /** + * Returns this field editor's text control. + * + * @return the text control, or null if no + * text field is created yet + */ + public Combo getComboControl(Composite parent) { + checkParent(optionSelector, parent); + return optionSelector; + } + /** * Set whether or not the controls in the field editor * are enabled. diff --git a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/BuildOptionSettingsPage.java b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/BuildOptionSettingsPage.java index 60279eaf64f..44076dd64f6 100644 --- a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/BuildOptionSettingsPage.java +++ b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/BuildOptionSettingsPage.java @@ -7,6 +7,7 @@ * * Contributors: * IBM Rational Software - Initial API and implementation + * ARM Ltd. - basic tooltip support *******************************************************************************/ package org.eclipse.cdt.managedbuilder.ui.properties; @@ -100,137 +101,98 @@ public class BuildOptionSettingsPage extends BuildSettingsPage { } else { config = clonedConfig; } + if (applicabilityCalculator == null || applicabilityCalculator.isOptionVisible(config, holder, opt)) { - try { - // Figure out which type the option is and add a proper field - // editor for it - switch (opt.getValueType()) { - case IOption.STRING: - // fix for PR 63973 - // Check browse type. - // If browsing is set, use a field editor that has a - // browse button of - // the appropriate type. - // Otherwise, use a regular text field. - switch (opt.getBrowseType()) { - case IOption.BROWSE_DIR: - Composite fieldEditorParent2 = getFieldEditorParent(); - DirectoryFieldEditor dirFieldEditor = new DirectoryFieldEditor( - prefName, opt.getName(), fieldEditorParent2); + try { + // Figure out which type the option is and add a proper field + // editor for it + Composite fieldEditorParent = getFieldEditorParent(); + FieldEditor fieldEditor; - setFieldEditorEnablement(holder, - opt, applicabilityCalculator, dirFieldEditor, fieldEditorParent2); - - addField(dirFieldEditor); - fieldsMap.put(prefName, dirFieldEditor); - fieldEditorsToParentMap.put(dirFieldEditor, fieldEditorParent2); - - break; - - case IOption.BROWSE_FILE: - Composite fieldEditorParent3 = getFieldEditorParent(); - FileFieldEditor fileFieldEditor = new FileFieldEditor( - prefName, opt.getName(), fieldEditorParent3); - - setFieldEditorEnablement(holder, - opt, applicabilityCalculator, fileFieldEditor, fieldEditorParent3); - - addField(fileFieldEditor); - fieldsMap.put(prefName, fileFieldEditor); - fieldEditorsToParentMap.put(fileFieldEditor, fieldEditorParent3); - break; - - case IOption.BROWSE_NONE: - Composite fieldEditorParent4 = getFieldEditorParent(); - StringFieldEditor stringField = new StringFieldEditor( - prefName, opt.getName(), fieldEditorParent4); - - setFieldEditorEnablement(holder, - opt, applicabilityCalculator, stringField, fieldEditorParent4); - - addField(stringField); - fieldsMap.put(prefName, stringField); - fieldEditorsToParentMap.put(stringField, fieldEditorParent4); - break; - - default: - // should not be possible - throw (new AssertionError()); - } - // end fix for 63973 - break; - case IOption.BOOLEAN: - Composite fieldEditorParent5 = getFieldEditorParent(); - BooleanFieldEditor booleanField = new BooleanFieldEditor( - prefName, opt.getName(), fieldEditorParent5); - - setFieldEditorEnablement(holder, - opt, applicabilityCalculator, booleanField, fieldEditorParent5); - - addField(booleanField); - fieldsMap.put(prefName, booleanField); - fieldEditorsToParentMap.put(booleanField, fieldEditorParent5); - break; - case IOption.ENUMERATED: - String selId; - String sel; - try { - selId = opt.getSelectedEnum(); - sel = opt.getEnumName(selId); - } catch (BuildException e) { - // If we get this exception, then the option type is - // wrong - break; - } - // Get all applicable values for this enumerated Option, But display - // only the enumerated values that are valid (static set of enumerated values defined - // in the plugin.xml file) in the UI Combobox. This refrains the user from selecting an - // invalid value and avoids issuing an error message. - String[] enumNames = opt.getApplicableValues(); - Vector enumValidList = new Vector(); - for (int i = 0; i < enumNames.length; ++i) { - if (opt.getValueHandler().isEnumValueAppropriate(config, - opt.getOptionHolder(), opt, opt.getValueHandlerExtraArgument(), enumNames[i])) { - enumValidList.add(enumNames[i]); + switch (opt.getValueType()) { + case IOption.STRING: { + StringFieldEditor stringField; + + // If browsing is set, use a field editor that has a + // browse button of the appropriate type. + switch (opt.getBrowseType()) { + case IOption.BROWSE_DIR: { + stringField = new DirectoryFieldEditor(prefName, opt.getName(), fieldEditorParent); + } break; + + case IOption.BROWSE_FILE: { + stringField = new FileFieldEditor(prefName, opt.getName(), fieldEditorParent); + } break; + + case IOption.BROWSE_NONE: { + stringField = new StringFieldEditor(prefName, opt.getName(), fieldEditorParent); + } break; + + default: { + throw new BuildException(null); + } } - } - String[] enumValidNames = new String[enumValidList.size()]; - enumValidList.copyInto(enumValidNames); - Composite fieldEditorParent6 = getFieldEditorParent(); - BuildOptionComboFieldEditor comboField = new BuildOptionComboFieldEditor( - prefName, opt.getName(), enumValidNames, sel, fieldEditorParent6); + stringField.getTextControl(fieldEditorParent).setToolTipText(opt.getToolTip()); + stringField.getLabelControl(fieldEditorParent).setToolTipText(opt.getToolTip()); + + fieldEditor = stringField; + } break; + + case IOption.BOOLEAN: { + class TooltipBooleanFieldEditor extends BooleanFieldEditor { + public TooltipBooleanFieldEditor(String name, String labelText, String tooltip, Composite parent) { + super(name, labelText, parent); + getChangeControl(parent).setToolTipText(tooltip); + } + } + + fieldEditor = new TooltipBooleanFieldEditor(prefName, opt.getName(), opt.getToolTip(), fieldEditorParent); + } break; + + case IOption.ENUMERATED: { + String selId = opt.getSelectedEnum(); + String sel = opt.getEnumName(selId); - setFieldEditorEnablement(holder, - opt, applicabilityCalculator, comboField, fieldEditorParent6); - - addField(comboField); - fieldsMap.put(prefName, comboField); - fieldEditorsToParentMap.put(comboField, fieldEditorParent6); - break; - case IOption.INCLUDE_PATH: - case IOption.STRING_LIST: - case IOption.PREPROCESSOR_SYMBOLS: - case IOption.LIBRARIES: - case IOption.OBJECTS: - - Composite fieldEditorParent7 = getFieldEditorParent(); - FileListControlFieldEditor listField = new FileListControlFieldEditor( - prefName, opt.getName(), fieldEditorParent7, opt.getBrowseType()); - - setFieldEditorEnablement(holder, - opt, applicabilityCalculator, listField, fieldEditorParent7); - - addField(listField); - fieldsMap.put(prefName, listField); - fieldEditorsToParentMap.put(listField, fieldEditorParent7); - break; - default: - break; + // Get all applicable values for this enumerated Option, But display + // only the enumerated values that are valid (static set of enumerated values defined + // in the plugin.xml file) in the UI Combobox. This refrains the user from selecting an + // invalid value and avoids issuing an error message. + String[] enumNames = opt.getApplicableValues(); + Vector enumValidList = new Vector(); + for (int i = 0; i < enumNames.length; ++i) { + if (opt.getValueHandler().isEnumValueAppropriate(config, + opt.getOptionHolder(), opt, opt.getValueHandlerExtraArgument(), enumNames[i])) { + enumValidList.add(enumNames[i]); + } + } + String[] enumValidNames = new String[enumValidList.size()]; + enumValidList.copyInto(enumValidNames); + + fieldEditor = new BuildOptionComboFieldEditor(prefName, opt.getName(), opt.getToolTip(), enumValidNames, sel, fieldEditorParent); + } break; + + case IOption.INCLUDE_PATH: + case IOption.STRING_LIST: + case IOption.PREPROCESSOR_SYMBOLS: + case IOption.LIBRARIES: + case IOption.OBJECTS: { + fieldEditor = new FileListControlFieldEditor(prefName, opt.getName(), opt.getToolTip(), fieldEditorParent, opt.getBrowseType()); + } break; + + default: + throw new BuildException(null); } - } catch (BuildException e) { - } + + setFieldEditorEnablement(holder, opt, applicabilityCalculator, fieldEditor, fieldEditorParent); + + addField(fieldEditor); + fieldsMap.put(prefName, fieldEditor); + fieldEditorsToParentMap.put(fieldEditor, fieldEditorParent); + + } catch (BuildException e) { + } } } } diff --git a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/FileListControlFieldEditor.java b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/FileListControlFieldEditor.java index 829176bf26c..867ccfe2124 100644 --- a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/FileListControlFieldEditor.java +++ b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/FileListControlFieldEditor.java @@ -7,6 +7,7 @@ * * Contributors: * BitMethods Inc - Initial API and implementation + * ARM Ltd. - basic tooltip support *******************************************************************************/ package org.eclipse.cdt.managedbuilder.ui.properties; @@ -58,6 +59,56 @@ public class FileListControlFieldEditor extends FieldEditor { list.setType(type); } + /** + * Creates a file list control field editor. + * @param name the name of the preference this field editor works on + * @param labelText the label text of the field editor + * @param tooltip the tooltip text of the field editor + * @param parent the parent of the field editor's control + * @param type the browseType of the file list control + */ + public FileListControlFieldEditor( + String name, + String labelText, + String tooltip, + Composite parent, + int type) { + this(name, labelText, parent, type); + // can't use setToolTip(tooltip) as label not created yet + getLabelControl(parent).setToolTipText(tooltip); + } + + /** + * Sets the field editor's tool tip text to the argument, which + * may be null indicating that no tool tip text should be shown. + * + * @param string the new tool tip text (or null) + * + * @exception SWTException + */ + public void setToolTip(String tooltip) { + // Currently just the label has the tooltip + getLabelControl().setToolTipText(tooltip); + } + + /** + * Returns the field editor's tool tip text, or null if it has + * not been set. + * + * @return the field editor's tool tip text + * + * @exception SWTException + */ + public String getToolTipText() { + return getLabelControl().getToolTipText(); + } + /** * Creates a file list control field editor. * @param name the name of the preference this field editor works on