KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > contexts > NestableContextService


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.contexts;
13
14 import java.util.Iterator JavaDoc;
15
16 import org.eclipse.core.expressions.Expression;
17 import org.eclipse.ui.contexts.IContextActivation;
18 import org.eclipse.ui.contexts.IContextService;
19 import org.eclipse.ui.internal.services.INestable;
20
21 /**
22  * <p>
23  * A context service which delegates almost all responsibility to the parent
24  * service. This service is capable of being nested inside a component that is
25  * not recognized by the "source" event mechanism.
26  * </p>
27  * <p>
28  * This class is not intended for use outside of the
29  * <code>org.eclipse.ui.workbench</code> plug-in.
30  * </p>
31  *
32  * @since 3.2
33  */

34 public class NestableContextService extends SlaveContextService implements
35         INestable {
36     /**
37      * Maintain the state of the context service.
38      */

39     private boolean fActive;
40
41     /**
42      * Construct the new nested slave context.
43      *
44      * @param parentService
45      * the parent context service; must not be <code>null</code>.
46      * @param defaultExpression
47      * A default expression to use to determine viability. It's
48      * mainly used for conflict resolution. It can be
49      * <code>null</code>.
50      */

51     public NestableContextService(IContextService parentService,
52             Expression defaultExpression) {
53         super(parentService, defaultExpression);
54         fActive = false;
55     }
56
57     /*
58      * (non-Javadoc)
59      *
60      * @see org.eclipse.ui.internal.contexts.SlaveContextService#doActivateContext(org.eclipse.ui.contexts.IContextActivation)
61      */

62     protected IContextActivation doActivateContext(IContextActivation activation) {
63         if (fActive) {
64             return super.doActivateContext(activation);
65         }
66         fLocalActivations.put(activation, null);
67         return activation;
68     }
69
70     /*
71      * (non-Javadoc)
72      *
73      * @see org.eclipse.ui.internal.services.INestable#activate()
74      */

75     public void activate() {
76         if (fActive) {
77             return;
78         }
79
80         Iterator JavaDoc c = fLocalActivations.keySet().iterator();
81         while (c.hasNext()) {
82             IContextActivation activation = (IContextActivation) c.next();
83             super.doActivateContext(activation);
84         }
85         fActive = true;
86     }
87
88     /*
89      * (non-Javadoc)
90      *
91      * @see org.eclipse.ui.internal.services.INestable#deactivate()
92      */

93     public void deactivate() {
94         if (!fActive) {
95             return;
96         }
97         deactivateContexts(fParentActivations);
98         fParentActivations.clear();
99
100         Iterator JavaDoc c = fLocalActivations.keySet().iterator();
101         while (c.hasNext()) {
102             fLocalActivations.put(c.next(), null);
103         }
104         fActive = false;
105     }
106 }
107
Popular Tags