Bug 86862 - [content type] need API for related custom objects lookup
Summary: [content type] need API for related custom objects lookup
Status: RESOLVED WONTFIX
Alias: None
Product: Platform
Classification: Eclipse Project
Component: Runtime (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: Rafael Chaves CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 78652 82986
  Show dependency tree
 
Reported: 2005-02-28 13:34 EST by Rafael Chaves CLA
Modified: 2009-08-18 16:19 EDT (History)
3 users (show)

See Also:


Attachments
patch for org.eclipse.core.runtime (5.14 KB, patch)
2005-03-08 11:06 EST, Rafael Chaves CLA
no flags Details | Diff
patch for org.eclipse.core.tests.runtime (4.61 KB, patch)
2005-03-08 11:07 EST, Rafael Chaves CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Rafael Chaves CLA 2005-02-28 13:34:31 EST
Many clients provide their custom objects that are associated to content types. 

We should provide API that helps clients to find out whhich of their custom
objects are associated to a given content type. This API should perform a
traversal of the content type hierarchy, finding matching custom objects (order
is important). Also, this API should help clients to deal with legacy
associations with file names (as most clients support).

Proposed API changes:

New sub-interface in IContentTypeManager:

// clients should implement
interface IRelatedRegistry {
  // returns objects *directly* related to the given content type.
  Object[] getRelatedObjects(IContentType type);
}

New sub-interface in IContentTypeManager:

// clients should implement
interface ILegacyRegistry extends IRelatedRegistry {
  // returns objects related to the given file name
  Object[] getRelatedObjects(String fileName);
}

New operation in IContentTypeManager:

/* 
  Returns all custom objects related to the given content type and fileName
  (optional, should be provided if available/for legacy support)
*/
Object[] findRelatedObjects(IContentType type, String fileName, IRelatedRegistry
registry)

This operation would return an array of related custom objects (as provided by
the client implementation of IRelatedRegistry). The order the results would
appear would be:

1st - all custom objects *directly* related to the given content type
2nd - all custom objects related to the given file name (if any provided)
3rd - all custom objects *indirectly* related to the given content type
Comment 1 Rafael Chaves CLA 2005-02-28 13:37:29 EST
Kim, I believe this API could be very helpful when implementing editor-content
type associations lookup.
Comment 2 Rafael Chaves CLA 2005-03-08 11:06:50 EST
Created attachment 18538 [details]
patch for org.eclipse.core.runtime
Comment 3 Rafael Chaves CLA 2005-03-08 11:07:06 EST
Created attachment 18539 [details]
patch for org.eclipse.core.tests.runtime
Comment 4 Rafael Chaves CLA 2005-03-08 11:13:57 EST
CC'ing Andre.
Comment 5 Rafael Chaves CLA 2005-03-08 11:14:26 EST
CC'ing Daniel.
Comment 6 Rafael Chaves CLA 2005-03-08 11:18:05 EST
CC'ing Darin.

I will release this API as soon this week~s i-build settles down. To give an
idea on how it works, here is the corresponding test case. Please let me know if
you have any suggestions/concerns about this API. The goal here is to provide an
uniform/single way people providing content type related registries look up for
the objects they provide (editors, content viewers, object contributions,
document setup extensions, etc).

  public void testRelatedRegistry() {
    IContentTypeManager manager = Platform.getContentTypeManager();
    IContentType text = manager.getContentType(Platform.PI_RUNTIME + ".text");
    IContentType xml = manager.getContentType(Platform.PI_RUNTIME + ".xml");
    String textEditor = "Text editor";
    String xmlEditor = "XML editor";
    String legacyTextEditor = "Legacy Text editor";
    String legacyXmlEditor = "Legacy XML editor";
    final Object[][] contentTypeAssociations = { {text, textEditor}, {xml,
xmlEditor}};
    final Object[][] legacyAssociations = { {"legacy.txt", legacyTextEditor},
{"legacy.xml", legacyXmlEditor}};

    IContentTypeMatcher matcher = manager.getMatcher(new LocalSelectionPolicy());

    IRelatedRegistry registry = new IRelatedRegistry() {
      public Object[] getRelatedObjects(IContentType type) {
        List result = new ArrayList();
        for (int i = 0; i < contentTypeAssociations.length; i++)
          if (contentTypeAssociations[i][0].equals(type))
            result.add(contentTypeAssociations[i][1]);
        return result.toArray();
      }

      public Object[] getRelatedObjects(String fileName) {
        List result = new ArrayList();
        for (int i = 0; i < contentTypeAssociations.length; i++)
          if (legacyAssociations[i][0].equals(fileName))
            result.add(legacyAssociations[i][1]);
        return result.toArray();
      }
    };

    Object[] editors;
    editors = matcher.findRelatedObjects(xml, null, registry);
    assertEquals("1.0", 2, editors.length);
    assertEquals("1.1", editors[0], xmlEditor);
    assertEquals("1.1", editors[1], textEditor);

    editors = matcher.findRelatedObjects(text, null, registry);
    assertEquals("2.0", 1, editors.length);
    assertEquals("2.1", editors[0], textEditor);

    editors = matcher.findRelatedObjects(xml, "legacy.txt", registry);
    assertEquals("3.0", 3, editors.length);
    assertEquals("3.1", editors[0], xmlEditor);
    assertEquals("3.2", editors[1], legacyTextEditor);
    assertEquals("3.3", editors[2], textEditor);

    editors = matcher.findRelatedObjects(text, "legacy.xml", registry);
    assertEquals("4.0", 2, editors.length);
    assertEquals("4.1", editors[0], textEditor);
    assertEquals("4.2", editors[1], legacyXmlEditor);

    editors = matcher.findRelatedObjects(xml, "legacy.xml", registry);
    assertEquals("5.0", 3, editors.length);
    assertEquals("5.1", editors[0], xmlEditor);
    assertEquals("5.2", editors[1], legacyXmlEditor);
    assertEquals("5.3", editors[2], textEditor);

    editors = matcher.findRelatedObjects(text, "legacy.txt", registry);
    assertEquals("6.0", 2, editors.length);
    assertEquals("6.1", editors[0], textEditor);
    assertEquals("6.2", editors[1], legacyTextEditor);

  }
Comment 7 Rafael Chaves CLA 2005-03-08 14:17:41 EST
Fixed. Released to HEAD. Patches are obsolete.
Comment 8 Dani Megert CLA 2005-03-16 09:46:44 EST
Rafael, I see that this could be used in the file buffer's ExtensionsRegistry.
Do you see another place in Platform/JDT Text?

Since the ExtensionsRegistry already considers the hierarchy and given the load
of work we already have we can't change the code to use this new API but would
be happily accept a patch.
Comment 9 Rafael Chaves CLA 2005-03-16 11:37:06 EST
If you already have code in place that does the right thing, you may leave it as
it is, and consider doing it at a later date. This is more intended for new
adopters and components thar are not happy/have problems with doing content type
matching themselves.
Comment 10 Rafael Chaves CLA 2005-03-16 11:45:45 EST
Answering your other question, the only other place in Platform/JDT Text I saw
hierarchy traversal being done was DefaultSpellingEngine. But in that case it is
ok, because it is looking for one content type, and does not have to support
legacy association with file names, the two use cases for adopting the API
proposed here.
Comment 11 Rafael Chaves CLA 2005-03-22 13:28:09 EST
Talked to Kim about this and decided to revert these changes (once this week's
i-build settles down). Might put it back in 3.2 if people need it.
Comment 12 Rafael Chaves CLA 2005-03-23 17:39:35 EST
Changes rolled back. 

Marking as later.
Comment 13 John Arthorne CLA 2009-08-18 16:13:47 EDT
[LATER->WONTFIX] The "LATER" bugzilla resolution is being removed so reopening to mark as WONTFIX.
Comment 14 John Arthorne CLA 2009-08-18 16:19:51 EDT
[LATER->WONTFIX] The "LATER" bugzilla resolution is being removed so reopening to mark as WONTFIX.