Yeni adresim http://doganberktas.com

6 Nisan 2009 Pazartesi

Creating Eclipse RCP Toolbars with Custom Actions

There are two ways to create a toolbar in Eclipse RCP. One of this methods is using Actions. In the first post I use predefined actions for creating a toolbar. This post will examplify using custom actions inside code for creating toolbars. 

1. Create an RCP project (see Howto Create an RCP project)

2. Open ApplicationWorkbenchWindowAdvisor class and changed  preWindowOpen method as follows

public void preWindowOpen()
{
IWorkbenchWindowConfigurer configurer = getWindowConfigurer();
configurer.setInitialSize(new Point(400, 300));
configurer.setShowCoolBar(true);
configurer.setShowStatusLine(false);
}

3. Open ApplicationWorkbenchWindowAdvisor class and change it as follows 


public class ApplicationActionBarAdvisor extends ActionBarAdvisor
{
Action myAction;

public ApplicationActionBarAdvisor(IActionBarConfigurer configurer)
{
super(configurer);
}

protected void makeActions(IWorkbenchWindow window)
{
myAction = new Action("jkjnkjn", null)
{
@Override
public void run()
{
System.out.println("custom action is called!");
}
};
}

@Override
protected void fillCoolBar(ICoolBarManager coolBar)
{
// This will add a new toolbar to the application
IToolBarManager toolbar = new ToolBarManager(SWT.FLAT | SWT.RIGHT);
coolBar.add(new ToolBarContributionItem(toolbar, "main"));

toolbar.add(myAction);
}
}

4. Run the project as an Eclipse Application 

0 yorum: