Everyone who's used any MS office application would have come across this annoying yet sometimes useful Office assistant. He's there to "point" us in the right direction to do something. If we've got questions (as silly as how to wrap text) he may have the "answers".
I was wondering ... RCP has a very nice help system in the form of cheatsheets, balloon help, context based help, status bar messages, etc... which will prompt the user for action/attention as required. But the help system doesn't have something like a help assistant - similar to the ones in MS Office applications. Eclipse RCP as an application is used in a variety of domains (hell even Swiss Railway people use it!) we get users who aren't aware as much and aren't willing to experiment or search to find out. I'll share some inputs I got from users who don't know much the Eclipse UI way. There are a some of them who say "How do I know that i have to right-click on the wizard to get a context-menu full of options ?" We can provide a message in the wizard page ... but that may be hard to notice.
I feel RCP help assistant widget is a better HMI mechanism than the usual status bar messages. May be the widget can be a very low on graphics, animation and high on usefulness. This is just an idea ... I thought I'll share.
Monday, May 4, 2009
Monday, February 23, 2009
PgUp and PgDwn through Editors
Today started off pretty good. My favorite music-director (composer) A R Rahman won the Best Original Score Oscar for the movie Slumdog Millionaire ... and i got a "Welcome to the Planet" mail from Planeteclipse.org
This motivated me to write something on this day ... just to keep a note. Being true to my blog's "tweakeclipse" self ... I want to tell you about a nice to have and lesser known (as far as i know) navigation feature in Eclipse Editors. You can use Ctrl + PgUp and Ctrl + PgDwn to move across the open editors! This is one more shortcut amongst many as listed in this blog entry by Nirav Thaker. One of my guru's says that this shortcut is inspired from MS Excel.
Hope this helps!
This motivated me to write something on this day ... just to keep a note. Being true to my blog's "tweakeclipse" self ... I want to tell you about a nice to have and lesser known (as far as i know) navigation feature in Eclipse Editors. You can use Ctrl + PgUp and Ctrl + PgDwn to move across the open editors! This is one more shortcut amongst many as listed in this blog entry by Nirav Thaker. One of my guru's says that this shortcut is inspired from MS Excel.
Hope this helps!
Monday, February 16, 2009
Create Maps in EMF - the other way
EMF wiki on Eclipsepedia has a post which shows you one method of creating maps in EMF.
I feel that the suggested method in wiki will not exactly allow you to access a map as it should be.
like say - myMap.put("key", value); Instead you'll have to do:
myMap.eSet(keyFeature, "key");
myMap.eSet(valueFeature, valueObj);
After some trails here's the second method summarized in terms of steps.
To create a map using Reflective Ecore Editor:
here is a snap shot of how a map looks in the Ecore Editor.

what happens behind the scenes of the editor ?
well, these lines of code are executed.
EAttribute _map = EcoreFactory.eINSTANCE.createEAttribute();
_map.setName("_map");
EGenericType _mapType = EcoreFactory. eINSTANCE.createEGenericType();
_mapType.setEClassifier(EcorePackage. eINSTANCE.getEMap());
// set key
EGenericType key = EcoreFactory. eINSTANCE.createEGenericType();
key.setEClassifier(EcorePackage. eINSTANCE.getEString());
// set key
EGenericType value = EcoreFactory. eINSTANCE.createEGenericType();
value.setEClassifier(EcorePackage. eINSTANCE.getEObject());
// add them
_mapType.getETypeArguments().add(key);
_mapType.getETypeArguments().add(value);
_map.setEGenericType(_mapType);
You have to use it like this:
Map _map = (Map) instance
.eGet(_mapFeature); // this is now java.util.Map
// don't forget to set the changes on _map back to instance!
Happy mapping!
I feel that the suggested method in wiki will not exactly allow you to access a map as it should be.
like say - myMap.put("key", value); Instead you'll have to do:
myMap.eSet(keyFeature, "key");
myMap.eSet(valueFeature, valueObj);
After some trails here's the second method summarized in terms of steps.
To create a map using Reflective Ecore Editor:
- create an EAttribute and set a name (let's say _map) to it.
- set _map's EType as EMap
[java.util.Map] create an ETypedParameterfor key and set ETypeaccordingly crate another ETypedParameterfor value and set ETypeaccordingly.
well, these lines of code are executed.
EAttribute _map = EcoreFactory.eINSTANCE.createEAttribute();
_map.setName("_map");
EGenericType _mapType = EcoreFactory.
_mapType.setEClassifier(EcorePackage.
// set key
EGenericType key = EcoreFactory.
key.setEClassifier(EcorePackage.
// set key
EGenericType value = EcoreFactory.
value.setEClassifier(EcorePackage.
// add them
_mapType.getETypeArguments().add(key);
_mapType.getETypeArguments().add(value);
_map.setEGenericType(_mapType);
You have to use it like this:
Map
.eGet(_mapFeature); // this is now java.util.Map
// don't forget to set the changes on _map back to instance!
Happy mapping!
Tuesday, February 10, 2009
Add branding to the XML files you generate from your EMF model
What if you want to suggest that an XML file is generated using your product?
If you look at some of these commercial tools they add a comment which proudly says "used XXX v a.b.c to generate this file." Just out of curiosity I wanted to do the same using EMF resource save api.
Guess what! It is possible to do such a thing with EMF resource api. There's this interface called ResourceHandler inside org.eclipse.emf.ecore.xmi.XMLResource.java which can be implemented as required. I have provided an example for your benifit.
public class MyResourceHandler implements ResourceHandler {
/*
* you have the file handle of the XML!
*/
public void postSave(XMLResource resource, OutputStream outputStream,
Map options) {
// append your comment here.
byte[] trailcomment = "some comment"; // enclose it in XML comment tags.
try {
outputStream.write(trailComment);
}
catch (IOException e) {
// may be log something here.
}
// do NOT close the stream here. EMF resource save will eventually do it for you.
}
}
You can find the link to the EMF newsgroup thread here.
If you look at some of these commercial tools they add a comment which proudly says "used XXX v a.b.c to generate this file." Just out of curiosity I wanted to do the same using EMF resource save api.
Guess what! It is possible to do such a thing with EMF resource api. There's this interface called ResourceHandler inside org.eclipse.emf.ecore.xmi.XMLResource.java which can be implemented as required. I have provided an example for your benifit.
public class MyResourceHandler implements ResourceHandler {
/*
* you have the file handle of the XML!
*/
public void postSave(XMLResource resource, OutputStream outputStream,
Map options) {
// append your comment here.
byte[] trailcomment = "some comment"; // enclose it in XML comment tags.
try {
outputStream.write(trailComment);
}
catch (IOException e) {
// may be log something here.
}
// do NOT close the stream here. EMF resource save will eventually do it for you.
}
}
You can find the link to the EMF newsgroup thread here.
Monday, January 5, 2009
The Unbearable Stupidity of Modeling - a talk by Ed Merks
"Unbearable stupidity of Modeling" is the name of a 50 minute long tech talk to be given by Ed Merks himself at EclipseCon 2009. Choosing such a title is a very good example of Reverse Engineering ... that is ... accept the mis-conception before disproving it! In this case it may be an attempt to clear out some of the so-called disadvantages or problems with using EMF.
I was just browsing around on some of the talks in the EclipseCon website and I found this. The heading of Ed's talk makes a bold statement, and so does almost all of the content in the abstract. If a guy who is using EMF in his projects/requirements reads through the abstract will be taken slightly aback by the tone except for one last line which changes the tone completely. Nice trick to make people read on ;)
I so want to listen to Ed speak about this topic ... given the different nature of the abstract itself the whole topic ... i think will be an eye opener for many of us. People who have an oppurtunity to attend EclipseCon ... don't miss this talk! You can find the abstract here.
Can't wait for the content of the talk to come out ... coz I cannot make it to EclipseCon (the reason is simply complicated ;)
I was just browsing around on some of the talks in the EclipseCon website and I found this. The heading of Ed's talk makes a bold statement, and so does almost all of the content in the abstract. If a guy who is using EMF in his projects/requirements reads through the abstract will be taken slightly aback by the tone except for one last line which changes the tone completely. Nice trick to make people read on ;)
I so want to listen to Ed speak about this topic ... given the different nature of the abstract itself the whole topic ... i think will be an eye opener for many of us. People who have an oppurtunity to attend EclipseCon ... don't miss this talk! You can find the abstract here.
Can't wait for the content of the talk to come out ... coz I cannot make it to EclipseCon (the reason is simply complicated ;)
Sunday, October 19, 2008
Manage Extension Locations in Eclipse Ganymede
An Eclipse developer is very quick to spot the very visible difference in the new Ganymede release. We are used to download an IDE and customize the configuration using the Help -> Software Updates -> Manage Configuration. Guess what! there is no more a Manage Configuration option anymore in Ganymede. Instead its called Software Updates for Installed Software and Available Software.
It looks kinda complicated at first, let's see how do u Manage Configuration in Eclipse Ganymede. This article gives a clear picture.
Saturday, October 18, 2008
Save an EMF Resource with or without namespace!
We tried out this one somewhere in 2007, but i suddenly felt the need to write about it now( i dono, funny like that!). Well coming to the point... serializing an EMF Resource to an XML file actually seems strange but sometimes it becomes necessary. I'll not get into the details of why do we need an XML file with no namespace! and just tell you how to do it.
When an XML file is parsed using Resource API, for every XML element a corresponding model element is searched from an EPackage instance. This EPacakge instance is normally registered to an namespace URI. For eg. <myns:SHIPORDER> XML element may map to an EClass ShipOrder in the model and myns URI is registered to an instance of ShipOrderPackage. So when the SHIPORDER XML element is encountered Resource API understands that an object of type StudentType is to be created.
Now, what if the XML element has no namespace... it'll look like this: . If we want to continue the usual way, then we have to do:
- Register the EPackage instance to an empty namespace URI.
- extend the XMLHelperImpl class and override getQName(EPackage, String, boolean) method
- bind this XMLHelper implementation to your model's generated XyzResouceImpl through createXMLHelper() method.
/**
* let's save without namespace!
* just delegate to appropriate Resouce API
*
*/
public class ShipOrderXMLHelper extends XMLHelperImpl {
protected String getQName(EPackage package1, String name,
boolean mustHavePrefix)
{
if( isNameSpaceNeeded() ) {
// let's send what ever prefix that's got as the arguement
return super.getQName(package1, name, true);
}
else {
// i don't want a namespace prefix
return super.getQName(package1, name, false);
}
return "";
}
}
Now that we have our implementation of XMLHelper, let's bind it to the generated ShipOrderResource implementation.
/**
*
* The Resource associated with the package.
*
* @see org.example.shiporder.util.ShiporderResourceFactoryImpl
* @generated
*/
public class ShiporderResourceImpl extends XMLResourceImpl {
/* (non-Javadoc)
* @see org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl#createXMLHelper()
* an override to bind our helper implementation
*/
protected XMLHelper createXMLHelper() {
return new ShipOrderXMLHelper();
}
// other generated ShipOrderResouceImpl methods follow.
} //ShiporderResourceImpl
That's it you are all set to serialize an EMF resource without namespace. Before you go for a coffee ... one last thing ... do not forget to create ur EMF resource from the generated XyzResourceFactory.
Labels:
EMF Resource,
save,
serialize,
without namespace,
XMLHelper
Subscribe to:
Posts (Atom)