Tuesday, November 4, 2008

Use of perspective extensions

Recently i came across this extension.Say u want to add an actionset/wizard shortcut or anything to an existing perspective without modifying the perspecive class , u can make use of this perspective extension...Will be very useful when u want to add ur custom actionsets/wizardshortcuts to standard perspectives like Java perspective..
Follow this link to learn perspective extensions.


Monday, September 8, 2008

Problems with enabling/disabling a button ???

I had big problem in solving problem with enabling/disabling a SWT button.my sample code is as follows:

checkButton = new Button(composite,SWT.NONE);
checkButton .addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
IStructuredSelection selection = (IStructuredSelection) tableViewer.getSelection();

To my surprise , when it enters else condition ,its disabling the button forever!!!i mean once its disabled..even if i select anything in viewer , button is not enabled.
I broke my head to solve this..did hours of googling and finally asked one of my genious team mate and he told me that i should be doing enabling/disabling of a widget in the viewers selection changed listener event..I tried that and to my surprise it worked..
below is the sample code

checkButton = new Button(composite,SWT.NONE);
checkButton .addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
IStructuredSelection selection = (IStructuredSelection) tableViewer.getSelection();
// do nothing

tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent event) {
IStructuredSelection selection = (IStructuredSelection) tableViewer.getSelection();

Monday, August 25, 2008

Use of Progress View

When ever i update my code from repository , eclipse shows update status at the bottom right corner ...many times i was nt really sure whether its getting hanged or progressing...so wanted to find a way to see the progress of update task...In the list of views given by eclipse i observed progress view and when i opened it , its showing the progress of updates..then i realized i never used this view before...
If u want to see progress of any task eclipse is doing say updates, synchronizing or anything...u can see progress in this view...

Thursday, August 7, 2008

Ever dreamt of opening Views, Perspectives, Commands, etc. - by just typing their name

What i usually do to open any view or perspective or some other is like to go through steps Window/ShowView/MyView , just now realized that i wasted lot of time...Came to know from my lead that using Ctrl+3 keyboard Shortcut we can open them with out above steps..It seems this feature is introduced in Eclipse 3.3 M7 ...Make use of it...

The source link http://eclipsenuggets.blogspot.com/2007/05/quick-access-ctrl3-is-bliss-are-you-one.html

Monday, July 14, 2008

Automation of project and package creation in Ganemede!!!

I was going through eclipse blogs after a long time..Came to know from one such posts there, that Ganemede has a cool feature..Just copy few lines of code say this
Now go to package explorer view and paste , making sure that none of the projects are selected...
then u can see that project wud be created and ur code will be in a class with a main method enclosed which is ready to run...

Thursday, June 26, 2008

Examples on demand

I was going through MyEclipse article articles and found the concept of Examples on demand...We just have to click example and it gets checkedout into our workspace and surprisingly with all configurations...
see this


Wednesday, May 28, 2008

Adding action sets and wizards to perspective

Recently I had a requirement to add launch configuration to our custom perspective. Before looking into perspective source codes thats already there, i tried googling ...din get anything...then later I happened to see source code of Java Perspective and found out that we can add wizards,view shortcuts and action sets to our perspective like below:

// snippet code from JavaPerspectiveFactory class
public void createInitialLayout(IPageLayout layout) {

layout.addActionSet(IDebugUIConstants.LAUNCH_ACTION_SET); // line no A

layout.addNewWizardShortcut("org.eclipse.jdt.ui.wizards.JavaProjectWizard"); //$NON-NLS-1$
layout.addNewWizardShortcut("org.eclipse.jdt.ui.wizards.NewPackageCreationWizard"); //$NON-NLS-1$
layout.addNewWizardShortcut("org.eclipse.jdt.ui.wizards.NewClassCreationWizard"); //$NON-NLS-1$


Since my interest was to add launch configuration , I made use of line no A in my custom perspective and it served my purpose...

Monday, May 19, 2008

Converting File to a corresponding IFIle

If you File refers to a file in your workspace, then yes you can convert it
to an IFile.
java.io.File file = ...;
Path path = new Path(file.getAbsolutePath());
IFile f = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(path);

If it's not in the workspace, there is no corresponding IFile so you cannot

Thursday, May 15, 2008

Removing an EMF object from an EMF generated model

The toughest part so far i have worked with is removing an EMF object.
I have an EMF generated model and I want to remove an element(object) from the model.
To my surprise all the methods in EObject are returning read only properties and when i try to remove an element from an Eobjects object, in runtime iam getting UNSUPPORTEDTYPEEXCEPTION which is trivial coz all the methods are returning read only elements/lists....
Then I did a sample test... i want to remove "emfObjectToBeRemoved" from "emfParentObject".

EList originalList = emfParentObject.eContents(); // returns a readonly list
List duplicateList = new ArrayList();
duplciateList.addAll(originalList); //line 3 , copying the list
duplicateList.remove(emfObjectToBeRemoved); // line 4

To my shock duplicateList is removing properly but the element is not getting removed from originalList...
I broke my head for some hours, did some googling and i dint have any clue ...Then when i was about to leave office , I felt like googling again and this time miracle happened...I observed an open bug with subject EcoreUtil.remove(object) in Eclipse Bugzilla and for a minute i was surprised seeing that EcoreUtil. I wasnt aware of that.

Then after line 4 , I put this statement

and when i run it , it is able to delete from EMF model(original list) also .....
I hope poor ppl like me will make use of this tip and merry ...

If you have an alternative for this, plz add it in comments..

Getting Active Editor and Active File associated with active editor

I had a requirement to find the active editor in the runtime eclispe and also the file , with which editor is associated to...

This is how we get active editor from RuntimeEclipse


The above line gives us the active editor , ofcurse u have to make null checks everytime...
getActiveWorkbenchWindow() first and then make null check and if its not null,then getActivePage()
and again check for null and then getActiveEditor().

and then getEditorInput (method in editorpart) and do the following
IEditorInput input = getEditorInput();
IFile activeFile = ((IFileEditorInput) input).getFile();
IProject project = activeFile.getProject();
like that u can get the project and can create files as u wish,,,

Sunday, May 4, 2008

You want to display a tooltip for a SWT tree Item ??

Well I had same requirement..I did some googling and found out from eclipse dev blogs that we have to fake it as tree item doesnt have such method toolTip with it :-(

At that time, i found this example to be very useful...Just replace table with tree if u want to show tooltip for a tree item corresponding to a tree....
Btw in the following example the result is same even if u comment the code of LabelListener...
I dont think we need it ...so i scrapped that part and im using the remaining part of the code as it is shamelessly;-)

package org.eclipse.swt.snippets;

* Tool Tips example snippet: create fake tool tips for items in a table
* For a list of all SWT example snippets see
* http://www.eclipse.org/swt/snippets/
import org.eclipse.swt.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;

public class Snippet125 {

public static void main (String[] args) {
final Display display = new Display ();
final Shell shell = new Shell (display);
shell.setLayout (new FillLayout ());
final Table table = new Table (shell, SWT.BORDER);
for (int i = 0; i < 20; i++) {
TableItem item = new TableItem (table, SWT.NONE);
item.setText ("item " + i);
// Disable native tooltip
table.setToolTipText ("");

// Implement a "fake" tooltip
final Listener labelListener = new Listener () {
public void handleEvent (Event event) {
Label label = (Label)event.widget;
Shell shell = label.getShell ();
switch (event.type) {
case SWT.MouseDown:
Event e = new Event ();
e.item = (TableItem) label.getData ("_TABLEITEM");
// Assuming table is single select, set the selection as if
// the mouse down event went through to the table
table.setSelection (new TableItem [] {(TableItem) e.item});
table.notifyListeners (SWT.Selection, e);
shell.dispose ();
case SWT.MouseExit:
shell.dispose ();

Listener tableListener = new Listener () {
Shell tip = null;
Label label = null;
public void handleEvent (Event event) {
switch (event.type) {
case SWT.Dispose:
case SWT.KeyDown:
case SWT.MouseMove: {
if (tip == null) break;
tip.dispose ();
tip = null;
label = null;
case SWT.MouseHover: {
TableItem item = table.getItem (new Point (event.x, event.y));
if (item != null) {
if (tip != null && !tip.isDisposed ()) tip.dispose ();
tip = new Shell (shell, SWT.ON_TOP | SWT.NO_FOCUS | SWT.TOOL);
tip.setBackground (display.getSystemColor (SWT.COLOR_INFO_BACKGROUND));
FillLayout layout = new FillLayout ();
layout.marginWidth = 2;
tip.setLayout (layout);
label = new Label (tip, SWT.NONE);
label.setForeground (display.getSystemColor (SWT.COLOR_INFO_FOREGROUND));
label.setBackground (display.getSystemColor (SWT.COLOR_INFO_BACKGROUND));
label.setData ("_TABLEITEM", item);
label.setText (item.getText ());
label.addListener (SWT.MouseExit, labelListener);
label.addListener (SWT.MouseDown, labelListener);
Point size = tip.computeSize (SWT.DEFAULT, SWT.DEFAULT);
Rectangle rect = item.getBounds (0);
Point pt = table.toDisplay (rect.x, rect.y);
tip.setBounds (pt.x, pt.y, size.x, size.y);
tip.setVisible (true);
table.addListener (SWT.Dispose, tableListener);
table.addListener (SWT.KeyDown, tableListener);
table.addListener (SWT.MouseMove, tableListener);
table.addListener (SWT.MouseHover, tableListener);
shell.pack ();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())

Thursday, May 1, 2008

How do u delete a repository that u added to Mylyn ReportBugs?

Now say u wud have added that repository with some mistakes and u want to delete it??? Try for all the options available in that wizard ..u wont be able to...and if u try to create another one with same URL it says "Already exists" and it wont allow u to create another one....

How to delete is : Open "Task Repositories" View and there u can right click and delete the repostiories u added....I hope eclipse guys will fix it in next releases...

Sunday, April 27, 2008

Best J2EE material from SUN site

Check out all the concepts and examples of J2EE at this link...


Friday, April 18, 2008

Uses of Drag and Drop feature

Now a days the fancy n yet useful feature is drap and drop...
Eclipse(swt/jface) and other frame works supports drag and drop widely...

The way in which we drag drop files in windows , similarly its a gud to have feature for desktop applications as well..say u have a viewer(widget to display data) and u want to fill some data present in a file in that viewer in the form of a table ...instead of asking user to browse through file dialog...its gud to support drag and drop feature from any location in file system onto the application...Surprisingly u can do this minimal lines of code...

How do u decide what actions should go into Menu and Tool bar?

Whenever we design a desktop application ..we often need to use Menu and Tool bar to do some actions when user clicks on either of menu or tool bar items...How do u decide which actions go into Menu and which actions go into Tool Bar...

Say u have an editor/view or composite(in general say GUI area) and depending on some specific widget selection (or some other restrictions ) only u want to allow some action to be done , then u can put those actions in corresponding menu items...

If u want user to give freedom to excute an action no matter what ever is selection or state of any widget in GUI , then all those kind of actions go into Tool Bar...

Any comments ???

Use of confirm dialogs in GUI......What do u prefer a Menu or a pop up dialog in a default case??

Consider a scenario in which u want to inform user that some thing is going to happen when he plays around with GUI..say User is filling an online application form and when hes done with that he wants to click one of three buttons Submit , Cancel , Reset ....

No issues with Submit/Cancel buttons as their actions are trivial...
In case of Reset button... Reset button entire application form is reset and all info he entered will be lost ...So what if he clicks it by mistake...So when ever this kind of scenario is there...its always gud to open a confirm dialog and according to yes/no choice of user , form should be reset / do nothing...

Out of box ,... another idea is if a case is default and if u want user to confirm what hes doing prefer a Dialog and if he has multiple actions then only go for Menu...

Thursday, March 27, 2008

Ever thought that a linux command can be used as a reminder / organizer!!!!!


• cal -3 Display a calendar
• cal 9 1752 Display a calendar for a particular month year
• date -d fri What date is it this friday. See also day
• date --date='25 Dec' +%A What day does xmas fall on, this year
• date --date '1970-01-01 UTC 2147483647 seconds' Convert number of seconds since the epoch to a date
• TZ=':America/Los_Angeles' date What time is it on West coast of US (use tzselect to find TZ)
echo "mail -s 'get the train' P@draigBrady.com < /dev/null" | at 17:45 Email reminder
• echo "DISPLAY=$DISPLAY xmessage cooker" | at "NOW + 30 minutes" Popup reminder

Interesting commands in linux ..check them out

Useful when u download in linux machines where u have lot of options
wget (multi purpose download tool)

(cd cli && wget -nd -pHEKk http://www.pixelbeat.org/cmdline.html) Store local browsable version of a page to the current dir
wget -c http://www.example.com/large.file Continue downloading a partially downloaded file
wget -r -nd -np -l1 -A '*.jpg' http://www.example.com/dir/ Download a set of files to the current directory
wget ftp://remote/file[1-9].iso/ FTP supports globbing directly
wget -q -O- http://www.pixelbeat.org/timeline.html | grep 'a href' | head Process output directly
echo 'wget url' | at 01:00 Download url at 1AM to current dir
wget --limit-rate=20k url Do a low priority download (limit to 20KB/s in this case)
wget -nv --spider --force-html -i bookmarks.html Check links in a file
wget --mirror http://www.example.com/ Efficiently update a local copy of a site (handy from cron)

Monday, March 17, 2008

Want to show help about a feature u design in Eclipse's online help???

U can refer to this link

Thursday, February 14, 2008

Getting ArrayIndexOutofBounds exception while removing selected indices from a list through a loop????

Consider this scenario..u have a list containing some "n" elements and u want to remove some elements say with indices 3,6,12 ,...
See the following code:

int indices[100] ; // indices array contains list of indices of elements to be removed from list

for(int i=0;i namesList.remove(indices[i]); // namesList is a list that contains // //elements
Now if u feel that above code is fyn...u r in a soup ;-) Try executing it ...U will get ArrayIndexOutofBoundsException...
Wonder yyyy??????Its silly actually.
The key is when u remove an element from a list...the remaining elements will push each one a level forward.. say u removed an element with index 5 , now 6 element will become 5.. and 7 th element will become 6 element ..
So while removing items in a loop the logic should be chosen accordingly...

Monday, February 11, 2008

Miscallaneous Study material links

Best site for XML,XSD,DTD ,XSLT material

Friday, February 8, 2008

Eclipse news


Wednesday, February 6, 2008

Eclipse articles: Really helpful for ppl working in eclipse

Ulimate site for eclipse articles:

Community :

Eclipse plugin architecture:

Layouts in SWT:

JFace tree viewer:

Eclipse views:


Properties page:

UI Forms:

Extension Points:

Selection Service:

Building & Testing:

Adding Help:


Java Standard Material



Christian Music Downloads and passages