Menu

EmfRcpPlugin

Tom Swain

Eclipse EMF RCP Plugin Development

Transition to RCP Development

Initial RCP Creation

Do the following for jemf and testemf plugins:

  1. In jemf.genmodel and testemf.genmodel, change property Rich Client Platform (in the Editor category) to True.
  2. Backup, then Delete, plugin.xml and MANIFEST.MF for both plugins.
  3. Regenerate all code. For both plugins:
    a. Open the *.genmodel editor.
    b. Right click the root object and select Generate All.
  4. For plugin.xml and MANIFEST.MF in both plugins,
    a. Right click and select Compare With->Latest from Repository.
    b. Use the Source Compare window to copy extension points and other elements lost in steps 2 and 3.
  5. Fix import errors by importing any needed packages.
  6. In getFileExtensionFilters() in the new files TestemfEditorAdvisor.java and JemfEditorAdvisor.java, change result.addAll(EcoreEditor.FILE_EXTENSION_FILTERS) to result.add(EcoreEditor.ECORE_FILE_EXTENSION).

Resource and Package Registration

In TestemfEditorAdvisor.initialize(), append the following:

    // register resource factories
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("testemf", new XMIResourceFactoryImpl());
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("tst", new TstResourceFactoryImpl());
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("emf", new XMIResourceFactoryImpl());
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("html", new MmaResourceFactoryImpl());
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("tml", new TmlResourceFactoryImpl());
// cause the package to be registered
TestemfPackage testemfPackage = TestemfPackage.eINSTANCE;
EmfPackage emfPackage = EmfPackage.eINSTANCE;

Top Level Menu Setup

Prep

  1. Open editor for plugin.xml.
  2. Select the Extensions tab.

Create the Commands

  1. Add extension point org.eclipse.ui.commands.
  2. Right-click org.eclipse.ui.commands and select New->category.
  3. Set the id (e.g, edu.utk.sqrl.emf.commands.category), name, and description fields.
  4. For all commands to be implemented,
    a. Right-click org.eclipse.ui.commands and select New->command.
    b. Set the id field to something like edu.utk.sqrl.emf.commands.cmd, where cmd is the command name in lower case.
    c. Set the name and description fields.
    d. Set categoryid to the id entered in item 3 above.

Create the Menu

  1. Add extension point org.eclipse.ui.menus.
  2. Right-click org.eclipse.ui.menus and select New->menuContribution.
  3. Set locationURI to menu:org.eclipse.ui.main.menu?after=additions.
  4. Right-click the menuContribution and select New->menu.
  5. Set the label, id (e.g., edu.utk.sqrl.emf.menus.main), and mnemonic fields.
  6. For each desired menu selection,
    a. Right-click the menu entry and select New->command.
    b. Set commandId field to the id of the corresponding command defined above.
    c. Set the id field to something like edu.utk.sqrl.emf.menus.cmd, where cmd is the command name in lower case.
    d. Set the mnemonic field.

Create Handlers

  1. Add extension point org.eclipse.ui.handlers.
  2. For each required command handler,
    a. Right-click org.eclipse.ui.handlers and select New->handler.
    b. Set the commandId field to the corresponding command id defined above.
    c. Set the class field to the full name of the class (e.g., edu.utk.sqrl.emf.handlers.CheckModel) that will process this command.
    d. Right-click the handler and create an activeWhen expression.
    e. Right-click the handler and create an enabledWhen expression.
  3. If the handler class specified in 2c does not exist already, clicking the class link will generate it.
    a. The required action must be implemented in the execute() method.
    b. The isEnabled() and isHandled() methods must return true to activate the associated menu item.

Note: If a menu item is used by a plug-in higher in the dependency hierarchy AND activeWhen and enabledWhen expressions are needed for that menu item, then an equivalent handler extension point must be added to the using plug-in.

Removing "Open File..." from the File Menu

Caveat: This is useful to know but turned out to be the wrong thing to do for ESTA'. It turned out to be better to eliminate the generated File->Open... extension point because Open File... gives you access to Eclipse built in editors (e.g., text and html), while Open... is just configured for EMF generated file types. Removing Open... requires removing the associated action from the org.eclipse.ui.actionSets extension point and the associated command from the org.eclipse.ui.commands extension point (both in plugin.xml).

Anyway, here is the way to remove Open File...:

In the editor advisor class there should be a static WindowAdvisor subclass. Just add the postWindowCreate method below to the WindowAdvisor.

@Override
public void postWindowCreate() {
    super.postWindowCreate();
    // Find and remove the "Open File" menu item.
    //
    IMenuManager menuManager = getWindowConfigurer().getActionBarConfigurer().getMenuManager();
    IContributionItem[] menuItems = menuManager.getItems();
    // For each menu item, check the class.
    //
    for (int i = 0; i < menuItems.length; i++) {
        IContributionItem menuItem = menuItems[i];
        // If this is a menu manager, then check the id.
        //
        if (menuItem instanceof MenuManager) {  
            // If this is the file menu, then remove the "Open File" menu action.
            //
            if (menuItem.getId().equals("file")) {
                ((MenuManager) menuItem).remove("org.eclipse.ui.openLocalFile");
            }
        }
    }
    }

MongoDB Logo MongoDB