Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 137091 | Differences between
and this patch

Collapse All | Expand All

(-)Eclipse UI/org/eclipse/ui/internal/EditorReference.java (-1 / +1 lines)
Lines 405-411 Link Here
405
            
405
            
406
            EditorSite site = new EditorSite(this, part, manager.page, descr);
406
            EditorSite site = new EditorSite(this, part, manager.page, descr);
407
            
407
            
408
            site.setActionBars(new EditorActionBars(manager.page, site, getId()));
408
            site.setActionBars(new EditorActionBars(manager.page, site.getWorkbenchWindow(), getId()));
409
            try {
409
            try {
410
                part.init(site, input);
410
                part.init(site, input);
411
            } catch (PartInitException e) {
411
            } catch (PartInitException e) {
(-)Eclipse UI/org/eclipse/ui/internal/EditorActionBars.java (-1 / +16 lines)
Lines 10-15 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.ui.internal;
11
package org.eclipse.ui.internal;
12
12
13
import org.eclipse.core.expressions.Expression;
13
import org.eclipse.jface.action.ActionContributionItem;
14
import org.eclipse.jface.action.ActionContributionItem;
14
import org.eclipse.jface.action.ContributionManager;
15
import org.eclipse.jface.action.ContributionManager;
15
import org.eclipse.jface.action.GroupMarker;
16
import org.eclipse.jface.action.GroupMarker;
Lines 31-36 Link Here
31
import org.eclipse.ui.IWorkbenchPart;
32
import org.eclipse.ui.IWorkbenchPart;
32
import org.eclipse.ui.SubActionBars2;
33
import org.eclipse.ui.SubActionBars2;
33
import org.eclipse.ui.actions.RetargetAction;
34
import org.eclipse.ui.actions.RetargetAction;
35
import org.eclipse.ui.internal.expressions.LegacyEditorActionBarExpression;
34
import org.eclipse.ui.internal.misc.Policy;
36
import org.eclipse.ui.internal.misc.Policy;
35
import org.eclipse.ui.internal.provisional.presentations.IActionBarPresentationFactory;
37
import org.eclipse.ui.internal.provisional.presentations.IActionBarPresentationFactory;
36
import org.eclipse.ui.services.IServiceLocator;
38
import org.eclipse.ui.services.IServiceLocator;
Lines 89-94 Link Here
89
	
91
	
90
	private IActionBarPresentationFactory actionBarPresentation;
92
	private IActionBarPresentationFactory actionBarPresentation;
91
93
94
92
	/**
95
	/**
93
	 * Constructs the EditorActionBars for an editor.
96
	 * Constructs the EditorActionBars for an editor.
94
	 */
97
	 */
Lines 327-333 Link Here
327
		super.partChanged(part);
330
		super.partChanged(part);
328
		if (part instanceof IEditorPart) {
331
		if (part instanceof IEditorPart) {
329
			IEditorPart editor = (IEditorPart) part;
332
			IEditorPart editor = (IEditorPart) part;
330
			setServiceLocator(editor.getEditorSite());
331
			if (editorContributor != null) {
333
			if (editorContributor != null) {
332
				editorContributor.setActiveEditor(editor);
334
				editorContributor.setActiveEditor(editor);
333
			}
335
			}
Lines 470-473 Link Here
470
			}
472
			}
471
		}
473
		}
472
	}
474
	}
475
476
	private LegacyEditorActionBarExpression editorHandlerExpression = null;
477
	
478
	/**
479
	 * Returns the expression used for action handler activation.
480
	 * @return the expression used for action handler activation.
481
	 */
482
	public Expression getHandlerExpression() {
483
		if (editorHandlerExpression == null) {
484
			editorHandlerExpression = new LegacyEditorActionBarExpression(type);
485
		}
486
		return editorHandlerExpression;
487
	}
473
}
488
}
(-)Eclipse UI/org/eclipse/ui/internal/EditorManager.java (-2 / +2 lines)
Lines 301-307 Link Here
301
		}
301
		}
302
302
303
		// Create a new action bar set.
303
		// Create a new action bar set.
304
		actionBars = new EditorActionBars(page, site, type);
304
		actionBars = new EditorActionBars(page, site.getWorkbenchWindow(), type);
305
		actionBars.addRef();
305
		actionBars.addRef();
306
		actionCache.put(type, actionBars);
306
		actionCache.put(type, actionBars);
307
307
Lines 333-339 Link Here
333
333
334
		// Create a new action bar set.
334
		// Create a new action bar set.
335
		// Note: It is an empty set.
335
		// Note: It is an empty set.
336
		EditorActionBars actionBars = new EditorActionBars(page, site, type);
336
		EditorActionBars actionBars = new EditorActionBars(page, site.getWorkbenchWindow(), type);
337
		actionBars.addRef();
337
		actionBars.addRef();
338
		actionCache.put(type, actionBars);
338
		actionCache.put(type, actionBars);
339
339
(-)Eclipse UI/org/eclipse/ui/SubActionBars.java (-1 / +6 lines)
Lines 33-38 Link Here
33
import org.eclipse.jface.util.PropertyChangeEvent;
33
import org.eclipse.jface.util.PropertyChangeEvent;
34
import org.eclipse.ui.handlers.IHandlerActivation;
34
import org.eclipse.ui.handlers.IHandlerActivation;
35
import org.eclipse.ui.handlers.IHandlerService;
35
import org.eclipse.ui.handlers.IHandlerService;
36
import org.eclipse.ui.internal.EditorActionBars;
36
import org.eclipse.ui.internal.WorkbenchPlugin;
37
import org.eclipse.ui.internal.WorkbenchPlugin;
37
import org.eclipse.ui.internal.handlers.IActionCommandMappingService;
38
import org.eclipse.ui.internal.handlers.IActionCommandMappingService;
38
import org.eclipse.ui.internal.services.SourcePriorityNameMapping;
39
import org.eclipse.ui.internal.services.SourcePriorityNameMapping;
Lines 504-512 Link Here
504
					// the expression gives the setGlobalActionHandler() a
505
					// the expression gives the setGlobalActionHandler() a
505
					// priority.
506
					// priority.
506
					final IHandler actionHandler = new ActionHandler(handler);
507
					final IHandler actionHandler = new ActionHandler(handler);
508
					Expression handlerExpression = EXPRESSION;
509
					//XXX add new API in next release to avoid down-casting (bug 137091)
510
					if (this instanceof EditorActionBars)
511
						handlerExpression = ((EditorActionBars)this).getHandlerExpression();
507
					final IHandlerActivation activation = service
512
					final IHandlerActivation activation = service
508
							.activateHandler(commandId, actionHandler,
513
							.activateHandler(commandId, actionHandler,
509
									EXPRESSION);
514
									handlerExpression);
510
					activationsByActionId.put(actionID, activation);
515
					activationsByActionId.put(actionID, activation);
511
				}
516
				}
512
			}
517
			}
(-)Eclipse (+103 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 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.expressions;
13
14
import org.eclipse.core.expressions.EvaluationResult;
15
import org.eclipse.core.expressions.Expression;
16
import org.eclipse.core.expressions.ExpressionInfo;
17
import org.eclipse.core.expressions.IEvaluationContext;
18
import org.eclipse.ui.ISources;
19
import org.eclipse.ui.internal.services.SourcePriorityNameMapping;
20
21
/**
22
 * <p>
23
 * An expression representing the <code>part id</code> of the legacy editor
24
 * action bar contribution.
25
 * </p>
26
 * <p>
27
 * This class is not intended for use outside of the
28
 * <code>org.eclipse.ui.workbench</code> plug-in.
29
 * </p>
30
 * 
31
 * @since 3.2
32
 */
33
public class LegacyEditorActionBarExpression extends Expression {
34
	/**
35
	 * The seed for the hash code for all schemes.
36
	 */
37
	private static final int HASH_INITIAL = LegacyEditorActionBarExpression.class
38
			.getName().hashCode();
39
40
	/**
41
	 * The identifier for the editor that must be active for this expression to
42
	 * evaluate to <code>true</code>. This value is never <code>null</code>.
43
	 */
44
	private final String activeEditorId;
45
46
	/**
47
	 * Constructs a new instance of <code>LegacyEditorActionBarExpression</code>
48
	 * 
49
	 * @param activeEditorId
50
	 *            The identifier of the editor to match with the active editor;
51
	 *            must not be <code>null</code>
52
	 */
53
	public LegacyEditorActionBarExpression(final String activeEditorId) {
54
55
		if (activeEditorId == null) {
56
			throw new NullPointerException(
57
					"The targetId for an editor contribution must not be null"); //$NON-NLS-1$
58
		}
59
		this.activeEditorId = activeEditorId;
60
	}
61
62
	public final void collectExpressionInfo(final ExpressionInfo info) {
63
		info.addVariableNameAccess(ISources.ACTIVE_EDITOR_ID_NAME);
64
		info
65
				.addVariableNameAccess(SourcePriorityNameMapping.LEGACY_LEGACY_NAME);
66
	}
67
68
	protected final int computeHashCode() {
69
		int hashCode = HASH_INITIAL * HASH_FACTOR + hashCode(activeEditorId);
70
		return hashCode;
71
	}
72
73
	public final boolean equals(final Object object) {
74
		if (object instanceof LegacyEditorActionBarExpression) {
75
			final LegacyEditorActionBarExpression that = (LegacyEditorActionBarExpression) object;
76
			return equals(activeEditorId, that.activeEditorId);
77
		}
78
79
		return false;
80
	}
81
82
	/*
83
	 * (non-Javadoc)
84
	 * 
85
	 * @see org.eclipse.core.expressions.Expression#evaluate(org.eclipse.core.expressions.IEvaluationContext)
86
	 */
87
	public final EvaluationResult evaluate(final IEvaluationContext context) {
88
		final Object variable = context
89
				.getVariable(ISources.ACTIVE_EDITOR_ID_NAME);
90
		if (equals(activeEditorId, variable)) {
91
			return EvaluationResult.TRUE;
92
		}
93
		return EvaluationResult.FALSE;
94
	}
95
96
	public final String toString() {
97
		final StringBuffer buffer = new StringBuffer();
98
		buffer.append("LegacyEditorActionBarExpression("); //$NON-NLS-1$
99
		buffer.append(activeEditorId);
100
		buffer.append(')');
101
		return buffer.toString();
102
	}
103
}

Return to bug 137091