blob: 4576a75865af2a23f2d61c8366fd790cba9939e9 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
/*******************************************************************************
* Copyright (c) 2006, 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
******************************************************************************/
package org.eclipse.ui.internal.handlers;
import java.util.Iterator;
import org.eclipse.core.expressions.Expression;
import org.eclipse.ui.handlers.IHandlerActivation;
import org.eclipse.ui.handlers.IHandlerService;
import org.eclipse.ui.internal.services.INestable;
/**
* <p>
* A handler service which delegates almost all responsibility to the parent
* service. It is capable of being nested inside a component that is not
* recognizable by the "sources" event mechanism. This means that the handlers
* must be activated and deactivated manually.
* </p>
* <p>
* This class is not intended for use outside of the
* <code>org.eclipse.ui.workbench</code> plug-in.
* </p>
*
* @since 3.2
*/
public final class NestableHandlerService extends SlaveHandlerService implements
INestable {
/**
* Whether the component with which this service is associated is active.
*/
private boolean active = false;
/**
* Constructs a new instance.
*
* @param parentHandlerService
* The parent handler service for this slave; must not be
* <code>null</code>.
* @param defaultExpression
* The default expression to use if none is provided. This is
* primarily used for conflict resolution. This value may be
* <code>null</code>.
*/
public NestableHandlerService(final IHandlerService parentHandlerService,
final Expression defaultExpression) {
super(parentHandlerService, defaultExpression);
}
public final void activate() {
if (active) {
return;
}
final Iterator localActivationItr = localActivationsToParentActivations
.keySet().iterator();
while (localActivationItr.hasNext()) {
final Object object = localActivationItr.next();
if (object instanceof IHandlerActivation) {
final IHandlerActivation localActivation = (IHandlerActivation) object;
super.doActivation(localActivation);
}
}
active = true;
}
protected final IHandlerActivation doActivation(
final IHandlerActivation localActivation) {
if (active) {
return super.doActivation(localActivation);
}
localActivationsToParentActivations.put(localActivation, null);
return localActivation;
}
public final void deactivate() {
if (!active) {
return;
}
deactivateHandlers(parentActivations);
parentActivations.clear();
final Iterator localActivationItr = localActivationsToParentActivations
.keySet().iterator();
while (localActivationItr.hasNext()) {
final Object object = localActivationItr.next();
localActivationsToParentActivations.put(object, null);
}
active = false;
}
}
|