Add Toolbar in eclipse rcp application

2019-07-20 20:10发布

I want to add toolbar in eclipse rcp application, i tried to write the code in fillCoolBar function in ActionBarAdvisor.java and also using extensions. But the extensions provided by other plugins is not aligned properly. My guess is that the names of various toolbarManager inside the toolbar is not proper. Anyone can tell me how to add all the icons so that the extra icons added by other plugins and added by me are aligned properly? Every time i restart or open a new work-space the icons spacing changes! I have attached a image of the problem.

Coolbar problem in eclipse application

The code in fillCoolBar is as follows:

@Override
protected void fillCoolBar(ICoolBarManager coolBar){
        IToolBarManager fileToolbar1 = new ToolBarManager(SWT.WRAP);
        fileToolbar1.add(new Separator(IWorkbenchActionConstants.NEW_GROUP));
        fileToolbar1.add(newDropDownAction);
        fileToolbar1.add(new GroupMarker(IWorkbenchActionConstants.NEW_EXT));
        fileToolbar1.add(new GroupMarker(IWorkbenchActionConstants.SAVE_GROUP));
        fileToolbar1.add(saveFileAction);
        fileToolbar1.add(saveAllFilesAction);
        fileToolbar1.add(new GroupMarker(IWorkbenchActionConstants.SAVE_EXT));
        fileToolbar1.add(printAction);
        fileToolbar1.add(new GroupMarker(IWorkbenchActionConstants.PRINT_EXT));
        coolBar.add(fileToolbar1);
}

1条回答
萌系小妹纸
2楼-- · 2019-07-20 20:21

Figured it out. Need to add CSS styling to it. Take following steps:

1. Open plugin.xml
2. Add extension org.eclipse.e4.ui.css.swt.theme
   2.1 Add Theme to above extension.
      2.1.2 Basestyleurl is relative path to css file, like css/theme.css
      2.1.2 Give a id like plugin.theme [id can be anything]
      2.1.3 Fill rest of the fields
3. In extension org.eclipse.core.runtime.products , the one that has your product
   3.1 Add a property
      3.1.1 name: cssTheme [do not change]
      3.1.2 value: id given in step 2.1.2
   3.2 Add a property
      3.2.1 name: applicationCSSResources
      3.2.2 value: platform:/plugin/plugin.name/images/ 
[inside plugin i have images folder which has all essential images for my css, you can see images used by eclipse css theme in eclipse\plugins\org.eclipse.platform_4.3.0.v20130605-2000\images and the css used is inside css folder ]

And thats it ! Done :)

查看更多
登录 后发表回答