Feb 8, 2010

Eclipse Day in Bangalore - registrations open

Today the registrations open for Eclipse Day in Bangalore. The entry is *free*, but you have to register to get the ticket. The tickets are limited, so hurry up.

The deadline for talk submissions are fast approaching and you have only one week left. Again, hurry up :-)

We also have a calendar published in the wiki. You can subscribe to it in your calendar, so you won't miss any dates.

Jan 23, 2010

Launching www.eclipse-tips.com ...

Its due for a long time :-) Ever since I purchased this domain, I wanted to create a site as a resource for Eclipse Plug-in developers. With little bit of hacking over the two weekends, the website is up and running with bare minimum content. I'll be adding more content from this blog and elsewhere, meanwhile you can check out the layout and other stuff.




Coolest and most useful thing for the visitors would be Eclipse Search. Even though the results portion occupies a significant space in the prime area, I decided to have it because its very handy if you want to search for something. And the whole interface is very nice (courtesy: Google Ajax APIs) Whether you want to search for a particular class in the repository or search for an xml editor plugin or a blog entry about Tray Item, its available in  few clicks.

Every article has a pdf & print icon. So if you need an offline copy, its available. This was not possible earlier with this blog.

And last, but not the least, for international visitors, the translate option is available in the bottom bar. With just two clicks you can translate to a language of your choice - without reloading the page. Again, done thru Google Ajax APIs. (you got to love this web stuff - esp when you can implement a feature without writing a single line of code :-) )

Mail me/leave a comment if you have any comments/suggestions

Jan 19, 2010

Eclipse Day in Bangalore

About

Last year we had a successful Eclipse Demo Camp in Bangalore. In a post-event survey, many people said that they are willing to attend a full day event, and here we are.

Me and Ankur are planning for an Eclipse Day in Bangalore on April 9th. This year's theme would be "Eclipse Plug-in Development". It will be a full day event. Unlike the Demo Camp, there will be three types of talks (Long talk, Short talk and Lightning talk) and we have a committee (Ketan from ThoughtWorks, Anshu Jain from IBM & Madhu, an Independent Eclipse Consultant) to review the proposals. So you will get to attend only the best out of the proposals.

Want to attend?

Just like the Demo Camp, the entry is free. However you have to pre-register and the registrations open on Feb 1st. There are only 100 seats available, so you want to register as soon as its opens. Registrations can be done from here.

Interested in presenting?

Fill in this form and submit your proposals. The review team will get back to you.

Sponsoring:

Last but not least, sponsors. We are reaching out various companies for sponsorship. Your company can support the event by sponsoring it. It also had added advantage of:

* 5 reserved attendee seats
* One lightning talk
* Ads & stall space in the venue (banners and contact booth at sponsor's cost. We will help provide as much space possible.)
* Mention in various promotions on Eclipse websites as mentioned here.

Do contact me or Ankur if you have any questions.

Dec 21, 2009

Toggle Commands the toggle other contributions

Found this one on Phil's blog. Republishing it with his permission. Thanks Phil!

Introduction

This is a follow up to Commands Part 6: Toggle & Radio menu contributions of fellow blogger Prakash G.R.. He described how to use command toggle and radio states. Here I will show you how to drive other contributions in the Eclipse Workbench using a toggle command.

What we want to achieve

I needed to show another toolbar button when a certain toggle command was executed. Imagine something like "Show clock" that will show or hide a little clock in the worbench window status bar.
Such contribution can be easily added using a menuContribution for the trim area. First create a toolbar in the trim area and then contribute controls/commands to this toolbar also using the menuContribution extension point.
Since we want the clock contribution


<menucontribution locationuri="toolbar:mytoolbar">
<control class="test.ui.clocl.internal.ClockControlContribution" id="test.ui.clock">
<visiblewhen checkenabled="false">
  <with variable="activeWorkbenchWindow">
    <test args="test.ui.clock.ToggleCommand"
      forcepluginactivation="true"
      property="org.eclipse.core.commands.toggle"
      value="true"/>
  </with>
</visiblewhen>

</control>
</menucontribution>

That will create a toolbar contribution that is only visible when the test.ui.clock.ToggleCommand is in the "true" state, when its checked.

Lets define the command:
<command defaulthandler="org.eclipse.core.commands.extender.ToggleCommandHandler" id="test.ui.clock.ToggleCommand" name="Show clock">
<state
  class="org.eclipse.ui.handlers.RegistryToggleState:true"
  id="org.eclipse.ui.commands.toggleState">
</state>

</command>

How this command works and what the state is you have already read in Prakash's blog entry. The default handler for this command does a little more than the one in the latter mentioned blog entry. It is defined like this:

/**
* Generic command that toggles the executed command and re-evaluates property testers for the
* org.eclipse.core.commands.toggle property.
*
*/
public class ToggleCommandHandler extends AbstractHandler {

public Object execute(final ExecutionEvent event) throws ExecutionException {
  HandlerUtil.toggleCommandState(event.getCommand());
  final IWorkbenchWindow ww = HandlerUtil.getActiveWorkbenchWindowChecked(event);
  final IEvaluationService service = (IEvaluationService) ww.getService(IEvaluationService.class);
  if (service != null) {
    service.requestEvaluation("org.eclipse.core.commands.toggle");
  }
  return null;
}
}

How do toggle the visibility of the clock contribution


The connection between toggling the command and making the clock contribution visible is hidden in a property tester, that the clock contribution uses:

public class CommandsPropertyTester extends PropertyTester {
public static final String NAMESPACE = "org.eclipse.core.commands"; //$NON-NLS-1$
public static final String PROPERTY_BASE = NAMESPACE + '.';
public static final String TOGGLE_PROPERTY_NAME = "toggle"; //$NON-NLS-1$
public static final String TOGGLE_PROPERTY = PROPERTY_BASE + TOGGLE_PROPERTY_NAME;

public boolean test(final Object receiver, final String property, final Object[] args, final Object expectedValue) {
  if (receiver instanceof IServiceLocator && args.length == 1 && args[0] instanceof String) {
    final IServiceLocator locator = (IServiceLocator) receiver;
    if (TOGGLE_PROPERTY_NAME.equals(property)) {
      final String commandId = args[0].toString();
      final ICommandService commandService = (ICommandService)locator.getService(ICommandService.class);
      final Command command = commandService.getCommand(commandId);
      final State state = command.getState(RegistryToggleState.STATE_ID);
      if (state != null) {
        return state.getValue().equals(expectedValue);
      }
    }
  }
  return false;
}
}


It is defined in plugin.xml like this:
<propertytester
class="org.eclipse.core.commands.extender.internal.CommandsPropertyTester"
id="org.eclipse.core.expressions.testers.CommandsPropertyTester"
namespace="org.eclipse.core.commands"
properties="toggle"
type="org.eclipse.ui.services.IServiceLocator"/>

That means we define a new property for the namespace "org.eclipse.core.command" and the property is named "toggle". It will operate on IServiceLocator variables. Such variable that is an IServiceLocator is the "activeWorkbenchWindow" variable. Now you should understand the visibleWhen expression of the clock contribution. It should be only visible when the toggle for the clock toggle command is "true". The re-evaluation of the property testers is triggered by the generic ToggleCommand.


A little tip at the end

If you put the ToggleCommand and property tester in a seperate bundle for easier re-use in all your projects and other bundles make sure you either start the bundle at the beginning or set the "test" expressions "forcePluginActivation" to true to let the Eclipse expression framework activate the bundle for you. Otherwise the property tester is completly ignored and the clock would be always visible.

Bonus

Since the state of the toggle is preserved in an instance preference value the visibility of all associated contributions that use the property tester to check for the toggle state of the command.

Of course you can also reverse the test expression for your contributions if you have a toggle command that says something like "Hide clock".

Click here for the original entry.

Dec 2, 2009

Reload your plugins without restarting Eclipse

When you are developing Eclipse plugins, sometimes its annoying that the changes in the plugin.xml won't reflect immediately. You need to restart the target Eclipse to see the changes. This will be painful if you are playing with trial-n-error stuff like the menu urls. In this tip, I'll explain how to make Eclipse reread your plugin.xml without restarting the target.


  • Create a plugin, launch as an Eclipse Application (you don't even need to Debug, just Run would do)
  • Check the UI contributions of your plugin.
  • Make the desired change in your plugin.xml. Right now, I've changed a Command's name; added a Command contribution to an existing menu; added a new view and made changes to an existing perspective
  • In your target, open the Plug-ins Registry view and in the pull down menu, check the 'Show Advanced Operations'
  • Right click your plugin and select Disable.
  • Then right click again and select Enable.
  • Since you have made changes to the current perspective by adding a view, you would be greeted with this Dialog.
  • Say Yes. There you go. Now all the changes in the plugin.xml would reflect in the UI



While this may not be applicable for all the changes you make in plugin.xml, this should cover up for most the changes.

Nov 10, 2009

e4: First e4 RCP Application

The next big thing in Eclipse is Eclipse 4.0 dubbed as e4. It will be released in 2010. That doesn't mean that the 3.x stream will be deprecated or discontinued. The 3.x releases will go on for "few" years till everyone boards the 4.0. But clearly the future of Eclipse is e4 and its already here. I'll be writing a series of blog posts on e4 and this will be the first. You can follow this blog in RSS, or email or even in twitter. I'm still learning about e4, so feel free to correct me if you find any mistakes :-)

First set up your e4 Environment:

1) Download e4 1.0 M1
2) Click e4->Generate e4 Example Project



3) Right click e4-examples.psf and click 'Import Project Set'. This should import the contacts and the photo projects from the CVS to your workspace
4) Open the contacts.product file and click the "Launch an Eclipse Application" link in the Overview page
5) Thats it. You should be running the Contacts demo.

You can play around with the css theme or code and check out the effects. When you are done, lets start an app from the scratch. The first app will have nothing more than a view (something like the 'RCP Application with a View', created by PDE Wizard). Note: If you find it hard to work with e4, you can grab a latest 3.6 build and set the e4 as the target platform and proceed with the following steps)

Step 1:
Use the New Plug-in wizard and create a new plugin. (No RCP - just plain old plugin)

Step 2:
You don't need an Activator. In the Overview tab, remove the Activator class and also delete the Activator.java file from the sources.

Step 3:
The default dependencies of this would have o.e.core.runtime and o.e.ui. In e4, we still need the core.runtime in e4, but not the o.e.ui. Remove it. Now add the following dependencies:
  • org.eclipse.swt,
  • org.eclipse.jface,
  • org.eclipse.e4.ui.workbench
  • org.eclipse.e4.ui.workbench.swt
Step 4:
Lets create a view. Instead of o.e.ui.views, now we have to use org.eclipse.e4.workbench.parts extension (which should now serve both the editors and views). The extension point would look like

<extension point="org.eclipse.e4.workbench.parts">
      <part class="com.eclipse_tips.e4.firstapp.MyFirstView" />
</extension>

The implementation class would be:

public class MyFirstView {

 public MyFirstView(Composite parent){
    
  // this shouldn't be there ideally, investigating
  if(parent.getLayout() == null)
    parent.setLayout(new FillLayout());

  Composite composite = new Composite(parent, SWT.NONE);
  composite.setLayout(new FillLayout());
  
  Button button = new Button(composite, SWT.PUSH);
  button.setText("Hello World");
  button.addSelectionListener(new SelectionAdapter() {
   @Override
   public void widgetSelected(SelectionEvent e) {
    MessageDialog.openInformation(new Shell(), "e4", "Hello e4 World!");
   }
  });
 }

}

Yes, what you are seeing it correct. It doesn't implement the IWorkbenchView or extend ViewPart. Further more, it appears that I've done one of the top 10 mistakes by not having a default constructor. Don't worry, e4 is smart. When it instantiates an object like this thru reflection, it identifies the parameters for the constructor and will pass them from the context. If more than one constructor is present, it can even identify the right one to use (more on this later)

Step 5:
Now, we have the view, lets create an RCP product that will use this view. Fire up the New Wizard and create a Product Configuration file with the basic settings. In the Product Configuration editor, give it some name and click the New for the Product. Specify some id and select 'org.eclipse.e4.ui.workbench.swt.application' for Application.




Step 6:
Go back to your plugin.xml. You should see the newly created application there. Now lets create the missing link between the product and the view - the UI model. In a typical 3.x RCP, you would have specified an application that has a run method, an initial perspective id, the layout for that perspective, the views, menus, actions thru the ActionFactory constants etc. This whole setup would require a little bit of both java coding and plugin.xml configuration. In e4, you can specify the entire UI in a model. Thats the applicationXMI. It can get as complex as your UI can be, but the simplest one looks like this:

<?xml version="1.0" encoding="ASCII"?>
<application:MApplication xmi:version="2.0" 
 xmlns:xmi="http://www.omg.org/XMI" 
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
 xmlns:application="http://www.eclipse.org/ui/2008/Application">

  <windows name="Main Window" width="200" height="100">
 <children xsi:type="application:MContributedPart" 
  id="MyView" 
  iconURI="platform:/plugin/com.eclipse-tips.e4.firstApp/icons/sample.gif" 
  URI="platform:/plugin/com.eclipse-tips.e4.firstApp/com.eclipse_tips.e4.firstapp.MyFirstView"/>
  </windows>
</application:MApplication>

There is nothing much to explain. It has got nothing more than a window and a view in it. (no menus,no tool bars, no status lines and even no stacks to hold the view) Specify this file in the parameter of the product extension:

<extension
       id="rcpProduct"
       point="org.eclipse.core.runtime.products">
    <product
          application="org.eclipse.e4.ui.workbench.swt.application"
          name="My First e4 RCP">
       <property
             name="applicationXMI"
             value="com.eclipse-tips.e4.firstApp/App.xmi">
       </property>
    </product>
 </extension>


Step 7:
You are all set to go. Switch to the Dependencies tab of the Product Editor and add your plugin. Click 'Add Required plugins' and launch. The launch will fail, because we have not included few more plugins that are required, but not specified in the dependencies (from databinding beans to renderers will be missing) The simplest way to get thru the error, is to edit the launch configuration and launch with 'all workspace and enabled target plugins'.




Now launch again, voila - there comes your first e4 RCP!

So what has happened till now? With the product & launch configuration, we are basically running the org.eclipse.e4.ui.workbench.swt.application. The application looks for the model of the UI in the applicationXMI parameter. It creates the Workbench, and asks it to render the UI from that model. Recursively, an appropriate renderer for every element in the XMI file is found, and its asked to create the UI. Finally you get the app:

Nov 3, 2009

Eclipse Tips on Twitter !

Get (a different set of) Eclipse  Tips in twitter: @Eclipse_Tips. If you are still in the RSS reader era, get the feed here.

Oct 28, 2009

Associating a Command with a Job

Earlier we saw how to associate an Action with a Job. Now you can associate a Command. Its very similar - use the constant to set a property on the job:

ICommandService service = (ICommandService) serviceLocator.getService(ICommandService.class);
Command command = service.getCommand(commandId);
ParameterizedCommand parameterizedCommand = new ParameterizedCommand(command, null);
job.setProperty(IProgressConstants.COMMAND_PROPERTY, parameterizedCommand);

You have to specify either the ACTION_PROPERTY or COMMAND_PROPERTY, but not both. If you specify both, neither of them will get executed.

Note: You need a 3.6 M3 or a latest I-Build for this to work.

Sep 23, 2009

Eclipse Demo Camp, Bangalore

Its back :-)


We are planning to organize a Demo Camp sometime in November. Date, time and venue to be decided. Since IBM's Eclipse team has grown since last Demo Camp, this time, you get a very good opportunity to learn right from the source, on whats coming up. From p2 to b3 and e4 (Am I the only one who thinks that things can be named better?) we can give a good number of demos/presentations. But we don't want to make it as the Big Blue show, so we need few contributions from the community as well. We are glad that Madhu and Anil have already signed up with some topics. I would encourage you to add a demo on what you are working on. Even if not sign up as an attendee, its a nice chance to meet other Eclipse plug-in developers and see what they are building with Eclipse.


http://wiki.eclipse.org/Eclipse_DemoCamps_November_2009/Bangalore

Sep 22, 2009

Catching up with Milestones and I-Builds

Helios M2 is released. Now the biggest problem for the early adopters would be how to catch up with these milestones. Every time, you have to download the milestone build, and then update it with all your required plugins (svn, mylyn, etc). If you are on the I builds, then you have to do this on every week. If you feel that its a painful process, here is a tip.

The  p2 repos for Eclipse are not only for the stable releases, but also for the Milestones, I Builds and Nightly builds.

Milestones: http://download.eclipse.org/eclipse/updates/3.6milestones
I-Builds: http://download.eclipse.org/eclipse/updates/3.6-I-builds
Nightly Builds: http://download.eclipse.org/eclipse/updates/3.6-N-builds

The build schedule is available here.

Go to your Preferences and add the required repo in your Available Software Site preferences (and disable all others, it will be slow to update).




Also enable the automatic updates. You are done. Whenever there is a new Milestone (or an I-Build), then your Eclipse gets updated automatically to it and you don't have to worry about installing other required plug-ins.



Enjoy with the latest and greatest without any pains :-)

Followers

Disclaimer

Any opinion expressed here, in any other blogs, forums, websites, "Letters to the Editor" column in "The Hindu" daily, weekly magazine’s sudoku column, my daughter’s drawing book and scribbling on the toilet papers, are not necessary my employers opinion, but all my own :-P

Unless specified, all the content of this blog is made available under Eclipse Public License
 
Design by Wpthemedesigner. Converted To Blogger Template By Anshul .