1 11 package org.eclipse.ui.internal.keys; 12 13 import org.eclipse.jface.bindings.BindingManager; 14 import org.eclipse.jface.bindings.Scheme; 15 import org.eclipse.ui.commands.IKeyConfiguration; 16 import org.eclipse.ui.commands.IKeyConfigurationListener; 17 import org.eclipse.ui.commands.NotDefinedException; 18 19 22 public final class SchemeWrapper implements IKeyConfiguration { 23 24 28 private final BindingManager bindingManager; 29 30 33 private final Scheme scheme; 34 35 44 public SchemeWrapper(final Scheme scheme, 45 final BindingManager bindingManager) { 46 if (scheme == null) { 47 throw new NullPointerException ("Cannot wrap a null scheme"); } 49 50 if (bindingManager == null) { 51 throw new NullPointerException ( 52 "Cannot wrap a scheme without a binding manager"); } 54 55 this.scheme = scheme; 56 this.bindingManager = bindingManager; 57 } 58 59 64 public void addKeyConfigurationListener( 65 IKeyConfigurationListener keyConfigurationListener) { 66 scheme.addSchemeListener(new SchemeListenerWrapper( 67 keyConfigurationListener, bindingManager)); 68 } 69 70 75 public int compareTo(Object o) { 76 return scheme.compareTo(o); 77 } 78 79 84 public String getDescription() throws NotDefinedException { 85 try { 86 return scheme.getDescription(); 87 } catch (final org.eclipse.core.commands.common.NotDefinedException e) { 88 throw new NotDefinedException(e); 89 } 90 } 91 92 97 public String getId() { 98 return scheme.getId(); 99 } 100 101 106 public String getName() throws NotDefinedException { 107 try { 108 return scheme.getName(); 109 } catch (final org.eclipse.core.commands.common.NotDefinedException e) { 110 throw new NotDefinedException(e); 111 } 112 } 113 114 119 public String getParentId() throws NotDefinedException { 120 try { 121 return scheme.getParentId(); 122 } catch (final org.eclipse.core.commands.common.NotDefinedException e) { 123 throw new NotDefinedException(e); 124 } 125 } 126 127 132 public boolean isActive() { 133 return scheme.getId().equals(bindingManager.getActiveScheme().getId()); 134 } 135 136 141 public boolean isDefined() { 142 return scheme.isDefined(); 143 } 144 145 150 public void removeKeyConfigurationListener( 151 IKeyConfigurationListener keyConfigurationListener) { 152 scheme.removeSchemeListener(new SchemeListenerWrapper( 153 keyConfigurationListener, bindingManager)); 154 155 } 156 157 } 158 | Popular Tags |