Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[e4-dev] Injecting 3.x Views/Editors

After a brief conversation with Paul on IRC, I hacked together a solution for grabbing the WorkbenchContext in a 3.x application.  (See attached)

It is clearly a hack, would be better to use a lifecycle hook.  But this allowed me to create an injector for all of my 3.x editors and views.  Obviously there are things that cannot be injected even though it would be possible (like the composite), but I am able to inject things like properties.  While I haven't tested it, I have a feeling that it *could* be possible to inject methods like @Focus.  
(It also gives me all the goodies like Logger and NLS injected!)

I am building an application that uses a diagram editor from GMF, thus I have to use 3.x editors.  But with a little more finessing, I think this would be a good option for 3.x & 4.x interoperability in the compat layer.  I am just getting started on this application so maybe something like this already exists and I just missed it.  But I thought I would share...

(The source files are attached)
- I created an abstract class "InjectableExecutableExtensionFactory" that defines the base functionality
- From this I extend to a "BlockDiagramPartFactory" that is capable of supplying the specific contexts for injection and anything else
- Then whether old or new classes, just annotate them with  @Creatable and any @Inject's
- Lastly, when I create my view/editor extension point, invoke the extension factory.  The factory is capable of providing context for specific classes or passing them through with no added context.

<plugin>
   <extension
         point="org.eclipse.ui.editors">
      <editor
            class="braintrader.blockdiagram.ui.parts.BlockDiagramPartFactory:braintrader.blockdiagram.ui.blockdiagrameditor"
            default="false"
            id="braintrader.blockdiagram.ui.blockdiagrameditor"
            name="Block Diagram Editor">
      </editor>
   </extension>
   <extension
         point="org.eclipse.ui.views">
      <view
            class="braintrader.blockdiagram.ui.parts.BlockDiagramPartFactory:braintrader.blockdiagram.ui.view.blocklibrary"
            id="braintrader.blockdiagram.ui.view.blocklibrary"
            name="Block Library"
            restorable="true">
      </view>
   </extension>
</plugin>

Whether or not this is actually useful / beneficial, I don't know.  But this is going to be my approach for now, presuming I don't run into any major road blocks.


Take care,

JD

Attachment: ApplicationWorkbenchAdvisor.java
Description: Binary data

Attachment: BlockDiagramPartFactory.java
Description: Binary data

Attachment: InjectableExecutableExtensionFactory.java
Description: Binary data


Back to the top