Search code examples
buttoneclipse-plugineclipse-pde

How do I create this button in an eclipse plugin


Inside my eclipse plugin I want to create this button in a composite:

alt text

Where do I get the icon? How do I create that button?


Solution

  • Here's the solution I found by digging a little deeper...

    Create an IAction:

    private class RemoveCurrentGraphAction extends Action {
        @Override
        public void run() {
            updateWith(new ModuleGraph());
        }
    
        public RemoveCurrentGraphAction() {
            setToolTipText("Reset to empty graph");
        }
    
        @Override
        public int getStyle() {
            return IAction.AS_PUSH_BUTTON;
        }
    
        @Override
        public ImageDescriptor getImageDescriptor() {
            return PlatformUI.getWorkbench().getSharedImages()
                    .getImageDescriptor(org.eclipse.ui.ISharedImages.IMG_ELCL_REMOVE);
        }
    }
    

    Then when creating the view, add the action to the toolbar:

    IActionBars bars = getViewSite().getActionBars();
    bars.getToolBarManager().add(new RemoveCurrentGraphAction());