Saturday, August 2, 2014

Hide toolbar in eclipse programatically


You might want to remove eclipse toolbar completely in your Eclipse RCP product to make use of that space or you might not have any useful toolbar actions which are specific to your product.

This how you can remove programatically.

private void hideCoolbar() {
try {
IHandlerService service = (IHandlerService) PlatformUI.getWorkbench().getActiveWorkbenchWindow()
.getService(IHandlerService.class);
if (service != null)
service.executeCommand("org.eclipse.ui.ToggleCoolbarAction", null);
} catch (Exception e) {
KEditorPlugin.logError("Unable to hide the eclipse toolbar.",e);
}
}








Hide tool bar in eclipse

In eclipse 3.8 version and earlier, you can find "Hide Toolbar" option on the right click of eclipse toolbar itself. This will hide the complete toolbar.

In Eclipse e4 versions, you can find this option in on the Eclipse toolbar Window menu.
Window -> Hide Toolbar

To enable again,
Window -> Show Toolbar


Thursday, July 31, 2014

git pull failed with file too long issue

Run below command to avoid the issue.

$ git config core.longpaths true

Wednesday, July 16, 2014

Executing batch file through Java

Batch file has to perform below actions.

1. Change the directory for a given path
2. start the node sever
3. Exit the command window

>cd D:\nodev0.18
>node app.js console
>exit

FileName: Myfile.bat
Batch file defined with variable arguments like below.

cd %1
%2 app.js console
exit

Java code for invocation:
String executePath = "cmd /c start Myfile.bat"
   Runtime.getRuntime().exec(executePath);

Executing windows commands through java

I wanted to start the node server programmatically.
>node app.js


Using Java:

String executePath = "cmd /c start node app.js"

Runtime.getRuntime().exec(executePath);


Removing eclipse view title bar tab


public class Perspective implements IPerspectiveFactory {
  public void createInitialLayout(IPageLayout layout) {      
    String editorArea = layout.getEditorArea();
    layout.setEditorAreaVisible(false);

    layout.addStandaloneView(View.ID, false, IPageLayout.LEFT, 1.0f, editorArea);      
  }
}


A standalone view's title can optionally be hidden. If hidden, then any controls typically shown with the title (such as the close button) are also hidden. Any contributions or other content from the view itself are always shown (e.g. toolbar or view menu contributions, content description).

Source:
http://andydunkel.net/eclipse/java/swt/2011/10/04/eclipse-rcp-remove-tab-folder-from-view.html

Thursday, July 3, 2014

Setting "java.library.path" programmatically

Requirement:

I have 6 dll files in my eclipse plug-in under lib/win64 folder. I wanted to load them dynamically during the launch of eclipse.

I have tried the eclipse way of bundling native-code in the plugin manifest, but somehow i could not achieve. So I have to go by manipulating the system path.

Eclipse bundle-native code mechanism:
http://blog.vogella.com/2010/07/27/osgi/


try {
     //eclipse call
Bundle bundle= getBundle();
URL fileUrl = FileLocator.toFileURL(FileLocator.find(bundle, new Path("/"), null));
String location = fileUrl.getFile();
String libPath = location + "lib/win64";
File file = new File(libPath);
System.out.println(file.getAbsolutePath());
System.setProperty("java.library.path", file.getAbsolutePath());
Field fieldSysPath = ClassLoader.class.getDeclaredField("sys_paths");
fieldSysPath.setAccessible( true );
fieldSysPath.set( null, null );
} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (SecurityException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}


The Classloader has a static field (sys_paths) that contains the paths. If that field is set to null, it is initialized automatically. Therefore forcing that field to null will result into the reevaluation of the library path as soon as loadLibrary() is called

Resources:
http://blog.cedarsoft.com/2010/11/setting-java-library-path-programmatically/
http://fahdshariff.blogspot.in/2011/08/changing-java-library-path-at-runtime.html