Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 209873 - [Workbench] [Incubator] Support dependency injection for contributed views, editors, etc
Summary: [Workbench] [Incubator] Support dependency injection for contributed views, e...
Status: CLOSED WONTFIX
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.4   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Platform UI Triaged CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
Depends on:
Blocks: 190918 200097
  Show dependency tree
 
Reported: 2007-11-14 17:08 EST by Boris Bokowski CLA
Modified: 2019-11-27 06:58 EST (History)
13 users (show)

See Also:


Attachments
experimental, work in progress (23.53 KB, patch)
2007-11-14 17:12 EST, Boris Bokowski CLA
no flags Details | Diff
plug-in with Javascript stuff (3.60 KB, application/octet-stream)
2007-11-14 23:04 EST, Boris Bokowski CLA
no flags Details
Updated plug-in for Javascript (4.53 KB, application/octet-stream)
2007-11-19 23:59 EST, Boris Bokowski CLA
no flags Details
updated patch, containing the dependency injection mechanism for views (22.07 KB, patch)
2007-11-22 12:26 EST, Boris Bokowski CLA
no flags Details | Diff
Same updated patch, with service factory (21.58 KB, patch)
2007-11-22 12:59 EST, Paul Webster CLA
no flags Details | Diff
made everything internal (22.32 KB, patch)
2007-11-22 17:04 EST, Boris Bokowski CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Boris Bokowski CLA 2007-11-14 17:08:57 EST
This was one of the best parts of the experimental component framework.
Comment 1 Boris Bokowski CLA 2007-11-14 17:12:12 EST
Created attachment 82919 [details]
experimental, work in progress

This was not hard at all.

You can contribute a view like this:
<extension
  point="org.eclipse.ui.views">
   <view
            class="org.eclipse.ui.services.CIFactory:org.eclipse.ui.examples.di.internal.SampleView"
            id="org.eclipse.ui.examples.di.view1"
            name="Dependency Injection">
   </view>
</extension>

("CIFactory" stands for constructor injection factory.)

public class SampleView {

	public SampleView(Composite parent) {
		Label label = new Label(parent, SWT.NONE);
		label.setText("Hello World");
		GridLayoutFactory.swtDefaults().generateLayout(parent);
	}
}
Comment 2 Boris Bokowski CLA 2007-11-14 17:24:07 EST
Tod, it should be fairly easy to create a variant of CIFactory for your Javascript experiments (at least if you use the syntax with colon for now). Something like:

<extension
  point="org.eclipse.ui.views">
   <view
           
class="org.eclipse.ui.services.JSFactory:/js/sample_view.js"
            id="org.eclipse.ui.examples.js.view1"
            name="Javascript Example">
   </view>
</extension>

sample_view.js:

{
  argumentTypes : [ "org.eclipse.swt.widgets.Composite",
                    "org.eclipse.ui.helpers.SWTFactory"],
  construct: function (composite, factory) {
    composite.setLayout(factory.createFillLayout());
    var label = factory.createLabel(composite, 0);
    label.setText("Hello World");
  }
}

Eval'ing this piece of Javascript should return a Javascript object from which you can get the array of argument types and the function to call.
Comment 3 Paul Webster CLA 2007-11-14 20:00:09 EST
(In reply to comment #1)
> Created an attachment (id=82919) [details]
> experimental, work in progress

DIViewPart I think needs this line in createPartControl:
implementation = factory.createObject(delegatingLocator);

PW
Comment 4 Boris Bokowski CLA 2007-11-14 20:45:13 EST
(In reply to comment #3)
> DIViewPart I think needs this line in createPartControl:
> implementation = factory.createObject(delegatingLocator);

Good catch!
Comment 5 Boris Bokowski CLA 2007-11-14 23:04:49 EST
Created attachment 82935 [details]
plug-in with Javascript stuff

This is a plug-in with a JavascriptFactory and a simple hello world view implemented in Javascript. I just couldn't resist... :-)

I tried to get rid of SWTFactory but ran into ClassLoader issues. This is what I would like the Javascript to look like:

importPackage(org.eclipse.swt);
importPackage(org.eclipse.swt.widgets);
importPackage(org.eclipse.swt.layout);

var argumentTypes = [ "org.eclipse.swt.widgets.Composite" ];
                   
function construct (composite) {
   composite.setLayout(new FillLayout());
   var label = new Label(composite, SWT.NONE);
   label.setText("Hello World");
}

It currently looks like this:

var argumentTypes = [ "org.eclipse.swt.widgets.Composite",
                   "org.eclipse.ui.js.SWTFactory"];
                   
function construct (composite, factory) {
   composite.setLayout(factory.createFillLayout());
   var label = factory.createLabel(composite, 0);
   label.setText("Hello World");
}
Comment 6 Boris Bokowski CLA 2007-11-14 23:06:53 EST
See also http://www.mozilla.org/rhino/ScriptingJava.html
Comment 7 Boris Bokowski CLA 2007-11-15 10:02:55 EST
just a test, please ignore
Comment 8 Boris Bokowski CLA 2007-11-19 23:47:21 EST
It is working, including callbacks and all!

importPackage(Packages.org.eclipse.swt);
importPackage(Packages.org.eclipse.swt.widgets);
importPackage(Packages.org.eclipse.swt.layout);

var argumentTypes = [ "org.eclipse.swt.widgets.Composite" ];
                   
function construct (composite) {
   composite.setLayout(new FillLayout());
   var label = new Label(composite, SWT.NONE);
   label.setText("Hello World");
   var button = new Button(composite, SWT.PUSH);
   button.setText("Push me");
   button.addListener(SWT.Selection, function(){ label.setText("pushed"); });
}
Comment 9 Boris Bokowski CLA 2007-11-19 23:59:32 EST
Created attachment 83300 [details]
Updated plug-in for Javascript

To try it yourself, you need the patch and this plug-in (contains the example view written in Javascript).
Comment 10 Boris Bokowski CLA 2007-11-22 12:26:01 EST
Created attachment 83549 [details]
updated patch, containing the dependency injection mechanism for views
Comment 11 Paul Webster CLA 2007-11-22 12:59:15 EST
Created attachment 83554 [details]
Same updated patch, with service factory

This is the same updated patch, just replacing the delegating service locator with  IServiceLocatorCreator and AbstractServiceFactory.

The js view still shows up :-)

PW
Comment 12 Boris Bokowski CLA 2007-11-22 17:04:44 EST
Created attachment 83588 [details]
made everything internal

When we introduce this, we should refactor our existing API to simplify the programming model as much as we can. I will put the interesting pieces of this in the incubator (and only leave some hooks in the main codebase).
Comment 13 Boris Bokowski CLA 2007-11-28 16:54:12 EST
I've released this as a tweaklet together with two example plug-ins in the incubator. I've put the necessary tweaklet hooks for views and editors into the main codebase.
Comment 14 Boris Bokowski CLA 2007-11-28 16:58:37 EST
The plug-ins are called:

org.eclipse.ui.tweaklets.dependencyinjection
org.eclipse.ui.examples.di
org.eclipse.ui.examples.di.js

They are available from /cvsroot/eclipse/platform-incubator/ui/tweaklets and .../examples.
Comment 15 Dani Megert CLA 2013-06-05 10:41:59 EDT
Removing outdated target milestone.
Comment 16 Lars Vogel CLA 2019-11-27 06:58:25 EST
This bug hasn't had any activity in quite some time. Maybe the problem got
resolved, was a duplicate of something else, or became less pressing for some
reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it.
The information can be, for example, that the problem still occurs, that you
still want the feature, that more information is needed, or that the bug is
(for whatever reason) no longer relevant.

If the bug is still relevant, please remove the stalebug whiteboard tag.