Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 181515

Summary: Provide more structure, safety, and convenience for ID-based references between extension points (id hell)
Product: [Eclipse Project] PDE Reporter: Berthold Daum <berthold.daum>
Component: UIAssignee: Chris Aniszczyk <caniszczyk>
Status: VERIFIED FIXED QA Contact:
Severity: enhancement    
Priority: P3 CC: berthold.daum, caniszczyk, contact, ed, irbull, jan.diederich, jiri.klement, KetanPadegaonkar, markus.kell.r, pwebster, remy.suen, xavier.mehaut
Version: 3.3Keywords: noteworthy
Target Milestone: 3.4 M6   
Hardware: All   
OS: All   
Whiteboard: id hell
Attachments:
Description Flags
Schema definition for proposed extension point idFactory
none
Schema definition for proposed extension point idFactory
none
ID Search attribute v01
none
Schema examples v01
none
ID Search attribute v02
none
org.eclipse.pde.patch
none
mylyn/context/zip
none
Schema examples v02
none
org.eclipse.pde.patch
none
mylyn/context/zip
none
sample screenshot #1
none
sample screenshot #2
none
org.eclipse.pde.patch
none
mylyn/context/zip
none
Schema examples v03 none

Description Berthold Daum CLA 2007-04-08 05:56:34 EDT
Rationale: The ID-based "wiring" between plug-ins is currently one of the most error-prone and tedious areas when developing 

Eclipse plug-ins and Eclipse RCP applications.


1. Enhancements to the extension point schema (exsd). 
   a) Allow for a new attribute type "ref". Attributes of that type will refer to the id-Attribute of other configuration elements. 
   b) For attributes of type "ref" provide a property called "satisfiedBy". This property will specify which configuration elements qualify as an id-source for the attribute. 
   c) For the property "satisfiedBy" provide a "Browse" button. On demand this button will list all known configuration elements that own an attribute "id".

Example:
We show an example for extension point org.eclipse.ui.perspectiveExtensions. Extensions to this point can, for example, refer to a given view by ID. We change the type of attribute "id" from "string" to "ref" and add the attribute "satisfiedBy". This attribute specifies as an id-source the configuration element "view" in extension point "org.eclipse.ui.views". These configuration element has an "id" attribute and thus qualifies as an id-source.

   <element name="view">
      <complexType>
         <attribute name="id" type="ref" use="required" satisfiedBy="org.eclipse.ui.views/view">
            <annotation>
               <documentation>
                  the unique identifier of the view which will be added to the perspective layout.
               </documentation>
            </annotation>
         </attribute>
       ....
    </element>


2. Enhancement to the "Extensions" section of the Plug-in manifest editor.
   For attributes declared in the schema as of type "ref" provide a "Browse" button. On demand this button will list the IDs of all configuration elements matching the path specified in the schema's "satisfiedBy" property.


3. Automatically check for dangling "ref" attributes in a given scope. This tool should be provided both for features and RCP product configurations. A warning should be given for each dangling reference. This check should be made optional/configurable via the Preferences.
Comment 1 Wassim Melhem CLA 2007-04-08 11:28:30 EDT
This is an excellent idea and we were planning to do that for early 3.4.

While this would help to address most of the ID "hell", there will remain cases that we cannot address it in the schemas, e.g. all those "magical" IDs that are declared in code such as menu IDs, etc. in the workbench.
Comment 2 Wassim Melhem CLA 2007-04-09 02:42:19 EDT
*** Bug 117130 has been marked as a duplicate of this bug. ***
Comment 3 Wassim Melhem CLA 2007-04-15 00:47:55 EDT
*** Bug 78483 has been marked as a duplicate of this bug. ***
Comment 4 Berthold Daum CLA 2007-04-15 16:24:00 EDT
Created attachment 63844 [details]
Schema definition for proposed extension point idFactory
Comment 5 Berthold Daum CLA 2007-04-15 16:25:45 EDT
(In reply to comment #1)
> This is an excellent idea and we were planning to do that for early 3.4.
> 
> While this would help to address most of the ID "hell", there will remain cases
> that we cannot address it in the schemas, e.g. all those "magical" IDs that are
> declared in code such as menu IDs, etc. in the workbench.
> 

For all those "magical"id parts contained in the Java code and manifest definitions, the construction of an ID factory could help. The following rather elaborate proposal shows how it could work.


Let's consider the construction of menu path. With an extension point org.eclipse.core.idFactory (schema is appended) we could define:

 <extension point="org.eclipse.core.idFactory">
   <idSet id="org.eclipse.ui.menuPath"
          name="Menu Path"
          separator="/">
      <manifest attributeName="path"
                elementPath="actionSet/menu"
                point="org.eclipse.ui.actionSets">
        <append attributeName="id" subpath=".">
          <append attributeName="name" subpath="separator"/>
          <append attributeName="name" subpath="groupMarker"/>
          <appendDefault value="additions"/>
        </append>
      </manifest>
      <java annotationType="MenuPath"/>
    </idSet>
  </extension>

The "java" subelement refers to an annotation type defined as

  public @interface MenuPath {
    public String value();
  }

When defining menus, for example in an ActionBarAdvisor, we could use this annotation type to add IDs to the above idSet:

@MenuPath(IWorkbenchActionConstants.M_HELP+"/"+IWorkbenchActionConstants.HELP_END)
protected void fillMenuBar(IMenuManager menuBar) {
  MenuManager helpMenu = new MenuManager("&Help", IWorkbenchActionConstants.M_HELP);
  menuBar.add(helpMenu);
  helpMenu.add(getAction(ActionFactory.HELP_CONTENTS.getId()));
  helpMenu.add(new Separator(IWorkbenchActionConstants.HELP_END));
  helpMenu.add(getAction(ActionFactory.ABOUT.getId()));
  ...
}

----------

Another example generating IDs used as "relative" ID in perspective extensions:


  <extension point="org.eclipse.core.idFactory"> 
    <idSet id="org.eclipse.ui.areaId" name="Area ID">
      <manifest attributeName="id"
                elementPath="view"
                point="org.eclipse.ui.views"/>
      <java annotationType="AreaID"/>
    </idSet>
  </extension>

The "java" subelement refers to an annotation type defined as

  public @interface AreaID {
    public String value();
  }

All we need here is to add an annotation of this type to IPageLayout

   public static String ID_EDITOR_AREA = "org.eclipse.ui.editorss"; //$NON-NLS-1$
   @AreaID(ID_EDITOR_AREA)

----------

How are those manufactured IDs used? Basically in the same way as all other IDs provided by the property "satisfiedBy". Using the notation org.eclipse.core.idFactory:xxxxxx where xxxxx is the ID of a specific idSet, we can refer to that specific idSet and propose its values whenever a ref-attribute is used. Therefore, the "Browse" button mentioned under (1c) would not only list those configuration elements that own an attribute "id" but also all declared idSets org.eclipse.core.idFactory:xxxxxx.

The Java part (collecting the IDs defined by the declared annotation types) would probably need some help from the JDT developers.



Comment 6 Wassim Melhem CLA 2007-04-15 22:55:05 EDT
Berthold, thanks for putting a lot of thought into this.

Using annotations in Java code may be problematic though, since this will require plug-ins using them to upgrade their Execution Environment to J2SE-1.5.

I am not sure what the decision on that will be for 3.4.

However, this should not stop us from pursuing the declarative portion in 3.4.
Comment 7 Berthold Daum CLA 2007-04-19 16:12:10 EDT
(In reply to comment #6)
> Berthold, thanks for putting a lot of thought into this.
Pure selfishness :)

> Using annotations in Java code may be problematic though, since this will
> require plug-ins using them to upgrade their Execution Environment to J2SE-1.5.
> 
> I am not sure what the decision on that will be for 3.4.
> 
> However, this should not stop us from pursuing the declarative portion in 3.4.
> 
By allowing for the definitions of literals in the idFactory extension point the Java part can be dropped altogether, e.g.

  <extension point="org.eclipse.core.idFactory"> 
    <idSet id="org.eclipse.ui.areaId" name="Area ID">
      <manifest attributeName="id"
                elementPath="view"
                point="org.eclipse.ui.views"/>
      <literal value="org.eclipse.ui.editorss"/>
    </idSet>
  </extension>
Comment 8 Berthold Daum CLA 2007-04-19 16:14:22 EDT
Created attachment 64350 [details]
Schema definition for proposed extension point idFactory
Comment 9 Paul Webster CLA 2007-09-28 14:29:44 EDT
(In reply to comment #1)
> While this would help to address most of the ID "hell", there will remain cases
> that we cannot address it in the schemas, e.g. all those "magical" IDs that are
> declared in code such as menu IDs, etc. in the workbench.

True, without changing code in the platform those IDs wouldn't show up.  In 3.4 we will hopefully be in a position to define some of the basic menu structure (file, edit, window, etc) in a declaration (which would make some of it available).

PW
Comment 10 Chris Aniszczyk CLA 2008-02-12 10:32:05 EST
*** Bug 218593 has been marked as a duplicate of this bug. ***
Comment 11 Paul Webster CLA 2008-02-12 20:44:17 EST
Created attachment 89585 [details]
ID Search attribute v01

This is a proof of concept patch (i.e bad constant names, no edge condition checking)

Just like a java class attribute, it depends on adding appInfo to a string attribute.  ex:
               <appInfo>
                  <meta.attribute kind="xml_path" basedOn="org.eclipse.ui.perspectives/perspective/@id"/>
               </appInfo>

This added to the targetID attribute of perspective elements in org.eclipse.ui.perspectives will list perpsective IDs when the Browse button is clicked.

For org.eclipse.ui.handlers - handler commandId attribute the basedOn string looks like "org.eclipse.ui.commands/command/@id"

This is the PDEEditor part of the story ... there's no schema editor support for adding this appInfo marker.

PW
Comment 12 Paul Webster CLA 2008-02-15 12:54:16 EST
Created attachment 89861 [details]
Schema examples v01

using the new attribute type in perspectiveExtensions - targetID and handlers - commandId

PW
Comment 13 Chris Aniszczyk CLA 2008-02-15 16:37:37 EST
investigating...
Comment 14 Remy Suen CLA 2008-02-15 17:11:02 EST
Created attachment 89892 [details]
ID Search attribute v02

This builds on top of Paul's patch by:
-making the 'Browse' button of the new IdAttributeRow be on the same line as the other widgets
-prevents NPEs if the xml_path that has been entered in the exsd is not correct

The openReference() method is still not implemented but it should ideally open the plugin.xml of the declaring plug-in of the id in question.
Comment 15 Chris Aniszczyk CLA 2008-02-17 13:49:55 EST
Created attachment 89945 [details]
org.eclipse.pde.patch

Here is an updated patch for you to play with Paul. The only thing you will have to change is updating your sample schemas to use "identifier" instead of "xml_path"

- This patches adds support for the notion of an 'identifier' throughout the schema models. 
- The schema editor has support in defining an 'identifier' via a filtered selection dialog
- The extension editor has support to browse these identifiers and jump to the defining plug-in

I will work on cleaning up the patch a bit more tomorrow so we can possibly have something ready for the next I-build. I'm also working on actually adding schema-model related tests to PDE.
Comment 16 Chris Aniszczyk CLA 2008-02-17 13:50:02 EST
Created attachment 89946 [details]
mylyn/context/zip
Comment 17 Paul Webster CLA 2008-02-17 15:54:32 EST
Created attachment 89948 [details]
Schema examples v02

First let me say this is awesome!

Updated the schema examples to work with Chris' latest patch.  commands, handlers, bindings, contexts, and perspectiveExtensions.

Very cool.

2 comments on the schema editor part:

The dependsOn field only seems to hold the last value filled in ... i.e. if I switch to a previous identifier field, it still shows the old value.  AFAICT the xml is correct, though.

The attribute search dialog won't let you keep typing to narrow it ... i.e. id (which is everything :-) - perspective

Thanx a lot Chris ... did I mention this is awesome?  Try and datafill a keybindging now :-)

PW
Comment 18 Chris Aniszczyk CLA 2008-02-18 16:25:19 EST
Created attachment 89999 [details]
org.eclipse.pde.patch

Ok, I think we're good for launch. I cleaned up the code, created an image for identifier attributes and added some validation to the mix.

I think we're at the stage where we can release this to the public for testing and stabilization. What do you say Paul, let's dance?
Comment 19 Chris Aniszczyk CLA 2008-02-18 16:25:22 EST
Created attachment 90000 [details]
mylyn/context/zip
Comment 20 Chris Aniszczyk CLA 2008-02-18 16:33:09 EST
Created attachment 90001 [details]
sample screenshot #1
Comment 21 Chris Aniszczyk CLA 2008-02-18 16:42:44 EST
Created attachment 90002 [details]
sample screenshot #2
Comment 22 Benjamin Cabé CLA 2008-02-18 16:47:01 EST
WOW !
This is *really* awesome :)
Comment 23 Chris Aniszczyk CLA 2008-02-18 18:25:44 EST
Created attachment 90010 [details]
org.eclipse.pde.patch

Paul, try out this patch. The new attribute type 'identifier' is also allowed to specify restrictions in combination with the reference path. So for example, you can update the perspectiveExtensions example with a restriction of "*" to include that as a valid identifier. Restrictions in combination with the reference path will be used to compute valid identifiers.
Comment 24 Chris Aniszczyk CLA 2008-02-18 18:28:48 EST
Paul, so something like:
<attribute name="targetID" type="string" use="required">
            <annotation>
               <documentation>
                  the unique identifier of the perspective (as specified in the registry) into which the contribution is made. If the value is set to &quot;*&quot; the extension is applied to all perspectives.
               </documentation>
               <appinfo>
                  <meta.attribute kind="identifier" basedOn="org.eclipse.ui.perspectives/perspective/@id"/>
               </appinfo>
            </annotation>
            <simpleType>
               <restriction base="string">
                  <enumeration value="*">
                  </enumeration>
               </restriction>
            </simpleType>
         </attribute>

This will cause "*" come up in the list also along with other valid identifiers.
Comment 25 Chris Aniszczyk CLA 2008-02-18 19:00:16 EST
Ok, this will go into the next I-build to gather feedback from the community.

> 20080218
Comment 26 Chris Aniszczyk CLA 2008-02-18 19:00:22 EST
Created attachment 90011 [details]
mylyn/context/zip
Comment 27 Paul Webster CLA 2008-02-18 20:03:46 EST
Created attachment 90013 [details]
Schema examples v03

Works with PDE HEAD, released to showcase the PDE feature >20080218
PW
Comment 28 Jan-Hendrik Diederich CLA 2008-02-22 03:48:03 EST
To the I-Build
I downloaded both: the Win32 and the Linux version, but both archives (zip and tar) seem to be broken. Can someone look at this?
Comment 29 Chris Aniszczyk CLA 2008-02-22 09:37:40 EST
I don't see any issues.
Comment 30 Chris Aniszczyk CLA 2008-03-28 11:40:28 EDT
verified in I20080327-2251