KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > ShowViewMenuHandler


1 /*******************************************************************************
2  * Copyright (c) 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  ******************************************************************************/

11
12 package org.eclipse.ui.internal;
13
14 import org.eclipse.core.commands.ExecutionEvent;
15 import org.eclipse.core.commands.ExecutionException;
16 import org.eclipse.core.expressions.EvaluationResult;
17 import org.eclipse.core.expressions.Expression;
18 import org.eclipse.core.expressions.ExpressionInfo;
19 import org.eclipse.core.expressions.IEvaluationContext;
20 import org.eclipse.core.runtime.CoreException;
21 import org.eclipse.ui.ISources;
22 import org.eclipse.ui.IWorkbenchPart;
23 import org.eclipse.ui.IWorkbenchPartSite;
24 import org.eclipse.ui.handlers.HandlerUtil;
25
26 /**
27  * Shows the View Menu
28  * <p>
29  * Replacement for: ShowViewMenuAction
30  * </p>
31  *
32  * @since 3.3
33  *
34  */

35 public class ShowViewMenuHandler extends AbstractEvaluationHandler {
36
37     private Expression enabledWhen;
38
39     public ShowViewMenuHandler() {
40         registerEnablement();
41     }
42
43     /*
44      * (non-Javadoc)
45      *
46      * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
47      */

48     public Object JavaDoc execute(ExecutionEvent event) throws ExecutionException {
49
50         IWorkbenchPart part = HandlerUtil.getActivePart(event);
51         if (part != null) {
52             IWorkbenchPartSite site = part.getSite();
53             if (site instanceof PartSite) {
54                 PartPane pane = ((PartSite) site).getPane();
55                 pane.showPaneMenu();
56             }
57         }
58         return null;
59     }
60
61     /*
62      * (non-Javadoc)
63      *
64      * @see org.eclipse.ui.internal.AbstractEvaluationHandler#getEnabledWhenExpression()
65      */

66     protected Expression getEnabledWhenExpression() {
67         // TODO Auto-generated method stub
68
if (enabledWhen == null) {
69             enabledWhen = new Expression() {
70                 public EvaluationResult evaluate(IEvaluationContext context)
71                         throws CoreException {
72                     IWorkbenchPart part = InternalHandlerUtil
73                             .getActivePart(context);
74                     if (part != null) {
75                         PartPane pane = ((PartSite) part.getSite()).getPane();
76                         if ((pane instanceof ViewPane)
77                                 && ((ViewPane) pane).hasViewMenu()) {
78                             return EvaluationResult.TRUE;
79                         }
80                     }
81                     return EvaluationResult.FALSE;
82                 }
83
84                 /*
85                  * (non-Javadoc)
86                  *
87                  * @see org.eclipse.core.expressions.Expression#collectExpressionInfo(org.eclipse.core.expressions.ExpressionInfo)
88                  */

89                 public void collectExpressionInfo(ExpressionInfo info) {
90                     info.addVariableNameAccess(ISources.ACTIVE_PART_NAME);
91                 }
92             };
93         }
94         return enabledWhen;
95     }
96
97 }
98
Popular Tags