Saturday, 8 November 2014

How to get Workspace location in Eclipse RCP Plug-in ?

Try following :


//get object which represents the workspace
IWorkspace workspace = ResourcesPlugin.getWorkspace();

//get location of workspace (java.io.File)
File workspaceDirectory = workspace.getRoot().getLocation().toFile()


Add Following Package to dependency in Manifiest.MF
org.eclipse.core.resources

Sunday, 6 July 2014

Factory Design Pattern - Java

Factory Design Pattern

Factory Design Pattern works as per it's name. As one Factory can generate various types of items but of a specific category. Like, Car Factory ( Nissan Car Factory ) can create cars like, Micra, Sunny, Evalia but it can't create Duster. Because,Duster can be created by Renault Car Factory.



So, with the same concept, A company can create a various types of Employees. Like, Developer, Admin , Developer Manager. But, only Developer can be Dev Manager.




Here is the Complete example of creating the Company with all the Employee details.

Class Company.java
/**
 * Parent Class of all Class. Employee is Base class of all types of Employee.
 *
 * @author Hari
 *
 */
abstract class Employee {
 public abstract void getMyDetails();
}
/**
 * Admin is child class of the Employee class.
 *
 * @author Hari
 */
class Admin extends Employee {
 public void getMyDetails() {
  System.out.println("I'm admin");
 }
}
/**
 * Developer is another child class of Employee Class
 *
 * @author Hari
 */
class Developer extends Employee {
 public void getMyDetails() {
  System.out.println("I'm Developer");
 }
}
/**
 * DevManager is the Class derived from Developer.s
 *
 * @author Hari
 *
 */
class DevManager extends Developer {
 public void getMyDetails() {
  super.getMyDetails();
  System.out.println("I'm Manager");
 }
}
/**
 * Enum Type id defined to get the argument as specific type of the class
 *
 * @author Hari
 *
 */
enum EmployeeType {
 ADMIN, DEVELOPER, DEV_MANAGER
}
/**
 * Company Class is Factory. Company can create any type of the Employee.
 *
 * @author Hari
 *
 */
public class Company {
 /**
  * Method to create a Employee.
  *
  * @param employeeType
  * @return
  */
 public static Employee hireEmployee(EmployeeType employeeType) {
  Employee e = null;
  switch (employeeType) {
  case ADMIN:
   e = new Admin();
   break;
  case DEVELOPER:
   e = new Developer();
   break;
  case DEV_MANAGER:
   e = new DevManager();
   break;
  }
  return e;
 }
}

Friday, 17 January 2014

GTK Error in Eclipse RCP

GTK Error in Eclipse RCP

Many times while testing eclipse RCP application, you will see following error:

------------------------------------------------------------------------------------------------------------
(eclipse:2960): GLib-GObject-WARNING **: invalid (NULL) pointer instance

(eclipse:2960): GLib-GObject-CRITICAL **: g_signal_connect_data: assertion 'G_TYPE_CHECK_INSTANCE' (instance) failed

(eclipse:2960): Gtk-CRITICAL **: IA__gtk_screen_get_display: assertion 'GDK_IS_SCREEN (screen)' failed

(eclipse:2960): Gtk-WARNING **: Screen for GtkWindow not set; you must always set a screen for a GtkWindow before using the window

(eclipse:2960): Gtk-WARNING **: Screen for GtkWindow not set; you must always set a screen for a GtkWindow before using the window

(eclipse:2960): Gdk-CRITICAL **: IA__gdk_screen_get_display: assertion 'GDK_IS_SCREEN (screen)' failed

(eclipse:2960): Gdk-CRITICAL **: IA__gdk_display_get_pointer: assertion 'GDK_IS_DISPLAY (display)' failed

(eclipse:2960): Gtk-WARNING **: Screen for GtkWindow not set; you must always set a screen for a GtkWindow before using the window

(eclipse:2960): Gdk-CRITICAL **: IA__gdk_screen_get_n_monitors: assertion 'GDK_IS_SCREEN (screen)' failed

(eclipse:2960): Gtk-WARNING **: Screen for GtkWindow not set; you must always set a screen for a GtkWindow before using the window

(eclipse:2960): Gdk-CRITICAL **: IA__gdk_screen_get_monitors_geometry: assertion 'GDK_IS_SCREEN (screen)' failed

(eclipse:2960): Gdk-CRITICAL **: IA__gdk_screen_get_default_colormap: assertion 'GDK_IS_SCREEN (screen)' failed

(eclipse:2960): Gdk-CRITICAL **: IA__gdk_colormap_get_visual: assertion 'GDK_IS_COLORMAP (colormap)' failed

(eclipse:2960): Gdk-CRITICAL **: IA__gdk_screen_get_default_colormap: assertion 'GDK_IS_SCREEN (screen)' failed

(eclipse:2960): Gdk-CRITICAL **: IA__gdk_screen_get_root_window: assertion 'GDK_IS_SCREEN (screen)' failed

(eclipse:2960): Gdk-CRITICAL **: IA__gdk_screen_get_root_window: assertion 'GDK_IS_SCREEN (screen)' failed

(eclipse:2960): Gdk-CRITICAL **: IA__gdk_window_new: assertion 'GDK_IS_WINDOW (parent)' failed
Segmentation fault
---------------------------------------------------------------------------------------

Solution:
The cause of the occurrence of this error is , it it now able to find $DISPLAY varialbe. So better setup $DISPLAY , environemt variable. Other possibility is your VNC has disabled xhost
so try out following commands :
$> setenv DISPLAY :0
$> xhost 

I hope this will resolve your error.