Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Extension Points: "Second instance" not available
Extension Points: "Second instance" not available [message #764230] Sun, 11 December 2011 18:10 Go to next message
Matthias Becker is currently offline Matthias Becker
Messages: 29
Registered: July 2009
Junior Member
Hi

i have a problem with an extension point definition.

I defined an extension point which is used by two other plug ins (Developer: one extension "Workspace"; Administrator: two extensions "Users" and "User Groups"). Each PlugIn has its own extension handler that ensures by the means of an ID (extension.getSimpleIdentifier()) that only the correct extensions are processed. That works fine so far.
Unfortunatly the code below (registry.getConfigurationElementsFor(NavigationViewExtesionHandler.EXTENSION_POINT_ID) as well as extensionPoint.getExtensions() only works on "Workspace" and "Users". "User Groups" is not available in extensionPoint.getExtensions() and registry.getConfigurationElementsFor(NavigationViewExtesionHandler.EXTENSION_POINT_ID) contains "Users" two times.

What did i do wrong?

Below is the code:

Thanks
Matthias

Handler code:
    public NavigationViewExtesionHandler(final NavigationViewContentProvider contentProvider, final String id) {
        this.id = id;
        initializeExtensions();
    }

    private void initializeExtensions() {
        final IExtensionRegistry registry = RegistryFactory.getRegistry();
        final IExtensionPoint extensionPoint = registry.getExtensionPoint(NavigationViewExtesionHandler.EXTENSION_POINT_ID);
        tracker = new ExtensionTracker(registry);

        final IConfigurationElement[] configurationElementsFor = registry
                .getConfigurationElementsFor(NavigationViewExtesionHandler.EXTENSION_POINT_ID);
        for (final IConfigurationElement extension : configurationElementsFor) {
            final IExtension declaringExtension = extension.getDeclaringExtension();
            addExtension(tracker, declaringExtension);
            //returns "workspace", "users" and "users"
        }

        for (final IExtension extension : extensionPoint.getExtensions()) {
            addExtension(tracker, extension);
            //returns "workspace", "users"
        }

        tracker.registerHandler(this, ExtensionTracker.createExtensionPointFilter(extensionPoint));
    }

    /** {@inheritDoc} */
    @Override
    public void addExtension(final IExtensionTracker tracker, final IExtension extension) {
        if (id.equals(extension.getSimpleIdentifier())) {
            final IConfigurationElement configurationElement = extension.getConfigurationElements()[0];
            try {
                final Object createExecutableExtension = configurationElement.createExecutableExtension("class");
                System.out.println(createExecutableExtension);
            } catch (final CoreException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }


Extension Point definition:
<element name="extension">
 <complexType>
  <sequence>
   <element ref="RootElement" minOccurs="1" maxOccurs="unbounded"/>
  </sequence>
  <attribute name="point" type="string" use="required"/>
  <attribute name="id" type="string"/>
  <attribute name="name" type="string"/>
 </complexType>
</element>

<element name="RootElement">
 <complexType>
  <attribute name="ID" type="string" use="required"/>
  <attribute name="name" type="string" use="required"/>
  <attribute name="class" type="string" use="required">
   <annotation>
    <appinfo>
     <meta.attribute kind="java" basedOn=":navigationview.treeelements.IRootElemet"/>
    </appinfo>
   </annotation>
  </attribute>
  <attribute name="handler" type="string" use="required">
   <annotation>
    <appinfo>
     <meta.attribute kind="java"/>
    </appinfo>
   </annotation>
  </attribute>
  <attribute name="isVisible" type="boolean" use="default" value="true"/>
 </complexType>
</element>


In addition i have to PlugIns that use this extension point:
Developer:
<extension
  id="Developer"
  point="NavigationView.RootElements">
 <RootElement
   ID="Workspace"
   class="developerui.Workspace"
   handler="developerui.RootElement1"
   isVisible="true"
   name="Workspace">
 </RootElement>
</extension>

Administrator:
<extension 
  id="Administrator" 
  point="NavigationView.RootElements">
 <RootElement
  ID="Users"
  class="administrationui.treeelements.users.Users"
  handler="administrationui.RootElement2"
  isVisible="true"
  name="Users">
 </RootElement>
 <RootElement
  ID="UserGroups"
  class="administrationui.treeelements.usergroups.UserGroups"
  handler="administrationui.RootElement3"
  isVisible="true"
  name="UserGroups">
 </RootElement>
</extension>


Re: Extension Points: "Second instance" not available [message #764233 is a reply to message #764230] Sun, 11 December 2011 18:15 Go to previous message
Matthias Becker is currently offline Matthias Becker
Messages: 29
Registered: July 2009
Junior Member
Forget it... murphy presented himself to me again... my mistake jumped into my eyes right after i hit the "post" button...

That works:
    public void addExtension(final IExtensionTracker tracker, final IExtension extension) {
        if (id.equals(extension.getSimpleIdentifier())) {
            for (final IConfigurationElement configurationElement : extension.getConfigurationElements()) {
                try {
                    final Object createExecutableExtension = configurationElement.createExecutableExtension("class");
                    System.out.println(createExecutableExtension);
                } catch (final CoreException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        }
    }
Previous Topic:How to load a UI PlugIn by code without UI elements being already there
Next Topic:Getting active tableviewer in Handler
Goto Forum:
  


Current Time: Tue Sep 02 21:21:49 GMT 2014

Powered by FUDForum. Page generated in 0.12390 seconds