diff --git a/org.eclipse.wildwebdeveloper.xml/plugin.properties b/org.eclipse.wildwebdeveloper.xml/plugin.properties
index 487d51a40f..e7de8f0b81 100644
--- a/org.eclipse.wildwebdeveloper.xml/plugin.properties
+++ b/org.eclipse.wildwebdeveloper.xml/plugin.properties
@@ -20,4 +20,10 @@ XMLCodeMiningsPreferencePage.preferenceKeywords.xmlcodeminings=xml codeminings
XMLFormattingPreferencePage.name=Formatting
XMLFormattingPreferencePage.preferenceKeywords.xmlformatting=xml formatting
XMLValidationPreferencePage.name=Validation & Resolution
-XMLValidationPreferencePage.preferenceKeywords.xmlvalidation=xml validation resolution download external sources
\ No newline at end of file
+XMLValidationPreferencePage.preferenceKeywords.xmlvalidation=xml validation resolution download external sources
+XMLFileRulesPreferencePage.name=File Rules
+XMLFileRulesPreferencePage.preferenceKeywords.xmlfilerules=xml file rules patterns document matcher colors references
+XMLColorsPreferencePage.name=Colors
+XMLColorsPreferencePage.preferenceKeywords.xmlcolors=xml colors xpath color document
+XMLReferencesPreferencePage.name=References
+XMLReferencesPreferencePage.preferenceKeywords.xmlreferences=xml references xpath from to navigation rename
\ No newline at end of file
diff --git a/org.eclipse.wildwebdeveloper.xml/plugin.xml b/org.eclipse.wildwebdeveloper.xml/plugin.xml
index ef31e674ee..fcf9451460 100644
--- a/org.eclipse.wildwebdeveloper.xml/plugin.xml
+++ b/org.eclipse.wildwebdeveloper.xml/plugin.xml
@@ -203,6 +203,27 @@
name="%XMLValidationPreferencePage.name">
+
+
+
+
+
+
+
+
+
@@ -219,6 +240,15 @@
+
+
+
T toModel(Object object, Class clazz) {
+ if (object == null) {
+ return null;
+ }
+ if (clazz == null) {
+ throw new IllegalArgumentException("Class can not be null");
+ }
+ if (object instanceof JsonElement) {
+ return gson.fromJson((JsonElement) object, clazz);
+ }
+ if (object instanceof Map) {
+ return gson.fromJson(gson.toJsonTree(object), clazz);
+ }
+ if (clazz.isInstance(object)) {
+ return clazz.cast(object);
+ }
+ return null;
+ }
+
+ private static GsonBuilder getDefaultGsonBuilder() {
+ return new GsonBuilder() //
+ .registerTypeAdapterFactory(new EnumTypeAdapter.Factory()) //
+ .registerTypeAdapterFactory(new EitherTypeAdapter.Factory());
+ }
+
+ /**
+ * Loads a list of objects from a preference store.
+ *
+ * @param the type of objects in the list
+ * @param store the preference store
+ * @param key the preference key
+ * @param clazz the class of the objects in the list
+ * @return a list of objects, or an empty list if preference is null/empty or
+ * parsing fails
+ */
+ public static List getList(IPreferenceStore store, String key, Class clazz) {
+ String json = store.getString(key);
+ return loadList(json, clazz);
+ }
+
+ /**
+ * Loads a list of objects from a JSON array string.
+ *
+ * @param the type of objects in the list
+ * @param json the JSON array string to parse
+ * @param clazz the class of the objects in the list
+ * @return a list of objects, or an empty list if json is null/empty or parsing
+ * fails
+ */
+ private static List loadList(String json, Class clazz) {
+ List entries = new ArrayList<>();
+ if (json == null || json.trim().isEmpty()) {
+ return entries;
+ }
+ try {
+ JsonElement element = JsonParser.parseString(json);
+ if (element.isJsonArray()) {
+ JsonArray array = element.getAsJsonArray();
+ for (int i = 0; i < array.size(); i++) {
+ T entry = toModel(array.get(i), clazz);
+ if (entry != null) {
+ entries.add(entry);
+ }
+ }
+ }
+ } catch (Exception e) {
+ // Log or handle parse error silently
+ }
+ return entries;
+ }
+
+ /**
+ * Saves a list of objects to a preference store.
+ *
+ * @param store the preference store
+ * @param key the preference key
+ * @param entries the list of objects to serialize
+ */
+ public static void setValue(IPreferenceStore store, String key, List> entries) {
+ String json = toJsonArray(entries);
+ store.setValue(key, json);
+ }
+
+ /**
+ * Saves a list of objects to a preference default store.
+ *
+ * @param store the preference store
+ * @param key the preference key
+ * @param entries the list of objects to serialize
+ */
+ public static void setDefault(IPreferenceStore store, String key, List> entries) {
+ String json = toJsonArray(entries);
+ store.setDefault(key, json);
+ }
+
+ /**
+ * Saves a list of objects to a JSON array string.
+ *
+ * @param entries the list of objects to serialize
+ * @return a JSON array string, or an empty string if the list is null or empty
+ */
+ private static String toJsonArray(List> entries) {
+ if (entries == null || entries.isEmpty()) {
+ return "";
+ }
+ JsonArray array = new JsonArray();
+ for (Object entry : entries) {
+ JsonElement element = gson.toJsonTree(entry);
+ array.add(element);
+ }
+ return array.toString();
+ }
+}
diff --git a/org.eclipse.wildwebdeveloper.xml/src/org/eclipse/wildwebdeveloper/xml/internal/autoinsert/XMLAutoInsertReconciler.java b/org.eclipse.wildwebdeveloper.xml/src/org/eclipse/wildwebdeveloper/xml/internal/autoinsert/XMLAutoInsertReconciler.java
index 4753b1e722..b5d9173e65 100644
--- a/org.eclipse.wildwebdeveloper.xml/src/org/eclipse/wildwebdeveloper/xml/internal/autoinsert/XMLAutoInsertReconciler.java
+++ b/org.eclipse.wildwebdeveloper.xml/src/org/eclipse/wildwebdeveloper/xml/internal/autoinsert/XMLAutoInsertReconciler.java
@@ -27,6 +27,7 @@
import org.eclipse.jface.text.reconciler.IReconciler;
import org.eclipse.jface.text.reconciler.IReconcilingStrategy;
import org.eclipse.lsp4e.LSPEclipseUtils;
+import org.eclipse.lsp4e.LanguageServerWrapper;
import org.eclipse.lsp4e.LanguageServers;
import org.eclipse.lsp4j.Position;
import org.eclipse.lsp4j.Range;
diff --git a/org.eclipse.wildwebdeveloper.xml/src/org/eclipse/wildwebdeveloper/xml/internal/commands/ArgumentsUtils.java b/org.eclipse.wildwebdeveloper.xml/src/org/eclipse/wildwebdeveloper/xml/internal/commands/ArgumentsUtils.java
index 17a19ed40a..660e7b33a2 100644
--- a/org.eclipse.wildwebdeveloper.xml/src/org/eclipse/wildwebdeveloper/xml/internal/commands/ArgumentsUtils.java
+++ b/org.eclipse.wildwebdeveloper.xml/src/org/eclipse/wildwebdeveloper/xml/internal/commands/ArgumentsUtils.java
@@ -12,15 +12,9 @@
package org.eclipse.wildwebdeveloper.xml.internal.commands;
import java.util.List;
-import java.util.Map;
import org.eclipse.lsp4j.Command;
-import org.eclipse.lsp4j.jsonrpc.json.adapters.EitherTypeAdapter;
-import org.eclipse.lsp4j.jsonrpc.json.adapters.EnumTypeAdapter;
-
-import com.google.gson.Gson;
-import com.google.gson.GsonBuilder;
-import com.google.gson.JsonElement;
+import org.eclipse.wildwebdeveloper.xml.internal.JsonUtils;
/**
* Arguments utilities.
@@ -30,8 +24,6 @@
*/
public class ArgumentsUtils {
- private static Gson gson = getDefaultGsonBuilder().create();
-
/**
* Returns the object from the given index as a given class type and null
* otherwise.
@@ -50,7 +42,7 @@ public static T getArgAt(Command command, int index, Class clazz) {
if (obj == null) {
throw new IllegalArgumentException("Cannot find command argument at " + index);
}
- return toModel(obj, clazz);
+ return JsonUtils.toModel(obj, clazz);
}
/**
@@ -68,29 +60,4 @@ public static Object getArgAt(List arguments, int index) {
return arguments.get(index);
}
- private static T toModel(Object object, Class clazz) {
- if (object == null) {
- return null;
- }
- if (clazz == null) {
- throw new IllegalArgumentException("Class can not be null");
- }
- if (object instanceof JsonElement) {
- return gson.fromJson((JsonElement) object, clazz);
- }
- if (object instanceof Map) {
- return gson.fromJson(gson.toJsonTree(object), clazz);
- }
- if (clazz.isInstance(object)) {
- return clazz.cast(object);
- }
- return null;
- }
-
- private static GsonBuilder getDefaultGsonBuilder() {
- return new GsonBuilder() //
- .registerTypeAdapterFactory(new EnumTypeAdapter.Factory()) //
- .registerTypeAdapterFactory(new EitherTypeAdapter.Factory());
- }
-
}
diff --git a/org.eclipse.wildwebdeveloper.xml/src/org/eclipse/wildwebdeveloper/xml/internal/ui/Messages.java b/org.eclipse.wildwebdeveloper.xml/src/org/eclipse/wildwebdeveloper/xml/internal/ui/Messages.java
index f557e86cb5..459ff3c7ce 100644
--- a/org.eclipse.wildwebdeveloper.xml/src/org/eclipse/wildwebdeveloper/xml/internal/ui/Messages.java
+++ b/org.eclipse.wildwebdeveloper.xml/src/org/eclipse/wildwebdeveloper/xml/internal/ui/Messages.java
@@ -91,6 +91,58 @@ public class Messages extends NLS {
public static String AssociateGrammarDialog_download_prompt_message;
public static String AssociateGrammarDialog_download_prompt_toggle;
+ // --------- DocumentMatcherWidget
+ public static String DocumentMatcherWidget_pattern;
+ public static String DocumentMatcherWidget_namespaceURI;
+ public static String DocumentMatcherWidget_rootElement;
+ public static String DocumentMatcherWidget_publicId;
+ public static String DocumentMatcherWidget_systemId;
+ public static String DocumentMatcherWidget_grammarURI;
+
+ // --------- XML Colors preference page
+ public static String XMLColorsPreferencePage_description;
+ public static String XMLColorsPreferencePage_entries;
+ public static String XMLColorsPreferencePage_column_pattern;
+ public static String XMLColorsPreferencePage_column_expressions;
+
+ // --------- XML Colors entry dialog
+ public static String XMLColorsEntryDialog_title_add;
+ public static String XMLColorsEntryDialog_title_edit;
+ public static String XMLColorsEntryDialog_matcher_group;
+ public static String XMLColorsEntryDialog_expressions_group;
+ public static String XMLColorsEntryDialog_column_xpath;
+ public static String XMLColorsEntryDialog_error_pattern_required;
+ public static String XMLColorsEntryDialog_error_expression_required;
+ public static String XMLColorsEntryDialog_input_xpath_title;
+ public static String XMLColorsEntryDialog_input_xpath_message;
+ public static String XMLColorsEntryDialog_edit_button;
+
+ // --------- XML References preference page
+ public static String XMLReferencesPreferencePage_description;
+ public static String XMLReferencesPreferencePage_entries;
+ public static String XMLReferencesPreferencePage_column_pattern;
+ public static String XMLReferencesPreferencePage_column_expressions;
+
+ // --------- XML References entry dialog
+ public static String XMLReferencesEntryDialog_title_add;
+ public static String XMLReferencesEntryDialog_title_edit;
+ public static String XMLReferencesEntryDialog_matcher_group;
+ public static String XMLReferencesEntryDialog_expressions_group;
+ public static String XMLReferencesEntryDialog_column_from;
+ public static String XMLReferencesEntryDialog_column_to;
+ public static String XMLReferencesEntryDialog_column_prefix;
+ public static String XMLReferencesEntryDialog_column_multiple;
+ public static String XMLReferencesEntryDialog_error_pattern_required;
+ public static String XMLReferencesEntryDialog_error_expression_required;
+ public static String XMLReferencesEntryDialog_error_from_required;
+ public static String XMLReferencesEntryDialog_error_to_required;
+ public static String XMLReferencesEntryDialog_edit_expression_title;
+ public static String XMLReferencesEntryDialog_edit_expression_title_add;
+ public static String XMLReferencesEntryDialog_edit_expression_from;
+ public static String XMLReferencesEntryDialog_edit_expression_to;
+ public static String XMLReferencesEntryDialog_edit_expression_prefix;
+ public static String XMLReferencesEntryDialog_edit_expression_multiple;
+
// --------- Buttons
public static String Add_button;
public static String Remove_button;
diff --git a/org.eclipse.wildwebdeveloper.xml/src/org/eclipse/wildwebdeveloper/xml/internal/ui/messages.properties b/org.eclipse.wildwebdeveloper.xml/src/org/eclipse/wildwebdeveloper/xml/internal/ui/messages.properties
index 1f35c8eb64..6d866aaefe 100644
--- a/org.eclipse.wildwebdeveloper.xml/src/org/eclipse/wildwebdeveloper/xml/internal/ui/messages.properties
+++ b/org.eclipse.wildwebdeveloper.xml/src/org/eclipse/wildwebdeveloper/xml/internal/ui/messages.properties
@@ -86,6 +86,58 @@ AssociateGrammarDialog_download_prompt_title=Enable download of external resourc
AssociateGrammarDialog_download_prompt_message=The preference "Download external resources like referenced DTD, XSD" is currently disabled.\n\nWithout it, LemMinX will not fetch the remote grammar and grammar-driven features (completion, validation, hover, code actions…) will be unavailable.\n\nDo you want to enable it now?
AssociateGrammarDialog_download_prompt_toggle=Don''t ask again
+# DocumentMatcherWidget
+DocumentMatcherWidget_pattern=&Pattern:
+DocumentMatcherWidget_namespaceURI=Namespace URI:
+DocumentMatcherWidget_rootElement=Root &Element:
+DocumentMatcherWidget_publicId=Public ID:
+DocumentMatcherWidget_systemId=System ID:
+DocumentMatcherWidget_grammarURI=Grammar URI:
+
+# XML Colors preference page
+XMLColorsPreferencePage_description=Configure which XML attributes or text nodes contain color values, matched by XPath expressions per file pattern.
+XMLColorsPreferencePage_entries=Color entries
+XMLColorsPreferencePage_column_pattern=File Pattern
+XMLColorsPreferencePage_column_expressions=XPath Expression(s)
+
+# XML Colors entry dialog
+XMLColorsEntryDialog_title_add=Add Color Entry
+XMLColorsEntryDialog_title_edit=Edit Color Entry
+XMLColorsEntryDialog_matcher_group=Document Matcher
+XMLColorsEntryDialog_expressions_group=XPath Expressions
+XMLColorsEntryDialog_column_xpath=XPath Expression
+XMLColorsEntryDialog_error_pattern_required=A file pattern is required.
+XMLColorsEntryDialog_error_expression_required=At least one XPath expression is required.
+XMLColorsEntryDialog_input_xpath_title=XPath Expression
+XMLColorsEntryDialog_input_xpath_message=Enter an XPath expression (e.g. resources/color/text() or @color):
+XMLColorsEntryDialog_edit_button=\uD83D\uDD0F &Edit...
+
+# XML References preference page
+XMLReferencesPreferencePage_description=Configure cross-element references using XPath from/to expressions, enabling navigation, completion, and rename across XML documents.
+XMLReferencesPreferencePage_entries=Reference entries
+XMLReferencesPreferencePage_column_pattern=File Pattern
+XMLReferencesPreferencePage_column_expressions=Expression(s)
+
+# XML References entry dialog
+XMLReferencesEntryDialog_title_add=Add Reference Entry
+XMLReferencesEntryDialog_title_edit=Edit Reference Entry
+XMLReferencesEntryDialog_matcher_group=Document Matcher
+XMLReferencesEntryDialog_expressions_group=Reference Expressions
+XMLReferencesEntryDialog_column_from=From XPath
+XMLReferencesEntryDialog_column_to=To XPath
+XMLReferencesEntryDialog_column_prefix=Prefix
+XMLReferencesEntryDialog_column_multiple=Multiple
+XMLReferencesEntryDialog_error_pattern_required=A file pattern is required.
+XMLReferencesEntryDialog_error_expression_required=At least one reference expression is required.
+XMLReferencesEntryDialog_error_from_required=The 'from' XPath is required.
+XMLReferencesEntryDialog_error_to_required=The 'to' XPath is required.
+XMLReferencesEntryDialog_edit_expression_title=Edit Reference Expression
+XMLReferencesEntryDialog_edit_expression_title_add=Add Reference Expression
+XMLReferencesEntryDialog_edit_expression_from=&From XPath:
+XMLReferencesEntryDialog_edit_expression_to=&To XPath:
+XMLReferencesEntryDialog_edit_expression_prefix=Pre&fix:
+XMLReferencesEntryDialog_edit_expression_multiple=&Multiple values
+
# Buttons
Add_button=\u2795 &Add...
Remove_button=\uD83D\uDDD1 &Remove
diff --git a/org.eclipse.wildwebdeveloper.xml/src/org/eclipse/wildwebdeveloper/xml/internal/ui/preferences/XMLPreferenceInitializer.java b/org.eclipse.wildwebdeveloper.xml/src/org/eclipse/wildwebdeveloper/xml/internal/ui/preferences/XMLPreferenceInitializer.java
index 3261e43633..b6587436cd 100644
--- a/org.eclipse.wildwebdeveloper.xml/src/org/eclipse/wildwebdeveloper/xml/internal/ui/preferences/XMLPreferenceInitializer.java
+++ b/org.eclipse.wildwebdeveloper.xml/src/org/eclipse/wildwebdeveloper/xml/internal/ui/preferences/XMLPreferenceInitializer.java
@@ -15,6 +15,7 @@
import static org.eclipse.wildwebdeveloper.xml.internal.ui.preferences.XMLPreferenceClientConstants.XML_PREFERENCES_AUTO_INSERT_QUOTE_ATTRIBUTES;
import static org.eclipse.wildwebdeveloper.xml.internal.ui.preferences.XMLPreferenceServerConstants.XML_PREFERENCES_CATAGLOGS;
import static org.eclipse.wildwebdeveloper.xml.internal.ui.preferences.XMLPreferenceServerConstants.XML_PREFERENCES_CODEMININGS_ENABLED;
+import static org.eclipse.wildwebdeveloper.xml.internal.ui.preferences.XMLPreferenceServerConstants.XML_PREFERENCES_COLORS;
import static org.eclipse.wildwebdeveloper.xml.internal.ui.preferences.XMLPreferenceServerConstants.XML_PREFERENCES_DOWNLOAD_EXTERNAL_RESOURCES;
import static org.eclipse.wildwebdeveloper.xml.internal.ui.preferences.XMLPreferenceServerConstants.XML_PREFERENCES_FOLDING_INCLUDE_CLOSING_TAG_IN_FOLD;
import static org.eclipse.wildwebdeveloper.xml.internal.ui.preferences.XMLPreferenceServerConstants.XML_PREFERENCES_FORMAT_CLOSING_BRACKET_NEW_LINE;
@@ -35,6 +36,7 @@
import static org.eclipse.wildwebdeveloper.xml.internal.ui.preferences.XMLPreferenceServerConstants.XML_PREFERENCES_FORMAT_TRIM_FINAL_NEWLINES;
import static org.eclipse.wildwebdeveloper.xml.internal.ui.preferences.XMLPreferenceServerConstants.XML_PREFERENCES_FORMAT_TRIM_TRAILING_WHITESPACE;
import static org.eclipse.wildwebdeveloper.xml.internal.ui.preferences.XMLPreferenceServerConstants.XML_PREFERENCES_FORMAT_XSI_SCHEMA_LOCATION_SPLIT;
+import static org.eclipse.wildwebdeveloper.xml.internal.ui.preferences.XMLPreferenceServerConstants.XML_PREFERENCES_REFERENCES;
import static org.eclipse.wildwebdeveloper.xml.internal.ui.preferences.XMLPreferenceServerConstants.XML_PREFERENCES_VALIDATION_DISALLOW_DOCTYPE_DECL;
import static org.eclipse.wildwebdeveloper.xml.internal.ui.preferences.XMLPreferenceServerConstants.XML_PREFERENCES_VALIDATION_ENABLED;
import static org.eclipse.wildwebdeveloper.xml.internal.ui.preferences.XMLPreferenceServerConstants.XML_PREFERENCES_VALIDATION_NAMESPACES_ENABLED;
@@ -50,7 +52,10 @@
import org.eclipse.jface.dialogs.MessageDialogWithToggle;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.wildwebdeveloper.xml.internal.Activator;
+import org.eclipse.wildwebdeveloper.xml.internal.JsonUtils;
import org.eclipse.wildwebdeveloper.xml.internal.commands.AssociateGrammarDialog;
+import org.eclipse.wildwebdeveloper.xml.internal.ui.preferences.filerules.colors.XMLColorsEntry;
+import org.eclipse.wildwebdeveloper.xml.internal.ui.preferences.filerules.references.XMLReferencesEntry;
/**
* XML preference initializer.
@@ -60,7 +65,7 @@ public class XMLPreferenceInitializer extends AbstractPreferenceInitializer {
private static final IPreferenceStore STORE = Activator.getDefault().getPreferenceStore();
- private static final List DEFAULT_PRESERVE_SPACE = Arrays.asList(//
+ private static final String DEFAULT_PRESERVE_SPACE = Arrays.asList(//
"xsl:text", //
"xsl:comment", //
"xsl:processing-instruction", //
@@ -69,7 +74,39 @@ public class XMLPreferenceInitializer extends AbstractPreferenceInitializer {
"screen", //
"synopsis", //
"pre", //
- "xd:pre");
+ "xd:pre").stream() //
+ .collect(Collectors.joining(","));
+
+ public static final List DEFAULT_COLORS = List.of(//
+ // Android colors
+ new XMLColorsEntry() //
+ .setPattern("**/colors.xml") //
+ .addExpression("//color/text()"));
+
+ public static final List DEFAULT_REFERENCES = List.of(//
+ // DocBook 4 with DTD -//OASIS//DTD DocBook XML
+ new XMLReferencesEntry() //
+ .setPublicId(List.of("-//OASIS//DTD DocBook XML*")) //
+ .addExpression("xref/@linkend", "@id"),
+ // DocBook 5 with http://docbook.org/ns/docbook namespace
+ new XMLReferencesEntry() //
+ .setNamespaceURI(List.of("http://docbook.org/ns/docbook")) //
+ .addExpression("xref/@linkend", "@xml:id"),
+ // TEI (Text Encoding Initiative)
+ new XMLReferencesEntry() //
+ .setNamespaceURI(List.of("http://www.tei-c.org/ns/1.0")) //
+ .setPrefix("#") //
+ .addExpression("@resp", "persName/@xml:id") //
+ .addExpression("@corresp", "@xml:id"),
+ // Java Servlet web.xml
+ new XMLReferencesEntry() //
+ .setPattern("**/web.xml") //
+ .setNamespaceURI(List.of("http://xmlns.jcp.org/xml/ns/javaee", "http://java.sun.com/xml/ns/javaee",
+ "http://java.sun.com/xml/ns/j2ee")) //
+ .setPrefix(null) //
+ .addExpression("servlet-mapping/servlet-name/text()", "servlet/servlet-name/text()") //
+ .addExpression("filter-mapping/filter-name/text()", "filter/filter-name/text()") //
+ .addExpression("error-page/exception-type/text()", "//servlet/servlet-class/text()"));
@Override
public void initializeDefaultPreferences() {
@@ -97,8 +134,7 @@ public void initializeDefaultPreferences() {
STORE.setDefault(XML_PREFERENCES_FORMAT_INSERT_FINAL_NEWLINE.preferenceId, false);
STORE.setDefault(XML_PREFERENCES_FORMAT_TRIM_FINAL_NEWLINES.preferenceId, false);
STORE.setDefault(XML_PREFERENCES_FORMAT_TRIM_TRAILING_WHITESPACE.preferenceId, false);
- STORE.setDefault(XML_PREFERENCES_FORMAT_PRESERVE_SPACE.preferenceId,
- DEFAULT_PRESERVE_SPACE.stream().collect(Collectors.joining(",")));
+ STORE.setDefault(XML_PREFERENCES_FORMAT_PRESERVE_SPACE.preferenceId, DEFAULT_PRESERVE_SPACE);
STORE.setDefault(XML_PREFERENCES_FORMAT_EMPTY_ELEMENTS.preferenceId, "ignore");
STORE.setDefault(XML_PREFERENCES_FORMAT_SPACE_BEFORE_EMPTY_CLOSE_TAG.preferenceId, true);
@@ -117,6 +153,13 @@ public void initializeDefaultPreferences() {
STORE.setDefault(XML_PREFERENCES_VALIDATION_DISALLOW_DOCTYPE_DECL.preferenceId, false);
STORE.setDefault(XML_PREFERENCES_VALIDATION_RESOLVE_EXTERNAL_ENTITIES.preferenceId, false);
STORE.setDefault(XML_PREFERENCES_VALIDATION_NO_GRAMMAR.preferenceId, "hint");
+
+ // Colors settings - with default entry for Android colors.xml
+ JsonUtils.setDefault(STORE, XML_PREFERENCES_COLORS.preferenceId, DEFAULT_COLORS);
+
+ // References settings -with default entry for docbook
+ JsonUtils.setDefault(STORE, XML_PREFERENCES_REFERENCES.preferenceId, DEFAULT_REFERENCES);
+
}
}
\ No newline at end of file
diff --git a/org.eclipse.wildwebdeveloper.xml/src/org/eclipse/wildwebdeveloper/xml/internal/ui/preferences/XMLPreferenceServerConstants.java b/org.eclipse.wildwebdeveloper.xml/src/org/eclipse/wildwebdeveloper/xml/internal/ui/preferences/XMLPreferenceServerConstants.java
index 3fb9cff479..9d74284877 100644
--- a/org.eclipse.wildwebdeveloper.xml/src/org/eclipse/wildwebdeveloper/xml/internal/ui/preferences/XMLPreferenceServerConstants.java
+++ b/org.eclipse.wildwebdeveloper.xml/src/org/eclipse/wildwebdeveloper/xml/internal/ui/preferences/XMLPreferenceServerConstants.java
@@ -15,6 +15,7 @@
import java.io.File;
import java.util.Arrays;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
@@ -23,6 +24,10 @@
import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.wildwebdeveloper.xml.internal.Activator;
+import com.google.gson.Gson;
+import com.google.gson.JsonArray;
+import com.google.gson.JsonParser;
+
/**
* XML pXMLPreferenceServerConstantsants.
*
@@ -131,6 +136,12 @@ public void storeToLemminxOptions(Object value, Map options) {
public static final LemminxPreference XML_PREFERENCES_FORMAT_JOIN_CDATA_LINES = new LemminxPreference(
"format/joinCDATALines");
+ // Colors settings
+ public static final LemminxPreference XML_PREFERENCES_COLORS = new LemminxPreference("colors");
+
+ // References settings
+ public static final LemminxPreference XML_PREFERENCES_REFERENCES = new LemminxPreference("references");
+
// Validation settings
public static final LemminxPreference XML_PREFERENCES_VALIDATION_ENABLED = new LemminxPreference(
"validation/enabled");
@@ -173,7 +184,9 @@ public void storeToLemminxOptions(Object value, Map options) {
XML_PREFERENCES_VALIDATION_SCHEMA_ENABLED, //
XML_PREFERENCES_VALIDATION_DISALLOW_DOCTYPE_DECL, //
XML_PREFERENCES_VALIDATION_RESOLVE_EXTERNAL_ENTITIES, //
- XML_PREFERENCES_VALIDATION_NO_GRAMMAR };
+ XML_PREFERENCES_VALIDATION_NO_GRAMMAR, //
+ XML_PREFERENCES_COLORS, //
+ XML_PREFERENCES_REFERENCES };
public static Optional getLemminxPreference(PropertyChangeEvent event) {
return Arrays.stream(ALL_LEMMINX_PREFERENCES)
@@ -225,6 +238,12 @@ public static void storePreferencesToLemminxOptions(IPreferenceStore store, Map<
setAsBoolean(XML_PREFERENCES_VALIDATION_DISALLOW_DOCTYPE_DECL, store, xmlOpts);
setAsBoolean(XML_PREFERENCES_VALIDATION_RESOLVE_EXTERNAL_ENTITIES, store, xmlOpts);
setAsString(XML_PREFERENCES_VALIDATION_NO_GRAMMAR, store, xmlOpts);
+
+ // Colors settings
+ setAsJsonArray(XML_PREFERENCES_COLORS, store, xmlOpts);
+
+ // References settings
+ setAsJsonArray(XML_PREFERENCES_REFERENCES, store, xmlOpts);
}
private static void setAsString(LemminxPreference preference, IPreferenceStore store, Map xmlOpts) {
@@ -245,4 +264,20 @@ private static void setAsInt(LemminxPreference preference, IPreferenceStore stor
preference.storeToLemminxOptions(store.getInt(preference.preferenceId), xmlOpts);
}
+ private static void setAsJsonArray(LemminxPreference preference, IPreferenceStore store,
+ Map xmlOpts) {
+ String json = store.getString(preference.preferenceId);
+ if (json != null && !json.isBlank() && !json.equals("[]")) {
+ try {
+ JsonArray arr = JsonParser.parseString(json).getAsJsonArray();
+ if (!arr.isEmpty()) {
+ List> list = new Gson().fromJson(arr, List.class);
+ preference.storeToLemminxOptions(list, xmlOpts);
+ }
+ } catch (Exception e) {
+ // ignore malformed JSON
+ }
+ }
+ }
+
}
diff --git a/org.eclipse.wildwebdeveloper.xml/src/org/eclipse/wildwebdeveloper/xml/internal/ui/preferences/filerules/AbstractDocumentMatcherEntryDialog.java b/org.eclipse.wildwebdeveloper.xml/src/org/eclipse/wildwebdeveloper/xml/internal/ui/preferences/filerules/AbstractDocumentMatcherEntryDialog.java
new file mode 100644
index 0000000000..45b6ee7494
--- /dev/null
+++ b/org.eclipse.wildwebdeveloper.xml/src/org/eclipse/wildwebdeveloper/xml/internal/ui/preferences/filerules/AbstractDocumentMatcherEntryDialog.java
@@ -0,0 +1,355 @@
+/*******************************************************************************
+ * Copyright (c) 2026 Red Hat Inc. and others.
+ *
+ * This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License 2.0
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Angelo ZERR (Red Hat Inc.) - initial implementation
+ *******************************************************************************/
+package org.eclipse.wildwebdeveloper.xml.internal.ui.preferences.filerules;
+
+import static org.eclipse.swt.events.SelectionListener.widgetSelectedAdapter;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.TitleAreaDialog;
+import org.eclipse.jface.viewers.ArrayContentProvider;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.TableLayout;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.window.Window;
+import org.eclipse.swt.SWT;
+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.Shell;
+import org.eclipse.wildwebdeveloper.xml.internal.ui.Messages;
+
+/**
+ * Abstract base class for dialogs that edit DocumentMatcherEntry items with
+ * expressions.
+ *
+ * @param the type of DocumentMatcherEntry
+ * @param the type of expression
+ */
+public abstract class AbstractDocumentMatcherEntryDialog extends TitleAreaDialog {
+
+ private final T initialEntry;
+ private T result;
+
+ protected DocumentMatcherWidget matcherWidget;
+ protected TableViewer expressionsViewer;
+ protected final List expressions = new ArrayList<>();
+
+ private Button editButton;
+ private Button removeButton;
+
+ public AbstractDocumentMatcherEntryDialog(Shell parentShell, T entry) {
+ super(parentShell);
+ this.initialEntry = entry;
+ setShellStyle(getShellStyle() | SWT.RESIZE);
+ }
+
+ @Override
+ public void create() {
+ super.create();
+ String title = initialEntry == null ? getAddTitle() : getEditTitle();
+ setTitle(title);
+ getShell().setText(title);
+ validate();
+ }
+
+ @Override
+ protected Control createDialogArea(Composite parent) {
+ Composite area = (Composite) super.createDialogArea(parent);
+ Composite container = new Composite(area, SWT.NONE);
+ container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ container.setLayout(new GridLayout(1, false));
+
+ // Document Matcher group
+ Group matcherGroup = new Group(container, SWT.NONE);
+ matcherGroup.setText(getMatcherGroupTitle());
+ matcherGroup.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
+ matcherGroup.setLayout(new GridLayout(1, false));
+
+ matcherWidget = createMatcherWidget(matcherGroup);
+ matcherWidget.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
+ matcherWidget.getPatternText().addModifyListener(e -> validate());
+ matcherWidget.setMatchersChangedListener(() -> validate());
+
+ // Expressions group
+ Group expressionsGroup = new Group(container, SWT.NONE);
+ expressionsGroup.setText(getExpressionsGroupTitle());
+ expressionsGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ expressionsGroup.setLayout(new GridLayout(2, false));
+
+ expressionsViewer = new TableViewer(expressionsGroup,
+ SWT.BORDER | SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL);
+ expressionsViewer.getTable().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ expressionsViewer.getTable().setHeaderVisible(true);
+ expressionsViewer.getTable().setLinesVisible(true);
+
+ TableLayout tableLayout = new TableLayout();
+ expressionsViewer.getTable().setLayout(tableLayout);
+
+ // Create expression-specific columns
+ createExpressionColumns(expressionsViewer, tableLayout);
+
+ expressionsViewer.setContentProvider(ArrayContentProvider.getInstance());
+ expressionsViewer.setInput(expressions);
+ expressionsViewer.addSelectionChangedListener(e -> updateButtons());
+ expressionsViewer.addDoubleClickListener(e -> editExpression());
+
+ // Buttons
+ Composite btnComposite = new Composite(expressionsGroup, SWT.NONE);
+ btnComposite.setLayout(new GridLayout(1, false));
+ btnComposite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false));
+
+ Button addButton = new Button(btnComposite, SWT.PUSH);
+ addButton.setText(Messages.Add_button);
+ addButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
+ addButton.addSelectionListener(widgetSelectedAdapter(e -> addExpression()));
+
+ editButton = new Button(btnComposite, SWT.PUSH);
+ editButton.setText(Messages.XMLColorsEntryDialog_edit_button);
+ editButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
+ editButton.setEnabled(false);
+ editButton.addSelectionListener(widgetSelectedAdapter(e -> editExpression()));
+
+ removeButton = new Button(btnComposite, SWT.PUSH);
+ removeButton.setText(Messages.Remove_button);
+ removeButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
+ removeButton.setEnabled(false);
+ removeButton.addSelectionListener(widgetSelectedAdapter(e -> removeExpression()));
+
+ // Load initial data
+ if (initialEntry != null) {
+ loadMatcherFromEntry(initialEntry);
+ List initialExpressions = getExpressionsFromEntry(initialEntry);
+ if (initialExpressions != null) {
+ expressions.addAll(initialExpressions);
+ expressionsViewer.refresh();
+ }
+ } else {
+ // Load default values for new entries
+ loadDefaultValues();
+ }
+
+ return area;
+ }
+
+ private void addExpression() {
+ Object dialog = createExpressionDialog(null);
+ if (openDialog(dialog) == Window.OK) {
+ expressions.add(getDialogResult(dialog));
+ expressionsViewer.refresh();
+ validate();
+ }
+ }
+
+ private void editExpression() {
+ IStructuredSelection sel = expressionsViewer.getStructuredSelection();
+ if (sel.isEmpty())
+ return;
+ @SuppressWarnings("unchecked")
+ E current = (E) sel.getFirstElement();
+ int idx = expressions.indexOf(current);
+ Object dialog = createExpressionDialog(current);
+ if (openDialog(dialog) == Window.OK) {
+ expressions.set(idx, getDialogResult(dialog));
+ expressionsViewer.refresh();
+ }
+ }
+
+ private void removeExpression() {
+ IStructuredSelection sel = expressionsViewer.getStructuredSelection();
+ if (!sel.isEmpty()) {
+ expressions.remove(sel.getFirstElement());
+ expressionsViewer.refresh();
+ validate();
+ }
+ }
+
+ private void updateButtons() {
+ boolean hasSelection = !expressionsViewer.getStructuredSelection().isEmpty();
+ editButton.setEnabled(hasSelection);
+ removeButton.setEnabled(hasSelection);
+ }
+
+ protected void validate() {
+ String error = null;
+ if (matcherWidget != null && !hasAnyMatcher()) {
+ error = "At least one matcher criterion is required (pattern, namespace, root element, publicId, systemId, or grammar)";
+ } else if (expressions.isEmpty()) {
+ error = getExpressionRequiredError();
+ }
+ setErrorMessage(error);
+ Button ok = getButton(IDialogConstants.OK_ID);
+ if (ok != null) {
+ ok.setEnabled(error == null);
+ }
+ }
+
+ /**
+ * Check if at least one matcher criterion is specified.
+ * According to VSCode XML documentation, pattern is optional if other matchers are provided.
+ */
+ private boolean hasAnyMatcher() {
+ if (!matcherWidget.getPattern().isEmpty()) return true;
+ if (matcherWidget.getNamespaceURI() != null && !matcherWidget.getNamespaceURI().isEmpty()) return true;
+ if (matcherWidget.getRootElement() != null && !matcherWidget.getRootElement().isEmpty()) return true;
+ if (matcherWidget.getPublicId() != null && !matcherWidget.getPublicId().isEmpty()) return true;
+ if (matcherWidget.getSystemId() != null && !matcherWidget.getSystemId().isEmpty()) return true;
+ if (matcherWidget.getGrammarURI() != null && !matcherWidget.getGrammarURI().isEmpty()) return true;
+ return false;
+ }
+
+ @Override
+ protected void okPressed() {
+ result = createEntry();
+ saveMatcherToEntry(result);
+ setExpressionsToEntry(result, new ArrayList<>(expressions));
+ super.okPressed();
+ }
+
+ public T getResult() {
+ return result;
+ }
+
+ // Helper methods for matcher widget
+
+ /**
+ * Create the matcher widget. Subclasses can override to provide a custom widget.
+ *
+ * @param parent the parent composite
+ * @return the matcher widget
+ */
+ protected DocumentMatcherWidget createMatcherWidget(Composite parent) {
+ return new DocumentMatcherWidget(parent, SWT.NONE);
+ }
+
+ protected void loadMatcherFromEntry(T entry) {
+ matcherWidget.setPattern(entry.getPattern());
+ matcherWidget.setNamespaceURI(entry.getNamespaceURI());
+ matcherWidget.setRootElement(entry.getRootElement());
+ matcherWidget.setPublicId(entry.getPublicId());
+ matcherWidget.setSystemId(entry.getSystemId());
+ matcherWidget.setGrammarURI(entry.getGrammarURI());
+ // Subclasses can override to load additional matcher fields
+ }
+
+ /**
+ * Load default values when creating a new entry. Subclasses can override to
+ * provide default pattern and expressions.
+ */
+ protected void loadDefaultValues() {
+ // Pattern is optional - user can leave it empty and use other matchers
+ // Subclasses can override to set default values
+ }
+
+ protected void saveMatcherToEntry(T entry) {
+ entry.setPattern(matcherWidget.getPattern());
+ entry.setNamespaceURI(matcherWidget.getNamespaceURI());
+ entry.setRootElement(matcherWidget.getRootElement());
+ entry.setPublicId(matcherWidget.getPublicId());
+ entry.setSystemId(matcherWidget.getSystemId());
+ entry.setGrammarURI(matcherWidget.getGrammarURI());
+ // Subclasses can override to save additional matcher fields
+ }
+
+ // Abstract methods to be implemented by subclasses
+
+ /**
+ * @return the title for adding a new entry
+ */
+ protected abstract String getAddTitle();
+
+ /**
+ * @return the title for editing an existing entry
+ */
+ protected abstract String getEditTitle();
+
+ /**
+ * @return the title for the matcher group
+ */
+ protected abstract String getMatcherGroupTitle();
+
+ /**
+ * @return the title for the expressions group
+ */
+ protected abstract String getExpressionsGroupTitle();
+
+ /**
+ * @return the error message when pattern is required
+ */
+ protected abstract String getPatternRequiredError();
+
+ /**
+ * @return the error message when expression is required
+ */
+ protected abstract String getExpressionRequiredError();
+
+ /**
+ * Create the table columns for displaying expressions.
+ *
+ * @param viewer the table viewer
+ * @param tableLayout the table layout
+ */
+ protected abstract void createExpressionColumns(TableViewer viewer, TableLayout tableLayout);
+
+ /**
+ * Create a dialog for adding or editing an expression.
+ *
+ * @param expression the expression to edit, or null for adding
+ * @return the dialog (can be any type, e.g., Dialog, InputDialog)
+ */
+ protected abstract Object createExpressionDialog(E expression);
+
+ /**
+ * Open the expression dialog and return the result code.
+ *
+ * @param dialog the dialog to open
+ * @return the result code (Window.OK or Window.CANCEL)
+ */
+ protected abstract int openDialog(Object dialog);
+
+ /**
+ * Get the result from the expression dialog.
+ *
+ * @param dialog the dialog
+ * @return the expression result
+ */
+ protected abstract E getDialogResult(Object dialog);
+
+ /**
+ * Get the list of expressions from an entry.
+ *
+ * @param entry the entry
+ * @return the list of expressions
+ */
+ protected abstract List getExpressionsFromEntry(T entry);
+
+ /**
+ * Set the list of expressions to an entry.
+ *
+ * @param entry the entry
+ * @param expressions the list of expressions
+ */
+ protected abstract void setExpressionsToEntry(T entry, List expressions);
+
+ /**
+ * Create a new entry instance.
+ *
+ * @return a new entry
+ */
+ protected abstract T createEntry();
+}
diff --git a/org.eclipse.wildwebdeveloper.xml/src/org/eclipse/wildwebdeveloper/xml/internal/ui/preferences/filerules/AbstractDocumentMatcherPreferencePage.java b/org.eclipse.wildwebdeveloper.xml/src/org/eclipse/wildwebdeveloper/xml/internal/ui/preferences/filerules/AbstractDocumentMatcherPreferencePage.java
new file mode 100644
index 0000000000..fad2b182d3
--- /dev/null
+++ b/org.eclipse.wildwebdeveloper.xml/src/org/eclipse/wildwebdeveloper/xml/internal/ui/preferences/filerules/AbstractDocumentMatcherPreferencePage.java
@@ -0,0 +1,288 @@
+/*******************************************************************************
+ * Copyright (c) 2026 Red Hat Inc. and others.
+ *
+ * This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License 2.0
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Angelo ZERR (Red Hat Inc.) - initial implementation
+ *******************************************************************************/
+package org.eclipse.wildwebdeveloper.xml.internal.ui.preferences.filerules;
+
+import static org.eclipse.swt.events.SelectionListener.widgetSelectedAdapter;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.preference.PreferencePage;
+import org.eclipse.jface.viewers.ArrayContentProvider;
+import org.eclipse.jface.viewers.ColumnLabelProvider;
+import org.eclipse.jface.viewers.ColumnWeightData;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.TableLayout;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.TableViewerColumn;
+import org.eclipse.jface.window.Window;
+import org.eclipse.swt.SWT;
+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.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPreferencePage;
+import org.eclipse.wildwebdeveloper.xml.internal.Activator;
+import org.eclipse.wildwebdeveloper.xml.internal.JsonUtils;
+import org.eclipse.wildwebdeveloper.xml.internal.ui.Messages;
+
+/**
+ * Abstract base class for preference pages that manage lists of
+ * DocumentMatcherEntry items.
+ *
+ * @param the type of DocumentMatcherEntry
+ */
+public abstract class AbstractDocumentMatcherPreferencePage extends PreferencePage
+ implements IWorkbenchPreferencePage {
+
+ private final List entries = new ArrayList<>();
+ private TableViewer viewer;
+ private Button editButton;
+ private Button removeButton;
+
+ @Override
+ public void init(IWorkbench workbench) {
+ setPreferenceStore(Activator.getDefault().getPreferenceStore());
+ }
+
+ @Override
+ protected Control createContents(Composite parent) {
+ Composite composite = new Composite(parent, SWT.NONE);
+ composite.setLayout(new GridLayout(1, false));
+ composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+
+ Label description = new Label(composite, SWT.WRAP);
+ description.setText(getDescription());
+ description.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
+
+ Group group = new Group(composite, SWT.NONE);
+ group.setText(getGroupTitle());
+ group.setLayout(new GridLayout(2, false));
+ group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+
+ viewer = new TableViewer(group, SWT.BORDER | SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL);
+ viewer.getTable().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ viewer.getTable().setHeaderVisible(true);
+ viewer.getTable().setLinesVisible(true);
+
+ TableLayout tableLayout = new TableLayout();
+ viewer.getTable().setLayout(tableLayout);
+
+ // Pattern column (common to all)
+ TableViewerColumn patternCol = new TableViewerColumn(viewer, SWT.NONE);
+ patternCol.getColumn().setText(Messages.XMLColorsPreferencePage_column_pattern);
+ tableLayout.addColumnData(new ColumnWeightData(30, 100, true));
+ patternCol.setLabelProvider(new ColumnLabelProvider() {
+ @Override
+ public String getText(Object element) {
+ @SuppressWarnings("unchecked")
+ T entry = (T) element;
+ return entry.getPattern() != null ? entry.getPattern() : "";
+ }
+ });
+
+ // Matchers column (common to all)
+ TableViewerColumn matchersCol = new TableViewerColumn(viewer, SWT.NONE);
+ matchersCol.getColumn().setText("Matchers");
+ tableLayout.addColumnData(new ColumnWeightData(40, 150, true));
+ matchersCol.setLabelProvider(new ColumnLabelProvider() {
+ @Override
+ public String getText(Object element) {
+ @SuppressWarnings("unchecked")
+ T entry = (T) element;
+ return formatMatchers(entry);
+ }
+ });
+
+ // Additional columns (specific to subclass)
+ createAdditionalColumns(viewer, tableLayout);
+
+ viewer.setContentProvider(ArrayContentProvider.getInstance());
+ viewer.setInput(entries);
+ viewer.addSelectionChangedListener(e -> updateButtons());
+ viewer.addDoubleClickListener(e -> editEntry());
+
+ // Buttons
+ Composite btnComposite = new Composite(group, SWT.NONE);
+ btnComposite.setLayout(new GridLayout(1, false));
+ btnComposite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false));
+
+ Button addButton = new Button(btnComposite, SWT.PUSH);
+ addButton.setText(Messages.Add_button);
+ addButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
+ addButton.addSelectionListener(widgetSelectedAdapter(e -> addEntry()));
+
+ editButton = new Button(btnComposite, SWT.PUSH);
+ editButton.setText(Messages.XMLColorsEntryDialog_edit_button);
+ editButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
+ editButton.setEnabled(false);
+ editButton.addSelectionListener(widgetSelectedAdapter(e -> editEntry()));
+
+ removeButton = new Button(btnComposite, SWT.PUSH);
+ removeButton.setText(Messages.Remove_button);
+ removeButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
+ removeButton.setEnabled(false);
+ removeButton.addSelectionListener(widgetSelectedAdapter(e -> removeEntry()));
+
+ loadFromStore();
+
+ return composite;
+ }
+
+ private void loadFromStore() {
+ entries.clear();
+ entries.addAll(JsonUtils.getList(getPreferenceStore(), getPreferenceKey(), getEntryClass()));
+ if (viewer != null) {
+ viewer.refresh();
+ }
+ }
+
+ private void addEntry() {
+ Dialog dialog = createEntryDialog(null);
+ if (dialog.open() == Window.OK) {
+ entries.add(getDialogResult(dialog));
+ viewer.refresh();
+ }
+ }
+
+ private void editEntry() {
+ int idx = viewer.getTable().getSelectionIndex();
+ if (idx < 0)
+ return;
+ T entry = entries.get(idx);
+ Dialog dialog = createEntryDialog(entry);
+ if (dialog.open() == Window.OK) {
+ entries.set(idx, getDialogResult(dialog));
+ viewer.refresh();
+ }
+ }
+
+ private void removeEntry() {
+ int idx = viewer.getTable().getSelectionIndex();
+ if (idx >= 0) {
+ entries.remove(idx);
+ viewer.refresh();
+ }
+ }
+
+ private void updateButtons() {
+ boolean hasSelection = !viewer.getStructuredSelection().isEmpty();
+ editButton.setEnabled(hasSelection);
+ removeButton.setEnabled(hasSelection);
+ }
+
+ @Override
+ public boolean performOk() {
+ JsonUtils.setValue(getPreferenceStore(), getPreferenceKey(), entries);
+ return super.performOk();
+ }
+
+ @Override
+ protected void performDefaults() {
+ entries.clear();
+ entries.addAll(getDefaultEntries());
+ viewer.refresh();
+ super.performDefaults();
+ }
+
+ protected abstract Collection extends T> getDefaultEntries();
+
+ // Abstract methods to be implemented by subclasses
+
+ /**
+ * @return the title for the entries group
+ */
+ protected abstract String getGroupTitle();
+
+ /**
+ * @return the preference key for storing entries
+ */
+ protected abstract String getPreferenceKey();
+
+ /**
+ * @return the class of the entry type
+ */
+ protected abstract Class getEntryClass();
+
+ /**
+ * Create additional table columns specific to the entry type.
+ *
+ * @param viewer the table viewer
+ * @param tableLayout the table layout
+ */
+ protected abstract void createAdditionalColumns(TableViewer viewer, TableLayout tableLayout);
+
+ /**
+ * Create a dialog for adding or editing an entry.
+ *
+ * @param entry the entry to edit, or null for adding a new entry
+ * @return the dialog
+ */
+ protected abstract Dialog createEntryDialog(T entry);
+
+ /**
+ * Get the result from the dialog after it has been closed with OK.
+ *
+ * @param dialog the dialog
+ * @return the entry result
+ */
+ protected abstract T getDialogResult(Dialog dialog);
+
+ /**
+ * @return the weight for the pattern column (default 50)
+ */
+ protected int getPatternColumnWeight() {
+ return 50;
+ }
+
+ /**
+ * @return the minimum width for the pattern column (default 120)
+ */
+ protected int getPatternColumnMinWidth() {
+ return 120;
+ }
+
+ /**
+ * Format the matchers (namespace, root, publicId, etc.) into a readable string.
+ *
+ * @param entry the entry
+ * @return formatted string showing all non-empty matchers
+ */
+ private String formatMatchers(T entry) {
+ List parts = new ArrayList<>();
+
+ if (entry.getNamespaceURI() != null && !entry.getNamespaceURI().isEmpty()) {
+ parts.add("ns:" + String.join(", ", entry.getNamespaceURI()));
+ }
+ if (entry.getRootElement() != null && !entry.getRootElement().isEmpty()) {
+ parts.add("root:" + String.join(", ", entry.getRootElement()));
+ }
+ if (entry.getPublicId() != null && !entry.getPublicId().isEmpty()) {
+ parts.add("public:" + String.join(", ", entry.getPublicId()));
+ }
+ if (entry.getSystemId() != null && !entry.getSystemId().isEmpty()) {
+ parts.add("system:" + String.join(", ", entry.getSystemId()));
+ }
+ if (entry.getGrammarURI() != null && !entry.getGrammarURI().isEmpty()) {
+ parts.add("grammar:" + String.join(", ", entry.getGrammarURI()));
+ }
+
+ return parts.isEmpty() ? "" : String.join(" | ", parts);
+ }
+}
diff --git a/org.eclipse.wildwebdeveloper.xml/src/org/eclipse/wildwebdeveloper/xml/internal/ui/preferences/filerules/DocumentMatcherEntry.java b/org.eclipse.wildwebdeveloper.xml/src/org/eclipse/wildwebdeveloper/xml/internal/ui/preferences/filerules/DocumentMatcherEntry.java
new file mode 100644
index 0000000000..31ddc59c3c
--- /dev/null
+++ b/org.eclipse.wildwebdeveloper.xml/src/org/eclipse/wildwebdeveloper/xml/internal/ui/preferences/filerules/DocumentMatcherEntry.java
@@ -0,0 +1,93 @@
+/*******************************************************************************
+ * Copyright (c) 2026 Red Hat Inc. and others.
+ * This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License 2.0
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Angelo ZERR (Red Hat Inc.) - initial implementation
+ *******************************************************************************/
+package org.eclipse.wildwebdeveloper.xml.internal.ui.preferences.filerules;
+
+import java.util.List;
+import java.util.Objects;
+
+public class DocumentMatcherEntry {
+
+ private String pattern;
+ private List namespaceURI;
+ private List rootElement;
+ private List publicId;
+ private List systemId;
+ private List grammarURI;
+
+ public DocumentMatcherEntry() {
+ }
+
+ public DocumentMatcherEntry(String pattern) {
+ this.pattern = pattern;
+ }
+
+ public String getPattern() {
+ return pattern;
+ }
+
+ public DocumentMatcherEntry setPattern(String pattern) {
+ this.pattern = pattern;
+ return this;
+ }
+
+ public List getNamespaceURI() {
+ return namespaceURI;
+ }
+
+ public DocumentMatcherEntry setNamespaceURI(List namespaceURI) {
+ this.namespaceURI = namespaceURI;
+ return this;
+ }
+
+ public List getRootElement() {
+ return rootElement;
+ }
+
+ public DocumentMatcherEntry setRootElement(List rootElement) {
+ this.rootElement = rootElement;
+ return this;
+ }
+
+ public List getPublicId() {
+ return publicId;
+ }
+
+ public DocumentMatcherEntry setPublicId(List publicId) {
+ this.publicId = publicId;
+ return this;
+ }
+
+ public List getSystemId() {
+ return systemId;
+ }
+
+ public DocumentMatcherEntry setSystemId(List systemId) {
+ this.systemId = systemId;
+ return this;
+ }
+
+ public List getGrammarURI() {
+ return grammarURI;
+ }
+
+ public DocumentMatcherEntry setGrammarURI(List grammarURI) {
+ this.grammarURI = grammarURI;
+ return this;
+ }
+
+ @Override
+ public String toString() {
+ return "DocumentMatcherEntry{" + "pattern='" + pattern + '\'' + ", namespaceURI='" + namespaceURI + '\''
+ + ", rootElement='" + rootElement + '\'' + ", publicId='" + publicId + '\'' + ", systemId='" + systemId
+ + '\'' + ", grammarURI='" + grammarURI + '\'' + '}';
+ }
+}
diff --git a/org.eclipse.wildwebdeveloper.xml/src/org/eclipse/wildwebdeveloper/xml/internal/ui/preferences/filerules/DocumentMatcherWidget.java b/org.eclipse.wildwebdeveloper.xml/src/org/eclipse/wildwebdeveloper/xml/internal/ui/preferences/filerules/DocumentMatcherWidget.java
new file mode 100644
index 0000000000..6b51f11995
--- /dev/null
+++ b/org.eclipse.wildwebdeveloper.xml/src/org/eclipse/wildwebdeveloper/xml/internal/ui/preferences/filerules/DocumentMatcherWidget.java
@@ -0,0 +1,293 @@
+/*******************************************************************************
+ * Copyright (c) 2026 Red Hat Inc. and others.
+ *
+ * This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License 2.0
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Angelo ZERR (Red Hat Inc.) - initial implementation
+ *******************************************************************************/
+package org.eclipse.wildwebdeveloper.xml.internal.ui.preferences.filerules;
+
+import static org.eclipse.swt.events.SelectionListener.widgetSelectedAdapter;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.stream.Collectors;
+
+import org.eclipse.jface.viewers.ArrayContentProvider;
+import org.eclipse.jface.viewers.CellEditor;
+import org.eclipse.jface.viewers.ColumnLabelProvider;
+import org.eclipse.jface.viewers.ColumnWeightData;
+import org.eclipse.jface.viewers.EditingSupport;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.TableLayout;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.TableViewerColumn;
+import org.eclipse.jface.viewers.TextCellEditor;
+import org.eclipse.jface.window.Window;
+import org.eclipse.swt.SWT;
+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.Label;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.wildwebdeveloper.xml.internal.ui.Messages;
+
+/**
+ * SWT composite that exposes the DocumentMatcher fields (pattern, namespaceURI,
+ * rootElement, publicId, systemId, grammarURI). Reused by both
+ * XMLColorsEntryDialog and XMLReferencesEntryDialog.
+ *
+ * Pattern is a single-line text field (String).
+ * Other fields are displayed in a single table with Type and Value columns.
+ * Value column is editable inline.
+ */
+public class DocumentMatcherWidget extends Composite {
+
+ private final Text patternText;
+ private final TableViewer matchersViewer;
+ private final List matchers = new ArrayList<>();
+
+ private Button removeButton;
+
+ public DocumentMatcherWidget(Composite parent, int style) {
+ super(parent, style);
+ setLayout(new GridLayout(1, false));
+
+ // Pattern field (single-line text)
+ Composite patternComposite = new Composite(this, SWT.NONE);
+ patternComposite.setLayout(new GridLayout(2, false));
+ patternComposite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
+
+ Label patternLabel = new Label(patternComposite, SWT.NONE);
+ patternLabel.setText(Messages.DocumentMatcherWidget_pattern);
+ patternLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
+
+ patternText = new Text(patternComposite, SWT.BORDER | SWT.SINGLE);
+ patternText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
+
+ // Matchers table
+ Label matchersLabel = new Label(this, SWT.NONE);
+ matchersLabel.setText("Document Matchers:");
+ matchersLabel.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false));
+
+ Composite tableComposite = new Composite(this, SWT.NONE);
+ tableComposite.setLayout(new GridLayout(2, false));
+ tableComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+
+ matchersViewer = new TableViewer(tableComposite,
+ SWT.BORDER | SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL);
+ GridData tableData = new GridData(SWT.FILL, SWT.FILL, true, true);
+ tableData.heightHint = 150;
+ matchersViewer.getTable().setLayoutData(tableData);
+ matchersViewer.getTable().setHeaderVisible(true);
+ matchersViewer.getTable().setLinesVisible(true);
+
+ TableLayout tableLayout = new TableLayout();
+ matchersViewer.getTable().setLayout(tableLayout);
+
+ // Type column
+ TableViewerColumn typeCol = new TableViewerColumn(matchersViewer, SWT.NONE);
+ typeCol.getColumn().setText("Type");
+ tableLayout.addColumnData(new ColumnWeightData(30, 100, true));
+ typeCol.setLabelProvider(new ColumnLabelProvider() {
+ @Override
+ public String getText(Object element) {
+ MatcherEntry entry = (MatcherEntry) element;
+ return entry.getType() != null ? entry.getType().getLabel() : "";
+ }
+ });
+
+ // Value column (editable)
+ TableViewerColumn valueCol = new TableViewerColumn(matchersViewer, SWT.NONE);
+ valueCol.getColumn().setText("Value");
+ tableLayout.addColumnData(new ColumnWeightData(70, 200, true));
+ valueCol.setLabelProvider(new ColumnLabelProvider() {
+ @Override
+ public String getText(Object element) {
+ MatcherEntry entry = (MatcherEntry) element;
+ return entry.getValue() != null ? entry.getValue() : "";
+ }
+ });
+ valueCol.setEditingSupport(new EditingSupport(matchersViewer) {
+ @Override
+ protected CellEditor getCellEditor(Object element) {
+ return new TextCellEditor(matchersViewer.getTable());
+ }
+
+ @Override
+ protected boolean canEdit(Object element) {
+ return true;
+ }
+
+ @Override
+ protected Object getValue(Object element) {
+ MatcherEntry entry = (MatcherEntry) element;
+ return entry.getValue() != null ? entry.getValue() : "";
+ }
+
+ @Override
+ protected void setValue(Object element, Object value) {
+ MatcherEntry entry = (MatcherEntry) element;
+ entry.setValue(value != null ? value.toString() : "");
+ matchersViewer.refresh(entry);
+ }
+ });
+
+ matchersViewer.setContentProvider(ArrayContentProvider.getInstance());
+ matchersViewer.setInput(matchers);
+ matchersViewer.addSelectionChangedListener(e -> updateButtons());
+
+ // Buttons
+ Composite buttonComposite = new Composite(tableComposite, SWT.NONE);
+ buttonComposite.setLayout(new GridLayout(1, false));
+ buttonComposite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false));
+
+ Button addButton = new Button(buttonComposite, SWT.PUSH);
+ addButton.setText(Messages.Add_button);
+ addButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
+ addButton.addSelectionListener(widgetSelectedAdapter(e -> addMatcher()));
+
+ removeButton = new Button(buttonComposite, SWT.PUSH);
+ removeButton.setText(Messages.Remove_button);
+ removeButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
+ removeButton.setEnabled(false);
+ removeButton.addSelectionListener(widgetSelectedAdapter(e -> removeMatcher()));
+ }
+
+ private void addMatcher() {
+ MatcherEntryDialog dialog = new MatcherEntryDialog(getShell(), null);
+ if (dialog.open() == Window.OK) {
+ MatcherEntry entry = dialog.getResult();
+ if (entry != null) {
+ matchers.add(entry);
+ matchersViewer.refresh();
+ notifyMatchersChanged();
+ }
+ }
+ }
+
+ private void removeMatcher() {
+ IStructuredSelection sel = matchersViewer.getStructuredSelection();
+ if (!sel.isEmpty()) {
+ matchers.remove(sel.getFirstElement());
+ matchersViewer.refresh();
+ notifyMatchersChanged();
+ }
+ }
+
+ private void updateButtons() {
+ boolean hasSelection = !matchersViewer.getStructuredSelection().isEmpty();
+ removeButton.setEnabled(hasSelection);
+ }
+
+ private Runnable matchersChangedListener;
+
+ public void setMatchersChangedListener(Runnable listener) {
+ this.matchersChangedListener = listener;
+ }
+
+ private void notifyMatchersChanged() {
+ if (matchersChangedListener != null) {
+ matchersChangedListener.run();
+ }
+ }
+
+ public Text getPatternText() {
+ return patternText;
+ }
+
+ public String getPattern() {
+ return patternText.getText().trim();
+ }
+
+ public void setPattern(String v) {
+ patternText.setText(v != null ? v : "");
+ }
+
+ public List getNamespaceURI() {
+ return matchers.stream()
+ .filter(e -> e.getType() == MatcherType.NAMESPACE_URI)
+ .map(MatcherEntry::getValue)
+ .collect(Collectors.toList());
+ }
+
+ public void setNamespaceURI(List values) {
+ if (values != null) {
+ for (String value : values) {
+ matchers.add(new MatcherEntry(MatcherType.NAMESPACE_URI, value));
+ }
+ }
+ matchersViewer.refresh();
+ }
+
+ public List getRootElement() {
+ return matchers.stream()
+ .filter(e -> e.getType() == MatcherType.ROOT_ELEMENT)
+ .map(MatcherEntry::getValue)
+ .collect(Collectors.toList());
+ }
+
+ public void setRootElement(List values) {
+ if (values != null) {
+ for (String value : values) {
+ matchers.add(new MatcherEntry(MatcherType.ROOT_ELEMENT, value));
+ }
+ }
+ matchersViewer.refresh();
+ }
+
+ public List getPublicId() {
+ return matchers.stream()
+ .filter(e -> e.getType() == MatcherType.PUBLIC_ID)
+ .map(MatcherEntry::getValue)
+ .collect(Collectors.toList());
+ }
+
+ public void setPublicId(List values) {
+ if (values != null) {
+ for (String value : values) {
+ matchers.add(new MatcherEntry(MatcherType.PUBLIC_ID, value));
+ }
+ }
+ matchersViewer.refresh();
+ }
+
+ public List getSystemId() {
+ return matchers.stream()
+ .filter(e -> e.getType() == MatcherType.SYSTEM_ID)
+ .map(MatcherEntry::getValue)
+ .collect(Collectors.toList());
+ }
+
+ public void setSystemId(List values) {
+ if (values != null) {
+ for (String value : values) {
+ matchers.add(new MatcherEntry(MatcherType.SYSTEM_ID, value));
+ }
+ }
+ matchersViewer.refresh();
+ }
+
+ public List getGrammarURI() {
+ return matchers.stream()
+ .filter(e -> e.getType() == MatcherType.GRAMMAR_URI)
+ .map(MatcherEntry::getValue)
+ .collect(Collectors.toList());
+ }
+
+ public void setGrammarURI(List values) {
+ if (values != null) {
+ for (String value : values) {
+ matchers.add(new MatcherEntry(MatcherType.GRAMMAR_URI, value));
+ }
+ }
+ matchersViewer.refresh();
+ }
+
+}
diff --git a/org.eclipse.wildwebdeveloper.xml/src/org/eclipse/wildwebdeveloper/xml/internal/ui/preferences/filerules/MatcherEntry.java b/org.eclipse.wildwebdeveloper.xml/src/org/eclipse/wildwebdeveloper/xml/internal/ui/preferences/filerules/MatcherEntry.java
new file mode 100644
index 0000000000..0447384143
--- /dev/null
+++ b/org.eclipse.wildwebdeveloper.xml/src/org/eclipse/wildwebdeveloper/xml/internal/ui/preferences/filerules/MatcherEntry.java
@@ -0,0 +1,65 @@
+/*******************************************************************************
+ * Copyright (c) 2026 Red Hat Inc. and others.
+ *
+ * This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License 2.0
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Angelo ZERR (Red Hat Inc.) - initial implementation
+ *******************************************************************************/
+package org.eclipse.wildwebdeveloper.xml.internal.ui.preferences.filerules;
+
+import java.util.Objects;
+
+/**
+ * Represents a single matcher entry with a type and value.
+ */
+public class MatcherEntry {
+ private MatcherType type;
+ private String value;
+
+ public MatcherEntry() {
+ }
+
+ public MatcherEntry(MatcherType type, String value) {
+ this.type = type;
+ this.value = value;
+ }
+
+ public MatcherType getType() {
+ return type;
+ }
+
+ public void setType(MatcherType type) {
+ this.type = type;
+ }
+
+ public String getValue() {
+ return value;
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (!(o instanceof MatcherEntry)) return false;
+ MatcherEntry that = (MatcherEntry) o;
+ return type == that.type && Objects.equals(value, that.value);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(type, value);
+ }
+
+ @Override
+ public String toString() {
+ return "MatcherEntry{type=" + type + ", value='" + value + "'}";
+ }
+}
diff --git a/org.eclipse.wildwebdeveloper.xml/src/org/eclipse/wildwebdeveloper/xml/internal/ui/preferences/filerules/MatcherEntryDialog.java b/org.eclipse.wildwebdeveloper.xml/src/org/eclipse/wildwebdeveloper/xml/internal/ui/preferences/filerules/MatcherEntryDialog.java
new file mode 100644
index 0000000000..875c31e8aa
--- /dev/null
+++ b/org.eclipse.wildwebdeveloper.xml/src/org/eclipse/wildwebdeveloper/xml/internal/ui/preferences/filerules/MatcherEntryDialog.java
@@ -0,0 +1,130 @@
+/*******************************************************************************
+ * Copyright (c) 2026 Red Hat Inc. and others.
+ *
+ * This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License 2.0
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Angelo ZERR (Red Hat Inc.) - initial implementation
+ *******************************************************************************/
+package org.eclipse.wildwebdeveloper.xml.internal.ui.preferences.filerules;
+
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.TitleAreaDialog;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+
+/**
+ * Dialog for adding or editing a matcher entry (type + value).
+ */
+public class MatcherEntryDialog extends TitleAreaDialog {
+
+ private final MatcherEntry initialEntry;
+ private MatcherEntry result;
+
+ private Combo typeCombo;
+ private Text valueText;
+
+ public MatcherEntryDialog(Shell parentShell, MatcherEntry entry) {
+ super(parentShell);
+ this.initialEntry = entry;
+ setShellStyle(getShellStyle() | SWT.RESIZE);
+ }
+
+ @Override
+ public void create() {
+ super.create();
+ String title = initialEntry == null ? "Add Matcher" : "Edit Matcher";
+ setTitle(title);
+ setMessage("Specify the matcher type and value (glob pattern)");
+ getShell().setText(title);
+
+ // Set focus to value field for new entries
+ if (initialEntry == null && valueText != null) {
+ valueText.setFocus();
+ }
+
+ validate();
+ }
+
+ @Override
+ protected Control createDialogArea(Composite parent) {
+ Composite area = (Composite) super.createDialogArea(parent);
+ Composite container = new Composite(area, SWT.NONE);
+ container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ container.setLayout(new GridLayout(2, false));
+
+ // Type combo
+ Label typeLabel = new Label(container, SWT.NONE);
+ typeLabel.setText("Type:");
+ typeLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
+
+ typeCombo = new Combo(container, SWT.READ_ONLY | SWT.BORDER);
+ typeCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
+ for (MatcherType type : MatcherType.values()) {
+ typeCombo.add(type.getLabel());
+ }
+ typeCombo.addModifyListener(e -> validate());
+
+ // Value text
+ Label valueLabel = new Label(container, SWT.NONE);
+ valueLabel.setText("Value:");
+ valueLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
+
+ valueText = new Text(container, SWT.BORDER | SWT.SINGLE);
+ valueText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
+ valueText.addModifyListener(e -> validate());
+
+ // Load initial values
+ if (initialEntry != null) {
+ if (initialEntry.getType() != null) {
+ typeCombo.select(initialEntry.getType().ordinal());
+ }
+ if (initialEntry.getValue() != null) {
+ valueText.setText(initialEntry.getValue());
+ }
+ } else {
+ // For new entries, select first type by default
+ if (typeCombo.getItemCount() > 0) {
+ typeCombo.select(0);
+ }
+ }
+
+ return area;
+ }
+
+ private void validate() {
+ String error = null;
+ if (typeCombo != null && typeCombo.getSelectionIndex() == -1) {
+ error = "Type is required";
+ } else if (valueText != null && valueText.getText().trim().isEmpty()) {
+ error = "Value is required";
+ }
+ setErrorMessage(error);
+ if (getButton(IDialogConstants.OK_ID) != null) {
+ getButton(IDialogConstants.OK_ID).setEnabled(error == null);
+ }
+ }
+
+ @Override
+ protected void okPressed() {
+ result = new MatcherEntry();
+ result.setType(MatcherType.values()[typeCombo.getSelectionIndex()]);
+ result.setValue(valueText.getText().trim());
+ super.okPressed();
+ }
+
+ public MatcherEntry getResult() {
+ return result;
+ }
+}
diff --git a/org.eclipse.wildwebdeveloper.xml/src/org/eclipse/wildwebdeveloper/xml/internal/ui/preferences/filerules/MatcherType.java b/org.eclipse.wildwebdeveloper.xml/src/org/eclipse/wildwebdeveloper/xml/internal/ui/preferences/filerules/MatcherType.java
new file mode 100644
index 0000000000..55a9e6abe6
--- /dev/null
+++ b/org.eclipse.wildwebdeveloper.xml/src/org/eclipse/wildwebdeveloper/xml/internal/ui/preferences/filerules/MatcherType.java
@@ -0,0 +1,39 @@
+/*******************************************************************************
+ * Copyright (c) 2026 Red Hat Inc. and others.
+ *
+ * This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License 2.0
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Angelo ZERR (Red Hat Inc.) - initial implementation
+ *******************************************************************************/
+package org.eclipse.wildwebdeveloper.xml.internal.ui.preferences.filerules;
+
+/**
+ * Types of document matchers (excluding pattern which is handled separately).
+ */
+public enum MatcherType {
+ NAMESPACE_URI("Namespace URI"),
+ ROOT_ELEMENT("Root Element"),
+ PUBLIC_ID("Public ID"),
+ SYSTEM_ID("System ID"),
+ GRAMMAR_URI("Grammar URI");
+
+ private final String label;
+
+ MatcherType(String label) {
+ this.label = label;
+ }
+
+ public String getLabel() {
+ return label;
+ }
+
+ @Override
+ public String toString() {
+ return label;
+ }
+}
diff --git a/org.eclipse.wildwebdeveloper.xml/src/org/eclipse/wildwebdeveloper/xml/internal/ui/preferences/filerules/XMLFileRulesPreferencePage.java b/org.eclipse.wildwebdeveloper.xml/src/org/eclipse/wildwebdeveloper/xml/internal/ui/preferences/filerules/XMLFileRulesPreferencePage.java
new file mode 100644
index 0000000000..9f983e9f20
--- /dev/null
+++ b/org.eclipse.wildwebdeveloper.xml/src/org/eclipse/wildwebdeveloper/xml/internal/ui/preferences/filerules/XMLFileRulesPreferencePage.java
@@ -0,0 +1,76 @@
+/*******************************************************************************
+ * Copyright (c) 2026 Red Hat Inc. and others.
+ *
+ * This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License 2.0
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Angelo ZERR (Red Hat Inc.) - initial implementation
+ *******************************************************************************/
+package org.eclipse.wildwebdeveloper.xml.internal.ui.preferences.filerules;
+
+import org.eclipse.jface.preference.PreferencePage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Link;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPreferencePage;
+import org.eclipse.ui.dialogs.PreferencesUtil;
+
+/**
+ * Parent preference page for file-specific rules (Colors, References, etc.).
+ * This page serves as a container for sub-pages that configure rules based on file patterns.
+ */
+public class XMLFileRulesPreferencePage extends PreferencePage implements IWorkbenchPreferencePage {
+
+ public XMLFileRulesPreferencePage() {
+ super();
+ noDefaultAndApplyButton();
+ }
+
+ @Override
+ public void init(IWorkbench workbench) {
+ // Nothing to initialize
+ }
+
+ @Override
+ protected Control createContents(Composite parent) {
+ Composite composite = new Composite(parent, SWT.NONE);
+ composite.setLayout(new GridLayout(1, false));
+ composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+
+ Label description = new Label(composite, SWT.WRAP);
+ description.setText("Configure file-specific rules for XML documents.\n\n" +
+ "Define patterns that match specific XML files and configure behaviors:");
+ description.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
+
+ // Colors link
+ Link colorsLink = new Link(composite, SWT.NONE);
+ colorsLink.setText("• Colors - Extract color values from XML files for color picker support");
+ colorsLink.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
+ colorsLink.addSelectionListener(org.eclipse.swt.events.SelectionListener.widgetSelectedAdapter(e -> {
+ PreferencesUtil.createPreferenceDialogOn(getShell(),
+ org.eclipse.wildwebdeveloper.xml.internal.ui.preferences.filerules.colors.XMLColorsPreferencePage.PAGE_ID,
+ null, null).open();
+ }));
+
+ // References link
+ Link referencesLink = new Link(composite, SWT.NONE);
+ referencesLink.setText("• References - Define reference relationships for navigation and rename refactoring");
+ referencesLink.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
+ referencesLink.addSelectionListener(org.eclipse.swt.events.SelectionListener.widgetSelectedAdapter(e -> {
+ PreferencesUtil.createPreferenceDialogOn(getShell(),
+ org.eclipse.wildwebdeveloper.xml.internal.ui.preferences.filerules.references.XMLReferencesPreferencePage.PAGE_ID,
+ null, null).open();
+ }));
+
+ return composite;
+ }
+}
diff --git a/org.eclipse.wildwebdeveloper.xml/src/org/eclipse/wildwebdeveloper/xml/internal/ui/preferences/filerules/colors/XMLColorsEntry.java b/org.eclipse.wildwebdeveloper.xml/src/org/eclipse/wildwebdeveloper/xml/internal/ui/preferences/filerules/colors/XMLColorsEntry.java
new file mode 100644
index 0000000000..8a62c2df8e
--- /dev/null
+++ b/org.eclipse.wildwebdeveloper.xml/src/org/eclipse/wildwebdeveloper/xml/internal/ui/preferences/filerules/colors/XMLColorsEntry.java
@@ -0,0 +1,68 @@
+/*******************************************************************************
+ * Copyright (c) 2026 Red Hat Inc. and others.
+ * This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License 2.0
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Angelo ZERR (Red Hat Inc.) - initial implementation
+ *******************************************************************************/
+package org.eclipse.wildwebdeveloper.xml.internal.ui.preferences.filerules.colors;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.wildwebdeveloper.xml.internal.ui.preferences.filerules.DocumentMatcherEntry;
+
+/**
+ * POJO representing a single xml.colors entry with document matcher and XPath
+ * expressions.
+ */
+public class XMLColorsEntry extends DocumentMatcherEntry {
+
+ private List expressions;
+
+ public XMLColorsEntry() {
+ this.expressions = new ArrayList<>();
+ }
+
+ @Override
+ public XMLColorsEntry setPattern(String pattern) {
+ return (XMLColorsEntry) super.setPattern(pattern);
+ }
+
+ public XMLColorsEntry addExpression(String xpath) {
+ expressions.add(new XMLColorsExpression(xpath));
+ return this;
+ }
+
+ public List getExpressions() {
+ return expressions;
+ }
+
+ public void setExpressions(List expressions) {
+ this.expressions = expressions;
+ }
+
+ public static class XMLColorsExpression {
+ private String xpath;
+
+ public XMLColorsExpression() {
+ }
+
+ public XMLColorsExpression(String xpath) {
+ this.xpath = xpath;
+ }
+
+ public String getXpath() {
+ return xpath;
+ }
+
+ public void setXpath(String xpath) {
+ this.xpath = xpath;
+ }
+ }
+
+}
diff --git a/org.eclipse.wildwebdeveloper.xml/src/org/eclipse/wildwebdeveloper/xml/internal/ui/preferences/filerules/colors/XMLColorsEntryDialog.java b/org.eclipse.wildwebdeveloper.xml/src/org/eclipse/wildwebdeveloper/xml/internal/ui/preferences/filerules/colors/XMLColorsEntryDialog.java
new file mode 100644
index 0000000000..48153d9c20
--- /dev/null
+++ b/org.eclipse.wildwebdeveloper.xml/src/org/eclipse/wildwebdeveloper/xml/internal/ui/preferences/filerules/colors/XMLColorsEntryDialog.java
@@ -0,0 +1,127 @@
+/*******************************************************************************
+ * Copyright (c) 2026 Red Hat Inc. and others.
+ *
+ * This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License 2.0
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Angelo ZERR (Red Hat Inc.) - initial implementation
+ *******************************************************************************/
+package org.eclipse.wildwebdeveloper.xml.internal.ui.preferences.filerules.colors;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+import org.eclipse.jface.dialogs.IInputValidator;
+import org.eclipse.jface.dialogs.InputDialog;
+import org.eclipse.jface.viewers.ColumnLabelProvider;
+import org.eclipse.jface.viewers.ColumnWeightData;
+import org.eclipse.jface.viewers.TableLayout;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.TableViewerColumn;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.wildwebdeveloper.xml.internal.ui.Messages;
+import org.eclipse.wildwebdeveloper.xml.internal.ui.preferences.filerules.AbstractDocumentMatcherEntryDialog;
+import org.eclipse.wildwebdeveloper.xml.internal.ui.preferences.filerules.colors.XMLColorsEntry.XMLColorsExpression;
+
+/**
+ * Dialog to add or edit a single xml.colors entry (DocumentMatcher + XPath
+ * expressions).
+ */
+public class XMLColorsEntryDialog extends AbstractDocumentMatcherEntryDialog {
+
+ public XMLColorsEntryDialog(Shell parentShell, XMLColorsEntry entry) {
+ super(parentShell, entry);
+ }
+
+ @Override
+ protected String getAddTitle() {
+ return Messages.XMLColorsEntryDialog_title_add;
+ }
+
+ @Override
+ protected String getEditTitle() {
+ return Messages.XMLColorsEntryDialog_title_edit;
+ }
+
+ @Override
+ protected String getMatcherGroupTitle() {
+ return Messages.XMLColorsEntryDialog_matcher_group;
+ }
+
+ @Override
+ protected String getExpressionsGroupTitle() {
+ return Messages.XMLColorsEntryDialog_expressions_group;
+ }
+
+ @Override
+ protected String getPatternRequiredError() {
+ return Messages.XMLColorsEntryDialog_error_pattern_required;
+ }
+
+ @Override
+ protected String getExpressionRequiredError() {
+ return Messages.XMLColorsEntryDialog_error_expression_required;
+ }
+
+ @Override
+ protected void createExpressionColumns(TableViewer viewer, TableLayout tableLayout) {
+ TableViewerColumn xpathCol = new TableViewerColumn(viewer, SWT.NONE);
+ xpathCol.getColumn().setText(Messages.XMLColorsEntryDialog_column_xpath);
+ tableLayout.addColumnData(new ColumnWeightData(100, 200, true));
+ xpathCol.setLabelProvider(new ColumnLabelProvider());
+ }
+
+ @Override
+ protected Object createExpressionDialog(String expression) {
+ return new InputDialog(getShell(), //
+ Messages.XMLColorsEntryDialog_input_xpath_title, //
+ Messages.XMLColorsEntryDialog_input_xpath_message, //
+ expression != null ? expression : "", xpathValidator());
+ }
+
+ @Override
+ protected int openDialog(Object dialog) {
+ return ((InputDialog) dialog).open();
+ }
+
+ @Override
+ protected String getDialogResult(Object dialog) {
+ return ((InputDialog) dialog).getValue().trim();
+ }
+
+ @Override
+ protected List getExpressionsFromEntry(XMLColorsEntry entry) {
+ if (entry.getExpressions() == null) {
+ return null;
+ }
+ return entry.getExpressions().stream().map(XMLColorsExpression::getXpath).collect(Collectors.toList());
+ }
+
+ @Override
+ protected void setExpressionsToEntry(XMLColorsEntry entry, List expressions) {
+ List expList = expressions.stream().map(XMLColorsExpression::new)
+ .collect(Collectors.toList());
+ entry.setExpressions(expList);
+ }
+
+ @Override
+ protected XMLColorsEntry createEntry() {
+ return new XMLColorsEntry();
+ }
+
+ @Override
+ protected void loadDefaultValues() {
+ super.loadDefaultValues();
+ }
+
+ private IInputValidator xpathValidator() {
+ return value -> (value == null || value.trim().isEmpty())
+ ? Messages.XMLColorsEntryDialog_error_expression_required
+ : null;
+ }
+}
\ No newline at end of file
diff --git a/org.eclipse.wildwebdeveloper.xml/src/org/eclipse/wildwebdeveloper/xml/internal/ui/preferences/filerules/colors/XMLColorsPreferencePage.java b/org.eclipse.wildwebdeveloper.xml/src/org/eclipse/wildwebdeveloper/xml/internal/ui/preferences/filerules/colors/XMLColorsPreferencePage.java
new file mode 100644
index 0000000000..965c4f50da
--- /dev/null
+++ b/org.eclipse.wildwebdeveloper.xml/src/org/eclipse/wildwebdeveloper/xml/internal/ui/preferences/filerules/colors/XMLColorsPreferencePage.java
@@ -0,0 +1,103 @@
+/*******************************************************************************
+ * Copyright (c) 2026 Red Hat Inc. and others.
+ *
+ * This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License 2.0
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Angelo ZERR (Red Hat Inc.) - initial implementation
+ *******************************************************************************/
+package org.eclipse.wildwebdeveloper.xml.internal.ui.preferences.filerules.colors;
+
+import static org.eclipse.wildwebdeveloper.xml.internal.ui.preferences.XMLPreferenceServerConstants.XML_PREFERENCES_COLORS;
+
+import java.util.Collection;
+import java.util.List;
+
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.viewers.ColumnLabelProvider;
+import org.eclipse.jface.viewers.ColumnWeightData;
+import org.eclipse.jface.viewers.TableLayout;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.TableViewerColumn;
+import org.eclipse.wildwebdeveloper.xml.internal.ui.Messages;
+import org.eclipse.wildwebdeveloper.xml.internal.ui.preferences.XMLPreferenceInitializer;
+import org.eclipse.wildwebdeveloper.xml.internal.ui.preferences.filerules.AbstractDocumentMatcherPreferencePage;
+import org.eclipse.wildwebdeveloper.xml.internal.ui.preferences.filerules.colors.XMLColorsEntry.XMLColorsExpression;
+
+/**
+ * Preference page for xml.colors — specifies which XML elements contain color
+ * values via XPath.
+ */
+public class XMLColorsPreferencePage extends AbstractDocumentMatcherPreferencePage {
+
+ public static final String PAGE_ID = "org.eclipse.wildwebdeveloper.xml.internal.ui.preferences.filerules.colors.XMLColorsPreferencePage";
+
+ @Override
+ public String getDescription() {
+ return Messages.XMLColorsPreferencePage_description;
+ }
+
+ @Override
+ protected String getGroupTitle() {
+ return Messages.XMLColorsPreferencePage_entries;
+ }
+
+ @Override
+ protected String getPreferenceKey() {
+ return XML_PREFERENCES_COLORS.preferenceId;
+ }
+
+ @Override
+ protected Class getEntryClass() {
+ return XMLColorsEntry.class;
+ }
+
+ @Override
+ protected int getPatternColumnWeight() {
+ return 60;
+ }
+
+ @Override
+ protected int getPatternColumnMinWidth() {
+ return 150;
+ }
+
+ @Override
+ protected Collection extends XMLColorsEntry> getDefaultEntries() {
+ return XMLPreferenceInitializer.DEFAULT_COLORS;
+ }
+
+ @Override
+ protected void createAdditionalColumns(TableViewer viewer, TableLayout tableLayout) {
+ TableViewerColumn expressionsCol = new TableViewerColumn(viewer, org.eclipse.swt.SWT.NONE);
+ expressionsCol.getColumn().setText(Messages.XMLColorsPreferencePage_column_expressions);
+ tableLayout.addColumnData(new ColumnWeightData(40, 100, true));
+ expressionsCol.setLabelProvider(new ColumnLabelProvider() {
+ @Override
+ public String getText(Object element) {
+ XMLColorsEntry entry = (XMLColorsEntry) element;
+ List exprs = entry.getExpressions();
+ if (exprs == null || exprs.isEmpty())
+ return "0";
+ if (exprs.size() == 1) {
+ return exprs.get(0).getXpath();
+ }
+ return String.valueOf(exprs.size());
+ }
+ });
+ }
+
+ @Override
+ protected Dialog createEntryDialog(XMLColorsEntry entry) {
+ return new XMLColorsEntryDialog(getShell(), entry);
+ }
+
+ @Override
+ protected XMLColorsEntry getDialogResult(Dialog dialog) {
+ return ((XMLColorsEntryDialog) dialog).getResult();
+ }
+}
\ No newline at end of file
diff --git a/org.eclipse.wildwebdeveloper.xml/src/org/eclipse/wildwebdeveloper/xml/internal/ui/preferences/filerules/references/XMLReferenceExpressionDialog.java b/org.eclipse.wildwebdeveloper.xml/src/org/eclipse/wildwebdeveloper/xml/internal/ui/preferences/filerules/references/XMLReferenceExpressionDialog.java
new file mode 100644
index 0000000000..427882f37a
--- /dev/null
+++ b/org.eclipse.wildwebdeveloper.xml/src/org/eclipse/wildwebdeveloper/xml/internal/ui/preferences/filerules/references/XMLReferenceExpressionDialog.java
@@ -0,0 +1,136 @@
+/*******************************************************************************
+ * Copyright (c) 2026 Red Hat Inc. and others.
+ *
+ * This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License 2.0
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Angelo ZERR (Red Hat Inc.) - initial implementation
+ *******************************************************************************/
+package org.eclipse.wildwebdeveloper.xml.internal.ui.preferences.filerules.references;
+
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.TitleAreaDialog;
+import org.eclipse.swt.SWT;
+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.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.wildwebdeveloper.xml.internal.ui.Messages;
+import org.eclipse.wildwebdeveloper.xml.internal.ui.preferences.filerules.references.XMLReferencesEntry.XMLReferenceExpression;
+
+/**
+ * Dialog to add or edit a single xml.references expression ({from, to, prefix,
+ * multiple}).
+ */
+public class XMLReferenceExpressionDialog extends TitleAreaDialog {
+
+ private final XMLReferenceExpression initialExpression;
+ private XMLReferenceExpression result;
+
+ private Text fromText;
+ private Text toText;
+ private Text prefixText;
+ private Button multipleCheck;
+
+ public XMLReferenceExpressionDialog(Shell parentShell, XMLReferenceExpression expression) {
+ super(parentShell);
+ this.initialExpression = expression;
+ setShellStyle(getShellStyle() | SWT.RESIZE);
+ }
+
+ @Override
+ public void create() {
+ super.create();
+ String title = initialExpression == null //
+ ? Messages.XMLReferencesEntryDialog_edit_expression_title_add //
+ : Messages.XMLReferencesEntryDialog_edit_expression_title;
+ setTitle(title);
+ getShell().setText(title);
+ validate();
+ }
+
+ @Override
+ protected Control createDialogArea(Composite parent) {
+ Composite area = (Composite) super.createDialogArea(parent);
+ Composite container = new Composite(area, SWT.NONE);
+ container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ container.setLayout(new GridLayout(2, false));
+
+ createLabel(container, Messages.XMLReferencesEntryDialog_edit_expression_from);
+ fromText = createText(container);
+ fromText.addModifyListener(e -> validate());
+
+ createLabel(container, Messages.XMLReferencesEntryDialog_edit_expression_to);
+ toText = createText(container);
+ toText.addModifyListener(e -> validate());
+
+ createLabel(container, Messages.XMLReferencesEntryDialog_edit_expression_prefix);
+ prefixText = createText(container);
+
+ new Label(container, SWT.NONE); // spacer
+ multipleCheck = new Button(container, SWT.CHECK);
+ multipleCheck.setText(Messages.XMLReferencesEntryDialog_edit_expression_multiple);
+
+ if (initialExpression != null) {
+ fromText.setText(initialExpression.getFrom() != null ? initialExpression.getFrom() : "");
+ toText.setText(initialExpression.getTo() != null ? initialExpression.getTo() : "");
+ prefixText.setText(initialExpression.getPrefix() != null ? initialExpression.getPrefix() : "");
+ multipleCheck.setSelection(initialExpression.getMultiple() != null && initialExpression.getMultiple());
+ }
+
+ return area;
+ }
+
+ private static Label createLabel(Composite parent, String text) {
+ Label label = new Label(parent, SWT.NONE);
+ label.setText(text);
+ label.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
+ return label;
+ }
+
+ private static Text createText(Composite parent) {
+ Text text = new Text(parent, SWT.BORDER | SWT.SINGLE);
+ text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
+ return text;
+ }
+
+ private void validate() {
+ String error = null;
+ if (fromText.getText().trim().isEmpty()) {
+ error = Messages.XMLReferencesEntryDialog_error_from_required;
+ } else if (toText.getText().trim().isEmpty()) {
+ error = Messages.XMLReferencesEntryDialog_error_to_required;
+ }
+ setErrorMessage(error);
+ Button ok = getButton(IDialogConstants.OK_ID);
+ if (ok != null)
+ ok.setEnabled(error == null);
+ }
+
+ @Override
+ protected void okPressed() {
+ result = new XMLReferenceExpression();
+ result.setFrom(fromText.getText().trim());
+ result.setTo(toText.getText().trim());
+ String prefix = prefixText.getText().trim();
+ if (!prefix.isEmpty()) {
+ result.setPrefix(prefix);
+ }
+ if (multipleCheck.getSelection()) {
+ result.setMultiple(true);
+ }
+ super.okPressed();
+ }
+
+ public XMLReferenceExpression getResult() {
+ return result;
+ }
+}
diff --git a/org.eclipse.wildwebdeveloper.xml/src/org/eclipse/wildwebdeveloper/xml/internal/ui/preferences/filerules/references/XMLReferencesEntry.java b/org.eclipse.wildwebdeveloper.xml/src/org/eclipse/wildwebdeveloper/xml/internal/ui/preferences/filerules/references/XMLReferencesEntry.java
new file mode 100644
index 0000000000..1940ba1ee2
--- /dev/null
+++ b/org.eclipse.wildwebdeveloper.xml/src/org/eclipse/wildwebdeveloper/xml/internal/ui/preferences/filerules/references/XMLReferencesEntry.java
@@ -0,0 +1,131 @@
+/*******************************************************************************
+ * Copyright (c) 2026 Red Hat Inc. and others.
+ * This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License 2.0
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Angelo ZERR (Red Hat Inc.) - initial implementation
+ *******************************************************************************/
+package org.eclipse.wildwebdeveloper.xml.internal.ui.preferences.filerules.references;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.wildwebdeveloper.xml.internal.ui.preferences.filerules.DocumentMatcherEntry;
+
+/**
+ * POJO representing a single xml.references entry with document matcher and
+ * reference expressions.
+ */
+public class XMLReferencesEntry extends DocumentMatcherEntry {
+
+ private String prefix;
+ private List expressions;
+
+ public XMLReferencesEntry() {
+ this.expressions = new ArrayList<>();
+ }
+
+ @Override
+ public XMLReferencesEntry setPattern(String pattern) {
+ return (XMLReferencesEntry) super.setPattern(pattern);
+ }
+
+ @Override
+ public XMLReferencesEntry setNamespaceURI(List namespaceURI) {
+ return (XMLReferencesEntry) super.setNamespaceURI(namespaceURI);
+ }
+
+ @Override
+ public XMLReferencesEntry setRootElement(List rootElement) {
+ return (XMLReferencesEntry) super.setRootElement(rootElement);
+ }
+
+ @Override
+ public XMLReferencesEntry setPublicId(List publicId) {
+ return (XMLReferencesEntry) super.setPublicId(publicId);
+ }
+
+ @Override
+ public XMLReferencesEntry setSystemId(List systemId) {
+ return (XMLReferencesEntry) super.setSystemId(systemId);
+ }
+
+ @Override
+ public XMLReferencesEntry setGrammarURI(List grammarURI) {
+ return (XMLReferencesEntry) super.setGrammarURI(grammarURI);
+ }
+
+ public String getPrefix() {
+ return prefix;
+ }
+
+ public XMLReferencesEntry setPrefix(String prefix) {
+ this.prefix = prefix;
+ return this;
+ }
+
+ public List getExpressions() {
+ return expressions;
+ }
+
+ public void setExpressions(List expressions) {
+ this.expressions = expressions;
+ }
+
+ public static class XMLReferenceExpression {
+ private String from;
+ private String to;
+ private String prefix;
+ private Boolean multiple;
+
+ public XMLReferenceExpression() {
+ }
+
+ public XMLReferenceExpression(String from, String to) {
+ this.from = from;
+ this.to = to;
+ }
+
+ public String getFrom() {
+ return from;
+ }
+
+ public void setFrom(String from) {
+ this.from = from;
+ }
+
+ public String getTo() {
+ return to;
+ }
+
+ public void setTo(String to) {
+ this.to = to;
+ }
+
+ public String getPrefix() {
+ return prefix;
+ }
+
+ public void setPrefix(String prefix) {
+ this.prefix = prefix;
+ }
+
+ public Boolean getMultiple() {
+ return multiple;
+ }
+
+ public void setMultiple(Boolean multiple) {
+ this.multiple = multiple;
+ }
+ }
+
+ public XMLReferencesEntry addExpression(String from, String to) {
+ getExpressions().add(new XMLReferenceExpression(from, to));
+ return this;
+
+ }
+}
diff --git a/org.eclipse.wildwebdeveloper.xml/src/org/eclipse/wildwebdeveloper/xml/internal/ui/preferences/filerules/references/XMLReferencesEntryDialog.java b/org.eclipse.wildwebdeveloper.xml/src/org/eclipse/wildwebdeveloper/xml/internal/ui/preferences/filerules/references/XMLReferencesEntryDialog.java
new file mode 100644
index 0000000000..712e2454ae
--- /dev/null
+++ b/org.eclipse.wildwebdeveloper.xml/src/org/eclipse/wildwebdeveloper/xml/internal/ui/preferences/filerules/references/XMLReferencesEntryDialog.java
@@ -0,0 +1,174 @@
+/*******************************************************************************
+ * Copyright (c) 2026 Red Hat Inc. and others.
+ *
+ * This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License 2.0
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Angelo ZERR (Red Hat Inc.) - initial implementation
+ *******************************************************************************/
+package org.eclipse.wildwebdeveloper.xml.internal.ui.preferences.filerules.references;
+
+import java.util.List;
+
+import org.eclipse.jface.viewers.ColumnLabelProvider;
+import org.eclipse.jface.viewers.ColumnWeightData;
+import org.eclipse.jface.viewers.TableLayout;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.TableViewerColumn;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.wildwebdeveloper.xml.internal.ui.Messages;
+import org.eclipse.wildwebdeveloper.xml.internal.ui.preferences.filerules.AbstractDocumentMatcherEntryDialog;
+import org.eclipse.wildwebdeveloper.xml.internal.ui.preferences.filerules.references.XMLReferencesEntry.XMLReferenceExpression;
+
+/**
+ * Dialog to add or edit a single xml.references entry (DocumentMatcher +
+ * reference expressions).
+ */
+public class XMLReferencesEntryDialog
+ extends AbstractDocumentMatcherEntryDialog {
+
+ public XMLReferencesEntryDialog(Shell parentShell, XMLReferencesEntry entry) {
+ super(parentShell, entry);
+ }
+
+ @Override
+ protected String getAddTitle() {
+ return Messages.XMLReferencesEntryDialog_title_add;
+ }
+
+ @Override
+ protected String getEditTitle() {
+ return Messages.XMLReferencesEntryDialog_title_edit;
+ }
+
+ @Override
+ protected String getMatcherGroupTitle() {
+ return Messages.XMLReferencesEntryDialog_matcher_group;
+ }
+
+ @Override
+ protected String getExpressionsGroupTitle() {
+ return Messages.XMLReferencesEntryDialog_expressions_group;
+ }
+
+ @Override
+ protected String getPatternRequiredError() {
+ return Messages.XMLReferencesEntryDialog_error_pattern_required;
+ }
+
+ @Override
+ protected String getExpressionRequiredError() {
+ return Messages.XMLReferencesEntryDialog_error_expression_required;
+ }
+
+ @Override
+ protected void createExpressionColumns(TableViewer viewer, TableLayout tableLayout) {
+ TableViewerColumn fromCol = new TableViewerColumn(viewer, SWT.NONE);
+ fromCol.getColumn().setText(Messages.XMLReferencesEntryDialog_column_from);
+ tableLayout.addColumnData(new ColumnWeightData(30, 80, true));
+ fromCol.setLabelProvider(new ColumnLabelProvider() {
+ @Override
+ public String getText(Object element) {
+ XMLReferenceExpression expr = (XMLReferenceExpression) element;
+ return expr.getFrom() != null ? expr.getFrom() : "";
+ }
+ });
+
+ TableViewerColumn toCol = new TableViewerColumn(viewer, SWT.NONE);
+ toCol.getColumn().setText(Messages.XMLReferencesEntryDialog_column_to);
+ tableLayout.addColumnData(new ColumnWeightData(30, 80, true));
+ toCol.setLabelProvider(new ColumnLabelProvider() {
+ @Override
+ public String getText(Object element) {
+ XMLReferenceExpression expr = (XMLReferenceExpression) element;
+ return expr.getTo() != null ? expr.getTo() : "";
+ }
+ });
+
+ TableViewerColumn prefixCol = new TableViewerColumn(viewer, SWT.NONE);
+ prefixCol.getColumn().setText(Messages.XMLReferencesEntryDialog_column_prefix);
+ tableLayout.addColumnData(new ColumnWeightData(20, 60, true));
+ prefixCol.setLabelProvider(new ColumnLabelProvider() {
+ @Override
+ public String getText(Object element) {
+ XMLReferenceExpression expr = (XMLReferenceExpression) element;
+ return expr.getPrefix() != null ? expr.getPrefix() : "";
+ }
+ });
+
+ TableViewerColumn multipleCol = new TableViewerColumn(viewer, SWT.NONE);
+ multipleCol.getColumn().setText(Messages.XMLReferencesEntryDialog_column_multiple);
+ tableLayout.addColumnData(new ColumnWeightData(20, 60, true));
+ multipleCol.setLabelProvider(new ColumnLabelProvider() {
+ @Override
+ public String getText(Object element) {
+ XMLReferenceExpression expr = (XMLReferenceExpression) element;
+ return (expr.getMultiple() != null && expr.getMultiple()) ? "true" : "false";
+ }
+ });
+ }
+
+ @Override
+ protected Object createExpressionDialog(XMLReferenceExpression expression) {
+ return new XMLReferenceExpressionDialog(getShell(), expression);
+ }
+
+ @Override
+ protected int openDialog(Object dialog) {
+ return ((XMLReferenceExpressionDialog) dialog).open();
+ }
+
+ @Override
+ protected XMLReferenceExpression getDialogResult(Object dialog) {
+ return ((XMLReferenceExpressionDialog) dialog).getResult();
+ }
+
+ @Override
+ protected List getExpressionsFromEntry(XMLReferencesEntry entry) {
+ return entry.getExpressions();
+ }
+
+ @Override
+ protected void setExpressionsToEntry(XMLReferencesEntry entry, List expressions) {
+ entry.setExpressions(expressions);
+ }
+
+ @Override
+ protected XMLReferencesEntry createEntry() {
+ return new XMLReferencesEntry();
+ }
+
+ @Override
+ protected void loadDefaultValues() {
+ super.loadDefaultValues();
+ }
+
+ @Override
+ protected void loadMatcherFromEntry(XMLReferencesEntry entry) {
+ super.loadMatcherFromEntry(entry);
+ if (matcherWidget instanceof XMLReferencesMatcherWidget) {
+ ((XMLReferencesMatcherWidget) matcherWidget).setPrefix(entry.getPrefix());
+ }
+ }
+
+ @Override
+ protected void saveMatcherToEntry(XMLReferencesEntry entry) {
+ super.saveMatcherToEntry(entry);
+ if (matcherWidget instanceof XMLReferencesMatcherWidget) {
+ entry.setPrefix(((XMLReferencesMatcherWidget) matcherWidget).getPrefix());
+ }
+ }
+
+ @Override
+ protected XMLReferencesMatcherWidget createMatcherWidget(Composite parent) {
+ return new XMLReferencesMatcherWidget(parent, SWT.NONE);
+ }
+}
\ No newline at end of file
diff --git a/org.eclipse.wildwebdeveloper.xml/src/org/eclipse/wildwebdeveloper/xml/internal/ui/preferences/filerules/references/XMLReferencesMatcherWidget.java b/org.eclipse.wildwebdeveloper.xml/src/org/eclipse/wildwebdeveloper/xml/internal/ui/preferences/filerules/references/XMLReferencesMatcherWidget.java
new file mode 100644
index 0000000000..122a4b8785
--- /dev/null
+++ b/org.eclipse.wildwebdeveloper.xml/src/org/eclipse/wildwebdeveloper/xml/internal/ui/preferences/filerules/references/XMLReferencesMatcherWidget.java
@@ -0,0 +1,54 @@
+/*******************************************************************************
+ * Copyright (c) 2026 Red Hat Inc. and others.
+ *
+ * This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License 2.0
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Angelo ZERR (Red Hat Inc.) - initial implementation
+ *******************************************************************************/
+package org.eclipse.wildwebdeveloper.xml.internal.ui.preferences.filerules.references;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.wildwebdeveloper.xml.internal.ui.preferences.filerules.DocumentMatcherWidget;
+
+/**
+ * Extended DocumentMatcherWidget for XMLReferences that adds a prefix field.
+ */
+public class XMLReferencesMatcherWidget extends DocumentMatcherWidget {
+
+ private final Text prefixText;
+
+ public XMLReferencesMatcherWidget(Composite parent, int style) {
+ super(parent, style);
+
+ // Add prefix field after pattern field
+ // Get the pattern composite (first child)
+ Composite patternComposite = (Composite) getChildren()[0];
+
+ // Add prefix field to the same composite
+ Label prefixLabel = new Label(patternComposite, SWT.NONE);
+ prefixLabel.setText("Prefix:");
+ prefixLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
+
+ prefixText = new Text(patternComposite, SWT.BORDER | SWT.SINGLE);
+ prefixText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
+ }
+
+ public String getPrefix() {
+ String value = prefixText.getText().trim();
+ return value.isEmpty() ? null : value;
+ }
+
+ public void setPrefix(String prefix) {
+ prefixText.setText(prefix != null ? prefix : "");
+ }
+}
diff --git a/org.eclipse.wildwebdeveloper.xml/src/org/eclipse/wildwebdeveloper/xml/internal/ui/preferences/filerules/references/XMLReferencesPreferencePage.java b/org.eclipse.wildwebdeveloper.xml/src/org/eclipse/wildwebdeveloper/xml/internal/ui/preferences/filerules/references/XMLReferencesPreferencePage.java
new file mode 100644
index 0000000000..8fd81a557e
--- /dev/null
+++ b/org.eclipse.wildwebdeveloper.xml/src/org/eclipse/wildwebdeveloper/xml/internal/ui/preferences/filerules/references/XMLReferencesPreferencePage.java
@@ -0,0 +1,96 @@
+/*******************************************************************************
+ * Copyright (c) 2026 Red Hat Inc. and others.
+ *
+ * This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License 2.0
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Angelo ZERR (Red Hat Inc.) - initial implementation
+ *******************************************************************************/
+package org.eclipse.wildwebdeveloper.xml.internal.ui.preferences.filerules.references;
+
+import static org.eclipse.wildwebdeveloper.xml.internal.ui.preferences.XMLPreferenceServerConstants.XML_PREFERENCES_REFERENCES;
+
+import java.util.Collection;
+import java.util.List;
+
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.viewers.ColumnLabelProvider;
+import org.eclipse.jface.viewers.ColumnWeightData;
+import org.eclipse.jface.viewers.TableLayout;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.TableViewerColumn;
+import org.eclipse.wildwebdeveloper.xml.internal.ui.Messages;
+import org.eclipse.wildwebdeveloper.xml.internal.ui.preferences.XMLPreferenceInitializer;
+import org.eclipse.wildwebdeveloper.xml.internal.ui.preferences.filerules.AbstractDocumentMatcherPreferencePage;
+import org.eclipse.wildwebdeveloper.xml.internal.ui.preferences.filerules.references.XMLReferencesEntry.XMLReferenceExpression;
+
+/**
+ * Preference page for xml.references — specifies cross-element references via
+ * XPath from/to expressions.
+ */
+public class XMLReferencesPreferencePage extends AbstractDocumentMatcherPreferencePage {
+
+ public static final String PAGE_ID = "org.eclipse.wildwebdeveloper.xml.internal.ui.preferences.filerules.references.XMLReferencesPreferencePage";
+
+ @Override
+ public String getDescription() {
+ return Messages.XMLReferencesPreferencePage_description;
+ }
+
+ @Override
+ protected String getGroupTitle() {
+ return Messages.XMLReferencesPreferencePage_entries;
+ }
+
+ @Override
+ protected String getPreferenceKey() {
+ return XML_PREFERENCES_REFERENCES.preferenceId;
+ }
+
+ @Override
+ protected Class getEntryClass() {
+ return XMLReferencesEntry.class;
+ }
+
+ @Override
+ protected Collection extends XMLReferencesEntry> getDefaultEntries() {
+ return XMLPreferenceInitializer.DEFAULT_REFERENCES;
+ }
+
+ @Override
+ protected void createAdditionalColumns(TableViewer viewer, TableLayout tableLayout) {
+ TableViewerColumn expressionsCol = new TableViewerColumn(viewer, org.eclipse.swt.SWT.NONE);
+ expressionsCol.getColumn().setText(Messages.XMLReferencesPreferencePage_column_expressions);
+ tableLayout.addColumnData(new ColumnWeightData(50, 120, true));
+ expressionsCol.setLabelProvider(new ColumnLabelProvider() {
+ @Override
+ public String getText(Object element) {
+ XMLReferencesEntry entry = (XMLReferencesEntry) element;
+ List exprs = entry.getExpressions();
+ if (exprs == null || exprs.isEmpty())
+ return "0";
+ if (exprs.size() == 1) {
+ XMLReferenceExpression expr = exprs.get(0);
+ String from = expr.getFrom() != null ? expr.getFrom() : "";
+ String to = expr.getTo() != null ? expr.getTo() : "";
+ return from + " → " + to;
+ }
+ return String.valueOf(exprs.size()) + " expressions";
+ }
+ });
+ }
+
+ @Override
+ protected Dialog createEntryDialog(XMLReferencesEntry entry) {
+ return new XMLReferencesEntryDialog(getShell(), entry);
+ }
+
+ @Override
+ protected XMLReferencesEntry getDialogResult(Dialog dialog) {
+ return ((XMLReferencesEntryDialog) dialog).getResult();
+ }
+}
\ No newline at end of file