Friday, September 19, 2014

How to contribute a new menu to the workbench ?

Eclipse exposed a mechansim to contribute a new menu through "org.eclipse.ui.menus" extension and locationURI.
Requried extension: org.eclipse.ui.menus
LocationURI:  menu:org.eclipse.ui.main.menu

Example:
Below example will contribute a new "Cloud" menu to the eclipse workbench, and this will contain a "Upload" menu item.

 <extension
         point="org.eclipse.ui.menus">
      <menuContribution
            allPopups="false"
            locationURI="menu:org.eclipse.ui.main.menu">
         <menu
               id="com.kk.menus.cloud"
               label="Cloud">
             <command
                  commandId="com.kk.command.upload"
                  style="push">
            </command>
          </menu>
      </menuContribution>
</extension>

Command contribution to upload action:

<extension
         point="org.eclipse.ui.commands">
  <command
            id="com.kk.command.upload"
            name="Upload">
      </command>
</extension>

Handler contribution to upload action:

  <extension
         point="org.eclipse.ui.handlers">
      <handler
            class="com.kk.menus.handlers.UploadHandler"
            commandId="com.kk.command.upload">
      </handler>
   </extension>

Wednesday, September 17, 2014

UI Toolkits and Multi-threaded environment

How to get active perspective in Eclipse

Active workbench page will have getPerspective() this will return the IPerspectiveDescriptor

IWorkbench workbench = PlatformUI.getWorkbench();
if (workbench != null) {
IWorkbenchWindow activeWorkbenchWindow = workbench.getActiveWorkbenchWindow();
if (activeWorkbenchWindow != null) {
IWorkbenchPage activePage = activeWorkbenchWindow.getActivePage();
if (activePage != null) {
IPerspectiveDescriptor perspective = activePage.getPerspective();
if (perspective != null) {
String id = perspective.getId();
//This is your active perspective
}
}
}

visibleWhen on toolbar in Eclipse

I have added visibleWhen directly under toolbar, look like platform is not respecting visibleWhen for toolbar.

This is how I defined the extension:

<extension
       point="org.eclipse.ui.menus">
    <menuContribution
          allPopups="false"
          locationURI="toolbar:org.eclipse.ui.trim.vertical2">
       <toolbar
             id="com.kk.toolbar2"
             label="Charm bar">
          <command
                commandId="com.kk.command.showhelp"
                icon="icons/help.gif"
                label="Help"
                style="push">
           </command>
<visibleWhen
                   checkEnabled="false">
                <test
                      forcePluginActivation="true"
                      property="com.kk.isKKPerspective"
                      value="true">
                </test>
        </visibleWhen>
            </toolbar>
    </menuContribution>
 </extension>


visibleWhen has no effect on toolbar
https://bugs.eclipse.org/bugs/show_bug.cgi?id=201589


Workaround for this problem is, adding visibleWhen for each command. 
By adding visibleWhen on each command, toolbar is automatically getting disappeared if there are no visible elements

In my case, I want to add add a righside trim toolbar with some tool items. But I wanted to show this only in my perspective 'KKPerspective'.

<extension
       point="org.eclipse.ui.menus">
    <menuContribution
          allPopups="false"
          locationURI="toolbar:org.eclipse.ui.trim.vertical2">
       <toolbar
             id="com.kk.toolbar2"
             label="Charm bar">
          <command
                commandId="com.kk.command.showhelp"
                icon="icons/help.gif"
                label="Help"
                style="push">
             <visibleWhen
                   checkEnabled="false">
                <test
                      forcePluginActivation="true"
                      property="com.kk.isKKPerspective"
                      value="true">
                </test>
             </visibleWhen>
          </command>
            </toolbar>
    </menuContribution>
 </extension>

   <extension
         point="org.eclipse.core.expressions.propertyTesters">
      <propertyTester
            class="com.kk.KKPerspectiveTester"
            id="com.kk.propertyTester2"
            namespace="com.kk.propertyTester2"
            properties="isKKPerspective"
            type="java.lang.Object">
      </propertyTester>
   </extension>

Tuesday, September 16, 2014

Conventions for naming git branches for your development

Some practices which I follow for naming git branches.

If you are working on sprint/agile development, you might have planned certain activities for each sprint.

let's say, every sprint development is for 1 month,so for every sprint we can maintain different branches as mentioned below.

Example: In Development mode
Sprint 1  =>  Branch name: dev-1.0.1

here, dev-<Major version>.<Minor version>.<Sprint version>

While handing over your work to QA team, we can promote this branch to QA branch.

Example: In QA mode
dev-1.0.1 will become qa-1.0.1

If you are providing builds one top of dev branches.
Example: For sprint 1 on dev branch
com.kk.product_dev-1.0.1.0.jar

Here, <pluginname>_<<branch name>.<build number>>.jar

on QA builds generation,
com.kk.product_qa-1.0.1.0.jar

If many people are working on sprint on various features, then we can create a different branch for each feature(ex: dev-1.0.1_explorer), once the feature is stabilized then we can merge this with the main sprint branch i.e dev-1.0.1


Monday, September 15, 2014

Eclipse Plugin name and package name conventions

I will follow below conventions for naming any new plug-in which I am contributing.

Plug-in names should follow the standard Eclipse Naming conventions. That means that,
(i)   The project name on disk(Plug-in name) is the same as the plug-in id and
(ii)  Plug-in packages should start with plug-in name.
(iii) Don’t mix generated code plug-in and implementation plugins

com.kk.studio.<component name>
com.kk.studio.<major component name>.<minor component name>

 Examples:
com.kk.studio.sky   => Implemented code plug-in
com.kk.studio.sky.model    => EMF model based generated code plug-in

Package Names:
com.kk.studio.sky  => Plug-in name/Plug-in id

com.kk.studio.sky
com.kk.studio.sky.explorer
com.kk.studio.sky.explorer.model
com.kk.studio.sky.explorer.view
com.kk.studio.sky.explorer.view.actions
com.kk.studio.sky.explorer.view.dialogs
com.kk.studio.sky.explorer.view.dialogs.data
com.kk.studio.sky.explorer.view.providers
com.kk.studio.sky.i18n
com.kk.studio.sky.util


Eclipse Resources:
http://wiki.eclipse.org/Development_Resources/HOWTO/Project_Naming_Policy
http://wiki.eclipse.org/index.php/Naming_Conventions#Eclipse_Workspace_Projects

java.lang.OutOfMemoryError: unable to create new native thread

One of the developer reported "java.lang.OutOfMemoryError: unable to create new native thread" while working with eclipse on his application.

Below is the error log.
java.lang.OutOfMemoryError: unable to create new native thread
                at java.lang.Thread.start0(Native Method)
                at java.lang.Thread.start(Unknown Source)
                at java.lang.ref.Finalizer$1.run(Unknown Source)
                at java.security.AccessController.doPrivileged(Native Method)
                at java.lang.ref.Finalizer.forkSecondaryFinalizer(Unknown Source)
                at java.lang.ref.Finalizer.runFinalization(Unknown Source)
                at java.lang.Runtime.runFinalization0(Native Method)
                at java.lang.Runtime.runFinalization(Unknown Source)
                at java.lang.System.runFinalization(Unknown Source)
                at org.eclipse.ui.internal.ide.application.IDEIdleHelper$3.run(IDEIdleHelper.java:182)

                at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)


This is what i can think why he encountered with this issue.

User is running on 32 bit machine with 
Since he is running on 32 bit machine, you need to allocate –Xmx and -XX:PermSize carefully. Since 32 bit machines can address maximum of 4GB address space.

Since we allocated -Xmx is 1024m and -XX:PermSize is 512m, there is very less space is remaining to create a new Java native threads by OS.

To make it work, reduce -XX:PermSize to 256m and –Xmx to 512m(unless 1024 is required).