Tuesday, July 27, 2010

Add Actions-sets in existing Perspectives

Assumption/PRE-required knowledge : Actionsets has already been created in your plugin. I will only be using the ID declared fr this action set in order to customize its visibility on existing Perspectives.

Example Objective: To display my Actionset with id =”myActionSet” only in Debug perspective(id : org.eclipse.debug.ui.DebugPerspective")

Steps:

There are two ways of doing this.. One is through the class implementation as in (1) below), while is other is by using only plugin.xml file(2) below)

  1. Class implementation: As a first step, we need to register our plug-in as a perspective change listener.
--> include the below xml snippet in plugin.xml

--> Now, implement the class EarlyStartup mentioned in your xml code. This class should implement the IStartup interface and implement the method perspectiveActivated from within the method earlyStartup(). This method is responsible for the action performed every time a perspective is activated.
--------

--------
With the above code, your action sets will be visible only in perspectives related to JAVA, such as : Java, Java Browsing and Java Type Hierarchy.

***************************************************************

2. Extend your plug-in with the extension -Perspective Extensions(refer the blog - 'Customizing existing Perspective')

References:







Sunday, July 25, 2010

source code websites

DOCJAR

GREPCODE

KICKJAVA

http://www.devdaily.com/java/jwarehouse/eclipse/org.eclipse.ui.views/src/org/eclipse/ui/views/properties/PropertyEditingSupport.java.shtml

JAD - JAVA Decompiler / JADCLIPSE

  • In order to use JAD in eclipse, you need to update the eclipse version with the Update site forJADClipse - http://jadclipse.sf.net/update 1) Eclipse >> help >> install new software >> type - http://jadclipse.sf.net/update >> add >> choose ' JDT Decompiler feature' from list
    >> next >>and just follow eclipse instructions once this is done.... and you restart eclipseNow, you will be able to view source codes of all library classes when you search for a certain "java' element using the "alt+shift+t"

Wednesday, July 14, 2010

Externalize/Internationalize Plug-in strings

Externalize / Internationalize Strings in plugin.xml

When we extend our plug-in projects with some extension.. there will be soo many attribute values such as Names, labels etc. It becomes tedious to change every such attributue if in case required in the later stage of the project.

The easier way to do it is to be able to see it all at one file(the .properties file).

This becomes of utmost importance when the developer is ignorant of the local language and would want to just type-in English texts for these attribute values..

The language interpreter could just refer to this one file(.properties file) and convert all the required strings into the local language without having to know the Extension implementation details.

How is this implemented??

note: This article is applicable only for externalization of PLugin.xml files.. If you are to externalize source files.. its a whole new procedure...
  • Create your plug-in project.
  • once you have completed with including all the required extensions, make sure you have completed with all the textual values of attributes such as name, label, etc
  • Now, select your plugin.xml file form the explorer view
  • right click >>
  • PDE Tools >>
  • Externalize Strings/Internationalize >>
  • choose and expand the plug-in of interest
  • choose the manifest.mf and the plugin.xml file one by one to check if you are alright with the appended changes.
  • You could even modify the 'substitution key ' values if preferred
  • Next>> check with the appended changes in each file under your plug-in
  • Finish
Now, you will have a new bundle.properties file in your project which will map all the strings to a certain value.

Check the below screenshot after externalization:

Monday, July 12, 2010

Debug Eclipse Runtime Plug-ins

showView >> Plug-ins>>

choose the plug-in you want to debug..

>>right-click

>>Import as

>> source project

Now look at your project explorer to fins this plug-in...

Now.. go ahead and debug :)

Eclipse Pop-up Menu

org.eclipse.ui.popupMenus
****************************

Eclipse Pop-up menus are menuitems that appear when you right-click on an object in the Eclipse workbench.

Steps:

1) Create a Plug-in project with the.. While you are in the process of creating your plug-in project, when prompted for a template.. choose

' Plug-in project with pop-up menu'>>
next>>
finish

2)Open the Plugin.xml file

3)choose the 'extensions' tab. You will see th eextension structure as seen in the figure below:


4) Now, click on the ....(Object Contribution) item. This will populate the right tab with the details of 'id' and 'Object class'.(figure below)




5) Now, when you right-click on a object from the eclipse workbench, this Object class attribute is the value which determines, when right-clicked on which object, the pop-up needs to be visible as the context menu. Now, if you want to enable this pop-up meny when you click on a folder from any of the eclipse views, you have to browse to 'org.eclipse.core.resources.IFolder' in the field for Object class.


6) As a result of the above step, you will be able to view the pop-up when right-clicking on a folder object in your Eclipse wrkbench as seen in the figure below.

7) In your step 3), click on the ....(Action) item. This will populate the right tab with many details. Now when you click at the 'class' parameter from this view, It opens the class in an editor. This is the class where you can define the action that needs to be performed when you click on the popUpMenu Action(refer figure above)

And there you gooooo :)
***************************************

Eclipse SPY - (ALT+SHIFT+F1)

The Class responsible and the various class instances within the responsible class for a certain part of the Eclipse workbench can be easily recognised using the Eclipse SPY feature.


What exactly do I mean?

Let's consider an example...


Let's say that we want to know about the class and the list of classes instances called or responsible fo rth elaunch tab of "Eclipse Application".


How to see this list?


1)Create any eclipse application( a plug-in project)

2)Now right-click and open 'run configurations../debug configuration.." over this application.This will open the Debug/Run configuration dialog.

3)Now press, "alt+shift+f1". This will open the Eclipse spy dialog as shown in the figure below showing all the responsible classes fo rthe configuration dialog.

Sunday, July 11, 2010

Customizing Eclipse Launch Configurations

http://www.eclipse.org/articles/Article-Launch-Framework/launch.html

Launching is centered around two main entities, LaunchConfigurations and LaunchConfigurationTypes.
  • LaunchConfigurationType/Config-type : is an entity that knows how to launch certain types of launch configurations.
  • Launch configurations / configs : are entities that contain all information necessary to perform a specific launch.

Once a config type is implemented , the launching infrastructure contributed by the Debug core plug-in (org.eclipse.debug.core) creates configs on behalf of the config type, and infrastructure provided by the Debug UI plug-in ( org.eclipse.debug.ui) provides a dialog to manage configs (the 'LaunchConfigurationDialog'), as well as other launching-related UI.

To use the launcher API, plug-in must make some import declarations in its plugin.xml file.

  • If your plug-in declares a config type, it must import org.eclipse.debug.core, and
  • if plug-in declares anything related to launching UI, must import org.eclipse.debug.ui.
  • Note : In this case, the launcher can only be used programmatically from within code, not by a user (see the forthcoming related article "How to Launch Java Applications Programmatically" by Darin Wright).

****************************************************************************

Developing a launcher for Java applets. :

******************************************************************

  1. declaring a config type : as shown in the following snippet of XML from our plug-in's plugin.xml file.

Non-UI declaration

extension point<"org.eclipse.debug.core.launchConfigurationTypes">
launchConfigurationType
name="Diana's Java Applet"
modes="run, debug"

delegate= "org.eclipse.jdt.internal.launching.JavaAppletLaunchConfigurationDelegate"

id="org.eclipse.jdt.launching.dianasjavaApplet">
launchConfigurationType
extension>

  • The most important part of this declaration is the delegate attribute which specifies the fully-qualified name of a class that implements the interface org.eclipse.debug.core.model.ILaunchConfigurationDelegate. The delegate is the brains of the launcher, and implements the launch() method which launches a specified config.
  • The modes attribute specifies one or both of run & debug. Note :When specifying a launch mode in code, you should never use a hard-coded String. Instead, use one of the constants defined in org.eclipse.debug.core.ILaunchManager.
  • if the launch configuration dialog is opened in run mode, but your config type is for debug mode only, then your config type and any associated configs will not appear.
  • Note : if your config type declares both modes, it is your delegate's responsibility in the launch() method to handle both modes.
  • An optional attribute not present in the above declaration is private. This is a boolean attribute that indicates whether the config type should appear in the UI, if there is one. Setting this attribute to true effectively makes your launcher usable for programmatic launching only. The default value, if this attribute is omitted, is false.
  • Another optional attribute not shown above is category.

Result : Including the above snippet in plugin.xml as the first step will enable the type, "Diana's Java Applet" to be visible as one of the Config types in both,



Debug configurations.... & Run Configurations.... as in figure below




******************************************************************
2. declaring a config type icon: For this, include the snippet below in Plugin.xml


UI declaration

extension point="org.eclipse.debug.ui.launchConfigurationTypeImages"
launchConfigurationTypeImage icon="icons/full/ctool16/java_applet.gif"
configTypeID="org.eclipse.jdt.launching.dianajavaApplet"
id="org.eclipse.jdt.debug.ui.launchConfigurationTypeImage.javaApplet"
launchConfigurationTypeImage
extension

  • Note that the id attribute is just a unique identifier,
  • whereas the configTypeID attribute should have the same value as the id attribute for our config type declaration.

Result:


*************************************************************
3. Declaring a tab group : LaunchConfigurationDialog(LCD) provided by the Debug UI plug-in is a central point for creating, managing, deleting and launching configs of any config type. The LCD is broken into two main regions:

  • The config tree shows all configs currently defined in the workspace, grouped by config type.
  • The tabbed folder(list of tabs collectively called as tab groups), lets users edit attributes of the config currently selected in the tree. The contents of this tabbed folder are specified when you declare a tab group. For this, include the snippet below in Plugin.xml :

extension point="org.eclipse.debug.ui.launchConfigurationTabGroups"
launchConfigurationTabGroup
type="org.eclipse.jdt.launching.dianajavaApplet"
class="org.eclipse.jdt.internal.debug.ui.launcher.JavaAppletTabGroup"
id="org.eclipse.jdt.debug.ui.launchConfigurationTabGroup.javaApplet"
launchConfigurationTabGroup
extension

******************************************************************

Now, in order to make a customised Launch configuration, that is... to make a customised launch item in the list of Launch types(Eclipse Application, SWT application, Java Application, Java Applet, etc),

All the above steps would include copy of the JavaApplet Launch item in the Run/Debug configurations.... However, since the delegate included for the ConfigurationType in the extension point is specific for JavaApplet,which is -->"delegate = "org.eclipse.jdt.internal.launching.ui.JavaAppletLaunchConfigurationDelegate""..

This would open the TabGroup specific to JavaApplet Launch. And hence, everytime double-clicked, a Configuration item is added not under your type, but under JavaApplet type. or. the set of tabs opening for TabGroup woul dbe that of Applet Configuration

Now, To open a customised TabGroup, We need to map the "class" attribute of the launchConfigurationTabGroup in the extensions tab to your customised class.

The customised class for Configuration TabGroup should

1) implement AbstractLaunchConfigurationTabGroup.

2)overide Launch() to include the list of default tabs or customised tabs that needs to make up your tab group.

Find below an example code snippet:

---------------------------------------------------------------------------------

package z_launchconfig.TabImplementation;

import org.eclipse.debug.ui.AbstractLaunchConfigurationTabGroup;

import org.eclipse.debug.ui.CommonTab;

import org.eclipse.debug.ui.ILaunchConfigurationDialog;

import org.eclipse.debug.ui.ILaunchConfigurationTab;

/*import org.eclipse.jdt.debug.ui.launchConfigurations.AppletMainTab;import org.eclipse.jdt.debug.ui.launchConfigurations.AppletParametersTab;import org.eclipse.jdt.debug.ui.launchConfigurations.JavaArgumentsTab;import org.eclipse.jdt.debug.ui.launchConfigurations.JavaClasspathTab;import org.eclipse.jdt.debug.ui.launchConfigurations.JavaJRETab;*/

public class MyJavaAppletTabGroupClass extends AbstractLaunchConfigurationTabGroup
{
/** * Constructs a new Java applet tab group. */


public MyJavaAppletTabGroupClass()
{
}

/* (non-Javadoc) * @see org.eclipse.debug.ui.ILaunchConfigurationTabGroup#createTabs(org.eclipse.debug.ui.ILaunchConfigurationDialog, java.lang.String) */


public void createTabs(ILaunchConfigurationDialog dialog, String mode)
{
ILaunchConfigurationTab[] tabs = new ILaunchConfigurationTab[] { new CommonTab() };
setTabs(tabs);
}
}

--------------------------------------------------------------------------

In the code above, the line

new CommonTab()

adds the 'common' tab into the Configuration group. And therefore our customised ConfigurationTabGroup would consis of only one Tab as in figure below:

Now, if the line new CommonTab(),

is replaced with many more default tabs as in the code below..

------------------------------------

new CommonTab(),

new AppletMainTab(),

new AppletParametersTab(),

new JavaArgumentsTab(),

new JavaJRETab(),

new JavaClasspathTab(),

------------------------------------


The tabGroup will have more tabs as in figure below.


Now, for a quick summary of the above steps:

1) Create a simple plu-in project, maybe with a pop-upMenu

2) Open the Plugin.xml file of this project and include the following snippet in it.

This would like like the figure below in your extensions tab :

3) Now, the class attribute of the (launchConfigurationTabGroup) extension needs to be implemented as below(you could also refer above for the code) :


4)
Important note : The import statement of this source is not available in the default library of the project. Hence we need to add them.

And hence,
Add,
1)org.eclipse.debug.ui
and all other related plug-in in the dependencies tab of Plugin.xml

The above 4 steps ensures the implementation of customised Run and debug Configurations in your project.

*****************************************************



























Wednesday, July 7, 2010

how to identify between a 'pure/plain' java project or a 'plug-in java project'?

Have a look at the “.project” file. This file contains the description of your project. It contains a XML tag “natures” where the nature of the project is described. A plugin project has the nature “org.eclipse.pde.PluginNature” and a java project has the nature “org.eclipse.jdt.core.javanature”.

These tags will also steer some behavior of the development environment, e.g. a project with PluginNature will update the java class path if you change the dependency information in a plugin project. For example if you add the “org.eclipse.pde.PluginNature” to an existing Java project you get the PDE menu for your project.


http://www.vogella.de/blog/tag/pde/

Adding a non-default extensions to your Eclipse Plug-in Project

To extend any Plug-in with the Eclipse features, The modifications need to be performed in the Plug-in.xml.

1) As the first step, Create a plug-in project. Once done, open the Plug-in.xml file of this project.

2) To extend any Eclipse feature in your plug-in project... (example: features like Preference page, property page, Launch configuration, etc..), the feature's related jar needs to be added into the 'Extensions tab'. So, click on the 'extensions' tab and add the corresponding plug-in. Sometimes, the plug-in you are looking for may not be available to add form the extensions tab. This implies that the plug-in you are looking for needs to be added to the environment.

3) To make a certain plug-in available for your extensions tab, add the related plug-in in the 'dependencies tab'. Once this is done, The extensions will be available.

For instance, if I want to add the ' org.eclipse.debug.ui.launchShortcuts' into my Extensions, I need to first add the related plug-in, org.eclipse.debug.ui' into my 'dependencies'