Package org.eclipse.php.internal.ui.actions

Source Code of org.eclipse.php.internal.ui.actions.ProjectActionGroup

/*******************************************************************************
* Copyright (c) 2009 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
*     IBM Corporation - initial API and implementation
*     Zend Technologies
*******************************************************************************/
package org.eclipse.php.internal.ui.actions;

import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionProvider;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.php.internal.ui.IContextMenuConstants;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IActionBars;
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.IWorkbenchSite;
import org.eclipse.ui.actions.ActionGroup;
import org.eclipse.ui.actions.CloseResourceAction;
import org.eclipse.ui.ide.IDEActionFactory;

;

/**
* Adds actions to open and close a project to the global menu bar.
*
* <p>
* This class may be instantiated; it is not intended to be subclassed.
* </p>
*
* @since 2.0
*/
public class ProjectActionGroup extends ActionGroup {

  private IWorkbenchSite fSite;

  private OpenProjectAction fOpenAction;
  private CloseResourceAction fCloseAction;

  /**
   * Creates a new <code>ProjectActionGroup</code>. The group requires that
   * the selection provided by the site's selection provider is of type <code>
   * org.eclipse.jface.viewers.IStructuredSelection</code>
   * .
   *
   * @param part
   *            the view part that owns this action group
   */
  public ProjectActionGroup(IViewPart part) {
    fSite = part.getSite();
    Shell shell = fSite.getShell();
    ISelectionProvider provider = fSite.getSelectionProvider();
    ISelection selection = provider.getSelection();

    fCloseAction = new CloseResourceAction(shell);
    fCloseAction
        .setActionDefinitionId("org.eclipse.ui.project.closeProject"); //$NON-NLS-1$
    fOpenAction = new OpenProjectAction(fSite);
    fOpenAction.setActionDefinitionId("org.eclipse.ui.project.openProject"); //$NON-NLS-1$
    if (selection instanceof IStructuredSelection) {
      IStructuredSelection s = (IStructuredSelection) selection;
      fOpenAction.selectionChanged(s);
      fCloseAction.selectionChanged(s);
    }
    provider.addSelectionChangedListener(fOpenAction);
    provider.addSelectionChangedListener(fCloseAction);
    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    workspace.addResourceChangeListener(fOpenAction);
    workspace.addResourceChangeListener(fCloseAction);
  }

  /*
   * (non-Javadoc) Method declared in ActionGroup
   */
  public void fillActionBars(IActionBars actionBars) {
    super.fillActionBars(actionBars);
    actionBars.setGlobalActionHandler(IDEActionFactory.CLOSE_PROJECT
        .getId(), fCloseAction);
    actionBars.setGlobalActionHandler(
        IDEActionFactory.OPEN_PROJECT.getId(), fOpenAction);
  }

  /*
   * (non-Javadoc) Method declared in ActionGroup
   */
  public void fillContextMenu(IMenuManager menu) {
    super.fillContextMenu(menu);
    if (fOpenAction.isEnabled())
      menu.appendToGroup(IContextMenuConstants.GROUP_BUILD, fOpenAction);
    if (fCloseAction.isEnabled())
      menu.appendToGroup(IContextMenuConstants.GROUP_BUILD, fCloseAction);
  }

  /*
   * @see ActionGroup#dispose()
   */
  public void dispose() {
    ISelectionProvider provider = fSite.getSelectionProvider();
    provider.removeSelectionChangedListener(fOpenAction);
    provider.removeSelectionChangedListener(fCloseAction);
    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    workspace.removeResourceChangeListener(fOpenAction);
    workspace.removeResourceChangeListener(fCloseAction);
    super.dispose();
  }
}
TOP

Related Classes of org.eclipse.php.internal.ui.actions.ProjectActionGroup

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.