Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 208564 | Differences between
and this patch

Collapse All | Expand All

(-)Eclipse UI/org/eclipse/ui/internal/registry/PreferenceTransferRegistryReader.java (-2 / +15 lines)
Lines 7-12 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Semion Chichelnitsky (semion@il.ibm.com) - bug 208564
10
 *******************************************************************************/
11
 *******************************************************************************/
11
12
12
package org.eclipse.ui.internal.registry;
13
package org.eclipse.ui.internal.registry;
Lines 24-29 Link Here
24
import org.eclipse.core.runtime.Platform;
25
import org.eclipse.core.runtime.Platform;
25
import org.eclipse.core.runtime.preferences.PreferenceFilterEntry;
26
import org.eclipse.core.runtime.preferences.PreferenceFilterEntry;
26
import org.eclipse.ui.internal.WorkbenchPlugin;
27
import org.eclipse.ui.internal.WorkbenchPlugin;
28
import org.eclipse.ui.internal.preferences.PreferenceMatcher;
27
import org.eclipse.ui.internal.preferences.PreferenceTransferElement;
29
import org.eclipse.ui.internal.preferences.PreferenceTransferElement;
28
30
29
/**
31
/**
Lines 169-176 Link Here
169
				prefFilters = new PreferenceFilterEntry[keys.length];
171
				prefFilters = new PreferenceFilterEntry[keys.length];
170
				for (int j = 0; j < keys.length; j++) {
172
				for (int j = 0; j < keys.length; j++) {
171
					IConfigurationElement keyElement = keys[j];
173
					IConfigurationElement keyElement = keys[j];
172
					prefFilters[j] = new PreferenceFilterEntry(keyElement
174
					boolean regExp = !(keyElement
173
							.getAttribute(IWorkbenchRegistryConstants.ATT_NAME));
175
							.getAttribute(IWorkbenchRegistryConstants.REG_EXP) == null || !keyElement
176
							.getAttribute(IWorkbenchRegistryConstants.REG_EXP)
177
							.equalsIgnoreCase("true")); //$NON-NLS-1$
178
					if (!regExp)
179
						prefFilters[j] = new PreferenceFilterEntry(
180
								keyElement
181
										.getAttribute(IWorkbenchRegistryConstants.ATT_NAME));
182
					else
183
						prefFilters[j] = new PreferenceFilterEntry(
184
								keyElement
185
										.getAttribute(IWorkbenchRegistryConstants.ATT_NAME),
186
								new PreferenceMatcher());
174
				}
187
				}
175
			}
188
			}
176
			map.put(entry.getAttribute(IWorkbenchRegistryConstants.ATT_NODE),
189
			map.put(entry.getAttribute(IWorkbenchRegistryConstants.ATT_NODE),
(-)Eclipse UI/org/eclipse/ui/internal/registry/IWorkbenchRegistryConstants.java (+6 lines)
Lines 10-15 Link Here
10
 *     Dan Rubel <dan_rubel@instantiations.com>
10
 *     Dan Rubel <dan_rubel@instantiations.com>
11
 *     - Fix for bug 11490 - define hidden view (placeholder for view) in plugin.xml    
11
 *     - Fix for bug 11490 - define hidden view (placeholder for view) in plugin.xml    
12
 *     Markus Alexander Kuppe, Versant Corporation - bug #215797
12
 *     Markus Alexander Kuppe, Versant Corporation - bug #215797
13
 *     Semion Chichelnitsky (semion@il.ibm.com) - bug 208564
13
 *******************************************************************************/
14
 *******************************************************************************/
14
package org.eclipse.ui.internal.registry;
15
package org.eclipse.ui.internal.registry;
15
16
Lines 328-333 Link Here
328
	public static String ATT_NAME = "name"; //$NON-NLS-1$
329
	public static String ATT_NAME = "name"; //$NON-NLS-1$
329
330
330
	/**
331
	/**
332
	 * Name as regular expression attribute. Value <code>regexp</code>.
333
	 */
334
	public static String REG_EXP = "regexp"; //$NON-NLS-1$
335
336
	/**
331
	 * Name filter attribute. Value <code>nameFilter</code>.
337
	 * Name filter attribute. Value <code>nameFilter</code>.
332
	 */
338
	 */
333
	public static String ATT_NAME_FILTER = "nameFilter"; //$NON-NLS-1$
339
	public static String ATT_NAME_FILTER = "nameFilter"; //$NON-NLS-1$
(-)Eclipse (+56 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 ******************************************************************************/
11
12
package org.eclipse.ui.internal.preferences;
13
14
import java.util.regex.Matcher;
15
import java.util.regex.Pattern;
16
import java.util.regex.PatternSyntaxException;
17
import org.eclipse.core.runtime.IStatus;
18
import org.eclipse.core.runtime.preferences.IPreferenceMatcher;
19
import org.eclipse.ui.internal.WorkbenchPlugin;
20
import org.eclipse.ui.internal.misc.StatusUtil;
21
22
/**
23
 * @since 3.6
24
 * 
25
 */
26
public class PreferenceMatcher implements IPreferenceMatcher {
27
28
	/*
29
	 * (non-Javadoc)
30
	 * 
31
	 * @see
32
	 * org.eclipse.core.runtime.preferences.IPreferenceMatcher#find(java.lang
33
	 * .String, java.lang.String)
34
	 */
35
	public boolean find(String expression, String key) {
36
		if (key == null || key.length() == 0 || expression == null
37
				|| expression.length() == 0)
38
			return false;
39
		Pattern pattern = null;
40
		try {
41
			pattern = Pattern.compile(expression);
42
		} catch (PatternSyntaxException e) {
43
			WorkbenchPlugin
44
					.log(
45
							"Error occurred while searching preferences which match some regular expression", //$NON-NLS-1$
46
							StatusUtil.newStatus(IStatus.ERROR, e.getMessage(),
47
									e));
48
		}
49
		if (pattern == null)
50
			return false;
51
		Matcher matcher = pattern.matcher(key);
52
		if (matcher.find())
53
			return true;
54
		return false;
55
	}
56
}
(-)src/org/eclipse/core/internal/preferences/PreferencesService.java (-4 / +33 lines)
Lines 773-781 Link Here
773
							return true;
773
							return true;
774
					} else {
774
					} else {
775
						// otherwise check to see if we have any applicable keys
775
						// otherwise check to see if we have any applicable keys
776
						for (int k = 0; k < entries.length; k++) {
777
							if (entries[k] != null && entries[k].isRegexp())
778
								internalMatchesWithRegexp(entries[k], child.keys());
779
						}
776
						for (int j = 0; j < entries.length; j++) {
780
						for (int j = 0; j < entries.length; j++) {
777
							if (entries[j] != null && child.get(entries[j].getKey(), null) != null)
781
							if (entries[j] != null) {
778
								return true;
782
								if (!entries[j].isRegexp() && child.get(entries[j].getKey(), null) != null)
783
									return true;
784
								else if (entries[j].isRegexp()) {
785
									if (entries[j].getMatches() != null)
786
										return true;
787
								}
788
							}
779
						}
789
						}
780
					}
790
					}
781
				}
791
				}
Lines 785-790 Link Here
785
	}
795
	}
786
796
787
	/*
797
	/*
798
	 * Internal method that collects the matching preferences for the given regular expression.
799
	 */
800
	private void internalMatchesWithRegexp(PreferenceFilterEntry entry, String[] keys) {
801
		if (keys == null || keys.length == 0)
802
			return;
803
		for (int i = 0; i < keys.length; i++) {
804
			entry.addMatch(keys[i]);
805
		}
806
	}
807
808
	/*
788
	 * Internal method that collects the matching filters for the given tree and returns them.
809
	 * Internal method that collects the matching filters for the given tree and returns them.
789
	 */
810
	 */
790
	private IPreferenceFilter[] internalMatches(IEclipsePreferences tree, IPreferenceFilter[] filters) throws BackingStoreException {
811
	private IPreferenceFilter[] internalMatches(IEclipsePreferences tree, IPreferenceFilter[] filters) throws BackingStoreException {
Lines 973-980 Link Here
973
					if (entries != null) {
994
					if (entries != null) {
974
						ArrayList list = new ArrayList();
995
						ArrayList list = new ArrayList();
975
						for (int j = 0; j < entries.length; j++) {
996
						for (int j = 0; j < entries.length; j++) {
976
							if (entries[j] != null)
997
							if (entries[j] != null) {
977
								list.add(entries[j].getKey());
998
								if (!entries[j].isRegexp())
999
									list.add(entries[j].getKey());
1000
								else if (entries[j].getMatches() != null) {
1001
									Object[] matches = entries[j].getMatches();
1002
									for (int k = 0; k < matches.length; k++) {
1003
										list.add(matches[k]);
1004
									}
1005
								}
1006
							}
978
						}
1007
						}
979
						keys = (String[]) list.toArray(new String[list.size()]);
1008
						keys = (String[]) list.toArray(new String[list.size()]);
980
					}
1009
					}
(-)src/org/eclipse/core/runtime/preferences/PreferenceFilterEntry.java (+69 lines)
Lines 10-15 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.core.runtime.preferences;
11
package org.eclipse.core.runtime.preferences;
12
12
13
import java.util.HashSet;
14
13
/**
15
/**
14
 * Class which represents and preference filter entry to be used during preference
16
 * Class which represents and preference filter entry to be used during preference
15
 * import/export (for example).
17
 * import/export (for example).
Lines 21-26 Link Here
21
public final class PreferenceFilterEntry {
23
public final class PreferenceFilterEntry {
22
24
23
	private String key;
25
	private String key;
26
	private HashSet matches;
27
	private IPreferenceMatcher matcher;
28
	boolean isRegexp;
24
29
25
	/**
30
	/**
26
	 * Constructor for the class. Create a new preference filter entry with the given 
31
	 * Constructor for the class. Create a new preference filter entry with the given 
Lines 36-41 Link Here
36
	}
41
	}
37
42
38
	/**
43
	/**
44
	 * Constructor for the class. Create a new preference filter entry with the key, given 
45
	 * in the form of regular expression and implementation of {@link IPreferenceMatcher}, 
46
	 * used to find preferences with names, which are suitable for this regular expression. 
47
	 * The key must <em>not</em> be <code>null</code> or empty. 
48
	 * 
49
	 * @param key the name of the preference key
50
	 * @param matcher used to find preferences with names, which are suitable for key
51
	 * @see org.eclipse.core.runtime.preferences.IPreferenceMatcher
52
	 * 
53
	 * @since 3.6
54
	 */
55
	public PreferenceFilterEntry(String key, IPreferenceMatcher matcher) {
56
		super();
57
		if (key == null || key.length() == 0)
58
			throw new IllegalArgumentException();
59
		this.key = key;
60
		this.matcher = matcher;
61
		if (matcher != null)
62
			isRegexp = true;
63
	}
64
65
	/**
39
	 * Return the name of the preference key for this filter entry.
66
	 * Return the name of the preference key for this filter entry.
40
	 * It will <em>not</em> return <code>null</code> or the
67
	 * It will <em>not</em> return <code>null</code> or the
41
	 * empty string.
68
	 * empty string.
Lines 45-48 Link Here
45
	public String getKey() {
72
	public String getKey() {
46
		return key;
73
		return key;
47
	}
74
	}
75
76
	/**
77
	 * Return regular expression flag.
78
	 * 
79
	 * @return the regular expression flag
80
	 * 
81
	 * @since 3.6
82
	 */
83
	public boolean isRegexp() {
84
		return isRegexp;
85
	}
86
87
	/**
88
	 * Adding  into collection of preferences names, match the regular expression,
89
	 * which is contained in the <code>key</code>.
90
	 * 
91
	 * @param name the name of the preference, matches the regular expression, contained in the key
92
	 * 
93
	 * @since 3.6
94
	 */
95
	public void addMatch(String name) {
96
		if (!isRegexp)
97
			return;
98
		if (matches == null)
99
			matches = new HashSet();
100
		if (matcher.find(key, name))
101
			matches.add(name);
102
	}
103
104
	/**
105
	 * Return the array of preferences' names, matches the regular expression, contained in the key
106
	 * 
107
	 * @return the array of the preferencs' names, matches the regular expression, contained in the key
108
	 * 
109
	 * @since 3.6
110
	 */
111
	public Object[] getMatches() {
112
		if (!isRegexp || matches == null || matches.size() == 0)
113
			return null;
114
		return matches.toArray();
115
	}
116
48
}
117
}
(-)src/org/eclipse/core/runtime/preferences/IPreferenceMatcher.java (+31 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.core.runtime.preferences;
12
13
/**
14
 * Preference matcher is used to find preferences, which are suitable 
15
 * for given regular expression.
16
 * <p>
17
 * Clients may implement this interface.
18
 * </p>
19
 * 
20
 * @since 3.6
21
 */
22
public interface IPreferenceMatcher {
23
	/**
24
	 * Return <code>true</code> if key match given regular expression
25
	 *  
26
	 * @param expression regular expression
27
	 * @param key preference name
28
	 * @return true if key match given regular expression, false in opposite case
29
	 */
30
	public boolean find(String expression, String key);
31
}
(-)schema/preferenceTransfer.exsd (-18 / +16 lines)
Lines 1-6 Link Here
1
<?xml version='1.0' encoding='UTF-8'?>
1
<?xml version='1.0' encoding='UTF-8'?>
2
<!-- Schema file written by PDE -->
2
<!-- Schema file written by PDE -->
3
<schema targetNamespace="org.eclipse.ui">
3
<schema targetNamespace="org.eclipse.ui" xmlns="http://www.w3.org/2001/XMLSchema">
4
<annotation>
4
<annotation>
5
      <appInfo>
5
      <appInfo>
6
         <meta.schema plugin="org.eclipse.ui" id="preferenceTransfer" name="Preference Transfer"/>
6
         <meta.schema plugin="org.eclipse.ui" id="preferenceTransfer" name="Preference Transfer"/>
Lines 14-19 Link Here
14
   </annotation>
14
   </annotation>
15
15
16
   <element name="extension">
16
   <element name="extension">
17
      <annotation>
18
         <appInfo>
19
            <meta.element />
20
         </appInfo>
21
      </annotation>
17
      <complexType>
22
      <complexType>
18
         <sequence>
23
         <sequence>
19
            <element ref="transfer" minOccurs="0" maxOccurs="unbounded"/>
24
            <element ref="transfer" minOccurs="0" maxOccurs="unbounded"/>
Lines 152-157 Link Here
152
               </documentation>
157
               </documentation>
153
            </annotation>
158
            </annotation>
154
         </attribute>
159
         </attribute>
160
         <attribute name="regexp" type="boolean">
161
            <annotation>
162
               <documentation>
163
                  This attribute specifies, how attribute &quot;name&quot; is used. If it is omitted or set to &quot;false&quot;, &quot;name&quot; contains exact name of preference. In opposite case value of &quot;name&quot; is used as a regular expression for searching in the set of  preferences. 
164
Since 3.6.
165
               </documentation>
166
            </annotation>
167
         </attribute>
155
      </complexType>
168
      </complexType>
156
   </element>
169
   </element>
157
170
Lines 268-274 Link Here
268
                   &lt;key name=&quot;showIntro,DOCK_PERSPECTIVE_BAR&quot;/&gt;
281
                   &lt;key name=&quot;showIntro,DOCK_PERSPECTIVE_BAR&quot;/&gt;
269
                &lt;/entry&gt;
282
                &lt;/entry&gt;
270
                &lt;entry node=&quot;org.eclipse.ui.workbench&quot;&gt;
283
                &lt;entry node=&quot;org.eclipse.ui.workbench&quot;&gt;
271
                   &lt;key name=&quot;bogus,RUN_IN_BACKGROUND&quot;/&gt;
284
                   &lt;key name=&quot;RUN_IN_BACKGROUND&quot;/&gt;
285
                   &lt;key name=&quot;OPEN*&quot; regexp=&quot;true&quot;/&gt;
272
                &lt;/entry&gt;   
286
                &lt;/entry&gt;   
273
                &lt;entry node=&quot;org.eclipse.ui.ide&quot;/&gt;
287
                &lt;entry node=&quot;org.eclipse.ui.ide&quot;/&gt;
274
                &lt;entry node=&quot;org.eclipse.core.resources&quot;/&gt;
288
                &lt;entry node=&quot;org.eclipse.core.resources&quot;/&gt;
Lines 284-306 Link Here
284
      </documentation>
298
      </documentation>
285
   </annotation>
299
   </annotation>
286
300
287
   <annotation>
288
      <appInfo>
289
         <meta.section type="apiInfo"/>
290
      </appInfo>
291
      <documentation>
292
         
293
      </documentation>
294
   </annotation>
295
301
296
   <annotation>
297
      <appInfo>
298
         <meta.section type="implementation"/>
299
      </appInfo>
300
      <documentation>
301
         
302
      </documentation>
303
   </annotation>
304
302
305
   <annotation>
303
   <annotation>
306
      <appInfo>
304
      <appInfo>

Return to bug 208564