capint
1/11/2016 - 11:12 AM

Eclipse >> Common Navigator Framework >> Action Provider

Eclipse >> Common Navigator Framework >> Action Provider

>> Step 1: Register the Action Provider with the CNF
<extension
         name="Capella Project Explorer"
         point="org.eclipse.ui.navigator.navigatorContent">
  <navigatorContent
    ...>
    <actionProvider
               class="org.polarsys.capella.core.platform.sirius.ui.navigator.actions.providers.EditCommonActionProvider"
               id="capella.project.explorer.editContributor">
            <enablement> ...

>> Step 2: Extends the CommonActionProvider class, 
public class EditCommonActionProvider extends CommonActionProvider {
  @Override
  public void dispose() {
    ISelectionProvider selectionProvider = getActionSite().getViewSite().getSelectionProvider();
    if (null != _cutAction) {
      selectionProvider.removeSelectionChangedListener(_cutAction);
      _cutAction = null;
    }
  
  @Override
  public void fillActionBars(IActionBars actionBars) {
    actionBars.setGlobalActionHandler(ActionFactory.CUT.getId(), _cutAction);
    
   @Override
  public void fillContextMenu(IMenuManager menu) {
    menu.appendToGroup(ICommonMenuConstants.GROUP_EDIT, _cutAction);
  
   @Override
  public void init(ICommonActionExtensionSite site) {
    super.init(site);
    //*** Get the view site
    ICommonViewerSite commonViewSite = site.getViewSite();
    if (!(commonViewSite instanceof ICommonViewerWorkbenchSite)) {
      return;
    }
    
    ICommonViewerWorkbenchSite commonViewerWorkbenchSite = (ICommonViewerWorkbenchSite) commonViewSite;

    // *** Get the active part.
    CapellaCommonNavigator activePart = (CapellaCommonNavigator) commonViewerWorkbenchSite.getPart();

    // Get the shared images.
    ISharedImages sharedImages = PlatformUI.getWorkbench().getSharedImages();
    
    // Get the selection provider
    ISelectionProvider selectionProvider = commonViewSite.getSelectionProvider();
    
    // Set up the action
    _sortSelection = new SortSelectionAction();
    // Register the action with the selection provider
    selectionProvider_p.addSelectionChangedListener(action_p);
    // selectionChanged needs to be fired mannually the first time. The next time, the view takes care of this
    ISelection selection = selectionProvider_p.getSelection();
    if (!selection.isEmpty()) {
      action_p.selectionChanged(new SelectionChangedEvent(selectionProvider_p, selection));
    }