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

Copy Resources from Eclipse Plug-in to Local File System

If we need to read a resource from an eclipse plugin and want to save it to local file system we can use following code :





















Following code will copy basicTemplate.diagram to local-file system:


private void copyTemplateToLocalDirectory() {

URI diagramTemplateFileUri = URI.createPlatformPluginURI(
"/dk.bording.viking.rcp.ui.till.editor/templates/basicTemplate.diagram", true);

URIConverter uriConverter = new ExtensibleURIConverterImpl();
try {

InputStream infile =  uriConverter.createInputStream(diagramTemplateFileUri);
FileOutputStream file = new FileOutputStream( new File(Platform.getInstanceLocation().getURL().getPath()+File.separator+NewFileName.diagram"));
file.write(ByteStreams.toByteArray(infile));
file.close();

} catch (IOException e1) {

e1.printStackTrace();
}

}





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();
}

Tuesday, September 25, 2012

List of all available plug in for eclipse

If you need list of all the available plug-in available for eclipse platform please visit the following website:

http://www.eclipseplugincentral.com/



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...