Package org.eclipse.ui.internal

Source Code of org.eclipse.ui.internal.ShowPartPaneMenuHandler

/*******************************************************************************
* Copyright (c) 2007 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
******************************************************************************/

package org.eclipse.ui.internal;

import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.expressions.EvaluationResult;
import org.eclipse.core.expressions.Expression;
import org.eclipse.core.expressions.ExpressionInfo;
import org.eclipse.core.expressions.IEvaluationContext;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.ui.ISources;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IWorkbenchPartSite;
import org.eclipse.ui.handlers.HandlerUtil;

/**
* Show the menu on top of the icon in the view or editor label.
* <p>
* Replacement for ShowPartPaneMenuAction
* </p>
*
* @since 3.3
*/
public class ShowPartPaneMenuHandler extends AbstractEvaluationHandler {

  private Expression enabledWhen;

  public ShowPartPaneMenuHandler() {
    registerEnablement();
  }

  public Object execute(ExecutionEvent event) throws ExecutionException {

    IWorkbenchPart part = HandlerUtil.getActivePart(event);
    if (part != null) {
      IWorkbenchPartSite site = part.getSite();
      if (site instanceof PartSite) {
        PartPane pane = ((PartSite) site).getPane();
        pane.showSystemMenu();
      }
    }
    return null;
  }

  /*
   * (non-Javadoc)
   *
   * @see org.eclipse.ui.internal.AbstractEvaluationHandler#getEnabledWhenExpression()
   */
  protected Expression getEnabledWhenExpression() {
    if (enabledWhen == null) {
      enabledWhen = new Expression() {
        public EvaluationResult evaluate(IEvaluationContext context)
            throws CoreException {
          IWorkbenchPart part = InternalHandlerUtil
              .getActivePart(context);

          if (part != null) {
            return EvaluationResult.TRUE;
          }
          return EvaluationResult.FALSE;
        }

        /*
         * (non-Javadoc)
         *
         * @see org.eclipse.core.expressions.Expression#collectExpressionInfo(org.eclipse.core.expressions.ExpressionInfo)
         */
        public void collectExpressionInfo(ExpressionInfo info) {
          info.addVariableNameAccess(ISources.ACTIVE_PART_NAME);
        }
      };
    }
    return enabledWhen;
  }
}
TOP

Related Classes of org.eclipse.ui.internal.ShowPartPaneMenuHandler

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.