Showing posts with label Eclipse RCP. Show all posts
Showing posts with label Eclipse RCP. Show all posts

Sunday, June 26, 2016

“Java heap space” error in eclipse (Windows 7)

Little background : I am currently working in a project based on Eclipse RCP.  In this project whenever i need to setup a new work-space or dependency of my project change i need to resolve the target.

During resolving the target i was getting the  “Java heap space error in eclipse" frequently : i have tried different solution from web but i it never worked. specially changing the JVM argument in the eclipse.ini file never worked for me.

Fist of all i did not know how to check  current JVM min and max heap size. after googling i have found this nice tool which come by-default with JDK .

JConsole : 
Using JConsole you can check the current minimum and maximum head size alocated in the JVM for a program or process:

Please check the below link for details
http://docs.oracle.com/javase/7/docs/technotes/guides/management/jconsole.html



Now i know how much heap size is allocated currently: so i need to increase the heap size.
For increasing the heap size i have done the following  :

Try setting a Windows System Environment variable called _JAVA_OPTIONS with the heap size you want. Java should be able to find it and act accordingly.






 setting windows  system  env variable _JAVA_OPTIONS as -Xms2048m -Xmx4096m -XX:MaxPermSize=1024m


works for me  :)



Sunday, October 4, 2015

Css Stying in E4 Compatibility Layer

I can apply Css Styling  in my Eclipse 3.x plugin using following steps:


Step 1. Configuring CSS Stylesheets:


1.1 add a css file





1.2 add a theme using theme extension point






1.3






Step 2. add css id/class to your swt control:
final Composite composite = new Composite(parent, SWT.NONE);
composite.setData("org.eclipse.e4.ui.css.id","MyCSSTagForLabel");

Step 3. add the folowing block to your default.css file:

#MyCSSTagForLabel{
  color: black;
  background: #99b4d1;
  swt-corner-radius: 20;
}

Done!

Thursday, September 10, 2015

Eclipse RCP : How to check state(toggle) of a menu items or toolbar items inside handlers

In Eclipse RCP there are at-least two different ways we  can check the state of a menu item or  a toolbar item inside a handlers execute method :

Option 1 :


ICommandService service =(ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);
Command command = service.getCommand("org.eclipse.example.command.toggle");
State state = command.getState("org.eclipse.example.command.toggleState");
System.out.println(state.getValue());

//state.setValue(!(Boolean) state.getValue());



Option 2:


   @Override
    public Object execute(ExecutionEvent event) throws ExecutionException {
   
   
        Event selEvent = (Event) event.getTrigger();
        Widget widget =  selEvent.widget;
        if (widget instanceof ToolItem) {        
        isSelected = ((ToolItem)widget).getSelection();
}else {
isSelected = ((MenuItem)widget).getSelection();
}
}


Wednesday, September 2, 2015

Eclipse RCP : How to check a view is currenlty visible


If we need to check whether a view currently available or visible we can use following code :

Boolean result = false;

IViewReference viewReferene =  PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findViewReference("my_view_id");


if (viewReferene != null) {
result = true;
}





Tuesday, January 13, 2015

Eclipse Jobs API : Perform something when job is done

When we need to do something for example notify user or cleaup someting after a JOB is finished we can user the  JobChangeListener to accomplish this. see the folowing code:


     final Job job = new Job("Long Running Job") {
        protected IStatus run(IProgressMonitor monitor) {
           try {
              while(hasMoreWorkToDo()) {
                 // do some work
                 // ...
              if (monitor.isCanceled()) return Status.CANCEL_STATUS;
             }
              return Status.OK_STATUS;
           } finally {
              schedule(60000); // start again in an hour
           }
        }
     };
  job.addJobChangeListener(new JobChangeAdapter() {
        public void done(IJobChangeEvent event) {
        if (event.getResult().isOK())
           postMessage("Job completed successfully");
           else
              postError("Job did not complete successfully");
        }
     });
  job.setSystem(true);
     job.schedule(); // start as soon as possible


See the details in following website:
https://eclipse.org/articles/Article-Concurrency/jobs-api.html





Monday, August 25, 2014

How to find a view in Eclipse RCP

The following technique can be used to get the currently active page and any view within that page.


IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IViewPart view = page.findView(MyView.ID);


The MyView.ID specified the ID of the view as declared in the plugin.xml file.

Open a perspective in a new window

Using the following code we can use a perspective in a separate window:



String myPerspectiveid = "dk.bording.viking.rcp.ui.till.editor.TillDesignerPerspective";
PlatformUI.getWorkbench().getActiveWorkbenchWindow().openPage(myPerspectiveid , null);

Sunday, August 24, 2014

Eclipse RCP: How to Hide or Remove a Contribution Item from a toolbar or Menubar

Using the following code we can hide or remove a Contribution item from a toolbar or menubar



private void hidePinbuttonFromPropertySheet() { IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IViewPart view = page.findView(IPageLayout.ID_PROP_SHEET);   String id = "";
if(view!=null)
{
for ( IContributionItem item : view.getViewSite().getActionBars().getToolBarManager().getItems()) {
if (item.getId().indexOf("PinPropertySheetAction")!=-1) { id = item.getId();
break;
}
}
view.getViewSite().getActionBars().getToolBarManager().remove(id);
view.getViewSite().getActionBars().getToolBarManager().update(false); } }


Thursday, May 2, 2013

PopertyTesters : Requesting Evaluation of Expressions

The command framework is quite lazy. It doesn't really care about your expressions and your wishes about when handlers should be enabled or not. It’s your duty to refresh the enabled state of your handlers by telling the IEvaluationService. It’s not wise to refresh the commands regularly as it can be quite expensive. Instead triggering the refresh on events is the way to go.

using the following code we can Request Evalueation of our Expressoin:


 protected void requestRefresh() {
  IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
  IEvaluationService evaluationService = (IEvaluationService) window.getService(IEvaluationService.class);
  if (evaluationService != null) {
   evaluationService.requestEvaluation(PROPERTY_NAMESPACE + "." + PROPERTY_CAN_FOO);
   evaluationService.requestEvaluation(PROPERTY_NAMESPACE + "." + PROPERTY_CAN_BAR);
  }
 }


More information can be found:
http://www.robertwloch.net/2011/01/eclipse-tips-tricks-property-testers-with-command-core-expressions/

Wednesday, January 2, 2013

Eclipse RCP : Execute a command programatically

using the folowing code we can execute a command in eclipse rcp:



IHandlerService handlerService = (IHandlerService) PlatformUI.getWorkbench().getService(IHandlerService.class);
try {
handlerService.executeCommand("org.eclipse.ui.ToggleCoolbarAction", null);
} catch (NotDefinedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (NotEnabledException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (NotHandledException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

5 Strategies for Getting More Work Done in Less Time

Summary.    You’ve got more to do than could possibly get done with your current work style. You’ve prioritized. You’ve planned. You’ve dele...