View | Details | Raw Unified | Return to bug 86862 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/core/internal/content/ContentTypeMatcher.java (+27 lines)
Lines 11-16 Link Here
11
package org.eclipse.core.internal.content;
11
package org.eclipse.core.internal.content;
12
12
13
import java.io.*;
13
import java.io.*;
14
import java.util.ArrayList;
15
import java.util.List;
14
import org.eclipse.core.runtime.QualifiedName;
16
import org.eclipse.core.runtime.QualifiedName;
15
import org.eclipse.core.runtime.content.*;
17
import org.eclipse.core.runtime.content.*;
16
18
Lines 54-59 Link Here
54
	 */
56
	 */
55
	public IContentType[] findContentTypesFor(String fileName) {
57
	public IContentType[] findContentTypesFor(String fileName) {
56
		return getCatalog().findContentTypesFor(fileName, policy);
58
		return getCatalog().findContentTypesFor(fileName, policy);
59
	}
60
61
	public Object[] findRelatedObjects(IContentType type, String fileName, IRelatedRegistry registry) {
62
		List allRelated = new ArrayList();
63
		// first add any objects directly related to the content type
64
		Object[] related = registry.getRelatedObjects(type);
65
		for (int i = 0; i < related.length; i++)
66
			allRelated.add(related[i]);
67
		// backward compatibility requested - add any objects related to the file name
68
		if (fileName != null) {
69
			related = registry.getRelatedObjects(fileName);
70
			for (int i = 0; i < related.length; i++)
71
				if (!allRelated.contains(related[i]))
72
					// we don't want to return duplicates
73
					allRelated.add(related[i]);
74
		}
75
		// now add any indirectly related objects, walking up the content type hierarchy 
76
		while ((type = type.getBaseType()) != null) {
77
			related = registry.getRelatedObjects(type);
78
			for (int i = 0; i < related.length; i++)
79
				if (!allRelated.contains(related[i]))
80
					// we don't want to return duplicates					
81
					allRelated.add(related[i]);
82
		}
83
		return allRelated.toArray();
57
	}
84
	}
58
85
59
	private ContentTypeCatalog getCatalog() {
86
	private ContentTypeCatalog getCatalog() {
(-)src/org/eclipse/core/runtime/content/IContentTypeMatcher.java (+56 lines)
Lines 23-28 Link Here
23
 * @since 3.1
23
 * @since 3.1
24
 */
24
 */
25
public interface IContentTypeMatcher {
25
public interface IContentTypeMatcher {
26
27
	/**
28
	 * A client-provided registry containing objects that are related to content types. Implementations
29
	 * of this interface collaborate with the content type infrastructure in order to support lookup 
30
	 * of content type related objects. 
31
	 * <p>
32
	 * Clients may implement this interface.
33
	 * </p>
34
	 * 
35
	 * @see IContentTypeMatcher#findRelatedObjects(IContentType, String, IRelatedRegistry)
36
	 */
37
	interface IRelatedRegistry {
38
		/**
39
		 * Returns all objects in this client-provided registry that are directly related to the given
40
		 * content type.
41
		 * 
42
		 * @param type a content type
43
		 * @return an array containing all objects directly related to the given content type
44
		 */
45
		Object[] getRelatedObjects(IContentType type);
46
47
		/**
48
		 * Returns all objects in this client-provided registry that are directly related to the given
49
		 * file name.
50
		 * <p>
51
		 * This method is optional. It only has to be implemented if this registry supports 
52
		 * file name based association in addition to content type based association. 
53
		 * Otherwise, it can throw <code>UnsupportedOperationException</code>.
54
		 * </p>
55
		 * 
56
		 * @param fileName a file name
57
		 * @return an array containing all objects directly related to the given file name
58
		 * @throws UnsupportedOperationException if this registry does not support file
59
		 * name based association
60
		 */
61
		Object[] getRelatedObjects(String fileName);
62
	}
63
26
	/**
64
	/**
27
	 * Returns the preferred content type for the given contents and file name.
65
	 * Returns the preferred content type for the given contents and file name.
28
	 * <p>
66
	 * <p>
Lines 90-95 Link Here
90
	 * @return all content types associated to the given file spec
128
	 * @return all content types associated to the given file spec
91
	 */
129
	 */
92
	public IContentType[] findContentTypesFor(String fileName);
130
	public IContentType[] findContentTypesFor(String fileName);
131
132
	/**
133
	 * Returns all objects in the given content type-related registry  that are 
134
	 * related to the content type and file name specified. This method will walk 
135
	 * the content type hierarchy tree up to a root content type, collecting all related
136
	 * objects from the given registry. 
137
	 * <p>
138
	 * The file name is optional, and has to be omitted if the given registry 
139
	 * does not support file name based associations.  
140
	 * </p>
141
	 * 
142
	 * @param type a content type
143
	 * @param fileName the name of the file, or <code>null</code> 
144
	 * @param registry a related registry
145
	 * @return all objects in the related registry that are associated to the 
146
	 * content type
147
	 */
148
	public Object[] findRelatedObjects(IContentType type, String fileName, IRelatedRegistry registry);
93
149
94
	/**
150
	/**
95
	 * Tries to obtain a description for the given contents and file name. 
151
	 * Tries to obtain a description for the given contents and file name. 

Return to bug 86862