RCP ViewPart Wizard

Subclasses of the RCP ViewPart class can be created using the RCP ViewPart wizard. The wizard can be selected from the drop down wizard menu or from the Eclipse New wizard.

To use the wizard, select the project source folder and package to contain the class. Then enter the class name, view name/title and hit the Finish button.


 


The wizard generates the following code.

import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.IToolBarManager;

import
org.eclipse.swt.SWT;
import
org.eclipse.swt.widgets.Composite;
import
org.eclipse.ui.part.ViewPart;

public
class RcpViewPart extends ViewPart {

    public
static final String ID = "com.test.RcpViewPart";
//$NON-NLS-1$

    public RcpViewPart() {
    }

    @Override
    public void createPartControl(Composite parent) {
        Composite container = new Composite(parent, SWT.NONE);

        createActions();
        // Uncomment if you wish to add code to initialize the toolbar         //initializeToolBar();
        initializeMenu();

    }

    private void createActions() {
        // Create the actions
    }

    private void initializeToolBar() {
        IToolBarManager toolbarManager=getViewSite().getActionBars().getToolBarManager();
           
    }

    private void initializeMenu() {
        IMenuManager menuManager = getViewSite().getActionBars().getMenuManager();
          
    }

    @Override
    public void setFocus() {
        // set the focus
    }
}

When editing RCP ViewParts, all of the standard SWT layouts, containers and widgets are available.

If the ViewPart is created in an existing plugin project, the plugin.xml file is also updated with the appropriate view declaration.

When editing ViewParts, SWT Designer adds a new Palette category, JFace Actions, for defining actions and assigning them to the view's toolbar and menu.

New actions may be created using the New command, and existing actions may be added using the External command. New actions are created as inner classes of the current class and are automatically added to the palette for easy access. Any existing actions may be deleted using the Delete key. Selecting an action allows you to edit its icons, label and tool tip text within the property pane. 

The view's toolbar is live and actions may be dropped on it. Actions and separators may be dragged from the palette and dropped on the toolbar. Toolbar actions may be rearranged using drag/drop and deleted using the Delete key.

The view's menu is also live and actions may be dropped on it. Actions, separators and menu managers may be dragged from the palette and dropped into the menu. Menus may be rearranged using drag/drop and deleted using the Delete key.

When the ViewPart itself is selected in the property pane, its name and icon may be edited as part of the Extension property.