[91866] Schema-based Content Assist should be stricter (string externalization)
diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/XMLUIMessages.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/XMLUIMessages.java index 56a02ed..0c470f9 100644 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/XMLUIMessages.java +++ b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/XMLUIMessages.java
@@ -226,6 +226,9 @@ public static String Clear_all_blank_lines_UI_; public static String Grammar_Constraints; public static String Use_inferred_grammar_in_absence_of; + public static String Suggestion_Strategy; + public static String Suggestion_Strategy_Lax; + public static String Suggestion_Strategy_Strict; public static String Element____1; public static String Content_Model____2; public static String Attribute____3;
diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/XMLUIPluginResources.properties b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/XMLUIPluginResources.properties index b81047c..fed4031 100644 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/XMLUIPluginResources.properties +++ b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/XMLUIPluginResources.properties
@@ -254,6 +254,9 @@ Clear_all_blank_lines_UI_=Clear all &blank lines Grammar_Constraints=Grammar Constraints Use_inferred_grammar_in_absence_of=Use inferred grammar in absence of DTD/Schema +Suggestion_Strategy=&Suggestion strategy: +Suggestion_Strategy_Lax=Lax +Suggestion_Strategy_Strict=Strict ## tag info Element____1=Element : Content_Model____2=Content Model :
diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/AbstractContentAssistProcessor.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/AbstractContentAssistProcessor.java index 4e5da01..e256aa3 100644 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/AbstractContentAssistProcessor.java +++ b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/AbstractContentAssistProcessor.java
@@ -868,7 +868,7 @@ if (beginsWith(tagname, matchString)) { String proposedText = getRequiredText(parent, elementDecl); String proposedInfo = getAdditionalInfo(parentDecl, elementDecl); - int relevance = isStrictCMNodeSuggestion ? XMLRelevanceConstants.R_STICTLY_VALID_TAG_INSERTION : XMLRelevanceConstants.R_TAG_INSERTION; + int relevance = isStrictCMNodeSuggestion ? XMLRelevanceConstants.R_STRICTLY_VALID_TAG_INSERTION : XMLRelevanceConstants.R_TAG_INSERTION; CustomCompletionProposal proposal = new CustomCompletionProposal(proposedText, contentAssistRequest.getReplacementBeginPosition(), contentAssistRequest.getReplacementLength(), markupAdjustment, image, tagname, null, proposedInfo, relevance); contentAssistRequest.addProposal(proposal); }
diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/XMLRelevanceConstants.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/XMLRelevanceConstants.java index ae6dd76..1ac3554 100644 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/XMLRelevanceConstants.java +++ b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/XMLRelevanceConstants.java
@@ -44,7 +44,7 @@ // CMVC 246618 int R_REQUIRED = 10; int R_TAG_INSERTION = 500; - int R_STICTLY_VALID_TAG_INSERTION = 600; + int R_STRICTLY_VALID_TAG_INSERTION = 600; int R_TAG_NAME = 1200; int R_XML_ATTRIBUTE_NAME = 900; int R_XML_ATTRIBUTE_VALUE = 800;
diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/preferences/XMLSourcePreferencePage.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/preferences/XMLSourcePreferencePage.java index 4d47b0a..b611e44 100644 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/preferences/XMLSourcePreferencePage.java +++ b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/preferences/XMLSourcePreferencePage.java
@@ -12,6 +12,8 @@ *******************************************************************************/ package org.eclipse.wst.xml.ui.internal.preferences; +import java.util.Vector; + import org.eclipse.core.runtime.Preferences; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.swt.SWT; @@ -27,7 +29,7 @@ import org.eclipse.swt.widgets.Spinner; import org.eclipse.swt.widgets.Text; import org.eclipse.ui.IWorkbenchPreferencePage; -import org.eclipse.ui.help.WorkbenchHelp; +import org.eclipse.ui.PlatformUI; import org.eclipse.wst.sse.ui.internal.preferences.ui.AbstractPreferencePage; import org.eclipse.wst.xml.core.internal.XMLCorePlugin; import org.eclipse.wst.xml.core.internal.preferences.XMLCorePreferenceNames; @@ -43,7 +45,8 @@ protected Button fAutoPropose; protected Label fAutoProposeLabel; protected Text fAutoProposeText; - protected Combo fSuggestionStrategyCombo; + private Combo fSuggestionStrategyCombo; + private Vector fSuggestionStrategies = null; protected Button fClearAllBlankLines; // Formatting @@ -59,7 +62,7 @@ protected Control createContents(Composite parent) { Composite composite = (Composite) super.createContents(parent); - WorkbenchHelp.setHelp(composite, IHelpContextIds.XML_PREFWEBX_SOURCE_HELPID); + PlatformUI.getWorkbench().getHelpSystem().setHelp(composite, IHelpContextIds.XML_PREFWEBX_SOURCE_HELPID); createContentsForFormattingGroup(composite); createContentsForContentAssistGroup(composite); @@ -80,12 +83,15 @@ fAutoProposeLabel = createLabel(contentAssistGroup, XMLUIMessages.Prompt_when_these_characte_UI_); fAutoProposeText = createTextField(contentAssistGroup); - - createLabel(contentAssistGroup, "Suggestion strategy:"); - fSuggestionStrategyCombo = new Combo(contentAssistGroup, SWT.READ_ONLY); - fSuggestionStrategyCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - fSuggestionStrategyCombo.add("Lax"); - fSuggestionStrategyCombo.add("Strict"); + + createLabel(contentAssistGroup, XMLUIMessages.Suggestion_Strategy); + fSuggestionStrategyCombo = new Combo(contentAssistGroup, SWT.READ_ONLY); + fSuggestionStrategies = new Vector(); + fSuggestionStrategyCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + fSuggestionStrategyCombo.add(XMLUIMessages.Suggestion_Strategy_Lax); + fSuggestionStrategies.add(XMLUIPreferenceNames.SUGGESTION_STRATEGY_VALUE_LAX); + fSuggestionStrategyCombo.add(XMLUIMessages.Suggestion_Strategy_Strict); + fSuggestionStrategies.add(XMLUIPreferenceNames.SUGGESTION_STRATEGY_VALUE_STRICT); } protected void createContentsForFormattingGroup(Composite parent) { @@ -106,8 +112,8 @@ fIndentUsingTabs = createRadioButton(formattingGroup, XMLUIMessages.Indent_using_tabs); ((GridData) fIndentUsingTabs.getLayoutData()).horizontalSpan = 2; - - fIndentUsingSpaces = createRadioButton(formattingGroup, XMLUIMessages.Indent_using_spaces); + + fIndentUsingSpaces = createRadioButton(formattingGroup, XMLUIMessages.Indent_using_spaces); ((GridData) fIndentUsingSpaces.getLayoutData()).horizontalSpan = 2; createLabel(formattingGroup, XMLUIMessages.Indentation_size); @@ -144,7 +150,8 @@ if (fAutoPropose.getSelection()) { fAutoProposeLabel.setEnabled(true); fAutoProposeText.setEnabled(true); - } else { + } + else { fAutoProposeLabel.setEnabled(false); fAutoProposeText.setEnabled(false); } @@ -155,6 +162,19 @@ return XMLCorePlugin.getDefault().getPluginPreferences(); } + /** + * Return the currently selected suggestion strategy preference + * + * @return a suggestion strategy constant from XMLUIPreferenceNames + */ + private String getCurrentSuggestionStrategy() { + int i = fSuggestionStrategyCombo.getSelectionIndex(); + if (i >= 0) { + return (String) (fSuggestionStrategies.elementAt(i)); + } + return ""; //$NON-NLS-1$ + } + protected void initializeValues() { initializeValuesForFormattingGroup(); initializeValuesForContentAssistGroup(); @@ -164,8 +184,12 @@ protected void initializeValuesForContentAssistGroup() { // Content Assist fAutoPropose.setSelection(getPreferenceStore().getBoolean(XMLUIPreferenceNames.AUTO_PROPOSE)); - fAutoProposeText.setText(getPreferenceStore().getString(XMLUIPreferenceNames.AUTO_PROPOSE_CODE)); - fSuggestionStrategyCombo.setText(getPreferenceStore().getString(XMLUIPreferenceNames.SUGGESTION_STRATEGY)); + fAutoProposeText.setText(getPreferenceStore().getString(XMLUIPreferenceNames.AUTO_PROPOSE_CODE)); + String suggestionStrategy = getPreferenceStore().getString(XMLUIPreferenceNames.SUGGESTION_STRATEGY); + if (suggestionStrategy.length() > 0) + setCurrentSuggestionStrategy(suggestionStrategy); + else + setCurrentSuggestionStrategy(XMLUIPreferenceNames.SUGGESTION_STRATEGY_VALUE_LAX); } protected void initializeValuesForFormattingGroup() { @@ -177,7 +201,8 @@ if (XMLCorePreferenceNames.TAB.equals(getModelPreferences().getString(XMLCorePreferenceNames.INDENTATION_CHAR))) { fIndentUsingTabs.setSelection(true); fIndentUsingSpaces.setSelection(false); - } else { + } + else { fIndentUsingSpaces.setSelection(true); fIndentUsingTabs.setSelection(false); } @@ -204,9 +229,11 @@ // Content Assist fAutoPropose.setSelection(getPreferenceStore().getDefaultBoolean(XMLUIPreferenceNames.AUTO_PROPOSE)); fAutoProposeText.setText(getPreferenceStore().getDefaultString(XMLUIPreferenceNames.AUTO_PROPOSE_CODE)); - - // TODO.. (cs) we need to map the preference value to a translated name - fSuggestionStrategyCombo.setText(getPreferenceStore().getDefaultString(XMLUIPreferenceNames.SUGGESTION_STRATEGY)); + String suggestionStrategy = getPreferenceStore().getDefaultString(XMLUIPreferenceNames.SUGGESTION_STRATEGY); + if (suggestionStrategy.length() > 0) + setCurrentSuggestionStrategy(suggestionStrategy); + else + setCurrentSuggestionStrategy(XMLUIPreferenceNames.SUGGESTION_STRATEGY_VALUE_LAX); } protected void performDefaultsForFormattingGroup() { @@ -218,7 +245,8 @@ if (XMLCorePreferenceNames.TAB.equals(getModelPreferences().getDefaultString(XMLCorePreferenceNames.INDENTATION_CHAR))) { fIndentUsingTabs.setSelection(true); fIndentUsingSpaces.setSelection(false); - } else { + } + else { fIndentUsingSpaces.setSelection(true); fIndentUsingTabs.setSelection(false); } @@ -237,6 +265,22 @@ return result; } + /** + * Set a suggestion strategy in suggestion strategy combo box + * + * @param strategy + */ + private void setCurrentSuggestionStrategy(String strategy) { + // Clear the current selection. + fSuggestionStrategyCombo.clearSelection(); + fSuggestionStrategyCombo.deselectAll(); + + int i = fSuggestionStrategies.indexOf(strategy); + if (i >= 0) { + fSuggestionStrategyCombo.select(i); + } + } + protected void storeValues() { storeValuesForFormattingGroup(); storeValuesForContentAssistGroup(); @@ -247,7 +291,7 @@ // Content Assist getPreferenceStore().setValue(XMLUIPreferenceNames.AUTO_PROPOSE, fAutoPropose.getSelection()); getPreferenceStore().setValue(XMLUIPreferenceNames.AUTO_PROPOSE_CODE, fAutoProposeText.getText()); - getPreferenceStore().setValue(XMLUIPreferenceNames.SUGGESTION_STRATEGY, fSuggestionStrategyCombo.getText()); + getPreferenceStore().setValue(XMLUIPreferenceNames.SUGGESTION_STRATEGY, getCurrentSuggestionStrategy()); } protected void storeValuesForFormattingGroup() { @@ -258,7 +302,8 @@ if (fIndentUsingTabs.getSelection()) { getModelPreferences().setValue(XMLCorePreferenceNames.INDENTATION_CHAR, XMLCorePreferenceNames.TAB); - } else { + } + else { getModelPreferences().setValue(XMLCorePreferenceNames.INDENTATION_CHAR, XMLCorePreferenceNames.SPACE); } getModelPreferences().setValue(XMLCorePreferenceNames.INDENTATION_SIZE, fIndentationSize.getSelection()); @@ -278,7 +323,8 @@ int formattingLineWidth = Integer.parseInt(widthText); if ((formattingLineWidth < WIDTH_VALIDATION_LOWER_LIMIT) || (formattingLineWidth > WIDTH_VALIDATION_UPPER_LIMIT)) throw new NumberFormatException(); - } catch (NumberFormatException nfexc) { + } + catch (NumberFormatException nfexc) { setInvalidInputMessage(widthText); setValid(false); isError = true; @@ -291,7 +337,8 @@ indentSize = fIndentationSize.getSelection(); if ((indentSize < MIN_INDENTATION_SIZE) || (indentSize > MAX_INDENTATION_SIZE)) throw new NumberFormatException(); - } catch (NumberFormatException nfexc) { + } + catch (NumberFormatException nfexc) { setInvalidInputMessage(Integer.toString(indentSize)); setValid(false); isError = true;
diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/preferences/XMLUIPreferenceNames.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/preferences/XMLUIPreferenceNames.java index e0bda81..7269308 100644 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/preferences/XMLUIPreferenceNames.java +++ b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/preferences/XMLUIPreferenceNames.java
@@ -16,8 +16,8 @@ */ public class XMLUIPreferenceNames { - public final static String SUGGESTION_STRATEGY_VALUE_LAX = "Lax"; - public final static String SUGGESTION_STRATEGY_VALUE_STRICT = "Strict"; + public final static String SUGGESTION_STRATEGY_VALUE_LAX = "Lax"; //$NON-NLS-1$ + public final static String SUGGESTION_STRATEGY_VALUE_STRICT = "Strict"; //$NON-NLS-1$ /** * A named preference that controls if code assist gets auto activated. * <p>