org.eclipse.emf.mint.ui
Class AbstractOpenGeneratedMenu

java.lang.Object
  extended by org.eclipse.jface.action.ContributionItem
      extended by org.eclipse.ui.actions.CompoundContributionItem
          extended by org.eclipse.emf.mint.ui.AbstractOpenGeneratedMenu
All Implemented Interfaces:
IContributionItem, IWorkbenchContribution

public abstract class AbstractOpenGeneratedMenu
extends CompoundContributionItem
implements IWorkbenchContribution

Abstract base for dynamic menu contributions that provide actions to open generated artifacts related to the current selection, whatever it may be.

Clients may extend this class.


Nested Class Summary
protected static class AbstractOpenGeneratedMenu.DescriptorComparator
          Default comparator used for sorting java element descriptors.
 
Field Summary
protected  AdapterFactory adapterFactory
          Cached adapter factory reference.
protected  IServiceLocator serviceLocator
          Reference to the service locator obtained in initialize(IServiceLocator).
 
Constructor Summary
protected AbstractOpenGeneratedMenu()
          Default constructor.
protected AbstractOpenGeneratedMenu(String id)
          Constructs this menu with the given identifier.
 
Method Summary
protected  IAction createAction(IItemJavaElementDescriptor descriptor, Object target)
          Creates an action for opening a particular generated artifact for a given target object.
protected  AdapterFactory createAdapterFactory(Object target)
          Creates an instance of an adapter factory suitable for the given target.
protected  Comparator<? super IItemJavaElementDescriptor> createDescriptorComparator(Object target)
          Creates a comparator used for sorting the menu items.
 void dispose()
           
protected  AdapterFactory getAdapterFactory(Object target)
          Returns the adapter factory suitable for the given object.
protected  IContributionItem[] getContributionItems()
           
protected  int getMinCategoryItems()
          Returns the minimum number of menu items per category.
protected  Object getTarget(ISelection selection)
          Given the selection, returns the object whose generated artifacts to include in the menu.
 void initialize(IServiceLocator serviceLocator)
           
 
Methods inherited from class org.eclipse.ui.actions.CompoundContributionItem
fill, isDirty, isDynamic, setParent
 
Methods inherited from class org.eclipse.jface.action.ContributionItem
fill, fill, fill, getId, getParent, isEnabled, isGroupMarker, isSeparator, isVisible, saveWidgetState, setId, setVisible, toString, update, update
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

serviceLocator

protected IServiceLocator serviceLocator
Reference to the service locator obtained in initialize(IServiceLocator).


adapterFactory

protected AdapterFactory adapterFactory
Cached adapter factory reference.

Constructor Detail

AbstractOpenGeneratedMenu

protected AbstractOpenGeneratedMenu()
Default constructor.


AbstractOpenGeneratedMenu

protected AbstractOpenGeneratedMenu(String id)
Constructs this menu with the given identifier.

Parameters:
id - menu identifier
Method Detail

initialize

public void initialize(IServiceLocator serviceLocator)
Specified by:
initialize in interface IWorkbenchContribution

getContributionItems

protected final IContributionItem[] getContributionItems()
Specified by:
getContributionItems in class CompoundContributionItem

getTarget

protected Object getTarget(ISelection selection)
Given the selection, returns the object whose generated artifacts to include in the menu. Clients may override to "unwrap" the selection in a model-specific way. By default, the first element of the structured selection is returned.

Parameters:
selection - current selection
Returns:
object whose artifacts to collect

getAdapterFactory

protected AdapterFactory getAdapterFactory(Object target)
Returns the adapter factory suitable for the given object. The default implementation calls createAdapterFactory(Object) the first time this method is called, caches the result in adapterFactory and returns it on every subsequent call (regardless of the target).

Parameters:
target - object for which to get the adapter factory
Returns:
adapter factory suitable for the given object

createAdapterFactory

protected AdapterFactory createAdapterFactory(Object target)
Creates an instance of an adapter factory suitable for the given target. The default implementation creates a composed adapter factory using the global descriptor registry.

Parameters:
target - object for which to create the adapter factory
Returns:
newly created adapter factory

createDescriptorComparator

protected Comparator<? super IItemJavaElementDescriptor> createDescriptorComparator(Object target)
Creates a comparator used for sorting the menu items. The default implementation returns a new AbstractOpenGeneratedMenu.DescriptorComparator.

Parameters:
target - object for which to create the comparator
Returns:
new comparator

getMinCategoryItems

protected int getMinCategoryItems()
Returns the minimum number of menu items per category. The default is 2.

Returns:
minimum number of menu items per category

createAction

protected IAction createAction(IItemJavaElementDescriptor descriptor,
                               Object target)
Creates an action for opening a particular generated artifact for a given target object.

Parameters:
descriptor - descriptor representing the artifact to open
target - object whose artifact to open
Returns:
action to open the given artifact

dispose

public void dispose()
Specified by:
dispose in interface IContributionItem
Overrides:
dispose in class ContributionItem

Copyright 2008, 2009 Ecliptical Software Inc. and others.
All Rights Reserved.