1 11 package org.eclipse.ui.internal.part.services; 12 13 import java.util.ArrayList ; 14 import java.util.Iterator ; 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 [] scopes = new String [0]; 28 private boolean active = false; 29 private IKeyBindingService parent; 30 private ArrayList actions = new ArrayList (); 31 32 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 [] 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 [] 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 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 newActive) { 80 for (Iterator 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 |