Monday, December 24, 2012

Practices for Eclipse 4 Programming Model

For "Eclipse 4 programming model"[1], I mean the way of how to program with the Eclipse 4.x platform, not the "Eclipse 4 application model"[2] itself, although they definitely have some close relations.

There are several tutorials[3] for the Eclipse 4 techologies. Here, I share some of practices in my last weekend theme plugin project[4] for making your projects more happy in Eclipse 4 platform. They may not be the best practices although I hope them are. So it is welcome to add criticisms and suggestions here:)

The biggest advantages of Eclipse 4 programming model, IMHO, is that:
  • Dependency injection has been introduced;
We have had the Guice[5] from crazy Bob[6] for a long time. We found it is bettter to be adopted for container/framework-provided behaviors. This has been widely used in Java EE 6+ world. And now it comes to Eclipse planet!
  • Many services have been extracted and become standard;
This is a absolute overhaul for Eclipse platform. This makes the consuming to Eclipse platform become much simple and relaxed.

Let me summarize somethings for you:

1. Consume the services by dependency injection way as possible.

For a self-explained instance,
Loading ....
Here, I get the IEclipsePreferences service.

Another way is to use the programatic API call. As you known, the service is verbose to use it correctly. The DI way makes your life easier!
[caveats/bugs]
Note, there are some caveats described here[9]. If you have problems in DI, please report it to Eclipse[10] and this helps Eclipse 4 to faster growth.

2. Consume plaform services as possible.

There are many very important services have been abstracted as the services of platform.
Loading ....
In this sinppet, Eclipse will provide four services for us. For example, the event service is powerful for general use. It, in fact, provides a mechanism for hooking/intercepting into the whole platform.
Loading ....
Here, I observe the theme change event for hooking editor-scoped preferences customization.

More detailed services could be seen in [7] and [8].
[caveats/bugs]
In my experiences with the event service, there is a bug for @EventTopic injection now, which, I found, has been discussed here[12]. That is, if you work under the Eclipse IDE environment, then the @EventTopic annotated method parameter will be injected with an org.eclipse.equinox.console.command.adapter.CommandProviderAdapter object. My workaround, shown above, is to use the event handler explicitly. But seemly you can use @Optional annotation with combination of @Inject as metioned in that discussion[12], although it is an e4 specific annontation and the semantics of it is not for the workaround obviously. However, finally, I prefer @EventTopic way in that reason shown in the following #3.

3. Injection to your objects in a full managed way is simple.

The truth here is, Eclipse 4 DI does not come into your world automatically. Then, how to link the Eclipse world with your business?
One workable way is to use IEclipseContext to bind you model. IEclipseContext is hierarchical. There are several kinds of IEclipseContext. Do not mess you up with the hierarchy! You can consult one Jonas's tutorial [11] for getting more basic infos. If you construct an RCP, then you may like to use this way.
For IDE managed enirvoment, like an Eclipse plugin, I recommend you to use the model processor extension as your entry point to the Eclipse 4 DI world.
Loading ....

You can extend the extension point org.eclipse.e4.workbench.model to enable it, like this:
Loading ....
It extension point is for the application model, in fact, as the document. But I think, it is simple and nice to use it with you business objects before we have a general DI hooking point if you want to forget the programatic injection.
[caveats/bugs]
Do not assume that a platform UI side services or objects could be injected and used here. For instance, you can not inject the IThemeEngine service in the model processor(IThemeEngine service is prepared after the processing of model). I guess it is intentional. There are still two ways for  this:
  • use the EventHandler to watch the UI side topic exactly.
  • use application model to bridge to your UI related POJOs. You can inject kinds of services here. This is just the way the e4 bundles selfs do their works.

4. Eclipse 4 Tooling is your friend.

It is not easy to consume the Eclipse 4 technologies now. There is a tooling project[13] come to help you: it includes the CSS Spy, CSS editor, application model editor and live editor.
For example, there are two ways to contribute/extend the application model:
  • one is to change the model pragramatically(this is my favorite way).
  • another is to use e4xmi model file. For this way, an application model editor is expected to have. Lars has provide the step-by-step guide[16].
[caveats/bugs]
The emf live editor is a little out-of-date in the weekend. I think it will be fixed soon. If you meet error log shows that one shell can not be found and injected. You can pull the source from[13] and annonated IServiceConstants.ACTIVE_SELECTION) to it. This is an intentional change documented in the[9].

As my evaluation to the Eclipse 4.3 nightly, it is good to consume now!
And we have got famous perfermance bugs fixed[14].
And I find the quick fixing for plugins is more intellisense[15].
And GTK3 is out for linux fans' testing(But it has an obvious bug now. So, I suggest you wait one or two milestone to test)[15].

As a plaform, Eclipse 4 has many many advantages to IDEA 12, IMHO. Do not hesitate to migrate to Eclipse 4! Help us to evolve!


References:
[1] http://www.eclipse.org/eclipse4/
[2] http://eclipsesource.com/blogs/2012/05/10/eclipse-4-final-sprint-part-1-the-e4-application-model/
[3] http://wiki.eclipse.org/Eclipse4/Tutorials
[4] https://github.com/jinmingjian/eclipse.themes.darker
[5] http://code.google.com/p/google-guice/
[6] http://blog.crazybob.org/
[7] http://wiki.eclipse.org/E4/Contexts
[8] http://wiki.eclipse.org/E4/EAS
[9] http://wiki.eclipse.org/Eclipse4/RCP/Dependency_Injection
[10] https://bugs.eclipse.org/bugs/
[11] http://eclipsesource.com/blogs/tutorials/eclipse-4-e4-tutorial-part-4-dependency-injection-basics/
[12] http://www.eclipse.org/forums/index.php/t/351144/
[13] http://git.eclipse.org/c/e4/org.eclipse.e4.tools.git/
[14] http://wiki.eclipse.org/Platform_UI/Juno_Performance_Investigation
[15] http://download.eclipse.org/eclipse/downloads/drops4/S-4.3M4-201212140730/news/
[16] http://www.vogella.com/articles/EclipseRCP/article.html

3 comments:

nazia shah said...

great and nice sharing jin mingjian about programing model MODELS AND MODEL RELATIONSHIPS have the key role in programing model.
Mobile news

Otr 214423 said...

VIRUS REMOVAL

Is Your Computer Sluggish or Plagued With a Virus? – If So you Need Online Tech Repairs
As a leader in online computer repair, Online Tech Repairs Inc has the experience to deliver professional system optimization and virus removal.Headquartered in Great Neck, New York our certified technicians have been providing online computer repair and virus removal for customers around the world since 2004.
Our three step system is easy to use; and provides you a safe, unobtrusive, and cost effective alternative to your computer service needs. By using state-of-the-art technology our computer experts can diagnose, and repair your computer system through the internet, no matter where you are.
Our technician will guide you through the installation of Online Tech Repair Inc secure software. This software allows your dedicated computer expert to see and operate your computer just as if he was in the room with you. That means you don't have to unplug everything and bring it to our shop, or have a stranger tramping through your home.
From our remote location the Online Tech Repairs.com expert can handle any computer issue you want addressed, like:
• - System Optimization
• - How it works Software Installations or Upgrades
• - How it works Virus Removal
• - How it works Home Network Set-ups
Just to name a few.
If you are unsure of what the problem may be, that is okay. We can run a complete diagnostic on your system and fix the problems we encounter. When we are done our software is removed; leaving you with a safe, secure and properly functioning system. The whole process usually takes less than an hour. You probably couldn't even get your computer to your local repair shop that fast!
Call us now for a FREE COMPUTER DIAGONISTIC using DISCOUNT CODE (otr214423@gmail.com) on +1-914-613-3786 or chat with us on www.onlinetechrepairs.com.

Otr 214423 said...


Problem: HP Printer not connecting to my laptop.

I had an issue while connecting my 2 year old HP printer to my brother's laptop that I had borrowed for starting my own business. I used a quick google search to fix the problem but that did not help me.

I then decided to get professional help to solve my problem. After having received many quotations from various companies, i decided to go ahead with Online Tech Repair (www.onlinetechrepairs.com).

Reasons I chose them over the others:
1) They were extremely friendly and patient with me during my initial discussions and responded promptly to my request.
2) Their prices were extremely reasonable.
3) They were ready and willing to walk me through the entire process step by step and were on call with me till i got it fixed.

How did they do it
1) They first asked me to state my problem clearly and asked me a few questions. This was done to detect any physical connectivity issues with the printer.
2) After having answered this, they confirmed that the printer and the laptop were functioning correctly.
3) They then, asked me if they could access my laptop remotely to troubleshoot the problem and fix it. I agreed.
4) One of the tech support executives accessed my laptop and started troubleshooting.
5) I sat back and watched as the tech support executive was navigating my laptop to spot the issue. The issue was fixed.
6) I was told that it was due to an older version of the driver that had been installed.

My Experience
I loved the entire friendly conversation that took place with them. They understood my needs clearly and acted upon the solution immediately. Being a technical noob, i sometimes find it difficult to communicate with tech support teams. It was a very different experience with the guys at Online Tech Repairs. You can check out their website www.onlinetechrepairs.com or call them on 1-914-613-3786.
Would definitely recommend this service to anyone who needs help fixing their computers.
Thanks a ton guys. Great Job....!!