KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > part > services > ChildKeyBindingService


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

11 package org.eclipse.ui.internal.part.services;
12
13 import java.util.ArrayList JavaDoc;
14 import java.util.Iterator JavaDoc;
15
16 import org.eclipse.jface.action.IAction;
17 import org.eclipse.ui.IKeyBindingService;
18 import org.eclipse.ui.internal.components.Assert;
19 import org.eclipse.ui.internal.components.framework.ComponentException;
20 import org.eclipse.ui.internal.components.framework.IServiceProvider;
21 import org.eclipse.ui.internal.part.Part;
22 import org.eclipse.ui.internal.part.multiplexer.INestedComponent;
23 import org.eclipse.ui.internal.part.multiplexer.ISharedContext;
24
25 public class ChildKeyBindingService implements IKeyBindingService, INestedComponent {
26
27     private String JavaDoc[] scopes = new String JavaDoc[0];
28     private boolean active = false;
29     private IKeyBindingService parent;
30     private ArrayList JavaDoc actions = new ArrayList JavaDoc();
31     
32     /**
33      * Component constructor. Do not invoke directly.
34      */

35     public ChildKeyBindingService(ISharedContext shared) throws ComponentException {
36         Assert.isNotNull(shared);
37         IServiceProvider sharedContainer = shared.getSharedComponents();
38         
39         this.parent = (IKeyBindingService)sharedContainer.getService(IKeyBindingService.class);
40     }
41     
42     public String JavaDoc[] getScopes() {
43         return scopes;
44     }
45
46     public void registerAction(IAction action) {
47         actions.add(action);
48         
49         if (active) {
50             parent.registerAction(action);
51         }
52     }
53
54     public void setScopes(String JavaDoc[] scopes) {
55         this.scopes = scopes;
56         
57         if (active) {
58             parent.setScopes(scopes);
59         }
60     }
61
62     public void unregisterAction(IAction action) {
63         actions.remove(action);
64         
65         if (active) {
66             parent.unregisterAction(action);
67         }
68     }
69
70     public void activate(Part partBeingActivated) {
71         for (Iterator JavaDoc iter = actions.iterator(); iter.hasNext();) {
72             IAction next = (IAction) iter.next();
73             
74             parent.registerAction(next);
75         }
76         active = true;
77     }
78     
79     public void deactivate(Object JavaDoc newActive) {
80         for (Iterator JavaDoc iter = actions.iterator(); iter.hasNext();) {
81             IAction next = (IAction) iter.next();
82             
83             parent.unregisterAction(next);
84         }
85         active = false;
86     }
87 }
88
Popular Tags