Tuesday, August 12, 2014

Opening eclipse editor or view in the dialog programatically

We can open eclipse editor or view in the dialog by using the Eclipse e4 model services. This is also called detaching the editors/views from the eclipse workbench.

For this, you need to have e4 workbench plugin and it provides org.eclipse.e4.ui.workbench.modeling API services.


IWorkbench workbench = ActivatorPlugin.getDefault().getWorkbench();

//get editorpart somehow which you wanted to open it.
EditorPart openEditor = /*IDE.openEditor(workbench.getActiveWorkbenchWindow().getActivePage(), module, MyEditorID, false); */

//get editor site
IWorkbenchPartSite site = openEditor.getSite();

//get model service for editor site
EModelService modelService = (EModelService) site.getService(EModelService.class);
MPartSashContainerElement  mpartService = (MPart) site.getService(MPart.class);

//invoke detach on model service with coordinates.
modelService.detach(mpartService, 100, 100, 700, 700);


For view:

//Get view part
IViewPart view = workbench.getActiveWorkbenchWindow().getActivePage().findView(MyPerspective.ExplorerView_ID);
//get site for view
//invoke detach


Resources:
http://eclipsesource.com/blogs/tutorials/eclipse-4-e4-tutorial-part-7-services/
http://help.eclipse.org/luna/index.jsp?topic=%2Forg.eclipse.platform.doc.user%2Ftasks%2Ftasks-9l.htm
http://mcuoneclipse.com/2012/02/29/go-multiply-and-detach-multiple-screens-with-eclipse/

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